Created
June 16, 2014 17:08
-
-
Save iwilbert/21b1b1dd680f33d5ead7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isPerm(String str1, String str2) { | |
// edge cases: null, len not equal, len = 0 | |
if(str1 == null || str2 == null) | |
return false; | |
int m = str1.length(); | |
int n = str2.length(); | |
if(m != n) | |
return false; | |
if(m == 0) | |
return true; | |
// count character occurrences | |
int[] count = new int[256]; | |
for(int i = 0; i < m; i++) | |
count[str1.charAt(i)]++; | |
for(int i = 0; i < n; i++) | |
{ | |
char c = str2.charAt(i); | |
count[c]--; | |
if(count[c] < 0) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 9-10:
so "" is not a permutation of "" ?