Created
June 18, 2014 14:42
-
-
Save bitcpf/bc83a56c7c3ef44187cb 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
/** | |
* | |
* @author bitcpf on June 18th | |
* | |
*/ | |
public class permutation { | |
public static boolean stringpermutation(String s1, String s2){ | |
// Default value is 0 | |
int[] assic1 = new int[256]; | |
int[] assic2 = new int[256]; | |
if (s1.length() != s2.length()){ | |
return false; | |
} | |
// Statistic the number of characters in the arrays | |
int i=0; | |
while(i<s1.length()){ | |
assic1[s1.charAt(i)]++; | |
assic2[s2.charAt(i)]++; | |
i++; | |
} | |
// Check if the two strings has the same number of each char | |
i = 0; | |
while(i<256){ | |
if (assic1[i]-assic2[i]!=0) | |
return false; | |
i++; | |
} | |
return true; | |
} | |
public static void main(String[] args){ | |
String input_s1 = "abcdefg"; | |
String input_s2 = "bcdefga"; | |
System.out.println(stringpermutation(input_s1,input_s2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment