Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Created July 9, 2013 01:54
Show Gist options
  • Select an option

  • Save rfaisal/5954059 to your computer and use it in GitHub Desktop.

Select an option

Save rfaisal/5954059 to your computer and use it in GitHub Desktop.
public class SimpleSpamDetectorInefficient {
public static boolean doesDuplicatingMatch(String s,String p){
if(p.length()>s.length()) //if pattern is larger than the original string
return false;
else if(s.length()==0 && p.length()==0) //if both empty
return true;
else if(s.length()==0 || p.length()==0) //if one empty
return false;
else if(Character.toLowerCase(s.charAt(0)) == Character.toLowerCase(p.charAt(0)))
return doesDuplicatingMatch(s.substring(1),p.substring(1))
||doesDuplicatingMatch(s.substring(1),p);
else
return false;
}
public static int countKeywords(String subjectLine, String[] keywords){
String[] words=subjectLine.split(" ");
int count=0;
for(String s:words){
if(s!=""){
for(String p:keywords){
if(doesDuplicatingMatch(s,p)){
count++;
break;
}
}
}
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment