Created
June 16, 2014 17:59
-
-
Save JoyceeLee/826c8c3ea2bdedfe9622 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
/*1.3 Given two strings, write a method to decide if one is a permutation of the other. */ | |
public class Solution { | |
public boolean isPermutation(String s, String t) { | |
if(s.length()!=t.length()) | |
return false; | |
int[] check = new int[256]; | |
for(int i=0; i<s.length(); i++) { | |
check[s.charAt(i)]++; | |
} | |
for(int i=0; i<t.length(); i++) { | |
check[s.charAt(i)]--; | |
if(check[s.charAt(i)]<0) | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment