From bd5f1936d454dafb5ae80ab02db4641af43930b5 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 18 Nov 2020 13:50:42 -0500 Subject: [PATCH 01/19] 2020-11-18 --- ...25\350\257\215\346\220\234\347\264\242.py" | 47 +++++----- ...02\347\233\264\351\201\215\345\216\206.py" | 32 +++++++ ...17\346\234\272\345\205\203\347\264\240.py" | 67 ++++++++++++++ ...\346\225\260\347\233\270\345\212\240II.py" | 89 ++++++++++++------- ...11\347\242\216\347\263\226\346\236\234.py" | 44 +++++++++ ...75\347\232\204\350\267\257\345\276\204.py" | 21 ++--- ...02\345\272\217\351\201\215\345\216\206.py" | 28 ++++++ ...60\351\223\201\347\263\273\347\273\237.py" | 48 ++++++++++ 8 files changed, 308 insertions(+), 68 deletions(-) create mode 100644 "0314.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206/0314-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206.py" create mode 100644 "0380.\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240/0380-\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240.py" create mode 100644 "0723.\347\262\211\347\242\216\347\263\226\346\236\234/0723-\347\262\211\347\242\216\347\263\226\346\236\234.py" create mode 100644 "0987.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206/0987-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206.py" create mode 100644 "1396.\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237/1396-\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237.py" diff --git "a/0079.\345\215\225\350\257\215\346\220\234\347\264\242/0079-\345\215\225\350\257\215\346\220\234\347\264\242.py" "b/0079.\345\215\225\350\257\215\346\220\234\347\264\242/0079-\345\215\225\350\257\215\346\220\234\347\264\242.py" index 77cc5f1..d3cdcde 100644 --- "a/0079.\345\215\225\350\257\215\346\220\234\347\264\242/0079-\345\215\225\350\257\215\346\220\234\347\264\242.py" +++ "b/0079.\345\215\225\350\257\215\346\220\234\347\264\242/0079-\345\215\225\350\257\215\346\220\234\347\264\242.py" @@ -7,34 +7,31 @@ def exist(self, board, word): """ if not board or not board[0]: return False - if not word: - return True - - self.res = False + + m, n = len(board), len(board[0]) dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - def dfs(start, x0, y0): - if start == len(word) - 1: + self.res = False + def dfs(word_idx, x0, y0): + # print word_idx + if word_idx >= len(word): self.res = True - return - visited.add((x0, y0)) - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - # print x, y - if 0 <= x < m and 0 <= y < n and (x, y) not in visited and board[x][y] == word[start + 1] and not self.res: - visited.add((x, y)) - dfs(start + 1, x, y) - visited.remove((x, y)) - - m, n = len(board), len(board[0]) - # print m * n, len(word) + return + if not self.res: + for k in range(len(dx)): + x1 = x0 + dx[k] + y1 = y0 + dy[k] + + if 0 <= x1 < m and 0 <= y1 < n and board[x1][y1] == word[word_idx]: + temp = board[x1][y1] + board[x1][y1] = -1 + dfs(word_idx + 1, x1, y1) + board[x1][y1] = temp for i in range(m): for j in range(n): if board[i][j] == word[0]: - visited = set() - dfs(0, i, j) - if self.res: - return True - return False \ No newline at end of file + temp = board[i][j] + board[i][j] = 0 + dfs(1, i, j) + board[i][j] = temp + return self.res \ No newline at end of file diff --git "a/0314.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206/0314-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206.py" "b/0314.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206/0314-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206.py" new file mode 100644 index 0000000..4fc5d0e --- /dev/null +++ "b/0314.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206/0314-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\347\233\264\351\201\215\345\216\206.py" @@ -0,0 +1,32 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def verticalOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + if not root: + return None + + from collections import defaultdict, deque + + queue = deque([(0, root)]) + res = defaultdict(list) # key is column idx in the result, value is all elements that have that idx + while queue: + col_idx, node = queue.popleft() + + res[col_idx].append(node.val) + + if node.left: + queue.append((col_idx - 1, node.left)) + if node.right: + queue.append((col_idx + 1, node.right)) + + return [val for idx, val, in sorted(res.items(), key=lambda x: x[0])] + diff --git "a/0380.\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240/0380-\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240.py" "b/0380.\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240/0380-\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240.py" new file mode 100644 index 0000000..49b33ad --- /dev/null +++ "b/0380.\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240/0380-\345\270\270\346\225\260\346\227\266\351\227\264\346\217\222\345\205\245\343\200\201\345\210\240\351\231\244\345\222\214\350\216\267\345\217\226\351\232\217\346\234\272\345\205\203\347\264\240.py" @@ -0,0 +1,67 @@ +import random +class RandomizedSet(object): + + def __init__(self): + """ + Initialize your data structure here. + """ + self.dic = dict() + self.l = [] + + def insert(self, val): + """ + Ins +from typing import ValuesViewerts a value to the set. Returns true if the set did not already contain the specified element. + :type val: int + :rtype: bool + """ + if val in self.dic: + return False + else: + self.l.append(val) + self.dic[val] = len(self.l) - 1 + return True + + + def remove(self, val): + """ + Removes a value from the set. Returns true if the set contained the specified element. + :type val: int + :rtype: bool + """ + + if val not in self.dic: + return False + else: + # get the index of the element to be delted + index = self.dic[val] + self.dic.pop(val) + + # swap the element with the last element + self.l[index], self.l[-1] = self.l[-1], self.l[index] + + if index != len(self.l) - 1: + # if swap happened, update the index of element that got swapped + self.dic[self.l[index]] = index + + self.l.pop() + + return True + + + + def getRandom(self): + """ + Get a random element from the set. + :rtype: int + """ + + return random.choice(self.l) + + + +# Your RandomizedSet object will be instantiated and called as such: +# obj = RandomizedSet() +# param_1 = obj.insert(val) +# param_2 = obj.remove(val) +# param_3 = obj.getRandom() \ No newline at end of file diff --git "a/0445.\344\270\244\346\225\260\347\233\270\345\212\240II/0445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" "b/0445.\344\270\244\346\225\260\347\233\270\345\212\240II/0445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" index 4fbe278..6ce5ec1 100644 --- "a/0445.\344\270\244\346\225\260\347\233\270\345\212\240II/0445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" +++ "b/0445.\344\270\244\346\225\260\347\233\270\345\212\240II/0445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" @@ -11,39 +11,68 @@ def addTwoNumbers(self, l1, l2): :type l2: ListNode :rtype: ListNode """ - s1, s2 = [], [] - while l1: - s1.append(l1.val) + def getLinkedListLength(l): + length = 0 + while l: + l = l.next + length += 1 + return length + + def printLL(node): + l = [] + while node: + l.append(node.val) + node = node.next + print(l) + + def reverseLL(node): + if not node or not node.next: + return node + p = reverseLL(node.next) + node.next.next = node + node.next = None + return p + + length1 = getLinkedListLength(l1) + length2 = getLinkedListLength(l2) + + if length1 < length2: + l1, l2 = l2, l1 + length1, length2 = length2, length1 + + dummy = ListNode(-1) + p = dummy + + n = length1 - length2 + while n: + p.next = ListNode(l1.val) l1 = l1.next - + p = p.next + n -= 1 + while l2: - s2.append(l2.val) + p.next = ListNode(l1.val + l2.val) + p = p.next + l1 = l1.next l2 = l2.next - + + + dummy.next = reverseLL(dummy.next) + + p = dummy.next carry = 0 - cur = ListNode(-1) - while s1 or s2: - value = carry - if s1: - value += s1.pop() - if s2: - value += s2.pop() - - carry = value > 9 - value %= 10 - - cur.val = value - pre = ListNode(-1) - pre.next = cur - cur = pre - - if carry: #处理可能的进位 - pre.val = 1 - return pre - - return pre.next + pre = dummy + while p: + p.val += carry + if p.val > 9: + p.val -= 10 + carry = 1 + else: + carry = 0 + p = p.next + pre = pre.next - - + if carry: + pre.next = ListNode(1) - \ No newline at end of file + return reverseLL(dummy.next) diff --git "a/0723.\347\262\211\347\242\216\347\263\226\346\236\234/0723-\347\262\211\347\242\216\347\263\226\346\236\234.py" "b/0723.\347\262\211\347\242\216\347\263\226\346\236\234/0723-\347\262\211\347\242\216\347\263\226\346\236\234.py" new file mode 100644 index 0000000..e624702 --- /dev/null +++ "b/0723.\347\262\211\347\242\216\347\263\226\346\236\234/0723-\347\262\211\347\242\216\347\263\226\346\236\234.py" @@ -0,0 +1,44 @@ +class Solution(object): + def candyCrush(self, board): + """ + :type board: List[List[int]] + :rtype: List[List[int]] + """ + if not board or not board[0]: + return None + + m, n = len(board), len(board[0]) + # 1. crush stage + + # flag all elements to be crushed + todo = 0 + for i in range(m): + for j in range(n - 2): + if board[i][j] and abs(board[i][j]) == abs(board[i][j + 1]) == abs(board[i][j + 2]): + board[i][j] = board[i][j + 1] = board[i][j + 2] = -abs(board[i][j]) + todo = 1 + + for j in range(n): + for i in range(m - 2): + if board[i][j] and abs(board[i][j]) == abs(board[i + 1][j]) == abs(board[i + 2][j]): + board[i][j] = board[i + 1][j] = board[i + 2][j] = -abs(board[i][j]) + todo = 1 + # print board, todo + # 2. gravity stage + for j in range(n): + lo, hi = m - 1, m - 1 + while hi >= 0: + while hi >= 0 and board[hi][j] < 0: + hi -= 1 + + if hi >= 0: + board[lo][j] = board[hi][j] + lo -= 1 + hi -= 1 + + while lo >= 0: + board[lo][j] = 0 + lo -= 1 + + # recursively call this function if more crush is necessary + return self.candyCrush(board) if todo else board \ No newline at end of file diff --git "a/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" "b/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" index 7a1a2ea..f53fbe5 100644 --- "a/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" +++ "b/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" @@ -4,19 +4,14 @@ def allPathsSourceTarget(self, graph): :type graph: List[List[int]] :rtype: List[List[int]] """ - res = list() n = len(graph) - def dfs(start, tmp): - if graph[start] == [] and start == n - 1:#没有下一个节点 - tmp += graph[start] - res.append(tmp[:]) + visited = set() + def dfs(cur_node, path): + if cur_node == n - 1: + res.append(path[:]) return - - l = graph[start] - for node in l: - tmp.append(node) - dfs(node, tmp) - tmp.pop() - - dfs(0, [0]) + for next_node in graph[cur_node]: + dfs(next_node, path + [next_node]) + res = [] + dfs(0, [0]) return res \ No newline at end of file diff --git "a/0987.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206/0987-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206.py" "b/0987.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206/0987-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..d3790e7 --- /dev/null +++ "b/0987.\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206/0987-\344\272\214\345\217\211\346\240\221\347\232\204\345\236\202\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def verticalTraversal(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import defaultdict + dic = defaultdict(list) + def dfs(root, x, y): + if root: + dic[x].append((y, root.val)) + dfs(root.left, x - 1, y + 1) + dfs(root.right, x + 1, y + 1) + + dfs(root, 0, 0) + res = [] + for k in sorted(dic.keys()): + x = [pair[1] for pair in sorted(dic[k])] + res.append(x) + + return res \ No newline at end of file diff --git "a/1396.\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237/1396-\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237.py" "b/1396.\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237/1396-\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237.py" new file mode 100644 index 0000000..a54cba9 --- /dev/null +++ "b/1396.\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237/1396-\350\256\276\350\256\241\345\234\260\351\223\201\347\263\273\347\273\237.py" @@ -0,0 +1,48 @@ +class UndergroundSystem(object): + + def __init__(self): + self.check_in_history = dict() # key is id + stationName, val is t + self.StationTraverlTime = dict() + def checkIn(self, id, stationName, t): + """ + :type id: int + :type stationName: str + :type t: int + :rtype: None + """ + self.check_in_history[str(id)] = [stationName, t] + + + def checkOut(self, id, stationName, t): + """ + :type id: int + :type stationName: str + :type t: int + :rtype: None + """ + start_station, start_time = self.check_in_history[str(id)] + self.check_in_history.pop(str(id)) + time_spent = t - start_time + key = start_station + "#" + stationName + if key not in self.StationTraverlTime: + self.StationTraverlTime[key] = [time_spent,1] + else: + self.StationTraverlTime[key][0] += time_spent + self.StationTraverlTime[key][1] += 1 + + + def getAverageTime(self, startStation, endStation): + """ + :type startStation: str + :type endStation: str + :rtype: float + """ + key = startStation + "#" + endStation + return self.StationTraverlTime[key][0] * 1.0 / self.StationTraverlTime[key][1] + + +# Your UndergroundSystem object will be instantiated and called as such: +# obj = UndergroundSystem() +# obj.checkIn(id,stationName,t) +# obj.checkOut(id,stationName,t) +# param_3 = obj.getAverageTime(startStation,endStation) \ No newline at end of file From bea30f953cb5e10efedbd6785f4c4b11cf835074 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 10 Feb 2021 21:59:24 -0500 Subject: [PATCH 02/19] 2021-02-10 --- ...0146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/0146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/0146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" "b/0146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/0146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" index 73bc89e..c2c9139 100644 --- "a/0146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/0146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" +++ "b/0146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/0146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" @@ -15,7 +15,7 @@ def __init__(self, capacity): self.head = DLLNode(-1, -1, None, None) self.tail = DLLNode(-1, -1, self.head, None) self.head.next = self.tail - self.dic = dict() + self.dic = dict() def get(self, key): """ From e29a90736699c3c4c88ef1541cf63b56bbcb210e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 10 Feb 2021 22:08:05 -0500 Subject: [PATCH 03/19] 2021-02-10 --- ...23\266\350\241\214\347\232\204\351\222\261.py" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "1716.\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261/1716-\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261.py" diff --git "a/1716.\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261/1716-\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261.py" "b/1716.\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261/1716-\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261.py" new file mode 100644 index 0000000..e1090ee --- /dev/null +++ "b/1716.\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261/1716-\350\256\241\347\256\227\345\212\233\346\211\243\351\223\266\350\241\214\347\232\204\351\222\261.py" @@ -0,0 +1,15 @@ +class Solution(object): + def totalMoney(self, n): + """ + :type n: int + :rtype: int + """ + day_cnt = 1 + summ = 0 + for i in range(1, n + 1): + if i % 7 == 1: + day_cnt = i // 7 + 1 + summ += day_cnt + day_cnt += 1 + + return summ From 2db34c8c7a3f28a727f42f669acd6d4d68311985 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 21 Feb 2021 16:53:59 -0500 Subject: [PATCH 04/19] 2021-02-21 --- ...04\346\255\243\346\225\264\346\225\260.py" | 15 +++---- ...30\345\255\227\347\254\246\344\270\262.py" | 36 +++++++++++++++++ ...22\345\205\245\346\254\241\346\225\260.py" | 39 +++++++++++++++++++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 "1540.K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262/1540-K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262.py" create mode 100644 "1541.\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1541-\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260.py" diff --git "a/1539.\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260/1539-\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260.py" "b/1539.\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260/1539-\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260.py" index 4572955..96aaa68 100644 --- "a/1539.\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260/1539-\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260.py" +++ "b/1539.\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260/1539-\347\254\254k\344\270\252\347\274\272\345\244\261\347\232\204\346\255\243\346\225\264\346\225\260.py" @@ -5,10 +5,11 @@ def findKthPositive(self, arr, k): :type k: int :rtype: int """ - cnt = 0 - s = set(arr) - for i in range(1, max(arr) + k + 1): - if i not in s: - cnt += 1 - if cnt == k: - return i \ No newline at end of file + arr = set(arr) + num = 1 + while k: + if num not in arr: + k -= 1 + + num += 1 + return num - 1 \ No newline at end of file diff --git "a/1540.K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262/1540-K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262.py" "b/1540.K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262/1540-K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b474363 --- /dev/null +++ "b/1540.K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262/1540-K\346\254\241\346\223\215\344\275\234\350\275\254\345\217\230\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,36 @@ +class Solution(object): + def canConvertString(self, s, t, k): + """ + :type s: str + :type t: str + :type k: int + :rtype: bool + """ + from collections import defaultdict + + if not s or not t or len(s) != len(t): + return False + + d = list() + + for i in range(len(s)): + if s[i] < t[i]: + d.append(ord(t[i]) - ord(s[i])) + elif s[i] > t[i]: + d.append(26 - ord(s[i]) + ord(t[i])) + + d.sort() + res = 0 + pre = None + for distance in d: + if not pre or pre != distance: + res = max(res, distance) + pre = distance + pre_cnt = 1 + else: + res = max(res, 26 * pre_cnt + distance) + pre_cnt += 1 + if res > k: + return False + return True + diff --git "a/1541.\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1541-\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260.py" "b/1541.\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1541-\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260.py" new file mode 100644 index 0000000..b818001 --- /dev/null +++ "b/1541.\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1541-\345\271\263\350\241\241\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260.py" @@ -0,0 +1,39 @@ +class Solution(object): + def minInsertions(self, s): + """ + :type s: str + :rtype: int + """ + left_cnt, cons_right_cnt = 0, 0 + res = 0 + for ch in s: + if ch == "(": + if cons_right_cnt: + if cons_right_cnt % 2: # add 1 to make it even + res += 1 + cons_right_cnt += 1 + pair = min(left_cnt, cons_right_cnt // 2) # build all possible pairs + left_cnt -= pair + cons_right_cnt -= pair * 2 + + if cons_right_cnt: # if two or more ) left + res += cons_right_cnt // 2 # add "(" every 2 ) + cons_right_cnt = 0 + left_cnt += 1 + else: + cons_right_cnt += 1 + + if cons_right_cnt: + if cons_right_cnt % 2: # add 1 to make it even + res += 1 + cons_right_cnt += 1 + pair = min(left_cnt, cons_right_cnt // 2) # build all possible pairs + left_cnt -= pair + cons_right_cnt -= pair * 2 + + if cons_right_cnt: # if two or more ) left + res += cons_right_cnt // 2 # add "(" every 2 ) + cons_right_cnt = 0 + + res += left_cnt * 2 # add 2 ) every ( + return res \ No newline at end of file From d496b22126dc940b3b030e4f15b8331ba47e045a Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 2 Mar 2021 19:34:20 -0500 Subject: [PATCH 05/19] 2021-03-02 --- ...06\345\255\227\347\254\246\344\270\262.py" | 5 ++-- ...5\347\232\204\347\254\254K\344\275\215.py" | 23 +++++-------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git "a/1544.\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262/1544-\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262.py" "b/1544.\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262/1544-\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262.py" index 24cae60..792fb4a 100644 --- "a/1544.\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262/1544-\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262.py" +++ "b/1544.\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262/1544-\346\225\264\347\220\206\345\255\227\347\254\246\344\270\262.py" @@ -6,8 +6,9 @@ def makeGood(self, s): """ stack = [] for ch in s: - if not stack or abs(ord(stack[-1]) - ord(ch)) != 32: + if not stack or abs(ord(ch) - ord(stack[-1])) != 32: stack.append(ch) else: stack.pop() - return "".join(ch for ch in stack) \ No newline at end of file + + return "".join(stack) \ No newline at end of file diff --git "a/1545.\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215/1545-\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215.py" "b/1545.\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215/1545-\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215.py" index 095f097..296cb74 100644 --- "a/1545.\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215/1545-\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215.py" +++ "b/1545.\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215/1545-\346\211\276\345\207\272\347\254\254N\344\270\252\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254K\344\275\215.py" @@ -5,21 +5,10 @@ def findKthBit(self, n, k): :type k: int :rtype: str """ - - def invert(s): - res = "" - for ch in s: - if ch == "0": - res += "1" - else: - res += "0" - return res - - i = 1 + # len 1锛 3锛 7锛 15 ... L(n) = 2 * (L(n - 1)) + 1 + # if k == 2 * (n - 2) + 2: return 1 s = "0" - while i < n: - s = s + "1" + invert(s)[::-1] - i += 1 - if k - 1 < len(s): - return s[k - 1] - return s[k - 1] + while len(s) <= k: + s = s + "1" + "".join([str(1 - int(ch)) for ch in s])[::-1] + # print (s) + return s[k - 1] \ No newline at end of file From db1db7d976d39eb91ccf5e1297231d0f4c8b0ce3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 9 Mar 2021 22:12:59 -0500 Subject: [PATCH 06/19] 2021-03-09 --- ...\275\215\345\210\206\351\232\224\346\225\260.py" | 13 ++++++++----- ...\211\271\346\256\212\344\275\215\347\275\256.py" | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 "1582.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256/1582-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256.py" diff --git "a/1556.\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260/1556-\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260.py" "b/1556.\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260/1556-\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260.py" index 284c19e..c84dd2b 100644 --- "a/1556.\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260/1556-\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260.py" +++ "b/1556.\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260/1556-\345\215\203\344\275\215\345\210\206\351\232\224\346\225\260.py" @@ -4,10 +4,13 @@ def thousandSeparator(self, n): :type n: int :rtype: str """ - s = str(n)[::-1] res = "" - for i in range(len(s)): - res += s[i] - if i % 3 == 2 and i != len(s) - 1: + cnt = 0 + for digit in str(n)[::-1]: + res += digit + cnt += 1 + if cnt == 3: + cnt = 0 res += "." - return res[::-1] \ No newline at end of file + + return res[::-1].strip(".") \ No newline at end of file diff --git "a/1582.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256/1582-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256.py" "b/1582.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256/1582-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256.py" new file mode 100644 index 0000000..12c3357 --- /dev/null +++ "b/1582.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256/1582-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\347\211\271\346\256\212\344\275\215\347\275\256.py" @@ -0,0 +1,12 @@ +class Solution(object): + def numSpecial(self, mat): + """ + :type mat: List[List[int]] + :rtype: int + """ + # 鎵惧嚭鎵鏈夋弧瓒虫潯浠剁殑琛屽拰鍒 + possible_rows = [i for i, row in enumerate(mat) if sum(row) == 1] + possible_cols = [i for i, col in enumerate(zip(*mat)) if sum(col) == 1] + + # 鍦ㄦ弧瓒虫潯浠剁殑琛屽拰鍒楅噷缁熻鍊间负1鐨勭偣 + return sum([mat[i][j] for i in possible_rows for j in possible_cols]) \ No newline at end of file From 477c31753a574709eec1b4cfaf283de6d4404b92 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 10 Mar 2021 16:14:03 -0500 Subject: [PATCH 07/19] 2021-03-10 --- ...03\347\232\204\346\234\213\345\217\213.py" | 32 +++++++++++ ...00\345\260\217\350\264\271\347\224\250.py" | 54 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 "1583.\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213/1583-\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213.py" create mode 100644 "1584.\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250/1584-\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250.py" diff --git "a/1583.\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213/1583-\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213.py" "b/1583.\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213/1583-\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213.py" new file mode 100644 index 0000000..b6db322 --- /dev/null +++ "b/1583.\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213/1583-\347\273\237\350\256\241\344\270\215\345\274\200\345\277\203\347\232\204\346\234\213\345\217\213.py" @@ -0,0 +1,32 @@ +class Solution(object): + def unhappyFriends(self, n, preferences, pairs): + """ + :type n: int + :type preferences: List[List[int]] + :type pairs: List[List[int]] + :rtype: int + """ + # 寤虹珛浜插瘑搴︾煩闃碉紝prefer_degrees[i][j]鍗充负 i 瀵 j 鐨勪翰瀵嗗害 + prefer_degrees = [[-n-1 for _ in range(n)] for _ in range(n)] + for i, preference in enumerate(preferences): + for degree, j in enumerate(preference): + prefer_degrees[i][j] = -degree + + # 寤虹珛閰嶅瀛楀吀锛岀粰瀹歺锛 ppl2friends[x]鍗充负 x 鍒嗛厤鐨勬湅鍙 + ppl2friends = dict() + for x, y in pairs: + ppl2friends[x] = y + ppl2friends[y] = x + + def isUnhappy(x): + # 鍒ゅ畾 x 鏄惁蹇箰 + y = ppl2friends[x] + + for u in range(n): + v = ppl2friends[u] + if x != u and prefer_degrees[x][u] > prefer_degrees[x][y] and \ + prefer_degrees[u][x] > prefer_degrees[u][v]: + return 1 + return 0 + + return sum([isUnhappy(i) for i in range(n)]) \ No newline at end of file diff --git "a/1584.\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250/1584-\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250.py" "b/1584.\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250/1584-\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250.py" new file mode 100644 index 0000000..c140670 --- /dev/null +++ "b/1584.\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250/1584-\350\277\236\346\216\245\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\350\264\271\347\224\250.py" @@ -0,0 +1,54 @@ + +class UnionFindSet(object): + def __init__(self, n): + # m, n = len(grid), len(grid[0]) + self.roots = [i for i in range(n + 1)] + self.rank = [0 for i in range(n + 1)] + self.count = n + + def find(self, member): + tmp = [] + while member != self.roots[member]: + tmp.append(member) + member = self.roots[member] + for root in tmp: + self.roots[root] = member + return member + + def union(self, p, q): + parentP = self.find(p) + parentQ = self.find(q) + if parentP != parentQ: + if self.rank[parentP] > self.rank[parentQ]: + self.roots[parentQ] = parentP + elif self.rank[parentP] < self.rank[parentQ]: + self.roots[parentP] = parentQ + else: + self.roots[parentQ] = parentP + self.rank[parentP] -= 1 + self.count -= 1 + +class Solution(object): + def minCostConnectPoints(self, points): + """ + :type points: List[List[int]] + :rtype: int + """ + from heapq import * + queue = [] + res = 0 + n = len(points) + for i in range(n): + for j in range(i + 1, n): + d = abs(points[i][0] - points[j][0]) + abs(points[i][1] - points[j][1]) + heappush(queue, (d, i, j)) + + ufs = UnionFindSet(n) + while ufs.count > 1: + d, i, j = heappop(queue) + + if ufs.find(i) != ufs.find(j): + res += d + ufs.union(i, j) + + return res \ No newline at end of file From 10422e13aeb489750c98f3f85f13f9a835bbf349 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 11 Mar 2021 22:38:03 -0500 Subject: [PATCH 08/19] 2021-03-11 --- ...\211\347\232\204\351\227\256\345\217\267.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "1576.\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267/1576-\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267.py" diff --git "a/1576.\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267/1576-\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267.py" "b/1576.\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267/1576-\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267.py" new file mode 100644 index 0000000..6ab4307 --- /dev/null +++ "b/1576.\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267/1576-\346\233\277\346\215\242\346\211\200\346\234\211\347\232\204\351\227\256\345\217\267.py" @@ -0,0 +1,17 @@ +class Solution(object): + def modifyString(self, s): + """ + :type s: str + :rtype: str + """ + res = [] + for i, ch in enumerate(s): + if ch == "?": + for new in "abc": + if ((i and res[-1] != new) or not i) and ((i < len(s) - 1 and s[i + 1] != new) or i == len(s) - 1): + res.append(new) + break + else: + res.append(ch) + + return "".join(res) \ No newline at end of file From a07c800610f35b80355796a618ea73aa431ce96e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 13 Mar 2021 21:21:46 -0500 Subject: [PATCH 09/19] 2021-03-13 --- ...27\346\220\234\351\233\206\345\231\250.py" | 13 +++++ ...47\346\211\277\351\241\272\345\272\217.py" | 50 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 "1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" create mode 100644 "1600.\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217/1600-\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217.py" diff --git "a/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" "b/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" new file mode 100644 index 0000000..ecf5e8f --- /dev/null +++ "b/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" @@ -0,0 +1,13 @@ +class Solution(object): + def minOperations(self, logs): + """ + :type logs: List[str] + :rtype: int + """ + steps = 0 + for log in logs: + if log == "../" and steps: + steps -= 1 + elif log not in ["../", "./"]: + steps += 1 + return steps \ No newline at end of file diff --git "a/1600.\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217/1600-\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217.py" "b/1600.\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217/1600-\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217.py" new file mode 100644 index 0000000..a60f5a1 --- /dev/null +++ "b/1600.\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217/1600-\347\232\207\344\275\215\347\273\247\346\211\277\351\241\272\345\272\217.py" @@ -0,0 +1,50 @@ +class ThroneInheritance(object): + def __init__(self, kingName): + """ + :type kingName: str + """ + from collections import defaultdict + self.par2child = defaultdict(list) + self.kingName = kingName + self.deaths = set() + + def birth(self, parentName, childName): + """ + :type parentName: str + :type childName: str + :rtype: None + """ + self.par2child[parentName].append(childName) + + + def death(self, name): + """ + :type name: str + :rtype: None + """ + self.deaths.add(name) + + def getInheritanceOrder(self): + """ + :rtype: List[str] + """ + return self.preorder(self.kingName) + + def preorder(self, cur): + res = [] + if cur not in self.deaths: + res.append(cur) + + for child in self.par2child[cur]: + res += self.preorder(child) + return res + + + + + +# Your ThroneInheritance object will be instantiated and called as such: +# obj = ThroneInheritance(kingName) +# obj.birth(parentName,childName) +# obj.death(name) +# param_3 = obj.getInheritanceOrder() \ No newline at end of file From ad59c582c28e5eb6f103b6c29b1a9cdf3442954b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 14 Mar 2021 23:37:36 -0400 Subject: [PATCH 10/19] 2021-03-14 --- ...34\350\275\246\347\263\273\347\273\237.py" | 24 ++++++++++++++++ ...11\346\254\241\347\232\204\344\272\272.py" | 28 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 "1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" create mode 100644 "1604.\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272/1604-\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272.py" diff --git "a/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" "b/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" new file mode 100644 index 0000000..3259d52 --- /dev/null +++ "b/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" @@ -0,0 +1,24 @@ +class ParkingSystem(object): + + def __init__(self, big, medium, small): + """ + :type big: int + :type medium: int + :type small: int + """ + self.space = [0, big, medium, small] + + def addCar(self, carType): + """ + :type carType: int + :rtype: bool + """ + if self.space[carType]: + self.space[carType] -= 1 + return True + return False + + +# Your ParkingSystem object will be instantiated and called as such: +# obj = ParkingSystem(big, medium, small) +# param_1 = obj.addCar(carType) \ No newline at end of file diff --git "a/1604.\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272/1604-\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272.py" "b/1604.\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272/1604-\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272.py" new file mode 100644 index 0000000..75da20e --- /dev/null +++ "b/1604.\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272/1604-\350\255\246\345\221\212\344\270\200\345\260\217\346\227\266\345\206\205\344\275\277\347\224\250\347\233\270\345\220\214\345\221\230\345\267\245\345\215\241\345\244\247\344\272\216\347\255\211\344\272\216\344\270\211\346\254\241\347\232\204\344\272\272.py" @@ -0,0 +1,28 @@ +class Solution(object): + def alertNames(self, keyName, keyTime): + """ + :type keyName: List[str] + :type keyTime: List[str] + :rtype: List[str] + """ + from collections import defaultdict + name2time = defaultdict(list) + + res = set() + + def timeToMinutes(time): + # convert 10:05 to 605 + splitted_time = time.split(":") + return 60 * int(splitted_time[0]) + int(splitted_time[1]) + + pairs = sorted(zip(keyName, keyTime), key = lambda x: (x[0], x[1])) + + for name, time in pairs: + if name not in res: + name2time[name].append(time) + if len(name2time[name]) >= 3 and 0 <= timeToMinutes(time) - timeToMinutes(name2time[name][-3]) <= 60: + res.add(name) + + return sorted(list(res)) + + From 1b4af60e1fdb96c81c035920cc999718e5bd8a77 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 16 Mar 2021 23:49:11 -0400 Subject: [PATCH 11/19] 2021-03-16 --- ...5\214\345\245\227\346\267\261\345\272\246.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" diff --git "a/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" "b/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" new file mode 100644 index 0000000..6944a1f --- /dev/null +++ "b/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" @@ -0,0 +1,16 @@ +class Solution(object): + def maxDepth(self, s): + """ + :type s: str + :rtype: int + """ + depth = 0 + res = 0 + for ch in s: + if ch == "(": + depth += 1 + res = max(res, depth) + elif ch == ")": + depth -= 1 + + return res \ No newline at end of file From ad99e6d472ff9e489b7364c43a9011e983dffa79 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 4 Apr 2021 23:40:45 -0400 Subject: [PATCH 12/19] 2021-04-04 --- ...345\215\207\345\272\217\346\216\222\345\272\217.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "1636.\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217/1636-\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217.py" diff --git "a/1636.\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217/1636-\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217.py" "b/1636.\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217/1636-\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217.py" new file mode 100644 index 0000000..3f193e2 --- /dev/null +++ "b/1636.\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217/1636-\346\214\211\347\205\247\351\242\221\347\216\207\345\260\206\346\225\260\347\273\204\345\215\207\345\272\217\346\216\222\345\272\217.py" @@ -0,0 +1,10 @@ +class Solution(object): + def frequencySort(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + from collections import Counter + dic = Counter(nums) + + return sorted(nums, key = lambda x:(dic[x], -x)) \ No newline at end of file From d765fcfd648b9563f529586b1eb771fc5b66362a Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 30 Apr 2021 01:14:38 -0400 Subject: [PATCH 13/19] 2021-04-30 --- ...345\215\225\347\272\277\347\250\213CPU.py" | 34 +++++++++++++++++++ ...60\345\255\227\346\200\273\345\222\214.py" | 12 +++++++ ...20\345\255\227\347\254\246\344\270\262.py" | 23 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 "1834.\345\215\225\347\272\277\347\250\213CPU/1834-\345\215\225\347\272\277\347\250\213CPU.py" create mode 100644 "1837.K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214/1837-K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214.py" create mode 100644 "1839.\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/1839-\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262.py" diff --git "a/1834.\345\215\225\347\272\277\347\250\213CPU/1834-\345\215\225\347\272\277\347\250\213CPU.py" "b/1834.\345\215\225\347\272\277\347\250\213CPU/1834-\345\215\225\347\272\277\347\250\213CPU.py" new file mode 100644 index 0000000..f62a4a2 --- /dev/null +++ "b/1834.\345\215\225\347\272\277\347\250\213CPU/1834-\345\215\225\347\272\277\347\250\213CPU.py" @@ -0,0 +1,34 @@ +class Solution(object): + def getOrder(self, tasks): + """ + :type tasks: List[List[int]] + :rtype: List[int] + """ + from heapq import * + if not tasks: + return [] + + tasks = [(pair[1], index, pair[0]) for index, pair in enumerate(tasks)] # 鎵撳寘鍘熷涓嬫爣 + tasks.sort(key = lambda x: x[2]) # 鎸夊叆闃熸椂闂存帓搴 + + next_task_id = 0 # 涓嬩竴椤硅骞茬殑宸ヤ綔 + cur_time = tasks[0][2] + min_heap = [] + res = [] + while next_task_id < len(tasks) or min_heap: + while next_task_id < len(tasks) and tasks[next_task_id][2] <= cur_time: + # 鍏ラ槦鎵鏈夊凡缁忓彲浠ュ紑濮嬪共鐨勫伐浣 + heappush(min_heap, tasks[next_task_id]) + next_task_id += 1 + + # 寮濮嬪伐浣 + if not min_heap: + # 鐩存帴璺冲埌涓嬩竴涓湁鏁堟椂闂 + cur_time = tasks[next_task_id][2] + else: + # 宸ヤ綔 + working_task = heappop(min_heap) + cur_time += working_task[0] + res.append(working_task[1]) + + return res \ No newline at end of file diff --git "a/1837.K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214/1837-K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214.py" "b/1837.K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214/1837-K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214.py" new file mode 100644 index 0000000..6c8119e --- /dev/null +++ "b/1837.K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214/1837-K\350\277\233\345\210\266\350\241\250\347\244\272\344\270\213\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\346\200\273\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution(object): + def sumBase(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + res = 0 + while n: + res += n % k + n //= k + return res \ No newline at end of file diff --git "a/1839.\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/1839-\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262.py" "b/1839.\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/1839-\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..bcbe22d --- /dev/null +++ "b/1839.\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262/1839-\346\211\200\346\234\211\345\205\203\351\237\263\346\214\211\351\241\272\345\272\217\346\216\222\345\270\203\347\232\204\346\234\200\351\225\277\345\255\220\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,23 @@ +class Solution(object): + def longestBeautifulSubstring(self, word): + """ + :type word: str + :rtype: int + """ + sequence = {"a":1, "e":2, "i":3, "o":4, "u":5} + + last_vowel = None + res = 0 + start = 0 + cur_set = set() + for i, ch in enumerate(word): + if not i or sequence[last_vowel] > sequence[ch]: + start = i + cur_set = set(ch) + else: + cur_set.add(ch) + # print(cur_set) + if ch == "u" and len(cur_set) == 5: + res = max(res, i - start + 1) + last_vowel = ch + return res From 3e9dd66cd64588de50ee9766cfc1df9882c88514 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 30 Apr 2021 01:15:14 -0400 Subject: [PATCH 14/19] 2021-04-30 --- ...\205\250\345\255\227\346\257\215\345\217\245.py" | 7 +++++++ ...\234\200\345\244\247\346\225\260\351\207\217.py" | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 "1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" create mode 100644 "1833.\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/1833-\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" diff --git "a/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" "b/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" new file mode 100644 index 0000000..502c70e --- /dev/null +++ "b/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" @@ -0,0 +1,7 @@ +class Solution(object): + def checkIfPangram(self, sentence): + """ + :type sentence: str + :rtype: bool + """ + return len(set(sentence)) == 26 \ No newline at end of file diff --git "a/1833.\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/1833-\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" "b/1833.\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/1833-\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" new file mode 100644 index 0000000..b719006 --- /dev/null +++ "b/1833.\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/1833-\351\233\252\347\263\225\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" @@ -0,0 +1,13 @@ +class Solution(object): + def maxIceCream(self, costs, coins): + """ + :type costs: List[int] + :type coins: int + :rtype: int + """ + costs.sort() + for i in range(len(costs)): + if coins < costs[i]: + return i + coins -= costs[i] + return len(costs) \ No newline at end of file From f83f39d7e52872f0c4fda2ef61cd2be9f22c7447 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 4 May 2021 15:12:29 -0400 Subject: [PATCH 15/19] 2021-05-04 --- ...260\347\273\204\351\200\222\345\242\236.cpp" | 14 ++++++++++++++ ...\260\347\273\204\351\200\222\345\242\236.py" | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 "1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.cpp" create mode 100644 "1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.py" diff --git "a/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.cpp" "b/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.cpp" new file mode 100644 index 0000000..318b613 --- /dev/null +++ "b/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.cpp" @@ -0,0 +1,14 @@ +class Solution { +public: + int minOperations(vector& nums) { + int res = 0; + for (int i = 1; i < nums.size(); i++) + { + if (nums[i] <= nums[i - 1]) { + res += nums[i - 1] - nums[i] + 1; + nums[i] = nums[i - 1] + 1; + } + } + return res; + } +}; diff --git "a/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.py" "b/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.py" new file mode 100644 index 0000000..da4b37b --- /dev/null +++ "b/1827.\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236/1827-\346\234\200\345\260\221\346\223\215\344\275\234\344\275\277\346\225\260\347\273\204\351\200\222\345\242\236.py" @@ -0,0 +1,17 @@ +class Solution(object): + def minOperations(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if len(nums) == 1: + return 0 + res = 0 + for i, num in enumerate(nums): + if i: + if num <= nums[i - 1]: + res += (nums[i - 1] + 1) - num + nums[i] = nums[i - 1] + 1 + # print(nums) + return res + \ No newline at end of file From 0b8b9a0fb371f1816fdf5fbfb8f59f40a97d7618 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 24 Aug 2021 22:30:30 -0700 Subject: [PATCH 16/19] 2021-08-24 --- ...3\275\347\232\204\350\267\257\345\276\204.py" | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git "a/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" "b/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" index f53fbe5..7942ab6 100644 --- "a/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" +++ "b/0797.\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204/0797-\346\211\200\346\234\211\345\217\257\350\203\275\347\232\204\350\267\257\345\276\204.py" @@ -5,13 +5,15 @@ def allPathsSourceTarget(self, graph): :rtype: List[List[int]] """ n = len(graph) - visited = set() - def dfs(cur_node, path): - if cur_node == n - 1: + res = [] + def dfs(cur, path): + path.append(cur) + if cur == n - 1: res.append(path[:]) return - for next_node in graph[cur_node]: - dfs(next_node, path + [next_node]) - res = [] - dfs(0, [0]) + + for nxt in graph[cur]: + dfs(nxt, path[:]) + + dfs(0, []) return res \ No newline at end of file From 712c6ce7b4076159181ac1ff7d650bb3a5788d05 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 24 Aug 2021 22:39:14 -0700 Subject: [PATCH 17/19] 2021-08-24 --- ...232\204\346\234\200\345\244\247\345\200\274.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "1646.\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274/1646-\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274.py" diff --git "a/1646.\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274/1646-\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/1646.\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274/1646-\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..2d64c3c --- /dev/null +++ "b/1646.\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274/1646-\350\216\267\345\217\226\347\224\237\346\210\220\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,14 @@ +class Solution(object): + def getMaximumGenerated(self, n): + """ + :type n: int + :rtype: int + """ + nums = [0, 1] + for i in range(2, n + 1): + if i % 2 == 0: + nums.append(nums[i // 2]) + else: + nums.append(nums[i // 2] + nums[i // 2 + 1]) + # print nums + return max(nums) if n else 0 \ No newline at end of file From 2ec722e19382aecf4bfa56c72361a7fd2289e977 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 25 Aug 2021 22:24:00 -0700 Subject: [PATCH 18/19] 2021-08-25 --- .../0881-\346\225\221\347\224\237\350\211\207.py" | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git "a/0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" "b/0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" index b98af18..d0b4d3a 100644 --- "a/0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" +++ "b/0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" @@ -7,16 +7,13 @@ def numRescueBoats(self, people, limit): """ people.sort() left, right = 0, len(people) - 1 - res = 0 + boat_count = 0 while left <= right: - if left == right: - res += 1 - break + # print (people[left], people[right], boat_count) if people[left] + people[right] <= limit: left += 1 right -= 1 - res += 1 else: right -= 1 - res += 1 - return res \ No newline at end of file + boat_count += 1 + return boat_count From 720ae7e1885e28520aba3fcf2766b3063b703f54 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 4 Jun 2023 21:22:51 -0700 Subject: [PATCH 19/19] 2023-06-04 --- ...\346\225\260\347\233\270\345\212\240 2.py" | 39 ++++++++++++ ...\345\233\236\346\226\207\346\225\260 2.py" | 17 ++++++ ...4N\344\270\252\347\273\223\347\202\271.py" | 28 +++++++++ ...\347\232\204\346\213\254\345\217\267 2.py" | 16 +++++ ...\345\272\217\351\223\276\350\241\250 2.py" | 33 +++++++++++ ...\345\217\267\347\224\237\346\210\220 2.py" | 22 +++++++ ...\347\232\204\350\212\202\347\202\271 2.py" | 26 ++++++++ ...04\351\207\215\345\244\215\351\241\271.py" | 10 ++++ ...\351\231\244\345\205\203\347\264\240 2.py" | 21 +++++++ ...71\347\232\204\344\270\213\346\240\207.py" | 5 ++ ...\344\270\252\344\275\215\347\275\256 2.py" | 56 ++++++++++++++++++ ...\345\205\245\344\275\215\347\275\256 2.py" | 18 ++++++ ...\347\232\204\346\225\260\347\213\254 2.py" | 15 +++++ ...\350\267\203\346\270\270\346\210\217II.py" | 9 +++ ...\345\205\250\346\216\222\345\210\227 2.py" | 16 +++++ ...\350\275\254\345\233\276\345\203\217 2.py" | 20 +++++++ ...\350\257\215\345\210\206\347\273\204 2.py" | 18 ++++++ ...\346\227\213\347\237\251\351\230\265 2.py" | 42 +++++++++++++ ...\350\267\203\346\270\270\346\210\217 2.py" | 12 ++++ ...\347\232\204\351\225\277\345\272\246 2.py" | 14 +++++ ...\345\271\263\346\226\271\346\240\271 2.py" | 17 ++++++ ...\347\210\254\346\245\274\346\242\257 2.py" | 19 ++++++ ...\345\214\226\350\267\257\345\276\204 2.py" | 15 +++++ ...\351\230\265\347\275\256\351\233\266 2.py" | 24 ++++++++ .../0078-\345\255\220\351\233\206 2.py" | 14 +++++ ...\351\207\215\345\244\215\351\241\271II.py" | 17 ++++++ ...45\244\215\345\205\203\347\264\240II 2.py" | 28 +++++++++ ...\345\244\215\345\205\203\347\264\240 2.py" | 20 +++++++ ...\345\272\217\346\225\260\347\273\204 2.py" | 12 ++++ ...50\275\254\351\223\276\350\241\250II 2.py" | 51 ++++++++++++++++ ...\345\220\214\347\232\204\346\240\221 2.py" | 18 ++++++ ...02\345\272\217\351\201\215\345\216\206.py" | 23 ++++++++ ...02\345\272\217\351\201\215\345\216\206.py" | 28 +++++++++ ...\344\272\214\345\217\211\346\240\221 2.py" | 23 ++++++++ ...\344\272\214\345\217\211\346\240\221 2.py" | 23 ++++++++ ...\345\272\217\351\201\215\345\216\206II.py" | 23 ++++++++ ...\346\220\234\347\264\242\346\240\221 2.py" | 23 ++++++++ ...\346\220\234\347\264\242\346\240\221 2.py" | 39 ++++++++++++ ...\345\260\217\346\267\261\345\272\246 2.py" | 23 ++++++++ ...\345\276\204\346\200\273\345\222\214 2.py" | 24 ++++++++ ...45\276\204\346\200\273\345\222\214II 2.py" | 28 +++++++++ ...\344\270\272\351\223\276\350\241\250 2.py" | 26 ++++++++ ...\347\202\271\346\214\207\351\222\210 2.py" | 40 +++++++++++++ ...47\202\271\346\214\207\351\222\210II 2.py" | 42 +++++++++++++ ...\344\275\263\346\227\266\346\234\272 2.py" | 12 ++++ ...\345\233\236\346\226\207\344\270\262 2.py" | 12 ++++ ...60\345\255\227\344\271\213\345\222\214.py" | 22 +++++++ ...\345\205\213\351\232\206\345\233\276 2.py" | 49 +++++++++++++++ ...\347\232\204\351\223\276\350\241\250 2.py" | 31 ++++++++++ ...\345\275\242\351\223\276\350\241\250 2.py" | 24 ++++++++ ...45\275\242\351\223\276\350\241\250II 2.py" | 34 +++++++++++ ...\345\274\217\346\261\202\345\200\274 2.py" | 27 +++++++++ ...55\347\232\204\345\215\225\350\257\215.py" | 3 + ...\346\234\200\345\260\217\346\240\210 2.py" | 47 +++++++++++++++ ...\344\272\244\351\223\276\350\241\250 2.py" | 37 ++++++++++++ ...\346\225\260\345\205\203\347\264\240 2.py" | 19 ++++++ ...56\350\275\254\346\225\260\347\273\204.py" | 15 +++++ ...\345\256\266\345\212\253\350\210\215 2.py" | 14 +++++ ...\345\217\263\350\247\206\345\233\276 2.py" | 28 +++++++++ ...\345\277\253\344\271\220\346\225\260 2.py" | 20 +++++++ ...\345\255\227\347\254\246\344\270\262 2.py" | 17 ++++++ ...45\256\266\345\212\253\350\210\215II 2.py" | 26 ++++++++ ...\345\244\247\345\205\203\347\264\240 2.py" | 30 ++++++++++ ...45\244\215\345\205\203\347\264\240II 2.py" | 14 +++++ ...\347\202\271\344\270\252\346\225\260 2.py" | 18 ++++++ ...\346\200\273\345\214\272\351\227\264 2.py" | 25 ++++++++ ...\347\232\204\345\205\203\347\264\240 2.py" | 26 ++++++++ .../0231-2\347\232\204\345\271\202 2.py" | 7 +++ ...\347\232\204\350\212\202\347\202\271 2.py" | 15 +++++ ...\347\232\204\344\271\230\347\247\257 2.py" | 14 +++++ ...\345\274\202\344\275\215\350\257\215 2.py" | 8 +++ ...\346\234\211\350\267\257\345\276\204 2.py" | 30 ++++++++++ ...\344\275\215\347\233\270\345\212\240 2.py" | 7 +++ .../0264-\344\270\221\346\225\260II 2.py" | 24 ++++++++ ...61\347\232\204\346\225\260\345\255\227.py" | 4 ++ ...47\264\242\346\240\221\345\200\274II 2.py" | 34 +++++++++++ ...\345\221\275\346\270\270\346\210\217 2.py" | 37 ++++++++++++ ...\350\257\215\350\247\204\345\276\213 2.py" | 20 +++++++ .../0292-Nim\346\270\270\346\210\217 2.py" | 7 +++ ...05\347\272\247\344\270\221\346\225\260.py" | 16 +++++ ...15\345\244\215\345\255\227\346\257\215.py" | 13 ++++ ...\345\255\227\347\254\246\344\270\262 2.py" | 15 +++++ ...\347\232\204\344\272\244\351\233\206 2.py" | 8 +++ ...17\346\234\272\350\212\202\347\202\271.py" | 22 +++++++ ...\350\265\216\351\207\221\344\277\241 2.py" | 19 ++++++ ...\345\255\220\345\272\217\345\210\227 2.py" | 14 +++++ ...\346\234\200\345\244\247\345\200\274 2.py" | 31 ++++++++++ 0412.FizzBuzz/0412-FizzBuzz 2.py | 17 ++++++ ...\347\216\207\346\216\222\345\272\217 2.py" | 7 +++ ...345\244\247\345\205\203\347\264\240I 2.py" | 24 ++++++++ ...\351\224\256\347\233\230\350\241\214 2.py" | 34 +++++++++++ ...45\244\247\345\205\203\347\264\240II 2.py" | 34 +++++++++++ ...70\345\257\271\345\220\215\346\254\241.py" | 21 +++++++ ...\350\247\222\347\232\204\345\200\274 2.py" | 29 +++++++++ ...\346\234\200\345\244\247\345\200\274 2.py" | 38 ++++++++++++ ...12\345\272\217\345\210\227\342\205\240.py" | 5 ++ ...\347\264\257\345\212\240\346\240\221 2.py" | 29 +++++++++ ...7\232\204\345\215\225\350\257\215III 2.py" | 7 +++ ...\345\272\217\351\201\215\345\216\206 2.py" | 20 +++++++ ...\345\272\217\351\201\215\345\216\206 2.py" | 19 ++++++ ...\344\272\214\345\217\211\346\240\221 2.py" | 23 ++++++++ ...\345\271\263\345\235\207\345\200\274 2.py" | 28 +++++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 26 ++++++++ ...\344\272\214\345\217\211\346\240\221 2.py" | 20 +++++++ ...\345\233\236\345\216\237\347\202\271 2.py" | 7 +++ ...\345\233\236\346\226\207\344\270\262II.py" | 20 +++++++ ...\347\220\203\346\257\224\350\265\233 2.py" | 19 ++++++ ...\347\232\204\346\220\234\347\264\242 2.py" | 21 +++++++ ...\345\272\217\346\225\260\347\273\204 2.py" | 19 ++++++ ...4K\345\244\247\345\205\203\347\264\240.py" | 22 +++++++ ...\345\206\231\345\255\227\346\257\215 2.py" | 8 +++ ...24\347\211\271\345\255\227\347\254\246.py" | 15 +++++ ...06\351\232\224\351\223\276\350\241\250.py" | 26 ++++++++ ...\347\210\254\346\245\274\346\242\257 2.py" | 18 ++++++ ...40\346\225\260\345\210\206\346\225\260.py" | 10 ++++ ...\345\257\206\347\240\201\350\257\215 2.py" | 16 +++++ ...\345\244\251\351\231\205\347\272\277 2.py" | 22 +++++++ ...\350\275\254\345\233\276\345\203\217 2.py" | 11 ++++ ...\351\241\266\347\264\242\345\274\225 2.py" | 18 ++++++ ...55\351\227\264\347\273\223\347\202\271.py" | 13 ++++ ...17\346\220\234\347\264\242\346\240\221.py" | 21 +++++++ ...\345\272\217\346\225\260\347\273\204 2.py" | 8 +++ ...\350\214\203\345\233\264\345\222\214 2.py" | 28 +++++++++ ...347\232\204K\344\270\252\347\202\271 2.py" | 9 +++ ...11\346\220\234\347\264\242\346\240\221.py" | 27 +++++++++ ...\347\232\204\350\203\275\345\212\233 2.py" | 27 +++++++++ ...\350\277\233\345\210\266\344\270\262 2.py" | 13 ++++ ...\345\210\266\350\275\254\346\215\242 2.py" | 16 +++++ ...\345\244\247\350\212\202\347\202\271 2.py" | 35 +++++++++++ ...\347\232\204\346\213\254\345\217\267 2.py" | 24 ++++++++ ...\346\225\260\344\271\213\345\222\214 2.py" | 37 ++++++++++++ ...\345\244\247\345\222\214\346\240\221 2.py" | 26 ++++++++ ...64\347\232\204\351\207\215\351\207\217.py" | 16 +++++ ...\346\235\241\345\275\242\347\240\201 2.py" | 34 +++++++++++ ...66\346\225\260\347\233\270\345\212\240.py" | 20 +++++++ ...73\345\255\227\345\215\260\345\210\267.py" | 14 +++++ ...15\350\266\263\350\212\202\347\202\271.py" | 44 ++++++++++++++ ...\347\237\255\350\267\257\345\276\204 2.py" | 35 +++++++++++ ...45\210\206\347\263\226\346\236\234II 2.py" | 20 +++++++ ...00\346\227\240\346\225\210\345\214\226.py" | 4 ++ ...40\347\202\271\346\210\220\346\236\227.py" | 27 +++++++++ ...\347\232\204\345\205\203\351\237\263 2.py" | 8 +++ ...67\347\224\237\346\210\220\346\240\221.py" | 12 ++++ ...\345\244\247\351\225\277\345\272\246 2.py" | 41 +++++++++++++ ...\345\205\203\347\264\240\345\222\214 2.py" | 33 +++++++++++ ...\350\241\214\351\224\256\347\233\230 2.py" | 16 +++++ ...\347\232\204\345\255\220\344\270\262 2.py" | 14 +++++ ...\345\205\261\345\205\203\347\264\240 2.py" | 13 ++++ ...\345\255\227\347\254\246\344\270\262 2.py" | 21 +++++++ ...\345\267\247\345\205\213\345\212\233 2.py" | 27 +++++++++ ...43\346\225\264\346\225\260\350\247\243.py" | 26 ++++++++ ...\347\232\204\346\225\260\347\233\256 2.py" | 22 +++++++ ...45\346\211\276\345\205\203\347\264\240.py" | 33 +++++++++++ ...57\345\217\230\351\223\276\350\241\250.py" | 15 +++++ ...50\346\210\267\345\210\206\347\273\204.py" | 13 ++++ ...50\350\275\254\346\225\264\346\225\260.py" | 13 ++++ ...02\347\202\271\347\232\204\345\222\214.py" | 21 +++++++ ...04\350\212\202\347\202\271\345\222\214.py" | 21 +++++++ ...0\345\274\261\347\232\204K\350\241\214.py" | 5 ++ ...\345\260\217\345\207\217\345\215\212 2.py" | 23 ++++++++ ...\347\232\204\350\264\237\346\225\260 2.py" | 16 +++++ ...\345\255\227\347\254\246\344\270\262 2.py" | 9 +++ ...70\345\220\214\350\212\202\347\202\271.py" | 20 +++++++ ...\346\240\207\346\225\260\347\273\204 2.py" | 11 ++++ ...56\347\232\204\346\216\222\345\210\227.py" | 9 +++ ...34\345\261\225\347\244\272\350\241\250.py" | 23 ++++++++ ...\347\273\210\347\202\271\347\253\231 2.py" | 7 +++ ...17\346\225\260\347\273\204\345\222\214.py" | 24 ++++++++ ...\345\273\272\346\225\260\347\273\204 2.py" | 29 +++++++++ ...\345\244\247\344\271\230\347\247\257 2.py" | 8 +++ ...\347\224\237\350\212\202\347\202\271 2.py" | 30 ++++++++++ ...\345\210\227\346\225\260\347\273\204 2.py" | 12 ++++ ...\347\273\210\344\273\267\346\240\274 2.py" | 20 +++++++ ...04\344\272\214\345\217\211\346\240\221.py" | 41 +++++++++++++ ...\345\255\227\347\254\246\344\270\262 2.py" | 11 ++++ ...64\347\232\204\347\243\201\345\212\233.py" | 18 ++++++ ...\346\220\234\351\233\206\345\231\250 2.py" | 13 ++++ ...\350\275\246\347\263\273\347\273\237 2.py" | 24 ++++++++ ...\345\245\227\346\267\261\345\272\246 2.py" | 16 +++++ ...44\344\270\252\351\223\276\350\241\250.py" | 28 +++++++++ ...al\350\247\243\346\236\220\345\231\250.py" | 21 +++++++ ...15\345\257\271\346\254\241\346\225\260.py" | 11 ++++ ...46\347\224\237\346\225\260\351\207\217.py" | 16 +++++ ...57\345\220\246\347\233\270\344\274\274.py" | 8 +++ ...16\347\232\204\346\225\260\347\273\204.py" | 6 ++ ...55\347\232\204\350\212\202\347\202\271.py" | 28 +++++++++ ...26\345\235\220\346\240\207\345\200\274.py" | 24 ++++++++ ...00\345\244\247\345\276\227\345\210\206.py" | 15 +++++ ...RU\357\274\211\351\230\237\345\210\227.py" | 15 +++++ ...04\345\273\272\347\255\221\347\211\251.py" | 9 +++ ...66\345\255\227\347\254\246\344\270\262.py" | 12 ++++ ...17\346\223\215\344\275\234\346\225\260.py" | 15 +++++ ...51\345\223\201\346\225\260\351\207\217.py" | 8 +++ ...20\347\232\204\351\242\234\350\211\262.py" | 13 ++++ ...\345\255\227\346\257\215\345\217\245 2.py" | 7 +++ ...15\345\244\215\345\205\203\347\264\240.py" | 28 +++++++++ ...27\347\254\246\346\233\277\346\215\242.py" | 12 ++++ ...05\345\255\230\346\263\204\351\234\262.py" | 18 ++++++ ...14\345\206\215\346\261\202\345\222\214.py" | 12 ++++ ...17\344\271\230\347\247\257\345\222\214.py" | 10 ++++ ...25\350\257\215\344\271\213\345\222\214.py" | 9 +++ ...04\345\273\272\346\225\260\347\273\204.py" | 3 + ...60\347\273\204\344\270\262\350\201\224.py" | 3 + ...41\346\225\260\347\233\270\345\220\214.py" | 5 ++ ...60\345\255\227\344\271\213\345\222\214.py" | 16 +++++ ...46\344\270\262\346\225\260\347\233\256.py" | 9 +++ ...25\350\257\215\345\211\215\347\274\200.py" | 7 +++ ...04\345\217\230\351\207\217\345\200\274.py" | 10 ++++ ...56\346\240\207\344\270\213\346\240\207.py" | 8 +++ ...3-\347\216\257\345\222\214\346\235\206.py" | 14 +++++ ...07\345\255\227\347\254\246\344\270\262.py" | 6 ++ ...32\345\215\225\350\257\215\346\225\260.py" | 8 +++ ...16\347\274\200\346\214\207\344\273\244.py" | 27 +++++++++ ...11\346\235\237\346\225\260\351\207\217.py" | 10 ++++ ...47\345\255\252\347\224\237\345\222\214.py" | 26 ++++++++ ...15\346\216\222\346\225\260\347\273\204.py" | 17 ++++++ ...4\345\200\274\344\271\230\344\273\2452.py" | 6 ++ ...22\345\210\206\346\225\260\347\273\204.py" | 13 ++++ ...04\346\223\215\344\275\234\346\225\260.py" | 11 ++++ ...64\347\232\204\350\212\202\347\202\271.py" | 24 ++++++++ ...04\345\255\227\347\254\246\344\270\262.py" | 8 +++ ...04\345\215\225\345\205\203\346\240\274.py" | 10 ++++ ...04\344\270\211\350\247\222\345\222\214.py" | 6 ++ ...00\345\244\247\346\225\260\345\255\227.py" | 12 ++++ ...64\346\225\260\347\233\270\345\212\240.py" | 3 + ...23\347\202\271\344\271\213\345\222\214.py" | 9 +++ ...46\344\270\262\346\225\260\347\233\256.py" | 7 +++ ...04\350\212\202\347\202\271\346\225\260.py" | 28 +++++++++ ...04\347\231\276\345\210\206\346\257\224.py" | 3 + ...60\344\275\215\347\232\204\345\200\274.py" | 10 ++++ ...61\346\226\207\345\255\227\346\257\215.py" | 9 +++ ...37\350\256\241\346\230\237\345\217\267.py" | 10 ++++ ...0\344\270\252X\347\237\251\351\230\265.py" | 15 +++++ ...\347\232\204\345\233\236\346\226\207IV.py" | 12 ++++ ...11\346\240\221\347\232\204\345\200\274.py" | 16 +++++ ...55\346\200\273\346\227\266\351\225\277.py" | 16 +++++ ...00\345\260\217\346\225\260\345\255\227.py" | 23 ++++++++ ...11\350\241\214\345\210\227\345\257\271.py" | 8 +++ ...75\347\255\211\344\272\216\351\233\266.py" | 13 ++++ ...21\346\200\273\346\227\266\351\227\264.py" | 36 +++++++++++ ...07\347\232\204\346\225\260\345\255\227.py" | 11 ++++ ...64\347\232\204\350\267\235\347\246\273.py" | 9 +++ ...17\345\201\266\345\200\215\346\225\260.py" | 3 + ...53\351\253\230\346\216\222\345\272\217.py" | 6 ++ ...47\346\255\243\346\225\264\346\225\260.py" | 8 +++ ...30\345\234\250\345\206\262\347\252\201.py" | 8 +++ ...04\345\255\227\347\254\246\344\270\262.py" | 17 ++++++ ...04\345\271\263\345\235\207\345\200\274.py" | 8 +++ ...47\350\241\214\346\223\215\344\275\234.py" | 17 ++++++ ...07\345\200\274\346\225\260\347\233\256.py" | 9 +++ ...04\346\226\271\346\241\210\346\225\260.py" | 36 +++++++++++ ...51\345\272\246\350\275\254\346\215\242.py" | 3 + ...66\347\232\204\345\267\256\345\200\274.py" | 15 +++++ ...73\351\231\244\350\212\202\347\202\271.py" | 28 +++++++++ ...04\346\234\200\345\244\247\345\200\274.py" | 14 +++++ ...71\347\232\204\346\225\260\347\233\256.py" | 11 ++++ ...47\347\224\234\350\234\234\345\272\246.py" | 25 ++++++++ ...00\345\244\247\350\256\241\346\225\260.py" | 32 ++++++++++ ...06\346\225\260\346\216\222\345\272\217.py" | 3 + ...27\347\232\204\346\225\260\344\275\215.py" | 8 +++ ...26\350\265\260\347\244\274\347\211\251.py" | 12 ++++ ...04\344\270\262\350\201\224\345\200\274.py" | 11 ++++ ...14\347\232\204\345\267\256\345\200\274.py" | 12 ++++ ...27\347\254\246\344\270\262\346\225\260.py" | 17 ++++++ ...14\347\273\264\346\225\260\347\273\204.py" | 12 ++++ ...04\346\234\200\345\244\247\345\222\214.py" | 3 + ...56\345\267\256\346\225\260\347\273\204.py" | 10 ++++ ...07\350\267\237\350\270\252\345\231\250.py" | 34 +++++++++++ ...52\347\216\257\351\223\276\350\241\250.py" | 29 +++++++++ ...72\347\232\204\346\225\260\347\233\256.py" | 8 +++ ...65\344\270\255\347\232\204\345\222\214.py" | 23 ++++++++ ...70\346\210\217\350\276\223\345\256\266.py" | 12 ++++ ...11\344\275\215\345\274\202\346\210\226.py" | 9 +++ ...00\345\244\247\346\254\241\346\225\260.py" | 43 ++++++++++++++ ...17\347\232\204\346\225\260\351\207\217.py" | 27 +++++++++ ...00\345\260\217\351\225\277\345\272\246.py" | 12 ++++ ...17\345\233\236\346\226\207\344\270\262.py" | 16 +++++ ...04\346\203\251\347\275\232\346\225\260.py" | 27 +++++++++ ...27\345\267\247\345\205\213\345\212\233.py" | 5 ++ ...35\345\244\226\345\255\227\347\254\246.py" | 15 +++++ ...47\345\256\236\345\212\233\345\200\274.py" | 21 +++++++ ...04\345\260\276\351\232\217\351\233\266.py" | 5 ++ ...00\345\260\217\346\210\220\346\234\254.py" | 12 ++++ ...11\345\272\217\346\216\222\345\210\227.py" | 8 +++ ...46\344\270\262\351\225\277\345\272\246.py" | 3 + ...51\351\230\265\347\232\204\345\222\214.py" | 16 +++++ ...1-\347\214\234\346\225\260\345\255\227.py" | 3 + ...27\346\234\272\345\231\250\344\272\272.py" | 10 ++++ ...25\345\274\217\347\204\260\347\201\253.py" | 14 +++++ ...25\345\217\260\346\225\260\351\207\217.py" | 11 ++++ ...7-\350\243\205\351\245\260\346\240\221.py" | 26 ++++++++ ...44\346\225\260\344\271\213\345\222\214.py" | 9 +++ ...44\346\225\260\347\233\270\345\212\240.py" | 56 ++++++++++++++++++ ...9-\345\233\236\346\226\207\346\225\260.py" | 3 + ...4N\344\270\252\347\273\223\347\202\271.py" | 28 +++++++++ ...10\347\232\204\346\213\254\345\217\267.py" | 11 ++++ ...11\345\272\217\351\223\276\350\241\250.py" | 25 ++++++++ ...54\345\217\267\347\224\237\346\210\220.py" | 14 +++++ ...55\347\232\204\350\212\202\347\202\271.py" | 14 +++++ ...04\351\207\215\345\244\215\351\241\271.py" | 10 ++++ ...73\351\231\244\345\205\203\347\264\240.py" | 11 ++++ ...71\347\232\204\344\270\213\346\240\207.py" | 5 ++ ...00\344\270\252\344\275\215\347\275\256.py" | 25 ++++++++ ...22\345\205\245\344\275\215\347\275\256.py" | 13 ++++ ...10\347\232\204\346\225\260\347\213\254.py" | 28 +++++++++ ...\350\267\203\346\270\270\346\210\217II.py" | 9 +++ ...6-\345\205\250\346\216\222\345\210\227.py" | 16 +++++ ...13\350\275\254\345\233\276\345\203\217.py" | 15 +++++ ...15\350\257\215\345\210\206\347\273\204.py" | 9 +++ ...72\346\227\213\347\237\251\351\230\265.py" | 40 +++++++++++++ ...63\350\267\203\346\270\270\346\210\217.py" | 11 ++++ ...15\347\232\204\351\225\277\345\272\246.py" | 3 + ...04\345\271\263\346\226\271\346\240\271.py" | 12 ++++ ...0-\347\210\254\346\245\274\346\242\257.py" | 22 +++++++ ...00\345\214\226\350\267\257\345\276\204.py" | 13 ++++ ...51\351\230\265\347\275\256\351\233\266.py" | 26 ++++++++ .../0078-\345\255\220\351\233\206.py" | 9 +++ ...\351\207\215\345\244\215\351\241\271II.py" | 17 ++++++ ...\345\244\215\345\205\203\347\264\240II.py" | 24 ++++++++ ...15\345\244\215\345\205\203\347\264\240.py" | 18 ++++++ ...11\345\272\217\346\225\260\347\273\204.py" | 21 +++++++ ...\350\275\254\351\223\276\350\241\250II.py" | 40 +++++++++++++ ...55\345\272\217\351\201\215\345\216\206.py" | 25 ++++++++ ...70\345\220\214\347\232\204\346\240\221.py" | 17 ++++++ ...60\344\272\214\345\217\211\346\240\221.py" | 35 +++++++++++ ...02\345\272\217\351\201\215\345\216\206.py" | 23 ++++++++ ...02\345\272\217\351\201\215\345\216\206.py" | 28 +++++++++ ...00\345\244\247\346\267\261\345\272\246.py" | 28 +++++++++ ...40\344\272\214\345\217\211\346\240\221.py" | 21 +++++++ ...40\344\272\214\345\217\211\346\240\221.py" | 22 +++++++ ...\345\272\217\351\201\215\345\216\206II.py" | 23 ++++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 17 ++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 29 +++++++++ ...00\345\260\217\346\267\261\345\272\246.py" | 26 ++++++++ ...57\345\276\204\346\200\273\345\222\214.py" | 23 ++++++++ ...\345\276\204\346\200\273\345\222\214II.py" | 47 +++++++++++++++ ...00\344\270\272\351\223\276\350\241\250.py" | 28 +++++++++ ...02\347\202\271\346\214\207\351\222\210.py" | 31 ++++++++++ ...\347\202\271\346\214\207\351\222\210II.py" | 46 +++++++++++++++ ...00\344\275\263\346\227\266\346\234\272.py" | 9 +++ ...01\345\233\236\346\226\207\344\270\262.py" | 14 +++++ ...60\345\255\227\344\271\213\345\222\214.py" | 22 +++++++ ...3-\345\205\213\351\232\206\345\233\276.py" | 43 ++++++++++++++ ...10\347\232\204\351\223\276\350\241\250.py" | 33 +++++++++++ ...57\345\275\242\351\223\276\350\241\250.py" | 18 ++++++ ...\345\275\242\351\223\276\350\241\250II.py" | 26 ++++++++ ...15\345\272\217\351\201\215\345\216\206.py" | 23 ++++++++ ...16\345\272\217\351\201\215\345\216\206.py" | 24 ++++++++ ...76\345\274\217\346\261\202\345\200\274.py" | 19 ++++++ ...55\347\232\204\345\215\225\350\257\215.py" | 3 + ...5-\346\234\200\345\260\217\346\240\210.py" | 30 ++++++++++ ...70\344\272\244\351\223\276\350\241\250.py" | 37 ++++++++++++ ...32\346\225\260\345\205\203\347\264\240.py" | 16 +++++ ...56\350\275\254\346\225\260\347\273\204.py" | 15 +++++ ...23\345\256\266\345\212\253\350\210\215.py" | 26 ++++++++ ...04\345\217\263\350\247\206\345\233\276.py" | 28 +++++++++ ...2-\345\277\253\344\271\220\346\225\260.py" | 10 ++++ ...04\345\255\227\347\254\246\344\270\262.py" | 20 +++++++ ...\345\256\266\345\212\253\350\210\215II.py" | 19 ++++++ ...00\345\244\247\345\205\203\347\264\240.py" | 15 +++++ ...\345\244\215\345\205\203\347\264\240II.py" | 24 ++++++++ ...02\347\202\271\344\270\252\346\225\260.py" | 14 +++++ ...54\344\272\214\345\217\211\346\240\221.py" | 14 +++++ ...07\346\200\273\345\214\272\351\227\264.py" | 24 ++++++++ ...17\347\232\204\345\205\203\347\264\240.py" | 22 +++++++ .../0231-2\347\232\204\345\271\202.py" | 3 + ...55\347\232\204\350\212\202\347\202\271.py" | 20 +++++++ ...04\347\232\204\344\271\230\347\247\257.py" | 15 +++++ ...15\345\274\202\344\275\215\350\257\215.py" | 4 ++ ...00\346\234\211\350\267\257\345\276\204.py" | 25 ++++++++ ...04\344\275\215\347\233\270\345\212\240.py" | 9 +++ .../0264-\344\270\221\346\225\260II.py" | 18 ++++++ ...61\347\232\204\346\225\260\345\255\227.py" | 4 ++ ...\347\264\242\346\240\221\345\200\274II.py" | 26 ++++++++ ...37\345\221\275\346\270\270\346\210\217.py" | 34 +++++++++++ ...25\350\257\215\350\247\204\345\276\213.py" | 24 ++++++++ .../0292-Nim\346\270\270\346\210\217.py" | 3 + ...05\347\272\247\344\270\221\346\225\260.py" | 16 +++++ ...15\345\244\215\345\255\227\346\257\215.py" | 13 ++++ ...54\345\255\227\347\254\246\344\270\262.py" | 11 ++++ ...04\347\232\204\344\272\244\351\233\206.py" | 21 +++++++ ...17\346\234\272\350\212\202\347\202\271.py" | 22 +++++++ ...3-\350\265\216\351\207\221\344\277\241.py" | 4 ++ ...55\345\255\220\345\272\217\345\210\227.py" | 8 +++ ...04\346\234\200\345\244\247\345\200\274.py" | 19 ++++++ .../0412.FizzBuzz/0412-FizzBuzz.py | 13 ++++ ...21\347\216\207\346\216\222\345\272\217.py" | 15 +++++ ...4\345\244\247\345\205\203\347\264\240I.py" | 19 ++++++ ...0-\351\224\256\347\233\230\350\241\214.py" | 25 ++++++++ ...\345\244\247\345\205\203\347\264\240II.py" | 13 ++++ ...70\345\257\271\345\220\215\346\254\241.py" | 21 +++++++ ...13\350\247\222\347\232\204\345\200\274.py" | 23 ++++++++ ...76\346\234\200\345\244\247\345\200\274.py" | 24 ++++++++ ...12\345\272\217\345\210\227\342\205\240.py" | 5 ++ ...72\347\264\257\345\212\240\346\240\221.py" | 20 +++++++ ...347\232\204\345\215\225\350\257\215III.py" | 3 + ...15\345\272\217\351\201\215\345\216\206.py" | 25 ++++++++ ...16\345\272\217\351\201\215\345\216\206.py" | 25 ++++++++ ...66\344\272\214\345\217\211\346\240\221.py" | 20 +++++++ ...02\345\271\263\345\235\207\345\200\274.py" | 27 +++++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 26 ++++++++ ...47\344\272\214\345\217\211\346\240\221.py" | 16 +++++ ...24\345\233\236\345\216\237\347\202\271.py" | 15 +++++ ...\345\233\236\346\226\207\344\270\262II.py" | 20 +++++++ ...22\347\220\203\346\257\224\350\265\233.py" | 13 ++++ ...55\347\232\204\346\220\234\347\264\242.py" | 20 +++++++ ...11\345\272\217\346\225\260\347\273\204.py" | 25 ++++++++ ...4K\345\244\247\345\205\203\347\264\240.py" | 22 +++++++ ...17\345\206\231\345\255\227\346\257\215.py" | 6 ++ ...24\347\211\271\345\255\227\347\254\246.py" | 15 +++++ ...06\351\232\224\351\223\276\350\241\250.py" | 26 ++++++++ ...71\347\210\254\346\245\274\346\242\257.py" | 21 +++++++ ...63\344\270\216\347\237\263\345\244\264.py" | 10 ++++ ...40\346\225\260\345\210\206\346\225\260.py" | 10 ++++ ...57\345\257\206\347\240\201\350\257\215.py" | 11 ++++ ...02\345\244\251\351\231\205\347\272\277.py" | 8 +++ ...73\350\275\254\345\233\276\345\203\217.py" | 9 +++ ...60\351\241\266\347\264\242\345\274\225.py" | 13 ++++ ...55\351\227\264\347\273\223\347\202\271.py" | 13 ++++ ...17\346\220\234\347\264\242\346\240\221.py" | 21 +++++++ ...22\345\272\217\346\225\260\347\273\204.py" | 13 ++++ ...04\350\214\203\345\233\264\345\222\214.py" | 23 ++++++++ ...74\344\272\214\345\217\211\346\240\221.py" | 13 ++++ ...1\347\232\204K\344\270\252\347\202\271.py" | 15 +++++ ...11\346\220\234\347\264\242\346\240\221.py" | 27 +++++++++ ...71\347\232\204\350\203\275\345\212\233.py" | 22 +++++++ ...14\350\277\233\345\210\266\344\270\262.py" | 7 +++ ...33\345\210\266\350\275\254\346\215\242.py" | 10 ++++ ...64\345\244\247\350\212\202\347\202\271.py" | 25 ++++++++ ...02\347\232\204\346\213\254\345\217\267.py" | 21 +++++++ ...66\346\225\260\344\271\213\345\222\214.py" | 22 +++++++ ...64\345\244\247\345\222\214\346\240\221.py" | 21 +++++++ ...64\347\232\204\351\207\215\351\207\217.py" | 16 +++++ ...04\346\235\241\345\275\242\347\240\201.py" | 25 ++++++++ ...66\346\225\260\347\233\270\345\212\240.py" | 20 +++++++ ...73\345\255\227\345\215\260\345\210\267.py" | 14 +++++ ...15\350\266\263\350\212\202\347\202\271.py" | 44 ++++++++++++++ ...00\347\237\255\350\267\257\345\276\204.py" | 31 ++++++++++ ...\345\210\206\347\263\226\346\236\234II.py" | 14 +++++ ...00\346\227\240\346\225\210\345\214\226.py" | 4 ++ ...40\347\202\271\346\210\220\346\236\227.py" | 27 +++++++++ ...55\347\232\204\345\205\203\351\237\263.py" | 8 +++ ...67\347\224\237\346\210\220\346\240\221.py" | 12 ++++ ...00\345\244\247\351\225\277\345\272\246.py" | 21 +++++++ ...05\345\205\203\347\264\240\345\222\214.py" | 32 ++++++++++ ...25\350\241\214\351\224\256\347\233\230.py" | 13 ++++ ...15\347\232\204\345\255\220\344\270\262.py" | 13 ++++ ...54\345\205\261\345\205\203\347\264\240.py" | 25 ++++++++ ...41\345\255\227\347\254\246\344\270\262.py" | 15 +++++ ...53\345\267\247\345\205\213\345\212\233.py" | 21 +++++++ ...43\346\225\264\346\225\260\350\247\243.py" | 26 ++++++++ ...74\347\232\204\346\225\260\347\233\256.py" | 17 ++++++ ...45\346\211\276\345\205\203\347\264\240.py" | 33 +++++++++++ ...57\345\217\230\351\223\276\350\241\250.py" | 15 +++++ ...50\346\210\267\345\210\206\347\273\204.py" | 13 ++++ ...50\350\275\254\346\225\264\346\225\260.py" | 13 ++++ ...02\347\202\271\347\232\204\345\222\214.py" | 21 +++++++ ...04\350\212\202\347\202\271\345\222\214.py" | 21 +++++++ ...0\345\274\261\347\232\204K\350\241\214.py" | 5 ++ ...47\345\260\217\345\207\217\345\215\212.py" | 18 ++++++ ...55\347\232\204\350\264\237\346\225\260.py" | 8 +++ ...04\345\255\227\347\254\246\344\270\262.py" | 5 ++ ...70\345\220\214\350\212\202\347\202\271.py" | 20 +++++++ ...56\346\240\207\346\225\260\347\273\204.py" | 6 ++ ...56\347\232\204\346\216\222\345\210\227.py" | 9 +++ ...34\345\261\225\347\244\272\350\241\250.py" | 23 ++++++++ ...14\347\273\210\347\202\271\347\253\231.py" | 15 +++++ ...17\346\225\260\347\273\204\345\222\214.py" | 24 ++++++++ ...04\345\273\272\346\225\260\347\273\204.py" | 12 ++++ ...00\345\244\247\344\271\230\347\247\257.py" | 4 ++ ...54\347\224\237\350\212\202\347\202\271.py" | 24 ++++++++ ...22\345\210\227\346\225\260\347\273\204.py" | 5 ++ ...00\347\273\210\344\273\267\346\240\274.py" | 12 ++++ ...04\344\272\214\345\217\211\346\240\221.py" | 41 +++++++++++++ ...27\345\255\227\347\254\246\344\270\262.py" | 7 +++ ...64\347\232\204\347\243\201\345\212\233.py" | 18 ++++++ ...27\346\220\234\351\233\206\345\231\250.py" | 10 ++++ ...34\350\275\246\347\263\273\347\273\237.py" | 25 ++++++++ ...14\345\245\227\346\267\261\345\272\246.py" | 12 ++++ ...44\344\270\252\351\223\276\350\241\250.py" | 28 +++++++++ ...al\350\247\243\346\236\220\345\231\250.py" | 21 +++++++ ...15\345\257\271\346\254\241\346\225\260.py" | 11 ++++ ...46\347\224\237\346\225\260\351\207\217.py" | 16 +++++ ...57\345\220\246\347\233\270\344\274\274.py" | 8 +++ ...16\347\232\204\346\225\260\347\273\204.py" | 6 ++ ...55\347\232\204\350\212\202\347\202\271.py" | 28 +++++++++ ...26\345\235\220\346\240\207\345\200\274.py" | 24 ++++++++ ...00\345\244\247\345\276\227\345\210\206.py" | 15 +++++ ...RU\357\274\211\351\230\237\345\210\227.py" | 15 +++++ ...04\345\273\272\347\255\221\347\211\251.py" | 9 +++ ...66\345\255\227\347\254\246\344\270\262.py" | 12 ++++ ...17\346\223\215\344\275\234\346\225\260.py" | 15 +++++ ...51\345\223\201\346\225\260\351\207\217.py" | 8 +++ ...20\347\232\204\351\242\234\350\211\262.py" | 13 ++++ ...50\345\255\227\346\257\215\345\217\245.py" | 3 + ...15\345\244\215\345\205\203\347\264\240.py" | 28 +++++++++ ...27\347\254\246\346\233\277\346\215\242.py" | 12 ++++ ...05\345\255\230\346\263\204\351\234\262.py" | 18 ++++++ ...14\345\206\215\346\261\202\345\222\214.py" | 12 ++++ ...17\344\271\230\347\247\257\345\222\214.py" | 10 ++++ ...25\350\257\215\344\271\213\345\222\214.py" | 9 +++ ...04\345\273\272\346\225\260\347\273\204.py" | 3 + ...60\347\273\204\344\270\262\350\201\224.py" | 3 + ...41\346\225\260\347\233\270\345\220\214.py" | 5 ++ ...60\345\255\227\344\271\213\345\222\214.py" | 16 +++++ ...46\344\270\262\346\225\260\347\233\256.py" | 9 +++ ...25\350\257\215\345\211\215\347\274\200.py" | 7 +++ ...04\345\217\230\351\207\217\345\200\274.py" | 10 ++++ ...56\346\240\207\344\270\213\346\240\207.py" | 8 +++ ...3-\347\216\257\345\222\214\346\235\206.py" | 14 +++++ ...07\345\255\227\347\254\246\344\270\262.py" | 6 ++ ...32\345\215\225\350\257\215\346\225\260.py" | 8 +++ ...16\347\274\200\346\214\207\344\273\244.py" | 27 +++++++++ ...11\346\235\237\346\225\260\351\207\217.py" | 10 ++++ ...47\345\255\252\347\224\237\345\222\214.py" | 26 ++++++++ ...15\346\216\222\346\225\260\347\273\204.py" | 17 ++++++ ...4\345\200\274\344\271\230\344\273\2452.py" | 6 ++ ...22\345\210\206\346\225\260\347\273\204.py" | 13 ++++ ...04\346\223\215\344\275\234\346\225\260.py" | 11 ++++ ...64\347\232\204\350\212\202\347\202\271.py" | 24 ++++++++ ...04\345\255\227\347\254\246\344\270\262.py" | 8 +++ ...04\345\215\225\345\205\203\346\240\274.py" | 10 ++++ ...04\344\270\211\350\247\222\345\222\214.py" | 6 ++ ...00\345\244\247\346\225\260\345\255\227.py" | 12 ++++ ...64\346\225\260\347\233\270\345\212\240.py" | 3 + ...23\347\202\271\344\271\213\345\222\214.py" | 9 +++ ...46\344\270\262\346\225\260\347\233\256.py" | 7 +++ ...04\350\212\202\347\202\271\346\225\260.py" | 28 +++++++++ ...04\347\231\276\345\210\206\346\257\224.py" | 3 + ...60\344\275\215\347\232\204\345\200\274.py" | 10 ++++ ...61\346\226\207\345\255\227\346\257\215.py" | 9 +++ ...37\350\256\241\346\230\237\345\217\267.py" | 10 ++++ ...0\344\270\252X\347\237\251\351\230\265.py" | 15 +++++ ...\347\232\204\345\233\236\346\226\207IV.py" | 12 ++++ ...11\346\240\221\347\232\204\345\200\274.py" | 16 +++++ ...55\346\200\273\346\227\266\351\225\277.py" | 16 +++++ ...00\345\260\217\346\225\260\345\255\227.py" | 23 ++++++++ ...11\350\241\214\345\210\227\345\257\271.py" | 8 +++ ...75\347\255\211\344\272\216\351\233\266.py" | 13 ++++ ...21\346\200\273\346\227\266\351\227\264.py" | 36 +++++++++++ ...07\347\232\204\346\225\260\345\255\227.py" | 11 ++++ ...64\347\232\204\350\267\235\347\246\273.py" | 9 +++ ...17\345\201\266\345\200\215\346\225\260.py" | 3 + ...53\351\253\230\346\216\222\345\272\217.py" | 6 ++ ...47\346\255\243\346\225\264\346\225\260.py" | 8 +++ ...30\345\234\250\345\206\262\347\252\201.py" | 8 +++ ...04\345\255\227\347\254\246\344\270\262.py" | 17 ++++++ ...04\345\271\263\345\235\207\345\200\274.py" | 8 +++ ...47\350\241\214\346\223\215\344\275\234.py" | 17 ++++++ ...07\345\200\274\346\225\260\347\233\256.py" | 9 +++ ...04\346\226\271\346\241\210\346\225\260.py" | 36 +++++++++++ ...51\345\272\246\350\275\254\346\215\242.py" | 3 + ...66\347\232\204\345\267\256\345\200\274.py" | 15 +++++ ...73\351\231\244\350\212\202\347\202\271.py" | 28 +++++++++ ...04\346\234\200\345\244\247\345\200\274.py" | 14 +++++ ...71\347\232\204\346\225\260\347\233\256.py" | 11 ++++ ...47\347\224\234\350\234\234\345\272\246.py" | 25 ++++++++ ...00\345\244\247\350\256\241\346\225\260.py" | 32 ++++++++++ ...06\346\225\260\346\216\222\345\272\217.py" | 3 + ...27\347\232\204\346\225\260\344\275\215.py" | 8 +++ ...26\350\265\260\347\244\274\347\211\251.py" | 12 ++++ ...04\344\270\262\350\201\224\345\200\274.py" | 11 ++++ ...14\347\232\204\345\267\256\345\200\274.py" | 12 ++++ ...27\347\254\246\344\270\262\346\225\260.py" | 17 ++++++ ...14\347\273\264\346\225\260\347\273\204.py" | 12 ++++ ...04\346\234\200\345\244\247\345\222\214.py" | 3 + ...56\345\267\256\346\225\260\347\273\204.py" | 10 ++++ ...07\350\267\237\350\270\252\345\231\250.py" | 34 +++++++++++ ...52\347\216\257\351\223\276\350\241\250.py" | 29 +++++++++ ...72\347\232\204\346\225\260\347\233\256.py" | 8 +++ ...65\344\270\255\347\232\204\345\222\214.py" | 23 ++++++++ ...70\346\210\217\350\276\223\345\256\266.py" | 12 ++++ ...11\344\275\215\345\274\202\346\210\226.py" | 9 +++ ...00\345\244\247\346\254\241\346\225\260.py" | 43 ++++++++++++++ ...17\347\232\204\346\225\260\351\207\217.py" | 27 +++++++++ ...00\345\260\217\351\225\277\345\272\246.py" | 12 ++++ ...17\345\233\236\346\226\207\344\270\262.py" | 16 +++++ ...04\346\203\251\347\275\232\346\225\260.py" | 27 +++++++++ ...27\345\267\247\345\205\213\345\212\233.py" | 5 ++ ...35\345\244\226\345\255\227\347\254\246.py" | 15 +++++ ...47\345\256\236\345\212\233\345\200\274.py" | 21 +++++++ ...04\345\260\276\351\232\217\351\233\266.py" | 5 ++ ...00\345\260\217\346\210\220\346\234\254.py" | 12 ++++ ...11\345\272\217\346\216\222\345\210\227.py" | 8 +++ ...46\344\270\262\351\225\277\345\272\246.py" | 3 + ...51\351\230\265\347\232\204\345\222\214.py" | 16 +++++ ...1-\347\214\234\346\225\260\345\255\227.py" | 3 + ...27\346\234\272\345\231\250\344\272\272.py" | 10 ++++ ...25\345\274\217\347\204\260\347\201\253.py" | 14 +++++ ...25\345\217\260\346\225\260\351\207\217.py" | 11 ++++ ...7-\350\243\205\351\245\260\346\240\221.py" | 26 ++++++++ ...15\347\232\204\346\225\260\345\255\227.py" | 8 +++ ...77\346\215\242\347\251\272\346\240\274.py" | 3 + ...23\345\215\260\351\223\276\350\241\250.py" | 14 +++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 23 ++++++++ ...21\347\232\204\351\225\234\345\203\217.py" | 15 +++++ ...50\347\232\204\345\244\215\345\210\266.py" | 32 ++++++++++ ...\207 Offer 49-\344\270\221\346\225\260.py" | 17 ++++++ ...54\345\205\261\350\212\202\347\202\271.py" | 22 +++++++ ...5\346\211\276\346\225\260\345\255\227I.py" | 25 ++++++++ ...4k\345\244\247\350\212\202\347\202\271.py" | 24 ++++++++ ...21\347\232\204\346\267\261\345\272\246.py" | 23 ++++++++ ...44\344\270\252\346\225\260\345\255\227.py" | 12 ++++ ...54\345\255\227\347\254\246\344\270\262.py" | 3 + ...ffer 64-\346\261\2021+2+\342\200\246+n.py" | 3 + ...41\347\232\204\346\225\260\345\255\227.py" | 3 + ...60\345\255\227\344\271\213\345\222\214.py" | 7 +++ ...10\347\232\204\345\233\236\346\226\207.py" | 5 ++ ...27\345\210\260\345\233\236\346\226\207.py" | 20 +++++++ ...15\345\220\210\350\212\202\347\202\271.py" | 37 ++++++++++++ ...15\350\275\254\351\223\276\350\241\250.py" | 19 ++++++ ...04\345\217\230\344\275\215\350\257\215.py" | 4 ++ ...00\350\241\250\350\276\276\345\274\217.py" | 22 +++++++ ...17\346\227\245\346\270\251\345\272\246.py" | 11 ++++ ...04\346\234\200\345\244\247\345\200\274.py" | 24 ++++++++ ...46\350\276\271\347\232\204\345\200\274.py" | 23 ++++++++ ...60\345\255\227\344\271\213\345\222\214.py" | 23 ++++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 23 ++++++++ ...55\345\272\217\345\220\216\347\273\247.py" | 17 ++++++ ...04\345\200\274\344\271\213\345\222\214.py" | 46 +++++++++++++++ ...21\350\277\255\344\273\243\345\231\250.py" | 29 +++++++++ ...02\347\202\271\344\271\213\345\222\214.py" | 27 +++++++++ ...4K\345\244\247\346\225\260\345\200\274.py" | 22 +++++++ ...4k\344\270\252\346\225\260\345\255\227.py" | 20 +++++++ ...04\347\232\204\351\241\266\351\203\250.py" | 13 ++++ ...47\347\232\204\346\225\260\345\255\227.py" | 3 + ...00\346\234\211\345\255\220\351\233\206.py" | 9 +++ ...04\345\205\250\346\216\222\345\210\227.py" | 16 +++++ ...15\347\232\204\346\213\254\345\217\267.py" | 14 +++++ ...36\347\273\255\345\272\217\345\210\227.py" | 15 +++++ ...57\345\220\246\345\224\257\344\270\200.py" | 3 + ...27\347\254\246\351\207\215\346\216\222.py" | 4 ++ ...\225\351\242\230 01.03-URL\345\214\226.py" | 3 + ...36\346\226\207\346\216\222\345\210\227.py" | 10 ++++ ...46\344\270\262\345\216\213\347\274\251.py" | 14 +++++ ...13\350\275\254\347\237\251\351\230\265.py" | 14 +++++ ...8-\351\233\266\347\237\251\351\230\265.py" | 23 ++++++++ ...46\344\270\262\350\275\256\350\275\254.py" | 5 ++ ...15\345\244\215\350\212\202\347\202\271.py" | 39 ++++++++++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 23 ++++++++ ...55\351\227\264\350\212\202\347\202\271.py" | 19 ++++++ ...06\345\211\262\351\223\276\350\241\250.py" | 24 ++++++++ ...76\350\241\250\346\261\202\345\222\214.py" | 59 +++++++++++++++++++ ...36\346\226\207\351\223\276\350\241\250.py" | 13 ++++ ...76\350\241\250\347\233\270\344\272\244.py" | 36 +++++++++++ ...57\350\267\257\346\243\200\346\265\213.py" | 28 +++++++++ ...04\346\234\200\345\260\217\345\200\274.py" | 35 +++++++++++ ...71\351\227\264\351\200\232\350\267\257.py" | 27 +++++++++ ...17\351\253\230\345\272\246\346\240\221.py" | 14 +++++ ...02\347\202\271\351\223\276\350\241\250.py" | 32 ++++++++++ ...45\345\271\263\350\241\241\346\200\247.py" | 20 +++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 16 +++++ ...6-\345\220\216\347\273\247\350\200\205.py" | 22 +++++++ ...11\346\255\245\351\227\256\351\242\230.py" | 8 +++ ...04\346\234\272\345\231\250\344\272\272.py" | 30 ++++++++++ ...24\346\234\257\347\264\242\345\274\225.py" | 6 ++ ...22\345\275\222\344\271\230\346\263\225.py" | 7 +++ ...30\344\275\215\350\257\215\347\273\204.py" | 9 +++ ...44\346\215\242\346\225\260\345\255\227.py" | 3 + ...25\350\257\215\351\242\221\347\216\207.py" | 14 +++++ ...00\345\244\247\346\225\260\345\200\274.py" | 3 + ...15\347\232\204\346\225\260\345\255\227.py" | 8 +++ ...77\346\215\242\347\251\272\346\240\274.py" | 3 + ...23\345\215\260\351\223\276\350\241\250.py" | 14 +++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 23 ++++++++ ...21\347\232\204\351\225\234\345\203\217.py" | 15 +++++ ...50\347\232\204\345\244\215\345\210\266.py" | 32 ++++++++++ ...\207 Offer 49-\344\270\221\346\225\260.py" | 17 ++++++ ...54\345\205\261\350\212\202\347\202\271.py" | 22 +++++++ ...5\346\211\276\346\225\260\345\255\227I.py" | 25 ++++++++ ...4k\345\244\247\350\212\202\347\202\271.py" | 24 ++++++++ ...21\347\232\204\346\267\261\345\272\246.py" | 23 ++++++++ ...44\344\270\252\346\225\260\345\255\227.py" | 12 ++++ ...54\345\255\227\347\254\246\344\270\262.py" | 3 + ...ffer 64-\346\261\2021+2+\342\200\246+n.py" | 3 + ...41\347\232\204\346\225\260\345\255\227.py" | 3 + ...60\345\255\227\344\271\213\345\222\214.py" | 7 +++ ...10\347\232\204\345\233\236\346\226\207.py" | 5 ++ ...27\345\210\260\345\233\236\346\226\207.py" | 20 +++++++ ...15\345\220\210\350\212\202\347\202\271.py" | 37 ++++++++++++ ...15\350\275\254\351\223\276\350\241\250.py" | 19 ++++++ ...04\345\217\230\344\275\215\350\257\215.py" | 4 ++ ...00\350\241\250\350\276\276\345\274\217.py" | 22 +++++++ ...17\346\227\245\346\270\251\345\272\246.py" | 11 ++++ ...04\346\234\200\345\244\247\345\200\274.py" | 24 ++++++++ ...46\350\276\271\347\232\204\345\200\274.py" | 23 ++++++++ ...60\345\255\227\344\271\213\345\222\214.py" | 23 ++++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 23 ++++++++ ...55\345\272\217\345\220\216\347\273\247.py" | 17 ++++++ ...04\345\200\274\344\271\213\345\222\214.py" | 46 +++++++++++++++ ...21\350\277\255\344\273\243\345\231\250.py" | 29 +++++++++ ...02\347\202\271\344\271\213\345\222\214.py" | 27 +++++++++ ...4K\345\244\247\346\225\260\345\200\274.py" | 22 +++++++ ...4k\344\270\252\346\225\260\345\255\227.py" | 20 +++++++ ...04\347\232\204\351\241\266\351\203\250.py" | 13 ++++ ...47\347\232\204\346\225\260\345\255\227.py" | 3 + ...00\346\234\211\345\255\220\351\233\206.py" | 9 +++ ...04\345\205\250\346\216\222\345\210\227.py" | 16 +++++ ...15\347\232\204\346\213\254\345\217\267.py" | 14 +++++ ...36\347\273\255\345\272\217\345\210\227.py" | 15 +++++ ...57\345\220\246\345\224\257\344\270\200.py" | 3 + ...27\347\254\246\351\207\215\346\216\222.py" | 4 ++ ...\225\351\242\230 01.03-URL\345\214\226.py" | 3 + ...36\346\226\207\346\216\222\345\210\227.py" | 10 ++++ ...46\344\270\262\345\216\213\347\274\251.py" | 14 +++++ ...13\350\275\254\347\237\251\351\230\265.py" | 14 +++++ ...8-\351\233\266\347\237\251\351\230\265.py" | 23 ++++++++ ...\344\270\262\350\275\256\350\275\254 2.py" | 8 +++ ...\345\244\215\350\212\202\347\202\271 2.py" | 26 ++++++++ ...\344\270\252\350\212\202\347\202\271 2.py" | 22 +++++++ ...\351\227\264\350\212\202\347\202\271 2.py" | 19 ++++++ ...06\345\211\262\351\223\276\350\241\250.py" | 24 ++++++++ ...76\350\241\250\346\261\202\345\222\214.py" | 59 +++++++++++++++++++ ...36\346\226\207\351\223\276\350\241\250.py" | 13 ++++ ...76\350\241\250\347\233\270\344\272\244.py" | 36 +++++++++++ ...57\350\267\257\346\243\200\346\265\213.py" | 28 +++++++++ ...04\346\234\200\345\260\217\345\200\274.py" | 35 +++++++++++ ...71\351\227\264\351\200\232\350\267\257.py" | 27 +++++++++ ...17\351\253\230\345\272\246\346\240\221.py" | 14 +++++ ...02\347\202\271\351\223\276\350\241\250.py" | 32 ++++++++++ ...45\345\271\263\350\241\241\346\200\247.py" | 20 +++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 16 +++++ ...6-\345\220\216\347\273\247\350\200\205.py" | 22 +++++++ ...11\346\255\245\351\227\256\351\242\230.py" | 8 +++ ...04\346\234\272\345\231\250\344\272\272.py" | 30 ++++++++++ ...\346\234\257\347\264\242\345\274\225 2.py" | 10 ++++ ...22\345\275\222\344\271\230\346\263\225.py" | 7 +++ ...30\344\275\215\350\257\215\347\273\204.py" | 9 +++ ...44\346\215\242\346\225\260\345\255\227.py" | 3 + ...25\350\257\215\351\242\221\347\216\207.py" | 14 +++++ ...\345\244\247\346\225\260\345\200\274 2.py" | 8 +++ 731 files changed, 12838 insertions(+) create mode 100644 "0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240 2.py" create mode 100644 "0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260 2.py" create mode 100644 "0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" create mode 100644 "0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267 2.py" create mode 100644 "0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250 2.py" create mode 100644 "0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220 2.py" create mode 100644 "0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" create mode 100644 "0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" create mode 100644 "0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240 2.py" create mode 100644 "0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" create mode 100644 "0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256 2.py" create mode 100644 "0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256 2.py" create mode 100644 "0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254 2.py" create mode 100644 "0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" create mode 100644 "0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227 2.py" create mode 100644 "0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217 2.py" create mode 100644 "0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204 2.py" create mode 100644 "0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265 2.py" create mode 100644 "0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217 2.py" create mode 100644 "0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246 2.py" create mode 100644 "0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271 2.py" create mode 100644 "0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257 2.py" create mode 100644 "0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204 2.py" create mode 100644 "0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266 2.py" create mode 100644 "0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206 2.py" create mode 100644 "0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" create mode 100644 "0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" create mode 100644 "0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240 2.py" create mode 100644 "0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204 2.py" create mode 100644 "0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II 2.py" create mode 100644 "0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221 2.py" create mode 100644 "0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" create mode 100644 "0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" create mode 100644 "0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" create mode 100644 "0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" create mode 100644 "0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" create mode 100644 "0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" create mode 100644 "0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" create mode 100644 "0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246 2.py" create mode 100644 "0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214 2.py" create mode 100644 "0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II 2.py" create mode 100644 "0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250 2.py" create mode 100644 "0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210 2.py" create mode 100644 "0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II 2.py" create mode 100644 "0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272 2.py" create mode 100644 "0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262 2.py" create mode 100644 "0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276 2.py" create mode 100644 "0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250 2.py" create mode 100644 "0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250 2.py" create mode 100644 "0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II 2.py" create mode 100644 "0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274 2.py" create mode 100644 "0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" create mode 100644 "0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210 2.py" create mode 100644 "0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250 2.py" create mode 100644 "0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240 2.py" create mode 100644 "0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" create mode 100644 "0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215 2.py" create mode 100644 "0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276 2.py" create mode 100644 "0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260 2.py" create mode 100644 "0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262 2.py" create mode 100644 "0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II 2.py" create mode 100644 "0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240 2.py" create mode 100644 "0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" create mode 100644 "0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260 2.py" create mode 100644 "0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264 2.py" create mode 100644 "0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240 2.py" create mode 100644 "0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202 2.py" create mode 100644 "0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" create mode 100644 "0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257 2.py" create mode 100644 "0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215 2.py" create mode 100644 "0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204 2.py" create mode 100644 "0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240 2.py" create mode 100644 "0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II 2.py" create mode 100644 "0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" create mode 100644 "0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II 2.py" create mode 100644 "0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217 2.py" create mode 100644 "0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213 2.py" create mode 100644 "0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217 2.py" create mode 100644 "0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" create mode 100644 "0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" create mode 100644 "0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262 2.py" create mode 100644 "0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206 2.py" create mode 100644 "0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" create mode 100644 "0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241 2.py" create mode 100644 "0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227 2.py" create mode 100644 "0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274 2.py" create mode 100644 0412.FizzBuzz/0412-FizzBuzz 2.py create mode 100644 "0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217 2.py" create mode 100644 "0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I 2.py" create mode 100644 "0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214 2.py" create mode 100644 "0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II 2.py" create mode 100644 "0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" create mode 100644 "0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274 2.py" create mode 100644 "0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274 2.py" create mode 100644 "0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" create mode 100644 "0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221 2.py" create mode 100644 "0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III 2.py" create mode 100644 "0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206 2.py" create mode 100644 "0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206 2.py" create mode 100644 "0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221 2.py" create mode 100644 "0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274 2.py" create mode 100644 "0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221 2.py" create mode 100644 "0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271 2.py" create mode 100644 "0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" create mode 100644 "0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233 2.py" create mode 100644 "0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242 2.py" create mode 100644 "0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204 2.py" create mode 100644 "0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" create mode 100644 "0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215 2.py" create mode 100644 "0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" create mode 100644 "0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" create mode 100644 "0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257 2.py" create mode 100644 "0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" create mode 100644 "0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215 2.py" create mode 100644 "0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277 2.py" create mode 100644 "0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217 2.py" create mode 100644 "0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225 2.py" create mode 100644 "0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" create mode 100644 "0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" create mode 100644 "0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204 2.py" create mode 100644 "0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214 2.py" create mode 100644 "0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271 2.py" create mode 100644 "1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233 2.py" create mode 100644 "1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262 2.py" create mode 100644 "1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242 2.py" create mode 100644 "1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271 2.py" create mode 100644 "1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267 2.py" create mode 100644 "1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214 2.py" create mode 100644 "1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221 2.py" create mode 100644 "1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" create mode 100644 "1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201 2.py" create mode 100644 "1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" create mode 100644 "1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" create mode 100644 "1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" create mode 100644 "1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204 2.py" create mode 100644 "1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II 2.py" create mode 100644 "1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" create mode 100644 "1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" create mode 100644 "1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263 2.py" create mode 100644 "1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" create mode 100644 "1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246 2.py" create mode 100644 "1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214 2.py" create mode 100644 "1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230 2.py" create mode 100644 "1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262 2.py" create mode 100644 "1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240 2.py" create mode 100644 "1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262 2.py" create mode 100644 "1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233 2.py" create mode 100644 "1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" create mode 100644 "1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256 2.py" create mode 100644 "1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" create mode 100644 "1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" create mode 100644 "1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" create mode 100644 "1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" create mode 100644 "1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" create mode 100644 "1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" create mode 100644 "1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" create mode 100644 "1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212 2.py" create mode 100644 "1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260 2.py" create mode 100644 "1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262 2.py" create mode 100644 "1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" create mode 100644 "1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204 2.py" create mode 100644 "1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" create mode 100644 "1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" create mode 100644 "1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231 2.py" create mode 100644 "1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" create mode 100644 "1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204 2.py" create mode 100644 "1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257 2.py" create mode 100644 "1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271 2.py" create mode 100644 "1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204 2.py" create mode 100644 "1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274 2.py" create mode 100644 "1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" create mode 100644 "1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262 2.py" create mode 100644 "1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" create mode 100644 "1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250 2.py" create mode 100644 "1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237 2.py" create mode 100644 "1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246 2.py" create mode 100644 "1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" create mode 100644 "1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" create mode 100644 "1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" create mode 100644 "1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" create mode 100644 "1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" create mode 100644 "1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" create mode 100644 "1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" create mode 100644 "1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" create mode 100644 "1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" create mode 100644 "1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" create mode 100644 "1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" create mode 100644 "1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" create mode 100644 "1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" create mode 100644 "1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" create mode 100644 "1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" create mode 100644 "1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245 2.py" create mode 100644 "1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" create mode 100644 "1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" create mode 100644 "1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" create mode 100644 "1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" create mode 100644 "1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" create mode 100644 "1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" create mode 100644 "1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" create mode 100644 "1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" create mode 100644 "1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" create mode 100644 "1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" create mode 100644 "2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" create mode 100644 "2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" create mode 100644 "2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" create mode 100644 "2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" create mode 100644 "2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" create mode 100644 "2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" create mode 100644 "2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" create mode 100644 "2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" create mode 100644 "2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" create mode 100644 "2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" create mode 100644 "2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" create mode 100644 "2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" create mode 100644 "2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" create mode 100644 "2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" create mode 100644 "2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" create mode 100644 "2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" create mode 100644 "2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" create mode 100644 "2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" create mode 100644 "2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" create mode 100644 "2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" create mode 100644 "2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" create mode 100644 "2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" create mode 100644 "2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" create mode 100644 "2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" create mode 100644 "2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" create mode 100644 "2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" create mode 100644 "2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" create mode 100644 "2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" create mode 100644 "2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" create mode 100644 "2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" create mode 100644 "2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" create mode 100644 "2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" create mode 100644 "2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" create mode 100644 "2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" create mode 100644 "2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" create mode 100644 "2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" create mode 100644 "2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" create mode 100644 "2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" create mode 100644 "2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" create mode 100644 "2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" create mode 100644 "2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" create mode 100644 "2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" create mode 100644 "2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" create mode 100644 "2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" create mode 100644 "2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" create mode 100644 "2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" create mode 100644 "2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 "2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" create mode 100644 "2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" create mode 100644 "2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" create mode 100644 "2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" create mode 100644 "2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" create mode 100644 "2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" create mode 100644 "2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" create mode 100644 "2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" create mode 100644 "2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" create mode 100644 "2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" create mode 100644 "2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" create mode 100644 "2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" create mode 100644 "2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" create mode 100644 "2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" create mode 100644 "2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" create mode 100644 "2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" create mode 100644 "2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" create mode 100644 "2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" create mode 100644 "2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" create mode 100644 "2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" create mode 100644 "2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" create mode 100644 "2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" create mode 100644 "2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" create mode 100644 "2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" create mode 100644 "2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" create mode 100644 "2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" create mode 100644 "2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" create mode 100644 "2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" create mode 100644 "6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" create mode 100644 "6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" create mode 100644 "6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" create mode 100644 "LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" create mode 100644 "LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" create mode 100644 "LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" create mode 100644 "LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" create mode 100644 "LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" create mode 100644 "LeetCode-Python/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240.py" create mode 100644 "LeetCode-Python/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" create mode 100644 "LeetCode-Python/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" create mode 100644 "LeetCode-Python/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" create mode 100644 "LeetCode-Python/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220.py" create mode 100644 "LeetCode-Python/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" create mode 100644 "LeetCode-Python/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" create mode 100644 "LeetCode-Python/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.py" create mode 100644 "LeetCode-Python/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.py" create mode 100644 "LeetCode-Python/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254.py" create mode 100644 "LeetCode-Python/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" create mode 100644 "LeetCode-Python/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" create mode 100644 "LeetCode-Python/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217.py" create mode 100644 "LeetCode-Python/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" create mode 100644 "LeetCode-Python/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265.py" create mode 100644 "LeetCode-Python/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217.py" create mode 100644 "LeetCode-Python/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246.py" create mode 100644 "LeetCode-Python/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271.py" create mode 100644 "LeetCode-Python/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" create mode 100644 "LeetCode-Python/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204.py" create mode 100644 "LeetCode-Python/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266.py" create mode 100644 "LeetCode-Python/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" create mode 100644 "LeetCode-Python/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" create mode 100644 "LeetCode-Python/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II.py" create mode 100644 "LeetCode-Python/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\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" create mode 100644 "LeetCode-Python/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II.py" create mode 100644 "LeetCode-Python/0094.\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206/0094-\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221.py" create mode 100644 "LeetCode-Python/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221/0101-\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0104-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" create mode 100644 "LeetCode-Python/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" create mode 100644 "LeetCode-Python/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.py" create mode 100644 "LeetCode-Python/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214.py" create mode 100644 "LeetCode-Python/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II.py" create mode 100644 "LeetCode-Python/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210.py" create mode 100644 "LeetCode-Python/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II.py" create mode 100644 "LeetCode-Python/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.py" create mode 100644 "LeetCode-Python/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" create mode 100644 "LeetCode-Python/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" create mode 100644 "LeetCode-Python/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II.py" create mode 100644 "LeetCode-Python/0144.\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0144-\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0145.\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0145-\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.py" create mode 100644 "LeetCode-Python/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" create mode 100644 "LeetCode-Python/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" create mode 100644 "LeetCode-Python/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215.py" create mode 100644 "LeetCode-Python/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" create mode 100644 "LeetCode-Python/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" create mode 100644 "LeetCode-Python/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II.py" create mode 100644 "LeetCode-Python/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II.py" create mode 100644 "LeetCode-Python/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.py" create mode 100644 "LeetCode-Python/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0226-\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264.py" create mode 100644 "LeetCode-Python/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202.py" create mode 100644 "LeetCode-Python/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257.py" create mode 100644 "LeetCode-Python/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.py" create mode 100644 "LeetCode-Python/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.py" create mode 100644 "LeetCode-Python/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240.py" create mode 100644 "LeetCode-Python/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" create mode 100644 "LeetCode-Python/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II.py" create mode 100644 "LeetCode-Python/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217.py" create mode 100644 "LeetCode-Python/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213.py" create mode 100644 "LeetCode-Python/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217.py" create mode 100644 "LeetCode-Python/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" create mode 100644 "LeetCode-Python/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" create mode 100644 "LeetCode-Python/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" create mode 100644 "LeetCode-Python/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241.py" create mode 100644 "LeetCode-Python/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.py" create mode 100644 "LeetCode-Python/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 LeetCode-Python/0412.FizzBuzz/0412-FizzBuzz.py create mode 100644 "LeetCode-Python/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217.py" create mode 100644 "LeetCode-Python/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" create mode 100644 "LeetCode-Python/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214.py" create mode 100644 "LeetCode-Python/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II.py" create mode 100644 "LeetCode-Python/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" create mode 100644 "LeetCode-Python/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.py" create mode 100644 "LeetCode-Python/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274.py" create mode 100644 "LeetCode-Python/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" create mode 100644 "LeetCode-Python/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.py" create mode 100644 "LeetCode-Python/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III.py" create mode 100644 "LeetCode-Python/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" create mode 100644 "LeetCode-Python/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274.py" create mode 100644 "LeetCode-Python/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271.py" create mode 100644 "LeetCode-Python/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" create mode 100644 "LeetCode-Python/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233.py" create mode 100644 "LeetCode-Python/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.py" create mode 100644 "LeetCode-Python/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215.py" create mode 100644 "LeetCode-Python/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" create mode 100644 "LeetCode-Python/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.py" create mode 100644 "LeetCode-Python/0771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/0771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" create mode 100644 "LeetCode-Python/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" create mode 100644 "LeetCode-Python/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215.py" create mode 100644 "LeetCode-Python/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277.py" create mode 100644 "LeetCode-Python/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217.py" create mode 100644 "LeetCode-Python/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225.py" create mode 100644 "LeetCode-Python/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" create mode 100644 "LeetCode-Python/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214.py" create mode 100644 "LeetCode-Python/0965.\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221/0965-\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.py" create mode 100644 "LeetCode-Python/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233.py" create mode 100644 "LeetCode-Python/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262.py" create mode 100644 "LeetCode-Python/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242.py" create mode 100644 "LeetCode-Python/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267.py" create mode 100644 "LeetCode-Python/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221.py" create mode 100644 "LeetCode-Python/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" create mode 100644 "LeetCode-Python/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201.py" create mode 100644 "LeetCode-Python/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" create mode 100644 "LeetCode-Python/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" create mode 100644 "LeetCode-Python/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" create mode 100644 "LeetCode-Python/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" create mode 100644 "LeetCode-Python/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" create mode 100644 "LeetCode-Python/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" create mode 100644 "LeetCode-Python/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263.py" create mode 100644 "LeetCode-Python/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" create mode 100644 "LeetCode-Python/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246.py" create mode 100644 "LeetCode-Python/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214.py" create mode 100644 "LeetCode-Python/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230.py" create mode 100644 "LeetCode-Python/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262.py" create mode 100644 "LeetCode-Python/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233.py" create mode 100644 "LeetCode-Python/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" create mode 100644 "LeetCode-Python/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" create mode 100644 "LeetCode-Python/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" create mode 100644 "LeetCode-Python/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" create mode 100644 "LeetCode-Python/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" create mode 100644 "LeetCode-Python/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" create mode 100644 "LeetCode-Python/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212.py" create mode 100644 "LeetCode-Python/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260.py" create mode 100644 "LeetCode-Python/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" create mode 100644 "LeetCode-Python/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" create mode 100644 "LeetCode-Python/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231.py" create mode 100644 "LeetCode-Python/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" create mode 100644 "LeetCode-Python/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" create mode 100644 "LeetCode-Python/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274.py" create mode 100644 "LeetCode-Python/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" create mode 100644 "LeetCode-Python/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" create mode 100644 "LeetCode-Python/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" create mode 100644 "LeetCode-Python/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" create mode 100644 "LeetCode-Python/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" create mode 100644 "LeetCode-Python/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" create mode 100644 "LeetCode-Python/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" create mode 100644 "LeetCode-Python/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" create mode 100644 "LeetCode-Python/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" create mode 100644 "LeetCode-Python/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" create mode 100644 "LeetCode-Python/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" create mode 100644 "LeetCode-Python/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" create mode 100644 "LeetCode-Python/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" create mode 100644 "LeetCode-Python/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" create mode 100644 "LeetCode-Python/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" create mode 100644 "LeetCode-Python/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" create mode 100644 "LeetCode-Python/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" create mode 100644 "LeetCode-Python/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" create mode 100644 "LeetCode-Python/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" create mode 100644 "LeetCode-Python/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" create mode 100644 "LeetCode-Python/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" create mode 100644 "LeetCode-Python/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" create mode 100644 "LeetCode-Python/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" create mode 100644 "LeetCode-Python/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" create mode 100644 "LeetCode-Python/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" create mode 100644 "LeetCode-Python/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" create mode 100644 "LeetCode-Python/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" create mode 100644 "LeetCode-Python/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" create mode 100644 "LeetCode-Python/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" create mode 100644 "LeetCode-Python/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" create mode 100644 "LeetCode-Python/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" create mode 100644 "LeetCode-Python/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" create mode 100644 "LeetCode-Python/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" create mode 100644 "LeetCode-Python/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" create mode 100644 "LeetCode-Python/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" create mode 100644 "LeetCode-Python/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" create mode 100644 "LeetCode-Python/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" create mode 100644 "LeetCode-Python/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" create mode 100644 "LeetCode-Python/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" create mode 100644 "LeetCode-Python/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" create mode 100644 "LeetCode-Python/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" create mode 100644 "LeetCode-Python/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" create mode 100644 "LeetCode-Python/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" create mode 100644 "LeetCode-Python/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" create mode 100644 "LeetCode-Python/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" create mode 100644 "LeetCode-Python/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" create mode 100644 "LeetCode-Python/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" create mode 100644 "LeetCode-Python/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" create mode 100644 "LeetCode-Python/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" create mode 100644 "LeetCode-Python/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" create mode 100644 "LeetCode-Python/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" create mode 100644 "LeetCode-Python/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" create mode 100644 "LeetCode-Python/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" create mode 100644 "LeetCode-Python/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" create mode 100644 "LeetCode-Python/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" create mode 100644 "LeetCode-Python/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" create mode 100644 "LeetCode-Python/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" create mode 100644 "LeetCode-Python/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" create mode 100644 "LeetCode-Python/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" create mode 100644 "LeetCode-Python/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 "LeetCode-Python/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" create mode 100644 "LeetCode-Python/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" create mode 100644 "LeetCode-Python/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" create mode 100644 "LeetCode-Python/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" create mode 100644 "LeetCode-Python/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" create mode 100644 "LeetCode-Python/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" create mode 100644 "LeetCode-Python/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" create mode 100644 "LeetCode-Python/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" create mode 100644 "LeetCode-Python/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" create mode 100644 "LeetCode-Python/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" create mode 100644 "LeetCode-Python/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" create mode 100644 "LeetCode-Python/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" create mode 100644 "LeetCode-Python/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" create mode 100644 "LeetCode-Python/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" create mode 100644 "LeetCode-Python/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" create mode 100644 "LeetCode-Python/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" create mode 100644 "LeetCode-Python/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" create mode 100644 "LeetCode-Python/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" create mode 100644 "LeetCode-Python/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" create mode 100644 "LeetCode-Python/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" create mode 100644 "LeetCode-Python/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" create mode 100644 "LeetCode-Python/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" create mode 100644 "LeetCode-Python/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" create mode 100644 "LeetCode-Python/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" create mode 100644 "LeetCode-Python/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" create mode 100644 "LeetCode-Python/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" create mode 100644 "LeetCode-Python/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" create mode 100644 "LeetCode-Python/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" create mode 100644 "LeetCode-Python/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" create mode 100644 "LeetCode-Python/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" create mode 100644 "LeetCode-Python/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" create mode 100644 "LeetCode-Python/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" create mode 100644 "LeetCode-Python/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" create mode 100644 "LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" create mode 100644 "\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" create mode 100644 "\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" create mode 100644 "\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" create mode 100644 "\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" create mode 100644 "\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" create mode 100644 "\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" create mode 100644 "\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" create mode 100644 "\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" create mode 100644 "\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" create mode 100644 "\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" create mode 100644 "\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" create mode 100644 "\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" create mode 100644 "\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" create mode 100644 "\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" create mode 100644 "\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" create mode 100644 "\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" create mode 100644 "\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" create mode 100644 "\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" create mode 100644 "\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" create mode 100644 "\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 "\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" create mode 100644 "\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" create mode 100644 "\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" create mode 100644 "\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" create mode 100644 "\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" create mode 100644 "\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" create mode 100644 "\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" create mode 100644 "\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" create mode 100644 "\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" create mode 100644 "\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" create mode 100644 "\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" create mode 100644 "\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254 2.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271 2.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271 2.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271 2.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225 2.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" create mode 100644 "\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274 2.py" diff --git "a/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240 2.py" "b/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240 2.py" new file mode 100644 index 0000000..92afc5c --- /dev/null +++ "b/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240 2.py" @@ -0,0 +1,39 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def addTwoNumbers(self, l1, l2): + """ + :type l1: ListNode + :type l2: ListNode + :rtype: ListNode + """ + if self.getLength(l1) < self.getLength(l2): + l1, l2 = l2, l1 + head = l1 + while(l2): + l1.val += l2.val + l1 = l1.next + l2 = l2.next + + p = head + while(p): + if p.val > 9: + p.val -= 10 + if p.next: + p.next.val += 1 + else: + p.next = ListNode(1) + p = p.next + return head + + + def getLength(self, l): + tmp = 0 + while(l): + tmp += 1 + l = l.next + return tmp \ No newline at end of file diff --git "a/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260 2.py" "b/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260 2.py" new file mode 100644 index 0000000..fc986ad --- /dev/null +++ "b/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260 2.py" @@ -0,0 +1,17 @@ +class Solution(object): + def isPalindrome(self, x): + """ + :type x: int + :rtype: bool + """ + #2019.6.1 + xx = x + if x < 0: + return False + + reverse = 0 + while x > 0: + x, tmp = divmod(x, 10) + reverse = reverse * 10 + tmp + + return reverse == xx \ No newline at end of file diff --git "a/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" "b/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" new file mode 100644 index 0000000..30dac97 --- /dev/null +++ "b/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: + l = 0 + p = head + while p: + l += 1 + p = p.next + + count = l - n + 1 + + dummy = ListNode(-1) + dummy.next = head + cur = -1 + p = dummy + while p: + cur += 1 + if cur == count - 1: + node_to_be_deleted = p.next + p.next = node_to_be_deleted.next + break + p = p.next + + return dummy.next \ No newline at end of file diff --git "a/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267 2.py" "b/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267 2.py" new file mode 100644 index 0000000..563ad92 --- /dev/null +++ "b/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def isValid(self, s): + """ + :type s: str + :rtype: bool + """ + dic = {")": "(", "]":"[", "}":"{"} + stack = [] + for ch in s: + if ch in ["(", "[", "{"]: + stack.append(ch) + else: + if not stack or dic[ch] != stack[-1]: + return False + stack.pop() + return len(stack) == 0 \ No newline at end of file diff --git "a/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250 2.py" "b/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250 2.py" new file mode 100644 index 0000000..7e7be51 --- /dev/null +++ "b/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250 2.py" @@ -0,0 +1,33 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def mergeTwoLists(self, l1, l2): + """ + :type l1: ListNode + :type l2: ListNode + :rtype: ListNode + """ + dummy = ListNode(-1) + + p = dummy + + while l1 and l2: + if l1.val <= l2.val: + p.next = ListNode(l1.val) + l1 = l1.next + else: + p.next = ListNode(l2.val) + l2 = l2.next + p = p.next + + if l1: + p.next = l1 + + if l2: + p.next = l2 + + return dummy.next \ No newline at end of file diff --git "a/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220 2.py" "b/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220 2.py" new file mode 100644 index 0000000..326c241 --- /dev/null +++ "b/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220 2.py" @@ -0,0 +1,22 @@ +class Solution(object): + def generateParenthesis(self, n): + """ + :type n: int + :rtype: List[str] + """ + + res = [] + + def dfs(tmp, left, right): + if len(tmp) == 2 * n: + res.append(tmp) + + if left: + dfs(tmp + "(", left - 1, right) + if right > left: + dfs(tmp + ")", left, right - 1) + + + dfs("", n, n) + return res + \ No newline at end of file diff --git "a/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" "b/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..85dc922 --- /dev/null +++ "b/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def swapPairs(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head or not head.next: + return head + dummy = ListNode(1) + dummy.next = head + + first = head + second = head.next + + tail = second.next + first.next = self.swapPairs(tail) + second.next = first + dummy.next = second + + return dummy.next \ No newline at end of file diff --git "a/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" "b/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" new file mode 100644 index 0000000..5f77e5e --- /dev/null +++ "b/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" @@ -0,0 +1,10 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + visited = set() + index = 0 + for num in nums: + if num not in visited: + visited.add(num) + nums[index] = num + index += 1 + return index \ No newline at end of file diff --git "a/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240 2.py" "b/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..7f0c216 --- /dev/null +++ "b/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240 2.py" @@ -0,0 +1,21 @@ +class Solution(object): + def removeElement(self, nums, val): + """ + :type nums: List[int] + :type val: int + :rtype: int + """ + nums.sort() + for i, num in enumerate(nums): + if num == val: + j = i + 1 + while(j < len(nums) and nums[j] == num): + j += 1 + t = j + while(j < len(nums)): + nums[i] = nums[j] + i += 1 + j += 1 + return i + + \ No newline at end of file diff --git "a/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" "b/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" new file mode 100644 index 0000000..781ae1a --- /dev/null +++ "b/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" @@ -0,0 +1,5 @@ +class Solution: + def strStr(self, haystack: str, needle: str) -> int: + if needle not in haystack: + return -1 + return haystack.index(needle) \ No newline at end of file diff --git "a/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256 2.py" "b/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256 2.py" new file mode 100644 index 0000000..6916af6 --- /dev/null +++ "b/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256 2.py" @@ -0,0 +1,56 @@ +class Solution(object): + def searchRange(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + lo, hi = 0, len(nums) - 1 + + while lo <= hi: + + mid = (lo + hi) // 2 + # print lo, hi, mid, nums + if nums[mid] == target: + break + elif nums[mid] < target: + lo = mid + 1 + else: + hi = mid - 1 + + if lo > hi: + return [-1, -1] + midposition = mid + leftside, rightside = midposition, midposition + #找左边界 + # print 1 + lo, hi = 0, midposition + while lo <= hi: + # print lo, hi, mid + mid = (lo + hi) // 2 + if nums[mid] < target: + lo = mid + 1 + elif nums[mid] == target: + if mid == 0 or (mid - 1 >= 0 and nums[mid - 1] < target): + leftside = mid + break + else: + hi = mid - 1 + # print 1 + #找右边界 + lo, hi = midposition, len(nums) - 1 + while lo <= hi: + mid = (lo + hi) // 2 + if nums[mid] > target: + hi = mid - 1 + elif nums[mid] == target: + if mid == len(nums) - 1 or (mid + 1 < len(nums) and nums[mid + 1] > target): + rightside = mid + break + else: + lo = mid + 1 + + return [leftside, rightside] + + + \ No newline at end of file diff --git "a/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256 2.py" "b/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256 2.py" new file mode 100644 index 0000000..af9dcf0 --- /dev/null +++ "b/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256 2.py" @@ -0,0 +1,18 @@ +class Solution(object): + def searchInsert(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: int + """ + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + + if nums[mid] == target: + return mid + elif nums[mid] > target: + right = mid - 1 + elif nums[mid] < target: + left = mid + 1 + return left \ No newline at end of file diff --git "a/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254 2.py" "b/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254 2.py" new file mode 100644 index 0000000..29ea49c --- /dev/null +++ "b/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254 2.py" @@ -0,0 +1,15 @@ +class Solution: + def isValidSudoku(self, board: List[List[str]]) -> bool: + row = defaultdict(set) + col = defaultdict(set) + square = defaultdict(set) + for i in range(9): + for j in range(9): + if board[i][j].isdigit(): + if board[i][j] in row[i] or board[i][j] in col[j] or board[i][j] in square[(i // 3, j // 3)]: + return False + else: + row[i].add(board[i][j]) + col[j].add(board[i][j]) + square[(i // 3, j // 3)].add(board[i][j]) + return True diff --git "a/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" "b/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" new file mode 100644 index 0000000..5ad82f4 --- /dev/null +++ "b/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" @@ -0,0 +1,9 @@ +class Solution: + def jump(self, nums: List[int]) -> int: + dp = [float("inf") for _ in nums] + dp[0] = 0 + for i, num in enumerate(nums): + for j in range(1, 1 + num): + if i + j < len(nums): + dp[i + j] = min(dp[i + j], dp[i] + 1) + return dp[-1] \ No newline at end of file diff --git "a/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227 2.py" "b/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227 2.py" new file mode 100644 index 0000000..f2a991c --- /dev/null +++ "b/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def permute(self, nums): + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [] + def dfs(tmp, nums): + if not nums: + res.append(tmp) + + for i, x in enumerate(nums): + dfs(tmp + [x], nums[:i] + nums[i + 1:]) + + dfs([], nums) + return res \ No newline at end of file diff --git "a/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217 2.py" "b/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217 2.py" new file mode 100644 index 0000000..e97f740 --- /dev/null +++ "b/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217 2.py" @@ -0,0 +1,20 @@ +class Solution(object): + def rotate(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: None Do not return anything, modify matrix in-place instead. + """ + #先转置再左右对称翻转 + if not matrix or not matrix[0]: + return matrix + n = len(matrix) + + for i in range(n): + for j in range(i + 1, n): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + + for row in matrix: + for i in range(n // 2): + row[i], row[n - 1 - i] = row[n - 1 - i], row[i] + + return matrix \ No newline at end of file diff --git "a/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204 2.py" "b/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204 2.py" new file mode 100644 index 0000000..6998b4a --- /dev/null +++ "b/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204 2.py" @@ -0,0 +1,18 @@ +class Solution(object): + def groupAnagrams(self, strs): + """ + :type strs: List[str] + :rtype: List[List[str]] + """ + record = dict() + + for word in strs: + tmp = tuple(sorted(word)) + # print tmp + if tmp in record: + record[tmp].append(word) + else: + record[tmp] = [word] + return [val for key, val in record.items()] + + \ No newline at end of file diff --git "a/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265 2.py" "b/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265 2.py" new file mode 100644 index 0000000..33e693b --- /dev/null +++ "b/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265 2.py" @@ -0,0 +1,42 @@ +class Solution(object): + def spiralOrder(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: List[int] + """ + if not matrix or not matrix[0]: + return [] + m, n = len(matrix), len(matrix[0]) + i, j = 0, 0 + state = "right" + cnt = 0 + res = [] + while(cnt < m * n): + cnt += 1 + res.append(matrix[i][j]) + matrix[i][j] = "X" + if state == "right": + j += 1 + if j == n or matrix[i][j] == "X": + i += 1 + j -= 1 + state = "down" + elif state == "down": + i += 1 + if i == m or matrix[i][j] == "X": + i -= 1 + j -= 1 + state = "left" + elif state == "left": + j -= 1 + if j == -1 or matrix[i][j] == "X": + j += 1 + i -= 1 + state = "up" + elif state == "up": + i -= 1 + if i == -1 or matrix[i][j] == "X": + i += 1 + j += 1 + state = "right" + return res \ No newline at end of file diff --git "a/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217 2.py" "b/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217 2.py" new file mode 100644 index 0000000..b6283c9 --- /dev/null +++ "b/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217 2.py" @@ -0,0 +1,12 @@ +class Solution(object): + def canJump(self, nums): + """ + :type nums: List[int] + :rtype: bool + """ + start, end = 0, 0 + + while start <= end and end < len(nums): + end = max(end, start + nums[start]) + start += 1 + return end >= len(nums) - 1 \ No newline at end of file diff --git "a/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246 2.py" "b/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246 2.py" new file mode 100644 index 0000000..2ef7de1 --- /dev/null +++ "b/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def lengthOfLastWord(self, s): + """ + :type s: str + :rtype: int + """ + cnt = 0 + for i in range(len(s) - 1, -1, -1): + if s[i] != " ": + while i >= 0 and s[i] != " ": + cnt += 1 + i -= 1 + break + return cnt \ No newline at end of file diff --git "a/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271 2.py" "b/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271 2.py" new file mode 100644 index 0000000..e4e3e3c --- /dev/null +++ "b/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271 2.py" @@ -0,0 +1,17 @@ +class Solution(object): + def mySqrt(self, x): + """ + :type x: int + :rtype: int + """ + left, right = 1, x + while left <= right: + mid = (left + right) // 2 + s = mid ** 2 + if s == x: + return mid + elif s < x: + left = mid + 1 + elif s > x: + right = mid - 1 + return left - 1 \ No newline at end of file diff --git "a/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257 2.py" "b/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257 2.py" new file mode 100644 index 0000000..88ab0fc --- /dev/null +++ "b/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257 2.py" @@ -0,0 +1,19 @@ +class Solution(object): + def climbStairs(self, n): + """ + :type n: int + :rtype: int + """ + if n <= 2: + return [1, 2][n - 1] + first = 1 + second = 2 + cnt = 2 + while cnt < n: + cnt += 1 + cur = first + second + if cnt == n: + return cur + first = second + second = cur + \ No newline at end of file diff --git "a/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204 2.py" "b/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204 2.py" new file mode 100644 index 0000000..d008010 --- /dev/null +++ "b/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204 2.py" @@ -0,0 +1,15 @@ +class Solution(object): + def simplifyPath(self, path): + """ + :type path: str + :rtype: str + """ + l = path.split("/") + stack = [] + for item in l: + if item != "." and item != ".." and item: + stack.append(item) + elif item == ".." and stack: + stack.pop() + + return "/" + "/".join(stack) \ No newline at end of file diff --git "a/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266 2.py" "b/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266 2.py" new file mode 100644 index 0000000..f33d6de --- /dev/null +++ "b/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266 2.py" @@ -0,0 +1,24 @@ +class Solution(object): + def setZeroes(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: None Do not return anything, modify matrix in-place instead. + """ + if not matrix or not matrix[0]: + return matrix + m, n = len(matrix), len(matrix[0]) + + for i in range(m): + for j in range(n): + if matrix[i][j] == 0: + for t in range(m):#同一列 + if matrix[t][j] != 0: + matrix[t][j] = "0" + for t in range(n):#同一行 + if matrix[i][t] != 0: + matrix[i][t] = "0" + for i in range(m): + for j in range(n): + if matrix[i][j] == "0": + matrix[i][j] = 0 + \ No newline at end of file diff --git "a/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206 2.py" "b/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206 2.py" new file mode 100644 index 0000000..6012ad0 --- /dev/null +++ "b/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def subsets(self, nums): + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [[]] + for num in nums: + tmp = res[:] + for item in res: + tmp.append(item + [num]) + res = tmp[:] + + return res \ No newline at end of file diff --git "a/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" "b/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" new file mode 100644 index 0000000..b9415ef --- /dev/null +++ "b/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" @@ -0,0 +1,17 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + prev, prev_count = nums[0], 1 + res = 1 + for num in nums[1:]: + if num == prev: + if prev_count == 1: + nums[res] = num + res += 1 + prev_count += 1 + else: + nums[res] = num + res += 1 + prev = num + prev_count = 1 + return res + \ No newline at end of file diff --git "a/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" "b/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" new file mode 100644 index 0000000..2f4b37b --- /dev/null +++ "b/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def deleteDuplicates(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head or not head.next: + return head + newhead = ListNode(-1) + newhead.next = head + if head.val != head.next.val: + head.next = self.deleteDuplicates(head.next) + else: + p = head + while p and p.val == head.val: + p = p.next + newhead.next = self.deleteDuplicates(p) + + return newhead.next + + + \ No newline at end of file diff --git "a/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240 2.py" "b/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..a601135 --- /dev/null +++ "b/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240 2.py" @@ -0,0 +1,20 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def deleteDuplicates(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head or not head.next: + return head + p = head + while p and p.val == head.val: + p = p.next + head.next = self.deleteDuplicates(p) + + return head \ No newline at end of file diff --git "a/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204 2.py" "b/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..2f0a252 --- /dev/null +++ "b/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204 2.py" @@ -0,0 +1,12 @@ +class Solution(object): + def merge(self, nums1, m, nums2, n): + """ + :type nums1: List[int] + :type m: int + :type nums2: List[int] + :type n: int + :rtype: None Do not return anything, modify nums1 in-place instead. + """ + nums1[:] = (nums1[:m] + nums2) + nums1.sort() + # return sorted(nums) \ No newline at end of file diff --git "a/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II 2.py" "b/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II 2.py" new file mode 100644 index 0000000..4edf755 --- /dev/null +++ "b/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II 2.py" @@ -0,0 +1,51 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def reverseBetween(self, head, m, n): + """ + :type head: ListNode + :type m: int + :type n: int + :rtype: ListNode + """ + newhead = ListNode(-1) + newhead.next = head + #找到第m - 1和第n个节点 + cnt = 1 + slow = head + while cnt < m - 1: + print slow.val + slow = slow.next + cnt += 1 + cnt = 1 + fast = head + while cnt < n: + # print fast.val, n + fast = fast.next + cnt += 1 + # print fast.val, cnt + print slow.val, fast.val + tail = fast.next + fast.next = None + if m != 1: + slow.next = self.reverseLL(slow.next) + else: + newhead.next = self.reverseLL(slow) + p = slow + while p and p.next: + p = p.next + p.next = tail + return newhead.next + + def reverseLL(self, head): + if not head or not head.next: + return head + + p = self.reverseLL(head.next) + head.next.next = head + head.next = None + return p \ No newline at end of file diff --git "a/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221 2.py" "b/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221 2.py" new file mode 100644 index 0000000..e3be02d --- /dev/null +++ "b/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221 2.py" @@ -0,0 +1,18 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: + if not p and not q: + return True + + if not p and q: + return False + + if p and not q: + return False + + return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) \ No newline at end of file diff --git "a/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..204ca41 --- /dev/null +++ "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res \ No newline at end of file diff --git "a/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" "b/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..6e4ed82 --- /dev/null +++ "b/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + flag = 1 + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + if flag: + res.append(cur_level) + flag = 0 + else: + flag = 1 + res.append(cur_level[::-1]) + queue = next_queue + return res \ No newline at end of file diff --git "a/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" "b/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" new file mode 100644 index 0000000..c9439fe --- /dev/null +++ "b/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def buildTree(self, preorder, inorder): + """ + :type preorder: List[int] + :type inorder: List[int] + :rtype: TreeNode + """ + if not preorder: + return None + + root = TreeNode(preorder[0]) + idx = inorder.index(root.val) + + root.left = self.buildTree(preorder[1:idx + 1], inorder[:idx]) + root.right = self.buildTree(preorder[idx + 1:], inorder[idx + 1:]) + return root \ No newline at end of file diff --git "a/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" "b/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" new file mode 100644 index 0000000..c67ac3d --- /dev/null +++ "b/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221 2.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def buildTree(self, inorder, postorder): + """ + :type inorder: List[int] + :type postorder: List[int] + :rtype: TreeNode + """ + if not inorder: + return None + + root = TreeNode(postorder[-1]) + idx = inorder.index(root.val) + + root.left = self.buildTree(inorder[:idx], postorder[:idx]) + root.right = self.buildTree(inorder[idx + 1:], postorder[idx:-1]) + return root \ No newline at end of file diff --git "a/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" new file mode 100644 index 0000000..e2a4c93 --- /dev/null +++ "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrderBottom(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res[::-1] \ No newline at end of file diff --git "a/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" "b/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" new file mode 100644 index 0000000..da3ec6e --- /dev/null +++ "b/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def sortedArrayToBST(self, nums): + """ + :type nums: List[int] + :rtype: TreeNode + """ + if not nums: + return None + rootIdx = len(nums)//2 + rootVal = nums[rootIdx] + + root = TreeNode(rootVal) + root.left = self.sortedArrayToBST(nums[:rootIdx]) + root.right = self.sortedArrayToBST(nums[rootIdx + 1:]) + + return root \ No newline at end of file diff --git "a/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" "b/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" new file mode 100644 index 0000000..2d2a03a --- /dev/null +++ "b/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221 2.py" @@ -0,0 +1,39 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def sortedListToBST(self, head): + """ + :type head: ListNode + :rtype: TreeNode + """ + if not head: + return None + if not head.next: + return TreeNode(head.val) + slow, fast = head, head + pre = head + while fast and fast.next: + pre = slow + slow = slow.next + fast = fast.next.next + # print slow.val, fast.val, pre.val + pre.next = None + part1 = head + part2 = slow.next + + root = TreeNode(slow.val) + root.left = self.sortedListToBST(part1) + root.right = self.sortedListToBST(part2) + return root + \ No newline at end of file diff --git "a/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246 2.py" "b/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246 2.py" new file mode 100644 index 0000000..15bab42 --- /dev/null +++ "b/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246 2.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def minDepth(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + if not root.left and not root.right: + return 1 + elif not root.left: + return 1 + self.minDepth(root.right) + elif not root.right: + return 1 + self.minDepth(root.left) + else: + return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) \ No newline at end of file diff --git "a/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214 2.py" "b/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214 2.py" new file mode 100644 index 0000000..274aed8 --- /dev/null +++ "b/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214 2.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def hasPathSum(self, root, sum): + """ + :type root: TreeNode + :type sum: int + :rtype: bool + """ + def dfs(node, s): + if not node: + return False + + s += node.val + if not node.left and not node.right: + return s == sum + return dfs(node.left, s) or dfs(node.right, s) + + return dfs(root, 0) \ No newline at end of file diff --git "a/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II 2.py" "b/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II 2.py" new file mode 100644 index 0000000..79538f5 --- /dev/null +++ "b/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II 2.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def pathSum(self, root, sum): + """ + :type root: TreeNode + :type sum: int + :rtype: List[List[int]] + """ + res = [] + def dfs(node, path, s): + if not node: + return [] + s += node.val + if not node.left and not node.right: + if s == sum: + res.append(path + [node.val]) + + dfs(node.left, path + [node.val], s) + dfs(node.right, path + [node.val], s) + + dfs(root, [], 0) + return res \ No newline at end of file diff --git "a/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250 2.py" "b/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250 2.py" new file mode 100644 index 0000000..c08d3f9 --- /dev/null +++ "b/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250 2.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution(object): + def flatten(self, root): + """ + :type root: TreeNode + :rtype: None Do not return anything, modify root in-place instead. + """ + if not root or (not root.left and not root.right): + return root + + self.flatten(root.left) + self.flatten(root.right) + + tmp = root.right + root.right = root.left + root.left = None + + while root and root.right: + root = root.right + + root.right = tmp \ No newline at end of file diff --git "a/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210 2.py" "b/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210 2.py" new file mode 100644 index 0000000..2ec9db4 --- /dev/null +++ "b/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210 2.py" @@ -0,0 +1,40 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next +""" +class Solution(object): + def connect(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return + wait = None + if root.left and root.right: + root.left.next = root.right + wait = root.right + elif root.left: + wait = root.left + elif root.right: + wait = root.right + + p = root.next + while p: + if p.left: + wait.next = p.left + break + elif p.right: + wait.next = p.right + break + else: + p = p.next + + self.connect(root.left) + self.connect(root.right) + return root \ No newline at end of file diff --git "a/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II 2.py" "b/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II 2.py" new file mode 100644 index 0000000..3cf5013 --- /dev/null +++ "b/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II 2.py" @@ -0,0 +1,42 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next +""" +class Solution(object): + def connect(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return + wait = None + if root.left and root.right: + root.left.next = root.right + wait = root.right + elif root.left: + wait = root.left + elif root.right: + wait = root.right + else: + return root + p = root.next + while p: + if p.left: + wait.next = p.left + break + elif p.right: + wait.next = p.right + break + else: + p = p.next + + + self.connect(root.right) + self.connect(root.left) + return root \ No newline at end of file diff --git "a/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272 2.py" "b/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272 2.py" new file mode 100644 index 0000000..325ada7 --- /dev/null +++ "b/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272 2.py" @@ -0,0 +1,12 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + res = 0 + pre_min = prices[0] if prices else 0 + for price in prices: + res = max(res, price - pre_min) + pre_min = min(pre_min, price) + return res \ No newline at end of file diff --git "a/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262 2.py" "b/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262 2.py" new file mode 100644 index 0000000..ff3a1f2 --- /dev/null +++ "b/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262 2.py" @@ -0,0 +1,12 @@ +class Solution(object): + def isPalindrome(self, s): + """ + :type s: str + :rtype: bool + """ + tmp = "" + for char in s.lower(): + if char.isalpha() or char.isdigit(): + tmp += char + print tmp + return tmp == tmp[::-1] \ No newline at end of file diff --git "a/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..8f580e1 --- /dev/null +++ "b/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumNumbers(self, root: Optional[TreeNode]) -> int: + self.res = 0 + def dfs(node, cur_sum): + if not node: + return + + cur_sum = cur_sum * 10 + node.val + if not node.left and not node.right: + self.res += cur_sum + else: + dfs(node.left, cur_sum) + dfs(node.right, cur_sum) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276 2.py" "b/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276 2.py" new file mode 100644 index 0000000..ebffc5b --- /dev/null +++ "b/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276 2.py" @@ -0,0 +1,49 @@ +class Solution(object): + def cloneGraph(self, node): + """ + :type node: Node + :rtype: Node + """ + from collections import defaultdict, deque + neighborList = defaultdict(list) #这个哈希表用于记录老结点和其邻居的关系, key是每个老结点,val是它的neighbors + mapping = dict() #这个哈希表用于记录老结点和它对应的新节点 + + def bfs(queue): + if not queue: + return + newqueue = deque() + + while queue: + cur = queue.popleft() + mapping[cur] = Node(cur.val, []) #为每个老结点创建一个对应的新节点 + for nei in cur.neighbors: + neighborList[cur].append(nei) #记录下当前老结点的所有邻居 + if nei not in visited: + visited.add(nei) + newqueue.append(nei) + bfs(newqueue) #BFS找下一层 + + visited = {node} + q = deque() + q.append(node) + bfs(q) + visited = {node} + + def generate(queue): + while queue: + newqueue = [] + for node in queue: + if node: + if not neighborList[node]: #如果没有邻居 + return + + for nei in neighborList[node]: #处理每个邻居 + mapping[node].neighbors.append(mapping[nei]) #在新的结点标记【老结点的邻居对应的】新结点 + if nei not in visited: + visited.add(nei) + newqueue.append(nei) + queue = newqueue[:] + + generate([node]) + + return mapping[node] #返回输入结点对应的新节点 \ No newline at end of file diff --git "a/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250 2.py" "b/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250 2.py" new file mode 100644 index 0000000..7e115f1 --- /dev/null +++ "b/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250 2.py" @@ -0,0 +1,31 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, next, random): + self.val = val + self.next = next + self.random = random +""" +class Solution(object): + def copyRandomList(self, head): + """ + :type head: Node + :rtype: Node + """ + #133变种题, 图换成链表 + mapping = dict() + + p = head + while p: + mapping[p] = Node(p.val, None, None) + p = p.next + + for key, val in mapping.items(): #key是老结点, val是新节点 + if key.next: + val.next = mapping[key.next] + if key.random and key.random in mapping: + val.random = mapping[key.random] + + return mapping[head] if head else head + + \ No newline at end of file diff --git "a/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250 2.py" "b/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250 2.py" new file mode 100644 index 0000000..568e4df --- /dev/null +++ "b/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250 2.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def hasCycle(self, head): + """ + :type head: ListNode + :rtype: bool + """ + if not head or not head.next: + return False + slow, fast = head, head + + while fast: + slow = slow.next + fast = fast.next + if fast: + fast = fast.next + if slow == fast: + return True + return False \ No newline at end of file diff --git "a/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II 2.py" "b/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II 2.py" new file mode 100644 index 0000000..3fbb11e --- /dev/null +++ "b/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II 2.py" @@ -0,0 +1,34 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def detectCycle(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head or not head.next: + return None + + slow, fast = head, head + while fast: + slow = slow.next + fast = fast.next + if fast: + fast = fast.next + + if slow == fast: + break + if slow != fast: + return None + + fast = head + while slow: + if slow == fast: + return slow + slow = slow.next + fast = fast.next + \ No newline at end of file diff --git "a/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274 2.py" "b/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274 2.py" new file mode 100644 index 0000000..d0ff710 --- /dev/null +++ "b/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274 2.py" @@ -0,0 +1,27 @@ +class Solution(object): + def evalRPN(self, tokens): + """ + :type tokens: List[str] + :rtype: int + """ + stack = [] + for i, x in enumerate(tokens): + # print stack + if x not in ["+", "-", "*", "/"]: + stack.append(int(x)) + else: + if x == "+": + tmp = stack[-1] + stack[-2] + stack = stack[:-2] + elif x == "-": + tmp = stack[-2] - stack[-1] + stack = stack[:-2] + elif x == "*": + tmp = stack[-1] * stack[-2] + stack = stack[:-2] + elif x == "/": + tmp = int( stack[-2] * 1.0 / stack[-1]) + stack = stack[:-2] + stack.append(tmp) + + return stack[0] \ No newline at end of file diff --git "a/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" "b/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" new file mode 100644 index 0000000..6b07361 --- /dev/null +++ "b/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" @@ -0,0 +1,3 @@ +class Solution: + def reverseWords(self, s: str) -> str: + return " ".join(s.split()[::-1]) \ No newline at end of file diff --git "a/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210 2.py" "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210 2.py" new file mode 100644 index 0000000..0b9c216 --- /dev/null +++ "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210 2.py" @@ -0,0 +1,47 @@ +class MinStack(object): + + def __init__(self): + """ + initialize your data structure here. + """ + self.s = [] + self.min_s = [] + + def push(self, x): + """ + :type x: int + :rtype: None + """ + self.s.append(x) + if self.min_s: + self.min_s.append(min(x, self.min_s[-1])) + else: + self.min_s.append(x) + + def pop(self): + """ + :rtype: None + """ + self.min_s.pop() + self.s.pop() + + + def top(self): + """ + :rtype: int + """ + return self.s[-1] + + def getMin(self): + """ + :rtype: int + """ + return self.min_s[-1] + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(x) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file diff --git "a/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250 2.py" "b/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250 2.py" new file mode 100644 index 0000000..c3b380b --- /dev/null +++ "b/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250 2.py" @@ -0,0 +1,37 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def getIntersectionNode(self, headA, headB): + """ + :type head1, head1: ListNode + :rtype: ListNode + """ + pa, pb = headA, headB + la, lb = 0, 0 + while pa: + la += 1 + pa = pa.next + + while pb: + lb += 1 + pb = pb.next + + if la < lb: + la, lb, headA, headB = lb, la, headB, headA + + n = la - lb + pa, pb = headA, headB + while n: + pa = pa.next + n -= 1 + + while pa: + if pa == pb: + return pa + pa = pa.next + pb = pb.next + return None \ No newline at end of file diff --git "a/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240 2.py" "b/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..858b7a2 --- /dev/null +++ "b/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240 2.py" @@ -0,0 +1,19 @@ +class Solution(object): + def majorityElement(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + vote = None + vote_cnt = 0 + + for num in nums: + if not vote or num == vote: + vote = num + vote_cnt += 1 + else: + vote_cnt -= 1 + if vote_cnt == 0: + vote = num + vote_cnt = 1 + return vote \ No newline at end of file diff --git "a/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" "b/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" new file mode 100644 index 0000000..0ea399b --- /dev/null +++ "b/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" @@ -0,0 +1,15 @@ +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + def reverse(left, right): + while left < right: + nums[left], nums[right] = nums[right], nums[left] + left += 1 + right -= 1 + k = k % len(nums) + reverse(0, len(nums) - 1) + reverse(0, k - 1) + reverse(k, len(nums) - 1) + \ No newline at end of file diff --git "a/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215 2.py" "b/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215 2.py" new file mode 100644 index 0000000..3d94e44 --- /dev/null +++ "b/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def rob(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if len(nums) == 0: + return 0 + if len(nums) <= 2: + return max(nums) + nums[1] = max(nums[0], nums[1]) + for i in range(2, len(nums)): + nums[i] = max(nums[i - 2] + nums[i], nums[i - 1]) + return max(nums) if nums else 0 \ No newline at end of file diff --git "a/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276 2.py" "b/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276 2.py" new file mode 100644 index 0000000..eb22eed --- /dev/null +++ "b/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276 2.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def rightSideView(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + from collections import deque + if not root: + return [] + queue = deque([root]) + res = [] + while queue: + tmp = None + for _ in range(len(queue)): + cur = queue.popleft() + if cur: + tmp = cur.val + queue += [cur.left, cur.right] + if tmp: + res.append(tmp) + return res diff --git "a/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260 2.py" "b/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260 2.py" new file mode 100644 index 0000000..b376561 --- /dev/null +++ "b/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260 2.py" @@ -0,0 +1,20 @@ +class Solution(object): + def isHappy(self, n): + """ + :type n: int + :rtype: bool + """ + def happy(num): + res = 0 + while num: + num, tmp = divmod(num, 10) + res += tmp ** 2 + return res + visited = set() + while n and n not in visited: + visited.add(n) + tmp = happy(n) + if tmp == 1: + return True + n = tmp + return False \ No newline at end of file diff --git "a/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262 2.py" "b/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262 2.py" new file mode 100644 index 0000000..101e467 --- /dev/null +++ "b/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262 2.py" @@ -0,0 +1,17 @@ +class Solution(object): + def isIsomorphic(self, s, t): + """ + :type s: str + :type t: str + :rtype: bool + """ + mapping = dict() + for i, char in enumerate(s): + if char in mapping: + if mapping[char] != t[i]: #一对多 + return False + else: + if t[i] in mapping.values(): #多对一 + return False + mapping[char] = t[i] + return True \ No newline at end of file diff --git "a/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II 2.py" "b/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II 2.py" new file mode 100644 index 0000000..ca4716c --- /dev/null +++ "b/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II 2.py" @@ -0,0 +1,26 @@ +class Solution(object): + def rob(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if len(nums) == 1: + return nums[0] + return max(self.rob2(nums[1:]), self.rob2(nums[:-1])) + + def rob2(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + # return 0 + if not nums: + return 0 + dp = [0 for _ in nums] + dp[0] = nums[0] + for i in range(1, len(nums)): + if i == 1: + dp[i] = max(dp[0], nums[i]) + else: + dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) + return dp[-1] \ No newline at end of file diff --git "a/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240 2.py" "b/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..6c62036 --- /dev/null +++ "b/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240 2.py" @@ -0,0 +1,30 @@ +class Solution(object): + def findKthLargest(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: int + """ + left, right, target = 0, len(nums) - 1, k - 1 + while True: + pos = self.partition(nums, left, right) + if pos == target: + return nums[pos] + elif pos > k: #要往左找 + right = pos - 1 + elif pos < k: #要往右找 + left = pos + 1 + + def partition(self, nums, left, right): + import random + k = random.randint(left, right) + pivot = nums[k] + nums[left], nums[k] = nums[k], nums[left] + index = left + + for i in range(left + 1, right + 1): + if nums[i] > pivot: + index += 1 + nums[i], nums[index] = nums[index], nums[i] + nums[left], nums[index] = nums[index], nums[left] + return index #此时所有index左侧的值都比nums[index]大, 所有右侧的值都比nums[index]小 \ No newline at end of file diff --git "a/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" "b/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" new file mode 100644 index 0000000..5d2aa7a --- /dev/null +++ "b/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def containsNearbyDuplicate(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: bool + """ + dic = dict() + for i, num in enumerate(nums): + if num in dic: + if i - dic[num] <= k: + return True + dic[num] = i + return False \ No newline at end of file diff --git "a/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260 2.py" "b/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260 2.py" new file mode 100644 index 0000000..0cf67da --- /dev/null +++ "b/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260 2.py" @@ -0,0 +1,18 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def countNodes(self, root): + """ + :type root: TreeNode + :rtype: int + """ + def dfs(node): + if not node: + return 0 + return 1 + dfs(node.left) + dfs(node.right) + return dfs(root) \ No newline at end of file diff --git "a/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264 2.py" "b/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264 2.py" new file mode 100644 index 0000000..30c6d84 --- /dev/null +++ "b/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264 2.py" @@ -0,0 +1,25 @@ +class Solution(object): + def summaryRanges(self, nums): + """ + :type nums: List[int] + :rtype: List[str] + """ + if not nums: + return nums + start, end = nums[0], nums[0] + res = [] + for i, num in enumerate(nums): + if i != 0: + if num == end + 1: + end += 1 + else: + if end - start == 0: + res.append(str(end)) + else: + res.append(str(start) + "->" + str(end)) + start, end = num, num + if end - start == 0: + res.append(str(end)) + else: + res.append(str(start) + "->" + str(end)) + return res \ No newline at end of file diff --git "a/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240 2.py" "b/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..bff7e15 --- /dev/null +++ "b/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240 2.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def kthSmallest(self, root, k): + """ + :type root: TreeNode + :type k: int + :rtype: int + """ + cnt = 0 + cur, stack = root, [] + while cur or stack: + if cur: + stack.append(cur) + cur = cur.left + else: + cnt += 1 + cur = stack.pop() + if cnt == k: + return cur.val + cur = cur.right \ No newline at end of file diff --git "a/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202 2.py" "b/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202 2.py" new file mode 100644 index 0000000..5faa721 --- /dev/null +++ "b/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def isPowerOfTwo(self, n): + """ + :type n: int + :rtype: bool + """ + return n > 0 and not (n & (n - 1)) \ No newline at end of file diff --git "a/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" "b/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..b0924b0 --- /dev/null +++ "b/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271 2.py" @@ -0,0 +1,15 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def deleteNode(self, node): + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + node.val = node.next.val + node.next = node.next.next + \ No newline at end of file diff --git "a/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257 2.py" "b/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257 2.py" new file mode 100644 index 0000000..f51bc1f --- /dev/null +++ "b/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def productExceptSelf(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + res = [1] * len(nums) + for i in range(1, len(nums)): + res[i] = res[i - 1] * nums[i - 1] + tmp = 1 + for i in range(len(nums) - 1, -1, -1): + res[i] *= tmp + tmp *= nums[i] + return res \ No newline at end of file diff --git "a/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215 2.py" "b/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215 2.py" new file mode 100644 index 0000000..469e1cd --- /dev/null +++ "b/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def isAnagram(self, s, t): + """ + :type s: str + :type t: str + :rtype: bool + """ + return sorted(s) == sorted(t) \ No newline at end of file diff --git "a/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204 2.py" "b/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204 2.py" new file mode 100644 index 0000000..23bc926 --- /dev/null +++ "b/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204 2.py" @@ -0,0 +1,30 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def binaryTreePaths(self, root): + """ + :type root: TreeNode + :rtype: List[str] + """ + if not root: + return [] + self.res = [] + + def dfs(node, tmp): + if not node: + return + if not node.left and not node.right: + self.res.append(tmp + str(node.val)) + return + + dfs(node.left, tmp + str(node.val) + "->") + dfs(node.right, tmp + str(node.val) + "->") + + dfs(root, "") + return self.res + \ No newline at end of file diff --git "a/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240 2.py" "b/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240 2.py" new file mode 100644 index 0000000..cc52a39 --- /dev/null +++ "b/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def addDigits(self, num): + """ + :type num: int + :rtype: int + """ + return 1 + (num - 1) % 9 if num > 9 else num \ No newline at end of file diff --git "a/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II 2.py" "b/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II 2.py" new file mode 100644 index 0000000..533b3c1 --- /dev/null +++ "b/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II 2.py" @@ -0,0 +1,24 @@ +class Solution(object): + def nthUglyNumber(self, n): + """ + :type n: int + :rtype: int + """ + from heapq import * + l = [1] + heapify(l) + cnt = 1 + used = set([1]) + while cnt < n: + cur = heappop(l) + if cur * 2 not in used: + heappush(l, cur * 2) + used.add(cur * 2) + if cur * 3 not in used: + heappush(l, cur * 3) + used.add(cur * 3) + if cur * 5 not in used: + used.add(cur * 5) + heappush(l, cur * 5) + cnt += 1 + return heappop(l) \ No newline at end of file diff --git "a/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..92349c3 --- /dev/null +++ "b/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,4 @@ +class Solution: + def missingNumber(self, nums: List[int]) -> int: + n = len(nums) + return (1 + n) * n // 2 - sum(nums) \ No newline at end of file diff --git "a/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II 2.py" "b/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II 2.py" new file mode 100644 index 0000000..45f45cf --- /dev/null +++ "b/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II 2.py" @@ -0,0 +1,34 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None +from heapq import * +class Solution(object): + def closestKValues(self, root, target, k): + """ + :type root: TreeNode + :type target: float + :type k: int + :rtype: List[int] + """ + def inOrder(node): + if not node: + return [] + return inOrder(node.left) + [node.val] + inOrder(node.right) + + l = inOrder(root) + subs = [] + heapify(subs) + for num in l: + sub = abs(target - num) + heappush(subs, (-sub, num)) + if len(subs) > k: + heappop(subs) + + res = [] + for sub, num in subs: + res.append(num) + return res + \ No newline at end of file diff --git "a/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217 2.py" "b/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217 2.py" new file mode 100644 index 0000000..4cf3306 --- /dev/null +++ "b/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217 2.py" @@ -0,0 +1,37 @@ +class Solution(object): + def gameOfLife(self, board): + """ + :type board: List[List[int]] + :rtype: None Do not return anything, modify board in-place instead. + """ + if not board or not board[0]: + return + m, n = len(board), len(board[0]) + dx = [1, -1, 0, 0, 1, 1, -1, -1] + dy = [0, 0, 1, -1, 1, -1, 1, -1] + + def countLiveCells(x0, y0): + cnt = 0 + for k in range(8): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and board[x][y] == 1: + cnt += 1 + + return cnt + + liveCellSet = set() + for i in range(m): + for j in range(n): + if board[i][j] == 1 and countLiveCells(i, j) in [2, 3]: + liveCellSet.add((i, j)) + elif board[i][j] == 0 and countLiveCells(i, j) == 3: + liveCellSet.add((i, j)) + + for i in range(m): + for j in range(n): + if (i, j) in liveCellSet: + board[i][j] = 1 + else: + board[i][j] = 0 \ No newline at end of file diff --git "a/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213 2.py" "b/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213 2.py" new file mode 100644 index 0000000..93a230e --- /dev/null +++ "b/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213 2.py" @@ -0,0 +1,20 @@ +class Solution(object): + def wordPattern(self, pattern, s): + """ + :type pattern: str + :type str: str + :rtype: bool + """ + s = s.split(" ") + if len(pattern) != len(s): + return False + dic = {} + for i, char in enumerate(pattern): + if char not in dic: + dic[char] = s[i] + else: + if dic[char] != s[i]: + return False + + return len(set(dic.values())) == len(dic.values()) + \ No newline at end of file diff --git "a/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217 2.py" "b/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217 2.py" new file mode 100644 index 0000000..ef4b15d --- /dev/null +++ "b/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def canWinNim(self, n): + """ + :type n: int + :rtype: bool + """ + return n % 4 != 0 \ No newline at end of file diff --git "a/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" "b/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" new file mode 100644 index 0000000..6fb1177 --- /dev/null +++ "b/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" @@ -0,0 +1,16 @@ +class Solution: + def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: + import heapq + min_heap = [1] # find the smallest ugly number + visited = set() + cnt = n + while cnt: + cur = heappop(min_heap) + cnt -= 1 + if not cnt: + return cur + for multiple in primes: + nxt = cur * multiple + if nxt not in visited: + visited.add(nxt) + heappush(min_heap, nxt) \ No newline at end of file diff --git "a/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" "b/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" new file mode 100644 index 0000000..0b190ed --- /dev/null +++ "b/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" @@ -0,0 +1,13 @@ +class Solution: + def removeDuplicateLetters(self, s: str) -> str: + from collections import Counter + c = Counter(s) + stack = [] # incresing stack + for char in s: + c[char] -= 1 + if char in stack: + continue + while stack and stack[-1] > char and c[stack[-1]] >= 1: + stack.pop() + stack.append(char) + return "".join(stack) \ No newline at end of file diff --git "a/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262 2.py" "b/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262 2.py" new file mode 100644 index 0000000..ceb97e9 --- /dev/null +++ "b/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262 2.py" @@ -0,0 +1,15 @@ +class Solution(object): + def reverseString(self, s): + """ + :type s: List[str] + :rtype: None Do not return anything, modify s in-place instead. + """ + if not s or len(s) == 0: + return s + left, right = 0, len(s) - 1 + while(left < right): + s[left], s[right] = s[right], s[left] + left += 1 + right -= 1 + return s + \ No newline at end of file diff --git "a/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206 2.py" "b/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206 2.py" new file mode 100644 index 0000000..530c02c --- /dev/null +++ "b/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def intersection(self, nums1, nums2): + """ + :type nums1: List[int] + :type nums2: List[int] + :rtype: List[int] + """ + return list(set(nums1) & set(nums2)) \ No newline at end of file diff --git "a/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" "b/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" new file mode 100644 index 0000000..3b76846 --- /dev/null +++ "b/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" @@ -0,0 +1,22 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +import random +class Solution: + + def __init__(self, head: Optional[ListNode]): + self.list = [] + p = head + while p: + self.list.append(p.val) + p = p.next + + def getRandom(self) -> int: + return random.choice(self.list) + + +# Your Solution object will be instantiated and called as such: +# obj = Solution(head) +# param_1 = obj.getRandom() \ No newline at end of file diff --git "a/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241 2.py" "b/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241 2.py" new file mode 100644 index 0000000..8bbe897 --- /dev/null +++ "b/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241 2.py" @@ -0,0 +1,19 @@ +class Solution(object): + def canConstruct(self, ransomNote, magazine): + """ + :type ransomNote: str + :type magazine: str + :rtype: bool + """ + + r = collections.Counter(ransomNote) + m = collections.Counter(magazine) + + for key in r: + if m.get(key, 0): + if m[key] < r[key]: + return False + else: + return False + + return True \ No newline at end of file diff --git "a/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227 2.py" "b/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227 2.py" new file mode 100644 index 0000000..715dff1 --- /dev/null +++ "b/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def isSubsequence(self, s, t): + """ + :type s: str + :type t: str + :rtype: bool + """ + i, j = 0, 0 + while i < len(s) and j < len(t): + if s[i] == t[j]: + i += 1 + j += 1 + # test + return i == len(s) \ No newline at end of file diff --git "a/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274 2.py" "b/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274 2.py" new file mode 100644 index 0000000..720f73f --- /dev/null +++ "b/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274 2.py" @@ -0,0 +1,31 @@ +class Solution(object): + def splitArray(self, nums, m): + """ + :type nums: List[int] + :type m: int + :rtype: int + """ + # min(nums), sum(nums) + if len(nums) == m: + return max(nums) + lo, hi = max(nums), sum(nums) + while(lo < hi): + mid = (lo + hi) // 2 # 最大和 + + temp, cnt = 0, 1 + for num in nums: + temp += num + # cnt += 1 + if temp > mid: + temp = num + cnt += 1 + # print temp, cnt, mid + + if cnt > m: #多切了几刀,说明mid应该加大 + lo = mid + 1 + elif cnt <= m: + hi = mid + + + return lo + \ No newline at end of file diff --git a/0412.FizzBuzz/0412-FizzBuzz 2.py b/0412.FizzBuzz/0412-FizzBuzz 2.py new file mode 100644 index 0000000..e58e5ae --- /dev/null +++ b/0412.FizzBuzz/0412-FizzBuzz 2.py @@ -0,0 +1,17 @@ +class Solution(object): + def fizzBuzz(self, n): + """ + :type n: int + :rtype: List[str] + """ + res = [] + for i in range(1,n+1): + if i % 3 == 0 and i % 5 == 0: + res.append("FizzBuzz") + elif i%3 == 0: + res.append("Fizz") + elif i%5 == 0: + res.append("Buzz") + else: + res.append(str(i)) + return res \ No newline at end of file diff --git "a/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217 2.py" "b/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217 2.py" new file mode 100644 index 0000000..880536d --- /dev/null +++ "b/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def frequencySort(self, s): + """ + :type s: str + :rtype: str + """ + return ''.join([char*freq for char,freq in collections.Counter(s).most_common()]) \ No newline at end of file diff --git "a/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I 2.py" "b/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I 2.py" new file mode 100644 index 0000000..b488d0e --- /dev/null +++ "b/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I 2.py" @@ -0,0 +1,24 @@ +class Solution(object): + def nextGreaterElement(self, nums1, nums2): + """ + :type nums1: List[int] + :type nums2: List[int] + :rtype: List[int] + """ + mapping = dict() + + stack = [] + for num in nums2: + while stack and stack[-1] < num: + top = stack.pop() + mapping[top] = num + stack.append(num) + + res = [] + for num in nums1: + if num in mapping: + res.append(mapping[num]) + else: + res.append(-1) + + return res \ No newline at end of file diff --git "a/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214 2.py" "b/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214 2.py" new file mode 100644 index 0000000..73d9e3b --- /dev/null +++ "b/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214 2.py" @@ -0,0 +1,34 @@ +class Solution(object): + def findWords(self, words): + """ + :type words: List[str] + :rtype: List[str] + """ + # words = words.lower() + g1 = ["q","w","e","r","t","y","u","i","o","p"] + g2 = ["a","s","d","f","g","h","j","k","l"] + g3 = ["z","x","c","v","b","n","m"] + res = list() + for word in words: + temp = word.lower() + if temp[0] in g1: + flag = 1 + elif temp[0] in g2: + flag = 2 + elif temp[0] in g3: + flag = 3 + temp = set(temp) + for char in temp: + if flag == 1 and char not in g1: + flag = 0 + break + if flag == 2 and char not in g2: + flag = 0 + break + if flag == 3 and char not in g3: + flag = 0 + break + if flag: + res.append(word) + + return res \ No newline at end of file diff --git "a/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II 2.py" "b/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II 2.py" new file mode 100644 index 0000000..046530d --- /dev/null +++ "b/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II 2.py" @@ -0,0 +1,34 @@ +class Solution(object): + def nextGreaterElements(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + if not nums: + return nums + max_element = max(nums) + stack = list() + res = [-1 for i in range(len(nums))] + + for i, x in enumerate(nums): + + if not stack or nums[stack[-1]] >= x: + stack.append(i) + else: + # print stack, res + while(stack and nums[stack[-1]] < x): + res[stack[-1]] = x + stack.pop() + if x != max_element:#最大的不用放进栈,直接默认-1就好 + stack.append(i) + + # print stack, res + if stack: #还有需要循环搜索的元素 + for i, x in enumerate(nums): + if not stack: + break + while stack and x > nums[stack[-1]]: + res[stack[-1]] = x + stack.pop() + + return res \ No newline at end of file diff --git "a/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" "b/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" new file mode 100644 index 0000000..4dbfe25 --- /dev/null +++ "b/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" @@ -0,0 +1,21 @@ +class Solution: + def findRelativeRanks(self, score: List[int]) -> List[str]: + p = [[score[i], i] for i in range(len(score))] + + p.sort(key = lambda x: -x[0]) + + res = [0 for _ in score] + for index, pair in enumerate(p): + score, original_index = pair[0], pair[1] + + if index == 0: + val = "Gold Medal" + elif index == 1: + val = "Silver Medal" + elif index == 2: + val = "Bronze Medal" + else: + val = str(index + 1) + + res[original_index] = val + return res \ No newline at end of file diff --git "a/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274 2.py" "b/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274 2.py" new file mode 100644 index 0000000..c9fbab3 --- /dev/null +++ "b/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274 2.py" @@ -0,0 +1,29 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def findBottomLeftValue(self, root): + """ + :type root: TreeNode + :rtype: int + """ + #灞傚簭閬嶅巻杩斿洖鏈鍚庝竴灞傜涓涓 + from collections import deque + if not root: + return None + queue = deque([root]) + while queue: + res = [] + for _ in range(len(queue)): + cur = queue.popleft() + res.append(cur.val) + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + return res[0] + \ No newline at end of file diff --git "a/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274 2.py" "b/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274 2.py" new file mode 100644 index 0000000..4b14616 --- /dev/null +++ "b/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274 2.py" @@ -0,0 +1,38 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def largestValues(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + + if not root: + return [] + next_layer = [root] + result = [] + while(next_layer): + temp_next_layer = [] + layer_value = [] + for node in next_layer: + if not node: + continue + layer_value.append(node.val) + # print layer_value + if node.left: + temp_next_layer.append(node.left) + if node.right: + temp_next_layer.append(node.right) + + # print temp_next_layer[0].val + next_layer = temp_next_layer + result.append(max(layer_value)) + + + return result + \ No newline at end of file diff --git "a/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" "b/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" new file mode 100644 index 0000000..1304139 --- /dev/null +++ "b/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" @@ -0,0 +1,5 @@ +class Solution: + def findLUSlength(self, a: str, b: str) -> int: + if a == b: + return -1 + return max(len(a), len(b)) \ No newline at end of file diff --git "a/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221 2.py" "b/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221 2.py" new file mode 100644 index 0000000..4ce2343 --- /dev/null +++ "b/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221 2.py" @@ -0,0 +1,29 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def convertBST(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + #右中左的遍历顺序 + if not root: + return root + self.s = 0 + + def convert(node): + if not node: + return + + convert(node.right) + node.val += self.s + self.s = node.val + convert(node.left) + + convert(root) + return root \ No newline at end of file diff --git "a/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III 2.py" "b/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III 2.py" new file mode 100644 index 0000000..baad7cf --- /dev/null +++ "b/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def reverseWords(self, s): + """ + :type s: str + :rtype: str + """ + return " ".join(word[::-1] for word in s.split(" ")) \ No newline at end of file diff --git "a/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206 2.py" "b/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206 2.py" new file mode 100644 index 0000000..d6ef697 --- /dev/null +++ "b/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206 2.py" @@ -0,0 +1,20 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val=None, children=None): + self.val = val + self.children = children +""" +class Solution(object): + def preorder(self, root): + """ + :type root: Node + :rtype: List[int] + """ + if not root: + return [] + + res = [root.val] + for child in root.children: + res += self.preorder(child) + return res \ No newline at end of file diff --git "a/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206 2.py" "b/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206 2.py" new file mode 100644 index 0000000..bd35385 --- /dev/null +++ "b/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206 2.py" @@ -0,0 +1,19 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val=None, children=None): + self.val = val + self.children = children +""" +class Solution(object): + def postorder(self, root): + """ + :type root: Node + :rtype: List[int] + """ + if not root: + return [] + res = [] + for child in root.children: + res += self.postorder(child) + return res + [root.val] \ No newline at end of file diff --git "a/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221 2.py" "b/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221 2.py" new file mode 100644 index 0000000..a708dc1 --- /dev/null +++ "b/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221 2.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def mergeTrees(self, t1, t2): + """ + :type t1: TreeNode + :type t2: TreeNode + :rtype: TreeNode + """ + if not t1: + return t2 + if not t2: + return t1 + t1.val += t2.val + t1.left = self.mergeTrees(t1.left, t2.left) + t1.right = self.mergeTrees(t1.right, t2.right) + return t1 + \ No newline at end of file diff --git "a/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274 2.py" "b/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274 2.py" new file mode 100644 index 0000000..0f29e9f --- /dev/null +++ "b/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274 2.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def averageOfLevels(self, root): + """ + :type root: TreeNode + :rtype: List[float] + """ + from collections import deque + if not root: + return [] + queue = deque([root]) + res = [] + while queue: + layer = [] + for _ in range(len(queue)): + cur = queue.popleft() + if cur: + layer.append(cur.val) + queue += [cur.left, cur.right] + if layer: + res.append(sum(layer) * 1.0 / len(layer)) + return res diff --git "a/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..6005f43 --- /dev/null +++ "b/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: Optional[TreeNode], k: int) -> bool: + visited = set() + self.res = False + + def inorder(node): + if not node: + return + + inorder(node.left) + + if k - node.val in visited: + self.res = True + visited.add(node.val) + + if not self.res: + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221 2.py" "b/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221 2.py" new file mode 100644 index 0000000..bacac72 --- /dev/null +++ "b/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221 2.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def constructMaximumBinaryTree(self, nums): + """ + :type nums: List[int] + :rtype: TreeNode + """ + if not nums: + return None + root = TreeNode(max(nums)) + root.left = self.constructMaximumBinaryTree(nums[:nums.index(root.val)]) + root.right = self.constructMaximumBinaryTree(nums[nums.index(root.val)+1:]) + return root + \ No newline at end of file diff --git "a/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271 2.py" "b/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271 2.py" new file mode 100644 index 0000000..8363e03 --- /dev/null +++ "b/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def judgeCircle(self, moves): + """ + :type moves: str + :rtype: bool + """ + return moves.count('U')==moves.count('D') and moves.count('R')==moves.count('L') \ No newline at end of file diff --git "a/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" "b/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" new file mode 100644 index 0000000..90330a6 --- /dev/null +++ "b/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" @@ -0,0 +1,20 @@ +class Solution: + def validPalindrome(self, s: str) -> bool: + delete = False + left, right = 0, len(s) - 1 + + while left < right: + if s[left] != s[right]: + if not delete: + delete = True + break + left += 1 + right -= 1 + + if delete: + s1 = s[:left] + s[left + 1:] + s2 = s[:right] + s[right + 1:] + return s1 == s1[::-1] or s2 == s2[::-1] + else: + return True + \ No newline at end of file diff --git "a/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233 2.py" "b/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233 2.py" new file mode 100644 index 0000000..7488253 --- /dev/null +++ "b/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233 2.py" @@ -0,0 +1,19 @@ +class Solution(object): + def calPoints(self, ops): + """ + :type ops: List[str] + :rtype: int + """ + stack = list() + for i, op in enumerate(ops): + # print stack + if op == "+": + stack.append(stack[-1] + stack[-2]) + elif op == "D": + stack.append(2 * stack[-1]) + elif op == "C": + stack.pop() + else: + stack.append(int(op)) + + return sum(stack) \ No newline at end of file diff --git "a/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242 2.py" "b/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242 2.py" new file mode 100644 index 0000000..6576874 --- /dev/null +++ "b/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242 2.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def searchBST(self, root, val): + """ + :type root: TreeNode + :type val: int + :rtype: TreeNode + """ + if not root or root.val == val: + return root + + if root.val > val: + return self.searchBST(root.left, val) + elif root.val < val: + return self.searchBST(root.right, val) \ No newline at end of file diff --git "a/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204 2.py" "b/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..607236b --- /dev/null +++ "b/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204 2.py" @@ -0,0 +1,19 @@ +class Solution(object): + def search(self, reader, target): + """ + :type reader: ArrayReader + :type target: int + :rtype: int + """ + i = 0 + tmp = reader.get(i) + if tmp > target: #target比第一个元素都小,所以不存在 + return -1 + while tmp != 2147483647: + if tmp == target: #找到了 + return i + if tmp > target: #后面的元素都比target大,找不到 + break + i += 1 + tmp = reader.get(i) + return -1 \ No newline at end of file diff --git "a/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" "b/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" new file mode 100644 index 0000000..4f478f0 --- /dev/null +++ "b/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" @@ -0,0 +1,22 @@ +import heapq +class KthLargest: + def __init__(self, k: int, nums: List[int]): + self.k = k + self.min_heap = [] + for num in nums: + if len(self.min_heap) < k: + heappush(self.min_heap, num) + else: + heappushpop(self.min_heap, num) + + def add(self, val: int) -> int: + if len(self.min_heap) < self.k: + heappush(self.min_heap, val) + else: + heappushpop(self.min_heap, val) + return self.min_heap[0] + + +# Your KthLargest object will be instantiated and called as such: +# obj = KthLargest(k, nums) +# param_1 = obj.add(val) \ No newline at end of file diff --git "a/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215 2.py" "b/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215 2.py" new file mode 100644 index 0000000..3ba9795 --- /dev/null +++ "b/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def toLowerCase(self, str): + """ + :type str: str + :rtype: str + """ + return str.lower() + \ No newline at end of file diff --git "a/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" "b/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" new file mode 100644 index 0000000..a5c61b3 --- /dev/null +++ "b/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" @@ -0,0 +1,15 @@ +class Solution: + def isOneBitCharacter(self, bits: List[int]) -> bool: + connected_with_prev = False + + for i, bit in enumerate(bits): + if connected_with_prev: + if i == len(bits) - 1: + return False + connected_with_prev = False + else: + if bit == 1: + connected_with_prev = True + else: + connected_with_prev = False + return True \ No newline at end of file diff --git "a/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" "b/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" new file mode 100644 index 0000000..cc285bb --- /dev/null +++ "b/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def partition(self, head: Optional[ListNode], x: int) -> Optional[ListNode]: + dummy1 = ListNode(-1) + dummy2 = ListNode(-1) + + smaller_list = dummy1 + larger_list = dummy2 + p = head + while p: + if p.val < x: + new_node = ListNode(p.val) + smaller_list.next = new_node + smaller_list = smaller_list.next + else: + new_node = ListNode(p.val) + larger_list.next = new_node + larger_list = larger_list.next + p = p.next + + smaller_list.next = dummy2.next + return dummy1.next diff --git "a/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257 2.py" "b/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257 2.py" new file mode 100644 index 0000000..8d8e3ed --- /dev/null +++ "b/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257 2.py" @@ -0,0 +1,18 @@ +class Solution(object): + def minCostClimbingStairs(self, cost): + """ + :type cost: List[int] + :rtype: int + """ + # dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i] + + l = len(cost) + + dp = [0 for _ in range(l + 1)] + + dp[0], dp[1] = cost[0], cost[1] + + for i in range(2, l): + dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i] + + return min(dp[l - 1], dp[l - 2]) \ No newline at end of file diff --git "a/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" "b/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" new file mode 100644 index 0000000..bd10cee --- /dev/null +++ "b/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" @@ -0,0 +1,10 @@ +class Solution: + def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]: + res = [] + + for i in range(len(arr)): + for j in range(i + 1, len(arr)): + res.append((arr[i], arr[j], arr[i] * 1.0 / arr[j])) + + res.sort(key = lambda x: x[2]) + return [res[k - 1][0], res[k - 1][1]] \ No newline at end of file diff --git "a/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215 2.py" "b/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215 2.py" new file mode 100644 index 0000000..b6fab5d --- /dev/null +++ "b/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def uniqueMorseRepresentations(self, words): + """ + :type words: List[str] + :rtype: int + """ + moore = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] + queue = set() + + for word in words: + temp = "" + for char in word: + temp += moore[ord(str(char)) - ord("a")] + queue.add(temp) + + return len(queue) \ No newline at end of file diff --git "a/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277 2.py" "b/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277 2.py" new file mode 100644 index 0000000..3632801 --- /dev/null +++ "b/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277 2.py" @@ -0,0 +1,22 @@ +class Solution(object): + def maxIncreaseKeepingSkyline(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + length = len(grid) + if length == 0: + return 0 + res = 0 + + for i in range(0, length): + for j in range(0, length): + rowMax = 0 + colomnMax = 0 + for t in range(0,length): + rowMax = max(grid[i][t],rowMax) + colomnMax = max(grid[t][j],colomnMax) + print rowMax, colomnMax + res += min(colomnMax,rowMax ) - grid[i][j] + return res + \ No newline at end of file diff --git "a/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217 2.py" "b/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217 2.py" new file mode 100644 index 0000000..9de6750 --- /dev/null +++ "b/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217 2.py" @@ -0,0 +1,11 @@ +class Solution(object): + def flipAndInvertImage(self, A): + """ + :type A: List[List[int]] + :rtype: List[List[int]] + """ + res = list() + for a in A: + a.reverse() + res.append((1 - i) for i in a) + return res \ No newline at end of file diff --git "a/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225 2.py" "b/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225 2.py" new file mode 100644 index 0000000..8c8b2ba --- /dev/null +++ "b/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225 2.py" @@ -0,0 +1,18 @@ +class Solution(object): + def peakIndexInMountainArray(self, A): + """ + :type A: List[int] + :rtype: int + """ + left = 0 + right = len(A) - 1 + while( left <= right): + mid = left + (right - left) / 2 + if A[mid - 1] < A[mid] < A[mid + 1]: + left = mid + 1 + elif A[mid - 1] > A[mid] > A[mid + 1]: + right = mid -1 + else: + break + print mid + return mid \ No newline at end of file diff --git "a/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" "b/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" new file mode 100644 index 0000000..39ec0a9 --- /dev/null +++ "b/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]: + slow, fast = head, head + while fast and fast.next: + fast = fast.next.next + slow = slow.next + + return slow \ No newline at end of file diff --git "a/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" "b/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..c2d6aa1 --- /dev/null +++ "b/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def increasingBST(self, root: TreeNode) -> TreeNode: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + inorder_list = inorder(root) + dummy = TreeNode(-1) + p = dummy + for val in inorder_list: + p.right = TreeNode(val) + p = p.right + + return dummy.right \ No newline at end of file diff --git "a/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204 2.py" "b/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..3e624db --- /dev/null +++ "b/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def sortArray(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + return sorted(nums) + \ No newline at end of file diff --git "a/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214 2.py" "b/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214 2.py" new file mode 100644 index 0000000..c707469 --- /dev/null +++ "b/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214 2.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def rangeSumBST(self, root, L, R): + """ + :type root: TreeNode + :type L: int + :type R: int + :rtype: int + """ + res = 0 + + if not root: + return 0 + if L <= root.val <= R: + res += root.val + if root.val < R: + res += self.rangeSumBST(root.right, L, R) + if root.val > L: + res += self.rangeSumBST(root.left, L, R) + + return res + \ No newline at end of file diff --git "a/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271 2.py" "b/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271 2.py" new file mode 100644 index 0000000..bc478a3 --- /dev/null +++ "b/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271 2.py" @@ -0,0 +1,9 @@ +class Solution(object): + def kClosest(self, points, K): + """ + :type points: List[List[int]] + :type K: int + :rtype: List[List[int]] + """ + return sorted(points, key = lambda x:x[0] **2 + x[1] ** 2)[:K] + \ No newline at end of file diff --git "a/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..94069fb --- /dev/null +++ "b/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]: + if not preorder: + return None + + root = TreeNode(preorder[0]) + hasRight = False + for i, val in enumerate(preorder): + if val > root.val: + right_index = i + hasRight = True + break + + + if hasRight: + root.left = self.bstFromPreorder(preorder[1:right_index]) + root.right = self.bstFromPreorder(preorder[right_index:]) + else: + root.left = self.bstFromPreorder(preorder[1:]) + return root + diff --git "a/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233 2.py" "b/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233 2.py" new file mode 100644 index 0000000..f620fd4 --- /dev/null +++ "b/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233 2.py" @@ -0,0 +1,27 @@ +class Solution(object): + def shipWithinDays(self, weights, D): + """ + :type weights: List[int] + :type D: int + :rtype: int + """ + lo, hi = max(weights), sum(weights) + while(lo <= hi): + mid = (lo + hi) // 2 # mid 即为当前运送的capacity + + #------以下为模拟运货的过程,temp表示当前这条船承载的重量,day表示已用的天数------- + temp = 0 + day = 1 + for weight in weights: + temp += weight + if temp > mid:# 当前货运不动 + day += 1 + temp = weight + #------以上为模拟运货的过程----------------- + + if day > D: # 当前的capacity太小了,不够,需要更大容量才能及时运完 + lo = mid + 1 + elif day <= D: + hi = mid - 1 + + return lo \ No newline at end of file diff --git "a/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262 2.py" "b/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262 2.py" new file mode 100644 index 0000000..f64c8c7 --- /dev/null +++ "b/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262 2.py" @@ -0,0 +1,13 @@ +class Solution(object): + def queryString(self, S, N): + """ + :type S: str + :type N: int + :rtype: bool + """ + for i in range(1, N + 1): + # print str(bin(i)[2:]) + if str(bin(i)[2:]) not in S: + return False + + return True \ No newline at end of file diff --git "a/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242 2.py" "b/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242 2.py" new file mode 100644 index 0000000..4d5641d --- /dev/null +++ "b/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def baseNeg2(self, N): + """ + :type N: int + :rtype: str + """ + res = [] + # n = N + while N: + # b = N % -2 + # N = N //-2 + N, b = divmod(N, 2) + N = -N + res.append(str(b)) + return "".join(res[::-1]) or "0" + # return "0" if not n else "".join(res[::-1]) diff --git "a/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271 2.py" "b/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..842ee77 --- /dev/null +++ "b/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271 2.py" @@ -0,0 +1,35 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def nextLargerNodes(self, head): + """ + :type head: ListNode + :rtype: List[int] + """ + h = head + l = list() + while(h): #这个循环是为了把链表转数组 + l.append(h.val) + h = h.next + + stack = list() + res = [0 for i in range(len(l))] + + cnt = 0 + while(cnt < len(l)): #从前到后线性扫描 + if not stack or l[stack[-1]] >= l[cnt]: #如果stack为空,或者当前栈顶对应的元素比当前扫描元素还大 + stack.append(cnt)#就直接把当前下标压入栈 + else:#如果当前下标对应的元素比栈顶元素大,就说明找到了比栈顶元素大的下一个数 + while(stack and l[stack[-1]] < l[cnt]): #一直出栈,直到栈顶元素比当前元素小 + res[stack[-1]] = l[cnt] + stack.pop() + stack.append(cnt) #把当前元素压入栈 + + cnt += 1 + + return res + \ No newline at end of file diff --git "a/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267 2.py" "b/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267 2.py" new file mode 100644 index 0000000..096cda4 --- /dev/null +++ "b/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267 2.py" @@ -0,0 +1,24 @@ +class Solution(object): + def removeOuterParentheses(self, S): + """ + :type S: str + :rtype: str + """ + s = list() + l,r = 0, 0 + res = "" + for i, x in enumerate(S): + if x == "(": + s.append(x) + l += 1 + elif x == ")": + r += 1 + if l == r: + print s[1:] + res += "".join(s[1:]) #s[0]和新来的x= ")"刚好构成最外层的"()",所以不要它们就好啦 + s = list() + else: + s.append(x) + + return res + \ No newline at end of file diff --git "a/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214 2.py" "b/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214 2.py" new file mode 100644 index 0000000..3a4b1a9 --- /dev/null +++ "b/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214 2.py" @@ -0,0 +1,37 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def sumRootToLeaf(self, root): + """ + :type root: TreeNode + :rtype: int + """ + res = [] + + def dfs(root, tmp): + if not root: + return + tmp += str(root.val) + if not root.left and not root.right: + res.append(tmp[:]) + + dfs(root.left, tmp) + dfs(root.right, tmp) + tmp = tmp[:-1] + + + + dfs(root, "") + # print res + rres = 0 + for item in res: + # print item, int(item, 2) + rres += int(item, 2) + rres %= (10 ** 9 + 7) + + return rres \ No newline at end of file diff --git "a/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221 2.py" "b/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221 2.py" new file mode 100644 index 0000000..7dcbbaa --- /dev/null +++ "b/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221 2.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def bstToGst(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + self.sum = 0 + + def inorder(node): + if not node: + return + + inorder(node.right) + self.sum += node.val + node.val = self.sum + inorder(node.left) + + inorder(root) + return root \ No newline at end of file diff --git "a/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" "b/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" new file mode 100644 index 0000000..f78cd85 --- /dev/null +++ "b/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" @@ -0,0 +1,16 @@ +from heapq import * +class Solution: + def lastStoneWeight(self, stones: List[int]) -> int: + max_heap = [] + + for stone in stones: + heappush(max_heap, -stone) + + while len(max_heap) > 1: + x, y = -heappop(max_heap), -heappop(max_heap) + + if y == x: + continue + else: + heappush(max_heap, -(x - y)) + return -max_heap[0] if max_heap else 0 \ No newline at end of file diff --git "a/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201 2.py" "b/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201 2.py" new file mode 100644 index 0000000..f5fc68f --- /dev/null +++ "b/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201 2.py" @@ -0,0 +1,34 @@ +class Solution(object): + def rearrangeBarcodes(self, barcodes): + """ + :type barcodes: List[int] + :rtype: List[int] + """ + from collections import Counter + import heapq + + record = Counter(barcodes) #统计每个数字出现的频率 + + queue = [] + for key, val in record.items(): + queue.append([-val, key]) + + heapq.heapify(queue) #建立优先级队列 + + res = [] + pre = None + while queue or pre: + if queue: + cur = heapq.heappop(queue) #取出当前出现次数最多的元素,如果次数相同则先进先出 + #frequency, value = cur[0], cur[1] + res.append(cur[1]) #把它放到答案里 + cur[0] += 1 #给它的频率 - 1,因为Python支持最小堆,为了达到最大堆的效果,所以取了相反数操作 + if cur[0] == 0: #这个元素已经放好了 + cur = None + else: + cur = None + if pre: #把前一个插入的数再进行入堆操作 + heapq.heappush(queue, pre) + pre = cur #把这一轮的数用pre保存起来,此时这个数不在堆里,可以保障相邻元素不会重复 + + return res diff --git "a/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" "b/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" new file mode 100644 index 0000000..91c5e98 --- /dev/null +++ "b/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" @@ -0,0 +1,20 @@ +class Solution: + def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]: + res = self.convertToDec(arr1) + self.convertToDec(arr2) + l = [] + if res == 0: + return [0] + while res: + d, m = divmod(res, -2) + res = - (res // 2) + l.append(-m) + return l[::-1] + + def convertToDec(self, arr): + res = 0 + for index, digit in enumerate(arr[::-1]): + res += digit * ((-2) ** index) + return res + + + \ No newline at end of file diff --git "a/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" "b/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" new file mode 100644 index 0000000..a61a8f3 --- /dev/null +++ "b/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" @@ -0,0 +1,14 @@ +class Solution: + def numTilePossibilities(self, tiles: str) -> int: + res = set([""]) + + for tile in tiles: + new_res = set() + for r in res: + for i in range(len(r) + 1): + t = r[:i] + tile + r[i:] + if t not in res: + new_res.add(t) + res = res.union(new_res) + + return len(res) - 1 \ No newline at end of file diff --git "a/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" "b/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" new file mode 100644 index 0000000..96e16b6 --- /dev/null +++ "b/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" @@ -0,0 +1,44 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sufficientSubset(self, root: Optional[TreeNode], limit: int) -> Optional[TreeNode]: + survivor_nodes = set() + + def dfs(node, path): + if not node: + return + # path.append(node) + if not node.left and not node.right: + path.append(node) + path_sum = 0 + for n in path: + path_sum += n.val + if path_sum >= limit: + for n in path: + survivor_nodes.add(n) + return + dfs(node.left, path + [node]) + dfs(node.right, path + [node]) + + dfs(root, []) + # print(survivor_nodes) + def killNodes(node): + if not node: + return + + if node.left not in survivor_nodes: + node.left = None + if node.right not in survivor_nodes: + node.right = None + + killNodes(node.left) + killNodes(node.right) + + if root not in survivor_nodes: + return None + killNodes(root) + return root \ No newline at end of file diff --git "a/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204 2.py" "b/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204 2.py" new file mode 100644 index 0000000..ea73840 --- /dev/null +++ "b/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204 2.py" @@ -0,0 +1,35 @@ +from collections import deque +class Solution(object): + def shortestPathBinaryMatrix(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + n = len(grid) + # print n + + if grid[0][0] or grid[-1][-1] == 1: + return -1 + queue = deque([[[0, 0], 1]]) + # queue2 = deque([[[n -1 , n - 1], 1]]) + visited = set((0,0)) + dx = [1, -1, 0, 0, 1, -1, -1, 1] + dy = [0, 0, 1, -1, -1, 1, -1, 1] + cnt = 1 + record = dict() + while queue: + cur, cnt = queue.popleft() + # print cur, cnt + x0, y0 = cur[0], cur[1] + + if x0 == n - 1 and y0 == n - 1: + return cnt + for k in range(8): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x = cnt: + res[i] += cnt + candies -= cnt + cnt += 1 + else: + res[i] += candies + candies = 0 + break + return res \ No newline at end of file diff --git "a/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" "b/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" new file mode 100644 index 0000000..b9c7c37 --- /dev/null +++ "b/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" @@ -0,0 +1,4 @@ +class Solution: + def defangIPaddr(self, address: str) -> str: + + return address.replace(".", "[.]") \ No newline at end of file diff --git "a/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" "b/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" new file mode 100644 index 0000000..bd49588 --- /dev/null +++ "b/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]: + to_delete = set(to_delete) + res = [] + def dfs(node, node_is_new_root): + if not node: + return + left = node.left + right = node.right + if node_is_new_root and node.val not in to_delete: + res.append(node) + if left and left.val in to_delete: + node.left = None + if right and right.val in to_delete: + node.right = None + + dfs(left, node.val in to_delete) + dfs(right, node.val in to_delete) + dfs(root, True) + return res + \ No newline at end of file diff --git "a/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263 2.py" "b/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263 2.py" new file mode 100644 index 0000000..cecdf5c --- /dev/null +++ "b/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def removeVowels(self, S): + """ + :type S: str + :rtype: str + """ + + return "".join(char for char in S if char not in "aeiou") \ No newline at end of file diff --git "a/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" "b/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" new file mode 100644 index 0000000..a72c05c --- /dev/null +++ "b/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" @@ -0,0 +1,12 @@ +class Solution: + def mctFromLeafValues(self, arr: List[int]) -> int: + res = 0 + stack = [16] + for num in arr: + while stack and stack[-1] < num: + res += stack.pop() * min(stack[-1], num) + stack.append(num) + + while len(stack) > 2: + res += stack.pop() * stack[-1] + return res \ No newline at end of file diff --git "a/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246 2.py" "b/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246 2.py" new file mode 100644 index 0000000..5ce1d0d --- /dev/null +++ "b/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246 2.py" @@ -0,0 +1,41 @@ +class Solution(object): + def maxRepOpt1(self, text): + """ + :type text: str + :rtype: int + """ + if len(text) == text.count(text[0]): + return len(text) + record = collections.Counter(text) + start, end = 0, 1 + cur, nxt, idx_nxt = text[0], None, 0 + res = 1 + while end < len(text): + if text[end] != cur : + if nxt is None: + nxt = text[end] #找到了第一个异字符 + idx_nxt = end + else: #当前段已经完成 + l = end - 1 - start + 1 #计算包括一个异字符的同字符子串长度 + if l <= record[text[start]]: #有多的同字符可以把这个夹在中间的同字符换掉 + res = max(res, l) + else: + res = max(res, l - 1) #只能用目前字串的边界同字符跟异字符交换 + + cur = nxt + nxt = None + start, end = idx_nxt, idx_nxt + idx_nxt = 0 + if end == len(text) - 1: #到输入终点了 + # print end + l = end - start + 1 #计算包括一个异字符的同字符子串长度 + # print l + if l <= record[text[start]]: #有多的同字符可以把这个夹在中间的同字符换掉 + res = max(res, l) + else: + res = max(res, l - 1) #只能用目前字串的边界同字符跟异字符交换 + + # print text[start:end + 1] + end += 1 + # print end + return res \ No newline at end of file diff --git "a/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214 2.py" "b/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214 2.py" new file mode 100644 index 0000000..81de25d --- /dev/null +++ "b/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214 2.py" @@ -0,0 +1,33 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def maxLevelSum(self, root): + """ + :type root: TreeNode + :rtype: int + """ + from collections import deque + queue = deque([root]) + + layer = 1 + res = 1 + max_values = 0 + while queue: + values = 0 + for _ in range(len(queue)): + node = queue.popleft() + if node: + values += node.val + queue.append(node.left) + queue.append(node.right) + if values > max_values: + max_values = values + res = layer + layer += 1 + return res + \ No newline at end of file diff --git "a/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230 2.py" "b/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230 2.py" new file mode 100644 index 0000000..9da80b9 --- /dev/null +++ "b/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def calculateTime(self, keyboard, word): + """ + :type keyboard: str + :type word: str + :rtype: int + """ + dic = dict() + for i, char in enumerate(keyboard): + dic[char] = i + + res, cur_pos = 0, 0 + for char in word: + res += abs(dic[char] - cur_pos) + cur_pos = dic[char] + return res diff --git "a/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262 2.py" "b/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262 2.py" new file mode 100644 index 0000000..d3e9c18 --- /dev/null +++ "b/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262 2.py" @@ -0,0 +1,14 @@ +class Solution(object): + def countLetters(self, S): + """ + :type S: str + :rtype: int + """ + res = 0 + for i in range(len(S)): + for j in range(i + 1, len(S) + 1): + substring = S[i:j] + if substring == substring[0] * len(substring): + res += 1 + # print substring + return res \ No newline at end of file diff --git "a/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240 2.py" "b/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240 2.py" new file mode 100644 index 0000000..744f711 --- /dev/null +++ "b/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240 2.py" @@ -0,0 +1,13 @@ +class Solution(object): + def smallestCommonElement(self, mat): + """ + :type mat: List[List[int]] + :rtype: int + """ + from collections import Counter + flatten = sum(mat,[]) + dic = Counter(flatten) + for num in mat[0]: + if dic[num] == len(mat): + return num + return -1 \ No newline at end of file diff --git "a/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262 2.py" "b/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262 2.py" new file mode 100644 index 0000000..6dcc6a1 --- /dev/null +++ "b/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262 2.py" @@ -0,0 +1,21 @@ +class Solution(object): + def balancedStringSplit(self, s): + """ + :type s: str + :rtype: int + """ + if not s: + return 0 + # print s + l, r = 0, 0 + + for i in range(len(s)): + if s[i] == "R": + r += 1 + else: + l += 1 + # print r, l + if l == r: + return 1 + self.balancedStringSplit(s[i + 1:]) + + return 0 \ No newline at end of file diff --git "a/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233 2.py" "b/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233 2.py" new file mode 100644 index 0000000..ba54ff0 --- /dev/null +++ "b/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233 2.py" @@ -0,0 +1,27 @@ +class Solution(object): + def maximizeSweetness(self, sweetness, K): + """ + :type sweetness: List[int] + :type K: int + :rtype: int + """ + if not K: + return sum(sweetness) + left, right = 0, sum(sweetness) // K + res = 0 + while left <= right: + mid = (left + right) // 2 + cnt = 0 + tmp = 0 + for s in sweetness: + if tmp + s > mid: + cnt += 1 + tmp = 0 + else: + tmp += s + + if cnt < K + 1: + right = mid - 1 + else: + left = mid + 1 + return left \ No newline at end of file diff --git "a/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" "b/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" new file mode 100644 index 0000000..b6568c3 --- /dev/null +++ "b/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" @@ -0,0 +1,26 @@ +""" + This is the custom function interface. + You should not implement it, or speculate about its implementation + class CustomFunction: + # Returns f(x, y) for any given positive integers x and y. + # Note that f(x, y) is increasing with respect to both x and y. + # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1) + def f(self, x, y): + +""" + +class Solution: + def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]: + res = [] + for x in range(1, 1001): + left, right = 1, 1001 + while left <= right: + mid = (left + right)// 2 + if customfunction.f(x, mid) == z: + res.append([x, mid]) + break + elif customfunction.f(x, mid) < z: + left = mid + 1 + else: + right = mid - 1 + return res diff --git "a/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256 2.py" "b/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256 2.py" new file mode 100644 index 0000000..be35f2f --- /dev/null +++ "b/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256 2.py" @@ -0,0 +1,22 @@ +class Solution(object): + def oddCells(self, n, m, indices): + """ + :type n: int + :type m: int + :type indices: List[List[int]] + :rtype: int + """ + b = [[0 for _ in range(m)] for _ in range(n)] + for row, col in indices: + for i in range(m): + b[row][i] += 1 + + for j in range(n): + b[j][col] += 1 + + res = 0 + for i in range(n): + for j in range(m): + if b[i][j] % 2: + res += 1 + return res \ No newline at end of file diff --git "a/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" "b/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" new file mode 100644 index 0000000..2f0ce01 --- /dev/null +++ "b/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" @@ -0,0 +1,33 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class FindElements: + + def __init__(self, root: Optional[TreeNode]): + root.val = 0 + self.values = set() + def dfs(node): + if not node: + return + + self.values.add(node.val) + if node.left: + node.left.val = 2 * node.val + 1 + if node.right: + node.right.val = 2 * node.val + 2 + + dfs(node.left) + dfs(node.right) + + dfs(root) + + def find(self, target: int) -> bool: + return target in self.values + + +# Your FindElements object will be instantiated and called as such: +# obj = FindElements(root) +# param_1 = obj.find(target) \ No newline at end of file diff --git "a/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" "b/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" new file mode 100644 index 0000000..1b04458 --- /dev/null +++ "b/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" @@ -0,0 +1,15 @@ +# """ +# This is the ImmutableListNode's API interface. +# You should not implement it, or speculate about its implementation. +# """ +# class ImmutableListNode: +# def printValue(self) -> None: # print the value of this node. +# def getNext(self) -> 'ImmutableListNode': # return the next node. + +class Solution: + def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None: + if not head: + return + + self.printLinkedListInReverse(head.getNext()) + head.printValue() \ No newline at end of file diff --git "a/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" "b/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" new file mode 100644 index 0000000..4e18cba --- /dev/null +++ "b/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" @@ -0,0 +1,13 @@ +class Solution: + def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: + from collections import defaultdict + + size2people = defaultdict(list) + for i, size in enumerate(groupSizes): + size2people[size].append(i) + + res = [] + for size, peoples in size2people.items(): + for i in range(0, len(peoples), size): + res.append(peoples[i: i + size]) + return res \ No newline at end of file diff --git "a/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" "b/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" new file mode 100644 index 0000000..70a5142 --- /dev/null +++ "b/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def getDecimalValue(self, head: ListNode) -> int: + res = 0 + p = head + while p: + res = res * 2 + p.val + p = p.next + return res \ No newline at end of file diff --git "a/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" "b/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" new file mode 100644 index 0000000..fb0b769 --- /dev/null +++ "b/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def deepestLeavesSum(self, root: Optional[TreeNode]) -> int: + queue = [root] + while queue: + level_sum = 0 + next_queue = [] + for node in queue: + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + level_sum += node.val + + queue = next_queue[:] + return level_sum \ No newline at end of file diff --git "a/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" "b/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" new file mode 100644 index 0000000..564b692 --- /dev/null +++ "b/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumEvenGrandparent(self, root: TreeNode) -> int: + self.sum = 0 + def dfs(node, isParentEven, isGrandparentEven): + if not node: + return + + if isGrandparentEven: + self.sum += node.val + + dfs(node.left, node.val % 2 == 0, isParentEven) + dfs(node.right, node.val % 2 == 0, isParentEven) + + dfs(root, False, False) + return self.sum \ No newline at end of file diff --git "a/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" "b/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" new file mode 100644 index 0000000..89e5ff2 --- /dev/null +++ "b/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" @@ -0,0 +1,5 @@ +class Solution: + def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]: + pair = [(i, sum(row)) for i, row in enumerate(mat)] + pair.sort(key = lambda x: x[1]) + return [p[0] for p in pair[:k]] \ No newline at end of file diff --git "a/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212 2.py" "b/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212 2.py" new file mode 100644 index 0000000..201e5f8 --- /dev/null +++ "b/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212 2.py" @@ -0,0 +1,23 @@ +from heapq import * +from collections import Counter +class Solution(object): + def minSetSize(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + t = len(arr) // 2 + dic = Counter(arr) + + queue = [] + for key, val in dic.items(): + heappush(queue, -val) + + cnt = 0 + res = 0 + while cnt < t: + tmp = heappop(queue) + res += 1 + cnt += -tmp + # print cnt, tmp, t + return res \ No newline at end of file diff --git "a/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260 2.py" "b/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260 2.py" new file mode 100644 index 0000000..7a7ef5d --- /dev/null +++ "b/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def countNegatives(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + if not grid or not grid[0]: + return 0 + m, n = len(grid), len(grid[0]) + + res = 0 + for i in range(m): + for j in range(n): + if grid[i][j] < 0: + res += 1 + return res \ No newline at end of file diff --git "a/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262 2.py" "b/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262 2.py" new file mode 100644 index 0000000..e09d933 --- /dev/null +++ "b/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262 2.py" @@ -0,0 +1,9 @@ +class Solution(object): + def generateTheString(self, n): + """ + :type n: int + :rtype: str + """ + if n % 2: + return "a" * n + return "a" * (n - 1) + "b" \ No newline at end of file diff --git "a/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" "b/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" new file mode 100644 index 0000000..8c9b498 --- /dev/null +++ "b/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode: + queue = [cloned] + while queue: + next_queue = [] + for node in queue: + if node: + if node.val == target.val: + return node + next_queue.append(node.left) + next_queue.append(node.right) + queue = next_queue[:] + \ No newline at end of file diff --git "a/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204 2.py" "b/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..0c987fe --- /dev/null +++ "b/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204 2.py" @@ -0,0 +1,11 @@ +class Solution(object): + def createTargetArray(self, nums, index): + """ + :type nums: List[int] + :type index: List[int] + :rtype: List[int] + """ + res = [] + for i in range(len(nums)): + res.insert(index[i], nums[i]) + return res \ No newline at end of file diff --git "a/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" "b/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" new file mode 100644 index 0000000..edec649 --- /dev/null +++ "b/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" @@ -0,0 +1,9 @@ +class Solution: + def processQueries(self, queries: List[int], m: int) -> List[int]: + P = [i for i in range(1, m + 1)] + res = [] + for query in queries: + index = P.index(query) + res.append(index) + P = [P[index]] + P[:index] + P[index + 1:] + return res \ No newline at end of file diff --git "a/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" "b/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" new file mode 100644 index 0000000..d0936a2 --- /dev/null +++ "b/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" @@ -0,0 +1,23 @@ +class Solution: + def displayTable(self, orders: List[List[str]]) -> List[List[str]]: + from collections import defaultdict + table_set = set() + tablefood2cnt = defaultdict(int) + food_set = set() + + for order in orders: + table, food = order[1], order[2] + food_set.add(food) + table_set.add(table) + tablefood2cnt[table + "-" + food] += 1 + + sorted_table = sorted(list(table_set), key = lambda x: int(x)) + sorted_food = sorted(list(food_set)) + res = [["Table"] + sorted_food] + + for table in sorted_table: + temp = [table] + for f in sorted_food: + temp.append(str(tablefood2cnt[table + "-" + f])) + res.append(temp) + return res \ No newline at end of file diff --git "a/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231 2.py" "b/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231 2.py" new file mode 100644 index 0000000..e065712 --- /dev/null +++ "b/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def destCity(self, paths): + """ + :type paths: List[List[str]] + :rtype: str + """ + return (set(pair[1] for pair in paths) - set(pair[0] for pair in paths)).pop() \ No newline at end of file diff --git "a/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" "b/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" new file mode 100644 index 0000000..1659fd7 --- /dev/null +++ "b/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" @@ -0,0 +1,24 @@ +from heapq import * +class Solution: + def kthSmallest(self, mat: List[List[int]], k: int) -> int: + m, n = len(mat), len(mat[0]) + min_sum = sum([mat[i][0] for i in range(m)]) + min_heap = [(min_sum, [0 for i in range(m)])] + cur = 0 + visited = set() + while cur < k: + s, indices = heappop(min_heap) + cur += 1 + if cur == k: + return s + + for i in range(m): + if indices[i] + 1 < n: + nxt_s = s - mat[i][indices[i]] + mat[i][indices[i] + 1] + nxt_indices = indices[:] + nxt_indices[i] += 1 + str_indices = "".join([str(i) for i in nxt_indices]) + if str_indices not in visited: + visited.add(str_indices) + heappush(min_heap, (nxt_s, nxt_indices)) + \ No newline at end of file diff --git "a/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204 2.py" "b/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..020d531 --- /dev/null +++ "b/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204 2.py" @@ -0,0 +1,29 @@ +class Solution(object): + def buildArray(self, target, n): + """ + :type target: List[int] + :type n: int + :rtype: List[str] + """ + pre = 1 + res = [] + for i, num in enumerate(target): + if i == 0: + res += (num - pre) * ["Push", "Pop"] + ["Push"] + else: + res += (num - pre - 1) * ["Push", "Pop"] + ["Push"] + pre = num + return res + +# i = 0 #index +# j = 1 #num for num in range(1, n) +# res = [] +# while i < len(target): +# if target[i] == j: +# res += ["Push"] +# i += 1 +# else: +# res += ["Push", "Pop"] +# j += 1 + +# return res \ No newline at end of file diff --git "a/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257 2.py" "b/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257 2.py" new file mode 100644 index 0000000..4a1af45 --- /dev/null +++ "b/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def maxProduct(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + l = sorted(nums) + return (l[-1] - 1) * (l[-2] - 1) \ No newline at end of file diff --git "a/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271 2.py" "b/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..9dba7a0 --- /dev/null +++ "b/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271 2.py" @@ -0,0 +1,30 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution(object): + def getLonelyNodes(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + self.res = [] + def dfs(node, siblings_cnt): + if not node: + return + + if siblings_cnt == 1: + self.res.append(node.val) + + siblings_cnt = 0 + if node.left: + siblings_cnt += 1 + if node.right: + siblings_cnt += 1 + dfs(node.left, siblings_cnt) + dfs(node.right, siblings_cnt) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204 2.py" "b/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204 2.py" new file mode 100644 index 0000000..274e58a --- /dev/null +++ "b/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204 2.py" @@ -0,0 +1,12 @@ +class Solution(object): + def shuffle(self, nums, n): + """ + :type nums: List[int] + :type n: int + :rtype: List[int] + """ + res = [] + for i in range(n): + res.append(nums[i]) + res.append(nums[i + n]) + return res \ No newline at end of file diff --git "a/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274 2.py" "b/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274 2.py" new file mode 100644 index 0000000..41ad968 --- /dev/null +++ "b/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274 2.py" @@ -0,0 +1,20 @@ +class Solution(object): + def finalPrices(self, prices): + """ + :type prices: List[int] + :rtype: List[int] + """ + stack = [] + res = [] + for i in range(len(prices) - 1, -1, -1): + if not stack: + res.append(prices[i]) + else: + while stack and stack[-1] > prices[i]: + stack.pop() + if stack: + res.append(prices[i] - stack[-1]) + else: + res.append(prices[i]) + stack.append(prices[i]) + return res[::-1] \ No newline at end of file diff --git "a/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" "b/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..df3e01c --- /dev/null +++ "b/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,41 @@ +# Definition for Node. +# class Node: +# def __init__(self, val=0, left=None, right=None, random=None): +# self.val = val +# self.left = left +# self.right = right +# self.random = random + +from collections import deque +class Solution: + def copyRandomBinaryTree(self, root: 'Optional[Node]') -> 'Optional[NodeCopy]': + if not root: + return root + + old2new = dict() + queue = deque([root]) + while queue: + cur_node = queue.popleft() + new_node = NodeCopy(cur_node.val) + old2new[cur_node] = new_node + + if cur_node.left: + queue.append(cur_node.left) + if cur_node.right: + queue.append(cur_node.right) + + queue = deque([root]) + while queue: + cur_node = queue.popleft() + new_node = old2new[cur_node] + + if cur_node.left: + new_node.left = old2new[cur_node.left] + queue.append(cur_node.left) + if cur_node.right: + new_node.right = old2new[cur_node.right] + queue.append(cur_node.right) + if cur_node.random: + new_node.random = old2new[cur_node.random] + + return old2new[root] \ No newline at end of file diff --git "a/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262 2.py" "b/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262 2.py" new file mode 100644 index 0000000..6ddd80a --- /dev/null +++ "b/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262 2.py" @@ -0,0 +1,11 @@ +class Solution(object): + def restoreString(self, s, indices): + """ + :type s: str + :type indices: List[int] + :rtype: str + """ + res = ["" for _ in indices] + for i in range(len(s)): + res[indices[i]] = s[i] + return "".join(ch for ch in res) \ No newline at end of file diff --git "a/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" "b/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" new file mode 100644 index 0000000..8cb54d6 --- /dev/null +++ "b/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" @@ -0,0 +1,18 @@ +class Solution: + def maxDistance(self, position: List[int], m: int) -> int: + position.sort() + left, right = 1, position[-1] - position[0] + while left <= right: + mid = (left + right) // 2 # target answer + + cnt, prev = 1, position[0] + for p in position: + if prev + mid <= p: # find another possible position + cnt += 1 + prev = p + + if cnt >= m: + left = mid + 1 + elif cnt < m: + right = mid - 1 + return right \ No newline at end of file diff --git "a/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250 2.py" "b/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250 2.py" new file mode 100644 index 0000000..ecf5e8f --- /dev/null +++ "b/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250 2.py" @@ -0,0 +1,13 @@ +class Solution(object): + def minOperations(self, logs): + """ + :type logs: List[str] + :rtype: int + """ + steps = 0 + for log in logs: + if log == "../" and steps: + steps -= 1 + elif log not in ["../", "./"]: + steps += 1 + return steps \ No newline at end of file diff --git "a/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237 2.py" "b/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237 2.py" new file mode 100644 index 0000000..3259d52 --- /dev/null +++ "b/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237 2.py" @@ -0,0 +1,24 @@ +class ParkingSystem(object): + + def __init__(self, big, medium, small): + """ + :type big: int + :type medium: int + :type small: int + """ + self.space = [0, big, medium, small] + + def addCar(self, carType): + """ + :type carType: int + :rtype: bool + """ + if self.space[carType]: + self.space[carType] -= 1 + return True + return False + + +# Your ParkingSystem object will be instantiated and called as such: +# obj = ParkingSystem(big, medium, small) +# param_1 = obj.addCar(carType) \ No newline at end of file diff --git "a/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246 2.py" "b/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246 2.py" new file mode 100644 index 0000000..6944a1f --- /dev/null +++ "b/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246 2.py" @@ -0,0 +1,16 @@ +class Solution(object): + def maxDepth(self, s): + """ + :type s: str + :rtype: int + """ + depth = 0 + res = 0 + for ch in s: + if ch == "(": + depth += 1 + res = max(res, depth) + elif ch == ")": + depth -= 1 + + return res \ No newline at end of file diff --git "a/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" "b/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" new file mode 100644 index 0000000..4b6cd69 --- /dev/null +++ "b/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: + dummy = ListNode(-1) + dummy.next = list1 + prev, cur = dummy, list1 + left, right = None, None + count = 0 + while cur: + if count == a: + left = prev + + if count == b: + right = cur.next + + count += 1 + prev, cur = cur, cur.next + + left.next = list2 + p = list2 + while p and p.next: + p = p.next + p.next = right + return dummy.next \ No newline at end of file diff --git "a/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" "b/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" new file mode 100644 index 0000000..c6d4300 --- /dev/null +++ "b/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" @@ -0,0 +1,21 @@ +class Solution: + def interpret(self, command: str) -> str: + res = "" + stack = [] + for char in command: + if char == "G": + res += char + elif char == "(": + stack.append(char) + elif char == ")": + if stack and stack[-1] == "(": + res += "o" + stack.pop() + else: + res += "al" + stack.pop() + stack.pop() + stack.pop() + else: + stack.append(char) + return res diff --git "a/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" "b/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" new file mode 100644 index 0000000..50a8100 --- /dev/null +++ "b/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution: + def numberOfMatches(self, n: int) -> int: + res = 0 + while n != 1: + if n % 2: + res += (n - 1) // 2 + n = (n - 1) // 2 + 1 + else: + res += n // 2 + n = n // 2 + return res \ No newline at end of file diff --git "a/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" "b/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" new file mode 100644 index 0000000..1f1db8c --- /dev/null +++ "b/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" @@ -0,0 +1,16 @@ +class Solution: + def countStudents(self, students: List[int], sandwiches: List[int]) -> int: + from collections import deque + students = deque(students) + while sandwiches: + cur, l = 0, len(students) + while cur < l: + student = students.popleft() + if student == sandwiches[0]: + break + students.append(student) + cur += 1 + if cur == l: + break + sandwiches = sandwiches[1:] + return len(students) \ No newline at end of file diff --git "a/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" "b/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" new file mode 100644 index 0000000..b9a2ae4 --- /dev/null +++ "b/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" @@ -0,0 +1,8 @@ +class Solution: + def halvesAreAlike(self, s: str) -> bool: + s1, s2 = s[:len(s) // 2], s[len(s) // 2:] + return self.countVowels(s1) == self.countVowels(s2) + + def countVowels(self, s): + vowels = "aeiouAEIOU" + return sum(char in vowels for char in s) \ No newline at end of file diff --git "a/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" "b/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" new file mode 100644 index 0000000..efc2c51 --- /dev/null +++ "b/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" @@ -0,0 +1,6 @@ +class Solution: + def decode(self, encoded: List[int], first: int) -> List[int]: + res = [first] + for num in encoded: + res.append(res[-1] ^ num) + return res \ No newline at end of file diff --git "a/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" "b/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..61bb471 --- /dev/null +++ "b/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def swapNodes(self, head: Optional[ListNode], k: int) -> Optional[ListNode]: + p = head + l = 0 + while p: + l += 1 + p = p.next + + reversed_k = l - k + 1 + + count = 0 + p = head + while p: + count += 1 + if count == k: + left_node = p + if count == reversed_k: + right_nnode = p + p = p.next + + left_node.val, right_nnode.val = right_nnode.val, left_node.val + + return head \ No newline at end of file diff --git "a/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" "b/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" new file mode 100644 index 0000000..8dcc9f4 --- /dev/null +++ "b/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" @@ -0,0 +1,24 @@ +from heapq import * +class Solution: + def kthLargestValue(self, matrix: List[List[int]], k: int) -> int: + m, n = len(matrix), len(matrix[0]) + xor_matrix = [[matrix[i][j] for j in range(n)] for i in range(m) ] + min_heap = [] + for i in range(m): + for j in range(n): + if i or j: + if not i: + # the first row + xor_matrix[i][j] ^= xor_matrix[i][j - 1] + elif not j: + xor_matrix[i][j] ^= xor_matrix[i - 1][j] + else: + xor_matrix[i][j] ^= xor_matrix[i][j - 1] ^ xor_matrix[i - 1][j] ^ xor_matrix[i - 1][j - 1] + if len(min_heap) < k: + heappush(min_heap, xor_matrix[i][j]) + else: + heappushpop(min_heap, xor_matrix[i][j]) + + return min_heap[0] + + \ No newline at end of file diff --git "a/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" new file mode 100644 index 0000000..dcb4af2 --- /dev/null +++ "b/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" @@ -0,0 +1,15 @@ +from heapq import * +class Solution: + def maximumScore(self, a: int, b: int, c: int) -> int: + max_heap = [-a, -b, -c] + heapify(max_heap) + res = 0 + while len(max_heap) > 1: + first, second = -heappop(max_heap), -heappop(max_heap) + res += 1 + + if first > 1: + heappush(max_heap, -(first - 1)) + if second > 1: + heappush(max_heap, -(second - 1)) + return res diff --git "a/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" "b/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" new file mode 100644 index 0000000..36e7a7a --- /dev/null +++ "b/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" @@ -0,0 +1,15 @@ +class MRUQueue: + + def __init__(self, n: int): + self.queue = [i for i in range(1, n + 1)] + + def fetch(self, k: int) -> int: + node = self.queue[k - 1] + self.queue = self.queue[:k - 1] + self.queue[k:] + [node] + return node + + + +# Your MRUQueue object will be instantiated and called as such: +# obj = MRUQueue(n) +# param_1 = obj.fetch(k) \ No newline at end of file diff --git "a/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" "b/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" new file mode 100644 index 0000000..ee30caa --- /dev/null +++ "b/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" @@ -0,0 +1,9 @@ +class Solution: + def findBuildings(self, heights: List[int]) -> List[int]: + stack = [] + for i, height in enumerate(heights): + while stack and heights[stack[-1]] <= height: + last_index = stack[-1] + stack.pop() + stack.append(i) + return sorted(stack) \ No newline at end of file diff --git "a/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" "b/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..42dd0b1 --- /dev/null +++ "b/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,12 @@ +class Solution: + def mergeAlternately(self, word1: str, word2: str) -> str: + res = "" + + for index, char1 in enumerate(word1): + res += char1 + if index < len(word2): + res += word2[index] + + if index < len(word2): + res += word2[index + 1:] + return res \ No newline at end of file diff --git "a/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" "b/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" new file mode 100644 index 0000000..f0ad0d4 --- /dev/null +++ "b/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" @@ -0,0 +1,15 @@ +class Solution: + def minOperations(self, boxes: str) -> List[int]: + ones = [] + for index, box in enumerate(boxes): + if box == "1": + ones.append(index) + + res = [] + for index, box in enumerate(boxes): + cur_sum = 0 + for one_index in ones: + cur_sum += abs(one_index - index) + res.append(cur_sum) + + return res diff --git "a/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" "b/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" new file mode 100644 index 0000000..793e12a --- /dev/null +++ "b/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" @@ -0,0 +1,8 @@ +class Solution: + def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: + res = 0 + key2index = {"type":0, "color":1, "name":2} + for item in items: + if item[key2index[ruleKey]] == ruleValue: + res += 1 + return res diff --git "a/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" "b/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" new file mode 100644 index 0000000..33ae741 --- /dev/null +++ "b/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" @@ -0,0 +1,13 @@ +class Solution: + def squareIsWhite(self, coordinates: str) -> bool: + row, col = int(coordinates[1]), ord(coordinates[0]) - ord("a") + # 0 for balck, 1 for white + if col % 2 == 0: + color = 0 + else: + color = 1 + + if row % 2 == 0: + color = 1 - color + return color == 1 + \ No newline at end of file diff --git "a/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245 2.py" "b/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245 2.py" new file mode 100644 index 0000000..502c70e --- /dev/null +++ "b/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245 2.py" @@ -0,0 +1,7 @@ +class Solution(object): + def checkIfPangram(self, sentence): + """ + :type sentence: str + :rtype: bool + """ + return len(set(sentence)) == 26 \ No newline at end of file diff --git "a/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" "b/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" new file mode 100644 index 0000000..ce980fd --- /dev/null +++ "b/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode: + visited = set() + duplicates = set() + p = head + while p: + if p.val not in visited: + visited.add(p.val) + else: + duplicates.add(p.val) + p = p.next + + dummy = ListNode(-1) + dummy.next = head + prev, cur = dummy, head + while cur: + if cur.val in duplicates: + prev.next = cur.next + cur = cur.next + else: + prev, cur = cur, cur.next + + return dummy.next diff --git "a/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" "b/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" new file mode 100644 index 0000000..3629862 --- /dev/null +++ "b/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" @@ -0,0 +1,12 @@ +class Solution: + def replaceDigits(self, s: str) -> str: + res = "" + for i in range(0, len(s), 2): + char = s[i] + + if i + 1 < len(s): + shift = int(s[i + 1]) + res += char + chr(ord(char) + shift) + else: + res += char + return res \ No newline at end of file diff --git "a/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" "b/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" new file mode 100644 index 0000000..c18d4ca --- /dev/null +++ "b/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" @@ -0,0 +1,18 @@ +class Solution: + def memLeak(self, memory1: int, memory2: int) -> List[int]: + res = [] + memory = 1 + while memory1 or memory2: + if memory1 >= memory2: + if memory1 < memory: + break + else: + memory1 -= memory + else: + if memory2 < memory: + break + else: + memory2 -= memory + + memory += 1 + return [memory, memory1, memory2] \ No newline at end of file diff --git "a/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" "b/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" new file mode 100644 index 0000000..fb765fa --- /dev/null +++ "b/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution: + def subsetXORSum(self, nums: List[int]) -> int: + subsets = [[]] + res = 0 + for num in nums: + new_subsets = [] + for subset in subsets: + new_subset = subset + [num] + res += reduce(lambda x, y: x^y, new_subset) + new_subsets.append(new_subset) + subsets += new_subsets + return res \ No newline at end of file diff --git "a/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" "b/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" new file mode 100644 index 0000000..62d9a28 --- /dev/null +++ "b/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" @@ -0,0 +1,10 @@ +class Solution: + def minProductSum(self, nums1: List[int], nums2: List[int]) -> int: + nums1.sort() + nums2.sort() + # print(nums1, nums2[::-1]) + res = 0 + for i in range(len(nums1)): + res += nums1[i] * nums2[-(i + 1)] + + return res \ No newline at end of file diff --git "a/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" "b/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" new file mode 100644 index 0000000..fad2cee --- /dev/null +++ "b/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" @@ -0,0 +1,9 @@ +class Solution: + def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: + return self.sumOfDigit(firstWord) + self.sumOfDigit(secondWord) == self.sumOfDigit(targetWord) + + def sumOfDigit(self, word): + res = "" + for char in word: + res += str(ord(char) - ord("a")) + return int(res) \ No newline at end of file diff --git "a/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" "b/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" new file mode 100644 index 0000000..bbff3e1 --- /dev/null +++ "b/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" @@ -0,0 +1,3 @@ +class Solution: + def buildArray(self, nums: List[int]) -> List[int]: + return [nums[num] for num in nums] \ No newline at end of file diff --git "a/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" "b/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" new file mode 100644 index 0000000..5e822e9 --- /dev/null +++ "b/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" @@ -0,0 +1,3 @@ +class Solution: + def getConcatenation(self, nums: List[int]) -> List[int]: + return nums + nums \ No newline at end of file diff --git "a/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" "b/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" new file mode 100644 index 0000000..43abcbc --- /dev/null +++ "b/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" @@ -0,0 +1,5 @@ +class Solution: + def areOccurrencesEqual(self, s: str) -> bool: + from collections import Counter + c = Counter(s) + return 1 == len(set(c.values())) \ No newline at end of file diff --git "a/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..66328fc --- /dev/null +++ "b/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution: + def getLucky(self, s: str, k: int) -> int: + + num = "" + for char in s: + num += str(ord(char) - ord("a") + 1) + + num = int(num) + while k: + new_num = 0 + while num: + num, m = divmod(num, 10) + new_num += m + num = new_num + k -= 1 + return num diff --git "a/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" "b/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" new file mode 100644 index 0000000..72ad316 --- /dev/null +++ "b/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" @@ -0,0 +1,9 @@ +class Solution: + def numOfStrings(self, patterns: List[str], word: str) -> int: + + res = 0 + for pattern in patterns: + if pattern in word: + res += 1 + + return res \ No newline at end of file diff --git "a/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" "b/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" new file mode 100644 index 0000000..7477494 --- /dev/null +++ "b/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" @@ -0,0 +1,7 @@ +class Solution: + def reversePrefix(self, word: str, ch: str) -> str: + if word.count(ch): + index = word.index(ch) + return word[:index + 1][::-1] + word[index + 1:] + else: + return word \ No newline at end of file diff --git "a/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" "b/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" new file mode 100644 index 0000000..e1aed68 --- /dev/null +++ "b/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" @@ -0,0 +1,10 @@ +class Solution: + def finalValueAfterOperations(self, operations: List[str]) -> int: + res = 0 + for operation in operations: + if operation[0] == "-" or operation[-1] == "-": + res-= 1 + else: + res += 1 + + return res \ No newline at end of file diff --git "a/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" "b/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" new file mode 100644 index 0000000..e33ddba --- /dev/null +++ "b/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" @@ -0,0 +1,8 @@ +class Solution: + def targetIndices(self, nums: List[int], target: int) -> List[int]: + nums.sort() + res = [] + for i, num in enumerate(nums): + if num == target: + res.append(i) + return res \ No newline at end of file diff --git "a/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" "b/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" new file mode 100644 index 0000000..a1afb38 --- /dev/null +++ "b/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" @@ -0,0 +1,14 @@ +class Solution: + def countPoints(self, rings: str) -> int: + from collections import defaultdict + + ring2color = defaultdict(set) + for index in range(0, len(rings), 2): + color, ring = rings[index], rings[index + 1] + + ring2color[ring].add(color) + res = 0 + for ring, color in ring2color.items(): + if len(color) == 3: + res += 1 + return res \ No newline at end of file diff --git "a/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" "b/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b2fb005 --- /dev/null +++ "b/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,6 @@ +class Solution: + def firstPalindrome(self, words: List[str]) -> str: + for word in words: + if word == word[::-1]: + return word + return "" \ No newline at end of file diff --git "a/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" "b/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" new file mode 100644 index 0000000..02760a0 --- /dev/null +++ "b/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution: + def mostWordsFound(self, sentences: List[str]) -> int: + res = 0 + + for sentence in sentences: + word_count = len(sentence.split()) + res = max(res, word_count) + return res \ No newline at end of file diff --git "a/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" "b/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" new file mode 100644 index 0000000..611fcfd --- /dev/null +++ "b/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" @@ -0,0 +1,27 @@ +class Solution: + def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]: + res = [] + for i, _ in enumerate(s): + j = i + cur_row, cur_col = startPos[0], startPos[1] + while 1: + if j == len(s): + break + ins = s[j] + if ins == "R": + cur_col += 1 + elif ins == "L": + cur_col -= 1 + elif ins == "U": + cur_row -= 1 + elif ins == "D": + cur_row += 1 + j += 1 + if self.moveOutside(cur_row, cur_col, n): + j -= 1 + break + res.append(j - i) + return res + + def moveOutside(self, cur_row, cur_col, n): + return not 0 <= cur_row < n or not 0 <= cur_col < n diff --git "a/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" "b/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" new file mode 100644 index 0000000..3ad4623 --- /dev/null +++ "b/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" @@ -0,0 +1,10 @@ +class Solution: + def numberOfBeams(self, bank: List[str]) -> int: + res = 0 + last_device_count = 0 + for row_index, row in enumerate(bank): + cur_device_count = row.count("1") + res += cur_device_count * last_device_count + if cur_device_count: + last_device_count = cur_device_count + return res \ No newline at end of file diff --git "a/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" "b/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" new file mode 100644 index 0000000..05973ff --- /dev/null +++ "b/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def pairSum(self, head: Optional[ListNode]) -> int: + p, l = head, 0 + while p: + l += 1 + p = p.next + + stack = [] + cur = 0 + p = head + while cur < l // 2: + cur += 1 + stack.append(p.val) + p = p.next + + res = 0 + while cur < l: + cur += 1 + res = max(res, p.val + stack.pop()) + p = p.next + return res \ No newline at end of file diff --git "a/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" "b/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" new file mode 100644 index 0000000..b2f3320 --- /dev/null +++ "b/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" @@ -0,0 +1,17 @@ +class Solution: + def rearrangeArray(self, nums: List[int]) -> List[int]: + pos, neg = [], [] + + for num in nums: + if num > 0: + pos.append(num) + else: + neg.append(num) + + t = [(pos[i], neg[i]) for i in range(len(pos))] + + res = [] + for pair in t: + res.append(pair[0]) + res.append(pair[1]) + return res \ No newline at end of file diff --git "a/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" "b/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" new file mode 100644 index 0000000..6c09e8b --- /dev/null +++ "b/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" @@ -0,0 +1,6 @@ +class Solution: + def findFinalValue(self, nums: List[int], original: int) -> int: + s = set(nums) + while original in s: + original *= 2 + return original \ No newline at end of file diff --git "a/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" "b/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" new file mode 100644 index 0000000..1f17945 --- /dev/null +++ "b/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" @@ -0,0 +1,13 @@ +class Solution: + def pivotArray(self, nums: List[int], pivot: int) -> List[int]: + small, equal, larger = [], 0, [] + + for num in nums: + if num < pivot: + small.append(num) + elif num == pivot: + equal += 1 + else: + larger.append(num) + + return small + equal * [pivot] + larger \ No newline at end of file diff --git "a/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" "b/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" new file mode 100644 index 0000000..5c7e93e --- /dev/null +++ "b/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution: + def countOperations(self, num1: int, num2: int) -> int: + res = 0 + while num1 and num2: + res += 1 + if num1 >= num2: + num1 -= num2 + else: + num2 -= num1 + + return res \ No newline at end of file diff --git "a/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" "b/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..fbb8dcd --- /dev/null +++ "b/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + p_new = dummy + + p = head + cur_sum = 0 + while p: + if p.val == 0: + if cur_sum: + node = ListNode(cur_sum) + p_new.next = node + p_new = p_new.next + cur_sum = 0 + else: + cur_sum += p.val + p = p.next + + return dummy.next \ No newline at end of file diff --git "a/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" "b/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b618879 --- /dev/null +++ "b/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,8 @@ +class Solution: + def prefixCount(self, words: List[str], pref: str) -> int: + res = 0 + + for word in words: + if word.startswith(pref): + res += 1 + return res \ No newline at end of file diff --git "a/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" "b/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" new file mode 100644 index 0000000..f5008cd --- /dev/null +++ "b/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" @@ -0,0 +1,10 @@ +class Solution: + def cellsInRange(self, s: str) -> List[str]: + res = [] + start_row, end_row = int(s[1]), int(s[-1]) + start_col, end_col = s[0], s[3] + + for cur in range(ord(start_col), ord(end_col) + 1): + for row in range(start_row, end_row + 1): + res.append(chr(cur) + str(row)) + return res \ No newline at end of file diff --git "a/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" "b/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" new file mode 100644 index 0000000..d755d2b --- /dev/null +++ "b/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" @@ -0,0 +1,6 @@ +class Solution: + def triangularSum(self, nums: List[int]) -> int: + if len(nums) == 1: + return nums[0] + + return self.triangularSum([nums[i] + nums[i - 1] for i in range(1, len(nums))]) % 10 \ No newline at end of file diff --git "a/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" "b/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" new file mode 100644 index 0000000..07efd32 --- /dev/null +++ "b/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" @@ -0,0 +1,12 @@ +class Solution: + def largestInteger(self, num: int) -> int: + odd = sorted([int(digit) for digit in str(num) if digit in "13579"]) + even = sorted([int(digit) for digit in str(num) if digit not in "13579"]) + res = 0 + for digit in str(num): + if int(digit) % 2: + res = res * 10 + odd.pop() + else: + res = res * 10 + even.pop() + + return res diff --git "a/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" "b/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" new file mode 100644 index 0000000..a0a7c1f --- /dev/null +++ "b/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" @@ -0,0 +1,3 @@ +class Solution: + def sum(self, num1: int, num2: int) -> int: + return num1 + num2 \ No newline at end of file diff --git "a/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" "b/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" new file mode 100644 index 0000000..157a3c8 --- /dev/null +++ "b/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" @@ -0,0 +1,9 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def checkTree(self, root: Optional[TreeNode]) -> bool: + return root.val == root.left.val + root.right.val \ No newline at end of file diff --git "a/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" "b/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" new file mode 100644 index 0000000..0966cdd --- /dev/null +++ "b/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" @@ -0,0 +1,7 @@ +class Solution: + def countPrefixes(self, words: List[str], s: str) -> int: + res = 0 + for word in words: + if s.startswith(word): + res += 1 + return res \ No newline at end of file diff --git "a/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" "b/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" new file mode 100644 index 0000000..a326504 --- /dev/null +++ "b/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def averageOfSubtree(self, root: Optional[TreeNode]) -> int: + + self.res = 0 + def getAverageOfSubtree(node): + # post-order traversal + # return sum count + if not node: + return 0, 0 + + left_subtree_sum, left_count = getAverageOfSubtree(node.left) + right_subtree_sum, right_count = getAverageOfSubtree(node.right) + + subtree_sum = node.val + left_subtree_sum + right_subtree_sum + subtree_count = left_count + right_count + 1 + if node.val == subtree_sum // subtree_count: + self.res += 1 + + return subtree_sum, subtree_count + + getAverageOfSubtree(root) + return self.res \ No newline at end of file diff --git "a/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" "b/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" new file mode 100644 index 0000000..2974f8e --- /dev/null +++ "b/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" @@ -0,0 +1,3 @@ +class Solution: + def percentageLetter(self, s: str, letter: str) -> int: + return 100 * s.count(letter) // len(s) \ No newline at end of file diff --git "a/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" "b/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" new file mode 100644 index 0000000..8f5aabe --- /dev/null +++ "b/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" @@ -0,0 +1,10 @@ +class Solution: + def digitCount(self, num: str) -> bool: + from collections import Counter + c = Counter(num) + + for index, n in enumerate(num): + if c[str(index)] != int(n): + # print(c[index], index, int(n)) + return False + return True \ No newline at end of file diff --git "a/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" "b/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" new file mode 100644 index 0000000..00682ae --- /dev/null +++ "b/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" @@ -0,0 +1,9 @@ +class Solution: + def greatestLetter(self, s: str) -> str: + res = "" + s = set(s) + for char in s: + if char.lower() in s and char.upper() in s: + if not res or char.upper() > res: + res = char.upper() + return res \ No newline at end of file diff --git "a/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" "b/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" new file mode 100644 index 0000000..cfed43d --- /dev/null +++ "b/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" @@ -0,0 +1,10 @@ +class Solution: + def countAsterisks(self, s: str) -> int: + bar = False + res = 0 + for char in s: + if char == "|": + bar = not bar + if not bar and char == "*": + res += 1 + return res \ No newline at end of file diff --git "a/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" "b/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" new file mode 100644 index 0000000..c8d94e1 --- /dev/null +++ "b/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" @@ -0,0 +1,15 @@ +class Solution: + def checkXMatrix(self, grid: List[List[int]]) -> bool: + if not grid or not grid[0]: + return False + m, n = len(grid), len(grid[0]) + + for i in range(m): + for j in range(n): + if i == j or i + j == n - 1: + if grid[i][j] == 0: + return False + else: + if grid[i][j] != 0: + return False + return True \ No newline at end of file diff --git "a/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" "b/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" new file mode 100644 index 0000000..2ce85bf --- /dev/null +++ "b/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" @@ -0,0 +1,12 @@ +class Solution: + def makePalindrome(self, s: str) -> bool: + left, right = 0, len(s) - 1 + + step = 0 + while left < right: + if s[left] != s[right]: + step += 1 + left += 1 + right -= 1 + + return step <= 2 \ No newline at end of file diff --git "a/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" "b/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" new file mode 100644 index 0000000..29c46c5 --- /dev/null +++ "b/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def evaluateTree(self, root: Optional[TreeNode]) -> bool: + if root.val == 0: + return False + if root.val == 1: + return True + if root.val == 2: + return self.evaluateTree(root.left) or self.evaluateTree(root.right) + if root.val == 3: + return self.evaluateTree(root.left) and self.evaluateTree(root.right) \ No newline at end of file diff --git "a/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" "b/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" new file mode 100644 index 0000000..7775e85 --- /dev/null +++ "b/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" @@ -0,0 +1,16 @@ +from heapq import * +class Solution: + def fillCups(self, amount: List[int]) -> int: + max_heap = [-a for a in amount if a] + heapify(max_heap) + res = 0 + while len(max_heap) > 1: + first, second = -heappop(max_heap), -heappop(max_heap) + if first > 1: + heappush(max_heap, -(first - 1)) + if second > 1: + heappush(max_heap, -(second - 1)) + res += 1 + + return res + -max_heap[0] if max_heap else res + \ No newline at end of file diff --git "a/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" "b/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" new file mode 100644 index 0000000..65801ca --- /dev/null +++ "b/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" @@ -0,0 +1,23 @@ +from heapq import * +class SmallestInfiniteSet: + + def __init__(self): + self.min_heap = [i for i in range(1, 1001)] + heapify(self.min_heap) + self.set = set(self.min_heap) + + def popSmallest(self) -> int: + val = heappop(self.min_heap) + self.set.remove(val) + return val + + def addBack(self, num: int) -> None: + if num not in self.set: + heappush(self.min_heap, num) + self.set.add(num) + + +# Your SmallestInfiniteSet object will be instantiated and called as such: +# obj = SmallestInfiniteSet() +# param_1 = obj.popSmallest() +# obj.addBack(num) \ No newline at end of file diff --git "a/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" "b/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" new file mode 100644 index 0000000..6b08e20 --- /dev/null +++ "b/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" @@ -0,0 +1,8 @@ +class Solution: + def equalPairs(self, grid: List[List[int]]) -> int: + col_grid = [list(col) for col in zip(*grid)] + res = 0 + for row in grid: + for col in col_grid: + res += row == col + return res \ No newline at end of file diff --git "a/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" "b/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" new file mode 100644 index 0000000..23592d7 --- /dev/null +++ "b/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" @@ -0,0 +1,13 @@ +class Solution: + def minimumOperations(self, nums: List[int]) -> int: + res = 0 + while sum(nums): + res += 1 + m = 101 + for num in nums: + if num: + m = min(m, num) + for i, num in enumerate(nums): + if num: + nums[i] -= m + return res \ No newline at end of file diff --git "a/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" "b/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" new file mode 100644 index 0000000..95d587a --- /dev/null +++ "b/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" @@ -0,0 +1,36 @@ +class Solution: + def garbageCollection(self, garbage: List[str], travel: List[int]) -> int: + t_m, t_p, t_g = 0, 0, 0 + + driving_time_m = 0 + driving_time_p = 0 + driving_time_g = 0 + for index, g in enumerate(garbage): + # M + count_m = g.count("M") + if index: + driving_time_m += travel[index - 1] + if count_m: + t_m += count_m + t_m += driving_time_m + driving_time_m = 0 + + + count_p = g.count("P") + if index: + driving_time_p += travel[index - 1] + if count_p: + t_p += count_p + t_p += driving_time_p + driving_time_p = 0 + + + count_g = g.count("G") + if index: + driving_time_g += travel[index - 1] + if count_g: + t_g += count_g + t_g += driving_time_g + driving_time_g = 0 + + return t_m + t_p + t_g \ No newline at end of file diff --git "a/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" "b/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..a6f7c89 --- /dev/null +++ "b/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,11 @@ +class Solution: + def isStrictlyPalindromic(self, n: int) -> bool: + for k in range(2, n - 1): + bk = "" + temp = n + while temp: + temp, m = divmod(temp, k) + bk += str(m) + if bk != bk[::-1]: + return False + return True \ No newline at end of file diff --git "a/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" "b/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" new file mode 100644 index 0000000..f9b5b32 --- /dev/null +++ "b/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" @@ -0,0 +1,9 @@ +class Solution: + def checkDistances(self, s: str, distance: List[int]) -> bool: + res = True + for i, d in enumerate(distance): + char = chr(ord("a") + i) + if s.count(char): + if s.rfind(char) - s.index(char) != d + 1: + res = False + return res \ No newline at end of file diff --git "a/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" "b/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" new file mode 100644 index 0000000..c5d3e13 --- /dev/null +++ "b/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" @@ -0,0 +1,3 @@ +class Solution: + def smallestEvenMultiple(self, n: int) -> int: + return 2 * n if n % 2 else n \ No newline at end of file diff --git "a/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" "b/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" new file mode 100644 index 0000000..ae9c914 --- /dev/null +++ "b/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" @@ -0,0 +1,6 @@ +class Solution: + def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: + combine = [(name, heights[index]) for index, name in enumerate(names)] + + + return [pair[0] for pair in sorted(combine, key = lambda x: -x[1])] \ No newline at end of file diff --git "a/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" "b/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" new file mode 100644 index 0000000..fc19c6b --- /dev/null +++ "b/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution: + def findMaxK(self, nums: List[int]) -> int: + s = set(nums) + res = -1 + for num in nums: + if -num in s: + res = max(num, -num, res) + return res \ No newline at end of file diff --git "a/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" "b/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" new file mode 100644 index 0000000..15bcc06 --- /dev/null +++ "b/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" @@ -0,0 +1,8 @@ +class Solution: + def haveConflict(self, event1: List[str], event2: List[str]) -> bool: + return not (self.time1EarlierThanTime2(event1[1], event2[0]) or self.time1EarlierThanTime2(event2[1], event1[0])) + + def time1EarlierThanTime2(self, time1, time2): + h1, h2 = int(time1[:2]), int(time2[:2]) + m1, m2 = int(time1[3:]), int(time2[3:]) + return h1 < h2 or (h1 == h2 and m1 < m2) \ No newline at end of file diff --git "a/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" "b/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b713bed --- /dev/null +++ "b/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,17 @@ +class Solution: + def oddString(self, words: List[str]) -> str: + l = [] + for word in words: + diff = [] + for i, char in enumerate(word): + if i: + diff.append(ord(char) - ord(word[i - 1])) + l.append(diff) + # print(l) + + if l[0] != l[1] and l[0] != l[2]: + return words[0] + + for i, diff in enumerate(l): + if diff != l[0]: + return words[i] \ No newline at end of file diff --git "a/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" "b/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" new file mode 100644 index 0000000..94144da --- /dev/null +++ "b/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" @@ -0,0 +1,8 @@ +class Solution: + def averageValue(self, nums: List[int]) -> int: + s, cnt = 0, 0 + for num in nums: + if num % 6 == 0: + cnt += 1 + s += num + return int(s / cnt) if cnt else 0 \ No newline at end of file diff --git "a/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" "b/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" new file mode 100644 index 0000000..6a40092 --- /dev/null +++ "b/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" @@ -0,0 +1,17 @@ +class Solution: + def applyOperations(self, nums: List[int]) -> List[int]: + n = len(nums) + for i in range(n - 1): + if nums[i] == nums[i + 1]: + nums[i] *= 2 + nums[i + 1] = 0 + + index = 0 + for i in range(n): + if nums[i]: + nums[index] = nums[i] + index += 1 + + for i in range(index, n): + nums[i] = 0 + return nums \ No newline at end of file diff --git "a/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" "b/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" new file mode 100644 index 0000000..02dfad9 --- /dev/null +++ "b/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" @@ -0,0 +1,9 @@ +class Solution: + def distinctAverages(self, nums: List[int]) -> int: + nums.sort() + res = set() + while nums: + res.add((nums[0] + nums[-1]) / 2.0) + nums = nums[1:-1] + + return len(res) \ No newline at end of file diff --git "a/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" "b/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" new file mode 100644 index 0000000..812b4f1 --- /dev/null +++ "b/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" @@ -0,0 +1,36 @@ +class Solution: + def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int: + # f(i) = f(i - zero) + f(i - one) + # 00, 10, 11, 10, 0, 1 + # self.res = 0 + # MOD = int(1e9 + 7) + # memo = dict() + # def dfs(i): + # if i == 0: + # return 1 + # count = 0 + # if i in memo: + # return memo[i] + # if i >= zero: + # count += dfs(i - zero) + # if i >= one: + # count += dfs(i - one) + # # l represents count of distinct good string of length i + # if i >= low: + # self.res += count % MOD + # memo[i] = count + # return count + # dfs(high) + # return self.res % MOD + MOD = int(1e9 + 7) + dp = [0] * (high + max(zero, one)) + dp[0] = 1 + res = 0 + for i in range(1, high + 1): + if i >= zero: + dp[i] += dp[i - zero] + if i >= one: + dp[i] += dp[i - one] + if i >= low: + res += dp[i] % MOD + return res % MOD \ No newline at end of file diff --git "a/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" "b/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" new file mode 100644 index 0000000..091b21a --- /dev/null +++ "b/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" @@ -0,0 +1,3 @@ +class Solution: + def convertTemperature(self, celsius: float) -> List[float]: + return [celsius + 273.15, celsius * 1.8 + 32] \ No newline at end of file diff --git "a/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" "b/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" new file mode 100644 index 0000000..270f3e4 --- /dev/null +++ "b/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" @@ -0,0 +1,15 @@ +class Solution: + def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]: + m, n = len(grid), len(grid[0]) + row2one = {} + col2one = {} + for i, row in enumerate(grid): + row2one[i] = sum(row) + for j, col in enumerate(zip(*grid)): + col2one[j] = sum(col) + + diff = [[0 for i in range(n)] for j in range(m)] + for i in range(m): + for j in range(n): + diff[i][j] = row2one[i] + col2one[j] - (n - row2one[i]) - (m - col2one[j]) + return diff \ No newline at end of file diff --git "a/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" "b/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" new file mode 100644 index 0000000..0848d99 --- /dev/null +++ "b/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + dummy.next = head + + stack = [] # [node] + nodes_to_be_deleted = set() + p = head + while p: + while stack and stack[-1].val < p.val: + nodes_to_be_deleted.add(stack[-1]) + stack.pop() + stack.append(p) + p = p.next + + p = dummy + while p.next: + if p.next in nodes_to_be_deleted: + p.next = p.next.next + else: + p = p.next + return dummy.next + diff --git "a/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..5a09c51 --- /dev/null +++ "b/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,14 @@ +class Solution: + def maximumValue(self, strs: List[str]) -> int: + res = float("-inf") + for s in strs: + isNumber = True + for char in s: + if not char.isdigit(): + isNumber = False + break + if isNumber: + res = max(res, int(s)) + else: + res = max(res, len(s)) + return res \ No newline at end of file diff --git "a/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" "b/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..80070f6 --- /dev/null +++ "b/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,11 @@ +class Solution: + def similarPairs(self, words: List[str]) -> int: + from collections import defaultdict + pattern2count = defaultdict(int) + for word in words: + pattern2count["".join(sorted(list(set(word))))] += 1 + + res = 0 + for pattern, count in pattern2count.items(): + res += count * (count - 1) // 2 + return res \ No newline at end of file diff --git "a/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" "b/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" new file mode 100644 index 0000000..a38b8cd --- /dev/null +++ "b/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" @@ -0,0 +1,25 @@ +class Solution: + def maximumTastiness(self, price: List[int], k: int) -> int: + # 13, 1, 21 - 12, 20, 8 + price = set(price) + if len(price) < k: + return 0 + + # 1, 2, 5, 8, 13, 21 + price = sorted(list(price)) + left, right = 0, price[-1] - price[0] + while left <= right: + mid = (left + right) // 2 # target tastyness + + cnt, prev = 1, price[0] + for p in price: + if prev + mid <= p: # 鍙堟壘鍒颁簡涓涓 + cnt += 1 + prev = p + + if cnt >= k: + left = mid + 1 + elif cnt < k: + right = mid - 1 + + return right \ No newline at end of file diff --git "a/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" "b/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" new file mode 100644 index 0000000..e7d86a4 --- /dev/null +++ "b/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" @@ -0,0 +1,32 @@ +class Solution: + def maximumCount(self, nums: List[int]) -> int: + # 1. find the right-most negative number + negative_index = -1 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] < 0: + negative_index = mid + left = mid + 1 + elif nums[mid] >= 0: + right = mid - 1 + + # print(negative_index) + # 2. find the left-most positive number + positive_index = -1 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] > 0: + positive_index = mid + right = mid - 1 + else: + left = mid + 1 + + if negative_index > -1 and positive_index > -1: + return max(negative_index + 1, len(nums) - positive_index) + elif negative_index > -1: + return negative_index + 1 + elif positive_index > -1: + return len(nums) - positive_index + return 0 \ No newline at end of file diff --git "a/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" "b/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" new file mode 100644 index 0000000..70cbf0e --- /dev/null +++ "b/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" @@ -0,0 +1,3 @@ +class Solution: + def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]: + return sorted(score, key = lambda x:-x[k]) \ No newline at end of file diff --git "a/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" "b/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" new file mode 100644 index 0000000..54d4646 --- /dev/null +++ "b/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" @@ -0,0 +1,8 @@ +class Solution: + def separateDigits(self, nums: List[int]) -> List[int]: + res = [] + + for num in nums: + for digit in str(num): + res.append(int(digit)) + return res \ No newline at end of file diff --git "a/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" "b/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" new file mode 100644 index 0000000..ddfc2cf --- /dev/null +++ "b/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" @@ -0,0 +1,12 @@ +from heapq import * +class Solution: + def pickGifts(self, gifts: List[int], k: int) -> int: + max_heap = [] + for gift in gifts: + heappush(max_heap, -gift) + + while k: + gift = -heappop(max_heap) + heappush(max_heap, -int(gift ** 0.5)) + k -= 1 + return -sum(max_heap) diff --git "a/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" "b/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" new file mode 100644 index 0000000..188fa3b --- /dev/null +++ "b/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" @@ -0,0 +1,11 @@ +class Solution: + def findTheArrayConcVal(self, nums: List[int]) -> int: + res = 0 + while nums: + if len(nums) > 1: + serial = int(str(nums[0]) + str(nums[-1])) + else: + serial = nums[0] + res += serial + nums = nums[1:-1] + return res \ No newline at end of file diff --git "a/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" "b/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" new file mode 100644 index 0000000..844959c --- /dev/null +++ "b/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" @@ -0,0 +1,12 @@ +class Solution: + def leftRightDifference(self, nums: List[int]) -> List[int]: + left_sum = [0] + right_sum = [0] + + for num in nums[:-1]: + left_sum.append(num + left_sum[-1]) + + for num in nums[::-1][:-1]: + right_sum.append(num + right_sum[-1]) + + return [abs(l - r) for l, r in zip(left_sum, right_sum[::-1])] \ No newline at end of file diff --git "a/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" "b/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" new file mode 100644 index 0000000..ee2f5d3 --- /dev/null +++ "b/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution: + def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: + vowelStringCount = [0 for _ in words] + VOWELS = set("aeiou") + for i in range(len(words)): + if words[i][0] in VOWELS and words[i][-1] in VOWELS: + vowelStringCount[i] = vowelStringCount[i - 1] + 1 + else: + vowelStringCount[i] = vowelStringCount[i - 1] + + res = [] + for l, r in queries: + if l: + res.append(vowelStringCount[r] - vowelStringCount[l - 1]) + else: + res.append(vowelStringCount[r]) + return res diff --git "a/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" "b/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" new file mode 100644 index 0000000..203e13d --- /dev/null +++ "b/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" @@ -0,0 +1,12 @@ +class Solution: + def findMatrix(self, nums: List[int]) -> List[List[int]]: + from collections import Counter + c = Counter(nums) + res = [] + for num, freq in c.items(): + while len(res) < freq: + res.append([]) + + for i in range(freq): + res[i].append(num) + return res diff --git "a/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" new file mode 100644 index 0000000..46fe631 --- /dev/null +++ "b/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" @@ -0,0 +1,3 @@ +class Solution: + def maximizeSum(self, nums: List[int], k: int) -> int: + return max(nums) * k + k * (k - 1) // 2 \ No newline at end of file diff --git "a/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" "b/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" new file mode 100644 index 0000000..d3bda30 --- /dev/null +++ "b/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" @@ -0,0 +1,10 @@ +class Solution: + def distinctDifferenceArray(self, nums: List[int]) -> List[int]: + res = [] + + for i, num in enumerate(nums): + pre_count = len(set(nums[:i + 1])) + post_count = len(set(nums[i + 1:])) + + res.append(pre_count - post_count) + return res \ No newline at end of file diff --git "a/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" "b/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" new file mode 100644 index 0000000..cd5339d --- /dev/null +++ "b/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" @@ -0,0 +1,34 @@ +from collections import defaultdict +class FrequencyTracker: + + def __init__(self): + self.freq2num = defaultdict(set) + self.num2freq = defaultdict(int) + + def add(self, number: int) -> None: + # print(self.num2freq, self.freq2num) + freq = self.num2freq[number] + self.num2freq[number] += 1 + if number in self.freq2num[freq]: + self.freq2num[freq].remove(number) + self.freq2num[freq + 1].add(number) + + def deleteOne(self, number: int) -> None: + # print(self.num2freq, self.freq2num) + if number not in self.num2freq or self.num2freq[number] == 0: + return + freq = self.num2freq[number] + self.num2freq[number] -= 1 + if number in self.freq2num[freq]: + self.freq2num[freq].remove(number) + self.freq2num[freq - 1].add(number) + + def hasFrequency(self, frequency: int) -> bool: + return len(self.freq2num[frequency]) > 0 + + +# Your FrequencyTracker object will be instantiated and called as such: +# obj = FrequencyTracker() +# obj.add(number) +# obj.deleteOne(number) +# param_3 = obj.hasFrequency(frequency) \ No newline at end of file diff --git "a/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" "b/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" new file mode 100644 index 0000000..aa8f15e --- /dev/null +++ "b/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" @@ -0,0 +1,29 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def splitCircularLinkedList(self, head: Optional[ListNode]) -> List[Optional[ListNode]]: + + l, p = 0, head + last = None + flag = False + while not flag or p != head: + flag = True + l += 1 + if p.next == head: + last = p + p = p.next + # print(l, last) + mid = math.ceil(l / 2) + + cnt, p = 1, head + while cnt < mid: + p = p.next + cnt += 1 + + next_head = p.next + p.next = head + last.next = next_head + return [head, next_head] diff --git "a/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" "b/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..6173751 --- /dev/null +++ "b/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,8 @@ +class Solution: + def countSeniors(self, details: List[str]) -> int: + # res = 0 + # for detail in details: + # if int(detail[-4:-2]) > 60: + # res += 1 + # return res + return sum([int(detail[-4:-2]) > 60 for detail in details]) \ No newline at end of file diff --git "a/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" "b/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" new file mode 100644 index 0000000..96145c7 --- /dev/null +++ "b/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" @@ -0,0 +1,23 @@ +from heapq import * +class Solution: + def matrixSum(self, nums: List[List[int]]) -> int: + # if not nums or not nums[0]: + # return 0 + # m, n = len(nums), len(nums[0]) + # all_max_heap = [] + # for num in nums: + # max_heap = [-n for n in num] + # heapify(max_heap) + # all_max_heap.append(max_heap) + + # res = 0 + # for _ in range(n): + # score = 0 + # for i in range(m): + # score = max(score, -heappop(all_max_heap[i])) + # res += score + # return res + for num in nums: + num.sort() + + return sum(max(col) for col in zip(*nums)) \ No newline at end of file diff --git "a/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" "b/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" new file mode 100644 index 0000000..7947da9 --- /dev/null +++ "b/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" @@ -0,0 +1,12 @@ +class Solution: + def circularGameLosers(self, n: int, k: int) -> List[int]: + visited = set() + cur, cnt = 1, 1 + while cur not in visited: + visited.add(cur) + cur = cur + k * cnt + while cur > n: + cur = cur - n + cnt += 1 + + return [i for i in range(1, n + 1) if i not in visited] \ No newline at end of file diff --git "a/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" "b/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" new file mode 100644 index 0000000..d7e390a --- /dev/null +++ "b/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" @@ -0,0 +1,9 @@ +class Solution: + def doesValidArrayExist(self, derived: List[int]) -> bool: + cur = 0 + for i, n in enumerate(derived): + if i != len(derived) - 1: + if n == 1: + cur = 1 - cur + else: + return 0 ^ cur == n \ No newline at end of file diff --git "a/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" "b/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" new file mode 100644 index 0000000..8fc6a8a --- /dev/null +++ "b/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" @@ -0,0 +1,43 @@ +class Solution: + def maxMoves(self, grid: List[List[int]]) -> int: + # if not grid or not grid[0]: + # return 0 + # m, n = len(grid), len(grid[0]) + # dp = [[0 for _ in range(n)] for k in range(m)] + # dij = [[-1, 1], [0, 1], [1, 1]] + + # for col in range(n): + # for row in range(m): + # if not col or dp[row][col] != 0: + # for d in dij: + # i, j = row + d[0], col + d[1] + # if self.nodeInMatrix(i, j, m, n) and grid[i][j] > grid[row][col]: + # dp[i][j] = max(dp[i][j], dp[row][col] + 1) + + # return max([max(row) for row in dp]) + from collections import deque + queue = deque([]) + if not grid or not grid[0]: + return 0 + m, n = len(grid), len(grid[0]) + dxy = [[-1, 1], [0, 1], [1, 1]] + res = 0 + visited = set() + for i in range(m): + queue.append((0, i, 0)) # step, x, y + + while queue: + step, x, y = queue.popleft() + res = max(res, step) + + for dx, dy in dxy: + xx, yy = x + dx, y + dy + + if self.nodeInMatrix(xx, yy, m, n) and grid[xx][yy] > grid[x][y] and (xx, yy) not in visited: + visited.add((xx, yy)) + queue.append((step + 1, xx, yy)) + return res + + def nodeInMatrix(self, row, col, m, n): + return 0 <= row < m and 0 <= col < n + \ No newline at end of file diff --git "a/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" "b/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" new file mode 100644 index 0000000..69d881a --- /dev/null +++ "b/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" @@ -0,0 +1,27 @@ +class Solution: + def countCompleteComponents(self, n: int, edges: List[List[int]]) -> int: + from collections import defaultdict + src2des = defaultdict(set) + + res = 0 + visited = set() + for edge in edges: + src, des = edge[0], edge[1] + src2des[src].add(des) + src2des[src].add(src) + src2des[des].add(src) + src2des[des].add(des) + + for node in range(n): + if node not in visited: + connected = True + visited.add(node) + for connected_node in src2des[node]: + visited.add(connected_node) + if src2des[connected_node] != src2des[node]: + connected = False + break + + if connected: + res += 1 + return res \ No newline at end of file diff --git "a/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" "b/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" new file mode 100644 index 0000000..793fbb8 --- /dev/null +++ "b/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" @@ -0,0 +1,12 @@ +class Solution: + def minLength(self, s: str) -> int: + stack = [] + + for char in s: + if char == "D" and stack and stack[-1] == "C": + stack.pop() + elif char == "B" and stack and stack[-1] == "A": + stack.pop() + else: + stack.append(char) + return len(stack) \ No newline at end of file diff --git "a/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" "b/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..aae6620 --- /dev/null +++ "b/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,16 @@ +class Solution: + def makeSmallestPalindrome(self, s: str) -> str: + left, right = 0, len(s) - 1 + res_left = "" + res_right = "" + while left < right: + res_left += min(s[left], s[right]) + res_right = min(s[left], s[right]) + res_right + left += 1 + right -= 1 + + if left == right: + res = res_left + s[left] + res_right + else: + res = res_left + res_right + return res \ No newline at end of file diff --git "a/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" "b/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" new file mode 100644 index 0000000..b152802 --- /dev/null +++ "b/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" @@ -0,0 +1,27 @@ +class Solution: + def punishmentNumber(self, n: int) -> int: + res = 0 + for i in range(1, n + 1): + i2 = i * i + self.possible(i) + if self.res: + res += i2 + return res + + def possible(self, num): + # 鍒ゆ柇 1296 鏄惁鍙互鍒嗘垚 1 + 29 + 6 == 36 + self.res = False + def helper(n, s): + # 棣栨閫掑綊 n = 36, s = 1296 + if not s or n > int(s): + return + if int(s) == n: + self.res = True + return + for i in range(1, len(str(n)) + 1): + # 涓嬫閫掑綊 n = 30, s = 129 + helper(n - int(s[-i:]), s[:-i]) + helper(num, str(num * num)) + + + \ No newline at end of file diff --git "a/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" "b/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" new file mode 100644 index 0000000..b368281 --- /dev/null +++ "b/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" @@ -0,0 +1,5 @@ +class Solution: + def buyChoco(self, prices: List[int], money: int) -> int: + prices.sort() + s = prices[0] + prices[1] + return money if s > money else money - s \ No newline at end of file diff --git "a/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" "b/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" new file mode 100644 index 0000000..eb2f6c5 --- /dev/null +++ "b/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" @@ -0,0 +1,15 @@ +class Solution: + def minExtraChar(self, s: str, dictionary: List[str]) -> int: + # dp[i] represents res for s[:i] + dp = [i for i in range(len(s) + 1)] + + for i in range(len(s) + 1): + dp[i] = min(dp[i], dp[i - 1] + 1) + for d in dictionary: + if i >= len(d) and s[i - len(d):i] == d: + dp[i] = min(dp[i], dp[i - len(d)]) + + return dp[-1] + + + \ No newline at end of file diff --git "a/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" "b/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" new file mode 100644 index 0000000..d91c8b4 --- /dev/null +++ "b/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" @@ -0,0 +1,21 @@ +class Solution: + def maxStrength(self, nums: List[int]) -> int: + if all([num == 0 for num in nums]): + return 0 + if len(nums) == 1: + return nums[0] + pos = [num for num in nums if num > 0] + neg = [num for num in nums if num < 0] + + res = 0 + neg_length = len(neg) + if neg_length >= 2: + if neg_length % 2 == 0: + res = reduce((lambda x, y: x * y), neg) + else: + neg.sort() + res = reduce((lambda x, y: x * y), neg[:-1]) + + if pos: + res = reduce((lambda x, y: x * y), pos) * max(res, 1) + return res diff --git "a/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" "b/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" new file mode 100644 index 0000000..2d286a5 --- /dev/null +++ "b/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" @@ -0,0 +1,5 @@ +class Solution: + def removeTrailingZeros(self, num: str) -> str: + for i in range(len(num) - 1, -1, -1): + if num[i] != "0": + return num[:i + 1] \ No newline at end of file diff --git "a/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" "b/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" new file mode 100644 index 0000000..c6ad528 --- /dev/null +++ "b/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" @@ -0,0 +1,12 @@ +class Solution: + def minimumCost(self, s: str) -> int: + # 110101 + # 111010 min(i, n - i) + prev = s[0] + res = 0 + for i, char in enumerate(s): + if i and char != prev: + # flip is required: + res += min(i, len(s) - i) + prev = char + return res \ No newline at end of file diff --git "a/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" "b/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" new file mode 100644 index 0000000..21bb5b9 --- /dev/null +++ "b/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" @@ -0,0 +1,8 @@ +class Solution: + def semiOrderedPermutation(self, nums: List[int]) -> int: + index_1 = nums.index(1) + index_n = nums.index(len(nums)) + if index_1 < index_n: + return index_1 + (len(nums) - 1 - index_n) + else: + return index_1 + (len(nums) - 1 - index_n - 1) \ No newline at end of file diff --git "a/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" "b/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" new file mode 100644 index 0000000..cae0b56 --- /dev/null +++ "b/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" @@ -0,0 +1,3 @@ +class Solution: + def minimizedStringLength(self, s: str) -> int: + return len(set(s)) \ No newline at end of file diff --git "a/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" "b/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" new file mode 100644 index 0000000..1f05ad5 --- /dev/null +++ "b/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution: + def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int: + visited_rows, visited_cols = set(), set() + res = 0 + for t, index, val in queries[::-1]: + if t == 0: + if index not in visited_rows: + res += val * (n - len(visited_cols)) + visited_rows.add(index) + elif t == 1: + if index not in visited_cols: + res += val * (n - len(visited_rows)) + visited_cols.add(index) + + return res + diff --git "a/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" "b/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" new file mode 100644 index 0000000..71601c2 --- /dev/null +++ "b/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def game(self, guess: List[int], answer: List[int]) -> int: + return sum(guess[i] == answer[i] for i in range(3)) \ No newline at end of file diff --git "a/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" "b/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" new file mode 100644 index 0000000..303f35f --- /dev/null +++ "b/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" @@ -0,0 +1,10 @@ +class Solution: + def calculate(self, s: str) -> int: + x, y = 1, 0 + + for char in s: + if char == "A": + x = 2 * x + y + else: + y = 2 * y + x + return x + y \ No newline at end of file diff --git "a/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" "b/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" new file mode 100644 index 0000000..4205610 --- /dev/null +++ "b/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None +class Solution: + def numColor(self, root: TreeNode) -> int: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + return len(set(inorder(root))) \ No newline at end of file diff --git "a/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" "b/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" new file mode 100644 index 0000000..3e9157b --- /dev/null +++ "b/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" @@ -0,0 +1,11 @@ +class Solution: + def minNumBooths(self, demands: List[str]) -> int: + from collections import defaultdict, Counter + char2count = defaultdict(int) + for demand in demands: + c = Counter(demand) + + for char, freq in c.items(): + char2count[char] = max(char2count[char], freq) + + return sum(freq for freq in char2count.values()) \ No newline at end of file diff --git "a/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" "b/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" new file mode 100644 index 0000000..0e7a995 --- /dev/null +++ "b/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def expandBinaryTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: + + def dfs(node): + if not node: + return node + + left, right = node.left, node.right + if left: + node.left = TreeNode(-1, left) + + if right: + node.right = TreeNode(-1, None, right) + + dfs(left) + dfs(right) + return node + + return dfs(root) + \ No newline at end of file diff --git "a/LeetCode-Python/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" "b/LeetCode-Python/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" new file mode 100644 index 0000000..fda31fd --- /dev/null +++ "b/LeetCode-Python/0001.\344\270\244\346\225\260\344\271\213\345\222\214/0001-\344\270\244\346\225\260\344\271\213\345\222\214.py" @@ -0,0 +1,9 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + value2index = {} + + for index, num in enumerate(nums): + if target - num in value2index: + return [value2index[target - num], index] + value2index[num] = index + \ No newline at end of file diff --git "a/LeetCode-Python/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240.py" "b/LeetCode-Python/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240.py" new file mode 100644 index 0000000..babd7fd --- /dev/null +++ "b/LeetCode-Python/0002.\344\270\244\346\225\260\347\233\270\345\212\240/0002-\344\270\244\346\225\260\347\233\270\345\212\240.py" @@ -0,0 +1,56 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: + if not l1 and not l2: + return l1 + if not l1: + return l2 + if not l2: + return l1 + + p1, p2 = l1, l2 + carry = 0 + dummy = ListNode(-1) + p = dummy + while l1 and l2: + s = l1.val + l2.val + carry + l1 = l1.next + l2 = l2.next + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + + p.next = ListNode(s) + p = p.next + + while l1: + s = l1.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l1 = l1.next + p.next = ListNode(s) + p = p.next + + while l2: + s = l2.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l2 = l2.next + p.next = ListNode(s) + p = p.next + + if carry: + p.next = ListNode(1) + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" "b/LeetCode-Python/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" new file mode 100644 index 0000000..fce763a --- /dev/null +++ "b/LeetCode-Python/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" @@ -0,0 +1,3 @@ +class Solution: + def isPalindrome(self, x: int) -> bool: + return str(x) == str(x)[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" "b/LeetCode-Python/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" new file mode 100644 index 0000000..30dac97 --- /dev/null +++ "b/LeetCode-Python/0019.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271/0019-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\347\273\223\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: + l = 0 + p = head + while p: + l += 1 + p = p.next + + count = l - n + 1 + + dummy = ListNode(-1) + dummy.next = head + cur = -1 + p = dummy + while p: + cur += 1 + if cur == count - 1: + node_to_be_deleted = p.next + p.next = node_to_be_deleted.next + break + p = p.next + + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" "b/LeetCode-Python/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 0000000..4635692 --- /dev/null +++ "b/LeetCode-Python/0020.\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,11 @@ +class Solution: + def isValid(self, s: str) -> bool: + right2left = {")":"(", "]":"[", "}":"{"} + stack = [] + for char in s: + if char in right2left: + if not stack or stack.pop() != right2left[char]: + return False + else: + stack.append(char) + return stack == [] diff --git "a/LeetCode-Python/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.py" "b/LeetCode-Python/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.py" new file mode 100644 index 0000000..0c462b0 --- /dev/null +++ "b/LeetCode-Python/0021.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.py" @@ -0,0 +1,25 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + p = dummy + while list1 and list2: + if list1.val <= list2.val: + node = ListNode(list1.val) + list1 = list1.next + else: + node = ListNode(list2.val) + list2 = list2.next + p.next = node + p = p.next + + if list1: + p.next = list1 + elif list2: + p.next = list2 + + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220.py" "b/LeetCode-Python/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220.py" new file mode 100644 index 0000000..1b94ac9 --- /dev/null +++ "b/LeetCode-Python/0022.\346\213\254\345\217\267\347\224\237\346\210\220/0022-\346\213\254\345\217\267\347\224\237\346\210\220.py" @@ -0,0 +1,14 @@ +class Solution: + def generateParenthesis(self, n: int) -> List[str]: + res = [] + def dfs(left, right, tmp): + if left == 0 and right == 0: + res.append(tmp) + return + if left > 0: + dfs(left - 1, right, tmp + "(") + if right > left: + dfs(left, right - 1, tmp + ")") + + dfs(n, n, "") + return res \ No newline at end of file diff --git "a/LeetCode-Python/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" "b/LeetCode-Python/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..a828a2c --- /dev/null +++ "b/LeetCode-Python/0024.\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0024-\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,14 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]: + if not head or not head.next: + return head + first, second = head, head.next + + tail = second.next + second.next, first.next = first, self.swapPairs(tail) + return second \ No newline at end of file diff --git "a/LeetCode-Python/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" "b/LeetCode-Python/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" new file mode 100644 index 0000000..5f77e5e --- /dev/null +++ "b/LeetCode-Python/0026.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271/0026-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.py" @@ -0,0 +1,10 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + visited = set() + index = 0 + for num in nums: + if num not in visited: + visited.add(num) + nums[index] = num + index += 1 + return index \ No newline at end of file diff --git "a/LeetCode-Python/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240.py" "b/LeetCode-Python/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240.py" new file mode 100644 index 0000000..92fd921 --- /dev/null +++ "b/LeetCode-Python/0027.\347\247\273\351\231\244\345\205\203\347\264\240/0027-\347\247\273\351\231\244\345\205\203\347\264\240.py" @@ -0,0 +1,11 @@ +class Solution: + def removeElement(self, nums: List[int], val: int) -> int: + i, right = 0, len(nums) - 1 + while i <= right: + if nums[i] == val: + while i < right and nums[right] == val: + right -= 1 + nums[i], nums[right] = nums[right], nums[i] + right -= 1 + i += 1 + return right + 1 \ No newline at end of file diff --git "a/LeetCode-Python/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" "b/LeetCode-Python/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" new file mode 100644 index 0000000..781ae1a --- /dev/null +++ "b/LeetCode-Python/0028.\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207/0028-\346\211\276\345\207\272\345\255\227\347\254\246\344\270\262\344\270\255\347\254\254\344\270\200\344\270\252\345\214\271\351\205\215\351\241\271\347\232\204\344\270\213\346\240\207.py" @@ -0,0 +1,5 @@ +class Solution: + def strStr(self, haystack: str, needle: str) -> int: + if needle not in haystack: + return -1 + return haystack.index(needle) \ No newline at end of file diff --git "a/LeetCode-Python/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.py" "b/LeetCode-Python/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.py" new file mode 100644 index 0000000..685aab9 --- /dev/null +++ "b/LeetCode-Python/0034.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256/0034-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.py" @@ -0,0 +1,25 @@ +class Solution: + def searchRange(self, nums: List[int], target: int) -> List[int]: + # 1. find the left-most index + left, right = 0, len(nums) - 1 + left_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] >= target: + left_index = mid + right = mid - 1 + else: + left = mid + 1 + print(left, right, left_index) + # 2. find the right-most index + left, right = 0, len(nums) - 1 + right_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] <= target: + right_index = mid + left = mid + 1 + else: + right = mid - 1 + + return [left_index, right_index] if left_index > -1 and nums[left_index] == target else [-1, -1] \ No newline at end of file diff --git "a/LeetCode-Python/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.py" "b/LeetCode-Python/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.py" new file mode 100644 index 0000000..80bf81c --- /dev/null +++ "b/LeetCode-Python/0035.\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.py" @@ -0,0 +1,13 @@ +class Solution: + def searchInsert(self, nums: List[int], target: int) -> int: + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + + if nums[mid] == target: + return mid + elif nums[mid] > target: + right = mid - 1 + elif nums[mid] < target: + left = mid + 1 + return left \ No newline at end of file diff --git "a/LeetCode-Python/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254.py" "b/LeetCode-Python/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254.py" new file mode 100644 index 0000000..ec1d64f --- /dev/null +++ "b/LeetCode-Python/0036.\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254/0036-\346\234\211\346\225\210\347\232\204\346\225\260\347\213\254.py" @@ -0,0 +1,28 @@ +class Solution: + def isValidSudoku(self, board: List[List[str]]) -> bool: + from collections import defaultdict + # validate row + for i in range(9): + row = [digit for digit in board[i] if digit.isdigit()] + s = set(row) + if len(s) < len(row): + return False + + # validate col + boardT = [list(col) for col in zip(*board)] + for j in range(9): + col = [digit for digit in boardT[j] if digit.isdigit()] + s = set(col) + if len(s) < len(col): + return False + + # validate smaller 3 * 3 square + rowcol2digitset = defaultdict(set) + for i in range(9): + for j in range(9): + if board[i][j].isdigit(): + if board[i][j] in rowcol2digitset[str(i // 3) + str(j // 3)]: + return False + rowcol2digitset[str(i // 3) + str(j // 3)].add(board[i][j]) + + return True \ No newline at end of file diff --git "a/LeetCode-Python/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" "b/LeetCode-Python/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" new file mode 100644 index 0000000..5ad82f4 --- /dev/null +++ "b/LeetCode-Python/0045.\350\267\263\350\267\203\346\270\270\346\210\217II/0045-\350\267\263\350\267\203\346\270\270\346\210\217II.py" @@ -0,0 +1,9 @@ +class Solution: + def jump(self, nums: List[int]) -> int: + dp = [float("inf") for _ in nums] + dp[0] = 0 + for i, num in enumerate(nums): + for j in range(1, 1 + num): + if i + j < len(nums): + dp[i + j] = min(dp[i + j], dp[i] + 1) + return dp[-1] \ No newline at end of file diff --git "a/LeetCode-Python/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" "b/LeetCode-Python/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" new file mode 100644 index 0000000..a9d570a --- /dev/null +++ "b/LeetCode-Python/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [] + def dfs(tmp, nums): + if not nums: + res.append(tmp) + + for i, x in enumerate(nums): + dfs(tmp + [x], nums[:i] + nums[i + 1:]) + + dfs([], nums) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217.py" "b/LeetCode-Python/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217.py" new file mode 100644 index 0000000..49a4cfd --- /dev/null +++ "b/LeetCode-Python/0048.\346\227\213\350\275\254\345\233\276\345\203\217/0048-\346\227\213\350\275\254\345\233\276\345\203\217.py" @@ -0,0 +1,15 @@ +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + n = len(matrix) + for i in range(n): + for j in range(i + 1, n): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + + for i in range(n): + row = matrix[i] + for j in range(n // 2): + row[j], row[-(j + 1)] = row[-(j + 1)], row[j] + diff --git "a/LeetCode-Python/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" "b/LeetCode-Python/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" new file mode 100644 index 0000000..50822de --- /dev/null +++ "b/LeetCode-Python/0049.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/0049-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" @@ -0,0 +1,9 @@ +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + from collections import defaultdict + + d = defaultdict(list) + for word in strs: + d["".join(sorted(word))].append(word) + + return [val for key, val in d.items() ] \ No newline at end of file diff --git "a/LeetCode-Python/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265.py" "b/LeetCode-Python/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265.py" new file mode 100644 index 0000000..8827369 --- /dev/null +++ "b/LeetCode-Python/0054.\350\236\272\346\227\213\347\237\251\351\230\265/0054-\350\236\272\346\227\213\347\237\251\351\230\265.py" @@ -0,0 +1,40 @@ +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + state = "right" + if not matrix or not matrix[0]: + return [] + + m, n = len(matrix), len(matrix[0]) + count = m * n + x, y = 0, 0 + res = [] + visited = set() + while count: + res.append(matrix[x][y]) + visited.add((x, y)) + if state == "right": + if y + 1 < n and (x, y + 1) not in visited: + y += 1 + else: + state = "down" + x += 1 + elif state == "left": + if y - 1 >= 0 and (x, y - 1) not in visited: + y -= 1 + else: + state = "up" + x -= 1 + elif state == "up": + if x - 1 >= 0 and (x - 1, y) not in visited: + x -= 1 + else: + state = "right" + y += 1 + elif state == "down": + if x + 1 < m and (x + 1, y) not in visited: + x += 1 + else: + state = "left" + y -= 1 + count -= 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217.py" "b/LeetCode-Python/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217.py" new file mode 100644 index 0000000..86728ce --- /dev/null +++ "b/LeetCode-Python/0055.\350\267\263\350\267\203\346\270\270\346\210\217/0055-\350\267\263\350\267\203\346\270\270\346\210\217.py" @@ -0,0 +1,11 @@ +class Solution: + def canJump(self, nums: List[int]) -> bool: + cur, reach = 0, nums[0] + while 1: + reach = max(reach, cur + nums[cur]) + if reach >= len(nums) - 1: + return True + if reach == cur: + return False + cur += 1 + \ No newline at end of file diff --git "a/LeetCode-Python/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246.py" "b/LeetCode-Python/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246.py" new file mode 100644 index 0000000..40ad18e --- /dev/null +++ "b/LeetCode-Python/0058.\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246/0058-\346\234\200\345\220\216\344\270\200\344\270\252\345\215\225\350\257\215\347\232\204\351\225\277\345\272\246.py" @@ -0,0 +1,3 @@ +class Solution: + def lengthOfLastWord(self, s: str) -> int: + return len(s.split()[-1]) \ No newline at end of file diff --git "a/LeetCode-Python/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271.py" "b/LeetCode-Python/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271.py" new file mode 100644 index 0000000..3ebe3a8 --- /dev/null +++ "b/LeetCode-Python/0069.x\347\232\204\345\271\263\346\226\271\346\240\271/0069-x\347\232\204\345\271\263\346\226\271\346\240\271.py" @@ -0,0 +1,12 @@ +class Solution: + def mySqrt(self, x: int) -> int: + left, right = 0, x + res = 0 + while left <= right: + mid = (left + right) // 2 + if mid * mid > x: + right = mid - 1 + elif mid * mid <= x: + left = mid + 1 + res = mid + return res diff --git "a/LeetCode-Python/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" "b/LeetCode-Python/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" new file mode 100644 index 0000000..52850f2 --- /dev/null +++ "b/LeetCode-Python/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" @@ -0,0 +1,22 @@ +class Solution: + def climbStairs(self, n: int) -> int: + # f(n) = f(n - 1) + f(n - 2) + # dp[n] = dp[n -1] + dp[n - 2] + # memo = dict() + # def dfs(n): + # if n < 0: + # return 0 + # if n <= 1: + # return 1 + # if n in memo: + # return memo[n] + # res = dfs(n - 1) + dfs(n - 2) + # memo[n] = res + # return res + # return dfs(n) + f0, f1 = 1, 1 + for i in range(1, n): + newf = f0 + f1 + f0 = f1 + f1 = newf + return f1 \ No newline at end of file diff --git "a/LeetCode-Python/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204.py" "b/LeetCode-Python/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204.py" new file mode 100644 index 0000000..48136d0 --- /dev/null +++ "b/LeetCode-Python/0071.\347\256\200\345\214\226\350\267\257\345\276\204/0071-\347\256\200\345\214\226\350\267\257\345\276\204.py" @@ -0,0 +1,13 @@ +class Solution: + def simplifyPath(self, path: str) -> str: + path_names = path.split("/") + stack = [] + for path_name in path_names: + if path_name: + if path_name == "..": + if stack: + stack.pop() + elif path_name != ".": + stack.append(path_name) + + return "/" + "/".join(stack) \ No newline at end of file diff --git "a/LeetCode-Python/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266.py" "b/LeetCode-Python/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266.py" new file mode 100644 index 0000000..cffc270 --- /dev/null +++ "b/LeetCode-Python/0073.\347\237\251\351\230\265\347\275\256\351\233\266/0073-\347\237\251\351\230\265\347\275\256\351\233\266.py" @@ -0,0 +1,26 @@ +class Solution: + def setZeroes(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + if not matrix or not matrix[0]: + return matrix + + m, n = len(matrix), len(matrix[0]) + + for i in range(m): + for j in range(n): + if matrix[i][j] == 0: + # set row zero + for zj in range(n): + if matrix[i][zj] != 0: + matrix[i][zj] = "ZERO" + for zi in range(m): + if matrix[zi][j] != 0: + matrix[zi][j] = "ZERO" + + for i in range(m): + for j in range(n): + if matrix[i][j] == "ZERO": + matrix[i][j] = 0 + \ No newline at end of file diff --git "a/LeetCode-Python/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" "b/LeetCode-Python/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" new file mode 100644 index 0000000..52471ac --- /dev/null +++ "b/LeetCode-Python/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" @@ -0,0 +1,9 @@ +class Solution: + def subsets(self, nums: List[int]) -> List[List[int]]: + res = [[]] + for num in nums: + new_res = [] + for subset in res: + new_res.append(subset + [num]) + res += new_res + return res \ No newline at end of file diff --git "a/LeetCode-Python/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" "b/LeetCode-Python/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" new file mode 100644 index 0000000..b9415ef --- /dev/null +++ "b/LeetCode-Python/0080.\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II/0080-\345\210\240\351\231\244\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271II.py" @@ -0,0 +1,17 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + prev, prev_count = nums[0], 1 + res = 1 + for num in nums[1:]: + if num == prev: + if prev_count == 1: + nums[res] = num + res += 1 + prev_count += 1 + else: + nums[res] = num + res += 1 + prev = num + prev_count = 1 + return res + \ No newline at end of file diff --git "a/LeetCode-Python/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II.py" "b/LeetCode-Python/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II.py" new file mode 100644 index 0000000..598ced5 --- /dev/null +++ "b/LeetCode-Python/0082.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II/0082-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240II.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + dummy.next = head + prev, cur = dummy, head + + while cur: + tail = cur.next + if cur and tail and cur.val == tail.val: + while cur.next and cur.val == cur.next.val: + tail = cur.next.next + cur = cur.next + + prev.next = tail + cur = tail + else: + prev, cur = cur, tail + + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.py" "b/LeetCode-Python/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.py" new file mode 100644 index 0000000..fe7b80f --- /dev/null +++ "b/LeetCode-Python/0083.\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240/0083-\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.py" @@ -0,0 +1,18 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]: + if not head: + return head + left, right = head, head + while right: + if left.val != right.val: + left = left.next + left.val = right.val + right = right.next + + left.next = None + return head \ No newline at end of file diff --git "a/LeetCode-Python/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\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/LeetCode-Python/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\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 0000000..60f3603 --- /dev/null +++ "b/LeetCode-Python/0088.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204/0088-\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,21 @@ +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. + """ + p1, p2 = m - 1, n - 1 + index = m + n - 1 + while p1 >= 0 and p2 >= 0: + if nums1[p1] < nums2[p2]: + nums1[index] = nums2[p2] + p2 -= 1 + else: + nums1[index] = nums1[p1] + p1 -= 1 + index -= 1 + + while p2 >= 0: + nums1[index] = nums2[p2] + p2 -= 1 + index -= 1 + diff --git "a/LeetCode-Python/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II.py" "b/LeetCode-Python/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II.py" new file mode 100644 index 0000000..f16cdaa --- /dev/null +++ "b/LeetCode-Python/0092.\345\217\215\350\275\254\351\223\276\350\241\250II/0092-\345\217\215\350\275\254\351\223\276\350\241\250II.py" @@ -0,0 +1,40 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverseBetween(self, head: Optional[ListNode], left: int, right: int) -> Optional[ListNode]: + dummy = ListNode(-501) + dummy.next = head + p = dummy.next + before_left = None + tail = None + prev, cur, count = dummy, p, 0 + left_node, right_node = None, None + while prev and cur: + count += 1 + if count == left: + before_left = prev + left_node = cur + if count == right: + tail = cur.next + right_node = cur + right_node.next = None + break + prev = cur + cur = cur.next + + self.reverse(left_node) + before_left.next = right_node + left_node.next = tail + return dummy.next + + def reverse(self, node): + if not node or not node.next: + return node + + tmp = self.reverse(node.next) + node.next.next = node + node.next = None + return tmp \ No newline at end of file diff --git "a/LeetCode-Python/0094.\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206/0094-\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0094.\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206/0094-\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..0c5549f --- /dev/null +++ "b/LeetCode-Python/0094.\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206/0094-\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,25 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: +# if not root: +# return [] +# return self.inorderTraversal(root.left) + [root.val] + self.inorderTraversal(root.right) + +class Solution: + def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + stack = [root] + res = [] + while stack: + node = stack.pop() + if isinstance(node, TreeNode): + stack.append(node.right) + stack.append(node.val) + stack.append(node.left) + elif isinstance(node, int): + res.append(node) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221.py" "b/LeetCode-Python/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221.py" new file mode 100644 index 0000000..ac20078 --- /dev/null +++ "b/LeetCode-Python/0100.\347\233\270\345\220\214\347\232\204\346\240\221/0100-\347\233\270\345\220\214\347\232\204\346\240\221.py" @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: + if not p and not q: + return True + if not p and q: + return False + + if p and not q: + return False + + return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) \ No newline at end of file diff --git "a/LeetCode-Python/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221/0101-\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221/0101-\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..53d983a --- /dev/null +++ "b/LeetCode-Python/0101.\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221/0101-\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,35 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def isSymmetric(self, root: Optional[TreeNode]) -> bool: +# queue = [root] +# while queue: +# next_queue = [] +# level_val = [] +# for node in queue: +# if node: +# next_queue.append(node.left) +# next_queue.append(node.right) +# level_val.append(node.val) +# else: +# level_val.append("n") + +# if level_val != level_val[::-1]: +# return False +# queue = next_queue[:] +# return True + +class Solution: + def isSymmetric(self, root: Optional[TreeNode]) -> bool: + def helper(left:Optional[TreeNode], right: Optional[TreeNode]): + if not left: + return not right + if not right: + return not left + return left.val == right.val and helper(left.left, right.right) and helper(left.right, right.left) + + return helper(root.left, root.right) diff --git "a/LeetCode-Python/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..204ca41 --- /dev/null +++ "b/LeetCode-Python/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res \ No newline at end of file diff --git "a/LeetCode-Python/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..6e4ed82 --- /dev/null +++ "b/LeetCode-Python/0103.\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206/0103-\344\272\214\345\217\211\346\240\221\347\232\204\351\224\257\351\275\277\345\275\242\345\261\202\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + flag = 1 + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + if flag: + res.append(cur_level) + flag = 0 + else: + flag = 1 + res.append(cur_level[::-1]) + queue = next_queue + return res \ No newline at end of file diff --git "a/LeetCode-Python/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0104-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" "b/LeetCode-Python/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0104-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" new file mode 100644 index 0000000..d544997 --- /dev/null +++ "b/LeetCode-Python/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0104-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def maxDepth(self, root: Optional[TreeNode]) -> int: +# if not root: +# return 0 +# return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) + +class Solution: + def maxDepth(self, root: Optional[TreeNode]) -> int: + if not root: + return 0 + queue = [root] + depth = 0 + while queue: + next_queue = [] + depth += 1 + for node in queue: + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + queue = next_queue[:] + return depth \ No newline at end of file diff --git "a/LeetCode-Python/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..42c8031 --- /dev/null +++ "b/LeetCode-Python/0105.\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0105-\344\273\216\345\211\215\345\272\217\344\270\216\344\270\255\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]: + if not preorder: + return None + + root_val = preorder[0] + root_index_inorder = inorder.index(root_val) + + left_inorder = inorder[:root_index_inorder] + right_inorder = inorder[root_index_inorder + 1:] + + left_preorder = preorder[1:1 + len(left_inorder)] + right_preorder = preorder[1 + len(left_inorder):] + + return TreeNode(root_val, self.buildTree(left_preorder, left_inorder), self.buildTree(right_preorder, right_inorder)) \ No newline at end of file diff --git "a/LeetCode-Python/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..d5f5415 --- /dev/null +++ "b/LeetCode-Python/0106.\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/0106-\344\273\216\344\270\255\345\272\217\344\270\216\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]: + if not inorder: + return None + + root_val = postorder[-1] + root_index_inorder = inorder.index(root_val) + + left_inorder = inorder[:root_index_inorder] + right_inorder = inorder[root_index_inorder + 1:] + + left_postorder = postorder[:len(left_inorder)] + right_postorder = postorder[len(left_inorder): -1] + + root = TreeNode(root_val, self.buildTree(left_inorder, left_postorder), self.buildTree(right_inorder, right_postorder)) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" "b/LeetCode-Python/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" new file mode 100644 index 0000000..e2a4c93 --- /dev/null +++ "b/LeetCode-Python/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206II.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrderBottom(self, root: Optional[TreeNode]) -> List[List[int]]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..9da1a22 --- /dev/null +++ "b/LeetCode-Python/0108.\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0108-\345\260\206\346\234\211\345\272\217\346\225\260\347\273\204\350\275\254\346\215\242\344\270\272\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]: + if not nums: + return None + + # if len(nums) == 1: + # return TreeNode(nums[0]) + + index = len(nums) // 2 + root = TreeNode(nums[index], self.sortedArrayToBST(nums[:index]), self.sortedArrayToBST(nums[index + 1:])) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..633975f --- /dev/null +++ "b/LeetCode-Python/0109.\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0109-\346\234\211\345\272\217\351\223\276\350\241\250\350\275\254\346\215\242\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,29 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sortedListToBST(self, head: Optional[ListNode]) -> Optional[TreeNode]: + p = head + array = [] + while p: + array.append(p.val) + p = p.next + + return self.sortedArrayToBST(array) + + + def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]: + if not nums: + return None + + index = len(nums) // 2 + root = TreeNode(nums[index], self.sortedArrayToBST(nums[:index]), self.sortedArrayToBST(nums[index + 1:])) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.py" "b/LeetCode-Python/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.py" new file mode 100644 index 0000000..d35dfa3 --- /dev/null +++ "b/LeetCode-Python/0111.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246/0111-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def minDepth(self, root: Optional[TreeNode]) -> int: + if not root: + return 0 + self.res = float("inf") + + def dfs(node, cur_depth): + if not node: + return + cur_depth += 1 + if not node.left and not node.right: + self.res = min(cur_depth, self.res) + dfs(node.left, cur_depth) + dfs(node.right, cur_depth) + + dfs(root, 0) + return self.res + + + \ No newline at end of file diff --git "a/LeetCode-Python/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214.py" "b/LeetCode-Python/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214.py" new file mode 100644 index 0000000..ae64136 --- /dev/null +++ "b/LeetCode-Python/0112.\350\267\257\345\276\204\346\200\273\345\222\214/0112-\350\267\257\345\276\204\346\200\273\345\222\214.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool: + self.res = False + def dfs(node, path_sum): + if not node: + return + + path_sum += node.val + if targetSum == path_sum and (not node.left and not node.right): + self.res = True + + if not self.res: + dfs(node.left, path_sum) + dfs(node.right, path_sum) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II.py" "b/LeetCode-Python/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II.py" new file mode 100644 index 0000000..3bfb413 --- /dev/null +++ "b/LeetCode-Python/0113.\350\267\257\345\276\204\346\200\273\345\222\214II/0113-\350\267\257\345\276\204\346\200\273\345\222\214II.py" @@ -0,0 +1,47 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def pathSum(self, root: Optional[TreeNode], targetSum: int) -> List[List[int]]: +# self.res = [] +# def dfs(node, path_sum, path): +# if not node: +# return + +# path_sum += node.val +# path.append(node.val) +# if targetSum == path_sum and (not node.left and not node.right): +# self.res.append(path[:]) + +# dfs(node.left, path_sum, path[:]) +# dfs(node.right, path_sum, path[:]) + +# dfs(root, 0, []) +# return self.res + +from collections import deque +class Solution: + def pathSum(self, root: Optional[TreeNode], targetSum: int) -> List[List[int]]: + if not root: + return [] + + res = [] + queue = deque([(root, root.val, [root.val])]) # node, cur_path_sum, cur_path + + while queue: + node, cur_path_sum, cur_path = queue.popleft() + # print(cur_path_sum, cur_path, not node.left, not node.right) + if not node.left and not node.right and cur_path_sum == targetSum: + res.append(cur_path[:]) + continue + + if node.left: + queue.append((node.left, cur_path_sum + node.left.val, cur_path + [node.left.val])) + + if node.right: + queue.append((node.right, cur_path_sum + node.right.val, cur_path + [node.right.val])) + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250.py" "b/LeetCode-Python/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250.py" new file mode 100644 index 0000000..a5c4870 --- /dev/null +++ "b/LeetCode-Python/0114.\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250/0114-\344\272\214\345\217\211\346\240\221\345\261\225\345\274\200\344\270\272\351\223\276\350\241\250.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def flatten(self, root: Optional[TreeNode]) -> None: + """ + Do not return anything, modify root in-place instead. + """ + if not root: + return None + + left = root.left + right = root.right + + self.flatten(left) + root.right = left + root.left = None + + p = root + while p.right: + p = p.right + + self.flatten(right) + p.right = right + diff --git "a/LeetCode-Python/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210.py" "b/LeetCode-Python/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210.py" new file mode 100644 index 0000000..28a993b --- /dev/null +++ "b/LeetCode-Python/0116.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210/0116-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210.py" @@ -0,0 +1,31 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None): + self.val = val + self.left = left + self.right = right + self.next = next +""" + +class Solution: + def connect(self, root: 'Optional[Node]') -> 'Optional[Node]': + if not root: + return root + + def dfs(node): + if not node: + return + + if node.left: + node.left.next = node.right + if node.next: + node.right.next = node.next.left + else: + node.right.next = None + + dfs(node.left) + dfs(node.right) + + dfs(root) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II.py" "b/LeetCode-Python/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II.py" new file mode 100644 index 0000000..ab10600 --- /dev/null +++ "b/LeetCode-Python/0117.\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II/0117-\345\241\253\345\205\205\346\257\217\344\270\252\350\212\202\347\202\271\347\232\204\344\270\213\344\270\200\344\270\252\345\217\263\344\276\247\350\212\202\347\202\271\346\214\207\351\222\210II.py" @@ -0,0 +1,46 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None): + self.val = val + self.left = left + self.right = right + self.next = next +""" + +class Solution: + def connect(self, root: 'Node') -> 'Node': + if not root: + return root + + def findCousin(node, parent): + parent_nxt = parent.next + while parent_nxt: + if parent_nxt.left: + node.next = parent_nxt.left + return + + if parent_nxt.right: + node.next = parent_nxt.right + return + + parent_nxt = parent_nxt.next + + def dfs(node): + if not node: + return node + + if node.right and node.left: + node.left.next = node.right + findCousin(node.right, node) + elif node.left: + findCousin(node.left, node) + elif node.right: + findCousin(node.right, node) + + dfs(node.right) + dfs(node.left) + + + dfs(root) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.py" "b/LeetCode-Python/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.py" new file mode 100644 index 0000000..0443ae0 --- /dev/null +++ "b/LeetCode-Python/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272/0121-\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.py" @@ -0,0 +1,9 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + prev_min = None + res = 0 + for price in prices: + if prev_min is None or prev_min > price: + prev_min = price + res = max(res, price - prev_min) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" "b/LeetCode-Python/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..feca307 --- /dev/null +++ "b/LeetCode-Python/0125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/0125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,14 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + left, right = 0, len(s) - 1 + while left < right: + while left < right and (not s[left].isalpha() and not s[left].isdigit()): + left += 1 + + while left < right and (not s[right].isalpha() and not s[right].isdigit()): + right -= 1 + if s[left].upper() != s[right].upper(): + return False + left += 1 + right -= 1 + return True \ No newline at end of file diff --git "a/LeetCode-Python/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/LeetCode-Python/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..8f580e1 --- /dev/null +++ "b/LeetCode-Python/0129.\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214/0129-\346\261\202\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumNumbers(self, root: Optional[TreeNode]) -> int: + self.res = 0 + def dfs(node, cur_sum): + if not node: + return + + cur_sum = cur_sum * 10 + node.val + if not node.left and not node.right: + self.res += cur_sum + else: + dfs(node.left, cur_sum) + dfs(node.right, cur_sum) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" "b/LeetCode-Python/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" new file mode 100644 index 0000000..1802092 --- /dev/null +++ "b/LeetCode-Python/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" @@ -0,0 +1,43 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, val = 0, neighbors = None): + self.val = val + self.neighbors = neighbors if neighbors is not None else [] +""" + +from collections import deque +class Solution: + def cloneGraph(self, node: 'Node') -> 'Node': + if not node: + return node + + old2new = dict() + queue = deque([node]) + visited = set([node]) + while queue: + cur_node = queue.popleft() + new_node = Node(cur_node.val) + old2new[cur_node] = new_node + + for neighbor in cur_node.neighbors: + if neighbor not in visited: + visited.add(neighbor) + queue.append(neighbor) + + queue = deque([node]) + visited = set([node]) + while queue: + cur_node = queue.popleft() + new_node = old2new[cur_node] + + for neighbor in cur_node.neighbors: + new_neighbor = old2new[neighbor] + new_node.neighbors.append(new_neighbor) + + if neighbor not in visited: + visited.add(neighbor) + queue.append(neighbor) + return old2new[node] + + \ No newline at end of file diff --git "a/LeetCode-Python/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250.py" "b/LeetCode-Python/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250.py" new file mode 100644 index 0000000..79dbbff --- /dev/null +++ "b/LeetCode-Python/0138.\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250/0138-\345\244\215\345\210\266\345\270\246\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\351\223\276\350\241\250.py" @@ -0,0 +1,33 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): + self.val = int(x) + self.next = next + self.random = random +""" + +class Solution: + def copyRandomList(self, head: 'Optional[Node]') -> 'Optional[Node]': + if not head: + return head + + old2new = dict() + p = head + while p: + cur_node = p + new_node = Node(cur_node.val) + old2new[cur_node] = new_node + p = p.next + + p = head + while p: + cur_node = p + new_node = old2new[cur_node] + + if cur_node.next: + new_node.next = old2new[cur_node.next] + if cur_node.random: + new_node.random = old2new[cur_node.random] + p = p.next + return old2new[head] \ No newline at end of file diff --git "a/LeetCode-Python/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250.py" "b/LeetCode-Python/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250.py" new file mode 100644 index 0000000..f817d92 --- /dev/null +++ "b/LeetCode-Python/0141.\347\216\257\345\275\242\351\223\276\350\241\250/0141-\347\216\257\345\275\242\351\223\276\350\241\250.py" @@ -0,0 +1,18 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + fast, slow = head, head + + while fast and fast.next: + fast = fast.next.next + slow = slow.next + + if fast == slow: + return True + + return False \ No newline at end of file diff --git "a/LeetCode-Python/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II.py" "b/LeetCode-Python/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II.py" new file mode 100644 index 0000000..2e0c9fd --- /dev/null +++ "b/LeetCode-Python/0142.\347\216\257\345\275\242\351\223\276\350\241\250II/0142-\347\216\257\345\275\242\351\223\276\350\241\250II.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]: + fast, slow = head, head + has_loop = False + while fast and fast.next: + fast = fast.next.next + slow = slow.next + + if fast == slow: + has_loop = True + break + if not has_loop: + return None + + fast = head + while 1: + if fast == slow: + return fast + fast = fast.next + slow = slow.next diff --git "a/LeetCode-Python/0144.\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0144-\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0144.\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0144-\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..fd8165e --- /dev/null +++ "b/LeetCode-Python/0144.\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0144-\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]: +# if not root: +# return [] +# return [root.val] + self.preorderTraversal(root.left) + self.preorderTraversal(root.right) + +class Solution: + def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + stack = [root] + res = [] + while stack: + node = stack.pop() + if isinstance(node, TreeNode): + stack.extend([node.right, node.left, node.val]) + elif isinstance(node, int): + res.append(node) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0145.\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0145-\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0145.\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0145-\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..977b47b --- /dev/null +++ "b/LeetCode-Python/0145.\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0145-\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]: +# if not root: +# return [] +# return self.postorderTraversal(root.left) + self.postorderTraversal(root.right) + [root.val] + +class Solution: + def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]: + stack = [root] + res = [] + while stack: + node = stack.pop() + if isinstance(node, TreeNode): + stack.extend([node.val, node.right, node.left]) + elif isinstance(node, int): + res.append(node) + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.py" "b/LeetCode-Python/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.py" new file mode 100644 index 0000000..c2ab564 --- /dev/null +++ "b/LeetCode-Python/0150.\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274/0150-\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.py" @@ -0,0 +1,19 @@ +class Solution: + def evalRPN(self, tokens: List[str]) -> int: + stack = [] + for token in tokens: + if token in "+-*/": + second = stack.pop() + first = stack.pop() + if token == "+": + stack.append(second + first) + elif token == "-": + stack.append(first - second) + elif token == "*": + stack.append(first * second) + else: + stack.append(int(first / second)) + else: + stack.append(int(token)) + return stack[0] + \ No newline at end of file diff --git "a/LeetCode-Python/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" "b/LeetCode-Python/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" new file mode 100644 index 0000000..6b07361 --- /dev/null +++ "b/LeetCode-Python/0151.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215/0151-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215.py" @@ -0,0 +1,3 @@ +class Solution: + def reverseWords(self, s: str) -> str: + return " ".join(s.split()[::-1]) \ No newline at end of file diff --git "a/LeetCode-Python/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" "b/LeetCode-Python/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" new file mode 100644 index 0000000..023718b --- /dev/null +++ "b/LeetCode-Python/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" @@ -0,0 +1,30 @@ +class MinStack: + + def __init__(self): + self.min_stack = [] + self.stack = [] + + def push(self, val: int) -> None: + self.stack.append(val) + if self.min_stack and self.min_stack[-1] < val: + self.min_stack.append(self.min_stack[-1]) + else: + self.min_stack.append(val) + + def pop(self) -> None: + self.stack.pop() + self.min_stack.pop() + + def top(self) -> int: + return self.stack[-1] + + def getMin(self) -> int: + return self.min_stack[-1] + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(val) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file diff --git "a/LeetCode-Python/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250.py" "b/LeetCode-Python/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250.py" new file mode 100644 index 0000000..1e17d1e --- /dev/null +++ "b/LeetCode-Python/0160.\347\233\270\344\272\244\351\223\276\350\241\250/0160-\347\233\270\344\272\244\351\223\276\350\241\250.py" @@ -0,0 +1,37 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + la, lb = 0, 0 + p = headA + while p: + la += 1 + p = p.next + + p = headB + while p: + lb += 1 + p = p.next + + if la > lb: + headA, headB = headB, headA + la, lb = lb, la + + diff = lb - la + pa, pb = headA, headB + while diff: + pb = pb.next + diff -= 1 + + while pa and pb: + if pa == pb: + return pa + else: + pa = pa.next + pb = pb.next + + return None diff --git "a/LeetCode-Python/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240.py" "b/LeetCode-Python/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240.py" new file mode 100644 index 0000000..46b0d98 --- /dev/null +++ "b/LeetCode-Python/0169.\345\244\232\346\225\260\345\205\203\347\264\240/0169-\345\244\232\346\225\260\345\205\203\347\264\240.py" @@ -0,0 +1,16 @@ +class Solution: + def majorityElement(self, nums: List[int]) -> int: + mode, count = None, 0 + for num in nums: + if not mode: + mode = num + count = 1 + else: + if num != mode: + count -= 1 + if count == 0: + mode = num + count = 1 + else: + count += 1 + return mode \ No newline at end of file diff --git "a/LeetCode-Python/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" "b/LeetCode-Python/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" new file mode 100644 index 0000000..0ea399b --- /dev/null +++ "b/LeetCode-Python/0189.\350\275\256\350\275\254\346\225\260\347\273\204/0189-\350\275\256\350\275\254\346\225\260\347\273\204.py" @@ -0,0 +1,15 @@ +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + def reverse(left, right): + while left < right: + nums[left], nums[right] = nums[right], nums[left] + left += 1 + right -= 1 + k = k % len(nums) + reverse(0, len(nums) - 1) + reverse(0, k - 1) + reverse(k, len(nums) - 1) + \ No newline at end of file diff --git "a/LeetCode-Python/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215.py" "b/LeetCode-Python/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215.py" new file mode 100644 index 0000000..9e6de15 --- /dev/null +++ "b/LeetCode-Python/0198.\346\211\223\345\256\266\345\212\253\350\210\215/0198-\346\211\223\345\256\266\345\212\253\350\210\215.py" @@ -0,0 +1,26 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + # res = 0 + # n = len(nums) + # memo = dict() + # def dfs(n): + # if n < 0: + # return 0 + # if n in memo: + # return memo[n] + # # f(n) = max(f(n - 1), f(n - 2) + nums[n]) + # res = max(dfs(n - 1), dfs(n - 2) + nums[n]) + # memo[n] = res + # return res + # return dfs(n - 1) + res = 0 + n = len(nums) + # dp[n] = max(dp[n - 1], dp[n - 2] + nums[n]) + # dp[n + 2] = max(dp[n + 1], dp[n] + nums[n]) + # f(2) = max(f1, f0 + nums[n]) + f0, f1 = 0, 0 + for i, num in enumerate(nums): + new_f = max(f1, f0 + num) + f0 = f1 + f1 = new_f + return f1 \ No newline at end of file diff --git "a/LeetCode-Python/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" "b/LeetCode-Python/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" new file mode 100644 index 0000000..017550d --- /dev/null +++ "b/LeetCode-Python/0199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/0199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def rightSideView(self, root: Optional[TreeNode]) -> List[int]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + cur_level.append(node.val) + + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + + if cur_level: + res.append(cur_level[-1]) + queue = next_queue + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" "b/LeetCode-Python/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" new file mode 100644 index 0000000..bd5d960 --- /dev/null +++ "b/LeetCode-Python/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" @@ -0,0 +1,10 @@ +class Solution: + def isHappy(self, n: int) -> bool: + visited = set() + while 1: + if n == 1: + return True + visited.add(n) + n = sum([int(digit) ** 2 for digit in str(n)]) + if n in visited: + return False diff --git "a/LeetCode-Python/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..17a7584 --- /dev/null +++ "b/LeetCode-Python/0205.\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262/0205-\345\220\214\346\236\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,20 @@ +class Solution: + def isIsomorphic(self, s: str, t: str) -> bool: + char2word = dict() + word2char = dict() + + for i in range(len(s)): + char, word = s[i], t[i] + if char not in char2word: + char2word[char] = word + else: + if char2word[char] != word: + return False + + if word not in word2char: + word2char[word] = char + else: + if word2char[word] != char: + return False + + return True \ No newline at end of file diff --git "a/LeetCode-Python/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II.py" "b/LeetCode-Python/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II.py" new file mode 100644 index 0000000..e025995 --- /dev/null +++ "b/LeetCode-Python/0213.\346\211\223\345\256\266\345\212\253\350\210\215II/0213-\346\211\223\345\256\266\345\212\253\350\210\215II.py" @@ -0,0 +1,19 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + # dp[i][0/1] 0 represents room1 was safe + n = len(nums) + if len(nums) <= 2: + return max(nums) + dp = [[0, 0]for _ in range(n)] + dp[0][1] = nums[0] + dp[1][1] = nums[0] + dp[1][0] = nums[1] + for i in range(2, n): + num = nums[i] + if i != n - 1: + dp[i][0] = max(dp[i - 2][0] + num, dp[i - 1][0]) + dp[i][1] = max(dp[i - 2][1] + num, dp[i - 1][1]) + else: + dp[i][0] = max(dp[i - 2][0] + num, dp[i - 1][0]) + dp[i][1] = max(dp[i - 2][1], dp[i - 1][1]) + return max(dp[n - 1][0], dp[n - 1][1]) \ No newline at end of file diff --git "a/LeetCode-Python/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.py" "b/LeetCode-Python/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.py" new file mode 100644 index 0000000..026133a --- /dev/null +++ "b/LeetCode-Python/0215.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240/0215-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.py" @@ -0,0 +1,15 @@ +class Solution: + def findKthLargest(self, nums: List[int], k: int) -> int: + bucket = [0 for _ in range(2 * (10 ** 4) + 1)] + + for num in nums: + bucket[num + 10 ** 4] += 1 + + cur = 0 + for index, count in enumerate(bucket): + if count: + # print(index, count) + cur += count + if cur >= (len(nums) - k + 1): + return index - 10 ** 4 + \ No newline at end of file diff --git "a/LeetCode-Python/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II.py" "b/LeetCode-Python/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II.py" new file mode 100644 index 0000000..da1425f --- /dev/null +++ "b/LeetCode-Python/0219.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II/0219-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240II.py" @@ -0,0 +1,24 @@ +class Solution: + def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: + # sliding window + from collections import defaultdict + k = min(k, len(nums)) + left, right = 0, k + 1 + num2freq = defaultdict(int) + + for index in range(left, right): + if index < len(nums): + num = nums[index] + num2freq[num] += 1 + if num2freq[num] > 1: + return True + + while right < len(nums): + # [left, right) + num2freq[nums[left]] -= 1 + num2freq[nums[right]] += 1 + if num2freq[nums[right]] > 1: + return True + right += 1 + left += 1 + return False \ No newline at end of file diff --git "a/LeetCode-Python/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.py" "b/LeetCode-Python/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.py" new file mode 100644 index 0000000..b723ccc --- /dev/null +++ "b/LeetCode-Python/0222.\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260/0222-\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def countNodes(self, root: Optional[TreeNode]) -> int: + def inorder(node): + if not node: + return 0 + + return 1 + inorder(node.left) + inorder(node.right) + return inorder(root) \ No newline at end of file diff --git "a/LeetCode-Python/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0226-\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0226-\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..4fe6533 --- /dev/null +++ "b/LeetCode-Python/0226.\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0226-\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: + if not root: + return root + root.left, root.right = root.right, root.left + self.invertTree(root.left) + self.invertTree(root.right) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264.py" "b/LeetCode-Python/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264.py" new file mode 100644 index 0000000..675f568 --- /dev/null +++ "b/LeetCode-Python/0228.\346\261\207\346\200\273\345\214\272\351\227\264/0228-\346\261\207\346\200\273\345\214\272\351\227\264.py" @@ -0,0 +1,24 @@ +class Solution: + def summaryRanges(self, nums: List[int]) -> List[str]: + if not nums: + return [] + res = [] + left, right = None, None + for i, num in enumerate(nums): + if i == 0: + left = num + else: + if nums[i - 1] != num - 1: + right = nums[i - 1] + if left != right: + res.append(str(left) + "->" + str(right)) + else: + res.append(str(left)) + left = num + + if left != num: + res.append(str(left) + "->" + str(num)) + else: + res.append(str(num)) + return res + diff --git "a/LeetCode-Python/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" "b/LeetCode-Python/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" new file mode 100644 index 0000000..39a305e --- /dev/null +++ "b/LeetCode-Python/0230.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/0230-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: + self.count = 0 + self.res = 0 + def inorder(node): + if not node: + return + + inorder(node.left) + self.count += 1 + if self.count == k: + self.res = node.val + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202.py" "b/LeetCode-Python/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202.py" new file mode 100644 index 0000000..829fec0 --- /dev/null +++ "b/LeetCode-Python/0231.2\347\232\204\345\271\202/0231-2\347\232\204\345\271\202.py" @@ -0,0 +1,3 @@ +class Solution: + def isPowerOfTwo(self, n: int) -> bool: + return bin(n)[2:].count("1") == 1 if n > 0 else False \ No newline at end of file diff --git "a/LeetCode-Python/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" "b/LeetCode-Python/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..f2cc537 --- /dev/null +++ "b/LeetCode-Python/0237.\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/0237-\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,20 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def deleteNode(self, node): + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + p = node + while p and p.next: + p.val = p.next.val + if not p.next.next: + p.next = None + break + p = p.next + \ No newline at end of file diff --git "a/LeetCode-Python/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257.py" "b/LeetCode-Python/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257.py" new file mode 100644 index 0000000..fd5f8a4 --- /dev/null +++ "b/LeetCode-Python/0238.\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257/0238-\351\231\244\350\207\252\350\272\253\344\273\245\345\244\226\346\225\260\347\273\204\347\232\204\344\271\230\347\247\257.py" @@ -0,0 +1,15 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + prefix_multip = [1] + [1 for _ in nums] # [1, 1, 2, 6, 24] + postfix_multip = [1 for _ in nums] + [1] # [24,12,4, 1, 1] + + for i in range(len(nums)): + prefix_multip[i + 1] = prefix_multip[i] * nums[i] + + for i in range(len(nums) - 2, -1, -1): + postfix_multip[i] = nums[i + 1] * postfix_multip[i + 1] + + res = [] + for i in range(len(nums)): + res.append(prefix_multip[i] * postfix_multip[i]) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.py" "b/LeetCode-Python/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.py" new file mode 100644 index 0000000..77d90b7 --- /dev/null +++ "b/LeetCode-Python/0242.\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/0242-\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.py" @@ -0,0 +1,4 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + from collections import Counter + return Counter(s) == Counter(t) \ No newline at end of file diff --git "a/LeetCode-Python/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.py" "b/LeetCode-Python/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.py" new file mode 100644 index 0000000..00dd9b1 --- /dev/null +++ "b/LeetCode-Python/0257.\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204/0257-\344\272\214\345\217\211\346\240\221\347\232\204\346\211\200\346\234\211\350\267\257\345\276\204.py" @@ -0,0 +1,25 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]: + if not root: + return [] + + self.res = [] + def dfs(node, path): + if not node: + return + + path.append(str(node.val)) + if not node.left and not node.right: + self.res.append("->".join(path)) + + dfs(node.left, path[:]) + dfs(node.right, path[:]) + + dfs(root, []) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240.py" "b/LeetCode-Python/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240.py" new file mode 100644 index 0000000..60b196a --- /dev/null +++ "b/LeetCode-Python/0258.\345\220\204\344\275\215\347\233\270\345\212\240/0258-\345\220\204\344\275\215\347\233\270\345\212\240.py" @@ -0,0 +1,9 @@ +class Solution: + def addDigits(self, num: int) -> int: + while num > 9: + new_nums = 0 + while num: + num, n = divmod(num, 10) + new_nums += n + num = new_nums + return num \ No newline at end of file diff --git "a/LeetCode-Python/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" "b/LeetCode-Python/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" new file mode 100644 index 0000000..f84b4d3 --- /dev/null +++ "b/LeetCode-Python/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" @@ -0,0 +1,18 @@ +class Solution: + def nthUglyNumber(self, n: int) -> int: + import heapq + + min_heap = [1] # find the smallest ugly number + visited = set() + cnt = n + while cnt: + cur = heappop(min_heap) + cnt -= 1 + if not cnt: + return cur + for multiple in [2, 3, 5]: + nxt = cur * multiple + if nxt not in visited: + visited.add(nxt) + heappush(min_heap, nxt) + \ No newline at end of file diff --git "a/LeetCode-Python/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/LeetCode-Python/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..92349c3 --- /dev/null +++ "b/LeetCode-Python/0268.\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227/0268-\344\270\242\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,4 @@ +class Solution: + def missingNumber(self, nums: List[int]) -> int: + n = len(nums) + return (1 + n) * n // 2 - sum(nums) \ No newline at end of file diff --git "a/LeetCode-Python/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II.py" "b/LeetCode-Python/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II.py" new file mode 100644 index 0000000..ae57eaf --- /dev/null +++ "b/LeetCode-Python/0272.\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II/0272-\346\234\200\346\216\245\350\277\221\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\200\274II.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +from heapq import * +class Solution: + def closestKValues(self, root: Optional[TreeNode], target: float, k: int) -> List[int]: + max_heap = [] + + def inorder(node): + if not node: + return + + inorder(node.left) + if len(max_heap) < k: + heappush(max_heap, (-abs(node.val - target), node.val)) + else: + heappushpop(max_heap, (-abs(node.val - target), node.val)) + inorder(node.right) + + inorder(root) + return [val for _, val in max_heap] + + \ No newline at end of file diff --git "a/LeetCode-Python/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217.py" "b/LeetCode-Python/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217.py" new file mode 100644 index 0000000..d107fe9 --- /dev/null +++ "b/LeetCode-Python/0289.\347\224\237\345\221\275\346\270\270\346\210\217/0289-\347\224\237\345\221\275\346\270\270\346\210\217.py" @@ -0,0 +1,34 @@ +class Solution: + def gameOfLife(self, board: List[List[int]]) -> None: + """ + Do not return anything, modify board in-place instead. + """ + di = [1, 1, 1, -1, -1, -1, 0, 0] + dj = [1, 0, -1, 1, 0, -1, 1, -1] + + if not board or not board[0]: + return board + + m, n = len(board), len(board[0]) + dead_set = set() + live_set = set() + for i in range(m): + for j in range(n): + live_cell_count = 0 + for k in range(8): + ii, jj = i + di[k], j + dj[k] + if 0 <= ii < m and 0 <= jj < n and board[ii][jj] == 1: + live_cell_count += 1 + if board[i][j] == 1 and (live_cell_count < 2 or live_cell_count > 3): + dead_set.add((i, j)) + elif board[i][j] == 0 and live_cell_count == 3: + live_set.add((i, j)) + + for i in range(m): + for j in range(n): + if (i, j) in dead_set: + board[i][j] = 0 + elif (i, j) in live_set: + board[i][j] = 1 + return board + \ No newline at end of file diff --git "a/LeetCode-Python/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213.py" "b/LeetCode-Python/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213.py" new file mode 100644 index 0000000..74a9324 --- /dev/null +++ "b/LeetCode-Python/0290.\345\215\225\350\257\215\350\247\204\345\276\213/0290-\345\215\225\350\257\215\350\247\204\345\276\213.py" @@ -0,0 +1,24 @@ +class Solution: + def wordPattern(self, pattern: str, s: str) -> bool: + char2word = dict() + word2char = dict() + + words = [word for word in s.split()] + if len(words) != len(pattern): + return False + + for i in range(len(words)): + char, word = words[i], pattern[i] + if char not in char2word: + char2word[char] = word + else: + if char2word[char] != word: + return False + + if word not in word2char: + word2char[word] = char + else: + if word2char[word] != char: + return False + + return True \ No newline at end of file diff --git "a/LeetCode-Python/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217.py" "b/LeetCode-Python/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217.py" new file mode 100644 index 0000000..81e7126 --- /dev/null +++ "b/LeetCode-Python/0292.Nim\346\270\270\346\210\217/0292-Nim\346\270\270\346\210\217.py" @@ -0,0 +1,3 @@ +class Solution: + def canWinNim(self, n: int) -> bool: + return n % 4 != 0 \ No newline at end of file diff --git "a/LeetCode-Python/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" "b/LeetCode-Python/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" new file mode 100644 index 0000000..6fb1177 --- /dev/null +++ "b/LeetCode-Python/0313.\350\266\205\347\272\247\344\270\221\346\225\260/0313-\350\266\205\347\272\247\344\270\221\346\225\260.py" @@ -0,0 +1,16 @@ +class Solution: + def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int: + import heapq + min_heap = [1] # find the smallest ugly number + visited = set() + cnt = n + while cnt: + cur = heappop(min_heap) + cnt -= 1 + if not cnt: + return cur + for multiple in primes: + nxt = cur * multiple + if nxt not in visited: + visited.add(nxt) + heappush(min_heap, nxt) \ No newline at end of file diff --git "a/LeetCode-Python/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" "b/LeetCode-Python/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" new file mode 100644 index 0000000..0b190ed --- /dev/null +++ "b/LeetCode-Python/0316.\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215/0316-\345\216\273\351\231\244\351\207\215\345\244\215\345\255\227\346\257\215.py" @@ -0,0 +1,13 @@ +class Solution: + def removeDuplicateLetters(self, s: str) -> str: + from collections import Counter + c = Counter(s) + stack = [] # incresing stack + for char in s: + c[char] -= 1 + if char in stack: + continue + while stack and stack[-1] > char and c[stack[-1]] >= 1: + stack.pop() + stack.append(char) + return "".join(stack) \ No newline at end of file diff --git "a/LeetCode-Python/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..02d4896 --- /dev/null +++ "b/LeetCode-Python/0344.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262/0344-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,11 @@ +class Solution: + def reverseString(self, s: List[str]) -> None: + """ + Do not return anything, modify s in-place instead. + """ + left, right = 0, len(s) - 1 + while left < right: + s[left], s[right] = s[right], s[left] + left += 1 + right -= 1 + \ No newline at end of file diff --git "a/LeetCode-Python/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" "b/LeetCode-Python/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" new file mode 100644 index 0000000..5b754c9 --- /dev/null +++ "b/LeetCode-Python/0349.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/0349-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" @@ -0,0 +1,21 @@ +class Solution: + def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: + if len(nums1) > len(nums2): + nums1, nums2 = nums2, nums1 + + nums2.sort() + res = set() + for num in nums1: + if num not in res: + # search num in nums2 + left, right = 0, len(nums2) - 1 + while left <= right: + mid = (left + right) // 2 + if nums2[mid] == num: + res.add(num) + break + elif nums2[mid] < num: + left = mid + 1 + else: + right = mid - 1 + return list(res) \ No newline at end of file diff --git "a/LeetCode-Python/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" "b/LeetCode-Python/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" new file mode 100644 index 0000000..3b76846 --- /dev/null +++ "b/LeetCode-Python/0382.\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271/0382-\351\223\276\350\241\250\351\232\217\346\234\272\350\212\202\347\202\271.py" @@ -0,0 +1,22 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +import random +class Solution: + + def __init__(self, head: Optional[ListNode]): + self.list = [] + p = head + while p: + self.list.append(p.val) + p = p.next + + def getRandom(self) -> int: + return random.choice(self.list) + + +# Your Solution object will be instantiated and called as such: +# obj = Solution(head) +# param_1 = obj.getRandom() \ No newline at end of file diff --git "a/LeetCode-Python/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241.py" "b/LeetCode-Python/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241.py" new file mode 100644 index 0000000..d55d495 --- /dev/null +++ "b/LeetCode-Python/0383.\350\265\216\351\207\221\344\277\241/0383-\350\265\216\351\207\221\344\277\241.py" @@ -0,0 +1,4 @@ +class Solution: + def canConstruct(self, ransomNote: str, magazine: str) -> bool: + from collections import Counter + return Counter(magazine) >= Counter(ransomNote) \ No newline at end of file diff --git "a/LeetCode-Python/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.py" "b/LeetCode-Python/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..d1ef746 --- /dev/null +++ "b/LeetCode-Python/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227/0392-\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,8 @@ +class Solution: + def isSubsequence(self, s: str, t: str) -> bool: + ps, pt = 0, 0 + while ps < len(s) and pt < len(t): + if s[ps] == t[pt]: + ps += 1 + pt += 1 + return ps == len(s) \ No newline at end of file diff --git "a/LeetCode-Python/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/LeetCode-Python/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..78965e2 --- /dev/null +++ "b/LeetCode-Python/0410.\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274/0410-\345\210\206\345\211\262\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,19 @@ +class Solution: + def splitArray(self, nums: List[int], k: int) -> int: + left, right = max(nums), sum(nums) + while left <= right: + mid = (left + right) // 2 # target answer + + subarray_cnt, cur_sum = 1, 0 + for num in nums: + if cur_sum + num <= mid: + cur_sum += num + else: + subarray_cnt += 1 + cur_sum = num + + if subarray_cnt <= k: # need to get more subarrays + right = mid - 1 + elif subarray_cnt > k: + left = mid + 1 + return left \ No newline at end of file diff --git a/LeetCode-Python/0412.FizzBuzz/0412-FizzBuzz.py b/LeetCode-Python/0412.FizzBuzz/0412-FizzBuzz.py new file mode 100644 index 0000000..65533c7 --- /dev/null +++ b/LeetCode-Python/0412.FizzBuzz/0412-FizzBuzz.py @@ -0,0 +1,13 @@ +class Solution: + def fizzBuzz(self, n: int) -> List[str]: + res = [] + for i in range(1, n + 1): + if i % 3 == 0 and i % 5 == 0: + res.append("FizzBuzz") + elif i % 3 == 0: + res.append("Fizz") + elif i % 5 == 0: + res.append("Buzz") + else: + res.append(str(i)) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217.py" "b/LeetCode-Python/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217.py" new file mode 100644 index 0000000..698dd1b --- /dev/null +++ "b/LeetCode-Python/0451.\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217/0451-\346\240\271\346\215\256\345\255\227\347\254\246\345\207\272\347\216\260\351\242\221\347\216\207\346\216\222\345\272\217.py" @@ -0,0 +1,15 @@ +from heapq import * +class Solution: + def frequencySort(self, s: str) -> str: + from collections import Counter + c = Counter(s) + + max_heap = [] + for char, freq in c.items(): + heappush(max_heap, (-freq, char)) + + res = "" + while max_heap: + freq, char = heappop(max_heap) + res += -freq * char + return res \ No newline at end of file diff --git "a/LeetCode-Python/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" "b/LeetCode-Python/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" new file mode 100644 index 0000000..ef93c59 --- /dev/null +++ "b/LeetCode-Python/0496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/0496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" @@ -0,0 +1,19 @@ +class Solution: + def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: + + num2larger = dict() + stack = [] + for i, num in enumerate(nums2): + while stack and nums2[stack[-1]] < num: + last_index = stack[-1] + num2larger[nums2[last_index]] = num + stack.pop() + stack.append(i) + + res = [] + for num in nums1: + if num in num2larger: + res.append(num2larger[num]) + else: + res.append(-1) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214.py" "b/LeetCode-Python/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214.py" new file mode 100644 index 0000000..d4a1366 --- /dev/null +++ "b/LeetCode-Python/0500.\351\224\256\347\233\230\350\241\214/0500-\351\224\256\347\233\230\350\241\214.py" @@ -0,0 +1,25 @@ +class Solution: + def findWords(self, words: List[str]) -> List[str]: + row_1 = "qwertyuiop" + row_2 = "asdfghjkl" + row_3 = "zxcvbnm" + res = [] + for word in words: + l_word = word.lower() + row = "" + if l_word[0] in row_1: + row = row_1 + elif l_word[0] in row_2: + row = row_2 + elif l_word[0] in row_3: + row = row_3 + + inSameRow = True + for char in l_word: + if char not in row: + inSameRow = False + break + + if inSameRow: + res.append(word) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II.py" "b/LeetCode-Python/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II.py" new file mode 100644 index 0000000..9cdc34c --- /dev/null +++ "b/LeetCode-Python/0503.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II/0503-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240II.py" @@ -0,0 +1,13 @@ +class Solution: + def nextGreaterElements(self, nums: List[int]) -> List[int]: + stack = [] + res = [-1 for _ in nums] + for i, num in enumerate(nums + nums): + while stack and nums[stack[-1]] < num: + last_index = stack[-1] + res[last_index] = num + stack.pop() + if i < len(nums): + stack.append(i) + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" "b/LeetCode-Python/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" new file mode 100644 index 0000000..4dbfe25 --- /dev/null +++ "b/LeetCode-Python/0506.\347\233\270\345\257\271\345\220\215\346\254\241/0506-\347\233\270\345\257\271\345\220\215\346\254\241.py" @@ -0,0 +1,21 @@ +class Solution: + def findRelativeRanks(self, score: List[int]) -> List[str]: + p = [[score[i], i] for i in range(len(score))] + + p.sort(key = lambda x: -x[0]) + + res = [0 for _ in score] + for index, pair in enumerate(p): + score, original_index = pair[0], pair[1] + + if index == 0: + val = "Gold Medal" + elif index == 1: + val = "Silver Medal" + elif index == 2: + val = "Bronze Medal" + else: + val = str(index + 1) + + res[original_index] = val + return res \ No newline at end of file diff --git "a/LeetCode-Python/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.py" "b/LeetCode-Python/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.py" new file mode 100644 index 0000000..5738ae9 --- /dev/null +++ "b/LeetCode-Python/0513.\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274/0513-\346\211\276\346\240\221\345\267\246\344\270\213\350\247\222\347\232\204\345\200\274.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findBottomLeftValue(self, root: Optional[TreeNode]) -> int: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res[-1][0] \ No newline at end of file diff --git "a/LeetCode-Python/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274.py" "b/LeetCode-Python/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..65363a5 --- /dev/null +++ "b/LeetCode-Python/0515.\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274/0515-\345\234\250\346\257\217\344\270\252\346\240\221\350\241\214\344\270\255\346\211\276\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def largestValues(self, root: Optional[TreeNode]) -> List[int]: + queue = [root] + res = [] + + while queue: + next_queue = [] + max_val = float("-inf") + for node in queue: + if node: + max_val = max(max_val, node.val) + next_queue.extend([node.left, node.right]) + + queue = next_queue + if max_val != float("-inf"): + res.append(max_val) + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" "b/LeetCode-Python/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" new file mode 100644 index 0000000..1304139 --- /dev/null +++ "b/LeetCode-Python/0521.\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240/0521-\346\234\200\351\225\277\347\211\271\346\256\212\345\272\217\345\210\227\342\205\240.py" @@ -0,0 +1,5 @@ +class Solution: + def findLUSlength(self, a: str, b: str) -> int: + if a == b: + return -1 + return max(len(a), len(b)) \ No newline at end of file diff --git "a/LeetCode-Python/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.py" "b/LeetCode-Python/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.py" new file mode 100644 index 0000000..5789d11 --- /dev/null +++ "b/LeetCode-Python/0538.\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221/0538-\346\212\212\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\346\215\242\344\270\272\347\264\257\345\212\240\346\240\221.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def convertBST(self, root: Optional[TreeNode]) -> Optional[TreeNode]: + self.cur_sum = 0 + def backwardInorder(node): + if not node: + return + + backwardInorder(node.right) + self.cur_sum += node.val + node.val = self.cur_sum + backwardInorder(node.left) + + backwardInorder(root) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III.py" "b/LeetCode-Python/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III.py" new file mode 100644 index 0000000..0f3aa81 --- /dev/null +++ "b/LeetCode-Python/0557.\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III/0557-\345\217\215\350\275\254\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\215\225\350\257\215III.py" @@ -0,0 +1,3 @@ +class Solution: + def reverseWords(self, s: str) -> str: + return " ".join(word[::-1] for word in s.split()) \ No newline at end of file diff --git "a/LeetCode-Python/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..1a246d0 --- /dev/null +++ "b/LeetCode-Python/0589.N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206/0589-N\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,25 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, val=None, children=None): + self.val = val + self.children = children +""" + +class Solution: + def preorder(self, root: 'Node') -> List[int]: + # root, left, right => right, left, root + if not root: + return [] + res = [] + stack = [root] + + while stack: + cur = stack.pop() + if isinstance(cur, Node): + for child in cur.children[::-1]: + stack.append(child) + stack.append(cur.val) + else: + res.append(cur) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" "b/LeetCode-Python/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" new file mode 100644 index 0000000..40ce7ef --- /dev/null +++ "b/LeetCode-Python/0590.N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206/0590-N\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.py" @@ -0,0 +1,25 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, val=None, children=None): + self.val = val + self.children = children +""" + +class Solution: + def postorder(self, root: 'Node') -> List[int]: + # left, right, root => root, right, left + if not root: + return [] + res = [] + stack = [root] + + while stack: + cur = stack.pop() + if isinstance(cur, Node): + stack.append(cur.val) + for child in cur.children[::-1]: + stack.append(child) + else: + res.append(cur) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..d4f48f0 --- /dev/null +++ "b/LeetCode-Python/0617.\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221/0617-\345\220\210\345\271\266\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def mergeTrees(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> Optional[TreeNode]: + if not root1 and not root2: + return None + if root1 and not root2: + return root1 + if not root1 and root2: + return root2 + + root1.val += root2.val + + root1.left = self.mergeTrees(root1.left, root2.left) + root1.right = self.mergeTrees(root1.right, root2.right) + return root1 \ No newline at end of file diff --git "a/LeetCode-Python/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274.py" "b/LeetCode-Python/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274.py" new file mode 100644 index 0000000..0eb440d --- /dev/null +++ "b/LeetCode-Python/0637.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274/0637-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\271\263\345\235\207\345\200\274.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def averageOfLevels(self, root: Optional[TreeNode]) -> List[float]: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_sum = 0 + cur_count = 0 + + for node in queue: + if node: + cur_count += 1 + cur_sum += node.val + + next_queue.append(node.left) + next_queue.append(node.right) + if cur_count: + res.append(cur_sum * 1.0 / cur_count) + queue = next_queue + return res \ No newline at end of file diff --git "a/LeetCode-Python/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..6005f43 --- /dev/null +++ "b/LeetCode-Python/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: Optional[TreeNode], k: int) -> bool: + visited = set() + self.res = False + + def inorder(node): + if not node: + return + + inorder(node.left) + + if k - node.val in visited: + self.res = True + visited.add(node.val) + + if not self.res: + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..3579ecc --- /dev/null +++ "b/LeetCode-Python/0654.\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221/0654-\346\234\200\345\244\247\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]: + if not nums: + return None + + max_val = max(nums) + max_val_index = nums.index(max_val) + + root = TreeNode(max_val, self.constructMaximumBinaryTree(nums[:max_val_index]), self.constructMaximumBinaryTree(nums[max_val_index + 1:])) + return root \ No newline at end of file diff --git "a/LeetCode-Python/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271.py" "b/LeetCode-Python/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271.py" new file mode 100644 index 0000000..c62ed16 --- /dev/null +++ "b/LeetCode-Python/0657.\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271/0657-\346\234\272\345\231\250\344\272\272\350\203\275\345\220\246\350\277\224\345\233\236\345\216\237\347\202\271.py" @@ -0,0 +1,15 @@ +class Solution: + def judgeCircle(self, moves: str) -> bool: + x, y = 0, 0 + + for move in moves: + if move == "R": + y += 1 + elif move == "L": + y -= 1 + elif move == "U": + x -= 1 + else: + x += 1 + + return [x, y] == [0, 0] \ No newline at end of file diff --git "a/LeetCode-Python/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" "b/LeetCode-Python/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" new file mode 100644 index 0000000..90330a6 --- /dev/null +++ "b/LeetCode-Python/0680.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II/0680-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262II.py" @@ -0,0 +1,20 @@ +class Solution: + def validPalindrome(self, s: str) -> bool: + delete = False + left, right = 0, len(s) - 1 + + while left < right: + if s[left] != s[right]: + if not delete: + delete = True + break + left += 1 + right -= 1 + + if delete: + s1 = s[:left] + s[left + 1:] + s2 = s[:right] + s[right + 1:] + return s1 == s1[::-1] or s2 == s2[::-1] + else: + return True + \ No newline at end of file diff --git "a/LeetCode-Python/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233.py" "b/LeetCode-Python/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233.py" new file mode 100644 index 0000000..0aecf36 --- /dev/null +++ "b/LeetCode-Python/0682.\346\243\222\347\220\203\346\257\224\350\265\233/0682-\346\243\222\347\220\203\346\257\224\350\265\233.py" @@ -0,0 +1,13 @@ +class Solution: + def calPoints(self, operations: List[str]) -> int: + stack = [] + for op in operations: + if op == "+": + stack.append(stack[-1] + stack[-2]) + elif op == "C": + stack.pop() + elif op == "D": + stack.append(2 * stack[-1]) + else: + stack.append(int(op)) + return sum(stack) diff --git "a/LeetCode-Python/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.py" "b/LeetCode-Python/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.py" new file mode 100644 index 0000000..0b23b9d --- /dev/null +++ "b/LeetCode-Python/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242/0700-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]: + self.res = None + def inorder(node): + if not node or self.res: + return + + inorder(node.left) + if node.val == val: + self.res = node + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204.py" "b/LeetCode-Python/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 0000000..f92b21b --- /dev/null +++ "b/LeetCode-Python/0702.\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204/0702-\346\220\234\347\264\242\351\225\277\345\272\246\346\234\252\347\237\245\347\232\204\346\234\211\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,25 @@ +# """ +# This is ArrayReader's API interface. +# You should not implement it, or speculate about its implementation +# """ +#class ArrayReader: +# def get(self, index: int) -> int: + +class Solution: + def search(self, reader: 'ArrayReader', target: int) -> int: + OVERFLOW = 2 ** 31 - 1 + left, right = 0, 10 ** 4 + while left <= right: + mid = (left + right) // 2 + returned_val = reader.get(mid) + if returned_val == OVERFLOW: + right = mid - 1 + continue + if returned_val == target: + return mid + elif returned_val > target: + right = mid - 1 + else: + left = mid + 1 + return -1 + \ No newline at end of file diff --git "a/LeetCode-Python/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" "b/LeetCode-Python/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" new file mode 100644 index 0000000..4f478f0 --- /dev/null +++ "b/LeetCode-Python/0703.\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240/0703-\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\347\254\254K\345\244\247\345\205\203\347\264\240.py" @@ -0,0 +1,22 @@ +import heapq +class KthLargest: + def __init__(self, k: int, nums: List[int]): + self.k = k + self.min_heap = [] + for num in nums: + if len(self.min_heap) < k: + heappush(self.min_heap, num) + else: + heappushpop(self.min_heap, num) + + def add(self, val: int) -> int: + if len(self.min_heap) < self.k: + heappush(self.min_heap, val) + else: + heappushpop(self.min_heap, val) + return self.min_heap[0] + + +# Your KthLargest object will be instantiated and called as such: +# obj = KthLargest(k, nums) +# param_1 = obj.add(val) \ No newline at end of file diff --git "a/LeetCode-Python/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215.py" "b/LeetCode-Python/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215.py" new file mode 100644 index 0000000..318d48b --- /dev/null +++ "b/LeetCode-Python/0709.\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215/0709-\350\275\254\346\215\242\346\210\220\345\260\217\345\206\231\345\255\227\346\257\215.py" @@ -0,0 +1,6 @@ +class Solution: + def toLowerCase(self, s: str) -> str: + res = "" + for char in s: + res += char.lower() + return res \ No newline at end of file diff --git "a/LeetCode-Python/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" "b/LeetCode-Python/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" new file mode 100644 index 0000000..a5c61b3 --- /dev/null +++ "b/LeetCode-Python/0717.1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246/0717-1\346\257\224\347\211\271\344\270\2162\346\257\224\347\211\271\345\255\227\347\254\246.py" @@ -0,0 +1,15 @@ +class Solution: + def isOneBitCharacter(self, bits: List[int]) -> bool: + connected_with_prev = False + + for i, bit in enumerate(bits): + if connected_with_prev: + if i == len(bits) - 1: + return False + connected_with_prev = False + else: + if bit == 1: + connected_with_prev = True + else: + connected_with_prev = False + return True \ No newline at end of file diff --git "a/LeetCode-Python/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" "b/LeetCode-Python/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" new file mode 100644 index 0000000..cc285bb --- /dev/null +++ "b/LeetCode-Python/0725.\345\210\206\351\232\224\351\223\276\350\241\250/0725-\345\210\206\351\232\224\351\223\276\350\241\250.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def partition(self, head: Optional[ListNode], x: int) -> Optional[ListNode]: + dummy1 = ListNode(-1) + dummy2 = ListNode(-1) + + smaller_list = dummy1 + larger_list = dummy2 + p = head + while p: + if p.val < x: + new_node = ListNode(p.val) + smaller_list.next = new_node + smaller_list = smaller_list.next + else: + new_node = ListNode(p.val) + larger_list.next = new_node + larger_list = larger_list.next + p = p.next + + smaller_list.next = dummy2.next + return dummy1.next diff --git "a/LeetCode-Python/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.py" "b/LeetCode-Python/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.py" new file mode 100644 index 0000000..f4207cc --- /dev/null +++ "b/LeetCode-Python/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257/0746-\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.py" @@ -0,0 +1,21 @@ +class Solution: + def minCostClimbingStairs(self, cost: List[int]) -> int: + # n = len(cost) + # res = 0 + # @cache + # def dfs(n): + # # dfs(n) represents the cost to climb to index n + # if n < 0: + # return 0 + # if n <= 1: + # return 0 + # res = min(dfs(n - 1) + cost[n - 1], dfs(n - 2) + cost[n - 2]) + # return res + # return dfs(n) + n = len(cost) + res = 0 + f0, f1 = 0, 0 + for i in range(n - 1): + new_f = min(f1 + cost[i + 1], f0 + cost[i]) + f0, f1 = f1, new_f + return f1 \ No newline at end of file diff --git "a/LeetCode-Python/0771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/0771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" "b/LeetCode-Python/0771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/0771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" new file mode 100644 index 0000000..689442a --- /dev/null +++ "b/LeetCode-Python/0771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/0771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" @@ -0,0 +1,10 @@ +class Solution: + def numJewelsInStones(self, jewels: str, stones: str) -> int: + jewels = set(jewels) + + res = 0 + for stone in stones: + if stone in jewels: + res += 1 + + return res \ No newline at end of file diff --git "a/LeetCode-Python/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" "b/LeetCode-Python/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" new file mode 100644 index 0000000..bd10cee --- /dev/null +++ "b/LeetCode-Python/0786.\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260/0786-\347\254\254K\344\270\252\346\234\200\345\260\217\347\232\204\347\264\240\346\225\260\345\210\206\346\225\260.py" @@ -0,0 +1,10 @@ +class Solution: + def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]: + res = [] + + for i in range(len(arr)): + for j in range(i + 1, len(arr)): + res.append((arr[i], arr[j], arr[i] * 1.0 / arr[j])) + + res.sort(key = lambda x: x[2]) + return [res[k - 1][0], res[k - 1][1]] \ No newline at end of file diff --git "a/LeetCode-Python/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215.py" "b/LeetCode-Python/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215.py" new file mode 100644 index 0000000..bf02194 --- /dev/null +++ "b/LeetCode-Python/0804.\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215/0804-\345\224\257\344\270\200\346\221\251\345\260\224\346\226\257\345\257\206\347\240\201\350\257\215.py" @@ -0,0 +1,11 @@ +class Solution: + def uniqueMorseRepresentations(self, words: List[str]) -> int: + res = set() + mores = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] + + for word in words: + word_mores = "" + for char in word: + word_mores += mores[ord(char) - ord("a")] + res.add(word_mores) + return len(res) \ No newline at end of file diff --git "a/LeetCode-Python/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277.py" "b/LeetCode-Python/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277.py" new file mode 100644 index 0000000..c63aae3 --- /dev/null +++ "b/LeetCode-Python/0807.\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277/0807-\344\277\235\346\214\201\345\237\216\345\270\202\345\244\251\351\231\205\347\272\277.py" @@ -0,0 +1,8 @@ +class Solution: + def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int: + col_grid = [list(col) for col in zip(*grid)] + res = 0 + for i in range(len(grid)): + for j in range(len(grid)): + res += min(max(grid[i]), max(col_grid[j])) - grid[i][j] + return res \ No newline at end of file diff --git "a/LeetCode-Python/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217.py" "b/LeetCode-Python/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217.py" new file mode 100644 index 0000000..841a80a --- /dev/null +++ "b/LeetCode-Python/0832.\347\277\273\350\275\254\345\233\276\345\203\217/0832-\347\277\273\350\275\254\345\233\276\345\203\217.py" @@ -0,0 +1,9 @@ +class Solution: + def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]: + for i, row in enumerate(image): + image[i] = row[::-1] + + for i in range(len(image)): + for j in range(len(image)): + image[i][j] = 1 - image[i][j] + return image \ No newline at end of file diff --git "a/LeetCode-Python/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225.py" "b/LeetCode-Python/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225.py" new file mode 100644 index 0000000..e013042 --- /dev/null +++ "b/LeetCode-Python/0852.\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225/0852-\345\261\261\350\204\211\346\225\260\347\273\204\347\232\204\345\263\260\351\241\266\347\264\242\345\274\225.py" @@ -0,0 +1,13 @@ +class Solution: + def peakIndexInMountainArray(self, arr: List[int]) -> int: + left, right = 0, len(arr) - 1 + while left <= right: + mid = (left + right) // 2 + if 0 < mid < len(arr) - 1 and arr[mid - 1] < arr[mid] and arr[mid] > arr[mid + 1]: + return mid + + if arr[mid + 1] > arr[mid]: + left = mid + 1 + else: + right = mid - 1 + return left \ No newline at end of file diff --git "a/LeetCode-Python/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" "b/LeetCode-Python/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" new file mode 100644 index 0000000..39ec0a9 --- /dev/null +++ "b/LeetCode-Python/0876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/0876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]: + slow, fast = head, head + while fast and fast.next: + fast = fast.next.next + slow = slow.next + + return slow \ No newline at end of file diff --git "a/LeetCode-Python/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..c2d6aa1 --- /dev/null +++ "b/LeetCode-Python/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def increasingBST(self, root: TreeNode) -> TreeNode: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + inorder_list = inorder(root) + dummy = TreeNode(-1) + p = dummy + for val in inorder_list: + p.right = TreeNode(val) + p = p.right + + return dummy.right \ No newline at end of file diff --git "a/LeetCode-Python/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/LeetCode-Python/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 0000000..5ed8e8d --- /dev/null +++ "b/LeetCode-Python/0912.\346\216\222\345\272\217\346\225\260\347\273\204/0912-\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,13 @@ +class Solution: + def sortArray(self, nums: List[int]) -> List[int]: + RANGE = 5 * 10 ** 4 + bucket = [0 for _ in range(2 * RANGE + 1)] + + for num in nums: + bucket[num + RANGE] += 1 + + res = [] + for index, count in enumerate(bucket): + if count: + res.extend([index - RANGE] * count) + return res \ No newline at end of file diff --git "a/LeetCode-Python/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214.py" "b/LeetCode-Python/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214.py" new file mode 100644 index 0000000..8491c7c --- /dev/null +++ "b/LeetCode-Python/0938.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214/0938-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\350\214\203\345\233\264\345\222\214.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def rangeSumBST(self, root: Optional[TreeNode], low: int, high: int) -> int: + self.res = 0 + def inorder(node): + if not node: + return + + inorder(node.left) + if low <= node.val <= high: + self.res += node.val + + if node.val > high: + return + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/0965.\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221/0965-\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/0965.\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221/0965-\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..91b3525 --- /dev/null +++ "b/LeetCode-Python/0965.\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221/0965-\345\215\225\345\200\274\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,13 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isUnivalTree(self, root: Optional[TreeNode]) -> bool: + if not root: + return True + left = not root.left or (self.isUnivalTree(root.left) and root.left.val == root.val) + right = not root.right or (self.isUnivalTree(root.right) and root.right.val == root.val) + return left and right \ No newline at end of file diff --git "a/LeetCode-Python/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.py" "b/LeetCode-Python/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.py" new file mode 100644 index 0000000..e829b06 --- /dev/null +++ "b/LeetCode-Python/0973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/0973-\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.py" @@ -0,0 +1,15 @@ +from heapq import * +class Solution: + def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: + max_heap = [] + for x, y in points: + d = self.getDistance(0, 0, x, y) + if len(max_heap) < k: + heappush(max_heap, (-d, [x, y])) + else: + heappushpop(max_heap, (-d, [x, y])) + return [p for _, p in max_heap] + + + def getDistance(self, x1, y1, x2, y2): + return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 \ No newline at end of file diff --git "a/LeetCode-Python/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..94069fb --- /dev/null +++ "b/LeetCode-Python/1008.\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/1008-\345\211\215\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]: + if not preorder: + return None + + root = TreeNode(preorder[0]) + hasRight = False + for i, val in enumerate(preorder): + if val > root.val: + right_index = i + hasRight = True + break + + + if hasRight: + root.left = self.bstFromPreorder(preorder[1:right_index]) + root.right = self.bstFromPreorder(preorder[right_index:]) + else: + root.left = self.bstFromPreorder(preorder[1:]) + return root + diff --git "a/LeetCode-Python/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233.py" "b/LeetCode-Python/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233.py" new file mode 100644 index 0000000..516c1d5 --- /dev/null +++ "b/LeetCode-Python/1011.\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233/1011-\345\234\250D\345\244\251\345\206\205\351\200\201\350\276\276\345\214\205\350\243\271\347\232\204\350\203\275\345\212\233.py" @@ -0,0 +1,22 @@ +class Solution: + def shipWithinDays(self, weights: List[int], days: int) -> int: + left, right = max(weights), sum(weights) + while left <= right: + mid = (left + right) // 2 # answer to be returned, max(capacity) + + capacity = mid + needed_days, cur_sum = 1, 0 + for w in weights: + if cur_sum + w > capacity: + needed_days += 1 + cur_sum = w + else: + cur_sum += w + # print(capacity, needed_days, days) + if needed_days > days: # need to increase the capacity + left = mid + 1 + elif needed_days == days: + right = mid - 1 + elif needed_days < days: + right = mid - 1 + return left \ No newline at end of file diff --git "a/LeetCode-Python/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262.py" "b/LeetCode-Python/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262.py" new file mode 100644 index 0000000..f359abb --- /dev/null +++ "b/LeetCode-Python/1016.\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262/1016-\345\255\220\344\270\262\350\203\275\350\241\250\347\244\272\344\273\2161\345\210\260N\346\225\260\345\255\227\347\232\204\344\272\214\350\277\233\345\210\266\344\270\262.py" @@ -0,0 +1,7 @@ +class Solution: + def queryString(self, s: str, n: int) -> bool: + for i in range(1, n + 1): + b = bin(i)[2:] + if b not in s: + return False + return True \ No newline at end of file diff --git "a/LeetCode-Python/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242.py" "b/LeetCode-Python/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242.py" new file mode 100644 index 0000000..70ffa9b --- /dev/null +++ "b/LeetCode-Python/1017.\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242/1017-\350\264\237\344\272\214\350\277\233\345\210\266\350\275\254\346\215\242.py" @@ -0,0 +1,10 @@ +class Solution: + def baseNeg2(self, n: int) -> str: + if not n: + return "0" + l = "" + while n: + d, m = divmod(n, -2) + n = - (n // 2) + l += str(-m) + return l[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271.py" "b/LeetCode-Python/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271.py" new file mode 100644 index 0000000..9d73c03 --- /dev/null +++ "b/LeetCode-Python/1019.\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271/1019-\351\223\276\350\241\250\344\270\255\347\232\204\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\350\212\202\347\202\271.py" @@ -0,0 +1,25 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def nextLargerNodes(self, head: Optional[ListNode]) -> List[int]: + stack = [] # [(2, 0)] (node.val, node.index) + p, l = head, 0 + while p: + l += 1 + p = p.next + res = [0] * l + + p = head + cur_index = 0 + while p: + while stack and stack[-1][0] < p.val: + last_index = stack[-1][1] + res[last_index] = p.val + stack.pop() + stack.append((p.val, cur_index)) + p = p.next + cur_index += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267.py" "b/LeetCode-Python/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 0000000..bce974f --- /dev/null +++ "b/LeetCode-Python/1021.\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267/1021-\345\210\240\351\231\244\346\234\200\345\244\226\345\261\202\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,21 @@ +class Solution: + def removeOuterParentheses(self, s: str) -> str: + left, right = 0, 0 + stack = "" + res = "" + for char in s: + if char == "(": + left += 1 + stack += char + elif char == ")": + right += 1 + if left == right: + # find an outmost parenthesis pair + res += stack[1:] + stack = "" + else: + stack += char + return res + + + diff --git "a/LeetCode-Python/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214.py" "b/LeetCode-Python/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214.py" new file mode 100644 index 0000000..a8e81d0 --- /dev/null +++ "b/LeetCode-Python/1022.\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214/1022-\344\273\216\346\240\271\345\210\260\345\217\266\347\232\204\344\272\214\350\277\233\345\210\266\346\225\260\344\271\213\345\222\214.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumRootToLeaf(self, root: Optional[TreeNode]) -> int: + self.res = 0 + def dfs(node, cur_binary): + if not node: + return + + cur_binary = cur_binary * 2 + node.val + if not node.left and not node.right: + self.res += cur_binary + return + + dfs(node.left, cur_binary) + dfs(node.right, cur_binary) + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221.py" "b/LeetCode-Python/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221.py" new file mode 100644 index 0000000..19fdaf8 --- /dev/null +++ "b/LeetCode-Python/1038.\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221/1038-\344\273\216\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\210\260\346\233\264\345\244\247\345\222\214\346\240\221.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def bstToGst(self, root: TreeNode) -> TreeNode: + + self.cur_sum = 0 + def backwardInorder(node): + if not node: + return + + backwardInorder(node.right) + self.cur_sum += node.val + node.val = self.cur_sum + backwardInorder(node.left) + + backwardInorder(root) + return root \ No newline at end of file diff --git "a/LeetCode-Python/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" "b/LeetCode-Python/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" new file mode 100644 index 0000000..f78cd85 --- /dev/null +++ "b/LeetCode-Python/1046.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217/1046-\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217.py" @@ -0,0 +1,16 @@ +from heapq import * +class Solution: + def lastStoneWeight(self, stones: List[int]) -> int: + max_heap = [] + + for stone in stones: + heappush(max_heap, -stone) + + while len(max_heap) > 1: + x, y = -heappop(max_heap), -heappop(max_heap) + + if y == x: + continue + else: + heappush(max_heap, -(x - y)) + return -max_heap[0] if max_heap else 0 \ No newline at end of file diff --git "a/LeetCode-Python/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201.py" "b/LeetCode-Python/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201.py" new file mode 100644 index 0000000..f6cdbf3 --- /dev/null +++ "b/LeetCode-Python/1054.\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201/1054-\350\267\235\347\246\273\347\233\270\347\255\211\347\232\204\346\235\241\345\275\242\347\240\201.py" @@ -0,0 +1,25 @@ +class Solution: + def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]: + from collections import Counter + import heapq + d = Counter(barcodes) + res = [] + t = [] + for val, freq in d.items(): + t.append((-freq, val)) + heapify(t) + + last_pair = None + while t: + pair = heappop(t) + val, freq = pair[1], -pair[0] + res.append(val) + if last_pair: + heappush(t, last_pair) + freq -= 1 + if freq: + last_pair = (-freq, val) + else: + last_pair = None + + return res diff --git "a/LeetCode-Python/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" "b/LeetCode-Python/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" new file mode 100644 index 0000000..91c5e98 --- /dev/null +++ "b/LeetCode-Python/1073.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/1073-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" @@ -0,0 +1,20 @@ +class Solution: + def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]: + res = self.convertToDec(arr1) + self.convertToDec(arr2) + l = [] + if res == 0: + return [0] + while res: + d, m = divmod(res, -2) + res = - (res // 2) + l.append(-m) + return l[::-1] + + def convertToDec(self, arr): + res = 0 + for index, digit in enumerate(arr[::-1]): + res += digit * ((-2) ** index) + return res + + + \ No newline at end of file diff --git "a/LeetCode-Python/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" "b/LeetCode-Python/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" new file mode 100644 index 0000000..a61a8f3 --- /dev/null +++ "b/LeetCode-Python/1079.\346\264\273\345\255\227\345\215\260\345\210\267/1079-\346\264\273\345\255\227\345\215\260\345\210\267.py" @@ -0,0 +1,14 @@ +class Solution: + def numTilePossibilities(self, tiles: str) -> int: + res = set([""]) + + for tile in tiles: + new_res = set() + for r in res: + for i in range(len(r) + 1): + t = r[:i] + tile + r[i:] + if t not in res: + new_res.add(t) + res = res.union(new_res) + + return len(res) - 1 \ No newline at end of file diff --git "a/LeetCode-Python/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" "b/LeetCode-Python/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" new file mode 100644 index 0000000..96e16b6 --- /dev/null +++ "b/LeetCode-Python/1080.\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271/1080-\346\240\271\345\210\260\345\217\266\350\267\257\345\276\204\344\270\212\347\232\204\344\270\215\350\266\263\350\212\202\347\202\271.py" @@ -0,0 +1,44 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sufficientSubset(self, root: Optional[TreeNode], limit: int) -> Optional[TreeNode]: + survivor_nodes = set() + + def dfs(node, path): + if not node: + return + # path.append(node) + if not node.left and not node.right: + path.append(node) + path_sum = 0 + for n in path: + path_sum += n.val + if path_sum >= limit: + for n in path: + survivor_nodes.add(n) + return + dfs(node.left, path + [node]) + dfs(node.right, path + [node]) + + dfs(root, []) + # print(survivor_nodes) + def killNodes(node): + if not node: + return + + if node.left not in survivor_nodes: + node.left = None + if node.right not in survivor_nodes: + node.right = None + + killNodes(node.left) + killNodes(node.right) + + if root not in survivor_nodes: + return None + killNodes(root) + return root \ No newline at end of file diff --git "a/LeetCode-Python/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" "b/LeetCode-Python/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" new file mode 100644 index 0000000..67c8271 --- /dev/null +++ "b/LeetCode-Python/1091.\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1091-\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" @@ -0,0 +1,31 @@ +class Solution: + def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int: + from collections import deque + if not grid or not grid[0]: + return -1 + n = len(grid) + if grid[0][0] or grid[n - 1][n - 1]: + return -1 + + # BFS + dx = [0, 0, 1, 1, 1, -1, -1, -1] + dy = [1, -1, 1, 0, -1, 1, 0, -1] + + visited = set([(0, 0)]) + queue = deque([((0, 0), 1)]) # (x, y), step + + while queue: + cur = queue.popleft() + x, y, step = cur[0][0], cur[0][1], cur[1] + + if [x, y] == [n - 1, n - 1]: + return step + + for i in range(8): + xx, yy = x + dx[i], y + dy[i] + if 0 <= xx < n and 0 <= yy < n and grid[xx][yy] == 0 and (xx, yy) not in visited: + visited.add((xx, yy)) + queue.append(((xx, yy), step + 1)) + + return -1 + diff --git "a/LeetCode-Python/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" "b/LeetCode-Python/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" new file mode 100644 index 0000000..3ff67cd --- /dev/null +++ "b/LeetCode-Python/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" @@ -0,0 +1,14 @@ +class Solution: + def distributeCandies(self, candies: int, num_people: int) -> List[int]: + candy_to_be_distributed = 1 + child = 1 + res = [0] * (num_people + 1) + while candies: + give = min(candy_to_be_distributed, candies) + candies -= give + res[child] += give + candy_to_be_distributed += 1 + child += 1 + if (child > num_people): + child = 1 + return res[1:] \ No newline at end of file diff --git "a/LeetCode-Python/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" "b/LeetCode-Python/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" new file mode 100644 index 0000000..b9c7c37 --- /dev/null +++ "b/LeetCode-Python/1108.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/1108-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" @@ -0,0 +1,4 @@ +class Solution: + def defangIPaddr(self, address: str) -> str: + + return address.replace(".", "[.]") \ No newline at end of file diff --git "a/LeetCode-Python/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" "b/LeetCode-Python/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" new file mode 100644 index 0000000..bd49588 --- /dev/null +++ "b/LeetCode-Python/1110.\345\210\240\347\202\271\346\210\220\346\236\227/1110-\345\210\240\347\202\271\346\210\220\346\236\227.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]: + to_delete = set(to_delete) + res = [] + def dfs(node, node_is_new_root): + if not node: + return + left = node.left + right = node.right + if node_is_new_root and node.val not in to_delete: + res.append(node) + if left and left.val in to_delete: + node.left = None + if right and right.val in to_delete: + node.right = None + + dfs(left, node.val in to_delete) + dfs(right, node.val in to_delete) + dfs(root, True) + return res + \ No newline at end of file diff --git "a/LeetCode-Python/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263.py" "b/LeetCode-Python/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263.py" new file mode 100644 index 0000000..6fb2e44 --- /dev/null +++ "b/LeetCode-Python/1119.\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263/1119-\345\210\240\345\216\273\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\205\203\351\237\263.py" @@ -0,0 +1,8 @@ +class Solution: + def removeVowels(self, s: str) -> str: + vowels = "aeiou" + res = "" + for char in s: + if char not in vowels: + res += char + return res \ No newline at end of file diff --git "a/LeetCode-Python/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" "b/LeetCode-Python/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" new file mode 100644 index 0000000..a72c05c --- /dev/null +++ "b/LeetCode-Python/1130.\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221/1130-\345\217\266\345\200\274\347\232\204\346\234\200\345\260\217\344\273\243\344\273\267\347\224\237\346\210\220\346\240\221.py" @@ -0,0 +1,12 @@ +class Solution: + def mctFromLeafValues(self, arr: List[int]) -> int: + res = 0 + stack = [16] + for num in arr: + while stack and stack[-1] < num: + res += stack.pop() * min(stack[-1], num) + stack.append(num) + + while len(stack) > 2: + res += stack.pop() * stack[-1] + return res \ No newline at end of file diff --git "a/LeetCode-Python/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246.py" "b/LeetCode-Python/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246.py" new file mode 100644 index 0000000..90a2662 --- /dev/null +++ "b/LeetCode-Python/1156.\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246/1156-\345\215\225\345\255\227\347\254\246\351\207\215\345\244\215\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\351\225\277\345\272\246.py" @@ -0,0 +1,21 @@ +class Solution: + def maxRepOpt1(self, text: str) -> int: + c = Counter(text) + res = 0 + for i in range(len(text)): + j = i + 1 + while j < len(text) and text[j] == text[i]: + j += 1 + + # [i, j) + cnt = j - i + if i > 0 and j < len(text) and cnt < c[text[i]]: + res = max(res, cnt + 1) + + k = j + 1 + while k < len(text) and text[k] == text[i]: + k += 1 + # [i, j)[j + 1, k) swap text[j] if possible + res = max(res, min(k - i, c[text[i]])) + i = j + return res \ No newline at end of file diff --git "a/LeetCode-Python/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214.py" "b/LeetCode-Python/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214.py" new file mode 100644 index 0000000..54a9a1b --- /dev/null +++ "b/LeetCode-Python/1161.\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214/1161-\346\234\200\345\244\247\345\261\202\345\206\205\345\205\203\347\264\240\345\222\214.py" @@ -0,0 +1,32 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def maxLevelSum(self, root: Optional[TreeNode]) -> int: + queue = [root] + max_level_sum = float("-inf") + max_level_sum_id = 0 + cur_level_id = 0 + + while queue: + next_queue = [] + cur_level_sum = 0 + cur_level_id += 1 + for node in queue: + if node: + cur_level_sum += node.val + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + + if cur_level_sum > max_level_sum: + max_level_sum = cur_level_sum + max_level_sum_id = cur_level_id + + queue = next_queue + + return max_level_sum_id \ No newline at end of file diff --git "a/LeetCode-Python/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230.py" "b/LeetCode-Python/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230.py" new file mode 100644 index 0000000..033587c --- /dev/null +++ "b/LeetCode-Python/1165.\345\215\225\350\241\214\351\224\256\347\233\230/1165-\345\215\225\350\241\214\351\224\256\347\233\230.py" @@ -0,0 +1,13 @@ +class Solution: + def calculateTime(self, keyboard: str, word: str) -> int: + char2pos = dict() + + for pos, char in enumerate(keyboard): + char2pos[char] = pos + + res = 0 + last_pos = 0 + for char in word: + res += abs(last_pos - char2pos[char]) + last_pos = char2pos[char] + return res \ No newline at end of file diff --git "a/LeetCode-Python/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262.py" "b/LeetCode-Python/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262.py" new file mode 100644 index 0000000..2b6fd8e --- /dev/null +++ "b/LeetCode-Python/1180.\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262/1180-\347\273\237\350\256\241\345\217\252\345\220\253\345\215\225\344\270\200\345\255\227\346\257\215\347\232\204\345\255\220\344\270\262.py" @@ -0,0 +1,13 @@ +class Solution: + def countLetters(self, s: str) -> int: + left, right = 0, 0 + res = 0 + while right < len(s): + while right < len(s) and s[left] == s[right]: + right += 1 + consecutive_chars_count = right - left + res += consecutive_chars_count * (consecutive_chars_count + 1) // 2 + left = right + return res + + diff --git "a/LeetCode-Python/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240.py" "b/LeetCode-Python/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240.py" new file mode 100644 index 0000000..904296b --- /dev/null +++ "b/LeetCode-Python/1198.\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240/1198-\346\211\276\345\207\272\346\211\200\346\234\211\350\241\214\344\270\255\346\234\200\345\260\217\345\205\254\345\205\261\345\205\203\347\264\240.py" @@ -0,0 +1,25 @@ +class Solution: + def smallestCommonElement(self, mat: List[List[int]]) -> int: + m, n = len(mat), len(mat[0]) + for candidate in mat[0]: + all_found_candidate = True + for row in mat[1:]: + found_candidate = False + left, right = 0, n - 1 + while left <= right: + mid = (left + right) // 2 + if row[mid] == candidate: + found_candidate = True + break + elif row[mid] < candidate: + left = mid + 1 + else: + right = mid - 1 + + if not found_candidate: + all_found_candidate = False + break + if all_found_candidate: + return candidate + return -1 + \ No newline at end of file diff --git "a/LeetCode-Python/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..f04b4c2 --- /dev/null +++ "b/LeetCode-Python/1221.\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262/1221-\345\210\206\345\211\262\345\271\263\350\241\241\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,15 @@ +class Solution: + def balancedStringSplit(self, s: str) -> int: + r_count, l_count = 0, 0 + res = 0 + for char in s: + if char == "R": + r_count += 1 + if char == "L": + l_count += 1 + + if l_count == r_count: + l_count = 0 + r_count = 0 + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233.py" "b/LeetCode-Python/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233.py" new file mode 100644 index 0000000..a26d062 --- /dev/null +++ "b/LeetCode-Python/1231.\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233/1231-\345\210\206\344\272\253\345\267\247\345\205\213\345\212\233.py" @@ -0,0 +1,21 @@ +class Solution: + def maximizeSweetness(self, sweetness: List[int], k: int) -> int: + left, right = 0, sum(sweetness) + k += 1 + while left <= right: + mid = (left + right) // 2 # mid 鏄瘡涓鍧楀阀鍏嬪姏鐨勭敎搴︿笅闄愯屼笉鏄笂闄愶紝涔熸槸杩斿洖鐨勫 + pieces_cnt, cur_sum = 0, 0 + for s in sweetness: + if cur_sum + s >= mid: + pieces_cnt += 1 + cur_sum = 0 + else: + cur_sum += s + + if pieces_cnt < k: # 闇瑕佸垏鏇村鍧 + right = mid - 1 + elif pieces_cnt == k: + left = mid + 1 + elif pieces_cnt > k: + left = mid + 1 + return right \ No newline at end of file diff --git "a/LeetCode-Python/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" "b/LeetCode-Python/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" new file mode 100644 index 0000000..b6568c3 --- /dev/null +++ "b/LeetCode-Python/1237.\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243/1237-\346\211\276\345\207\272\347\273\231\345\256\232\346\226\271\347\250\213\347\232\204\346\255\243\346\225\264\346\225\260\350\247\243.py" @@ -0,0 +1,26 @@ +""" + This is the custom function interface. + You should not implement it, or speculate about its implementation + class CustomFunction: + # Returns f(x, y) for any given positive integers x and y. + # Note that f(x, y) is increasing with respect to both x and y. + # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1) + def f(self, x, y): + +""" + +class Solution: + def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]: + res = [] + for x in range(1, 1001): + left, right = 1, 1001 + while left <= right: + mid = (left + right)// 2 + if customfunction.f(x, mid) == z: + res.append([x, mid]) + break + elif customfunction.f(x, mid) < z: + left = mid + 1 + else: + right = mid - 1 + return res diff --git "a/LeetCode-Python/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256.py" "b/LeetCode-Python/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..98f030d --- /dev/null +++ "b/LeetCode-Python/1252.\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256/1252-\345\245\207\346\225\260\345\200\274\345\215\225\345\205\203\346\240\274\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,17 @@ +class Solution: + def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: + from collections import defaultdict + row2one_count = defaultdict(int) + col2one_count = defaultdict(int) + + for row, col in indices: + row2one_count[row] += 1 + col2one_count[col] += 1 + + res = 0 + row_odd, col_odd = 0, 0 + for row in range(m): + row_odd += row2one_count[row] % 2 + for col in range(n): + col_odd += col2one_count[col] % 2 + return row_odd * (n - col_odd) + (m - row_odd) * col_odd \ No newline at end of file diff --git "a/LeetCode-Python/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" "b/LeetCode-Python/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" new file mode 100644 index 0000000..2f0ce01 --- /dev/null +++ "b/LeetCode-Python/1261.\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240/1261-\345\234\250\345\217\227\346\261\241\346\237\223\347\232\204\344\272\214\345\217\211\346\240\221\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240.py" @@ -0,0 +1,33 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class FindElements: + + def __init__(self, root: Optional[TreeNode]): + root.val = 0 + self.values = set() + def dfs(node): + if not node: + return + + self.values.add(node.val) + if node.left: + node.left.val = 2 * node.val + 1 + if node.right: + node.right.val = 2 * node.val + 2 + + dfs(node.left) + dfs(node.right) + + dfs(root) + + def find(self, target: int) -> bool: + return target in self.values + + +# Your FindElements object will be instantiated and called as such: +# obj = FindElements(root) +# param_1 = obj.find(target) \ No newline at end of file diff --git "a/LeetCode-Python/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" "b/LeetCode-Python/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" new file mode 100644 index 0000000..1b04458 --- /dev/null +++ "b/LeetCode-Python/1265.\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250/1265-\351\200\206\345\272\217\346\211\223\345\215\260\344\270\215\345\217\257\345\217\230\351\223\276\350\241\250.py" @@ -0,0 +1,15 @@ +# """ +# This is the ImmutableListNode's API interface. +# You should not implement it, or speculate about its implementation. +# """ +# class ImmutableListNode: +# def printValue(self) -> None: # print the value of this node. +# def getNext(self) -> 'ImmutableListNode': # return the next node. + +class Solution: + def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None: + if not head: + return + + self.printLinkedListInReverse(head.getNext()) + head.printValue() \ No newline at end of file diff --git "a/LeetCode-Python/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" "b/LeetCode-Python/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" new file mode 100644 index 0000000..4e18cba --- /dev/null +++ "b/LeetCode-Python/1282.\347\224\250\346\210\267\345\210\206\347\273\204/1282-\347\224\250\346\210\267\345\210\206\347\273\204.py" @@ -0,0 +1,13 @@ +class Solution: + def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: + from collections import defaultdict + + size2people = defaultdict(list) + for i, size in enumerate(groupSizes): + size2people[size].append(i) + + res = [] + for size, peoples in size2people.items(): + for i in range(0, len(peoples), size): + res.append(peoples[i: i + size]) + return res \ No newline at end of file diff --git "a/LeetCode-Python/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" "b/LeetCode-Python/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" new file mode 100644 index 0000000..70a5142 --- /dev/null +++ "b/LeetCode-Python/1290.\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260/1290-\344\272\214\350\277\233\345\210\266\351\223\276\350\241\250\350\275\254\346\225\264\346\225\260.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def getDecimalValue(self, head: ListNode) -> int: + res = 0 + p = head + while p: + res = res * 2 + p.val + p = p.next + return res \ No newline at end of file diff --git "a/LeetCode-Python/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" "b/LeetCode-Python/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" new file mode 100644 index 0000000..fb0b769 --- /dev/null +++ "b/LeetCode-Python/1302.\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214/1302-\345\261\202\346\225\260\346\234\200\346\267\261\345\217\266\345\255\220\350\212\202\347\202\271\347\232\204\345\222\214.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def deepestLeavesSum(self, root: Optional[TreeNode]) -> int: + queue = [root] + while queue: + level_sum = 0 + next_queue = [] + for node in queue: + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + level_sum += node.val + + queue = next_queue[:] + return level_sum \ No newline at end of file diff --git "a/LeetCode-Python/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" "b/LeetCode-Python/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" new file mode 100644 index 0000000..564b692 --- /dev/null +++ "b/LeetCode-Python/1315.\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214/1315-\347\245\226\347\210\266\350\212\202\347\202\271\345\200\274\344\270\272\345\201\266\346\225\260\347\232\204\350\212\202\347\202\271\345\222\214.py" @@ -0,0 +1,21 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumEvenGrandparent(self, root: TreeNode) -> int: + self.sum = 0 + def dfs(node, isParentEven, isGrandparentEven): + if not node: + return + + if isGrandparentEven: + self.sum += node.val + + dfs(node.left, node.val % 2 == 0, isParentEven) + dfs(node.right, node.val % 2 == 0, isParentEven) + + dfs(root, False, False) + return self.sum \ No newline at end of file diff --git "a/LeetCode-Python/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" "b/LeetCode-Python/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" new file mode 100644 index 0000000..89e5ff2 --- /dev/null +++ "b/LeetCode-Python/1337.\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214/1337-\347\237\251\351\230\265\344\270\255\346\210\230\346\226\227\345\212\233\346\234\200\345\274\261\347\232\204K\350\241\214.py" @@ -0,0 +1,5 @@ +class Solution: + def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]: + pair = [(i, sum(row)) for i, row in enumerate(mat)] + pair.sort(key = lambda x: x[1]) + return [p[0] for p in pair[:k]] \ No newline at end of file diff --git "a/LeetCode-Python/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212.py" "b/LeetCode-Python/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212.py" new file mode 100644 index 0000000..7ed3dff --- /dev/null +++ "b/LeetCode-Python/1338.\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212/1338-\346\225\260\347\273\204\345\244\247\345\260\217\345\207\217\345\215\212.py" @@ -0,0 +1,18 @@ +class Solution: + def minSetSize(self, arr: List[int]) -> int: + from collections import Counter + c = Counter(arr) + l = [] + visited = set() + for val in arr: + if val not in visited: + l.append((c[val], val)) + visited.add(val) + l.sort(key = lambda x:-x[0]) + + res, reduced_size = 0, 0 + for freq, val in l: + reduced_size += freq + res += 1 + if reduced_size >= len(arr) // 2: + return res \ No newline at end of file diff --git "a/LeetCode-Python/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260.py" "b/LeetCode-Python/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260.py" new file mode 100644 index 0000000..37a15f6 --- /dev/null +++ "b/LeetCode-Python/1351.\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260/1351-\347\273\237\350\256\241\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\350\264\237\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution: + def countNegatives(self, grid: List[List[int]]) -> int: + res = 0 + for row in grid: + for node in row: + if node < 0: + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..690c38d --- /dev/null +++ "b/LeetCode-Python/1374.\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262/1374-\347\224\237\346\210\220\346\257\217\347\247\215\345\255\227\347\254\246\351\203\275\346\230\257\345\245\207\346\225\260\344\270\252\347\232\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,5 @@ +class Solution: + def generateTheString(self, n: int) -> str: + if n % 2 == 1: + return "a" * n + return "a" * (n - 1) + "b" \ No newline at end of file diff --git "a/LeetCode-Python/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" "b/LeetCode-Python/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" new file mode 100644 index 0000000..8c9b498 --- /dev/null +++ "b/LeetCode-Python/1379.\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271/1379-\346\211\276\345\207\272\345\205\213\351\232\206\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\347\233\270\345\220\214\350\212\202\347\202\271.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode: + queue = [cloned] + while queue: + next_queue = [] + for node in queue: + if node: + if node.val == target.val: + return node + next_queue.append(node.left) + next_queue.append(node.right) + queue = next_queue[:] + \ No newline at end of file diff --git "a/LeetCode-Python/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204.py" "b/LeetCode-Python/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204.py" new file mode 100644 index 0000000..5235207 --- /dev/null +++ "b/LeetCode-Python/1389.\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204/1389-\346\214\211\346\227\242\345\256\232\351\241\272\345\272\217\345\210\233\345\273\272\347\233\256\346\240\207\346\225\260\347\273\204.py" @@ -0,0 +1,6 @@ +class Solution: + def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: + res = [] + for i, x in enumerate(index): + res = res[:x] + [nums[i]] + res[x:] + return res \ No newline at end of file diff --git "a/LeetCode-Python/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" "b/LeetCode-Python/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" new file mode 100644 index 0000000..edec649 --- /dev/null +++ "b/LeetCode-Python/1409.\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227/1409-\346\237\245\350\257\242\345\270\246\351\224\256\347\232\204\346\216\222\345\210\227.py" @@ -0,0 +1,9 @@ +class Solution: + def processQueries(self, queries: List[int], m: int) -> List[int]: + P = [i for i in range(1, m + 1)] + res = [] + for query in queries: + index = P.index(query) + res.append(index) + P = [P[index]] + P[:index] + P[index + 1:] + return res \ No newline at end of file diff --git "a/LeetCode-Python/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" "b/LeetCode-Python/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" new file mode 100644 index 0000000..d0936a2 --- /dev/null +++ "b/LeetCode-Python/1418.\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250/1418-\347\202\271\350\217\234\345\261\225\347\244\272\350\241\250.py" @@ -0,0 +1,23 @@ +class Solution: + def displayTable(self, orders: List[List[str]]) -> List[List[str]]: + from collections import defaultdict + table_set = set() + tablefood2cnt = defaultdict(int) + food_set = set() + + for order in orders: + table, food = order[1], order[2] + food_set.add(food) + table_set.add(table) + tablefood2cnt[table + "-" + food] += 1 + + sorted_table = sorted(list(table_set), key = lambda x: int(x)) + sorted_food = sorted(list(food_set)) + res = [["Table"] + sorted_food] + + for table in sorted_table: + temp = [table] + for f in sorted_food: + temp.append(str(tablefood2cnt[table + "-" + f])) + res.append(temp) + return res \ No newline at end of file diff --git "a/LeetCode-Python/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231.py" "b/LeetCode-Python/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231.py" new file mode 100644 index 0000000..98bd4f3 --- /dev/null +++ "b/LeetCode-Python/1436.\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231/1436-\346\227\205\350\241\214\347\273\210\347\202\271\347\253\231.py" @@ -0,0 +1,15 @@ +class Solution: + def destCity(self, paths: List[List[str]]) -> str: + cities = set() + + src2des = {} + for path in paths: + src, des = path[0], path[1] + cities.add(src) + cities.add(des) + + src2des[src] = des + + for city in cities: + if city not in src2des: + return city \ No newline at end of file diff --git "a/LeetCode-Python/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" "b/LeetCode-Python/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" new file mode 100644 index 0000000..1659fd7 --- /dev/null +++ "b/LeetCode-Python/1439.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214/1439-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\232\204\347\254\254k\344\270\252\346\234\200\345\260\217\346\225\260\347\273\204\345\222\214.py" @@ -0,0 +1,24 @@ +from heapq import * +class Solution: + def kthSmallest(self, mat: List[List[int]], k: int) -> int: + m, n = len(mat), len(mat[0]) + min_sum = sum([mat[i][0] for i in range(m)]) + min_heap = [(min_sum, [0 for i in range(m)])] + cur = 0 + visited = set() + while cur < k: + s, indices = heappop(min_heap) + cur += 1 + if cur == k: + return s + + for i in range(m): + if indices[i] + 1 < n: + nxt_s = s - mat[i][indices[i]] + mat[i][indices[i] + 1] + nxt_indices = indices[:] + nxt_indices[i] += 1 + str_indices = "".join([str(i) for i in nxt_indices]) + if str_indices not in visited: + visited.add(str_indices) + heappush(min_heap, (nxt_s, nxt_indices)) + \ No newline at end of file diff --git "a/LeetCode-Python/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204.py" "b/LeetCode-Python/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204.py" new file mode 100644 index 0000000..5828410 --- /dev/null +++ "b/LeetCode-Python/1441.\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204/1441-\347\224\250\346\240\210\346\223\215\344\275\234\346\236\204\345\273\272\346\225\260\347\273\204.py" @@ -0,0 +1,12 @@ +class Solution: + def buildArray(self, target: List[int], n: int) -> List[str]: + cur = 1 + res = [] + for t in target: + while t > cur: + res.append("Push") + res.append("Pop") + cur += 1 + res.append("Push") + cur += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" "b/LeetCode-Python/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" new file mode 100644 index 0000000..6c83a66 --- /dev/null +++ "b/LeetCode-Python/1464.\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1464-\346\225\260\347\273\204\344\270\255\344\270\244\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" @@ -0,0 +1,4 @@ +class Solution: + def maxProduct(self, nums: List[int]) -> int: + nums.sort() + return (nums[-1] - 1) * (nums[-2] - 1) \ No newline at end of file diff --git "a/LeetCode-Python/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271.py" "b/LeetCode-Python/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271.py" new file mode 100644 index 0000000..4efe291 --- /dev/null +++ "b/LeetCode-Python/1469.\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271/1469-\345\257\273\346\211\276\346\211\200\346\234\211\347\232\204\347\213\254\347\224\237\350\212\202\347\202\271.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def getLonelyNodes(self, root: Optional[TreeNode]) -> List[int]: + self.res = [] + + def dfs(node): + if not node: + return + + if node.left and not node.right: + self.res.append(node.left.val) + if node.right and not node.left: + self.res.append(node.right.val) + + dfs(node.left) + dfs(node.right) + + dfs(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204.py" "b/LeetCode-Python/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204.py" new file mode 100644 index 0000000..7b960b4 --- /dev/null +++ "b/LeetCode-Python/1470.\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204/1470-\351\207\215\346\226\260\346\216\222\345\210\227\346\225\260\347\273\204.py" @@ -0,0 +1,5 @@ +class Solution: + def shuffle(self, nums: List[int], n: int) -> List[int]: + x = nums[:n] + y = nums[n:] + return sum([list(pair) for pair in zip(x, y)], []) \ No newline at end of file diff --git "a/LeetCode-Python/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274.py" "b/LeetCode-Python/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274.py" new file mode 100644 index 0000000..bf73beb --- /dev/null +++ "b/LeetCode-Python/1475.\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274/1475-\345\225\206\345\223\201\346\212\230\346\211\243\345\220\216\347\232\204\346\234\200\347\273\210\344\273\267\346\240\274.py" @@ -0,0 +1,12 @@ +class Solution: + def finalPrices(self, prices: List[int]) -> List[int]: + res = [price for price in prices] + stack = [] + + for i, price in enumerate(prices): + while stack and prices[stack[-1]] >= price: + last_index = stack[-1] + res[last_index] = res[last_index] - price + stack.pop() + stack.append(i) + return res \ No newline at end of file diff --git "a/LeetCode-Python/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" "b/LeetCode-Python/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..df3e01c --- /dev/null +++ "b/LeetCode-Python/1485.\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221/1485-\345\205\213\351\232\206\345\220\253\351\232\217\346\234\272\346\214\207\351\222\210\347\232\204\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,41 @@ +# Definition for Node. +# class Node: +# def __init__(self, val=0, left=None, right=None, random=None): +# self.val = val +# self.left = left +# self.right = right +# self.random = random + +from collections import deque +class Solution: + def copyRandomBinaryTree(self, root: 'Optional[Node]') -> 'Optional[NodeCopy]': + if not root: + return root + + old2new = dict() + queue = deque([root]) + while queue: + cur_node = queue.popleft() + new_node = NodeCopy(cur_node.val) + old2new[cur_node] = new_node + + if cur_node.left: + queue.append(cur_node.left) + if cur_node.right: + queue.append(cur_node.right) + + queue = deque([root]) + while queue: + cur_node = queue.popleft() + new_node = old2new[cur_node] + + if cur_node.left: + new_node.left = old2new[cur_node.left] + queue.append(cur_node.left) + if cur_node.right: + new_node.right = old2new[cur_node.right] + queue.append(cur_node.right) + if cur_node.random: + new_node.random = old2new[cur_node.random] + + return old2new[root] \ No newline at end of file diff --git "a/LeetCode-Python/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..d7cea34 --- /dev/null +++ "b/LeetCode-Python/1528.\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262/1528-\351\207\215\346\226\260\346\216\222\345\210\227\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,7 @@ +class Solution: + def restoreString(self, s: str, indices: List[int]) -> str: + l = ["" for _ in s] + + for i, char in enumerate(s): + l[indices[i]] = char + return "".join(l) \ No newline at end of file diff --git "a/LeetCode-Python/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" "b/LeetCode-Python/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" new file mode 100644 index 0000000..8cb54d6 --- /dev/null +++ "b/LeetCode-Python/1552.\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233/1552-\344\270\244\347\220\203\344\271\213\351\227\264\347\232\204\347\243\201\345\212\233.py" @@ -0,0 +1,18 @@ +class Solution: + def maxDistance(self, position: List[int], m: int) -> int: + position.sort() + left, right = 1, position[-1] - position[0] + while left <= right: + mid = (left + right) // 2 # target answer + + cnt, prev = 1, position[0] + for p in position: + if prev + mid <= p: # find another possible position + cnt += 1 + prev = p + + if cnt >= m: + left = mid + 1 + elif cnt < m: + right = mid - 1 + return right \ No newline at end of file diff --git "a/LeetCode-Python/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" "b/LeetCode-Python/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" new file mode 100644 index 0000000..d36a9b1 --- /dev/null +++ "b/LeetCode-Python/1598.\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250/1598-\346\226\207\344\273\266\345\244\271\346\223\215\344\275\234\346\227\245\345\277\227\346\220\234\351\233\206\345\231\250.py" @@ -0,0 +1,10 @@ +class Solution: + def minOperations(self, logs: List[str]) -> int: + dir_count = 0 + for log in logs: + if log == "../": + if dir_count > 0: + dir_count -= 1 + elif log != "./": + dir_count += 1 + return dir_count \ No newline at end of file diff --git "a/LeetCode-Python/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" "b/LeetCode-Python/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" new file mode 100644 index 0000000..d2d32c7 --- /dev/null +++ "b/LeetCode-Python/1603.\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237/1603-\350\256\276\350\256\241\345\201\234\350\275\246\347\263\273\347\273\237.py" @@ -0,0 +1,25 @@ +class ParkingSystem: + + def __init__(self, big: int, medium: int, small: int): + self.b, self.m, self.s = big, medium, small + + def addCar(self, carType: int) -> bool: + if carType == 1: + if self.b: + self.b -= 1 + return True + return False + elif carType == 2: + if self.m: + self.m -= 1 + return True + return False + elif carType == 3: + if self.s: + self.s -= 1 + return True + return False + +# Your ParkingSystem object will be instantiated and called as such: +# obj = ParkingSystem(big, medium, small) +# param_1 = obj.addCar(carType) \ No newline at end of file diff --git "a/LeetCode-Python/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" "b/LeetCode-Python/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" new file mode 100644 index 0000000..0c33970 --- /dev/null +++ "b/LeetCode-Python/1614.\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246/1614-\346\213\254\345\217\267\347\232\204\346\234\200\345\244\247\345\265\214\345\245\227\346\267\261\345\272\246.py" @@ -0,0 +1,12 @@ +class Solution: + def maxDepth(self, s: str) -> int: + res = 0 + cur_depth = 0 + for char in s: + if char == "(": + cur_depth += 1 + res = max(res, cur_depth) + elif char == ")": + cur_depth -= 1 + + return res \ No newline at end of file diff --git "a/LeetCode-Python/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" "b/LeetCode-Python/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" new file mode 100644 index 0000000..4b6cd69 --- /dev/null +++ "b/LeetCode-Python/1669.\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250/1669-\345\220\210\345\271\266\344\270\244\344\270\252\351\223\276\350\241\250.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: + dummy = ListNode(-1) + dummy.next = list1 + prev, cur = dummy, list1 + left, right = None, None + count = 0 + while cur: + if count == a: + left = prev + + if count == b: + right = cur.next + + count += 1 + prev, cur = cur, cur.next + + left.next = list2 + p = list2 + while p and p.next: + p = p.next + p.next = right + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" "b/LeetCode-Python/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" new file mode 100644 index 0000000..c6d4300 --- /dev/null +++ "b/LeetCode-Python/1678.\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250/1678-\350\256\276\350\256\241Goal\350\247\243\346\236\220\345\231\250.py" @@ -0,0 +1,21 @@ +class Solution: + def interpret(self, command: str) -> str: + res = "" + stack = [] + for char in command: + if char == "G": + res += char + elif char == "(": + stack.append(char) + elif char == ")": + if stack and stack[-1] == "(": + res += "o" + stack.pop() + else: + res += "al" + stack.pop() + stack.pop() + stack.pop() + else: + stack.append(char) + return res diff --git "a/LeetCode-Python/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" "b/LeetCode-Python/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" new file mode 100644 index 0000000..50a8100 --- /dev/null +++ "b/LeetCode-Python/1688.\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260/1688-\346\257\224\350\265\233\344\270\255\347\232\204\351\205\215\345\257\271\346\254\241\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution: + def numberOfMatches(self, n: int) -> int: + res = 0 + while n != 1: + if n % 2: + res += (n - 1) // 2 + n = (n - 1) // 2 + 1 + else: + res += n // 2 + n = n // 2 + return res \ No newline at end of file diff --git "a/LeetCode-Python/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" "b/LeetCode-Python/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" new file mode 100644 index 0000000..1f1db8c --- /dev/null +++ "b/LeetCode-Python/1700.\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217/1700-\346\227\240\346\263\225\345\220\203\345\215\210\351\244\220\347\232\204\345\255\246\347\224\237\346\225\260\351\207\217.py" @@ -0,0 +1,16 @@ +class Solution: + def countStudents(self, students: List[int], sandwiches: List[int]) -> int: + from collections import deque + students = deque(students) + while sandwiches: + cur, l = 0, len(students) + while cur < l: + student = students.popleft() + if student == sandwiches[0]: + break + students.append(student) + cur += 1 + if cur == l: + break + sandwiches = sandwiches[1:] + return len(students) \ No newline at end of file diff --git "a/LeetCode-Python/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" "b/LeetCode-Python/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" new file mode 100644 index 0000000..b9a2ae4 --- /dev/null +++ "b/LeetCode-Python/1704.\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274/1704-\345\210\244\346\226\255\345\255\227\347\254\246\344\270\262\347\232\204\344\270\244\345\215\212\346\230\257\345\220\246\347\233\270\344\274\274.py" @@ -0,0 +1,8 @@ +class Solution: + def halvesAreAlike(self, s: str) -> bool: + s1, s2 = s[:len(s) // 2], s[len(s) // 2:] + return self.countVowels(s1) == self.countVowels(s2) + + def countVowels(self, s): + vowels = "aeiouAEIOU" + return sum(char in vowels for char in s) \ No newline at end of file diff --git "a/LeetCode-Python/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" "b/LeetCode-Python/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" new file mode 100644 index 0000000..efc2c51 --- /dev/null +++ "b/LeetCode-Python/1720.\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204/1720-\350\247\243\347\240\201\345\274\202\346\210\226\345\220\216\347\232\204\346\225\260\347\273\204.py" @@ -0,0 +1,6 @@ +class Solution: + def decode(self, encoded: List[int], first: int) -> List[int]: + res = [first] + for num in encoded: + res.append(res[-1] ^ num) + return res \ No newline at end of file diff --git "a/LeetCode-Python/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" "b/LeetCode-Python/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..61bb471 --- /dev/null +++ "b/LeetCode-Python/1721.\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271/1721-\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def swapNodes(self, head: Optional[ListNode], k: int) -> Optional[ListNode]: + p = head + l = 0 + while p: + l += 1 + p = p.next + + reversed_k = l - k + 1 + + count = 0 + p = head + while p: + count += 1 + if count == k: + left_node = p + if count == reversed_k: + right_nnode = p + p = p.next + + left_node.val, right_nnode.val = right_nnode.val, left_node.val + + return head \ No newline at end of file diff --git "a/LeetCode-Python/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" "b/LeetCode-Python/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" new file mode 100644 index 0000000..8dcc9f4 --- /dev/null +++ "b/LeetCode-Python/1738.\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274/1738-\346\211\276\345\207\272\347\254\254K\345\244\247\347\232\204\345\274\202\346\210\226\345\235\220\346\240\207\345\200\274.py" @@ -0,0 +1,24 @@ +from heapq import * +class Solution: + def kthLargestValue(self, matrix: List[List[int]], k: int) -> int: + m, n = len(matrix), len(matrix[0]) + xor_matrix = [[matrix[i][j] for j in range(n)] for i in range(m) ] + min_heap = [] + for i in range(m): + for j in range(n): + if i or j: + if not i: + # the first row + xor_matrix[i][j] ^= xor_matrix[i][j - 1] + elif not j: + xor_matrix[i][j] ^= xor_matrix[i - 1][j] + else: + xor_matrix[i][j] ^= xor_matrix[i][j - 1] ^ xor_matrix[i - 1][j] ^ xor_matrix[i - 1][j - 1] + if len(min_heap) < k: + heappush(min_heap, xor_matrix[i][j]) + else: + heappushpop(min_heap, xor_matrix[i][j]) + + return min_heap[0] + + \ No newline at end of file diff --git "a/LeetCode-Python/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/LeetCode-Python/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" new file mode 100644 index 0000000..dcb4af2 --- /dev/null +++ "b/LeetCode-Python/1753.\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1753-\347\247\273\351\231\244\347\237\263\345\255\220\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" @@ -0,0 +1,15 @@ +from heapq import * +class Solution: + def maximumScore(self, a: int, b: int, c: int) -> int: + max_heap = [-a, -b, -c] + heapify(max_heap) + res = 0 + while len(max_heap) > 1: + first, second = -heappop(max_heap), -heappop(max_heap) + res += 1 + + if first > 1: + heappush(max_heap, -(first - 1)) + if second > 1: + heappush(max_heap, -(second - 1)) + return res diff --git "a/LeetCode-Python/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" "b/LeetCode-Python/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" new file mode 100644 index 0000000..36e7a7a --- /dev/null +++ "b/LeetCode-Python/1756.\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227/1756-\350\256\276\350\256\241\346\234\200\350\277\221\344\275\277\347\224\250\357\274\210MRU\357\274\211\351\230\237\345\210\227.py" @@ -0,0 +1,15 @@ +class MRUQueue: + + def __init__(self, n: int): + self.queue = [i for i in range(1, n + 1)] + + def fetch(self, k: int) -> int: + node = self.queue[k - 1] + self.queue = self.queue[:k - 1] + self.queue[k:] + [node] + return node + + + +# Your MRUQueue object will be instantiated and called as such: +# obj = MRUQueue(n) +# param_1 = obj.fetch(k) \ No newline at end of file diff --git "a/LeetCode-Python/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" "b/LeetCode-Python/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" new file mode 100644 index 0000000..ee30caa --- /dev/null +++ "b/LeetCode-Python/1762.\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251/1762-\350\203\275\347\234\213\345\210\260\346\265\267\346\231\257\347\232\204\345\273\272\347\255\221\347\211\251.py" @@ -0,0 +1,9 @@ +class Solution: + def findBuildings(self, heights: List[int]) -> List[int]: + stack = [] + for i, height in enumerate(heights): + while stack and heights[stack[-1]] <= height: + last_index = stack[-1] + stack.pop() + stack.append(i) + return sorted(stack) \ No newline at end of file diff --git "a/LeetCode-Python/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..42dd0b1 --- /dev/null +++ "b/LeetCode-Python/1768.\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262/1768-\344\272\244\346\233\277\345\220\210\345\271\266\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,12 @@ +class Solution: + def mergeAlternately(self, word1: str, word2: str) -> str: + res = "" + + for index, char1 in enumerate(word1): + res += char1 + if index < len(word2): + res += word2[index] + + if index < len(word2): + res += word2[index + 1:] + return res \ No newline at end of file diff --git "a/LeetCode-Python/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" "b/LeetCode-Python/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" new file mode 100644 index 0000000..f0ad0d4 --- /dev/null +++ "b/LeetCode-Python/1769.\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1769-\347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" @@ -0,0 +1,15 @@ +class Solution: + def minOperations(self, boxes: str) -> List[int]: + ones = [] + for index, box in enumerate(boxes): + if box == "1": + ones.append(index) + + res = [] + for index, box in enumerate(boxes): + cur_sum = 0 + for one_index in ones: + cur_sum += abs(one_index - index) + res.append(cur_sum) + + return res diff --git "a/LeetCode-Python/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" "b/LeetCode-Python/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" new file mode 100644 index 0000000..793e12a --- /dev/null +++ "b/LeetCode-Python/1773.\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217/1773-\347\273\237\350\256\241\345\214\271\351\205\215\346\243\200\347\264\242\350\247\204\345\210\231\347\232\204\347\211\251\345\223\201\346\225\260\351\207\217.py" @@ -0,0 +1,8 @@ +class Solution: + def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: + res = 0 + key2index = {"type":0, "color":1, "name":2} + for item in items: + if item[key2index[ruleKey]] == ruleValue: + res += 1 + return res diff --git "a/LeetCode-Python/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" "b/LeetCode-Python/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" new file mode 100644 index 0000000..33ae741 --- /dev/null +++ "b/LeetCode-Python/1812.\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262/1812-\345\210\244\346\226\255\345\233\275\351\231\205\350\261\241\346\243\213\346\243\213\347\233\230\344\270\255\344\270\200\344\270\252\346\240\274\345\255\220\347\232\204\351\242\234\350\211\262.py" @@ -0,0 +1,13 @@ +class Solution: + def squareIsWhite(self, coordinates: str) -> bool: + row, col = int(coordinates[1]), ord(coordinates[0]) - ord("a") + # 0 for balck, 1 for white + if col % 2 == 0: + color = 0 + else: + color = 1 + + if row % 2 == 0: + color = 1 - color + return color == 1 + \ No newline at end of file diff --git "a/LeetCode-Python/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" "b/LeetCode-Python/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" new file mode 100644 index 0000000..b862937 --- /dev/null +++ "b/LeetCode-Python/1832.\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245/1832-\345\210\244\346\226\255\345\217\245\345\255\220\346\230\257\345\220\246\344\270\272\345\205\250\345\255\227\346\257\215\345\217\245.py" @@ -0,0 +1,3 @@ +class Solution: + def checkIfPangram(self, sentence: str) -> bool: + return len(set(sentence)) == 26 \ No newline at end of file diff --git "a/LeetCode-Python/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" "b/LeetCode-Python/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" new file mode 100644 index 0000000..ce980fd --- /dev/null +++ "b/LeetCode-Python/1836.\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240/1836-\344\273\216\346\234\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\351\207\215\345\244\215\345\205\203\347\264\240.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode: + visited = set() + duplicates = set() + p = head + while p: + if p.val not in visited: + visited.add(p.val) + else: + duplicates.add(p.val) + p = p.next + + dummy = ListNode(-1) + dummy.next = head + prev, cur = dummy, head + while cur: + if cur.val in duplicates: + prev.next = cur.next + cur = cur.next + else: + prev, cur = cur, cur.next + + return dummy.next diff --git "a/LeetCode-Python/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" "b/LeetCode-Python/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" new file mode 100644 index 0000000..3629862 --- /dev/null +++ "b/LeetCode-Python/1844.\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242/1844-\345\260\206\346\211\200\346\234\211\346\225\260\345\255\227\347\224\250\345\255\227\347\254\246\346\233\277\346\215\242.py" @@ -0,0 +1,12 @@ +class Solution: + def replaceDigits(self, s: str) -> str: + res = "" + for i in range(0, len(s), 2): + char = s[i] + + if i + 1 < len(s): + shift = int(s[i + 1]) + res += char + chr(ord(char) + shift) + else: + res += char + return res \ No newline at end of file diff --git "a/LeetCode-Python/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" "b/LeetCode-Python/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" new file mode 100644 index 0000000..c18d4ca --- /dev/null +++ "b/LeetCode-Python/1860.\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262/1860-\345\242\236\351\225\277\347\232\204\345\206\205\345\255\230\346\263\204\351\234\262.py" @@ -0,0 +1,18 @@ +class Solution: + def memLeak(self, memory1: int, memory2: int) -> List[int]: + res = [] + memory = 1 + while memory1 or memory2: + if memory1 >= memory2: + if memory1 < memory: + break + else: + memory1 -= memory + else: + if memory2 < memory: + break + else: + memory2 -= memory + + memory += 1 + return [memory, memory1, memory2] \ No newline at end of file diff --git "a/LeetCode-Python/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" "b/LeetCode-Python/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" new file mode 100644 index 0000000..fb765fa --- /dev/null +++ "b/LeetCode-Python/1863.\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214/1863-\346\211\276\345\207\272\346\211\200\346\234\211\345\255\220\351\233\206\347\232\204\345\274\202\346\210\226\346\200\273\345\222\214\345\206\215\346\261\202\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution: + def subsetXORSum(self, nums: List[int]) -> int: + subsets = [[]] + res = 0 + for num in nums: + new_subsets = [] + for subset in subsets: + new_subset = subset + [num] + res += reduce(lambda x, y: x^y, new_subset) + new_subsets.append(new_subset) + subsets += new_subsets + return res \ No newline at end of file diff --git "a/LeetCode-Python/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" "b/LeetCode-Python/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" new file mode 100644 index 0000000..62d9a28 --- /dev/null +++ "b/LeetCode-Python/1874.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214/1874-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\344\271\230\347\247\257\345\222\214.py" @@ -0,0 +1,10 @@ +class Solution: + def minProductSum(self, nums1: List[int], nums2: List[int]) -> int: + nums1.sort() + nums2.sort() + # print(nums1, nums2[::-1]) + res = 0 + for i in range(len(nums1)): + res += nums1[i] * nums2[-(i + 1)] + + return res \ No newline at end of file diff --git "a/LeetCode-Python/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" "b/LeetCode-Python/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" new file mode 100644 index 0000000..fad2cee --- /dev/null +++ "b/LeetCode-Python/1880.\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214/1880-\346\243\200\346\237\245\346\237\220\345\215\225\350\257\215\346\230\257\345\220\246\347\255\211\344\272\216\344\270\244\345\215\225\350\257\215\344\271\213\345\222\214.py" @@ -0,0 +1,9 @@ +class Solution: + def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: + return self.sumOfDigit(firstWord) + self.sumOfDigit(secondWord) == self.sumOfDigit(targetWord) + + def sumOfDigit(self, word): + res = "" + for char in word: + res += str(ord(char) - ord("a")) + return int(res) \ No newline at end of file diff --git "a/LeetCode-Python/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" "b/LeetCode-Python/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" new file mode 100644 index 0000000..bbff3e1 --- /dev/null +++ "b/LeetCode-Python/1920.\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204/1920-\345\237\272\344\272\216\346\216\222\345\210\227\346\236\204\345\273\272\346\225\260\347\273\204.py" @@ -0,0 +1,3 @@ +class Solution: + def buildArray(self, nums: List[int]) -> List[int]: + return [nums[num] for num in nums] \ No newline at end of file diff --git "a/LeetCode-Python/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" "b/LeetCode-Python/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" new file mode 100644 index 0000000..5e822e9 --- /dev/null +++ "b/LeetCode-Python/1929.\346\225\260\347\273\204\344\270\262\350\201\224/1929-\346\225\260\347\273\204\344\270\262\350\201\224.py" @@ -0,0 +1,3 @@ +class Solution: + def getConcatenation(self, nums: List[int]) -> List[int]: + return nums + nums \ No newline at end of file diff --git "a/LeetCode-Python/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" "b/LeetCode-Python/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" new file mode 100644 index 0000000..43abcbc --- /dev/null +++ "b/LeetCode-Python/1941.\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214/1941-\346\243\200\346\237\245\346\230\257\345\220\246\346\211\200\346\234\211\345\255\227\347\254\246\345\207\272\347\216\260\346\254\241\346\225\260\347\233\270\345\220\214.py" @@ -0,0 +1,5 @@ +class Solution: + def areOccurrencesEqual(self, s: str) -> bool: + from collections import Counter + c = Counter(s) + return 1 == len(set(c.values())) \ No newline at end of file diff --git "a/LeetCode-Python/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/LeetCode-Python/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..66328fc --- /dev/null +++ "b/LeetCode-Python/1945.\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214/1945-\345\255\227\347\254\246\344\270\262\350\275\254\345\214\226\345\220\216\347\232\204\345\220\204\344\275\215\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution: + def getLucky(self, s: str, k: int) -> int: + + num = "" + for char in s: + num += str(ord(char) - ord("a") + 1) + + num = int(num) + while k: + new_num = 0 + while num: + num, m = divmod(num, 10) + new_num += m + num = new_num + k -= 1 + return num diff --git "a/LeetCode-Python/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" "b/LeetCode-Python/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" new file mode 100644 index 0000000..72ad316 --- /dev/null +++ "b/LeetCode-Python/1967.\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/1967-\344\275\234\344\270\272\345\255\220\345\255\227\347\254\246\344\270\262\345\207\272\347\216\260\345\234\250\345\215\225\350\257\215\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" @@ -0,0 +1,9 @@ +class Solution: + def numOfStrings(self, patterns: List[str], word: str) -> int: + + res = 0 + for pattern in patterns: + if pattern in word: + res += 1 + + return res \ No newline at end of file diff --git "a/LeetCode-Python/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" "b/LeetCode-Python/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" new file mode 100644 index 0000000..7477494 --- /dev/null +++ "b/LeetCode-Python/2000.\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200/2000-\345\217\215\350\275\254\345\215\225\350\257\215\345\211\215\347\274\200.py" @@ -0,0 +1,7 @@ +class Solution: + def reversePrefix(self, word: str, ch: str) -> str: + if word.count(ch): + index = word.index(ch) + return word[:index + 1][::-1] + word[index + 1:] + else: + return word \ No newline at end of file diff --git "a/LeetCode-Python/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" "b/LeetCode-Python/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" new file mode 100644 index 0000000..e1aed68 --- /dev/null +++ "b/LeetCode-Python/2011.\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274/2011-\346\211\247\350\241\214\346\223\215\344\275\234\345\220\216\347\232\204\345\217\230\351\207\217\345\200\274.py" @@ -0,0 +1,10 @@ +class Solution: + def finalValueAfterOperations(self, operations: List[str]) -> int: + res = 0 + for operation in operations: + if operation[0] == "-" or operation[-1] == "-": + res-= 1 + else: + res += 1 + + return res \ No newline at end of file diff --git "a/LeetCode-Python/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" "b/LeetCode-Python/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" new file mode 100644 index 0000000..e33ddba --- /dev/null +++ "b/LeetCode-Python/2089.\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207/2089-\346\211\276\345\207\272\346\225\260\347\273\204\346\216\222\345\272\217\345\220\216\347\232\204\347\233\256\346\240\207\344\270\213\346\240\207.py" @@ -0,0 +1,8 @@ +class Solution: + def targetIndices(self, nums: List[int], target: int) -> List[int]: + nums.sort() + res = [] + for i, num in enumerate(nums): + if num == target: + res.append(i) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" "b/LeetCode-Python/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" new file mode 100644 index 0000000..a1afb38 --- /dev/null +++ "b/LeetCode-Python/2103.\347\216\257\345\222\214\346\235\206/2103-\347\216\257\345\222\214\346\235\206.py" @@ -0,0 +1,14 @@ +class Solution: + def countPoints(self, rings: str) -> int: + from collections import defaultdict + + ring2color = defaultdict(set) + for index in range(0, len(rings), 2): + color, ring = rings[index], rings[index + 1] + + ring2color[ring].add(color) + res = 0 + for ring, color in ring2color.items(): + if len(color) == 3: + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b2fb005 --- /dev/null +++ "b/LeetCode-Python/2108.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/2108-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,6 @@ +class Solution: + def firstPalindrome(self, words: List[str]) -> str: + for word in words: + if word == word[::-1]: + return word + return "" \ No newline at end of file diff --git "a/LeetCode-Python/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" "b/LeetCode-Python/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" new file mode 100644 index 0000000..02760a0 --- /dev/null +++ "b/LeetCode-Python/2114.\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260/2114-\345\217\245\345\255\220\344\270\255\347\232\204\346\234\200\345\244\232\345\215\225\350\257\215\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution: + def mostWordsFound(self, sentences: List[str]) -> int: + res = 0 + + for sentence in sentences: + word_count = len(sentence.split()) + res = max(res, word_count) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" "b/LeetCode-Python/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" new file mode 100644 index 0000000..611fcfd --- /dev/null +++ "b/LeetCode-Python/2120.\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244/2120-\346\211\247\350\241\214\346\211\200\346\234\211\345\220\216\347\274\200\346\214\207\344\273\244.py" @@ -0,0 +1,27 @@ +class Solution: + def executeInstructions(self, n: int, startPos: List[int], s: str) -> List[int]: + res = [] + for i, _ in enumerate(s): + j = i + cur_row, cur_col = startPos[0], startPos[1] + while 1: + if j == len(s): + break + ins = s[j] + if ins == "R": + cur_col += 1 + elif ins == "L": + cur_col -= 1 + elif ins == "U": + cur_row -= 1 + elif ins == "D": + cur_row += 1 + j += 1 + if self.moveOutside(cur_row, cur_col, n): + j -= 1 + break + res.append(j - i) + return res + + def moveOutside(self, cur_row, cur_col, n): + return not 0 <= cur_row < n or not 0 <= cur_col < n diff --git "a/LeetCode-Python/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" "b/LeetCode-Python/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" new file mode 100644 index 0000000..3ad4623 --- /dev/null +++ "b/LeetCode-Python/2125.\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217/2125-\351\223\266\350\241\214\344\270\255\347\232\204\346\277\200\345\205\211\346\235\237\346\225\260\351\207\217.py" @@ -0,0 +1,10 @@ +class Solution: + def numberOfBeams(self, bank: List[str]) -> int: + res = 0 + last_device_count = 0 + for row_index, row in enumerate(bank): + cur_device_count = row.count("1") + res += cur_device_count * last_device_count + if cur_device_count: + last_device_count = cur_device_count + return res \ No newline at end of file diff --git "a/LeetCode-Python/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" "b/LeetCode-Python/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" new file mode 100644 index 0000000..05973ff --- /dev/null +++ "b/LeetCode-Python/2130.\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214/2130-\351\223\276\350\241\250\346\234\200\345\244\247\345\255\252\347\224\237\345\222\214.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def pairSum(self, head: Optional[ListNode]) -> int: + p, l = head, 0 + while p: + l += 1 + p = p.next + + stack = [] + cur = 0 + p = head + while cur < l // 2: + cur += 1 + stack.append(p.val) + p = p.next + + res = 0 + while cur < l: + cur += 1 + res = max(res, p.val + stack.pop()) + p = p.next + return res \ No newline at end of file diff --git "a/LeetCode-Python/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" "b/LeetCode-Python/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" new file mode 100644 index 0000000..b2f3320 --- /dev/null +++ "b/LeetCode-Python/2149.\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204/2149-\346\214\211\347\254\246\345\217\267\351\207\215\346\216\222\346\225\260\347\273\204.py" @@ -0,0 +1,17 @@ +class Solution: + def rearrangeArray(self, nums: List[int]) -> List[int]: + pos, neg = [], [] + + for num in nums: + if num > 0: + pos.append(num) + else: + neg.append(num) + + t = [(pos[i], neg[i]) for i in range(len(pos))] + + res = [] + for pair in t: + res.append(pair[0]) + res.append(pair[1]) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" "b/LeetCode-Python/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" new file mode 100644 index 0000000..6c09e8b --- /dev/null +++ "b/LeetCode-Python/2154.\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452/2154-\345\260\206\346\211\276\345\210\260\347\232\204\345\200\274\344\271\230\344\273\2452.py" @@ -0,0 +1,6 @@ +class Solution: + def findFinalValue(self, nums: List[int], original: int) -> int: + s = set(nums) + while original in s: + original *= 2 + return original \ No newline at end of file diff --git "a/LeetCode-Python/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" "b/LeetCode-Python/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" new file mode 100644 index 0000000..1f17945 --- /dev/null +++ "b/LeetCode-Python/2161.\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204/2161-\346\240\271\346\215\256\347\273\231\345\256\232\346\225\260\345\255\227\345\210\222\345\210\206\346\225\260\347\273\204.py" @@ -0,0 +1,13 @@ +class Solution: + def pivotArray(self, nums: List[int], pivot: int) -> List[int]: + small, equal, larger = [], 0, [] + + for num in nums: + if num < pivot: + small.append(num) + elif num == pivot: + equal += 1 + else: + larger.append(num) + + return small + equal * [pivot] + larger \ No newline at end of file diff --git "a/LeetCode-Python/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" "b/LeetCode-Python/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" new file mode 100644 index 0000000..5c7e93e --- /dev/null +++ "b/LeetCode-Python/2169.\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260/2169-\345\276\227\345\210\2600\347\232\204\346\223\215\344\275\234\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution: + def countOperations(self, num1: int, num2: int) -> int: + res = 0 + while num1 and num2: + res += 1 + if num1 >= num2: + num1 -= num2 + else: + num2 -= num1 + + return res \ No newline at end of file diff --git "a/LeetCode-Python/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" "b/LeetCode-Python/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..fbb8dcd --- /dev/null +++ "b/LeetCode-Python/2181.\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271/2181-\345\220\210\345\271\266\351\233\266\344\271\213\351\227\264\347\232\204\350\212\202\347\202\271.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + p_new = dummy + + p = head + cur_sum = 0 + while p: + if p.val == 0: + if cur_sum: + node = ListNode(cur_sum) + p_new.next = node + p_new = p_new.next + cur_sum = 0 + else: + cur_sum += p.val + p = p.next + + return dummy.next \ No newline at end of file diff --git "a/LeetCode-Python/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b618879 --- /dev/null +++ "b/LeetCode-Python/2185.\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262/2185-\347\273\237\350\256\241\345\214\205\345\220\253\347\273\231\345\256\232\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,8 @@ +class Solution: + def prefixCount(self, words: List[str], pref: str) -> int: + res = 0 + + for word in words: + if word.startswith(pref): + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" "b/LeetCode-Python/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" new file mode 100644 index 0000000..f5008cd --- /dev/null +++ "b/LeetCode-Python/2194.Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274/2194-Excel\350\241\250\344\270\255\346\237\220\344\270\252\350\214\203\345\233\264\345\206\205\347\232\204\345\215\225\345\205\203\346\240\274.py" @@ -0,0 +1,10 @@ +class Solution: + def cellsInRange(self, s: str) -> List[str]: + res = [] + start_row, end_row = int(s[1]), int(s[-1]) + start_col, end_col = s[0], s[3] + + for cur in range(ord(start_col), ord(end_col) + 1): + for row in range(start_row, end_row + 1): + res.append(chr(cur) + str(row)) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" "b/LeetCode-Python/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" new file mode 100644 index 0000000..d755d2b --- /dev/null +++ "b/LeetCode-Python/2221.\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214/2221-\346\225\260\347\273\204\347\232\204\344\270\211\350\247\222\345\222\214.py" @@ -0,0 +1,6 @@ +class Solution: + def triangularSum(self, nums: List[int]) -> int: + if len(nums) == 1: + return nums[0] + + return self.triangularSum([nums[i] + nums[i - 1] for i in range(1, len(nums))]) % 10 \ No newline at end of file diff --git "a/LeetCode-Python/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" "b/LeetCode-Python/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" new file mode 100644 index 0000000..07efd32 --- /dev/null +++ "b/LeetCode-Python/2231.\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/2231-\346\214\211\345\245\207\345\201\266\346\200\247\344\272\244\346\215\242\345\220\216\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" @@ -0,0 +1,12 @@ +class Solution: + def largestInteger(self, num: int) -> int: + odd = sorted([int(digit) for digit in str(num) if digit in "13579"]) + even = sorted([int(digit) for digit in str(num) if digit not in "13579"]) + res = 0 + for digit in str(num): + if int(digit) % 2: + res = res * 10 + odd.pop() + else: + res = res * 10 + even.pop() + + return res diff --git "a/LeetCode-Python/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" "b/LeetCode-Python/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" new file mode 100644 index 0000000..a0a7c1f --- /dev/null +++ "b/LeetCode-Python/2235.\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240/2235-\344\270\244\346\225\264\346\225\260\347\233\270\345\212\240.py" @@ -0,0 +1,3 @@ +class Solution: + def sum(self, num1: int, num2: int) -> int: + return num1 + num2 \ No newline at end of file diff --git "a/LeetCode-Python/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" "b/LeetCode-Python/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" new file mode 100644 index 0000000..157a3c8 --- /dev/null +++ "b/LeetCode-Python/2236.\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214/2236-\345\210\244\346\226\255\346\240\271\347\273\223\347\202\271\346\230\257\345\220\246\347\255\211\344\272\216\345\255\220\347\273\223\347\202\271\344\271\213\345\222\214.py" @@ -0,0 +1,9 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def checkTree(self, root: Optional[TreeNode]) -> bool: + return root.val == root.left.val + root.right.val \ No newline at end of file diff --git "a/LeetCode-Python/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" "b/LeetCode-Python/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" new file mode 100644 index 0000000..0966cdd --- /dev/null +++ "b/LeetCode-Python/2255.\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256/2255-\347\273\237\350\256\241\346\230\257\347\273\231\345\256\232\345\255\227\347\254\246\344\270\262\345\211\215\347\274\200\347\232\204\345\255\227\347\254\246\344\270\262\346\225\260\347\233\256.py" @@ -0,0 +1,7 @@ +class Solution: + def countPrefixes(self, words: List[str], s: str) -> int: + res = 0 + for word in words: + if s.startswith(word): + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" "b/LeetCode-Python/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" new file mode 100644 index 0000000..a326504 --- /dev/null +++ "b/LeetCode-Python/2265.\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260/2265-\347\273\237\350\256\241\345\200\274\347\255\211\344\272\216\345\255\220\346\240\221\345\271\263\345\235\207\345\200\274\347\232\204\350\212\202\347\202\271\346\225\260.py" @@ -0,0 +1,28 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def averageOfSubtree(self, root: Optional[TreeNode]) -> int: + + self.res = 0 + def getAverageOfSubtree(node): + # post-order traversal + # return sum count + if not node: + return 0, 0 + + left_subtree_sum, left_count = getAverageOfSubtree(node.left) + right_subtree_sum, right_count = getAverageOfSubtree(node.right) + + subtree_sum = node.val + left_subtree_sum + right_subtree_sum + subtree_count = left_count + right_count + 1 + if node.val == subtree_sum // subtree_count: + self.res += 1 + + return subtree_sum, subtree_count + + getAverageOfSubtree(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" "b/LeetCode-Python/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" new file mode 100644 index 0000000..2974f8e --- /dev/null +++ "b/LeetCode-Python/2278.\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224/2278-\345\255\227\346\257\215\345\234\250\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\231\276\345\210\206\346\257\224.py" @@ -0,0 +1,3 @@ +class Solution: + def percentageLetter(self, s: str, letter: str) -> int: + return 100 * s.count(letter) // len(s) \ No newline at end of file diff --git "a/LeetCode-Python/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" "b/LeetCode-Python/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" new file mode 100644 index 0000000..8f5aabe --- /dev/null +++ "b/LeetCode-Python/2283.\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274/2283-\345\210\244\346\226\255\344\270\200\344\270\252\346\225\260\347\232\204\346\225\260\345\255\227\350\256\241\346\225\260\346\230\257\345\220\246\347\255\211\344\272\216\346\225\260\344\275\215\347\232\204\345\200\274.py" @@ -0,0 +1,10 @@ +class Solution: + def digitCount(self, num: str) -> bool: + from collections import Counter + c = Counter(num) + + for index, n in enumerate(num): + if c[str(index)] != int(n): + # print(c[index], index, int(n)) + return False + return True \ No newline at end of file diff --git "a/LeetCode-Python/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" "b/LeetCode-Python/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" new file mode 100644 index 0000000..00682ae --- /dev/null +++ "b/LeetCode-Python/2309.\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215/2309-\345\205\274\345\205\267\345\244\247\345\260\217\345\206\231\347\232\204\346\234\200\345\245\275\350\213\261\346\226\207\345\255\227\346\257\215.py" @@ -0,0 +1,9 @@ +class Solution: + def greatestLetter(self, s: str) -> str: + res = "" + s = set(s) + for char in s: + if char.lower() in s and char.upper() in s: + if not res or char.upper() > res: + res = char.upper() + return res \ No newline at end of file diff --git "a/LeetCode-Python/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" "b/LeetCode-Python/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" new file mode 100644 index 0000000..cfed43d --- /dev/null +++ "b/LeetCode-Python/2315.\347\273\237\350\256\241\346\230\237\345\217\267/2315-\347\273\237\350\256\241\346\230\237\345\217\267.py" @@ -0,0 +1,10 @@ +class Solution: + def countAsterisks(self, s: str) -> int: + bar = False + res = 0 + for char in s: + if char == "|": + bar = not bar + if not bar and char == "*": + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" "b/LeetCode-Python/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" new file mode 100644 index 0000000..c8d94e1 --- /dev/null +++ "b/LeetCode-Python/2319.\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265/2319-\345\210\244\346\226\255\347\237\251\351\230\265\346\230\257\345\220\246\346\230\257\344\270\200\344\270\252X\347\237\251\351\230\265.py" @@ -0,0 +1,15 @@ +class Solution: + def checkXMatrix(self, grid: List[List[int]]) -> bool: + if not grid or not grid[0]: + return False + m, n = len(grid), len(grid[0]) + + for i in range(m): + for j in range(n): + if i == j or i + j == n - 1: + if grid[i][j] == 0: + return False + else: + if grid[i][j] != 0: + return False + return True \ No newline at end of file diff --git "a/LeetCode-Python/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" "b/LeetCode-Python/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" new file mode 100644 index 0000000..2ce85bf --- /dev/null +++ "b/LeetCode-Python/2330.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV/2330-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207IV.py" @@ -0,0 +1,12 @@ +class Solution: + def makePalindrome(self, s: str) -> bool: + left, right = 0, len(s) - 1 + + step = 0 + while left < right: + if s[left] != s[right]: + step += 1 + left += 1 + right -= 1 + + return step <= 2 \ No newline at end of file diff --git "a/LeetCode-Python/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" "b/LeetCode-Python/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" new file mode 100644 index 0000000..29c46c5 --- /dev/null +++ "b/LeetCode-Python/2331.\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274/2331-\350\256\241\347\256\227\345\270\203\345\260\224\344\272\214\345\217\211\346\240\221\347\232\204\345\200\274.py" @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def evaluateTree(self, root: Optional[TreeNode]) -> bool: + if root.val == 0: + return False + if root.val == 1: + return True + if root.val == 2: + return self.evaluateTree(root.left) or self.evaluateTree(root.right) + if root.val == 3: + return self.evaluateTree(root.left) and self.evaluateTree(root.right) \ No newline at end of file diff --git "a/LeetCode-Python/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" "b/LeetCode-Python/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" new file mode 100644 index 0000000..7775e85 --- /dev/null +++ "b/LeetCode-Python/2335.\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277/2335-\350\243\205\346\273\241\346\235\257\345\255\220\351\234\200\350\246\201\347\232\204\346\234\200\347\237\255\346\200\273\346\227\266\351\225\277.py" @@ -0,0 +1,16 @@ +from heapq import * +class Solution: + def fillCups(self, amount: List[int]) -> int: + max_heap = [-a for a in amount if a] + heapify(max_heap) + res = 0 + while len(max_heap) > 1: + first, second = -heappop(max_heap), -heappop(max_heap) + if first > 1: + heappush(max_heap, -(first - 1)) + if second > 1: + heappush(max_heap, -(second - 1)) + res += 1 + + return res + -max_heap[0] if max_heap else res + \ No newline at end of file diff --git "a/LeetCode-Python/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" "b/LeetCode-Python/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" new file mode 100644 index 0000000..65801ca --- /dev/null +++ "b/LeetCode-Python/2336.\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/2336-\346\227\240\351\231\220\351\233\206\344\270\255\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" @@ -0,0 +1,23 @@ +from heapq import * +class SmallestInfiniteSet: + + def __init__(self): + self.min_heap = [i for i in range(1, 1001)] + heapify(self.min_heap) + self.set = set(self.min_heap) + + def popSmallest(self) -> int: + val = heappop(self.min_heap) + self.set.remove(val) + return val + + def addBack(self, num: int) -> None: + if num not in self.set: + heappush(self.min_heap, num) + self.set.add(num) + + +# Your SmallestInfiniteSet object will be instantiated and called as such: +# obj = SmallestInfiniteSet() +# param_1 = obj.popSmallest() +# obj.addBack(num) \ No newline at end of file diff --git "a/LeetCode-Python/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" "b/LeetCode-Python/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" new file mode 100644 index 0000000..6b08e20 --- /dev/null +++ "b/LeetCode-Python/2352.\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271/2352-\347\233\270\347\255\211\350\241\214\345\210\227\345\257\271.py" @@ -0,0 +1,8 @@ +class Solution: + def equalPairs(self, grid: List[List[int]]) -> int: + col_grid = [list(col) for col in zip(*grid)] + res = 0 + for row in grid: + for col in col_grid: + res += row == col + return res \ No newline at end of file diff --git "a/LeetCode-Python/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" "b/LeetCode-Python/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" new file mode 100644 index 0000000..23592d7 --- /dev/null +++ "b/LeetCode-Python/2357.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266/2357-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\351\203\275\347\255\211\344\272\216\351\233\266.py" @@ -0,0 +1,13 @@ +class Solution: + def minimumOperations(self, nums: List[int]) -> int: + res = 0 + while sum(nums): + res += 1 + m = 101 + for num in nums: + if num: + m = min(m, num) + for i, num in enumerate(nums): + if num: + nums[i] -= m + return res \ No newline at end of file diff --git "a/LeetCode-Python/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" "b/LeetCode-Python/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" new file mode 100644 index 0000000..95d587a --- /dev/null +++ "b/LeetCode-Python/2391.\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264/2391-\346\224\266\351\233\206\345\236\203\345\234\276\347\232\204\346\234\200\345\260\221\346\200\273\346\227\266\351\227\264.py" @@ -0,0 +1,36 @@ +class Solution: + def garbageCollection(self, garbage: List[str], travel: List[int]) -> int: + t_m, t_p, t_g = 0, 0, 0 + + driving_time_m = 0 + driving_time_p = 0 + driving_time_g = 0 + for index, g in enumerate(garbage): + # M + count_m = g.count("M") + if index: + driving_time_m += travel[index - 1] + if count_m: + t_m += count_m + t_m += driving_time_m + driving_time_m = 0 + + + count_p = g.count("P") + if index: + driving_time_p += travel[index - 1] + if count_p: + t_p += count_p + t_p += driving_time_p + driving_time_p = 0 + + + count_g = g.count("G") + if index: + driving_time_g += travel[index - 1] + if count_g: + t_g += count_g + t_g += driving_time_g + driving_time_g = 0 + + return t_m + t_p + t_g \ No newline at end of file diff --git "a/LeetCode-Python/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" "b/LeetCode-Python/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..a6f7c89 --- /dev/null +++ "b/LeetCode-Python/2396.\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227/2396-\344\270\245\346\240\274\345\233\236\346\226\207\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,11 @@ +class Solution: + def isStrictlyPalindromic(self, n: int) -> bool: + for k in range(2, n - 1): + bk = "" + temp = n + while temp: + temp, m = divmod(temp, k) + bk += str(m) + if bk != bk[::-1]: + return False + return True \ No newline at end of file diff --git "a/LeetCode-Python/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" "b/LeetCode-Python/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" new file mode 100644 index 0000000..f9b5b32 --- /dev/null +++ "b/LeetCode-Python/2399.\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273/2399-\346\243\200\346\237\245\347\233\270\345\220\214\345\255\227\346\257\215\351\227\264\347\232\204\350\267\235\347\246\273.py" @@ -0,0 +1,9 @@ +class Solution: + def checkDistances(self, s: str, distance: List[int]) -> bool: + res = True + for i, d in enumerate(distance): + char = chr(ord("a") + i) + if s.count(char): + if s.rfind(char) - s.index(char) != d + 1: + res = False + return res \ No newline at end of file diff --git "a/LeetCode-Python/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" "b/LeetCode-Python/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" new file mode 100644 index 0000000..c5d3e13 --- /dev/null +++ "b/LeetCode-Python/2413.\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260/2413-\346\234\200\345\260\217\345\201\266\345\200\215\346\225\260.py" @@ -0,0 +1,3 @@ +class Solution: + def smallestEvenMultiple(self, n: int) -> int: + return 2 * n if n % 2 else n \ No newline at end of file diff --git "a/LeetCode-Python/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" "b/LeetCode-Python/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" new file mode 100644 index 0000000..ae9c914 --- /dev/null +++ "b/LeetCode-Python/2418.\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217/2418-\346\214\211\350\272\253\351\253\230\346\216\222\345\272\217.py" @@ -0,0 +1,6 @@ +class Solution: + def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: + combine = [(name, heights[index]) for index, name in enumerate(names)] + + + return [pair[0] for pair in sorted(combine, key = lambda x: -x[1])] \ No newline at end of file diff --git "a/LeetCode-Python/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" "b/LeetCode-Python/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" new file mode 100644 index 0000000..fc19c6b --- /dev/null +++ "b/LeetCode-Python/2441.\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260/2441-\344\270\216\345\257\271\345\272\224\350\264\237\346\225\260\345\220\214\346\227\266\345\255\230\345\234\250\347\232\204\346\234\200\345\244\247\346\255\243\346\225\264\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution: + def findMaxK(self, nums: List[int]) -> int: + s = set(nums) + res = -1 + for num in nums: + if -num in s: + res = max(num, -num, res) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" "b/LeetCode-Python/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" new file mode 100644 index 0000000..15bcc06 --- /dev/null +++ "b/LeetCode-Python/2446.\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201/2446-\345\210\244\346\226\255\344\270\244\344\270\252\344\272\213\344\273\266\346\230\257\345\220\246\345\255\230\345\234\250\345\206\262\347\252\201.py" @@ -0,0 +1,8 @@ +class Solution: + def haveConflict(self, event1: List[str], event2: List[str]) -> bool: + return not (self.time1EarlierThanTime2(event1[1], event2[0]) or self.time1EarlierThanTime2(event2[1], event1[0])) + + def time1EarlierThanTime2(self, time1, time2): + h1, h2 = int(time1[:2]), int(time2[:2]) + m1, m2 = int(time1[3:]), int(time2[3:]) + return h1 < h2 or (h1 == h2 and m1 < m2) \ No newline at end of file diff --git "a/LeetCode-Python/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..b713bed --- /dev/null +++ "b/LeetCode-Python/2451.\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262/2451-\345\267\256\345\200\274\346\225\260\347\273\204\344\270\215\345\220\214\347\232\204\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,17 @@ +class Solution: + def oddString(self, words: List[str]) -> str: + l = [] + for word in words: + diff = [] + for i, char in enumerate(word): + if i: + diff.append(ord(char) - ord(word[i - 1])) + l.append(diff) + # print(l) + + if l[0] != l[1] and l[0] != l[2]: + return words[0] + + for i, diff in enumerate(l): + if diff != l[0]: + return words[i] \ No newline at end of file diff --git "a/LeetCode-Python/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" "b/LeetCode-Python/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" new file mode 100644 index 0000000..94144da --- /dev/null +++ "b/LeetCode-Python/2455.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274/2455-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\345\201\266\346\225\260\347\232\204\345\271\263\345\235\207\345\200\274.py" @@ -0,0 +1,8 @@ +class Solution: + def averageValue(self, nums: List[int]) -> int: + s, cnt = 0, 0 + for num in nums: + if num % 6 == 0: + cnt += 1 + s += num + return int(s / cnt) if cnt else 0 \ No newline at end of file diff --git "a/LeetCode-Python/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" "b/LeetCode-Python/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" new file mode 100644 index 0000000..6a40092 --- /dev/null +++ "b/LeetCode-Python/2460.\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234/2460-\345\257\271\346\225\260\347\273\204\346\211\247\350\241\214\346\223\215\344\275\234.py" @@ -0,0 +1,17 @@ +class Solution: + def applyOperations(self, nums: List[int]) -> List[int]: + n = len(nums) + for i in range(n - 1): + if nums[i] == nums[i + 1]: + nums[i] *= 2 + nums[i + 1] = 0 + + index = 0 + for i in range(n): + if nums[i]: + nums[index] = nums[i] + index += 1 + + for i in range(index, n): + nums[i] = 0 + return nums \ No newline at end of file diff --git "a/LeetCode-Python/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" "b/LeetCode-Python/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" new file mode 100644 index 0000000..02dfad9 --- /dev/null +++ "b/LeetCode-Python/2465.\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256/2465-\344\270\215\345\220\214\347\232\204\345\271\263\345\235\207\345\200\274\346\225\260\347\233\256.py" @@ -0,0 +1,9 @@ +class Solution: + def distinctAverages(self, nums: List[int]) -> int: + nums.sort() + res = set() + while nums: + res.add((nums[0] + nums[-1]) / 2.0) + nums = nums[1:-1] + + return len(res) \ No newline at end of file diff --git "a/LeetCode-Python/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" "b/LeetCode-Python/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" new file mode 100644 index 0000000..812b4f1 --- /dev/null +++ "b/LeetCode-Python/2466.\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260/2466-\347\273\237\350\256\241\346\236\204\351\200\240\345\245\275\345\255\227\347\254\246\344\270\262\347\232\204\346\226\271\346\241\210\346\225\260.py" @@ -0,0 +1,36 @@ +class Solution: + def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int: + # f(i) = f(i - zero) + f(i - one) + # 00, 10, 11, 10, 0, 1 + # self.res = 0 + # MOD = int(1e9 + 7) + # memo = dict() + # def dfs(i): + # if i == 0: + # return 1 + # count = 0 + # if i in memo: + # return memo[i] + # if i >= zero: + # count += dfs(i - zero) + # if i >= one: + # count += dfs(i - one) + # # l represents count of distinct good string of length i + # if i >= low: + # self.res += count % MOD + # memo[i] = count + # return count + # dfs(high) + # return self.res % MOD + MOD = int(1e9 + 7) + dp = [0] * (high + max(zero, one)) + dp[0] = 1 + res = 0 + for i in range(1, high + 1): + if i >= zero: + dp[i] += dp[i - zero] + if i >= one: + dp[i] += dp[i - one] + if i >= low: + res += dp[i] % MOD + return res % MOD \ No newline at end of file diff --git "a/LeetCode-Python/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" "b/LeetCode-Python/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" new file mode 100644 index 0000000..091b21a --- /dev/null +++ "b/LeetCode-Python/2469.\346\270\251\345\272\246\350\275\254\346\215\242/2469-\346\270\251\345\272\246\350\275\254\346\215\242.py" @@ -0,0 +1,3 @@ +class Solution: + def convertTemperature(self, celsius: float) -> List[float]: + return [celsius + 273.15, celsius * 1.8 + 32] \ No newline at end of file diff --git "a/LeetCode-Python/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" "b/LeetCode-Python/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" new file mode 100644 index 0000000..270f3e4 --- /dev/null +++ "b/LeetCode-Python/2482.\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274/2482-\350\241\214\345\222\214\345\210\227\344\270\255\344\270\200\345\222\214\351\233\266\347\232\204\345\267\256\345\200\274.py" @@ -0,0 +1,15 @@ +class Solution: + def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]: + m, n = len(grid), len(grid[0]) + row2one = {} + col2one = {} + for i, row in enumerate(grid): + row2one[i] = sum(row) + for j, col in enumerate(zip(*grid)): + col2one[j] = sum(col) + + diff = [[0 for i in range(n)] for j in range(m)] + for i in range(m): + for j in range(n): + diff[i][j] = row2one[i] + col2one[j] - (n - row2one[i]) - (m - col2one[j]) + return diff \ No newline at end of file diff --git "a/LeetCode-Python/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" "b/LeetCode-Python/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" new file mode 100644 index 0000000..0848d99 --- /dev/null +++ "b/LeetCode-Python/2487.\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271/2487-\344\273\216\351\223\276\350\241\250\344\270\255\347\247\273\351\231\244\350\212\202\347\202\271.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]: + dummy = ListNode(-1) + dummy.next = head + + stack = [] # [node] + nodes_to_be_deleted = set() + p = head + while p: + while stack and stack[-1].val < p.val: + nodes_to_be_deleted.add(stack[-1]) + stack.pop() + stack.append(p) + p = p.next + + p = dummy + while p.next: + if p.next in nodes_to_be_deleted: + p.next = p.next.next + else: + p = p.next + return dummy.next + diff --git "a/LeetCode-Python/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/LeetCode-Python/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..5a09c51 --- /dev/null +++ "b/LeetCode-Python/2496.\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274/2496-\346\225\260\347\273\204\344\270\255\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,14 @@ +class Solution: + def maximumValue(self, strs: List[str]) -> int: + res = float("-inf") + for s in strs: + isNumber = True + for char in s: + if not char.isdigit(): + isNumber = False + break + if isNumber: + res = max(res, int(s)) + else: + res = max(res, len(s)) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" "b/LeetCode-Python/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..80070f6 --- /dev/null +++ "b/LeetCode-Python/2506.\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256/2506-\347\273\237\350\256\241\347\233\270\344\274\274\345\255\227\347\254\246\344\270\262\345\257\271\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,11 @@ +class Solution: + def similarPairs(self, words: List[str]) -> int: + from collections import defaultdict + pattern2count = defaultdict(int) + for word in words: + pattern2count["".join(sorted(list(set(word))))] += 1 + + res = 0 + for pattern, count in pattern2count.items(): + res += count * (count - 1) // 2 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" "b/LeetCode-Python/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" new file mode 100644 index 0000000..a38b8cd --- /dev/null +++ "b/LeetCode-Python/2517.\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246/2517-\347\244\274\347\233\222\347\232\204\346\234\200\345\244\247\347\224\234\350\234\234\345\272\246.py" @@ -0,0 +1,25 @@ +class Solution: + def maximumTastiness(self, price: List[int], k: int) -> int: + # 13, 1, 21 - 12, 20, 8 + price = set(price) + if len(price) < k: + return 0 + + # 1, 2, 5, 8, 13, 21 + price = sorted(list(price)) + left, right = 0, price[-1] - price[0] + while left <= right: + mid = (left + right) // 2 # target tastyness + + cnt, prev = 1, price[0] + for p in price: + if prev + mid <= p: # 鍙堟壘鍒颁簡涓涓 + cnt += 1 + prev = p + + if cnt >= k: + left = mid + 1 + elif cnt < k: + right = mid - 1 + + return right \ No newline at end of file diff --git "a/LeetCode-Python/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" "b/LeetCode-Python/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" new file mode 100644 index 0000000..e7d86a4 --- /dev/null +++ "b/LeetCode-Python/2529.\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260/2529-\346\255\243\346\225\264\346\225\260\345\222\214\350\264\237\346\225\264\346\225\260\347\232\204\346\234\200\345\244\247\350\256\241\346\225\260.py" @@ -0,0 +1,32 @@ +class Solution: + def maximumCount(self, nums: List[int]) -> int: + # 1. find the right-most negative number + negative_index = -1 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] < 0: + negative_index = mid + left = mid + 1 + elif nums[mid] >= 0: + right = mid - 1 + + # print(negative_index) + # 2. find the left-most positive number + positive_index = -1 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] > 0: + positive_index = mid + right = mid - 1 + else: + left = mid + 1 + + if negative_index > -1 and positive_index > -1: + return max(negative_index + 1, len(nums) - positive_index) + elif negative_index > -1: + return negative_index + 1 + elif positive_index > -1: + return len(nums) - positive_index + return 0 \ No newline at end of file diff --git "a/LeetCode-Python/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" "b/LeetCode-Python/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" new file mode 100644 index 0000000..70cbf0e --- /dev/null +++ "b/LeetCode-Python/2545.\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217/2545-\346\240\271\346\215\256\347\254\254K\345\234\272\350\200\203\350\257\225\347\232\204\345\210\206\346\225\260\346\216\222\345\272\217.py" @@ -0,0 +1,3 @@ +class Solution: + def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]: + return sorted(score, key = lambda x:-x[k]) \ No newline at end of file diff --git "a/LeetCode-Python/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" "b/LeetCode-Python/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" new file mode 100644 index 0000000..54d4646 --- /dev/null +++ "b/LeetCode-Python/2553.\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215/2553-\345\210\206\345\211\262\346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\347\232\204\346\225\260\344\275\215.py" @@ -0,0 +1,8 @@ +class Solution: + def separateDigits(self, nums: List[int]) -> List[int]: + res = [] + + for num in nums: + for digit in str(num): + res.append(int(digit)) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" "b/LeetCode-Python/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" new file mode 100644 index 0000000..ddfc2cf --- /dev/null +++ "b/LeetCode-Python/2558.\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251/2558-\344\273\216\346\225\260\351\207\217\346\234\200\345\244\232\347\232\204\345\240\206\345\217\226\350\265\260\347\244\274\347\211\251.py" @@ -0,0 +1,12 @@ +from heapq import * +class Solution: + def pickGifts(self, gifts: List[int], k: int) -> int: + max_heap = [] + for gift in gifts: + heappush(max_heap, -gift) + + while k: + gift = -heappop(max_heap) + heappush(max_heap, -int(gift ** 0.5)) + k -= 1 + return -sum(max_heap) diff --git "a/LeetCode-Python/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" "b/LeetCode-Python/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" new file mode 100644 index 0000000..188fa3b --- /dev/null +++ "b/LeetCode-Python/2562.\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274/2562-\346\211\276\345\207\272\346\225\260\347\273\204\347\232\204\344\270\262\350\201\224\345\200\274.py" @@ -0,0 +1,11 @@ +class Solution: + def findTheArrayConcVal(self, nums: List[int]) -> int: + res = 0 + while nums: + if len(nums) > 1: + serial = int(str(nums[0]) + str(nums[-1])) + else: + serial = nums[0] + res += serial + nums = nums[1:-1] + return res \ No newline at end of file diff --git "a/LeetCode-Python/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" "b/LeetCode-Python/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" new file mode 100644 index 0000000..844959c --- /dev/null +++ "b/LeetCode-Python/2574.\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274/2574-\345\267\246\345\217\263\345\205\203\347\264\240\345\222\214\347\232\204\345\267\256\345\200\274.py" @@ -0,0 +1,12 @@ +class Solution: + def leftRightDifference(self, nums: List[int]) -> List[int]: + left_sum = [0] + right_sum = [0] + + for num in nums[:-1]: + left_sum.append(num + left_sum[-1]) + + for num in nums[::-1][:-1]: + right_sum.append(num + right_sum[-1]) + + return [abs(l - r) for l, r in zip(left_sum, right_sum[::-1])] \ No newline at end of file diff --git "a/LeetCode-Python/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" "b/LeetCode-Python/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" new file mode 100644 index 0000000..ee2f5d3 --- /dev/null +++ "b/LeetCode-Python/2586.\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260/2586-\347\273\237\350\256\241\350\214\203\345\233\264\345\206\205\347\232\204\345\205\203\351\237\263\345\255\227\347\254\246\344\270\262\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution: + def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]: + vowelStringCount = [0 for _ in words] + VOWELS = set("aeiou") + for i in range(len(words)): + if words[i][0] in VOWELS and words[i][-1] in VOWELS: + vowelStringCount[i] = vowelStringCount[i - 1] + 1 + else: + vowelStringCount[i] = vowelStringCount[i - 1] + + res = [] + for l, r in queries: + if l: + res.append(vowelStringCount[r] - vowelStringCount[l - 1]) + else: + res.append(vowelStringCount[r]) + return res diff --git "a/LeetCode-Python/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" "b/LeetCode-Python/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" new file mode 100644 index 0000000..203e13d --- /dev/null +++ "b/LeetCode-Python/2610.\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204/2610-\350\275\254\346\215\242\344\272\214\347\273\264\346\225\260\347\273\204.py" @@ -0,0 +1,12 @@ +class Solution: + def findMatrix(self, nums: List[int]) -> List[List[int]]: + from collections import Counter + c = Counter(nums) + res = [] + for num, freq in c.items(): + while len(res) < freq: + res.append([]) + + for i in range(freq): + res[i].append(num) + return res diff --git "a/LeetCode-Python/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/LeetCode-Python/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" new file mode 100644 index 0000000..46fe631 --- /dev/null +++ "b/LeetCode-Python/2656.K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214/2656-K\344\270\252\345\205\203\347\264\240\347\232\204\346\234\200\345\244\247\345\222\214.py" @@ -0,0 +1,3 @@ +class Solution: + def maximizeSum(self, nums: List[int], k: int) -> int: + return max(nums) * k + k * (k - 1) // 2 \ No newline at end of file diff --git "a/LeetCode-Python/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" "b/LeetCode-Python/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" new file mode 100644 index 0000000..d3bda30 --- /dev/null +++ "b/LeetCode-Python/2670.\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204/2670-\346\211\276\345\207\272\344\270\215\345\220\214\345\205\203\347\264\240\346\225\260\347\233\256\345\267\256\346\225\260\347\273\204.py" @@ -0,0 +1,10 @@ +class Solution: + def distinctDifferenceArray(self, nums: List[int]) -> List[int]: + res = [] + + for i, num in enumerate(nums): + pre_count = len(set(nums[:i + 1])) + post_count = len(set(nums[i + 1:])) + + res.append(pre_count - post_count) + return res \ No newline at end of file diff --git "a/LeetCode-Python/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" "b/LeetCode-Python/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" new file mode 100644 index 0000000..cd5339d --- /dev/null +++ "b/LeetCode-Python/2671.\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250/2671-\351\242\221\347\216\207\350\267\237\350\270\252\345\231\250.py" @@ -0,0 +1,34 @@ +from collections import defaultdict +class FrequencyTracker: + + def __init__(self): + self.freq2num = defaultdict(set) + self.num2freq = defaultdict(int) + + def add(self, number: int) -> None: + # print(self.num2freq, self.freq2num) + freq = self.num2freq[number] + self.num2freq[number] += 1 + if number in self.freq2num[freq]: + self.freq2num[freq].remove(number) + self.freq2num[freq + 1].add(number) + + def deleteOne(self, number: int) -> None: + # print(self.num2freq, self.freq2num) + if number not in self.num2freq or self.num2freq[number] == 0: + return + freq = self.num2freq[number] + self.num2freq[number] -= 1 + if number in self.freq2num[freq]: + self.freq2num[freq].remove(number) + self.freq2num[freq - 1].add(number) + + def hasFrequency(self, frequency: int) -> bool: + return len(self.freq2num[frequency]) > 0 + + +# Your FrequencyTracker object will be instantiated and called as such: +# obj = FrequencyTracker() +# obj.add(number) +# obj.deleteOne(number) +# param_3 = obj.hasFrequency(frequency) \ No newline at end of file diff --git "a/LeetCode-Python/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" "b/LeetCode-Python/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" new file mode 100644 index 0000000..aa8f15e --- /dev/null +++ "b/LeetCode-Python/2674.\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250/2674-\346\213\206\345\210\206\345\276\252\347\216\257\351\223\276\350\241\250.py" @@ -0,0 +1,29 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def splitCircularLinkedList(self, head: Optional[ListNode]) -> List[Optional[ListNode]]: + + l, p = 0, head + last = None + flag = False + while not flag or p != head: + flag = True + l += 1 + if p.next == head: + last = p + p = p.next + # print(l, last) + mid = math.ceil(l / 2) + + cnt, p = 1, head + while cnt < mid: + p = p.next + cnt += 1 + + next_head = p.next + p.next = head + last.next = next_head + return [head, next_head] diff --git "a/LeetCode-Python/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" "b/LeetCode-Python/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..6173751 --- /dev/null +++ "b/LeetCode-Python/2678.\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256/2678-\350\200\201\344\272\272\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,8 @@ +class Solution: + def countSeniors(self, details: List[str]) -> int: + # res = 0 + # for detail in details: + # if int(detail[-4:-2]) > 60: + # res += 1 + # return res + return sum([int(detail[-4:-2]) > 60 for detail in details]) \ No newline at end of file diff --git "a/LeetCode-Python/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" "b/LeetCode-Python/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" new file mode 100644 index 0000000..96145c7 --- /dev/null +++ "b/LeetCode-Python/2679.\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214/2679-\347\237\251\351\230\265\344\270\255\347\232\204\345\222\214.py" @@ -0,0 +1,23 @@ +from heapq import * +class Solution: + def matrixSum(self, nums: List[List[int]]) -> int: + # if not nums or not nums[0]: + # return 0 + # m, n = len(nums), len(nums[0]) + # all_max_heap = [] + # for num in nums: + # max_heap = [-n for n in num] + # heapify(max_heap) + # all_max_heap.append(max_heap) + + # res = 0 + # for _ in range(n): + # score = 0 + # for i in range(m): + # score = max(score, -heappop(all_max_heap[i])) + # res += score + # return res + for num in nums: + num.sort() + + return sum(max(col) for col in zip(*nums)) \ No newline at end of file diff --git "a/LeetCode-Python/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" "b/LeetCode-Python/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" new file mode 100644 index 0000000..7947da9 --- /dev/null +++ "b/LeetCode-Python/2682.\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/2682-\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266.py" @@ -0,0 +1,12 @@ +class Solution: + def circularGameLosers(self, n: int, k: int) -> List[int]: + visited = set() + cur, cnt = 1, 1 + while cur not in visited: + visited.add(cur) + cur = cur + k * cnt + while cur > n: + cur = cur - n + cnt += 1 + + return [i for i in range(1, n + 1) if i not in visited] \ No newline at end of file diff --git "a/LeetCode-Python/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" "b/LeetCode-Python/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" new file mode 100644 index 0000000..d7e390a --- /dev/null +++ "b/LeetCode-Python/2683.\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226/2683-\347\233\270\351\202\273\345\200\274\347\232\204\346\214\211\344\275\215\345\274\202\346\210\226.py" @@ -0,0 +1,9 @@ +class Solution: + def doesValidArrayExist(self, derived: List[int]) -> bool: + cur = 0 + for i, n in enumerate(derived): + if i != len(derived) - 1: + if n == 1: + cur = 1 - cur + else: + return 0 ^ cur == n \ No newline at end of file diff --git "a/LeetCode-Python/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" "b/LeetCode-Python/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" new file mode 100644 index 0000000..8fc6a8a --- /dev/null +++ "b/LeetCode-Python/2684.\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260/2684-\347\237\251\351\230\265\344\270\255\347\247\273\345\212\250\347\232\204\346\234\200\345\244\247\346\254\241\346\225\260.py" @@ -0,0 +1,43 @@ +class Solution: + def maxMoves(self, grid: List[List[int]]) -> int: + # if not grid or not grid[0]: + # return 0 + # m, n = len(grid), len(grid[0]) + # dp = [[0 for _ in range(n)] for k in range(m)] + # dij = [[-1, 1], [0, 1], [1, 1]] + + # for col in range(n): + # for row in range(m): + # if not col or dp[row][col] != 0: + # for d in dij: + # i, j = row + d[0], col + d[1] + # if self.nodeInMatrix(i, j, m, n) and grid[i][j] > grid[row][col]: + # dp[i][j] = max(dp[i][j], dp[row][col] + 1) + + # return max([max(row) for row in dp]) + from collections import deque + queue = deque([]) + if not grid or not grid[0]: + return 0 + m, n = len(grid), len(grid[0]) + dxy = [[-1, 1], [0, 1], [1, 1]] + res = 0 + visited = set() + for i in range(m): + queue.append((0, i, 0)) # step, x, y + + while queue: + step, x, y = queue.popleft() + res = max(res, step) + + for dx, dy in dxy: + xx, yy = x + dx, y + dy + + if self.nodeInMatrix(xx, yy, m, n) and grid[xx][yy] > grid[x][y] and (xx, yy) not in visited: + visited.add((xx, yy)) + queue.append((step + 1, xx, yy)) + return res + + def nodeInMatrix(self, row, col, m, n): + return 0 <= row < m and 0 <= col < n + \ No newline at end of file diff --git "a/LeetCode-Python/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" "b/LeetCode-Python/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" new file mode 100644 index 0000000..69d881a --- /dev/null +++ "b/LeetCode-Python/2685.\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217/2685-\347\273\237\350\256\241\345\256\214\345\205\250\350\277\236\351\200\232\345\210\206\351\207\217\347\232\204\346\225\260\351\207\217.py" @@ -0,0 +1,27 @@ +class Solution: + def countCompleteComponents(self, n: int, edges: List[List[int]]) -> int: + from collections import defaultdict + src2des = defaultdict(set) + + res = 0 + visited = set() + for edge in edges: + src, des = edge[0], edge[1] + src2des[src].add(des) + src2des[src].add(src) + src2des[des].add(src) + src2des[des].add(des) + + for node in range(n): + if node not in visited: + connected = True + visited.add(node) + for connected_node in src2des[node]: + visited.add(connected_node) + if src2des[connected_node] != src2des[node]: + connected = False + break + + if connected: + res += 1 + return res \ No newline at end of file diff --git "a/LeetCode-Python/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" "b/LeetCode-Python/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" new file mode 100644 index 0000000..793fbb8 --- /dev/null +++ "b/LeetCode-Python/2696.\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246/2696-\345\210\240\351\231\244\345\255\220\344\270\262\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\351\225\277\345\272\246.py" @@ -0,0 +1,12 @@ +class Solution: + def minLength(self, s: str) -> int: + stack = [] + + for char in s: + if char == "D" and stack and stack[-1] == "C": + stack.pop() + elif char == "B" and stack and stack[-1] == "A": + stack.pop() + else: + stack.append(char) + return len(stack) \ No newline at end of file diff --git "a/LeetCode-Python/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" "b/LeetCode-Python/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..aae6620 --- /dev/null +++ "b/LeetCode-Python/2697.\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262/2697-\345\255\227\345\205\270\345\272\217\346\234\200\345\260\217\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,16 @@ +class Solution: + def makeSmallestPalindrome(self, s: str) -> str: + left, right = 0, len(s) - 1 + res_left = "" + res_right = "" + while left < right: + res_left += min(s[left], s[right]) + res_right = min(s[left], s[right]) + res_right + left += 1 + right -= 1 + + if left == right: + res = res_left + s[left] + res_right + else: + res = res_left + res_right + return res \ No newline at end of file diff --git "a/LeetCode-Python/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" "b/LeetCode-Python/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" new file mode 100644 index 0000000..b152802 --- /dev/null +++ "b/LeetCode-Python/2698.\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260/2698-\346\261\202\344\270\200\344\270\252\346\225\264\346\225\260\347\232\204\346\203\251\347\275\232\346\225\260.py" @@ -0,0 +1,27 @@ +class Solution: + def punishmentNumber(self, n: int) -> int: + res = 0 + for i in range(1, n + 1): + i2 = i * i + self.possible(i) + if self.res: + res += i2 + return res + + def possible(self, num): + # 鍒ゆ柇 1296 鏄惁鍙互鍒嗘垚 1 + 29 + 6 == 36 + self.res = False + def helper(n, s): + # 棣栨閫掑綊 n = 36, s = 1296 + if not s or n > int(s): + return + if int(s) == n: + self.res = True + return + for i in range(1, len(str(n)) + 1): + # 涓嬫閫掑綊 n = 30, s = 129 + helper(n - int(s[-i:]), s[:-i]) + helper(num, str(num * num)) + + + \ No newline at end of file diff --git "a/LeetCode-Python/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" "b/LeetCode-Python/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" new file mode 100644 index 0000000..b368281 --- /dev/null +++ "b/LeetCode-Python/2706.\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233/2706-\350\264\255\344\271\260\344\270\244\345\235\227\345\267\247\345\205\213\345\212\233.py" @@ -0,0 +1,5 @@ +class Solution: + def buyChoco(self, prices: List[int], money: int) -> int: + prices.sort() + s = prices[0] + prices[1] + return money if s > money else money - s \ No newline at end of file diff --git "a/LeetCode-Python/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" "b/LeetCode-Python/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" new file mode 100644 index 0000000..eb2f6c5 --- /dev/null +++ "b/LeetCode-Python/2707.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246/2707-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\351\242\235\345\244\226\345\255\227\347\254\246.py" @@ -0,0 +1,15 @@ +class Solution: + def minExtraChar(self, s: str, dictionary: List[str]) -> int: + # dp[i] represents res for s[:i] + dp = [i for i in range(len(s) + 1)] + + for i in range(len(s) + 1): + dp[i] = min(dp[i], dp[i - 1] + 1) + for d in dictionary: + if i >= len(d) and s[i - len(d):i] == d: + dp[i] = min(dp[i], dp[i - len(d)]) + + return dp[-1] + + + \ No newline at end of file diff --git "a/LeetCode-Python/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" "b/LeetCode-Python/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" new file mode 100644 index 0000000..d91c8b4 --- /dev/null +++ "b/LeetCode-Python/2708.\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274/2708-\344\270\200\344\270\252\345\260\217\347\273\204\347\232\204\346\234\200\345\244\247\345\256\236\345\212\233\345\200\274.py" @@ -0,0 +1,21 @@ +class Solution: + def maxStrength(self, nums: List[int]) -> int: + if all([num == 0 for num in nums]): + return 0 + if len(nums) == 1: + return nums[0] + pos = [num for num in nums if num > 0] + neg = [num for num in nums if num < 0] + + res = 0 + neg_length = len(neg) + if neg_length >= 2: + if neg_length % 2 == 0: + res = reduce((lambda x, y: x * y), neg) + else: + neg.sort() + res = reduce((lambda x, y: x * y), neg[:-1]) + + if pos: + res = reduce((lambda x, y: x * y), pos) * max(res, 1) + return res diff --git "a/LeetCode-Python/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" "b/LeetCode-Python/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" new file mode 100644 index 0000000..2d286a5 --- /dev/null +++ "b/LeetCode-Python/2710.\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266/2710-\347\247\273\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\345\260\276\351\232\217\351\233\266.py" @@ -0,0 +1,5 @@ +class Solution: + def removeTrailingZeros(self, num: str) -> str: + for i in range(len(num) - 1, -1, -1): + if num[i] != "0": + return num[:i + 1] \ No newline at end of file diff --git "a/LeetCode-Python/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" "b/LeetCode-Python/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" new file mode 100644 index 0000000..c6ad528 --- /dev/null +++ "b/LeetCode-Python/2712.\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254/2712-\344\275\277\346\211\200\346\234\211\345\255\227\347\254\246\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\210\220\346\234\254.py" @@ -0,0 +1,12 @@ +class Solution: + def minimumCost(self, s: str) -> int: + # 110101 + # 111010 min(i, n - i) + prev = s[0] + res = 0 + for i, char in enumerate(s): + if i and char != prev: + # flip is required: + res += min(i, len(s) - i) + prev = char + return res \ No newline at end of file diff --git "a/LeetCode-Python/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" "b/LeetCode-Python/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" new file mode 100644 index 0000000..21bb5b9 --- /dev/null +++ "b/LeetCode-Python/6424.\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227/6424-\345\215\212\346\234\211\345\272\217\346\216\222\345\210\227.py" @@ -0,0 +1,8 @@ +class Solution: + def semiOrderedPermutation(self, nums: List[int]) -> int: + index_1 = nums.index(1) + index_n = nums.index(len(nums)) + if index_1 < index_n: + return index_1 + (len(nums) - 1 - index_n) + else: + return index_1 + (len(nums) - 1 - index_n - 1) \ No newline at end of file diff --git "a/LeetCode-Python/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" "b/LeetCode-Python/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" new file mode 100644 index 0000000..cae0b56 --- /dev/null +++ "b/LeetCode-Python/6462.\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246/6462-\346\234\200\345\260\217\345\214\226\345\255\227\347\254\246\344\270\262\351\225\277\345\272\246.py" @@ -0,0 +1,3 @@ +class Solution: + def minimizedStringLength(self, s: str) -> int: + return len(set(s)) \ No newline at end of file diff --git "a/LeetCode-Python/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" "b/LeetCode-Python/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" new file mode 100644 index 0000000..1f05ad5 --- /dev/null +++ "b/LeetCode-Python/6472.\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214/6472-\346\237\245\350\257\242\345\220\216\347\237\251\351\230\265\347\232\204\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution: + def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int: + visited_rows, visited_cols = set(), set() + res = 0 + for t, index, val in queries[::-1]: + if t == 0: + if index not in visited_rows: + res += val * (n - len(visited_cols)) + visited_rows.add(index) + elif t == 1: + if index not in visited_cols: + res += val * (n - len(visited_rows)) + visited_cols.add(index) + + return res + diff --git "a/LeetCode-Python/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" "b/LeetCode-Python/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" new file mode 100644 index 0000000..71601c2 --- /dev/null +++ "b/LeetCode-Python/LCP 01.\347\214\234\346\225\260\345\255\227/LCP 01-\347\214\234\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def game(self, guess: List[int], answer: List[int]) -> int: + return sum(guess[i] == answer[i] for i in range(3)) \ No newline at end of file diff --git "a/LeetCode-Python/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" "b/LeetCode-Python/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" new file mode 100644 index 0000000..303f35f --- /dev/null +++ "b/LeetCode-Python/LCP 17.\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272/LCP 17-\351\200\237\347\256\227\346\234\272\345\231\250\344\272\272.py" @@ -0,0 +1,10 @@ +class Solution: + def calculate(self, s: str) -> int: + x, y = 1, 0 + + for char in s: + if char == "A": + x = 2 * x + y + else: + y = 2 * y + x + return x + y \ No newline at end of file diff --git "a/LeetCode-Python/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" "b/LeetCode-Python/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" new file mode 100644 index 0000000..4205610 --- /dev/null +++ "b/LeetCode-Python/LCP 44.\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253/LCP 44-\345\274\200\345\271\225\345\274\217\347\204\260\347\201\253.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None +class Solution: + def numColor(self, root: TreeNode) -> int: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + return len(set(inorder(root))) \ No newline at end of file diff --git "a/LeetCode-Python/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" "b/LeetCode-Python/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" new file mode 100644 index 0000000..3e9157b --- /dev/null +++ "b/LeetCode-Python/LCP 66.\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217/LCP 66-\346\234\200\345\260\217\345\261\225\345\217\260\346\225\260\351\207\217.py" @@ -0,0 +1,11 @@ +class Solution: + def minNumBooths(self, demands: List[str]) -> int: + from collections import defaultdict, Counter + char2count = defaultdict(int) + for demand in demands: + c = Counter(demand) + + for char, freq in c.items(): + char2count[char] = max(char2count[char], freq) + + return sum(freq for freq in char2count.values()) \ No newline at end of file diff --git "a/LeetCode-Python/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" "b/LeetCode-Python/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" new file mode 100644 index 0000000..0e7a995 --- /dev/null +++ "b/LeetCode-Python/LCP 67.\350\243\205\351\245\260\346\240\221/LCP 67-\350\243\205\351\245\260\346\240\221.py" @@ -0,0 +1,26 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def expandBinaryTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: + + def dfs(node): + if not node: + return node + + left, right = node.left, node.right + if left: + node.left = TreeNode(-1, left) + + if right: + node.right = TreeNode(-1, None, right) + + dfs(left) + dfs(right) + return node + + return dfs(root) + \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..6104d25 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,8 @@ +class Solution: + def findRepeatNumber(self, nums: List[int]) -> int: + for i, num in enumerate(nums): + if num != i: + if nums[num] == num: + return num + nums[i], nums[num] = nums[num], nums[i] + return nums[-1] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" new file mode 100644 index 0000000..3e2d3c9 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" @@ -0,0 +1,3 @@ +class Solution: + def replaceSpace(self, s: str) -> str: + return s.replace(" ", "%20") \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" new file mode 100644 index 0000000..cd554da --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" @@ -0,0 +1,14 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def reversePrint(self, head: ListNode) -> List[int]: + res = [] + p = head + while p: + res.append(p.val) + p = p.next + return res[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" new file mode 100644 index 0000000..1b49137 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" @@ -0,0 +1,23 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getKthFromEnd(self, head: ListNode, k: int) -> ListNode: + l = 0 + p = head + while p: + l += 1 + p = p.next + + count = l - k + 1 + p = head + while 1: + count -= 1 + if count == 0: + break + p = p.next + + return p \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" new file mode 100644 index 0000000..5d79dfc --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" @@ -0,0 +1,15 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def mirrorTree(self, root: TreeNode) -> TreeNode: + if not root: + return root + root.left, root.right = root.right, root.left + self.mirrorTree(root.left) + self.mirrorTree(root.right) + return root \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" new file mode 100644 index 0000000..819027c --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" @@ -0,0 +1,32 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): + self.val = int(x) + self.next = next + self.random = random +""" +class Solution: + def copyRandomList(self, head: 'Node') -> 'Node': + if not head: + return head + + old2new = dict() + p = head + while p: + cur_node = p + new_node = Node(cur_node.val) + old2new[cur_node] = new_node + p = p.next + + p = head + while p: + cur_node = p + new_node = old2new[cur_node] + + if cur_node.next: + new_node.next = old2new[cur_node.next] + if cur_node.random: + new_node.random = old2new[cur_node.random] + p = p.next + return old2new[head] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" new file mode 100644 index 0000000..0513a62 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution: + def nthUglyNumber(self, n: int) -> int: + import heapq + + min_heap = [1] # find the smallest ugly number + visited = set() + cnt = n + while cnt: + cur = heappop(min_heap) + cnt -= 1 + if not cnt: + return cur + for multiple in [2, 3, 5]: + nxt = cur * multiple + if nxt not in visited: + visited.add(nxt) + heappush(min_heap, nxt) \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" new file mode 100644 index 0000000..49c593f --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" @@ -0,0 +1,22 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + if not headA or not headB: + return None + + pa, pb = headA, headB + while pa != pb: + if pa: + pa = pa.next + else: + pa = headB + if pb: + pb = pb.next + else: + pb = headA + return pa \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" new file mode 100644 index 0000000..df2d2ae --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" @@ -0,0 +1,25 @@ +class Solution: + def search(self, nums: List[int], target: int) -> int: + # return nums.count(target) + # 1. find the left-most index + left, right = 0, len(nums) - 1 + left_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] >= target: + left_index = mid + right = mid - 1 + else: + left = mid + 1 + # 2. find the right-most index + left, right = 0, len(nums) - 1 + right_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] <= target: + right_index = mid + left = mid + 1 + else: + right = mid - 1 + + return right_index - left_index + 1 if left_index > -1 else 0 \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" new file mode 100644 index 0000000..4760d38 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def kthLargest(self, root: TreeNode, k: int) -> int: + self.count = 0 + self.res = 0 + def inorder(node): + if not node: + return + + inorder(node.right) + self.count += 1 + if self.count == k: + self.res = node.val + + inorder(node.left) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" new file mode 100644 index 0000000..4fde3bf --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def maxDepth(self, root: TreeNode) -> int: + if not root: + return 0 + queue = [root] + depth = 0 + while queue: + next_queue = [] + depth += 1 + for node in queue: + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + queue = next_queue[:] + return depth \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" new file mode 100644 index 0000000..4b5917d --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" @@ -0,0 +1,12 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + for i, num in enumerate(nums): + left, right = i + 1, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] == target - num: + return [num, target - num] + elif nums[mid] < target - num: + left = mid + 1 + else: + right = mid - 1 \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..e065bdf --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,3 @@ +class Solution: + def reverseLeftWords(self, s: str, n: int) -> str: + return s[n:] + s[:n] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" new file mode 100644 index 0000000..f39339c --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" @@ -0,0 +1,3 @@ +class Solution: + def sumNums(self, n: int) -> int: + return (n ** 2 + n) >> 1 \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..64b9513 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def singleNumber(self, nums: List[int]) -> int: + return reduce(lambda x, y: x ^ y, nums) \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..17d2a7f --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,7 @@ +class Solution: + def twoSum(self, numbers: List[int], target: int) -> List[int]: + num2index = dict() + for index, num in enumerate(numbers): + if target - num in num2index: + return [num2index[target - num], index] + num2index[num] = index \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" new file mode 100644 index 0000000..c26b8dd --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" @@ -0,0 +1,5 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + s = "".join([char.lower() for char in s if char.isalpha() or char.isdigit()]) + print(s) + return s == s[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" new file mode 100644 index 0000000..90330a6 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" @@ -0,0 +1,20 @@ +class Solution: + def validPalindrome(self, s: str) -> bool: + delete = False + left, right = 0, len(s) - 1 + + while left < right: + if s[left] != s[right]: + if not delete: + delete = True + break + left += 1 + right -= 1 + + if delete: + s1 = s[:left] + s[left + 1:] + s2 = s[:right] + s[right + 1:] + return s1 == s1[::-1] or s2 == s2[::-1] + else: + return True + \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" new file mode 100644 index 0000000..1e17d1e --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" @@ -0,0 +1,37 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + la, lb = 0, 0 + p = headA + while p: + la += 1 + p = p.next + + p = headB + while p: + lb += 1 + p = p.next + + if la > lb: + headA, headB = headB, headA + la, lb = lb, la + + diff = lb - la + pa, pb = headA, headB + while diff: + pb = pb.next + diff -= 1 + + while pa and pb: + if pa == pb: + return pa + else: + pa = pa.next + pb = pb.next + + return None diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" new file mode 100644 index 0000000..bac3cc1 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" @@ -0,0 +1,19 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + # if not head or not head.next: + # return head + # tmp = self.reverseList(head.next) + # head.next.next = head + # head.next = None + # return tmp + prev, cur = None, head + while cur: + next_node = cur.next + cur.next = prev + prev, cur = cur, next_node + return prev \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" new file mode 100644 index 0000000..0a80846 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" @@ -0,0 +1,4 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + from collections import Counter + return s != t and Counter(s) == Counter(t) \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" new file mode 100644 index 0000000..a926627 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" @@ -0,0 +1,22 @@ +import math +class Solution: + def evalRPN(self, tokens: List[str]) -> int: + num_stack = [] + + res = 0 + for token in tokens: + # print(num_stack) + if token[-1].isdigit(): + num_stack.append(int(token)) + else: + second, first = num_stack.pop(), num_stack.pop() + if token == "+": + num_stack.append(first + second) + elif token == "-": + num_stack.append(first - second) + elif token == "*": + num_stack.append(first * second) + elif token == "/": + num_stack.append(int(first / second)) + + return num_stack[0] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" new file mode 100644 index 0000000..25240ec --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" @@ -0,0 +1,11 @@ +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + res = [0] * len(temperatures) + stack = [] # store index into this stack + for i, temp in enumerate(temperatures): + while stack and temperatures[stack[-1]] < temp: + last_index = stack[-1] + res[last_index] = i - last_index + stack.pop() + stack.append(i) + return res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..abc928a --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def largestValues(self, root: TreeNode) -> List[int]: + queue = [root] + res = [] + + while queue: + next_queue = [] + max_val = float("-inf") + for node in queue: + if node: + max_val = max(max_val, node.val) + next_queue.extend([node.left, node.right]) + + queue = next_queue + if max_val != float("-inf"): + res.append(max_val) + + return res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" new file mode 100644 index 0000000..4f44c52 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findBottomLeftValue(self, root: TreeNode) -> int: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res[-1][0] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..89118a0 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumNumbers(self, root: TreeNode) -> int: + self.res = False + self.res = 0 + def dfs(node, path_sum): + if not node: + return + + path_sum = path_sum * 10 + node.val + if not node.left and not node.right: + self.res += path_sum + + dfs(node.left, path_sum) + dfs(node.right, path_sum) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..490aa9d --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def increasingBST(self, root: TreeNode) -> TreeNode: + + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + inorder_list = inorder(root) + + dummy = TreeNode(-1) + p = dummy + for val in inorder_list: + p.right = TreeNode(val) + p = p.right + + return dummy.right diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" new file mode 100644 index 0000000..c18fff9 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def inorderSuccessor(self, root: TreeNode, p: TreeNode) -> Optional[TreeNode]: + # find the next node after p + if not root: + return None + if p.val >= root.val: + return self.inorderSuccessor(root.right, p) + else: + return self.inorderSuccessor(root.left, p) or root + \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" new file mode 100644 index 0000000..a4313b7 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" @@ -0,0 +1,46 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def convertBST(self, root: TreeNode) -> TreeNode: + +# def inOrderGetSum(node): +# if not node: +# return 0 +# return node.val + inOrderGetSum(node.left) + inOrderGetSum(node.right) + +# self.cur_sum = 0 +# def inOrderSetVal(node, total_sum): +# if not node: +# return 0 + +# original_node_val = node.val +# inOrderSetVal(node.left, total_sum) +# node.val = total_sum - self.cur_sum +# self.cur_sum += original_node_val +# right_subtree_sum = inOrderSetVal(node.right, total_sum) + + +# total_sum = inOrderGetSum(root) +# inOrderSetVal(root, total_sum) +# return root + + +class Solution: + def convertBST(self, root: TreeNode) -> TreeNode: + # right - root - left + self.cur_sum = 0 + def reverseInorder(node): + if not node: + return + + reverseInorder(node.right) + self.cur_sum += node.val + node.val = self.cur_sum + reverseInorder(node.left) + + reverseInorder(root) + return root diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" new file mode 100644 index 0000000..be2e409 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" @@ -0,0 +1,29 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class BSTIterator: + def __init__(self, root: TreeNode): + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + self.inorder = inorder(root) + self.index = 0 + + def next(self) -> int: + self.index += 1 + return self.inorder[self.index - 1] + + def hasNext(self) -> bool: + return self.index < len(self.inorder) + + + +# Your BSTIterator object will be instantiated and called as such: +# obj = BSTIterator(root) +# param_1 = obj.next() +# param_2 = obj.hasNext() \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" new file mode 100644 index 0000000..defd4cd --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: TreeNode, k: int) -> bool: + visited = set() + self.res = False + + def inorder(node): + if not node: + return + + inorder(node.left) + + if k - node.val in visited: + self.res = True + visited.add(node.val) + + if not self.res: + inorder(node.right) + + inorder(root) + return self.res + diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" new file mode 100644 index 0000000..e4f70e2 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" @@ -0,0 +1,22 @@ +class KthLargest: + + def __init__(self, k: int, nums: List[int]): + self.k = k + self.min_heap = [] + for num in nums: + if len(self.min_heap) < k: + heappush(self.min_heap, num) + else: + heappushpop(self.min_heap, num) + + def add(self, val: int) -> int: + if len(self.min_heap) < self.k: + heappush(self.min_heap, val) + else: + heappushpop(self.min_heap, val) + return self.min_heap[0] + + +# Your KthLargest object will be instantiated and called as such: +# obj = KthLargest(k, nums) +# param_1 = obj.add(val) \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" new file mode 100644 index 0000000..a27164b --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" @@ -0,0 +1,20 @@ +from collections import Counter +from heapq import * +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + c = Counter(nums) + # return sorted(set(nums), key = lambda x: -c[x])[:k] + heap_set = set() + min_heap = [] + for num in nums: + if num not in heap_set: + heap_set.add(num) + if len(min_heap) < k: + heappush(min_heap, (c[num], num)) + else: + heappushpop(min_heap, (c[num], num)) + # print(min_heap) + res = [] + while min_heap: + res.append(heappop(min_heap)[1]) + return res diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" new file mode 100644 index 0000000..e013042 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" @@ -0,0 +1,13 @@ +class Solution: + def peakIndexInMountainArray(self, arr: List[int]) -> int: + left, right = 0, len(arr) - 1 + while left <= right: + mid = (left + right) // 2 + if 0 < mid < len(arr) - 1 and arr[mid - 1] < arr[mid] and arr[mid] > arr[mid + 1]: + return mid + + if arr[mid + 1] > arr[mid]: + left = mid + 1 + else: + right = mid - 1 + return left \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..ab926ec --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def findKthLargest(self, nums: List[int], k: int) -> int: + return sorted(nums)[::-1][k - 1] \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" new file mode 100644 index 0000000..52471ac --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" @@ -0,0 +1,9 @@ +class Solution: + def subsets(self, nums: List[int]) -> List[List[int]]: + res = [[]] + for num in nums: + new_res = [] + for subset in res: + new_res.append(subset + [num]) + res += new_res + return res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" new file mode 100644 index 0000000..a9d570a --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [] + def dfs(tmp, nums): + if not nums: + res.append(tmp) + + for i, x in enumerate(nums): + dfs(tmp + [x], nums[:i] + nums[i + 1:]) + + dfs([], nums) + return res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 0000000..1b94ac9 --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,14 @@ +class Solution: + def generateParenthesis(self, n: int) -> List[str]: + res = [] + def dfs(left, right, tmp): + if left == 0 and right == 0: + res.append(tmp) + return + if left > 0: + dfs(left - 1, right, tmp + "(") + if right > left: + dfs(left, right - 1, tmp + ")") + + dfs(n, n, "") + return res \ No newline at end of file diff --git "a/LeetCode-Python/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" new file mode 100644 index 0000000..160e3de --- /dev/null +++ "b/LeetCode-Python/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" @@ -0,0 +1,15 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + record = dict() + res = 0 + for num in nums: + if num not in record: + left = record.get(num - 1, 0) + right = record.get(num + 1, 0) + + length = right + left + 1 + res = max(res, length) + for i in [num - left, num, num + right]: + record[i] = length + + return res diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" new file mode 100644 index 0000000..ea48c15 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" @@ -0,0 +1,3 @@ +class Solution: + def isUnique(self, astr: str) -> bool: + return len(set(astr)) == len(astr) \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" new file mode 100644 index 0000000..fa4e693 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" @@ -0,0 +1,4 @@ +class Solution: + def CheckPermutation(self, s1: str, s2: str) -> bool: + from collections import Counter + return Counter(s1) == Counter(s2) \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" new file mode 100644 index 0000000..54f13bd --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" @@ -0,0 +1,3 @@ +class Solution: + def replaceSpaces(self, S: str, length: int) -> str: + return S[:length].replace(" ", "%20") \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" new file mode 100644 index 0000000..8b2a31f --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" @@ -0,0 +1,10 @@ +class Solution: + def canPermutePalindrome(self, s: str) -> bool: + from collections import Counter + odd = False + for char, freq in Counter(s).items(): + if freq % 2: + if odd: + return False + odd = True + return True \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" new file mode 100644 index 0000000..a08b996 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" @@ -0,0 +1,14 @@ +class Solution: + def compressString(self, S: str) -> str: + res = "" + index = 0 + while index < len(S): + count = 1 + char = S[index] + while index + 1 < len(S) and S[index] == S[index + 1]: + index += 1 + count += 1 + res += char + str(count) + index += 1 + + return res if len(res) < len(S) else S \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" new file mode 100644 index 0000000..6ff3d39 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" @@ -0,0 +1,14 @@ +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + n = len(matrix) + for i in range(n): + for j in range(i + 1, n): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + + for i in range(n): + row = matrix[i] + for j in range(n // 2): + row[j], row[-(j + 1)] = row[-(j + 1)], row[j] \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" new file mode 100644 index 0000000..1834034 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" @@ -0,0 +1,23 @@ +class Solution: + def setZeroes(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + + row_zero, col_zero = set(), set() + + for i in range(len(matrix)): + for j in range(len(matrix[0])): + if not matrix[i][j]: + row_zero.add(i) + col_zero.add(j) + + for row_index in row_zero: + matrix[row_index] = [0] * len(matrix[0]) + + for col_index in col_zero: + for i in range(len(matrix)): + matrix[i][col_index] = 0 + + + \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" new file mode 100644 index 0000000..4616e7f --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" @@ -0,0 +1,5 @@ +class Solution: + def isFlipedString(self, s1: str, s2: str) -> bool: + if not s2: + return not s1 + return s2 in s1 + s1 \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" new file mode 100644 index 0000000..d6fdf7a --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" @@ -0,0 +1,39 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def removeDuplicateNodes(self, head: ListNode) -> ListNode: + # if not head or not head.next: + # return head + + # dummy = ListNode(-1) + # prev, cur = dummy, head + # dummy.next = cur + # while cur: + # p_find_duplicate = head + # while p_find_duplicate: + # if p_find_duplicate.val == cur.val: + # break + # p_find_duplicate = p_find_duplicate.next + # if p_find_duplicate and p_find_duplicate!= cur: + # prev.next = cur.next + # cur = cur.next + # else: + # prev, cur = cur, cur.next + # return head + if not head: + return head + visited = {head.val} + p = head + while p.next: + cur = p.next + if cur.val not in visited: + visited.add(cur.val) + p = p.next + else: + p.next = p.next.next + return head + diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" new file mode 100644 index 0000000..f21ff9c --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" @@ -0,0 +1,23 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def kthToLast(self, head: ListNode, k: int) -> int: + l = 0 + p = head + while p: + l += 1 + p = p.next + + count = l - k + 1 + p = head + while 1: + count -= 1 + if count == 0: + break + p = p.next + + return p.val \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" new file mode 100644 index 0000000..d15d8ae --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" @@ -0,0 +1,19 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def deleteNode(self, node): + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + p = node + while p and p.next: + p.val = p.next.val + if not p.next.next: + p.next = None + break + p = p.next \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" new file mode 100644 index 0000000..068ad14 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def partition(self, head: ListNode, x: int) -> ListNode: + dummy1, dummy2 = ListNode(-1), ListNode(-2) + + smaller, larger = dummy1, dummy2 + p = head + while p: + if p.val < x: + smaller.next = ListNode(p.val) + smaller = smaller.next + else: + larger.next = ListNode(p.val) + larger = larger.next + + p = p.next + + smaller.next = dummy2.next + return dummy1.next \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" new file mode 100644 index 0000000..70f930c --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" @@ -0,0 +1,59 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: + if not l1 and not l2: + return l1 + if not l1: + return l2 + if not l2: + return l1 + + p1, p2 = l1, l2 + carry = 0 + dummy = ListNode(-1) + p = dummy + while l1 and l2: + s = l1.val + l2.val + carry + l1 = l1.next + l2 = l2.next + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + + p.next = ListNode(s) + p = p.next + + while l1: + s = l1.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l1 = l1.next + p.next = ListNode(s) + p = p.next + + while l2: + s = l2.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l2 = l2.next + p.next = ListNode(s) + p = p.next + + if carry: + p.next = ListNode(1) + return dummy.next + + \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" new file mode 100644 index 0000000..654d1c5 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def isPalindrome(self, head: ListNode) -> bool: + p = head + l = [] + while p: + l.append(p.val) + p = p.next + return l == l[::-1] \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" new file mode 100644 index 0000000..f174760 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" @@ -0,0 +1,36 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + pa, pb = headA, headB + if not headA or not headB: + return None + + la, lb = 0, 0 + while pa: + la += 1 + pa = pa.next + while pb: + lb += 1 + pb = pb.next + + if la < lb: + headA, headB = headB, headA + la, lb = lb, la + + diff = la - lb + pa = headA + while diff: + pa = pa.next + diff -= 1 + + pb = headB + while pa and pb and pa != pb: + pa = pa.next + pb = pb.next + + return pa if pa == pb else None \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" new file mode 100644 index 0000000..c6abf6f --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def detectCycle(self, head: ListNode) -> ListNode: + if not head or not head.next: + return None + slow, fast = head, head + + while fast and fast.next: + slow = slow.next + fast = fast.next.next + + if slow == fast: + break + + if slow != fast: + return None + + fast = head + while fast != slow: + slow = slow.next + fast = fast.next + + return fast \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" new file mode 100644 index 0000000..b26eec1 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" @@ -0,0 +1,35 @@ +class MinStack: + + def __init__(self): + """ + initialize your data structure here. + """ + self.stack = [] + self.min_stack = [] + + def push(self, x: int) -> None: + self.stack.append(x) + if self.min_stack: + self.min_stack.append(min(self.min_stack[-1], x)) + else: + self.min_stack.append(x) + + def pop(self) -> None: + self.stack.pop() + self.min_stack.pop() + + def top(self) -> int: + return self.stack[-1] + + + def getMin(self) -> int: + return self.min_stack[-1] + + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(x) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" new file mode 100644 index 0000000..5443d3f --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" @@ -0,0 +1,27 @@ +from collections import * +class Solution: + def findWhetherExistsPath(self, n: int, graph: List[List[int]], start: int, target: int) -> bool: + src2des = defaultdict(list) + + for pair in graph: + src, des = pair[0], pair[1] + src2des[src].append(des) + + # BFS + queue = deque([start]) + visited = {start} + while queue: + cur = queue.popleft() + if cur == target: + return True + + for node in src2des[cur]: + if node not in visited: + queue.append(node) + visited.add(node) + + return False + + + + diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" new file mode 100644 index 0000000..cca5452 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def sortedArrayToBST(self, nums: List[int]) -> TreeNode: + if not nums: + return None + mid = len(nums) // 2 + root = TreeNode(nums[mid], self.sortedArrayToBST(nums[:mid]), self.sortedArrayToBST(nums[mid + 1:])) + return root \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" new file mode 100644 index 0000000..8bb57fa --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" @@ -0,0 +1,32 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def listOfDepth(self, tree: TreeNode) -> List[ListNode]: + queue = [tree] + res = [] + + while queue: + next_queue = [] + cur_level = ListNode(-1) + p = cur_level + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + p.next = ListNode(node.val) + p = p.next + + if cur_level != p: + res.append(cur_level.next) + queue = next_queue + return res \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" new file mode 100644 index 0000000..e357a5e --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def isBalanced(self, root: TreeNode) -> bool: + if not root or (not root.left and not root.right): + return True + + def getHeight(node): + if not node: + return 0 + return 1 + max(getHeight(node.left), getHeight(node.right)) + + if abs(getHeight(root.left) - getHeight(root.right)) > 1: + return False + return self.isBalanced(root.left) and self.isBalanced(root.right) diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..f7917a0 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def isValidBST(self, root: TreeNode) -> bool: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + l = inorder(root) + return l == sorted(l) and len(l) == len(set(l)) \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" new file mode 100644 index 0000000..b395f1d --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def inorderSuccessor(self, root: TreeNode, p: TreeNode) -> TreeNode: + self.res = None + def inorder(node): + if not node: + return + + inorder(node.left) + if not self.res and node.val > p.val: + self.res = node + return + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" new file mode 100644 index 0000000..92c38d7 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" @@ -0,0 +1,8 @@ +class Solution: + def waysToStep(self, n: int) -> int: + dp = [0] * (max(10, n + 1)) + MOD = 10 ** 9 + 7 + dp[1], dp[2], dp[3] = 1, 2, 4 + for i in range(4, n + 1): + dp[i] = (dp[i - 1] + dp[i - 2] + dp[i - 3]) % MOD + return dp[n] \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" new file mode 100644 index 0000000..00aeb6f --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" @@ -0,0 +1,30 @@ +from collections import deque +class Solution: + def pathWithObstacles(self, obstacleGrid: List[List[int]]) -> List[List[int]]: + if not obstacleGrid or not obstacleGrid[0] or obstacleGrid[0][0] == 1: + return [] + m, n = len(obstacleGrid), len(obstacleGrid[0]) + if obstacleGrid[m -1][n - 1] == 1: + return [] + + self.res = [] + # dfs + visited = set([(0, 0)]) + def dfs(i, j, path): + if not 0 <= i < m or not 0 <= j < n: + return + path.append([i, j]) + if i == m - 1 and j == n - 1: + self.res = path[:] + return + if not self.res: + if i + 1 < m and obstacleGrid[i + 1][j] != 1 and (i + 1, j) not in visited: + visited.add((i + 1, j)) + dfs(i + 1, j, path[:]) + if j + 1 < n and obstacleGrid[i][j + 1] != 1 and (i, j + 1) not in visited: + visited.add((i, j + 1)) + dfs(i, j + 1, path[:]) + dfs(0, 0, []) + return self.res + + \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" new file mode 100644 index 0000000..793972a --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" @@ -0,0 +1,6 @@ +class Solution: + def findMagicIndex(self, nums: List[int]) -> int: + for i, num in enumerate(nums): + if i == num: + return i + return -1 \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" new file mode 100644 index 0000000..2acc5a1 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" @@ -0,0 +1,7 @@ +class Solution: + def multiply(self, A: int, B: int) -> int: + if B == 1: + return A + if B == 0: + return 0 + return A + self.multiply(A, B - 1) \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" new file mode 100644 index 0000000..3488b03 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" @@ -0,0 +1,9 @@ +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + from collections import defaultdict + + d = defaultdict(list) + for word in strs: + d["".join(sorted(word))].append(word) + + return [val for key, val in d.items()] \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" new file mode 100644 index 0000000..7fb10f6 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def swapNumbers(self, numbers: List[int]) -> List[int]: + return [numbers[1], numbers[0]] \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" new file mode 100644 index 0000000..5c7be33 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" @@ -0,0 +1,14 @@ +from collections import Counter +class WordsFrequency: + + def __init__(self, book: List[str]): + self.word2freq = Counter(book) + + def get(self, word: str) -> int: + return self.word2freq[word] + + + +# Your WordsFrequency object will be instantiated and called as such: +# obj = WordsFrequency(book) +# param_1 = obj.get(word) \ No newline at end of file diff --git "a/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" new file mode 100644 index 0000000..22f9611 --- /dev/null +++ "b/LeetCode-Python/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" @@ -0,0 +1,3 @@ +class Solution: + def maximum(self, a: int, b: int) -> int: + return sorted([a, b])[-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..6104d25 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 03.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 03-\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,8 @@ +class Solution: + def findRepeatNumber(self, nums: List[int]) -> int: + for i, num in enumerate(nums): + if num != i: + if nums[num] == num: + return num + nums[i], nums[num] = nums[num], nums[i] + return nums[-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" "b/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" new file mode 100644 index 0000000..3e2d3c9 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207 Offer 05-\346\233\277\346\215\242\347\251\272\346\240\274.py" @@ -0,0 +1,3 @@ +class Solution: + def replaceSpace(self, s: str) -> str: + return s.replace(" ", "%20") \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" new file mode 100644 index 0000000..cd554da --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 06.\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/\345\211\221\346\214\207 Offer 06-\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.py" @@ -0,0 +1,14 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def reversePrint(self, head: ListNode) -> List[int]: + res = [] + p = head + while p: + res.append(p.val) + p = p.next + return res[::-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" new file mode 100644 index 0000000..1b49137 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 22.\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 22-\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271.py" @@ -0,0 +1,23 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getKthFromEnd(self, head: ListNode, k: int) -> ListNode: + l = 0 + p = head + while p: + l += 1 + p = p.next + + count = l - k + 1 + p = head + while 1: + count -= 1 + if count == 0: + break + p = p.next + + return p \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" "b/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" new file mode 100644 index 0000000..5d79dfc --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207 Offer 27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" @@ -0,0 +1,15 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def mirrorTree(self, root: TreeNode) -> TreeNode: + if not root: + return root + root.left, root.right = root.right, root.left + self.mirrorTree(root.left) + self.mirrorTree(root.right) + return root \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" "b/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" new file mode 100644 index 0000000..819027c --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 35.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\345\211\221\346\214\207 Offer 35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" @@ -0,0 +1,32 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): + self.val = int(x) + self.next = next + self.random = random +""" +class Solution: + def copyRandomList(self, head: 'Node') -> 'Node': + if not head: + return head + + old2new = dict() + p = head + while p: + cur_node = p + new_node = Node(cur_node.val) + old2new[cur_node] = new_node + p = p.next + + p = head + while p: + cur_node = p + new_node = old2new[cur_node] + + if cur_node.next: + new_node.next = old2new[cur_node.next] + if cur_node.random: + new_node.random = old2new[cur_node.random] + p = p.next + return old2new[head] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" "b/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" new file mode 100644 index 0000000..0513a62 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 49.\344\270\221\346\225\260/\345\211\221\346\214\207 Offer 49-\344\270\221\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution: + def nthUglyNumber(self, n: int) -> int: + import heapq + + min_heap = [1] # find the smallest ugly number + visited = set() + cnt = n + while cnt: + cur = heappop(min_heap) + cnt -= 1 + if not cnt: + return cur + for multiple in [2, 3, 5]: + nxt = cur * multiple + if nxt not in visited: + visited.add(nxt) + heappush(min_heap, nxt) \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" new file mode 100644 index 0000000..49c593f --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 52.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 52-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\350\212\202\347\202\271.py" @@ -0,0 +1,22 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + if not headA or not headB: + return None + + pa, pb = headA, headB + while pa != pb: + if pa: + pa = pa.next + else: + pa = headB + if pb: + pb = pb.next + else: + pb = headA + return pa \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" "b/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" new file mode 100644 index 0000000..df2d2ae --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 53 - I.\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I/\345\211\221\346\214\207 Offer 53 - I-\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\346\225\260\345\255\227I.py" @@ -0,0 +1,25 @@ +class Solution: + def search(self, nums: List[int], target: int) -> int: + # return nums.count(target) + # 1. find the left-most index + left, right = 0, len(nums) - 1 + left_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] >= target: + left_index = mid + right = mid - 1 + else: + left = mid + 1 + # 2. find the right-most index + left, right = 0, len(nums) - 1 + right_index = -1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] <= target: + right_index = mid + left = mid + 1 + else: + right = mid - 1 + + return right_index - left_index + 1 if left_index > -1 else 0 \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" new file mode 100644 index 0000000..4760d38 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 54.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/\345\211\221\346\214\207 Offer 54-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def kthLargest(self, root: TreeNode, k: int) -> int: + self.count = 0 + self.res = 0 + def inorder(node): + if not node: + return + + inorder(node.right) + self.count += 1 + if self.count == k: + self.res = node.val + + inorder(node.left) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" "b/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" new file mode 100644 index 0000000..4fde3bf --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 55 - I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207 Offer 55 - I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def maxDepth(self, root: TreeNode) -> int: + if not root: + return 0 + queue = [root] + depth = 0 + while queue: + next_queue = [] + depth += 1 + for node in queue: + if node.left: + next_queue.append(node.left) + if node.right: + next_queue.append(node.right) + queue = next_queue[:] + return depth \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" new file mode 100644 index 0000000..4b5917d --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 57.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer 57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" @@ -0,0 +1,12 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + for i, num in enumerate(nums): + left, right = i + 1, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] == target - num: + return [num, target - num] + elif nums[mid] < target - num: + left = mid + 1 + else: + right = mid - 1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" "b/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..e065bdf --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 58 - II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207 Offer 58 - II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,3 @@ +class Solution: + def reverseLeftWords(self, s: str, n: int) -> str: + return s[n:] + s[:n] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" "b/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" new file mode 100644 index 0000000..f39339c --- /dev/null +++ "b/\345\211\221\346\214\207 Offer 64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207 Offer 64-\346\261\2021+2+\342\200\246+n.py" @@ -0,0 +1,3 @@ +class Solution: + def sumNums(self, n: int) -> int: + return (n ** 2 + n) >> 1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..64b9513 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 004.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 004-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def singleNumber(self, nums: List[int]) -> int: + return reduce(lambda x, y: x ^ y, nums) \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..17d2a7f --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 006.\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 006-\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\344\270\244\344\270\252\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,7 @@ +class Solution: + def twoSum(self, numbers: List[int], target: int) -> List[int]: + num2index = dict() + for index, num in enumerate(numbers): + if target - num in num2index: + return [num2index[target - num], index] + num2index[num] = index \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" "b/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" new file mode 100644 index 0000000..c26b8dd --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 018.\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 018-\346\234\211\346\225\210\347\232\204\345\233\236\346\226\207.py" @@ -0,0 +1,5 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + s = "".join([char.lower() for char in s if char.isalpha() or char.isdigit()]) + print(s) + return s == s[::-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" "b/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" new file mode 100644 index 0000000..90330a6 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 019.\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207/\345\211\221\346\214\207 Offer II 019-\346\234\200\345\244\232\345\210\240\351\231\244\344\270\200\344\270\252\345\255\227\347\254\246\345\276\227\345\210\260\345\233\236\346\226\207.py" @@ -0,0 +1,20 @@ +class Solution: + def validPalindrome(self, s: str) -> bool: + delete = False + left, right = 0, len(s) - 1 + + while left < right: + if s[left] != s[right]: + if not delete: + delete = True + break + left += 1 + right -= 1 + + if delete: + s1 = s[:left] + s[left + 1:] + s2 = s[:right] + s[right + 1:] + return s1 == s1[::-1] or s2 == s2[::-1] + else: + return True + \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" new file mode 100644 index 0000000..1e17d1e --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 023.\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271/\345\211\221\346\214\207 Offer II 023-\344\270\244\344\270\252\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\351\207\215\345\220\210\350\212\202\347\202\271.py" @@ -0,0 +1,37 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + la, lb = 0, 0 + p = headA + while p: + la += 1 + p = p.next + + p = headB + while p: + lb += 1 + p = p.next + + if la > lb: + headA, headB = headB, headA + la, lb = lb, la + + diff = lb - la + pa, pb = headA, headB + while diff: + pb = pb.next + diff -= 1 + + while pa and pb: + if pa == pb: + return pa + else: + pa = pa.next + pb = pb.next + + return None diff --git "a/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" new file mode 100644 index 0000000..bac3cc1 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 024.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207 Offer II 024-\345\217\215\350\275\254\351\223\276\350\241\250.py" @@ -0,0 +1,19 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + # if not head or not head.next: + # return head + # tmp = self.reverseList(head.next) + # head.next.next = head + # head.next = None + # return tmp + prev, cur = None, head + while cur: + next_node = cur.next + cur.next = prev + prev, cur = cur, next_node + return prev \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" "b/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" new file mode 100644 index 0000000..0a80846 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 032.\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215/\345\211\221\346\214\207 Offer II 032-\346\234\211\346\225\210\347\232\204\345\217\230\344\275\215\350\257\215.py" @@ -0,0 +1,4 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + from collections import Counter + return s != t and Counter(s) == Counter(t) \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" "b/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" new file mode 100644 index 0000000..a926627 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 036.\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217/\345\211\221\346\214\207 Offer II 036-\345\220\216\347\274\200\350\241\250\350\276\276\345\274\217.py" @@ -0,0 +1,22 @@ +import math +class Solution: + def evalRPN(self, tokens: List[str]) -> int: + num_stack = [] + + res = 0 + for token in tokens: + # print(num_stack) + if token[-1].isdigit(): + num_stack.append(int(token)) + else: + second, first = num_stack.pop(), num_stack.pop() + if token == "+": + num_stack.append(first + second) + elif token == "-": + num_stack.append(first - second) + elif token == "*": + num_stack.append(first * second) + elif token == "/": + num_stack.append(int(first / second)) + + return num_stack[0] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" "b/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" new file mode 100644 index 0000000..25240ec --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 038.\346\257\217\346\227\245\346\270\251\345\272\246/\345\211\221\346\214\207 Offer II 038-\346\257\217\346\227\245\346\270\251\345\272\246.py" @@ -0,0 +1,11 @@ +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + res = [0] * len(temperatures) + stack = [] # store index into this stack + for i, temp in enumerate(temperatures): + while stack and temperatures[stack[-1]] < temp: + last_index = stack[-1] + res[last_index] = i - last_index + stack.pop() + stack.append(i) + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..abc928a --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 044.\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207 Offer II 044-\344\272\214\345\217\211\346\240\221\346\257\217\345\261\202\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,24 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def largestValues(self, root: TreeNode) -> List[int]: + queue = [root] + res = [] + + while queue: + next_queue = [] + max_val = float("-inf") + for node in queue: + if node: + max_val = max(max_val, node.val) + next_queue.extend([node.left, node.right]) + + queue = next_queue + if max_val != float("-inf"): + res.append(max_val) + + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" "b/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" new file mode 100644 index 0000000..4f44c52 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 045.\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274/\345\211\221\346\214\207 Offer II 045-\344\272\214\345\217\211\346\240\221\346\234\200\345\272\225\345\261\202\346\234\200\345\267\246\350\276\271\347\232\204\345\200\274.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findBottomLeftValue(self, root: TreeNode) -> int: + queue = [root] + res = [] + + while queue: + next_queue = [] + cur_level = [] + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + cur_level.append(node.val) + + if cur_level: + res.append(cur_level) + queue = next_queue + return res[-1][0] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" "b/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" new file mode 100644 index 0000000..89118a0 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 049.\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 049-\344\273\216\346\240\271\350\212\202\347\202\271\345\210\260\345\217\266\350\212\202\347\202\271\347\232\204\350\267\257\345\276\204\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def sumNumbers(self, root: TreeNode) -> int: + self.res = False + self.res = 0 + def dfs(node, path_sum): + if not node: + return + + path_sum = path_sum * 10 + node.val + if not node.left and not node.right: + self.res += path_sum + + dfs(node.left, path_sum) + dfs(node.right, path_sum) + + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..490aa9d --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 052.\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\345\211\221\346\214\207 Offer II 052-\345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def increasingBST(self, root: TreeNode) -> TreeNode: + + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + inorder_list = inorder(root) + + dummy = TreeNode(-1) + p = dummy + for val in inorder_list: + p.right = TreeNode(val) + p = p.right + + return dummy.right diff --git "a/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" "b/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" new file mode 100644 index 0000000..c18fff9 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 053.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247/\345\211\221\346\214\207 Offer II 053-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\344\270\255\345\272\217\345\220\216\347\273\247.py" @@ -0,0 +1,17 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def inorderSuccessor(self, root: TreeNode, p: TreeNode) -> Optional[TreeNode]: + # find the next node after p + if not root: + return None + if p.val >= root.val: + return self.inorderSuccessor(root.right, p) + else: + return self.inorderSuccessor(root.left, p) or root + \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" "b/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" new file mode 100644 index 0000000..a4313b7 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 054.\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 054-\346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214.py" @@ -0,0 +1,46 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# class Solution: +# def convertBST(self, root: TreeNode) -> TreeNode: + +# def inOrderGetSum(node): +# if not node: +# return 0 +# return node.val + inOrderGetSum(node.left) + inOrderGetSum(node.right) + +# self.cur_sum = 0 +# def inOrderSetVal(node, total_sum): +# if not node: +# return 0 + +# original_node_val = node.val +# inOrderSetVal(node.left, total_sum) +# node.val = total_sum - self.cur_sum +# self.cur_sum += original_node_val +# right_subtree_sum = inOrderSetVal(node.right, total_sum) + + +# total_sum = inOrderGetSum(root) +# inOrderSetVal(root, total_sum) +# return root + + +class Solution: + def convertBST(self, root: TreeNode) -> TreeNode: + # right - root - left + self.cur_sum = 0 + def reverseInorder(node): + if not node: + return + + reverseInorder(node.right) + self.cur_sum += node.val + node.val = self.cur_sum + reverseInorder(node.left) + + reverseInorder(root) + return root diff --git "a/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" "b/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" new file mode 100644 index 0000000..be2e409 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 055.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/\345\211\221\346\214\207 Offer II 055-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250.py" @@ -0,0 +1,29 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class BSTIterator: + def __init__(self, root: TreeNode): + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + self.inorder = inorder(root) + self.index = 0 + + def next(self) -> int: + self.index += 1 + return self.inorder[self.index - 1] + + def hasNext(self) -> bool: + return self.index < len(self.inorder) + + + +# Your BSTIterator object will be instantiated and called as such: +# obj = BSTIterator(root) +# param_1 = obj.next() +# param_2 = obj.hasNext() \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" "b/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" new file mode 100644 index 0000000..defd4cd --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 056.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214/\345\211\221\346\214\207 Offer II 056-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\344\270\244\344\270\252\350\212\202\347\202\271\344\271\213\345\222\214.py" @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def findTarget(self, root: TreeNode, k: int) -> bool: + visited = set() + self.res = False + + def inorder(node): + if not node: + return + + inorder(node.left) + + if k - node.val in visited: + self.res = True + visited.add(node.val) + + if not self.res: + inorder(node.right) + + inorder(root) + return self.res + diff --git "a/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" "b/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" new file mode 100644 index 0000000..e4f70e2 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 059.\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274/\345\211\221\346\214\207 Offer II 059-\346\225\260\346\215\256\346\265\201\347\232\204\347\254\254K\345\244\247\346\225\260\345\200\274.py" @@ -0,0 +1,22 @@ +class KthLargest: + + def __init__(self, k: int, nums: List[int]): + self.k = k + self.min_heap = [] + for num in nums: + if len(self.min_heap) < k: + heappush(self.min_heap, num) + else: + heappushpop(self.min_heap, num) + + def add(self, val: int) -> int: + if len(self.min_heap) < self.k: + heappush(self.min_heap, val) + else: + heappushpop(self.min_heap, val) + return self.min_heap[0] + + +# Your KthLargest object will be instantiated and called as such: +# obj = KthLargest(k, nums) +# param_1 = obj.add(val) \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" new file mode 100644 index 0000000..a27164b --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 060.\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 060-\345\207\272\347\216\260\351\242\221\347\216\207\346\234\200\351\253\230\347\232\204k\344\270\252\346\225\260\345\255\227.py" @@ -0,0 +1,20 @@ +from collections import Counter +from heapq import * +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + c = Counter(nums) + # return sorted(set(nums), key = lambda x: -c[x])[:k] + heap_set = set() + min_heap = [] + for num in nums: + if num not in heap_set: + heap_set.add(num) + if len(min_heap) < k: + heappush(min_heap, (c[num], num)) + else: + heappushpop(min_heap, (c[num], num)) + # print(min_heap) + res = [] + while min_heap: + res.append(heappop(min_heap)[1]) + return res diff --git "a/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" "b/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" new file mode 100644 index 0000000..e013042 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 069.\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250/\345\211\221\346\214\207 Offer II 069-\345\261\261\345\263\260\346\225\260\347\273\204\347\232\204\351\241\266\351\203\250.py" @@ -0,0 +1,13 @@ +class Solution: + def peakIndexInMountainArray(self, arr: List[int]) -> int: + left, right = 0, len(arr) - 1 + while left <= right: + mid = (left + right) // 2 + if 0 < mid < len(arr) - 1 and arr[mid - 1] < arr[mid] and arr[mid] > arr[mid + 1]: + return mid + + if arr[mid + 1] > arr[mid]: + left = mid + 1 + else: + right = mid - 1 + return left \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..ab926ec --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 076.\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207 Offer II 076-\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254k\345\244\247\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def findKthLargest(self, nums: List[int], k: int) -> int: + return sorted(nums)[::-1][k - 1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" "b/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" new file mode 100644 index 0000000..52471ac --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 079.\346\211\200\346\234\211\345\255\220\351\233\206/\345\211\221\346\214\207 Offer II 079-\346\211\200\346\234\211\345\255\220\351\233\206.py" @@ -0,0 +1,9 @@ +class Solution: + def subsets(self, nums: List[int]) -> List[List[int]]: + res = [[]] + for num in nums: + new_res = [] + for subset in res: + new_res.append(subset + [num]) + res += new_res + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" "b/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" new file mode 100644 index 0000000..a9d570a --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 083.\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227/\345\211\221\346\214\207 Offer II 083-\346\262\241\346\234\211\351\207\215\345\244\215\345\205\203\347\264\240\351\233\206\345\220\210\347\232\204\345\205\250\346\216\222\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution: + def permute(self, nums: List[int]) -> List[List[int]]: + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [] + def dfs(tmp, nums): + if not nums: + res.append(tmp) + + for i, x in enumerate(nums): + dfs(tmp + [x], nums[:i] + nums[i + 1:]) + + dfs([], nums) + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" "b/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 0000000..1b94ac9 --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 085.\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267/\345\211\221\346\214\207 Offer II 085-\347\224\237\346\210\220\345\214\271\351\205\215\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,14 @@ +class Solution: + def generateParenthesis(self, n: int) -> List[str]: + res = [] + def dfs(left, right, tmp): + if left == 0 and right == 0: + res.append(tmp) + return + if left > 0: + dfs(left - 1, right, tmp + "(") + if right > left: + dfs(left, right - 1, tmp + ")") + + dfs(n, n, "") + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" new file mode 100644 index 0000000..160e3de --- /dev/null +++ "b/\345\211\221\346\214\207 Offer II 119.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/\345\211\221\346\214\207 Offer II 119-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" @@ -0,0 +1,15 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + record = dict() + res = 0 + for num in nums: + if num not in record: + left = record.get(num - 1, 0) + right = record.get(num + 1, 0) + + length = right + left + 1 + res = max(res, length) + for i in [num - left, num, num + right]: + record[i] = length + + return res diff --git "a/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" "b/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" new file mode 100644 index 0000000..ea48c15 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.01.\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200/\351\235\242\350\257\225\351\242\230 01.01-\345\210\244\345\256\232\345\255\227\347\254\246\346\230\257\345\220\246\345\224\257\344\270\200.py" @@ -0,0 +1,3 @@ +class Solution: + def isUnique(self, astr: str) -> bool: + return len(set(astr)) == len(astr) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" "b/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" new file mode 100644 index 0000000..fa4e693 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.02.\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222/\351\235\242\350\257\225\351\242\230 01.02-\345\210\244\345\256\232\346\230\257\345\220\246\344\272\222\344\270\272\345\255\227\347\254\246\351\207\215\346\216\222.py" @@ -0,0 +1,4 @@ +class Solution: + def CheckPermutation(self, s1: str, s2: str) -> bool: + from collections import Counter + return Counter(s1) == Counter(s2) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" "b/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" new file mode 100644 index 0000000..54f13bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.03.URL\345\214\226/\351\235\242\350\257\225\351\242\230 01.03-URL\345\214\226.py" @@ -0,0 +1,3 @@ +class Solution: + def replaceSpaces(self, S: str, length: int) -> str: + return S[:length].replace(" ", "%20") \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" "b/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" new file mode 100644 index 0000000..8b2a31f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\230 01.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" @@ -0,0 +1,10 @@ +class Solution: + def canPermutePalindrome(self, s: str) -> bool: + from collections import Counter + odd = False + for char, freq in Counter(s).items(): + if freq % 2: + if odd: + return False + odd = True + return True \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" "b/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" new file mode 100644 index 0000000..a08b996 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\230 01.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" @@ -0,0 +1,14 @@ +class Solution: + def compressString(self, S: str) -> str: + res = "" + index = 0 + while index < len(S): + count = 1 + char = S[index] + while index + 1 < len(S) and S[index] == S[index + 1]: + index += 1 + count += 1 + res += char + str(count) + index += 1 + + return res if len(res) < len(S) else S \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" new file mode 100644 index 0000000..6ff3d39 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" @@ -0,0 +1,14 @@ +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + n = len(matrix) + for i in range(n): + for j in range(i + 1, n): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + + for i in range(n): + row = matrix[i] + for j in range(n // 2): + row[j], row[-(j + 1)] = row[-(j + 1)], row[j] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" new file mode 100644 index 0000000..1834034 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\230 01.08-\351\233\266\347\237\251\351\230\265.py" @@ -0,0 +1,23 @@ +class Solution: + def setZeroes(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + + row_zero, col_zero = set(), set() + + for i in range(len(matrix)): + for j in range(len(matrix[0])): + if not matrix[i][j]: + row_zero.add(i) + col_zero.add(j) + + for row_index in row_zero: + matrix[row_index] = [0] * len(matrix[0]) + + for col_index in col_zero: + for i in range(len(matrix)): + matrix[i][col_index] = 0 + + + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254 2.py" "b/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254 2.py" new file mode 100644 index 0000000..59b4b34 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 01.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\230 01.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def isFlipedString(self, s1, s2): + """ + :type s1: str + :type s2: str + :rtype: bool + """ + return s1 in s2 + s2 and len(s1) == len(s2) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271 2.py" "b/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..647f3de --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.01.\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271 2.py" @@ -0,0 +1,26 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def removeDuplicateNodes(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + visited = set() + + p = head + pre = None + while p: + if p.val in visited: + pre.next = p.next + p = p.next + else: + visited.add(p.val) + pre = p + p = p.next + return head + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271 2.py" "b/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..5ef4970 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.02.\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.02-\350\277\224\345\233\236\345\200\222\346\225\260\347\254\254k\344\270\252\350\212\202\347\202\271 2.py" @@ -0,0 +1,22 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def kthToLast(self, head, k): + """ + :type head: ListNode + :type k: int + :rtype: int + """ + slow, fast = head, head + while k: + k -= 1 + fast = fast.next + + while fast: + slow = slow.next + fast = fast.next + return slow.val \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271 2.py" "b/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271 2.py" new file mode 100644 index 0000000..c77b28f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.03.\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271/\351\235\242\350\257\225\351\242\230 02.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271 2.py" @@ -0,0 +1,19 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def deleteNode(self, node): + """ + :type node: ListNode + :rtype: void Do not return anything, modify node in-place instead. + """ + p = node + while p and p.next: + p.val = p.next.val + if not p.next.next: + p.next = None + p = p.next + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" "b/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" new file mode 100644 index 0000000..068ad14 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.04.\345\210\206\345\211\262\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.04-\345\210\206\345\211\262\351\223\276\350\241\250.py" @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def partition(self, head: ListNode, x: int) -> ListNode: + dummy1, dummy2 = ListNode(-1), ListNode(-2) + + smaller, larger = dummy1, dummy2 + p = head + while p: + if p.val < x: + smaller.next = ListNode(p.val) + smaller = smaller.next + else: + larger.next = ListNode(p.val) + larger = larger.next + + p = p.next + + smaller.next = dummy2.next + return dummy1.next \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" "b/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" new file mode 100644 index 0000000..70f930c --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.05.\351\223\276\350\241\250\346\261\202\345\222\214/\351\235\242\350\257\225\351\242\230 02.05-\351\223\276\350\241\250\346\261\202\345\222\214.py" @@ -0,0 +1,59 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: + if not l1 and not l2: + return l1 + if not l1: + return l2 + if not l2: + return l1 + + p1, p2 = l1, l2 + carry = 0 + dummy = ListNode(-1) + p = dummy + while l1 and l2: + s = l1.val + l2.val + carry + l1 = l1.next + l2 = l2.next + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + + p.next = ListNode(s) + p = p.next + + while l1: + s = l1.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l1 = l1.next + p.next = ListNode(s) + p = p.next + + while l2: + s = l2.val + carry + if s > 9: + s -= 10 + carry = 1 + else: + carry = 0 + l2 = l2.next + p.next = ListNode(s) + p = p.next + + if carry: + p.next = ListNode(1) + return dummy.next + + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" "b/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" new file mode 100644 index 0000000..654d1c5 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 02.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" @@ -0,0 +1,13 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def isPalindrome(self, head: ListNode) -> bool: + p = head + l = [] + while p: + l.append(p.val) + p = p.next + return l == l[::-1] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" "b/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" new file mode 100644 index 0000000..f174760 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.07.\351\223\276\350\241\250\347\233\270\344\272\244/\351\235\242\350\257\225\351\242\230 02.07-\351\223\276\350\241\250\347\233\270\344\272\244.py" @@ -0,0 +1,36 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: + pa, pb = headA, headB + if not headA or not headB: + return None + + la, lb = 0, 0 + while pa: + la += 1 + pa = pa.next + while pb: + lb += 1 + pb = pb.next + + if la < lb: + headA, headB = headB, headA + la, lb = lb, la + + diff = la - lb + pa = headA + while diff: + pa = pa.next + diff -= 1 + + pb = headB + while pa and pb and pa != pb: + pa = pa.next + pb = pb.next + + return pa if pa == pb else None \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" "b/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" new file mode 100644 index 0000000..c6abf6f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 02.08.\347\216\257\350\267\257\346\243\200\346\265\213/\351\235\242\350\257\225\351\242\230 02.08-\347\216\257\350\267\257\346\243\200\346\265\213.py" @@ -0,0 +1,28 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def detectCycle(self, head: ListNode) -> ListNode: + if not head or not head.next: + return None + slow, fast = head, head + + while fast and fast.next: + slow = slow.next + fast = fast.next.next + + if slow == fast: + break + + if slow != fast: + return None + + fast = head + while fast != slow: + slow = slow.next + fast = fast.next + + return fast \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" "b/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" new file mode 100644 index 0000000..b26eec1 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 03.02.\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274/\351\235\242\350\257\225\351\242\230 03.02-\346\240\210\347\232\204\346\234\200\345\260\217\345\200\274.py" @@ -0,0 +1,35 @@ +class MinStack: + + def __init__(self): + """ + initialize your data structure here. + """ + self.stack = [] + self.min_stack = [] + + def push(self, x: int) -> None: + self.stack.append(x) + if self.min_stack: + self.min_stack.append(min(self.min_stack[-1], x)) + else: + self.min_stack.append(x) + + def pop(self) -> None: + self.stack.pop() + self.min_stack.pop() + + def top(self) -> int: + return self.stack[-1] + + + def getMin(self) -> int: + return self.min_stack[-1] + + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(x) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" "b/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" new file mode 100644 index 0000000..5443d3f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.01.\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257/\351\235\242\350\257\225\351\242\230 04.01-\350\212\202\347\202\271\351\227\264\351\200\232\350\267\257.py" @@ -0,0 +1,27 @@ +from collections import * +class Solution: + def findWhetherExistsPath(self, n: int, graph: List[List[int]], start: int, target: int) -> bool: + src2des = defaultdict(list) + + for pair in graph: + src, des = pair[0], pair[1] + src2des[src].append(des) + + # BFS + queue = deque([start]) + visited = {start} + while queue: + cur = queue.popleft() + if cur == target: + return True + + for node in src2des[cur]: + if node not in visited: + queue.append(node) + visited.add(node) + + return False + + + + diff --git "a/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" "b/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" new file mode 100644 index 0000000..cca5452 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.02.\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221/\351\235\242\350\257\225\351\242\230 04.02-\346\234\200\345\260\217\351\253\230\345\272\246\346\240\221.py" @@ -0,0 +1,14 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def sortedArrayToBST(self, nums: List[int]) -> TreeNode: + if not nums: + return None + mid = len(nums) // 2 + root = TreeNode(nums[mid], self.sortedArrayToBST(nums[:mid]), self.sortedArrayToBST(nums[mid + 1:])) + return root \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" "b/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" new file mode 100644 index 0000000..8bb57fa --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.03.\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\230 04.03-\347\211\271\345\256\232\346\267\261\345\272\246\350\212\202\347\202\271\351\223\276\350\241\250.py" @@ -0,0 +1,32 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def listOfDepth(self, tree: TreeNode) -> List[ListNode]: + queue = [tree] + res = [] + + while queue: + next_queue = [] + cur_level = ListNode(-1) + p = cur_level + for node in queue: + if node: + next_queue.extend([node.left, node.right]) + p.next = ListNode(node.val) + p = p.next + + if cur_level != p: + res.append(cur_level.next) + queue = next_queue + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" "b/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" new file mode 100644 index 0000000..e357a5e --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.04.\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247/\351\235\242\350\257\225\351\242\230 04.04-\346\243\200\346\237\245\345\271\263\350\241\241\346\200\247.py" @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def isBalanced(self, root: TreeNode) -> bool: + if not root or (not root.left and not root.right): + return True + + def getHeight(node): + if not node: + return 0 + return 1 + max(getHeight(node.left), getHeight(node.right)) + + if abs(getHeight(root.left) - getHeight(root.right)) > 1: + return False + return self.isBalanced(root.left) and self.isBalanced(root.right) diff --git "a/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..f7917a0 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.05.\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/\351\235\242\350\257\225\351\242\230 04.05-\345\220\210\346\263\225\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -0,0 +1,16 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def isValidBST(self, root: TreeNode) -> bool: + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + l = inorder(root) + return l == sorted(l) and len(l) == len(set(l)) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" "b/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" new file mode 100644 index 0000000..b395f1d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 04.06.\345\220\216\347\273\247\350\200\205/\351\235\242\350\257\225\351\242\230 04.06-\345\220\216\347\273\247\350\200\205.py" @@ -0,0 +1,22 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution: + def inorderSuccessor(self, root: TreeNode, p: TreeNode) -> TreeNode: + self.res = None + def inorder(node): + if not node: + return + + inorder(node.left) + if not self.res and node.val > p.val: + self.res = node + return + inorder(node.right) + + inorder(root) + return self.res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" "b/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" new file mode 100644 index 0000000..92c38d7 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 08.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\230 08.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" @@ -0,0 +1,8 @@ +class Solution: + def waysToStep(self, n: int) -> int: + dp = [0] * (max(10, n + 1)) + MOD = 10 ** 9 + 7 + dp[1], dp[2], dp[3] = 1, 2, 4 + for i in range(4, n + 1): + dp[i] = (dp[i - 1] + dp[i - 2] + dp[i - 3]) % MOD + return dp[n] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" "b/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" new file mode 100644 index 0000000..00aeb6f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 08.02.\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272/\351\235\242\350\257\225\351\242\230 08.02-\350\277\267\350\267\257\347\232\204\346\234\272\345\231\250\344\272\272.py" @@ -0,0 +1,30 @@ +from collections import deque +class Solution: + def pathWithObstacles(self, obstacleGrid: List[List[int]]) -> List[List[int]]: + if not obstacleGrid or not obstacleGrid[0] or obstacleGrid[0][0] == 1: + return [] + m, n = len(obstacleGrid), len(obstacleGrid[0]) + if obstacleGrid[m -1][n - 1] == 1: + return [] + + self.res = [] + # dfs + visited = set([(0, 0)]) + def dfs(i, j, path): + if not 0 <= i < m or not 0 <= j < n: + return + path.append([i, j]) + if i == m - 1 and j == n - 1: + self.res = path[:] + return + if not self.res: + if i + 1 < m and obstacleGrid[i + 1][j] != 1 and (i + 1, j) not in visited: + visited.add((i + 1, j)) + dfs(i + 1, j, path[:]) + if j + 1 < n and obstacleGrid[i][j + 1] != 1 and (i, j + 1) not in visited: + visited.add((i, j + 1)) + dfs(i, j + 1, path[:]) + dfs(0, 0, []) + return self.res + + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225 2.py" "b/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225 2.py" new file mode 100644 index 0000000..55295bc --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 08.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\230 08.03-\351\255\224\346\234\257\347\264\242\345\274\225 2.py" @@ -0,0 +1,10 @@ +class Solution(object): + def findMagicIndex(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + for i, num in enumerate(nums): + if i == num: + return i + return -1 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" "b/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" new file mode 100644 index 0000000..2acc5a1 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 08.05.\351\200\222\345\275\222\344\271\230\346\263\225/\351\235\242\350\257\225\351\242\230 08.05-\351\200\222\345\275\222\344\271\230\346\263\225.py" @@ -0,0 +1,7 @@ +class Solution: + def multiply(self, A: int, B: int) -> int: + if B == 1: + return A + if B == 0: + return 0 + return A + self.multiply(A, B - 1) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" "b/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" new file mode 100644 index 0000000..3488b03 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 10.02.\345\217\230\344\275\215\350\257\215\347\273\204/\351\235\242\350\257\225\351\242\230 10.02-\345\217\230\344\275\215\350\257\215\347\273\204.py" @@ -0,0 +1,9 @@ +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + from collections import defaultdict + + d = defaultdict(list) + for word in strs: + d["".join(sorted(word))].append(word) + + return [val for key, val in d.items()] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" new file mode 100644 index 0000000..7fb10f6 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 16.01.\344\272\244\346\215\242\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\230 16.01-\344\272\244\346\215\242\346\225\260\345\255\227.py" @@ -0,0 +1,3 @@ +class Solution: + def swapNumbers(self, numbers: List[int]) -> List[int]: + return [numbers[1], numbers[0]] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" "b/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" new file mode 100644 index 0000000..5c7be33 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 16.02.\345\215\225\350\257\215\351\242\221\347\216\207/\351\235\242\350\257\225\351\242\230 16.02-\345\215\225\350\257\215\351\242\221\347\216\207.py" @@ -0,0 +1,14 @@ +from collections import Counter +class WordsFrequency: + + def __init__(self, book: List[str]): + self.word2freq = Counter(book) + + def get(self, word: str) -> int: + return self.word2freq[word] + + + +# Your WordsFrequency object will be instantiated and called as such: +# obj = WordsFrequency(book) +# param_1 = obj.get(word) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274 2.py" "b/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274 2.py" new file mode 100644 index 0000000..8f7148c --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 16.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\230 16.07-\346\234\200\345\244\247\346\225\260\345\200\274 2.py" @@ -0,0 +1,8 @@ +class Solution(object): + def maximum(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + return max(a, b) \ No newline at end of file