Skip to content

Instantly share code, notes, and snippets.

@XinboChen
Last active August 29, 2015 14:05
Show Gist options
  • Save XinboChen/d4e84e3e081c17fa609c to your computer and use it in GitHub Desktop.
Save XinboChen/d4e84e3e081c17fa609c to your computer and use it in GitHub Desktop.
/*1.3 Given two strings, write a method to decide if one is a permutation of the other.
space complexity:
time complexity:
date: 09/01/2014
*/
public class permutationString{
public static boolean permutation(String s1, String s2){
if(s1 ==NULL || s2 == NULL)
return false;
if(s1.isEmpty()&& s2.isEmpty())
return true;
else if(s1.isEmpty() || s2.isEmpty())
return false;
if(s1.length != s2.length)
return false;
int[] test = new int[256];
for(char c : s1.toCharArray()){
test[c] +=1;
}
for (char c : s2.toCharArray()){
test[c]-=1;
}
for(int i: test){
if(i!= 0)
return false;
else
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment