Created
December 20, 2014 03:45
-
-
Save Kekegou/977fff0c1235ad37f39f to your computer and use it in GitHub Desktop.
cc 150 1.3
This file contains hidden or 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 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