-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammerJinDian_1.1.java
More file actions
40 lines (35 loc) · 866 Bytes
/
Copy pathProgrammerJinDian_1.1.java
File metadata and controls
40 lines (35 loc) · 866 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
40
/*
* Check the elements in a array are differect which means no repeat.
* Only use array.
*/
// First, confirm that the elements are ASCII or Unicode
public boolean inUniqueChar2(String str){
int strLength = str.length();
if(strLength > 256) return false;
boolean[] char_set = new boolean[256];
for(int i = 0; i < strLength; i++){
int var = str.charAt[i];
if(char_set[val]){ //This element is found before
return false;
}
char_set[val] = true;
}
return true;
}
/*
* Only for a - z
*/
public boolean inUniqueChar2(String str){
int strLength = str.length();
int varA = (int) 'a';
if(strLength > 26) return false;
boolean[] char_set = new boolean[26];
for(int i = 0; i < strLength; i++){
int var = str.charAt[i] - varA;
if(char_set[val]){ //This element is found before
return false;
}
char_set[val] = true;
}
return true;
}