Skip to content

Commit

Permalink
2020-01-23
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Jan 24, 2020
1 parent ffe1708 commit 16f6617
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
9 changes: 1 addition & 8 deletions 0905.按奇偶排序数组/0905-按奇偶排序数组.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,4 @@ def sortArrayByParity(self, A):
:type A: List[int]
:rtype: List[int]
"""
odd, even = [], []
for i in A:
if i % 2:
odd.append(i)
else:
even.append(i)

return even + odd
return sorted(A, key = lambda x:x % 2)
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# -*- coding: utf-8 -*-
class Solution(object):
def minAddToMakeValid(self, S):
"""
:type S: str
:rtype: int
"""
dic = {"(":"", ")" : "("}
res = len(S)
temp = [None]
for item in S:
# print item
if temp[-1] != dic[item.encode('utf-8')]:
temp.append(item)
stack = []
dic = {"(":")", "{":"}", "[":"]"}
for ch in S:
if stack and stack[-1] in dic and dic[stack[-1]] == ch:
stack.pop()
else:
temp = temp[:-1]
return len(temp) -1


stack.append(ch)
return len(stack)

0 comments on commit 16f6617

Please sign in to comment.