-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueCharacters.java
More file actions
36 lines (31 loc) · 905 Bytes
/
UniqueCharacters.java
File metadata and controls
36 lines (31 loc) · 905 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
28
29
30
31
32
33
34
35
36
import java.util.ArrayList;
public class UniqueCharacters {
public static void main(String[] argS) {
String s = "statistics";
System.out.println(uniqueValIndex(s));
}
public static ArrayList uniqueValIndex(String s) {
ArrayList<Integer> arr = new ArrayList<>();
boolean unique = true;
int x = 0;
for(int i = 0; i < s.length();i++) {
char ch = s.charAt(i);
for(int j = 0; j < s.length(); j++ ){
System.out.println(s.charAt(j) + " " + ch);
if(ch==s.charAt(j)) {
x++;
}
if(x>1){
unique = false;
break;
}
}
if(unique){
arr.add(i);
}
x = 0;
unique = true;
}
return arr;
}
}