From 16f66172743935e0d20768712ad38eedfb61f80d Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 23 Jan 2020 23:58:32 -0500 Subject: [PATCH] 2020-01-23 --- ...22\345\272\217\346\225\260\347\273\204.py" | 9 +-------- ...00\345\260\221\346\267\273\345\212\240.py" | 19 +++++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git "a/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" index 626a868..43e1110 100644 --- "a/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" +++ "b/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -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 \ No newline at end of file + return sorted(A, key = lambda x:x % 2) \ No newline at end of file diff --git "a/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" "b/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" index f20e3b0..94e321e 100644 --- "a/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" +++ "b/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" @@ -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 - - \ No newline at end of file + stack.append(ch) + return len(stack) \ No newline at end of file