File tree 6 files changed +114
-2
lines changed
solution/1500-1599/1528.Shuffle String
6 files changed +114
-2
lines changed Original file line number Diff line number Diff line change 55
55
<!-- 这里可写当前语言的特殊实现逻辑 -->
56
56
57
57
``` python
58
-
58
+ class Solution :
59
+ def restoreString (self , s : str , indices : List[int ]) -> str :
60
+ ans = [0 ] * len (s)
61
+ for i, c in enumerate (s):
62
+ ans[indices[i]] = c
63
+ return ' ' .join(ans)
59
64
```
60
65
61
66
### ** Java**
62
67
63
68
<!-- 这里可写当前语言的特殊实现逻辑 -->
64
69
65
70
``` java
71
+ class Solution {
72
+ public String restoreString (String s , int [] indices ) {
73
+ int n = s. length();
74
+ char [] ans = new char [n];
75
+ for (int i = 0 ; i < n; ++ i) {
76
+ ans[indices[i]] = s. charAt(i);
77
+ }
78
+ return String . valueOf(ans);
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### ** C++**
84
+
85
+ ``` cpp
86
+ class Solution {
87
+ public:
88
+ string restoreString(string s, vector<int >& indices) {
89
+ int n = s.size();
90
+ string ans(n, 0);
91
+ for (int i = 0; i < n; ++i) ans[ indices[ i]] = s[ i] ;
92
+ return ans;
93
+ }
94
+ };
95
+ ```
96
+
97
+ ### **Go**
66
98
99
+ ```go
100
+ func restoreString(s string, indices []int) string {
101
+ ans := make([]rune, len(s))
102
+ for i, c := range s {
103
+ ans[indices[i]] = c
104
+ }
105
+ return string(ans)
106
+ }
67
107
```
68
108
69
109
### ** ...**
Original file line number Diff line number Diff line change 43
43
### ** Python3**
44
44
45
45
``` python
46
-
46
+ class Solution :
47
+ def restoreString (self , s : str , indices : List[int ]) -> str :
48
+ ans = [0 ] * len (s)
49
+ for i, c in enumerate (s):
50
+ ans[indices[i]] = c
51
+ return ' ' .join(ans)
47
52
```
48
53
49
54
### ** Java**
50
55
51
56
``` java
57
+ class Solution {
58
+ public String restoreString (String s , int [] indices ) {
59
+ int n = s. length();
60
+ char [] ans = new char [n];
61
+ for (int i = 0 ; i < n; ++ i) {
62
+ ans[indices[i]] = s. charAt(i);
63
+ }
64
+ return String . valueOf(ans);
65
+ }
66
+ }
67
+ ```
68
+
69
+ ### ** C++**
70
+
71
+ ``` cpp
72
+ class Solution {
73
+ public:
74
+ string restoreString(string s, vector<int >& indices) {
75
+ int n = s.size();
76
+ string ans(n, 0);
77
+ for (int i = 0; i < n; ++i) ans[ indices[ i]] = s[ i] ;
78
+ return ans;
79
+ }
80
+ };
81
+ ```
82
+
83
+ ### **Go**
52
84
85
+ ```go
86
+ func restoreString(s string, indices []int) string {
87
+ ans := make([]rune, len(s))
88
+ for i, c := range s {
89
+ ans[indices[i]] = c
90
+ }
91
+ return string(ans)
92
+ }
53
93
```
54
94
55
95
### ** ...**
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ string restoreString (string s, vector<int >& indices) {
4
+ int n = s.size ();
5
+ string ans (n, 0 );
6
+ for (int i = 0 ; i < n; ++i) ans[indices[i]] = s[i];
7
+ return ans;
8
+ }
9
+ };
Original file line number Diff line number Diff line change
1
+ func restoreString (s string , indices []int ) string {
2
+ ans := make ([]rune , len (s ))
3
+ for i , c := range s {
4
+ ans [indices [i ]] = c
5
+ }
6
+ return string (ans )
7
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public String restoreString (String s , int [] indices ) {
3
+ int n = s .length ();
4
+ char [] ans = new char [n ];
5
+ for (int i = 0 ; i < n ; ++i ) {
6
+ ans [indices [i ]] = s .charAt (i );
7
+ }
8
+ return String .valueOf (ans );
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def restoreString (self , s : str , indices : List [int ]) -> str :
3
+ ans = [0 ] * len (s )
4
+ for i , c in enumerate (s ):
5
+ ans [indices [i ]] = c
6
+ return '' .join (ans )
You can’t perform that action at this time.
0 commit comments