Skip to content

Commit d19f098

Browse files
authored
Create minimum-deletions-to-make-array-beautiful.py
1 parent 9ca78ad commit d19f098

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def minDeletion(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: int
10+
"""
11+
result = 0
12+
for i in xrange(len(nums)-1):
13+
result += int(i%2 == result%2 and nums[i] == nums[i+1])
14+
return result+(len(nums)-result)%2

0 commit comments

Comments
 (0)