diff --git "a/Week_01/20.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" "b/Week_01/20.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 00000000..cfae94dd --- /dev/null +++ "b/Week_01/20.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,21 @@ +# +# @lc app=leetcode.cn id=20 lang=python3 +# +# [20] 有效的括号 +# + +# @lc code=start +class Solution: + def isValid(self, s: str) -> bool: + if len(s) % 2: return False + smap = {'(':')', '{': '}', '[': ']', '?': '?'} + stack = ['?'] + for c in s: + if c in smap: + stack.append(c) + elif smap[stack.pop()] != c: + return False + return stack == ['?'] + +# @lc code=end + diff --git "a/Week_01/88.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204.py" "b/Week_01/88.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 00000000..83c02f16 --- /dev/null +++ "b/Week_01/88.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,24 @@ +# +# @lc app=leetcode.cn id=88 lang=python3 +# +# [88] 合并两个有序数组 +# + +# @lc code=start +class Solution: + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + """ + Do not return anything, modify nums1 in-place instead. + """ + p, p1, p2 = m + n - 1, m - 1, n - 1 + while p1 >= 0 and p2 >= 0: + if nums1[p1] > nums2[p2]: + nums1[p] = nums1[p1] + p1 -= 1 + else: + nums1[p] = nums2[p2] + p2 -= 1 + p -= 1 + nums1[:p2 + 1] = nums2[:p2 + 1] +# @lc code=end +