Skip to content

Instantly share code, notes, and snippets.

@JoyceeLee
Created June 16, 2014 17:59
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 JoyceeLee/826c8c3ea2bdedfe9622 to your computer and use it in GitHub Desktop.
Save JoyceeLee/826c8c3ea2bdedfe9622 to your computer and use it in GitHub Desktop.
/*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