- Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathFirstRepeatedWords.java
More file actions
Latest commit
28 lines (28 loc) · 601 Bytes
/
Copy pathFirstRepeatedWords.java
File metadata and controls
28 lines (28 loc) · 601 Bytes
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
importjava.util.*;
publicclassMain
{
publicstaticvoidmain(Stringargs[])
{
firstRepeatedWord("shashwat had been saying that he had been coding");
}
publicstaticvoidfirstRepeatedWord(Stringstr)
{
HashSet<String> set = newHashSet<>();
if(str.length()==0)
{
System.out.println("Not Found!");
return;
}
Stringwords[] = str.split(" ");
for(Strings : words)
{
if(set.contains(s))
{
System.out.println("First repeated is: "+s);
return;
}
set.add(s);
}
System.out.println("Not Found");
}
}