-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueness.java
More file actions
37 lines (25 loc) · 809 Bytes
/
Uniqueness.java
File metadata and controls
37 lines (25 loc) · 809 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
package com.java.cci.practice;
public class Uniqueness {
public static boolean isUniqueChars(String str) {
if (str == null) {
return false;
}
boolean [] booleanArray = new boolean[128];
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
int c = chars[i];
if (booleanArray[c]) {
return true;
} else {
booleanArray[c] = true;
}
}
return false;
}
public static void main(String[] args) {
String[] words = {"abcde", "hello", "apple", "kite", "padle"};
for (String word : words) {
System.out.println(word + ": " + isUniqueChars(word));
}
}
}