Skip to content

Commit 59b6e96

Browse files
committed
feat: add solutions to lc problem: No.1528
No.1528.Shuffle String
1 parent 18139a3 commit 59b6e96

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

solution/1500-1599/1528.Shuffle String/README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,55 @@
5555
<!-- 这里可写当前语言的特殊实现逻辑 -->
5656

5757
```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)
5964
```
6065

6166
### **Java**
6267

6368
<!-- 这里可写当前语言的特殊实现逻辑 -->
6469

6570
```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**
6698
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+
}
67107
```
68108

69109
### **...**

solution/1500-1599/1528.Shuffle String/README_EN.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,53 @@
4343
### **Python3**
4444

4545
```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)
4752
```
4853

4954
### **Java**
5055

5156
```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**
5284
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+
}
5393
```
5494

5595
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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)

0 commit comments

Comments
 (0)