Skip to content

Instantly share code, notes, and snippets.

@hilda8519
Created June 17, 2014 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilda8519/3fbd305943dab4addd62 to your computer and use it in GitHub Desktop.
Save hilda8519/3fbd305943dab4addd62 to your computer and use it in GitHub Desktop.
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