Created
March 17, 2013 20:42
-
-
Save astkaasa/5183556 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
import java.util.*; | |
public class PermutationChar { | |
public static void main( String[] args ) { | |
String[] strArray = { "Guo Haoxuan", "Haoxuan Guo" }; | |
System.out.println( isPermutation ( strArray[0], strArray[1] ) ); | |
} | |
public static boolean isPermutation( String str1, String str2 ) { | |
int[] set = new int[256]; | |
for ( int i = 0; i < 256; i++ ) | |
set[i] = 0; | |
for ( int j = 0, len = str1.length(); j < len; j++ ) { | |
int val = str1.charAt( j ); | |
set[val]++; | |
} | |
for ( int k = 0, len = str2.length(); k < len; k++ ) { | |
int val = str2.charAt( k ); | |
if ( set[val] == 0 ) | |
return false; | |
else set[val]--; | |
} | |
for ( int l = 0; l < 256; l++ ) { | |
if ( set[l] !=0 ) | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment