public int longestConsecutive(int[] num) {
    	
    	Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
    	
    	for (int n : num)
    		map.put(n, false);
    	
    	int maxLen = 0;
    	for (int n : num)
    	{
    		if (map.get(n) == true)
    			continue;
    		
    		//current node
    		int idx = n;
			map.put(idx, true);
    		int count = 1;
    		
    		//scan left
    		while (map.containsKey(--idx))
    		{
    			map.put(idx, true);
    			count++;
    		}
    		
    		//scan right
    		idx = n;
    		while (map.containsKey(++idx))
    		{
    			map.put(idx, true);
    			count++;
    		}
    		
    		maxLen = Math.max(maxLen, count);
    	}
    	
    	return maxLen;
    }