Created
June 17, 2014 18:00
-
-
Save hilda8519/3fbd305943dab4addd62 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
package isPermutation; | |
import java.util.Arrays; | |
public class isPermutation{ | |
public static void main (String[] args) { | |
String s="good"; | |
String t="adog";/*give s,t*/ | |
System.out.println(isPerm(s,t)); | |
} | |
public static boolean isPerm(String s, String t){ | |
if(s.length()!=t.length()) { | |
return false;/*if the length is different,it should be false*/ | |
} | |
if(s==null||t==null) {/*if s,t empty,false*/ | |
return false; | |
} | |
char[] array1=s.toCharArray();/*put s to array1*/ | |
char[] array2=t.toCharArray(); | |
Arrays.sort(array1); | |
Arrays.sort(array2);/*sort s,t*/ | |
if(Arrays.toString(array1).equals(Arrays.toString(array2))){ | |
return true;/*compare s,t*/ | |
} | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment