Created
November 13, 2016 22:48
-
-
Save mgarod/468c339fb1c5227702f80112c74e7ac2 to your computer and use it in GitHub Desktop.
This file contains 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
static String firstRepeatedWord(String s) { | |
HashSet<String> hashset = new HashSet<>(); | |
String[] splited = s.split("\\s+"); | |
for (String word : splited) { | |
word = word.trim().replaceAll("\\W", ""); | |
if (hashset.contains(word)) { | |
return word; | |
} else { | |
hashset.add(word); | |
} | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment