class Solution:
    # @param {integer[]} nums
    # @return {integer}
    def longestConsecutive(self, nums):
        nums = set(nums)
        m = 0
        while nums:
            start = end = nums.pop()
            while start - 1 in nums:
                start -= 1
                nums.remove(start)
            while end + 1 in nums:
                end += 1
                nums.remove(end)
            m = max(m, end - start + 1)
        return m
 
if __name__ == "__main__":
    sol = Solution()
    print sol.longestConsecutive([100, 4, 200, 1, 3, 2]) == 4

@@ -103,16 +103,586 @@
  nums):%0A
+        # use dictionary%0A        # h = dict.fromkeys(nums)%0A        h = dict(%5Bkey, None%5D for key in nums)%0A        m = 0%0A        while h:%0A            key, value = h.popitem()%0A            start = end = key%0A            #start = end = h.keys().pop()%0A            #del h%5Bstart%5D%0A            while start - 1 in h:%0A                start -= 1%0A                del h%5Bstart%5D%0A            while end + 1 in h:%0A                end += 1%0A                del h%5Bend%5D%0A            m = max(m, end - start + 1)%0A        return m%0A        %0A    def alongestConsecutive(self, nums):%0A        # use set%0A
         
@@ -1130,8 +1130,54 @@
 %5D) == 4%0A
+    print sol.longestConsecutive(%5B0, 1%5D) == 2%0A

add dictionary solution for 128