Skip to content

Instantly share code, notes, and snippets.

@berkayk
Created January 26, 2016 08:05
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 berkayk/3a85f1e50b781d6a361f to your computer and use it in GitHub Desktop.
Save berkayk/3a85f1e50b781d6a361f to your computer and use it in GitHub Desktop.
public boolean isPermutation(String source, String dest) {
// is source a permutation of dest?
if (source == null || dest == null)
return false;
if (source.length() != dest.length()
return false;
while (source.length() > 0) {
// If they somehow
if (source.equals(dest))
return true;
char temp = source.charAt(0);
int index = dest.indexOf(temp);
if (index < 0) {
return false;
}
source = source.substring(1, source.length());
dest = dest.substring(0, index) + dest.substring(index + 1, dest.length());
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment