-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathBigWord.java
45 lines (32 loc) · 1.01 KB
/
BigWord.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.ArrayList;
public class BigWord {
public String most(String[] sentences) {
ArrayList<String> words = new ArrayList<>();
int[] counts = new int[1250];
for (String s: sentences) {
String[] sList = s.toLowerCase().split(" ");
for (String w : sList) {
if (words.contains(w) == false) {
words.add(w);
}
counts[words.indexOf(w)]++;
}
}
int max = 0;
int indexMax = 0;
for (int i = 0; i < counts.length; i++) {
if (counts[i] > max) {
max = counts[i];
indexMax = i;
}
}
String ret = words.get(indexMax);
return ret;
}
public static void main(String [] args) {
BigWord Test = new BigWord();
String[] sentences = {"This is the way", "This is the way", "this is this"};
String ret = Test.most(sentences);
System.out.print(ret);
}
}