Skip to content

Commit 4b106b5

Browse files
add more tests for 1528
1 parent 097ffb3 commit 4b106b5

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1528|[Shuffle String](https://leetcode.com/problems/shuffle-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1528.java) | |Easy|Sort|
1112
|1526|[Minimum Number of Increments on Subarrays to Form a Target Array](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1526.java) | |Hard|Segment Tree|
1213
|1525|[Number of Good Ways to Split a String](https://leetcode.com/problems/number-of-good-ways-to-split-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1525.java) | |Medium|String, Bit Manipulation|
1314
|1524|[Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1524.java) | |Medium|Array, Math|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1528 {
4+
public static class Solution1 {
5+
public String restoreString(String s, int[] indices) {
6+
char[] c = new char[s.length()];
7+
for (int i = 0; i < s.length(); i++) {
8+
int index = findIndex(indices, i);
9+
c[i] = s.charAt(index);
10+
}
11+
return new String(c);
12+
}
13+
14+
private static int findIndex(int[] indices, int i) {
15+
for (int j = 0; j < indices.length; j++) {
16+
if (indices[j] == i) {
17+
return j;
18+
}
19+
}
20+
return 0;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1528;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1528Test {
10+
private static _1528.Solution1 solution1;
11+
private static int[] indices;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1528.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
indices = new int[]{4, 5, 6, 7, 0, 2, 1, 3};
21+
assertEquals("leetcode", solution1.restoreString("codeleet", indices));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)