Skip to content

Instantly share code, notes, and snippets.

@Kekegou
Created December 20, 2014 03:45
Show Gist options
  • Save Kekegou/977fff0c1235ad37f39f to your computer and use it in GitHub Desktop.
Save Kekegou/977fff0c1235ad37f39f to your computer and use it in GitHub Desktop.
cc 150 1.3
public class Solution {
public static boolean isPermutaion(String s1, String s2) {
if(s1.length() != s2.length()){
return false;
}
int[] charactor = new int[256];
char[] array1 = s1.toCharArray();
char[] array2 = s2.toCharArray();
for(int i = 0; i<s1.length(); i++){
int index = array1[i];
charactor[index]++;
}
for(int i = 0; i<s2.length(); i++){
int index = array2[i];
charactor[index]--;
}
for(int i : charactor){
if(i!=0){
return false;
}
}
return true;
}
public static void main(String[] args){
System.out.print(Solution.isPermutaion("colin","cloin"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment