@@ -0,0 +1,1303 @@
+Given an unsorted array of integers, find the length of the longest consecutive elements sequence.%0A%0AFor example,%0AGiven %5B100, 4, 200, 1, 3, 2%5D,%0AThe longest consecutive elements sequence is %5B1, 2, 3, 4%5D. Return its length: 4.%0A%0AYour algorithm should run in O(n) complexity.%0A%0Aclass Solution:%0A    # @param num, a list of integer%0A    # @return an integer%0A    def longestConsecutive(self, num):%0A        table = %7B%7D%0A        n = len(num)%0A        result = 0%0A        for i in xrange(n):%0A            left = 0; right = 0%0A            if num%5Bi%5D not in table:%0A                if (num%5Bi%5D-1) in table:%0A                    left = table%5Bnum%5Bi%5D-1%5D%0A                if (num%5Bi%5D+1) in table:%0A                    right = table%5Bnum%5Bi%5D+1%5D%0A                isum = left + right + 1%0A                table%5Bnum%5Bi%5D%5D = isum%0A                %0A                table%5Bnum%5Bi%5D-left%5D = isum%0A                table%5Bnum%5Bi%5D+right%5D = isum%0A                %0A                result = max(isum, result)%0A        return result %0A%0A# %E6%B3%A8%E6%84%8F%E8%BF%99%E9%87%8C%E7%9A%84corner case%EF%BC%9A %5B1,2,0,1%5D %E4%B8%8D%E5%85%89%E8%A6%81%E6%9B%B4%E6%96%B0%E5%BD%93%E4%B8%8B%E7%9A%84%E6%95%B0%E5%80%BC%E5%8F%AF%E4%BB%A5%E7%BB%84%E6%88%90%0A# maximum consecutive array %E7%9A%84%E6%9C%80%E5%A4%A7%E9%95%BF%E5%BA%A6%EF%BC%8C%E8%BF%98%E8%A6%81%E6%9B%B4%E6%96%B0 %E8%B5%B7%E7%82%B9%E5%92%8C%E7%BB%88%E7%82%B9%E7%9A%84%E5%80%BC%EF%BC%81%E8%AE%B0%E4%BD%8F%E4%B8%8D%E6%98%AF%E5%B7%A6%E5%8F%B3%E9%82%BB%E5%B1%85%E7%9A%84%E5%80%BC%EF%BC%8C%E8%80%8C%E6%98%AF%E8%B5%B7%E7%82%B9%E5%92%8C%E7%BB%88%E7%82%B9%0A# Use left and right to locate the other end of the sequences to the left and right of n respectively, and replace the value with the new length.%0A%0A# Corner Case %0A# Input:%09%5B0,3,7,2,5,8,4,6,0,1%5D%0A# Output:%097%0A# Expected:%099%0A

Create Longset_Consecutive_Sequence.py