-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidAnagram.java
More file actions
executable file
·36 lines (35 loc) · 965 Bytes
/
ValidAnagram.java
File metadata and controls
executable file
·36 lines (35 loc) · 965 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
package code.coder.lee.easy;
/**
* Created by bcc on 16/3/10.
*/
public class ValidAnagram {
public boolean isAnagram(String s, String t) {
if (s==null&&t==null){
return true;
}else if(s==null){
return false;
}else if(t==null){
return false;
}else{
if(s.length()!=t.length()){
return false;
}
int i=0;
int[] nums = new int[26];
while(i<s.length()&&i<t.length()){
nums[s.charAt(i)-'a']++;
nums[t.charAt(i)-'a']--;
i++;
}
for(int j=0;j<nums.length;j++){
if (nums[j]!=0)
return false;
}
return true;
}
}
public static void main(String[] args) {
ValidAnagram validAnagram = new ValidAnagram();
System.out.println(validAnagram.isAnagram("", ""));
}
}