Skip to content

Commit 8db401c

Browse files
add 2788
1 parent 8fe955f commit 8db401c

File tree

3 files changed

+54
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+54
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2824.java) | | Easy |
1111
| 2812 | [Find the Safest Path in a Grid](https://leetcode.com/problems/find-the-safest-path-in-a-grid/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2812.java) | | Medium |BFS
1212
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2810.java) | | Easy |
13+
| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2788.java) | | Easy |
1314
| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2784.java) | | Easy |
1415
| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2778.java) | | Easy |
1516
| 2769 | [Find the Maximum Achievable Number](https://leetcode.com/problems/find-the-maximum-achievable-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2769.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2788 {
7+
public static class Solution1 {
8+
public List<String> splitWordsBySeparator(List<String> words, char separator) {
9+
List<String> ans = new ArrayList<>();
10+
StringBuilder sb = new StringBuilder();
11+
for (String word : words) {
12+
sb.setLength(0);
13+
for (int i = 0; i < word.length(); i++) {
14+
if (word.charAt(i) == separator) {
15+
if (sb.length() != 0) {
16+
ans.add(sb.toString());
17+
sb.setLength(0);
18+
}
19+
} else {
20+
sb.append(word.charAt(i));
21+
}
22+
}
23+
if (sb.length() != 0) {
24+
ans.add(sb.toString());
25+
}
26+
}
27+
return ans;
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2788;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class _2788Test {
12+
private static _2788.Solution1 solution1;
13+
14+
@BeforeEach
15+
public void setup() {
16+
solution1 = new _2788.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
assertEquals(Arrays.asList("one", "two", "three", "four", "five", "six"), solution1.splitWordsBySeparator(Arrays.asList("one.two.three", "four.five", "six"), '.'));
22+
}
23+
}

0 commit comments

Comments
 (0)