package leetcode;

/**
 * https://leetcode.com/problems/find-lucky-integer-in-an-array/
 */
public class Problem1394 {
    public int findLucky(int[] arr) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1394 prob = new Problem1394();
        System.out.println(prob.findLucky(new int[]{2,2,3,4})); // 2
        System.out.println(prob.findLucky(new int[]{1,2,2,3,3,3})); // 3
        System.out.println(prob.findLucky(new int[]{2,2,2,3,3})); // -1
        System.out.println(prob.findLucky(new int[]{5})); // -1
        System.out.println(prob.findLucky(new int[]{7,7,7,7,7,7,7})); // 7
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -211,484 +211,429 @@
     
-// TODO%0A        return 0
+Map%3C/* number= */ Integer, /* count= */ Integer%3E map = new HashMap%3C%3E()
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1394 prob = new Problem1394();%0A        System.out.println(prob.findLucky(new int%5B%5D%7B2,2,3,4%7D)); // 2%0A        System.out.println(prob.findLucky(new int%5B%5D%7B1,2,2,3,3,3%7D)); // 3%0A        System.out.println(prob.findLucky(new int%5B%5D%7B2,2,2,3,3%7D)); // -1%0A        System.out.println(prob.findLucky(new int%5B%5D%7B5%7D)); // -1%0A        System.out.println(prob.findLucky(new int%5B%5D%7B7,7,7,7,7,7,7%7D)); // 7
+for (int a : arr) %7B%0A            map.put(a, map.getOrDefault(a, 0) + 1);%0A        %7D%0A        int answer = -1;%0A        for (Map.Entry%3CInteger, Integer%3E e : map.entrySet()) %7B%0A            if (e.getKey() != e.getValue()) %7B%0A                continue;%0A            %7D%0A            answer = Math.max(answer, e.getValue());%0A        %7D%0A        return answer;
 %0A   

Solve problem 1394