package leetcode;

/**
 * https://leetcode.com/problems/degree-of-an-array/
 */
public class Problem697 {
    public int findShortestSubArray(int[] nums) {
        // TODO
        return 0;
    }

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

@@ -12,16 +12,116 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -261,393 +261,1342 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem697 prob = new Problem697();%0A        System.out.println(prob.findShortestSubArray(new int%5B%5D%7B1, 2, 2, 3, 1%7D)); // 2%0A        System.out.println(prob.findShortestSubArray(new int%5B%5D%7B1, 2, 2, 3, 1, 4, 2%7D)); // 6%0A        System.out.println(prob.findShortestSubArray(new int%5B%5D%7B1, 1, 1, 1, 1%7D)); // 5
+Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (!map.containsKey(nums%5Bi%5D)) %7B%0A                map.put(nums%5Bi%5D, 1);%0A            %7D else %7B%0A                map.put(nums%5Bi%5D, map.get(nums%5Bi%5D) + 1);%0A            %7D%0A        %7D%0A        int max = 0;%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        for (Map.Entry%3CInteger, Integer%3E entry : map.entrySet()) %7B%0A            if (max %3C entry.getValue()) %7B%0A                list.clear();%0A                list.add(entry.getKey());%0A                max = entry.getValue();%0A            %7D else if (max == entry.getValue()) %7B%0A                list.add(entry.getKey());%0A            %7D%0A        %7D%0A        int result = Integer.MAX_VALUE;%0A        for (int num : list) %7B%0A            int tmpResult = 0;%0A            int count = 0;%0A            boolean first = true;%0A            for (int i = 0; i %3C nums.length; i++) %7B%0A                if (count == max) %7B%0A                    break;%0A                %7D%0A                if (nums%5Bi%5D == num) %7B%0A                    count++;%0A                    if (first) %7B%0A                        first = false;%0A                    %7D%0A                %7D%0A                if (!first) %7B%0A                    tmpResult++;%0A                %7D%0A            %7D%0A            result = Math.min(result, tmpResult);%0A        %7D%0A        return result;
 %0A   

Solve problem 697