Skip to content

Commit 82449ed

Browse files
committed
✨ add solution for shuffle string
1 parent 0ce8380 commit 82449ed

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

shufflestring/shufflestring.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package shufflestring
2+
3+
// https://leetcode.com/problems/shuffle-string/
4+
5+
func restoreString(s string, indices []int) string {
6+
shuffledSlice := make([]string, len(s))
7+
8+
for i := 0; i < len(s); i++ {
9+
v := string(s[i])
10+
pos := indices[i]
11+
12+
shuffledSlice[pos] = v
13+
}
14+
15+
result := ""
16+
for i := 0; i < len(shuffledSlice); i++ {
17+
result += string(shuffledSlice[i])
18+
}
19+
20+
return result
21+
}

0 commit comments

Comments
 (0)