-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnique.java
More file actions
39 lines (30 loc) · 944 Bytes
/
Unique.java
File metadata and controls
39 lines (30 loc) · 944 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
37
38
39
import com.sun.xml.internal.messaging.saaj.util.FastInfosetReflection;
class Solution {
public static void main(String[] args){
System.out.println(isUnique("heqiasdl").toString());
}
public static Boolean isUnique(String str){
int checker = 0;
for (int i = 0; i < str.length(); i ++){
int val = str.charAt(i) - 'a';
if ((checker & (1 << val)) > 0){
return false;
}
checker |= (1 << val);
}
return true;
}
public static Boolean isUnique1(String str){
if (str.length() > 128) return false;
boolean[] char_set = new boolean[128];
for (int i = 0; i < str.length(); i++){
int curr = str.charAt(i);
if (char_set[curr]){
return false;
} else {
char_set[curr] = true;
}
}
return true;
}
}