Created
July 9, 2013 01:54
-
-
Save rfaisal/5954059 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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