Skip to content

Instantly share code, notes, and snippets.

@RichardCSantana-zz
Created April 12, 2016 22:15
Show Gist options
  • Save RichardCSantana-zz/3108d9d1231d526ab4cf8c703ca7a13c to your computer and use it in GitHub Desktop.
Save RichardCSantana-zz/3108d9d1231d526ab4cf8c703ca7a13c to your computer and use it in GitHub Desktop.
package com.example;
/**
* @author richardsantana
*/
public class Solver {
public boolean checkAnagram(String phrase, String search) {
for (String substring : phrase.split(" ")) {
if(substring.length() == search.length()){
Structure phraseStructure = new Structure(phrase);
Structure searchStructure = new Structure(search);
if(searchStructure.calculateHash() == phraseStructure.calculateHash()){
return true;
}
}
}
return false;
}
class Structure {
final private String value;
public Structure(String value) {
this.value = value;
}
public int calculateHash(){
int result = 0;
for(char character : value.toCharArray()){
result += new Integer(character);
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment