'How to count groups string input with same character
this code is about Too Many Tabs code. URLs are considered equal if the domains are exactly the same, e.g. google.com and google.co.id are different
Example input
- google.com google.co.id facebook.com facebook.com/profil
- facebook.com/faq facebook.com/search facebook.com facebook.com/profil
Example output
- 3
- 1
For the first test case, it will contains and count as 3 groups
- google.com
- google.co.id
- facebook.com
For the second test case, it will contains and count as 1 group
Solution 1:[1]
import java.util.ArrayList;
import java.util.*;
public class CountGroup
{
public static void main(String[] args)
{
String input = "google.com google.co.id facebook.com facebook.com/profil";
// String input = "facebook.com/faq facebook.com/search facebook.com facebook.com/profil";
String[] arrinput = input.split(" ");
ArrayList<String> finalin = new ArrayList<>();
Set<String> finalinput = new HashSet<String>();
for (String str : arrinput)
{
finalin.add(str);
}
for (String str : finalin) //[facebook.com,google.com.google.co.id,facebook.com/id]
{
if(!(str.contains("/")))
{
finalinput.add(str);
}
}
for (String str : finalinput)
{
System.out.println(str);
}
System.out.println(finalinput.size());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Java Team |