-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrap.java
More file actions
38 lines (32 loc) · 1.02 KB
/
Copy pathScrap.java
File metadata and controls
38 lines (32 loc) · 1.02 KB
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
37
38
public class Scrap {
public static void main(String[] args){
//permutation("his");
System.out.println(isUnique("helllo"));
}
public static void permutation(String s){
permutation(s, "");
}
public static void permutation(String s, String prefix){
if (s.length() == 0) {
System.out.println(prefix);
} else {
for (int i = 0; i < s.length(); i++){
String rem = s.substring(0,i) + s.substring(i+1);
System.out.println("i is: "+ i + " rem:" + rem + " prefix:" + prefix+s.charAt(i));
permutation(rem, prefix+s.charAt(i));
}
}
}
public static Boolean isUnique(String str){
int tracker = 0;
char[] input_array = str.toCharArray();
for (char c : input_array){
int current = 1 << (c - 'a');
if ((tracker & current) > 0){
return false;
}
tracker |= current;
}
return true;
}
}