Skip to content

Commit 96b35ca

Browse files
authored
Update minimum-number-of-operations-to-make-array-continuous.py
1 parent 023894f commit 96b35ca

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Python/minimum-number-of-operations-to-make-array-continuous.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
# Time: O(nlogn)
2-
# Space: O(n)
2+
# Space: O(1)
33

44
class Solution(object):
55
def minOperations(self, nums):
66
"""
77
:type nums: List[int]
88
:rtype: int
99
"""
10+
def unique(nums):
11+
left = 0
12+
for right in xrange(1, len(nums)):
13+
if nums[left] != nums[right]:
14+
left += 1
15+
nums[left] = nums[right]
16+
return left
17+
18+
def erase(nums, i):
19+
while len(nums) > i+1:
20+
nums.pop()
21+
1022
n = len(nums)
11-
nums = sorted(set(nums))
23+
nums.sort()
24+
erase(nums, unique(nums))
1225
result = l = 0
1326
for i in xrange(len(nums)):
1427
if nums[i] <= nums[i-l]+n-1:

0 commit comments

Comments
 (0)