-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicate.java
More file actions
27 lines (24 loc) · 838 Bytes
/
Copy pathDuplicate.java
File metadata and controls
27 lines (24 loc) · 838 Bytes
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
package algo.basics;
import java.util.Arrays;
public class Duplicate {
public static String[] removeDup(String[] input){
String[] result = new String[input.length];
for (int i = 0; i < input.length; i++) {
String word = input[i];
String removed = "";
for (int j = 0; j < word.length() - 1; j++) {
if (word.charAt(j) != word.charAt(j + 1)) {
removed += word.charAt(j);
}
}
result[i] = removed + word.charAt(word.length() - 1);
}
return result;
}
public static void main(String[] args) {
String[] actual = Duplicate.removeDup(new String[]{
"bonjour", "boonsoir", "tteemmpps", "abcdd"
});
System.out.println(Arrays.toString(actual));
}
}