Skip to content

Instantly share code, notes, and snippets.

@iwilbert
Created June 16, 2014 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwilbert/21b1b1dd680f33d5ead7 to your computer and use it in GitHub Desktop.
Save iwilbert/21b1b1dd680f33d5ead7 to your computer and use it in GitHub Desktop.
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;
}
@jackson-rz
Copy link

line 9-10:
so "" is not a permutation of "" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment