Skip to content

Commit

Permalink
Update russian-doll-envelopes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Jun 7, 2016
1 parent f773e19 commit 5b3f126
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Python/russian-doll-envelopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Solution(object):
def maxEnvelopes(self, envelopes):
"""
:type envelopes: max_envelopest[max_envelopest[int]]
:type envelopes: List[List[int]]
:rtype: int
"""
def insert(target):
Expand All @@ -32,15 +32,9 @@ def insert(target):
else:
result[left] = target

envelopes.sort()
envelopes.sort(lambda x, y: y[1] - x[1] if x[0] == y[0] \
else x[0] - y[0])
result, i = [], 0
while i < len(envelopes):
w, same_count = envelopes[i][0], 0
while i < len(envelopes) and envelopes[i][0] == w:
i += 1
same_count += 1

for j in reversed(xrange(i-same_count, i)): # Insert from larger h.
insert(envelopes[j][1])

for envelope in envelopes:
insert(envelope[1])
return len(result)

0 comments on commit 5b3f126

Please sign in to comment.