@@ -0,0 +1,1133 @@
+// Given an unsorted array of integers, find the length of the longest consecutive elements sequence.%0A%0A// For example,%0A// Given %5B100, 4, 200, 1, 3, 2%5D,%0A// The longest consecutive elements sequence is %5B1, 2, 3, 4%5D. Return its length: 4.%0A%0A// Your algorithm should run in O(n) complexity.%0A%0Apublic class Solution %7B%0A    public int longestConsecutive(int%5B%5D num) %7B%0A        if(num.length %3C= 1) return num.length;%0A%0A        HashMap%3CInteger, Integer%3E map = new HashMap%3CInteger, Integer%3E();%0A%0A        for(int i : num)%7B%0A        %09map.put(i, 1);%0A        %7D%0A%0A        int max = Integer.MIN_VALUE;%0A        for(int i = 0; i %3C num.length; i++)%7B%0A        %09int curNum= num%5Bi%5D;%0A%0A        %09if(map.containsKey(curNum))%7B%0A        %09%09int count = 1;%0A%0A        %09%09int bigger = curNum + 1;%0A        %09%09int smaller = curNum - 1;%0A%0A        %09%09while(map.containsKey(bigger))%7B%0A        %09%09%09count++;%0A        %09%09%09map.remove(bigger);%0A        %09%09%09bigger++;%0A        %09%09%7D%0A%0A        %09%09while(map.containsKey(smaller))%7B%0A        %09%09%09count++;%0A        %09%09%09map.remove(smaller);%0A        %09%09%09smaller--;%0A        %09%09%7D%0A%0A        %09%09max = Math.max(max, count);%0A        %09%7D%0A        %7D%0A%0A        return max;%0A    %7D%0A%7D

add longest consecutive sequence solution