Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Hashtable;
- public class GoogleChallenge3 {
- public int solution(String[] L) {
- Hashtable<String, Integer> map = new Hashtable<>();
- for (int i = 0; i < L.length; i++) {
- String key = getDomain(L[i]) + countLocalName(L[i], 0);
- if (!map.containsKey(key))
- map.put(key, 1);
- else
- map.put(key, map.get(key) + 1);
- }
- int result = 0;
- for (String s : map.keySet()) {
- if (map.get(s) > 1)
- result++;
- }
- return result;
- }
- private int countLocalName(String email, int i) {
- if (email.charAt(i) == '@' || email.charAt(i) == '+')
- return 0;
- if (email.charAt(i) == '.')
- return countLocalName(email, i + 1);
- return countLocalName(email, i + 1) + 1;
- }
- private String getDomain(String email) {
- return email.substring(email.indexOf('@'), email.length());
- }
- public static void main(String[] args) {
- int N = 7;
- String[] L = new String[N];
- L[0] = "a.b@example.com";
- L[1] = "x@example.com";
- L[2] = "x@exa.mple.com";
- L[3] = "ab+1@example.com";
- L[4] = "y@example.com";
- L[5] = "y@example.com";
- L[6] = "y@example.com";
- System.out.println(new GoogleChallenge3().solution(L));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement