Skip to content

Commit f635bb8

Browse files
committed
Runtime: 23 ms (Top 55.73%) | Memory: 44.3 MB (Top 45.07%)
1 parent 1fb20e0 commit f635bb8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/algorithms/M/Most Common Word/Most Common Word.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// Runtime: 23 ms (Top 55.73%) | Memory: 44.3 MB (Top 45.07%)
2+
13
class Solution {
24
public String mostCommonWord(String paragraph, String[] banned) {
3-
5+
46
HashMap<String, Integer> hm = new HashMap<>();
57
String[] words = paragraph.replaceAll("[!?',;.]"," ").toLowerCase().split("\\s+");
68
for(int i=0; i<words.length; i++)
@@ -10,12 +12,11 @@ public String mostCommonWord(String paragraph, String[] banned) {
1012
else
1113
hm.put(words[i], 1);
1214
}
13-
15+
1416
for(int i=0; i< banned.length; i++)
1517
if(hm.containsKey(banned[i]))
1618
hm.remove(banned[i]);
1719

1820
return Collections.max(hm.entrySet(), Map.Entry.comparingByValue()).getKey();
1921
}
2022
}
21-

0 commit comments

Comments
 (0)