-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2788.java
30 lines (28 loc) · 984 Bytes
/
_2788.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.fishercoder.solutions.thirdthousand;
import java.util.ArrayList;
import java.util.List;
public class _2788 {
public static class Solution1 {
public List<String> splitWordsBySeparator(List<String> words, char separator) {
List<String> ans = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (String word : words) {
sb.setLength(0);
for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == separator) {
if (sb.length() != 0) {
ans.add(sb.toString());
sb.setLength(0);
}
} else {
sb.append(word.charAt(i));
}
}
if (sb.length() != 0) {
ans.add(sb.toString());
}
}
return ans;
}
}
}