@@ -0,0 +1,1564 @@
+package com.dw.leetcode;%0A%0Aimport java.util.HashMap;%0A%0Apublic class Degree_of_an_Array_697 %7B%0A%09%0A%09public static class Node %7B%0A%09%09public int counter = 0;%0A%09%09public int positionMin = 0;%0A%09%09public int positionMax = 0;%0A%09%7D%0A%0A    public static int findShortestSubArray(int%5B%5D nums) %7B%0A    %09%0A    %09if(nums == null %7C%7C nums.length == 0) return 0;%0A        %0A        HashMap%3CInteger, Node%3E hMap = new HashMap%3C%3E();%0A        int counter = 1;%0A        for(int i = 0;i%3Cnums.length;i++) %7B%0A        %09if(hMap.get(nums%5Bi%5D) == null) %7B%0A        %09%09Node node = new Node();%0A        %09%09node.counter = 1;%0A        %09%09node.positionMin = i;%0A        %09%09node.positionMax = i;%0A        %09%09hMap.put(nums%5Bi%5D, node);%0A        %09%7D%0A        %09else %7B%0A        %09%09Node node = hMap.get(nums%5Bi%5D);%0A        %09%09node.counter++;%0A        %09%09%0A        %09%09if(node.counter %3E counter)%0A        %09%09%09counter = node.counter;%0A        %09%09%0A        %09%09if(i %3C node.positionMin)%0A        %09%09%09node.positionMin = i;%0A        %09%09%0A        %09%09if(i %3E node.positionMax) %0A        %09%09%09node.positionMax = i;%0A        %09%09%0A        %09%09hMap.put(nums%5Bi%5D, node);%0A        %09%7D%0A        %09%09%0A        %7D%0A        %0A        int max = Integer.MAX_VALUE;%0A        %0A        for(int i : hMap.keySet()) %7B%0A        %09Node node = hMap.get(i);%0A        %09if(node.counter == counter) %7B%0A        %09%09int len = node.positionMax - node.positionMin;%0A        %09%09if(len %3C max)%0A        %09%09%09max = len;%0A        %09%7D%0A        %7D%0A        %0A        return max + 1;%0A    %7D%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09int%5B%5D array = %7B1%7D;%0A%09%09%0A%09%09System.out.println(findShortestSubArray(array));%0A%09%7D%0A%0A%7D%0A

add leetcode 697