GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/128_Longest_Consecutive_Sequence.py at master · qiyuangong/leetcode Expand file tree/ Copy path128_Longest_Consecutive_Sequence.pyMore file actions 27 lines (26 loc) · 742 Bytes / Copy path128_Longest_Consecutive_Sequence.pyFile metadata and controls27 lines (26 loc) · 742 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 class Solution(object): def longestConsecutive(self, nums): """ :type nums: List[int] :rtype: int """ def longestConsecutive(self, num): # Pop adjacency O(n) and O(n) num = set(num) maxLen = 0 while num: n = num.pop() i = n + 1 l1 = 0 l2 = 0 while i in num: num.remove(i) i += 1 l1 += 1 i = n - 1 while i in num: num.remove(i) i -= 1 l2 += 1 maxLen = max(maxLen, l1 + l2 + 1) return maxLen |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |