MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / longestConsecutive

Method longestConsecutive

Array/LongestConsecutiveSequence.py:105–150  ·  view source on GitHub ↗

:type nums: List[int] :rtype: int

(self, nums)

Source from the content-addressed store, hash-verified

103
104class Solution(object):
105 def longestConsecutive(self, nums):
106 """
107 :type nums: List[int]
108 :rtype: int
109 """
110 numx = set(nums)
111
112 maxes = 0
113
114 for i in nums:
115 if i-1 not in numx:
116 x = i
117 currentMaxes = 1
118 while 1:
119 if x+1 in numx:
120 x += 1
121 currentMaxes += 1
122 continue
123 else:
124 maxes = max(maxes, currentMaxes)
125 break
126 return maxes
127
128 # sorted.
129 # if not nums:
130 # return 0
131
132 # nums.sort()
133
134 # currentNums = nums[0]
135 # result = []
136 # currentMax = 1
137
138 # for i in nums[1:]:
139 # if i == currentNums + 1:
140 # currentMax += 1
141 # currentNums = i
142 # elif i == currentNums:
143 # pass
144 # else:
145 # result.append(currentMax)
146 # currentMax = 1
147 # currentNums = i
148 # result.append(currentMax)
149
150 # return max(result)
151

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected