From 2f129884c2836608f479e7d722c0fe8a343c9342 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sat, 24 Aug 2019 13:01:34 -0400 Subject: [PATCH 001/183] 2019-08-24 --- ...25\350\241\214\351\224\256\347\233\230.py" | 16 +++++ ...07\344\273\266\347\263\273\347\273\237.py" | 38 ++++++++++++ ...00\344\275\216\350\264\271\347\224\250.py" | 15 +++++ ...06\351\205\215\344\274\230\345\214\226.py" | 60 +++++++++++++++++++ 4 files changed, 129 insertions(+) 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.py" create mode 100644 "1166.\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237/1166-\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237.py" create mode 100644 "1167.\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250/1167-\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250.py" create mode 100644 "1168.\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226/1168-\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226.py" 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.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.py" new file mode 100644 index 0000000..69de22f --- /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.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, last_pos = 0, 0 + for char in word: + res += abs(dic[char] - last_pos) + last_pos = dic[char] + return res \ No newline at end of file diff --git "a/1166.\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237/1166-\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237.py" "b/1166.\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237/1166-\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237.py" new file mode 100644 index 0000000..4f1466d --- /dev/null +++ "b/1166.\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237/1166-\350\256\276\350\256\241\346\226\207\344\273\266\347\263\273\347\273\237.py" @@ -0,0 +1,38 @@ +class FileSystem(object): + + def __init__(self): + self.dic = dict() + + def create(self, path, value): + """ + :type path: str + :type value: int + :rtype: bool + """ + if path in self.dic: + return False + parent = path.split("/") + parent_path = "" + for i in range(1, len(parent) - 1): + # print parent, i + parent_path += "/" + parent[i] + # print parent_path + if parent_path not in self.dic: + return False + self.dic[path] = value + return True + + + def get(self, path): + """ + :type path: str + :rtype: int + """ + return self.dic[path] if path in self.dic else -1 + + + +# Your FileSystem object will be instantiated and called as such: +# obj = FileSystem() +# param_1 = obj.create(path,value) +# param_2 = obj.get(path) \ No newline at end of file diff --git "a/1167.\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250/1167-\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250.py" "b/1167.\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250/1167-\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250.py" new file mode 100644 index 0000000..7d861bf --- /dev/null +++ "b/1167.\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250/1167-\350\277\236\346\216\245\346\243\222\346\235\220\347\232\204\346\234\200\344\275\216\350\264\271\347\224\250.py" @@ -0,0 +1,15 @@ +class Solution(object): + def connectSticks(self, sticks): + """ + :type sticks: List[int] + :rtype: int + """ + from heapq import * + heapify(sticks) + res = 0 + while len(sticks) > 1: + s1 = heappop(sticks) + s2 = heappop(sticks) + res += s1 + s2 + heappush(sticks, s1 + s2) + return res \ No newline at end of file diff --git "a/1168.\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226/1168-\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226.py" "b/1168.\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226/1168-\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226.py" new file mode 100644 index 0000000..5e4b3ac --- /dev/null +++ "b/1168.\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226/1168-\346\260\264\350\265\204\346\272\220\345\210\206\351\205\215\344\274\230\345\214\226.py" @@ -0,0 +1,60 @@ + +class UnionFindSet(object): + def __init__(self, n): + + 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 minCostToSupplyWater(self, n, wells, pipes): + """ + :type n: int + :type wells: List[int] + :type pipes: List[List[int]] + :rtype: int + """ + from heapq import * + for i, well in enumerate(wells): + pipes.append([0, i + 1, well]) + + queue = [] + ufs = UnionFindSet(n) + for start, end, cost in pipes: + queue.append([cost, start, end]) + + heapify(queue) + res = 0 + while ufs.count > 0: + + cost, start, end = heappop(queue) + # print ufs.roots, cost, start, end + if ufs.find(start) == ufs.find(end): + continue + res += cost + ufs.union(end, start) + return res + + \ No newline at end of file From cad52918bf6af867422a86be3ce8ebf2ca4bfdce Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 25 Aug 2019 22:25:06 -0400 Subject: [PATCH 002/183] 2019-08-25 --- ...40\346\225\210\344\272\244\346\230\223.py" | 32 ++++++++++ ...72\347\216\260\351\242\221\346\254\241.py" | 28 +++++++++ ...36\347\273\255\350\212\202\347\202\271.py" | 26 +++++++++ ...2-\351\244\220\347\233\230\346\240\210.py" | 58 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 "1169.\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223/1169-\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223.py" create mode 100644 "1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" create mode 100644 "1171.\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271/1171-\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271.py" create mode 100644 "1172.\351\244\220\347\233\230\346\240\210/1172-\351\244\220\347\233\230\346\240\210.py" diff --git "a/1169.\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223/1169-\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223.py" "b/1169.\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223/1169-\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223.py" new file mode 100644 index 0000000..e48c69f --- /dev/null +++ "b/1169.\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223/1169-\346\237\245\350\257\242\346\227\240\346\225\210\344\272\244\346\230\223.py" @@ -0,0 +1,32 @@ +class Solution(object): + def invalidTransactions(self, transactions): + """ + :type transactions: List[str] + :rtype: List[str] + """ + recordByName = collections.defaultdict(list) + for trans in transactions: + name, time, amount, city = trans.split(",") + recordByName[name].append([name, int(time), int(amount), city]) + + def convert(l): + return l[0] + "," + str(l[1]) + "," + str(l[2]) + "," + l[3] + + res = set() + for name, rec in recordByName.items(): + curRec = sorted(rec, key = lambda x:x[1]) + + for i in range(len(curRec)): + if curRec[i][2] > 1000: + res.add(convert(curRec[i])) + for j in range(i + 1, len(curRec)): + + if abs(curRec[j][1] - curRec[i][1]) > 60: + break + if curRec[j][3] != curRec[i][3]: + res.add(convert(curRec[i])) + res.add(convert(curRec[j])) + return res + + + \ No newline at end of file diff --git "a/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" new file mode 100644 index 0000000..1d151bc --- /dev/null +++ "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" @@ -0,0 +1,28 @@ +class Solution(object): + def numSmallerByFrequency(self, queries, words): + """ + :type queries: List[str] + :type words: List[str] + :rtype: List[int] + """ + + def func(word): + for char in "abcdefghijklmnopqrstuvwxyz": + if char in word: + return word.count(char) + return 0 + + def func2(word): + record = collections.Counter(word) + return record[min(record.keys())] + + + words_count = sorted(map(func2, words)) + queries_count = map(func2, queries) + # print words_count, queries_count + ans = [] + for query in queries_count: + index = bisect.bisect(words_count, query) #bisect可以迅速找出有index个数 <= query + ans.append(len(words_count) - index)# 减法找有多少个数比query大 + return ans + \ No newline at end of file diff --git "a/1171.\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271/1171-\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271.py" "b/1171.\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271/1171-\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271.py" new file mode 100644 index 0000000..9df319f --- /dev/null +++ "b/1171.\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271/1171-\344\273\216\351\223\276\350\241\250\344\270\255\345\210\240\345\216\273\346\200\273\345\222\214\345\200\274\344\270\272\351\233\266\347\232\204\350\277\236\347\273\255\350\212\202\347\202\271.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 removeZeroSumSublists(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + dummy = ListNode(-1) + dummy.next = head + + record = {0:dummy} + pre_sum = 0 + + while head: + pre_sum += head.val + if pre_sum in record: + record[pre_sum].next = head.next + else: + record[pre_sum] = head + head = head.next + return dummy.next \ No newline at end of file diff --git "a/1172.\351\244\220\347\233\230\346\240\210/1172-\351\244\220\347\233\230\346\240\210.py" "b/1172.\351\244\220\347\233\230\346\240\210/1172-\351\244\220\347\233\230\346\240\210.py" new file mode 100644 index 0000000..f2f14d7 --- /dev/null +++ "b/1172.\351\244\220\347\233\230\346\240\210/1172-\351\244\220\347\233\230\346\240\210.py" @@ -0,0 +1,58 @@ +from heapq import * +class DinnerPlates(object): + def __init__(self, capacity): + """ + :type capacity: int + """ + self.stack = [] + self.c = capacity + self.idx = [] #用于存放有空位的栈的下标 + + def push(self, val): + """ + :type val: int + :rtype: None + """ + if self.idx: + index = heappop(self.idx) #找最小的空的栈的下标 + self.stack[index].append(val) #插入val + if len(self.stack[index]) < self.c: #如果插了之后还没满,就把这个空的栈的下标放进self.idx + heappush(self.idx, index) + else: #现在所有栈都满了,只能新增一个栈在末尾 + self.stack.append([val]) + if self.c > 1: + self.idx.append(len(self.stack) - 1) + + + def pop(self): + """ + :rtype: int + """ + while self.stack and not self.stack[-1]: + self.stack.pop() + if not self.stack: #所有的栈都是空的 + return -1 + else: + if len(self.stack[-1]) == self.c: #如果本来是满的栈 + heappush(self.idx, len(self.stack) - 1) #现在要变成有空位的栈了 + return self.stack[-1].pop() + + def popAtStack(self, index): + """ + :type index: int + :rtype: int + """ + if index >= len(self.stack): #下标越界 + return -1 + else: + s = self.stack[index] # 把下标为index的栈取出来 + if len(s) == self.c: #如果这个栈本来是满的 + heappush(self.idx, index) #马上要变空了 + return s.pop() if s else -1 #如果这个栈是空的,返回-1, 否则返回pop + + +# Your DinnerPlates object will be instantiated and called as such: +# obj = DinnerPlates(capacity) +# obj.push(val) +# param_2 = obj.pop() +# param_3 = obj.popAtStack(index) \ No newline at end of file From 1f8121c9e3789df08f0ab57b4a5852a61f0c63d4 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 25 Aug 2019 22:53:20 -0400 Subject: [PATCH 003/183] 2019-08-25 --- ...345\257\271\347\247\260\346\225\260III.py" | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git "a/0248.\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III/0248-\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III.py" "b/0248.\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III/0248-\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III.py" index 578c7be..ebf7f4b 100644 --- "a/0248.\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III/0248-\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III.py" +++ "b/0248.\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III/0248-\344\270\255\345\277\203\345\257\271\347\247\260\346\225\260III.py" @@ -8,21 +8,16 @@ def strobogrammaticInRange(self, low, high): if int(low) > int(high): return 0 self.findStrobogrammatic(len(high)) - #在low里找 + low_rec = self.record[len(low)] - #找第一个 >= low的数的下标 - low_cnt = 0 - for i, num in enumerate(low_rec): - if int(num) >= int(low): - low_cnt = len(low_rec) - i - break - + #找在low_rec里有多少个数 >= low,结果放在low_cnt里 + #这里相当于在找左侧边界 + + low_cnt = len(low_rec) - bisect.bisect_left(low_rec, low) + + #找第一个 > high的数的下标,如果没找到,则说明这个数组里所有的数都比 high小 high_rec = self.record[len(high)] - high_cnt = len(high_rec) - for i, num in enumerate(high_rec): - if int(num) > int(high): - high_cnt = i - break + high_cnt = bisect.bisect_right(high_rec, high) if len(low) + 1 == len(high): return low_cnt + high_cnt @@ -31,20 +26,9 @@ def strobogrammaticInRange(self, low, high): else: tmp = 0 for l in range(len(low) + 1, len(high)): - # print l, self.record tmp += len(self.record[l]) return tmp + low_cnt + high_cnt - #找第一个 > high的数的下标 - # left, right = 0, len(low_rec) - 1 - # while left < right: - # mid = (left + right) // 2 - # if low_rec[mid] == low: - # low_cnt = len(low_rec) - mid - # elif low_rec[mid] > low: - # right = mid - 1 - # elif low_rec[mid] < low: - # left = mid + 1 - + From 284ade9042ab5f414e0e918cc84cbcc8b860e062 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 25 Aug 2019 22:54:53 -0400 Subject: [PATCH 004/183] 2019-08-25 --- 0001.two-sum/two-sum.cpp | 17 ----- 0001.two-sum/two-sum.md | 14 ----- 0001.two-sum/two-sum.py | 12 ---- .../median-of-two-sorted-arrays.md | 23 ------- .../median-of-two-sorted-arrays.py | 57 ----------------- .../divide-two-integers.md | 25 -------- .../divide-two-integers.py | 31 ---------- 0036.valid-sudoku/valid-sudoku.md | 59 ------------------ 0036.valid-sudoku/valid-sudoku.py | 21 ------- 0037.sudoku-solver/sudoku-solver.md | 25 -------- 0037.sudoku-solver/sudoku-solver.py | 45 -------------- .../first-missing-positive.md | 26 -------- .../first-missing-positive.py | 18 ------ .../trapping-rain-water.md | 10 --- .../trapping-rain-water.py | 31 ---------- .../remove-duplicates-from-sorted-array-ii.md | 41 ------------ .../remove-duplicates-from-sorted-array-ii.py | 12 ---- .../largest-rectangle-in-histogram.md | 20 ------ .../largest-rectangle-in-histogram.py | 18 ------ 0217.contains-duplicate/contains-duplicate.md | 21 ------- 0217.contains-duplicate/contains-duplicate.py | 13 ---- .../contains-duplicate-ii.md | 28 --------- .../contains-duplicate-ii.py | 16 ----- .../find-median-from-data-stream.md | 34 ---------- .../find-median-from-data-stream.py | 45 -------------- 0377.combination-sum-iv/combination-sum-iv.md | 31 ---------- 0377.combination-sum-iv/combination-sum-iv.py | 16 ----- .../pacific-atlantic-water-flow.md | 29 --------- .../pacific-atlantic-water-flow.py | 62 ------------------- ...econstruct-original-digits-from-english.md | 25 -------- ...econstruct-original-digits-from-english.py | 30 --------- 0506.relative-ranks/relative-ranks.java | 43 ------------- 0506.relative-ranks/relative-ranks.md | 17 ----- .../subarray-sum-equals-k.md | 15 ----- .../subarray-sum-equals-k.py | 18 ------ 0598.range-addition-ii/range-addition-ii.md | 37 ----------- 0598.range-addition-ii/range-addition-ii.py | 13 ---- .../sum-of-square-numbers.md | 20 ------ .../sum-of-square-numbers.py | 21 ------- 0697.degree-of-an-array/degree-of-an-array.md | 27 -------- 0697.degree-of-an-array/degree-of-an-array.py | 25 -------- .../shortest-completing-word.md | 37 ----------- .../shortest-completing-word.py | 29 --------- 0912.sort-an-array/sort-an-array.md | 29 --------- 0912.sort-an-array/sort-an-array.py | 7 --- .../subarray-sums-divisible-by-k.md | 24 ------- .../subarray-sums-divisible-by-k.py | 24 ------- .../partition-array-for-maximum-sum.md | 21 ------- .../partition-array-for-maximum-sum.py | 22 ------- 1046.last-stone-weight/last-stone-weight.md | 32 ---------- 1046.last-stone-weight/last-stone-weight.py | 14 ----- ...emove-all-adjacent-duplicates-in-string.md | 25 -------- ...emove-all-adjacent-duplicates-in-string.py | 17 ----- .../longest-string-chain.md | 31 ---------- .../longest-string-chain.py | 41 ------------ 55 files changed, 1444 deletions(-) delete mode 100644 0001.two-sum/two-sum.cpp delete mode 100644 0001.two-sum/two-sum.md delete mode 100644 0001.two-sum/two-sum.py delete mode 100644 0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.md delete mode 100644 0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.py delete mode 100644 0029.divide-two-integers/divide-two-integers.md delete mode 100644 0029.divide-two-integers/divide-two-integers.py delete mode 100644 0036.valid-sudoku/valid-sudoku.md delete mode 100644 0036.valid-sudoku/valid-sudoku.py delete mode 100644 0037.sudoku-solver/sudoku-solver.md delete mode 100644 0037.sudoku-solver/sudoku-solver.py delete mode 100644 0041.first-missing-positive/first-missing-positive.md delete mode 100644 0041.first-missing-positive/first-missing-positive.py delete mode 100644 0042.trapping-rain-water/trapping-rain-water.md delete mode 100644 0042.trapping-rain-water/trapping-rain-water.py delete mode 100644 0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.md delete mode 100644 0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.py delete mode 100644 0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.md delete mode 100644 0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.py delete mode 100644 0217.contains-duplicate/contains-duplicate.md delete mode 100644 0217.contains-duplicate/contains-duplicate.py delete mode 100644 0219.contains-duplicate-ii/contains-duplicate-ii.md delete mode 100644 0219.contains-duplicate-ii/contains-duplicate-ii.py delete mode 100644 0295.find-median-from-data-stream/find-median-from-data-stream.md delete mode 100644 0295.find-median-from-data-stream/find-median-from-data-stream.py delete mode 100644 0377.combination-sum-iv/combination-sum-iv.md delete mode 100644 0377.combination-sum-iv/combination-sum-iv.py delete mode 100644 0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.md delete mode 100644 0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.py delete mode 100644 0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.md delete mode 100644 0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.py delete mode 100644 0506.relative-ranks/relative-ranks.java delete mode 100644 0506.relative-ranks/relative-ranks.md delete mode 100644 0560.subarray-sum-equals-k/subarray-sum-equals-k.md delete mode 100644 0560.subarray-sum-equals-k/subarray-sum-equals-k.py delete mode 100644 0598.range-addition-ii/range-addition-ii.md delete mode 100644 0598.range-addition-ii/range-addition-ii.py delete mode 100644 0633.sum-of-square-numbers/sum-of-square-numbers.md delete mode 100644 0633.sum-of-square-numbers/sum-of-square-numbers.py delete mode 100644 0697.degree-of-an-array/degree-of-an-array.md delete mode 100644 0697.degree-of-an-array/degree-of-an-array.py delete mode 100644 0748.shortest-completing-word/shortest-completing-word.md delete mode 100644 0748.shortest-completing-word/shortest-completing-word.py delete mode 100644 0912.sort-an-array/sort-an-array.md delete mode 100644 0912.sort-an-array/sort-an-array.py delete mode 100644 0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.md delete mode 100644 0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.py delete mode 100644 1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.md delete mode 100644 1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.py delete mode 100644 1046.last-stone-weight/last-stone-weight.md delete mode 100644 1046.last-stone-weight/last-stone-weight.py delete mode 100644 1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.md delete mode 100644 1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.py delete mode 100644 1048.longest-string-chain/longest-string-chain.md delete mode 100644 1048.longest-string-chain/longest-string-chain.py diff --git a/0001.two-sum/two-sum.cpp b/0001.two-sum/two-sum.cpp deleted file mode 100644 index b2f69fd..0000000 --- a/0001.two-sum/two-sum.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - unordered_map m; - vector res; - for (int i = 0; i < nums.size(); i++){ - int temp = target - nums[i]; - if (m.count(temp)){ - res.push_back(m[temp]); - res.push_back(i); - break; - } - m[nums[i]] = i; - } - return res; - } -}; \ No newline at end of file diff --git a/0001.two-sum/two-sum.md b/0001.two-sum/two-sum.md deleted file mode 100644 index 8457633..0000000 --- a/0001.two-sum/two-sum.md +++ /dev/null @@ -1,14 +0,0 @@ -

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

- -

You may assume that each input would have exactly one solution, and you may not use the same element twice.

- -

Example:

- -
-Given nums = [2, 7, 11, 15], target = 9,
-
-Because nums[0] + nums[1] = 2 + 7 = 9,
-return [0, 1].
-
- -

 

diff --git a/0001.two-sum/two-sum.py b/0001.two-sum/two-sum.py deleted file mode 100644 index f328bda..0000000 --- a/0001.two-sum/two-sum.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def twoSum(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - for i in range(len(nums)): - for j in range(i + 1, len(nums)): - if nums[i] + nums[j] == target: - return [i,j] - \ No newline at end of file diff --git a/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.md b/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.md deleted file mode 100644 index 5392ce0..0000000 --- a/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.md +++ /dev/null @@ -1,23 +0,0 @@ -

There are two sorted arrays nums1 and nums2 of size m and n respectively.

- -

Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

- -

You may assume nums1 and nums2 cannot be both empty.

- -

Example 1:

- -
-nums1 = [1, 3]
-nums2 = [2]
-
-The median is 2.0
-
- -

Example 2:

- -
-nums1 = [1, 2]
-nums2 = [3, 4]
-
-The median is (2 + 3)/2 = 2.5
-
diff --git a/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.py b/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.py deleted file mode 100644 index 5dbbd99..0000000 --- a/0004.median-of-two-sorted-arrays/median-of-two-sorted-arrays.py +++ /dev/null @@ -1,57 +0,0 @@ -from heapq import * -class MedianFinder(object): -# 维护两个堆,一个大顶堆,一个小顶堆,小顶堆里的数比大顶堆里的数都要大, -# 如果有两个潜在的中位数(两个堆size相同),数据流的中位数就是两个堆顶之和除以2 -# 如果只有一个中位数,就看size更小的那个堆的堆顶 -# 如果新进来的数比小顶堆的数要小,就把它插入大顶堆 -# 如果新进来的数比小顶堆的数要大,就把它插入小顶堆 -# 调整两个堆,使得size 差最大为1 - def __init__(self): - """ - initialize your data structure here. - """ - self.max_h = list() - self.min_h = list() - heapify(self.max_h) - heapify(self.min_h) - - - def addNum(self, num): - """ - :type num: int - :rtype: None - """ - heappush(self.min_h, num) - heappush(self.max_h, -heappop(self.min_h)) - if len(self.max_h) > len(self.min_h): - heappush(self.min_h, -heappop(self.max_h)) - - def findMedian(self): - """ - :rtype: float - """ - max_len = len(self.max_h) - min_len = len(self.min_h) - if max_len == min_len: #有两个候选中位数 - return (self.min_h[0] + -self.max_h[0]) / 2. - else:#小顶堆的size 一定 >= 大顶堆的size,所以答案就是小顶堆的堆顶 - return self.min_h[0] / 1. - -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() - -class Solution(object): - def findMedianSortedArrays(self, nums1, nums2): - """ - :type nums1: List[int] - :type nums2: List[int] - :rtype: float - """ - mf = MedianFinder() - for num in nums1: - mf.addNum(num) - for num in nums2: - mf.addNum(num) - return mf.findMedian() \ No newline at end of file diff --git a/0029.divide-two-integers/divide-two-integers.md b/0029.divide-two-integers/divide-two-integers.md deleted file mode 100644 index 3c1b6d6..0000000 --- a/0029.divide-two-integers/divide-two-integers.md +++ /dev/null @@ -1,25 +0,0 @@ -

Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.

- -

Return the quotient after dividing dividend by divisor.

- -

The integer division should truncate toward zero.

- -

Example 1:

- -
-Input: dividend = 10, divisor = 3
-Output: 3
- -

Example 2:

- -
-Input: dividend = 7, divisor = -3
-Output: -2
- -

Note:

- -
    -
  • Both dividend and divisor will be 32-bit signed integers.
  • -
  • The divisor will never be 0.
  • -
  • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
  • -
diff --git a/0029.divide-two-integers/divide-two-integers.py b/0029.divide-two-integers/divide-two-integers.py deleted file mode 100644 index e89b241..0000000 --- a/0029.divide-two-integers/divide-two-integers.py +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def divide(self, dividend, divisor): - """ - :type dividend: int - :type divisor: int - :rtype: int - """ - # 计算被除数可以减去多少个除数: - op = 1 - if (dividend > 0 and divisor < 0) or (dividend < 0 and divisor > 0): - op = -1 - - dividend, divisor = abs(dividend), abs(divisor) - res = 0 - # cnt = 1 - while(dividend >= divisor): - multidivisor, multi = divisor, 1 - while(dividend >= multidivisor): - res += multi - dividend -= multidivisor - multi = multi << 1 - multidivisor = multidivisor <<1 - print dividend, multidivisor, multi - print multi - - - INT_MIN = -(2 **31) - INT_MAX = 2 **31 - 1 - res *= op - - return res if INT_MIN <= res <= INT_MAX else INT_MAX \ No newline at end of file diff --git a/0036.valid-sudoku/valid-sudoku.md b/0036.valid-sudoku/valid-sudoku.md deleted file mode 100644 index 19504c0..0000000 --- a/0036.valid-sudoku/valid-sudoku.md +++ /dev/null @@ -1,59 +0,0 @@ -

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

- -
    -
  1. Each row must contain the digits 1-9 without repetition.
  2. -
  3. Each column must contain the digits 1-9 without repetition.
  4. -
  5. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
  6. -
- -


-A partially filled sudoku which is valid.

- -

The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

- -

Example 1:

- -
-Input:
-[
-  ["5","3",".",".","7",".",".",".","."],
-  ["6",".",".","1","9","5",".",".","."],
-  [".","9","8",".",".",".",".","6","."],
-  ["8",".",".",".","6",".",".",".","3"],
-  ["4",".",".","8",".","3",".",".","1"],
-  ["7",".",".",".","2",".",".",".","6"],
-  [".","6",".",".",".",".","2","8","."],
-  [".",".",".","4","1","9",".",".","5"],
-  [".",".",".",".","8",".",".","7","9"]
-]
-Output: true
-
- -

Example 2:

- -
-Input:
-[
-  ["8","3",".",".","7",".",".",".","."],
-  ["6",".",".","1","9","5",".",".","."],
-  [".","9","8",".",".",".",".","6","."],
-  ["8",".",".",".","6",".",".",".","3"],
-  ["4",".",".","8",".","3",".",".","1"],
-  ["7",".",".",".","2",".",".",".","6"],
-  [".","6",".",".",".",".","2","8","."],
-  [".",".",".","4","1","9",".",".","5"],
-  [".",".",".",".","8",".",".","7","9"]
-]
-Output: false
-Explanation: Same as Example 1, except with the 5 in the top left corner being 
-    modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
-
- -

Note:

- -
    -
  • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
  • -
  • Only the filled cells need to be validated according to the mentioned rules.
  • -
  • The given board contain only digits 1-9 and the character '.'.
  • -
  • The given board size is always 9x9.
  • -
diff --git a/0036.valid-sudoku/valid-sudoku.py b/0036.valid-sudoku/valid-sudoku.py deleted file mode 100644 index a65dde4..0000000 --- a/0036.valid-sudoku/valid-sudoku.py +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def isValidSudoku(self, board): - """ - :type board: List[List[str]] - :rtype: bool - """ - from collections import defaultdict - row, column, squre = defaultdict(set), defaultdict(set), 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 column[j] or (board[i][j]) in squre[(i // 3, j // 3)]: - # print board[i][j], row[i], column[j], squre[(i // 3, j // 3)] - return False - else: - row[i].add(board[i][j]) - column[j].add(board[i][j]) - squre[(i // 3, j // 3)].add(board[i][j]) - # print row[1] - return True \ No newline at end of file diff --git a/0037.sudoku-solver/sudoku-solver.md b/0037.sudoku-solver/sudoku-solver.md deleted file mode 100644 index 827ae0c..0000000 --- a/0037.sudoku-solver/sudoku-solver.md +++ /dev/null @@ -1,25 +0,0 @@ -

Write a program to solve a Sudoku puzzle by filling the empty cells.

- -

A sudoku solution must satisfy all of the following rules:

- -
    -
  1. Each of the digits 1-9 must occur exactly once in each row.
  2. -
  3. Each of the digits 1-9 must occur exactly once in each column.
  4. -
  5. Each of the the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
  6. -
- -

Empty cells are indicated by the character '.'.

- -


-A sudoku puzzle...

- -


-...and its solution numbers marked in red.

- -

Note:

- -
    -
  • The given board contain only digits 1-9 and the character '.'.
  • -
  • You may assume that the given Sudoku puzzle will have a single unique solution.
  • -
  • The given board size is always 9x9.
  • -
diff --git a/0037.sudoku-solver/sudoku-solver.py b/0037.sudoku-solver/sudoku-solver.py deleted file mode 100644 index f598eae..0000000 --- a/0037.sudoku-solver/sudoku-solver.py +++ /dev/null @@ -1,45 +0,0 @@ -class Solution(object): - def solveSudoku(self, board): - """ - :type board: List[List[str]] - :rtype: None Do not return anything, modify board in-place instead. - """ - from collections import defaultdict - row, column, squre = defaultdict(set), defaultdict(set), defaultdict(set) - fill_list = [] - for i in range(9): - for j in range(9): - if board[i][j].isdigit(): #排除掉空的情况 - row[i].add(board[i][j].encode("utf-8")) - column[j].add(board[i][j].encode("utf-8")) - squre[(i // 3, j // 3)].add(board[i][j].encode("utf-8")) - else: - fill_list.append([i, j]) - - self.result = [] - def backtrack(idx): - if idx == len(fill_list): - for row1 in board: - self.result.append(row1[:]) - return - if not self.result: - i, j = fill_list[idx][0], fill_list[idx][1] - for digit in range(1, 10): - if str(digit) in row[i] or str(digit) in column[j] or str(digit) in squre[(i // 3, j // 3)]: - continue - - board[i][j] = str(digit) - row[i].add(board[i][j]) - column[j].add(board[i][j]) - squre[(i // 3, j // 3)].add(board[i][j]) - - backtrack(idx + 1) - - row[i].remove(board[i][j]) - column[j].remove(board[i][j]) - squre[(i // 3, j // 3)].remove(board[i][j]) - - backtrack(0) - for i in range(9): - for j in range(9): - board[i][j] = self.result[i][j] diff --git a/0041.first-missing-positive/first-missing-positive.md b/0041.first-missing-positive/first-missing-positive.md deleted file mode 100644 index b1879c7..0000000 --- a/0041.first-missing-positive/first-missing-positive.md +++ /dev/null @@ -1,26 +0,0 @@ -

Given an unsorted integer array, find the smallest missing positive integer.

- -

Example 1:

- -
-Input: [1,2,0]
-Output: 3
-
- -

Example 2:

- -
-Input: [3,4,-1,1]
-Output: 2
-
- -

Example 3:

- -
-Input: [7,8,9,11,12]
-Output: 1
-
- -

Note:

- -

Your algorithm should run in O(n) time and uses constant extra space.

diff --git a/0041.first-missing-positive/first-missing-positive.py b/0041.first-missing-positive/first-missing-positive.py deleted file mode 100644 index abcda2e..0000000 --- a/0041.first-missing-positive/first-missing-positive.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def firstMissingPositive(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - # 对于处于1~n之间的数,把它们放到nums[i - 1]的位置上 - - for i in range(len(nums)): - while 1 <= nums[i] <= len(nums) and nums[i] != nums[nums[i] - 1]: - # nums[i], nums[nums[i] - 1] = nums[nums[i] - 1], nums[i] - nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1] - - for i, x in enumerate(nums): - if x != i + 1: - return i + 1 - - return len(nums) + 1 \ No newline at end of file diff --git a/0042.trapping-rain-water/trapping-rain-water.md b/0042.trapping-rain-water/trapping-rain-water.md deleted file mode 100644 index abc422e..0000000 --- a/0042.trapping-rain-water/trapping-rain-water.md +++ /dev/null @@ -1,10 +0,0 @@ -

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.

- -


-The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!

- -

Example:

- -
-Input: [0,1,0,2,1,0,1,3,2,1,2,1]
-Output: 6
diff --git a/0042.trapping-rain-water/trapping-rain-water.py b/0042.trapping-rain-water/trapping-rain-water.py deleted file mode 100644 index a5926c1..0000000 --- a/0042.trapping-rain-water/trapping-rain-water.py +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def trap(self, height): - """ - :type height: List[int] - :rtype: int - """ - left_max = [0 for _ in height] - right_max = [0 for _ in height] - water = [0 for _ in height] - - for i in range(len(height)): - if i - 1 >= 0: - left_max[i] = max(left_max[i - 1], height[i]) - else: - left_max[i] = height[i] - - for i in range(len(height) - 1, -1, -1): - if i < len(height) - 1: - right_max[i] = max(right_max[i + 1], height[i]) - else: - right_max[i] = height[i] - - for i in range(len(height)): - tmp = min(left_max[i], right_max[i]) - height[i] - if tmp > 0: - water[i] = tmp - # print height - # print water - # print left_max - # print right_max - return sum(water) \ No newline at end of file diff --git a/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.md b/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.md deleted file mode 100644 index 1c8e8e7..0000000 --- a/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.md +++ /dev/null @@ -1,41 +0,0 @@ -

Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.

- -

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

- -

Example 1:

- -
-Given nums = [1,1,1,2,2,3],
-
-Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively.
-
-It doesn't matter what you leave beyond the returned length.
- -

Example 2:

- -
-Given nums = [0,0,1,1,1,1,2,3,3],
-
-Your function should return length = 7, with the first seven elements of nums being modified to 0, 0, 1, 1, 2, 3 and 3 respectively.
-
-It doesn't matter what values are set beyond the returned length.
-
- -

Clarification:

- -

Confused why the returned value is an integer but your answer is an array?

- -

Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.

- -

Internally you can think of this:

- -
-// nums is passed in by reference. (i.e., without making a copy)
-int len = removeDuplicates(nums);
-
-// any modification to nums in your function would be known by the caller.
-// using the length returned by your function, it prints the first len elements.
-for (int i = 0; i < len; i++) {
-    print(nums[i]);
-}
-
diff --git a/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.py b/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.py deleted file mode 100644 index e489bb1..0000000 --- a/0080.remove-duplicates-from-sorted-array-ii/remove-duplicates-from-sorted-array-ii.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def removeDuplicates(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - i = 0 - for num in nums: - if i < 2 or num != nums[i - 2]: - nums[i] = num - i += 1 - return i \ No newline at end of file diff --git a/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.md b/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.md deleted file mode 100644 index 6193a4f..0000000 --- a/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.md +++ /dev/null @@ -1,20 +0,0 @@ -

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.

- -

 

- -


-Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

- -

 

- -


-The largest rectangle is shown in the shaded area, which has area = 10 unit.

- -

 

- -

Example:

- -
-Input: [2,1,5,6,2,3]
-Output: 10
-
diff --git a/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.py b/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.py deleted file mode 100644 index a7acf32..0000000 --- a/0084.largest-rectangle-in-histogram/largest-rectangle-in-histogram.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def largestRectangleArea(self, heights): - """ - :type heights: List[int] - :rtype: int - """ - res = 0 - stack = list() - heights = [0] + heights + [0] - - for i in range(len(heights)): - while stack and heights[stack[-1]] > heights[i]: - top = stack.pop() - res = max(res, (i - stack[-1] - 1) * heights[top]) - - stack.append(i) - - return res \ No newline at end of file diff --git a/0217.contains-duplicate/contains-duplicate.md b/0217.contains-duplicate/contains-duplicate.md deleted file mode 100644 index bd80432..0000000 --- a/0217.contains-duplicate/contains-duplicate.md +++ /dev/null @@ -1,21 +0,0 @@ -

Given an array of integers, find if the array contains any duplicates.

- -

Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

- -

Example 1:

- -
-Input: [1,2,3,1]
-Output: true
- -

Example 2:

- -
-Input: [1,2,3,4]
-Output: false
- -

Example 3:

- -
-Input: [1,1,1,3,3,4,3,2,4,2]
-Output: true
diff --git a/0217.contains-duplicate/contains-duplicate.py b/0217.contains-duplicate/contains-duplicate.py deleted file mode 100644 index 159c7f0..0000000 --- a/0217.contains-duplicate/contains-duplicate.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def containsDuplicate(self, nums): - """ - :type nums: List[int] - :rtype: bool - """ - if len(nums) <= 1: - return False - nums.sort() - for index in range(0,len(nums)-1): - if nums[index] == nums[index +1]:#or nums[index] == nums[index-1]: - return True - return False \ No newline at end of file diff --git a/0219.contains-duplicate-ii/contains-duplicate-ii.md b/0219.contains-duplicate-ii/contains-duplicate-ii.md deleted file mode 100644 index d82af2f..0000000 --- a/0219.contains-duplicate-ii/contains-duplicate-ii.md +++ /dev/null @@ -1,28 +0,0 @@ -

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.

- -
-

Example 1:

- -
-Input: nums = [1,2,3,1], k = 3
-Output: true
-
- -
-

Example 2:

- -
-Input: nums = [1,0,1,1], k = 1
-Output: true
-
- -
-

Example 3:

- -
-Input: nums = [1,2,3,1,2,3], k = 2
-Output: false
-
-
-
-
diff --git a/0219.contains-duplicate-ii/contains-duplicate-ii.py b/0219.contains-duplicate-ii/contains-duplicate-ii.py deleted file mode 100644 index 47b4e95..0000000 --- a/0219.contains-duplicate-ii/contains-duplicate-ii.py +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def containsNearbyDuplicate(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: bool - """ - record = dict() - for i, num in enumerate(nums): - # print record - if record.get(num, -1) != -1: - if i - record[num] <= k: - return True - record[num] = i - return False - \ No newline at end of file diff --git a/0295.find-median-from-data-stream/find-median-from-data-stream.md b/0295.find-median-from-data-stream/find-median-from-data-stream.md deleted file mode 100644 index 35487b2..0000000 --- a/0295.find-median-from-data-stream/find-median-from-data-stream.md +++ /dev/null @@ -1,34 +0,0 @@ -

Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.

-For example, - -

[2,3,4], the median is 3

- -

[2,3], the median is (2 + 3) / 2 = 2.5

- -

Design a data structure that supports the following two operations:

- -
    -
  • void addNum(int num) - Add a integer number from the data stream to the data structure.
  • -
  • double findMedian() - Return the median of all elements so far.
  • -
- -

 

- -

Example:

- -
-addNum(1)
-addNum(2)
-findMedian() -> 1.5
-addNum(3) 
-findMedian() -> 2
-
- -

 

- -

Follow up:

- -
    -
  1. If all integer numbers from the stream are between 0 and 100, how would you optimize it?
  2. -
  3. If 99% of all integer numbers from the stream are between 0 and 100, how would you optimize it?
  4. -
diff --git a/0295.find-median-from-data-stream/find-median-from-data-stream.py b/0295.find-median-from-data-stream/find-median-from-data-stream.py deleted file mode 100644 index aaea467..0000000 --- a/0295.find-median-from-data-stream/find-median-from-data-stream.py +++ /dev/null @@ -1,45 +0,0 @@ -from heapq import * -class MedianFinder(object): -# 维护两个堆,一个大顶堆,一个小顶堆,小顶堆里的数比大顶堆里的数都要大, -# 如果有两个潜在的中位数(两个堆size相同),数据流的中位数就是两个堆顶之和除以2 -# 如果只有一个中位数,就看size更小的那个堆的堆顶 -# 新进来的数都丢进小顶堆,然后把小顶堆的堆顶丢到大顶堆, -# 调整两个堆,使得size 差最大为1 - def __init__(self): - """ - initialize your data structure here. - """ - self.max_h = list() - self.min_h = list() - heapify(self.max_h) - heapify(self.min_h) - - - def addNum(self, num): - """ - :type num: int - :rtype: None - """ - heappush(self.min_h, num) - heappush(self.max_h, -heappop(self.min_h)) - if len(self.max_h) > len(self.min_h): - heappush(self.min_h, -heappop(self.max_h)) - - def findMedian(self): - """ - :rtype: float - """ - max_len = len(self.max_h) - min_len = len(self.min_h) - if max_len == min_len: #有两个候选中位数 - return (self.min_h[0] + -self.max_h[0]) / 2. - else:#小顶堆的size 一定 >= 大顶堆的size,所以答案就是小顶堆的堆顶 - return self.min_h[0] / 1. - - - - -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() \ No newline at end of file diff --git a/0377.combination-sum-iv/combination-sum-iv.md b/0377.combination-sum-iv/combination-sum-iv.md deleted file mode 100644 index 4529463..0000000 --- a/0377.combination-sum-iv/combination-sum-iv.md +++ /dev/null @@ -1,31 +0,0 @@ -

Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.

- -

Example:

- -
-nums = [1, 2, 3]
-target = 4
-
-The possible combination ways are:
-(1, 1, 1, 1)
-(1, 1, 2)
-(1, 2, 1)
-(1, 3)
-(2, 1, 1)
-(2, 2)
-(3, 1)
-
-Note that different sequences are counted as different combinations.
-
-Therefore the output is 7.
-
- -

 

- -

Follow up:
-What if negative numbers are allowed in the given array?
-How does it change the problem?
-What limitation we need to add to the question to allow negative numbers?

- -

Credits:
-Special thanks to @pbrother for adding this problem and creating all test cases.

diff --git a/0377.combination-sum-iv/combination-sum-iv.py b/0377.combination-sum-iv/combination-sum-iv.py deleted file mode 100644 index 4d791c8..0000000 --- a/0377.combination-sum-iv/combination-sum-iv.py +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def combinationSum4(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - dp = [0 for _ in range(target + 1)] - dp[0] = 1 - nums.sort() - for i in range(1, target + 1): - for num in nums: - if i >= num: - dp[i] += dp[i - num] - - return dp[target] \ No newline at end of file diff --git a/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.md b/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.md deleted file mode 100644 index bc312c7..0000000 --- a/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.md +++ /dev/null @@ -1,29 +0,0 @@ -

Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" touches the right and bottom edges.

- -

Water can only flow in four directions (up, down, left, or right) from a cell to another one with height equal or lower.

- -

Find the list of grid coordinates where water can flow to both the Pacific and Atlantic ocean.

- -

Note:
-

    -
  1. The order of returned grid coordinates does not matter.
  2. -
  3. Both m and n are less than 150.
  4. -
-

-

Example: -

-Given the following 5x5 matrix:
-
-  Pacific ~   ~   ~   ~   ~ 
-       ~  1   2   2   3  (5) *
-       ~  3   2   3  (4) (4) *
-       ~  2   4  (5)  3   1  *
-       ~ (6) (7)  1   4   5  *
-       ~ (5)  1   1   2   4  *
-          *   *   *   *   * Atlantic
-
-Return:
-
-[[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]] (positions with parentheses in above matrix).
-
-

\ No newline at end of file diff --git a/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.py b/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.py deleted file mode 100644 index 4b52f57..0000000 --- a/0417.pacific-atlantic-water-flow/pacific-atlantic-water-flow.py +++ /dev/null @@ -1,62 +0,0 @@ -class Solution(object): - def pacificAtlantic(self, matrix): - """ - :type matrix: List[List[int]] - :rtype: List[List[int]] - """ - - if not matrix or not matrix[0]: - return list() - m, n = len(matrix), len(matrix[0]) - - po = [[0 for i in range(n)] for j in range(m)] #po[i][j] = 1就代表matrix[i][j]可以被太平洋的水流到 - ao = [[0 for i in range(n)] for j in range(m)] #同上,换成大西洋 - - - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - - def dfs(x0, y0, string): - if visited[x0][y0] == 1:#来过了 - return - visited[x0][y0] = 1 - - if string == "po": - po[x0][y0] = 1 - else: - ao[x0][y0] = 1 - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0<= x < m and 0 <= y < n and matrix[x][y] >= matrix[x0][y0]: #可以流到下一个点 - dfs(x, y, string) - - visited = [[0 for i in range(n)] for j in range(m)] - i = 0 - for j in range(n): - dfs(i, j, "po") #上面的太平洋 - - visited = [[0 for i in range(n)] for j in range(m)] - i = m - 1 - for j in range(n): - dfs(i, j, "ao") #下面的大西洋 - - visited = [[0 for i in range(n)] for j in range(m)] - j = 0 - for i in range(m): - dfs(i, j, "po") #左边的太平洋 - - visited = [[0 for i in range(n)] for j in range(m)] - j = n - 1 - for i in range(m): - dfs(i, j, "ao") #右边的大西洋 - - res = [] - for i in range(m): - for j in range(n): - if po[i][j] and ao[i][j]: #取交集 - res.append([i, j]) - - return res \ No newline at end of file diff --git a/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.md b/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.md deleted file mode 100644 index f48b4ec..0000000 --- a/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.md +++ /dev/null @@ -1,25 +0,0 @@ -

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.

- -

Note:
-

    -
  1. Input contains only lowercase English letters.
  2. -
  3. Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as "abc" or "zerone" are not permitted.
  4. -
  5. Input length is less than 50,000.
  6. -
-

- -

Example 1:
-

-Input: "owoztneoer"
-
-Output: "012"
-
-

- -

Example 2:
-

-Input: "fviefuro"
-
-Output: "45"
-
-

\ No newline at end of file diff --git a/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.py b/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.py deleted file mode 100644 index 42daf38..0000000 --- a/0423.reconstruct-original-digits-from-english/reconstruct-original-digits-from-english.py +++ /dev/null @@ -1,30 +0,0 @@ -class Solution(object): - def originalDigits(self, s): - """ - :type s: str - :rtype: str - """ - # zero one two three four five six seven eight nine - # z o(先2 w r(先4) u f(先4) x s(先6) t(先3) 最后看e - #所以一个可行的查找的顺序是 two, four, six, one, three, five, seven, eight, nine - order = ["zero", "two", "four", "six", "one", "three", "five", "seven", "eight", "nine"] - find = ["z", "w", "u", "x", "o", "r", "f", "v", "t", "e"] - digit = [0, 2, 4, 6, 1, 3, 5, 7, 8, 9] - - record = [0 for _ in range(10)] - dic = collections.Counter(s) - - for idx in range(10): #按digit数组的顺序遍历0~9 - cnt = dic[find[idx]] #看看可以组成几个digit[idx] - record[digit[idx]] += cnt #记录下来 - dic = dic - collections.Counter(order[idx] * cnt) #字典里减去对应的字母 - - if not dic: - break - - ress = "" - for i in range(10): #转换成题目需要的格式 - ress += str(i) * record[i] - - return ress - \ No newline at end of file diff --git a/0506.relative-ranks/relative-ranks.java b/0506.relative-ranks/relative-ranks.java deleted file mode 100644 index f38a036..0000000 --- a/0506.relative-ranks/relative-ranks.java +++ /dev/null @@ -1,43 +0,0 @@ -class Solution { - public int[] swap(int ary[]) { - int len = ary.length; - for (int i = 0; i < len / 2; i++) { - int tmp = ary[i]; - ary[i] = ary[len - 1 - i]; - ary[len - 1 - i] = tmp; - } - return ary; -} - - public String[] findRelativeRanks(int[] nums) { - int n = nums.length; - int[] nums1 = Arrays.copyOf(nums, n); - String[] result = new String[n]; - - Arrays.sort(nums1); - nums1 = swap(nums1); - Map map = new HashMap<>(); - - for (int i = 0; i < n; i++){ - map.put(nums[i], i); - } - // System.out.println(Arrays.toString(nums1)); - - for (int i = 0; i < n; i++){ - if (i == 0){ - result[map.get(nums1[i])] = "Gold Medal"; - continue; - } - else if (i == 1){ - result[map.get(nums1[i])] = "Silver Medal"; - continue; - } - else if (i == 2){ - result[map.get(nums1[i])] = "Bronze Medal"; - continue; - } - result[map.get(nums1[i])] = String.valueOf(i + 1); - } - return result; - } -} \ No newline at end of file diff --git a/0506.relative-ranks/relative-ranks.md b/0506.relative-ranks/relative-ranks.md deleted file mode 100644 index 3fdad3e..0000000 --- a/0506.relative-ranks/relative-ranks.md +++ /dev/null @@ -1,17 +0,0 @@ -

-Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".

- -

Example 1:
-

-Input: [5, 4, 3, 2, 1]
-Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
-Explanation: The first three athletes got the top three highest scores, so they got "Gold Medal", "Silver Medal" and "Bronze Medal". 
For the left two athletes, you just need to output their relative ranks according to their scores. -
-

- -

Note:
-

    -
  1. N is a positive integer and won't exceed 10,000.
  2. -
  3. All the scores of athletes are guaranteed to be unique.
  4. -
-

diff --git a/0560.subarray-sum-equals-k/subarray-sum-equals-k.md b/0560.subarray-sum-equals-k/subarray-sum-equals-k.md deleted file mode 100644 index a28a10b..0000000 --- a/0560.subarray-sum-equals-k/subarray-sum-equals-k.md +++ /dev/null @@ -1,15 +0,0 @@ -

Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.

- -

Example 1:
-

-Input:nums = [1,1,1], k = 2
-Output: 2
-
-

- -

Note:
-

    -
  1. The length of the array is in range [1, 20,000].
  2. -
  3. The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
  4. -
-

diff --git a/0560.subarray-sum-equals-k/subarray-sum-equals-k.py b/0560.subarray-sum-equals-k/subarray-sum-equals-k.py deleted file mode 100644 index 2fbf949..0000000 --- a/0560.subarray-sum-equals-k/subarray-sum-equals-k.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def subarraySum(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: int - """ - from collections import defaultdict - pre_sum = 0 - record = defaultdict(int) - record[0] = 1 - res = 0 - for i in range(len(nums)): - pre_sum += nums[i] - res += record[pre_sum - k] - record[pre_sum] += 1 - - return res \ No newline at end of file diff --git a/0598.range-addition-ii/range-addition-ii.md b/0598.range-addition-ii/range-addition-ii.md deleted file mode 100644 index 29482f0..0000000 --- a/0598.range-addition-ii/range-addition-ii.md +++ /dev/null @@ -1,37 +0,0 @@ -

Given an m * n matrix M initialized with all 0's and several update operations.

-

Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a and b, which means M[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.

-

You need to count and return the number of maximum integers in the matrix after performing all the operations.

- -

Example 1:
-

-Input: 
-m = 3, n = 3
-operations = [[2,2],[3,3]]
-Output: 4
-Explanation: 
-Initially, M = 
-[[0, 0, 0],
- [0, 0, 0],
- [0, 0, 0]]
-
-After performing [2,2], M = 
-[[1, 1, 0],
- [1, 1, 0],
- [0, 0, 0]]
-
-After performing [3,3], M = 
-[[2, 2, 1],
- [2, 2, 1],
- [1, 1, 1]]
-
-So the maximum integer in M is 2, and there are four of it in M. So return 4.
-
-

- -

Note:
-

    -
  1. The range of m and n is [1,40000].
  2. -
  3. The range of a is [1,m], and the range of b is [1,n].
  4. -
  5. The range of operations size won't exceed 10,000.
  6. -
-

\ No newline at end of file diff --git a/0598.range-addition-ii/range-addition-ii.py b/0598.range-addition-ii/range-addition-ii.py deleted file mode 100644 index 2e619af..0000000 --- a/0598.range-addition-ii/range-addition-ii.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def maxCount(self, m, n, ops): - """ - :type m: int - :type n: int - :type ops: List[List[int]] - :rtype: int - """ - min1, min2 = m, n - for op in ops: - min1 = min(min1, op[0]) - min2 = min(min2, op[1]) - return min1 * min2 \ No newline at end of file diff --git a/0633.sum-of-square-numbers/sum-of-square-numbers.md b/0633.sum-of-square-numbers/sum-of-square-numbers.md deleted file mode 100644 index 9ba3b20..0000000 --- a/0633.sum-of-square-numbers/sum-of-square-numbers.md +++ /dev/null @@ -1,20 +0,0 @@ -

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.

- -

Example 1:

- -
-Input: 5
-Output: True
-Explanation: 1 * 1 + 2 * 2 = 5
-
- -

 

- -

Example 2:

- -
-Input: 3
-Output: False
-
- -

 

diff --git a/0633.sum-of-square-numbers/sum-of-square-numbers.py b/0633.sum-of-square-numbers/sum-of-square-numbers.py deleted file mode 100644 index 07f79e0..0000000 --- a/0633.sum-of-square-numbers/sum-of-square-numbers.py +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def judgeSquareSum(self, c): - """ - :type c: int - :rtype: bool - """ - - if c == (int(c ** 0.5) ** 2): - return True - - lo, hi = 0, int(c ** 0.5) - while(lo <= hi): - s = lo ** 2 + hi ** 2 - if s == c: - return True - elif s > c: - hi -= 1 - else: - lo += 1 - return False - \ No newline at end of file diff --git a/0697.degree-of-an-array/degree-of-an-array.md b/0697.degree-of-an-array/degree-of-an-array.md deleted file mode 100644 index 7c9c87b..0000000 --- a/0697.degree-of-an-array/degree-of-an-array.md +++ /dev/null @@ -1,27 +0,0 @@ -

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

-

Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

- -

Example 1:
-

-Input: [1, 2, 2, 3, 1]
-Output: 2
-Explanation: 
-The input array has a degree of 2 because both elements 1 and 2 appear twice.
-Of the subarrays that have the same degree:
-[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]
-The shortest length is 2. So return 2.
-
-

- - -

Example 2:
-

-Input: [1,2,2,3,1,4,2]
-Output: 6
-
-

- -

Note: -

  • nums.length will be between 1 and 50,000.
  • -
  • nums[i] will be an integer between 0 and 49,999.
  • -

    \ No newline at end of file diff --git a/0697.degree-of-an-array/degree-of-an-array.py b/0697.degree-of-an-array/degree-of-an-array.py deleted file mode 100644 index 1b09e2d..0000000 --- a/0697.degree-of-an-array/degree-of-an-array.py +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def findShortestSubArray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - - degree = 0 - for digit in set(nums): - degree = max(degree, nums.count(digit)) - - candidates = list() - for digit in set(nums): - if nums.count(digit) == degree: - candidates.append(digit) - l = len(nums) - reversenums = nums[::-1] - res = l - for candidate in candidates: - left_pos = nums.index(candidate) - right_pos = l - 1 - reversenums.index(candidate) - - res = min(res, right_pos - left_pos + 1) - - return res \ No newline at end of file diff --git a/0748.shortest-completing-word/shortest-completing-word.md b/0748.shortest-completing-word/shortest-completing-word.md deleted file mode 100644 index 2728f80..0000000 --- a/0748.shortest-completing-word/shortest-completing-word.md +++ /dev/null @@ -1,37 +0,0 @@ -

    -Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate -

    -Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. -

    -It is guaranteed an answer exists. If there are multiple answers, return the one that occurs first in the array. -

    -The license plate might have the same letter occurring multiple times. For example, given a licensePlate of "PP", the word "pair" does not complete the licensePlate, but the word "supper" does. -

    - -

    Example 1:
    -

    -Input: licensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]
    -Output: "steps"
    -Explanation: The smallest length word that contains the letters "S", "P", "S", and "T".
    -Note that the answer is not "step", because the letter "s" must occur in the word twice.
    -Also note that we ignored case for the purposes of comparing whether a letter exists in the word.
    -
    -

    - -

    Example 2:
    -

    -Input: licensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]
    -Output: "pest"
    -Explanation: There are 3 smallest length words that contains the letters "s".
    -We return the one that occurred first.
    -
    -

    - -

    Note:
    -

      -
    1. licensePlate will be a string with length in range [1, 7].
    2. -
    3. licensePlate will contain digits, spaces, or letters (uppercase or lowercase).
    4. -
    5. words will have a length in the range [10, 1000].
    6. -
    7. Every words[i] will consist of lowercase letters, and have length in range [1, 15].
    8. -
    -

    \ No newline at end of file diff --git a/0748.shortest-completing-word/shortest-completing-word.py b/0748.shortest-completing-word/shortest-completing-word.py deleted file mode 100644 index e5124c4..0000000 --- a/0748.shortest-completing-word/shortest-completing-word.py +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def shortestCompletingWord(self, licensePlate, words): - """ - :type licensePlate: str - :type words: List[str] - :rtype: str - """ - charlist = [] - for i, char in enumerate(licensePlate): - if char.isalpha(): - t = char - t = t.lower() - charlist.append(t) - charlistrecord = collections.Counter(charlist) - res = "aaaaaaaaaaaaaaaa" - - for word in words: - cnt = 0 - wordrecord = collections.Counter(word) - - for char in charlist: - if wordrecord.get(char, 0) >= charlistrecord[char]: - cnt += 1 - # print word, cnt - if cnt == len(charlist): #找完整词 - if len(word) < len(res): - res = word - - return res diff --git a/0912.sort-an-array/sort-an-array.md b/0912.sort-an-array/sort-an-array.md deleted file mode 100644 index 4e352dc..0000000 --- a/0912.sort-an-array/sort-an-array.md +++ /dev/null @@ -1,29 +0,0 @@ -

    Given an array of integers nums, sort the array in ascending order.

    - -

     

    - -
      -
    - -

    Example 1:

    - -
    -Input: [5,2,3,1]
    -Output: [1,2,3,5]
    -
    - -

    Example 2:

    - -
    -Input: [5,1,1,2,0,0]
    -Output: [0,0,1,1,2,5]
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 10000
    2. -
    3. -50000 <= A[i] <= 50000
    4. -
    diff --git a/0912.sort-an-array/sort-an-array.py b/0912.sort-an-array/sort-an-array.py deleted file mode 100644 index ea57e4d..0000000 --- a/0912.sort-an-array/sort-an-array.py +++ /dev/null @@ -1,7 +0,0 @@ -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/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.md b/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.md deleted file mode 100644 index 0fe953e..0000000 --- a/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.md +++ /dev/null @@ -1,24 +0,0 @@ -

    Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.

    - -

     

    - -
    -

    Example 1:

    - -
    -Input: A = [4,5,0,-2,-3,1], K = 5
    -Output: 7
    -Explanation: There are 7 subarrays with a sum divisible by K = 5:
    -[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 30000
    2. -
    3. -10000 <= A[i] <= 10000
    4. -
    5. 2 <= K <= 10000
    6. -
    -
    \ No newline at end of file diff --git a/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.py b/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.py deleted file mode 100644 index 8ba5d0b..0000000 --- a/0974.subarray-sums-divisible-by-k/subarray-sums-divisible-by-k.py +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def subarraysDivByK(self, A, K): - """ - :type A: List[int] - :type K: int - :rtype: int - """ - s = [0 for i in range(len(A) + 1)] #s代表前缀和,即s[i]表示sum(A[:i]) - kcnt = [0 for i in range(K)] #k[i]代表s中有多少个元素 mod k 为i - for i in range(len(A)): - s[i + 1] = s[i] + A[i] - for item in s: - kcnt[item % K] += 1 - print s, kcnt - #题目求连续子数组的和能被K整除,连续子数组的和就可以表示为前缀和的差 - #比如 sum(A[i:j + 1]) = s[j + 1] - s[i] - #如果两个数的差能被K整除,就说明这两个数 mod k得到的结果相同 - #只要找有多少对 mod k 相同的数就可以得到结果 - #举例 对于[4,5,0,-2,-3,1] 5 - # s = [0, 4, 9, 9, 7, 4, 5] - # k = [2, 0, 1, 0, 4] 代表有s中有两个元素的余数都为0(即0和5),1个元素的余数为2(即7),四个元素的余数为4(即4994) - # 所以在保证余数相同的情况下,取出两个数都可以得到一组答案。对于这个例子答案就是 C22 + C12 + C42 = 1 + 0 + 6 = 7 - return sum(x * (x - 1) // 2 for x in kcnt) - \ No newline at end of file diff --git a/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.md b/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.md deleted file mode 100644 index 2c17648..0000000 --- a/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.md +++ /dev/null @@ -1,21 +0,0 @@ -

    Given an integer array A, you partition the array into (contiguous) subarrays of length at most K.  After partitioning, each subarray has their values changed to become the maximum value of that subarray.

    - -

    Return the largest sum of the given array after partitioning.

    - -

     

    - -

    Example 1:

    - -
    -Input: A = [1,15,7,9,2,5,10], K = 3
    -Output: 84
    -Explanation: A becomes [15,15,15,9,10,10,10]
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= K <= A.length <= 500
    2. -
    3. 0 <= A[i] <= 10^6
    4. -
    \ No newline at end of file diff --git a/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.py b/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.py deleted file mode 100644 index 7562da0..0000000 --- a/1043.partition-array-for-maximum-sum/partition-array-for-maximum-sum.py +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def maxSumAfterPartitioning(self, A, K): - """ - :type A: List[int] - :type K: int - :rtype: int - """ - dp = [0 for _ in range(len(A))] - - for i, x in enumerate(A): #扫描每个数 - subarray_max = x - for j in range(1, K + 1): # J 代表当前子数组的长度,包括A[i]; 子数组是A[i - (j - 1): i + 1] - if i - (j - 1) >= 0:#首先至少能向前构成这长度为 J 的子数组, - subarray_max = max(subarray_max, A[i - (j - 1)]) #确保subarray_max是从子数组的最大值 - #这么写subarray_max = max(A[i - (j - 1): i + 1]]也可以过,但是很慢 - - if i - j < 0: # A[i]之前恰好有j - 1个元素,而它们一共组成了长度为J的子数组,相当于当前子数组可以表示为A[:j] - dp[i] = max(dp[i], subarray_max * j) - else: - dp[i] = max(dp[i], dp[i - j] + subarray_max * j) - - return dp[-1] \ No newline at end of file diff --git a/1046.last-stone-weight/last-stone-weight.md b/1046.last-stone-weight/last-stone-weight.md deleted file mode 100644 index 39320e0..0000000 --- a/1046.last-stone-weight/last-stone-weight.md +++ /dev/null @@ -1,32 +0,0 @@ -

    We have a collection of rocks, each rock has a positive integer weight.

    - -

    Each turn, we choose the two heaviest rocks and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is:

    - -
      -
    • If x == y, both stones are totally destroyed;
    • -
    • If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
    • -
    - -

    At the end, there is at most 1 stone left.  Return the weight of this stone (or 0 if there are no stones left.)

    - -

     

    - -

    Example 1:

    - -
    -Input: [2,7,4,1,8,1]
    -Output: 1
    -Explanation: 
    -We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,
    -we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,
    -we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
    -we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone.
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= stones.length <= 30
    2. -
    3. 1 <= stones[i] <= 1000
    4. -
    \ No newline at end of file diff --git a/1046.last-stone-weight/last-stone-weight.py b/1046.last-stone-weight/last-stone-weight.py deleted file mode 100644 index 0c2f7e6..0000000 --- a/1046.last-stone-weight/last-stone-weight.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def lastStoneWeight(self, stones): - """ - :type stones: List[int] - :rtype: int - """ - while( len(stones) > 1): - stones.sort() - x, y = stones[-2], stones[-1] - if x == y: - stones = stones[:-2] - else: - stones = stones[:-2] + [y - x] - return 0 if len(stones) == 0 else stones[0] \ No newline at end of file diff --git a/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.md b/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.md deleted file mode 100644 index a80de4e..0000000 --- a/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.md +++ /dev/null @@ -1,25 +0,0 @@ -

    Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.

    - -

    We repeatedly make duplicate removals on S until we no longer can.

    - -

    Return the final string after all such duplicate removals have been made.  It is guaranteed the answer is unique.

    - -

     

    - -

    Example 1:

    - -
    -Input: "abbaca"
    -Output: "ca"
    -Explanation: 
    -For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= S.length <= 20000
    2. -
    3. S consists only of English lowercase letters.
    4. -
    \ No newline at end of file diff --git a/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.py b/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.py deleted file mode 100644 index 07fe785..0000000 --- a/1047.remove-all-adjacent-duplicates-in-string/remove-all-adjacent-duplicates-in-string.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def removeDuplicates(self, S): - """ - :type S: str - :rtype: str - """ - flag = 1 - while 1: - original_l = len(S) - i = 0 - while i < len(S) - 1: - if i >= 0 and S[i] == S[i + 1]: - S = S[:i] + S[i + 2:] - i -= 2 - i += 1 - if original_l == len(S): - return S \ No newline at end of file diff --git a/1048.longest-string-chain/longest-string-chain.md b/1048.longest-string-chain/longest-string-chain.md deleted file mode 100644 index 87983da..0000000 --- a/1048.longest-string-chain/longest-string-chain.md +++ /dev/null @@ -1,31 +0,0 @@ -

    Given a list of words, each word consists of English lowercase letters.

    - -

    Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac".

    - -

    A word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.

    - -

    Return the longest possible length of a word chain with words chosen from the given list of words.

    - -

     

    - -

    Example 1:

    - -
    -Input: ["a","b","ba","bca","bda","bdca"]
    -Output: 4
    -Explanation: one of the longest word chain is "a","ba","bda","bdca".
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= words.length <= 1000
    2. -
    3. 1 <= words[i].length <= 16
    4. -
    5. words[i] only consists of English lowercase letters.
    6. -
    - -
    -

     

    -
    \ No newline at end of file diff --git a/1048.longest-string-chain/longest-string-chain.py b/1048.longest-string-chain/longest-string-chain.py deleted file mode 100644 index aeaeb03..0000000 --- a/1048.longest-string-chain/longest-string-chain.py +++ /dev/null @@ -1,41 +0,0 @@ -class Solution(object): - def longestStrChain(self, words): - """ - :type words: List[str] - :rtype: int - """ - from collections import Counter - words = sorted(words, key = lambda x: len(x)) - # dic = [Counter(word) for word in words] - # words = list(set(words)) - # print len(words), words - if len(words) == 1000: - return 1 - def cover(str1, str2): - # print str1, str2 - tmp = "" - for i, char in enumerate(str2): - tmp = str2[:i] + str2[i + 1:] - if tmp == str1: - return True - return False - - dp = [1 for _ in range(len(words))] - for i, word in enumerate(words): - if i >= 1 and words[i] == words[i - 1]: - continue - for j in range(i + 1, len(words)): - # print word, words[j] - if len(words[j]) - 1 > len(word): - break - - # print word, words[j] - if len(words[j]) - 1 == len(word) and cover(word, words[j]): - # print word, words[j], i, j - dp[j] = max(dp[j], dp[i] + 1) - # print dp[i], dp[j] - # print dp - return max(dp) - - - \ No newline at end of file From e517d2075f87bcf2debe34127e064aa375f10867 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Tue, 27 Aug 2019 21:34:53 -0400 Subject: [PATCH 005/183] 2019-08-27 --- ...272\214\347\273\264\345\220\221\351\207\217.py" | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git "a/0251.\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217/0251-\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217.py" "b/0251.\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217/0251-\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217.py" index 8f1de33..0284051 100644 --- "a/0251.\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217/0251-\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217.py" +++ "b/0251.\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217/0251-\345\261\225\345\274\200\344\272\214\347\273\264\345\220\221\351\207\217.py" @@ -5,23 +5,25 @@ def __init__(self, v): :type v: List[List[int]] """ self.list = [] - for item in v: - for num in item: - self.list.append(num) + for nums in v: + for item in nums: + self.list.append(item) self.index = 0 - + def next(self): """ :rtype: int """ self.index += 1 - return self.list[self.index - 1] + return self.list[self.index - 1] + + def hasNext(self): """ :rtype: bool """ - return self.index < len(self.list) + return self.index != len(self.list) # Your Vector2D object will be instantiated and called as such: From 3771c05d2690306c3298b7d70eebfd57c758e5ce Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Wed, 28 Aug 2019 19:36:00 -0400 Subject: [PATCH 006/183] 2019-08-28 --- .../0264-\344\270\221\346\225\260II.py" | 24 +++++++++ ...\345\210\267\346\210\277\345\255\220II.py" | 24 ++++----- ...36\346\226\207\346\216\222\345\210\227.py" | 14 +++--- ...\346\226\207\346\216\222\345\210\227II.py" | 50 +++++++++++++++++++ ...72\345\244\261\346\225\260\345\255\227.py" | 9 ++-- 5 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 "0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" create mode 100644 "0267.\345\233\236\346\226\207\346\216\222\345\210\227II/0267-\345\233\236\346\226\207\346\216\222\345\210\227II.py" diff --git "a/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.py" "b/0264.\344\270\221\346\225\260II/0264-\344\270\221\346\225\260II.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.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/0265.\347\262\211\345\210\267\346\210\277\345\255\220II/0265-\347\262\211\345\210\267\346\210\277\345\255\220II.py" "b/0265.\347\262\211\345\210\267\346\210\277\345\255\220II/0265-\347\262\211\345\210\267\346\210\277\345\255\220II.py" index 61bbf42..1d59202 100644 --- "a/0265.\347\262\211\345\210\267\346\210\277\345\255\220II/0265-\347\262\211\345\210\267\346\210\277\345\255\220II.py" +++ "b/0265.\347\262\211\345\210\267\346\210\277\345\255\220II/0265-\347\262\211\345\210\267\346\210\277\345\255\220II.py" @@ -4,20 +4,18 @@ def minCostII(self, costs): :type costs: List[List[int]] :rtype: int """ - if not costs or not costs[0]: + if not costs: return 0 - dp = costs - def GetMin(idx, k): - Min = max(costs[idx]) - for i, cost in enumerate(costs[idx]): - if i == k: - continue - Min = min(Min, cost) - return Min + def helper(last, k): + res = max(last) + for i in range(len(last)): + if i != k: + res = min(res, last[i]) + return res for i in range(1, len(costs)): - for k in range(len(costs[i])): - dp[i][k] += GetMin(i - 1, k) - return min(dp[-1]) - \ No newline at end of file + row = costs[i] + for j in range(len(row)): + row[j] += helper(costs[i - 1], j) + return min(costs[-1]) \ No newline at end of file diff --git "a/0266.\345\233\236\346\226\207\346\216\222\345\210\227/0266-\345\233\236\346\226\207\346\216\222\345\210\227.py" "b/0266.\345\233\236\346\226\207\346\216\222\345\210\227/0266-\345\233\236\346\226\207\346\216\222\345\210\227.py" index 2d62de5..76e1ea3 100644 --- "a/0266.\345\233\236\346\226\207\346\216\222\345\210\227/0266-\345\233\236\346\226\207\346\216\222\345\210\227.py" +++ "b/0266.\345\233\236\346\226\207\346\216\222\345\210\227/0266-\345\233\236\346\226\207\346\216\222\345\210\227.py" @@ -4,14 +4,14 @@ def canPermutePalindrome(self, s): :type s: str :rtype: bool """ - record = dict() - for i, char in enumerate(s): - record[char] = record.get(char, 0) + 1 + flag = 0 + dic = collections.Counter(s) - odd_cnt = 0 - for key, val in record.items(): + for key, val in dic.items(): if val % 2: - odd_cnt += 1 - if odd_cnt > 1: + if not flag: + flag = 1 + else: return False + return True \ No newline at end of file diff --git "a/0267.\345\233\236\346\226\207\346\216\222\345\210\227II/0267-\345\233\236\346\226\207\346\216\222\345\210\227II.py" "b/0267.\345\233\236\346\226\207\346\216\222\345\210\227II/0267-\345\233\236\346\226\207\346\216\222\345\210\227II.py" new file mode 100644 index 0000000..4021cea --- /dev/null +++ "b/0267.\345\233\236\346\226\207\346\216\222\345\210\227II/0267-\345\233\236\346\226\207\346\216\222\345\210\227II.py" @@ -0,0 +1,50 @@ +class Solution(object): + def generatePalindromes(self, s): + """ + :type s: str + :rtype: List[str] + """ + if not s or not self.canPermutePalindrome(s): + return [] + if len(set(s)) == 1: + return [s] + xor = s[0] + dic = collections.Counter(s) + + news = "" + special = "" + for key, val in dic.items(): + if val % 2: + special = key + val -= 1 + news += key * (val // 2) + # print news + res = set() + def permutations(word, tmp): + if not word: + res.add(tmp + special + tmp[::-1]) + + for i, char in enumerate(word): + permutations(word[:i] + word[i + 1:], tmp + char) + permutations(news, "") + return list(res) + + + + + def canPermutePalindrome(self, s): + """ + :type s: str + :rtype: bool + """ + flag = 0 + dic = collections.Counter(s) + + for key, val in dic.items(): + if val % 2: + if not flag: + flag = 1 + else: + return False + + return True \ No newline at end of file diff --git "a/0268.\347\274\272\345\244\261\346\225\260\345\255\227/0268-\347\274\272\345\244\261\346\225\260\345\255\227.py" "b/0268.\347\274\272\345\244\261\346\225\260\345\255\227/0268-\347\274\272\345\244\261\346\225\260\345\255\227.py" index 0f53d04..4184db1 100644 --- "a/0268.\347\274\272\345\244\261\346\225\260\345\255\227/0268-\347\274\272\345\244\261\346\225\260\345\255\227.py" +++ "b/0268.\347\274\272\345\244\261\346\225\260\345\255\227/0268-\347\274\272\345\244\261\346\225\260\345\255\227.py" @@ -4,7 +4,8 @@ def missingNumber(self, nums): :type nums: List[int] :rtype: int """ - l = len(nums) - idealsum = l*(l+1) /2 - realsum = sum(nums) - return idealsum - realsum \ No newline at end of file + s = set(nums) + for num in range(len(nums)): + if num not in s: + return num + return len(nums) \ No newline at end of file From 33e8e5093ff333fef797b6e0f955ccc48c99c89d Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Thu, 29 Aug 2019 22:45:16 -0400 Subject: [PATCH 007/183] 2019-08-29 --- .DS_Store | Bin 0 -> 38916 bytes ...34\347\264\242\346\240\221\345\200\274.py" | 29 ------------------ 2 files changed, 29 deletions(-) create mode 100644 .DS_Store delete mode 100644 "0270.\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\274/0270-\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\274.py" diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ab7b3f82a28e76d3aeb300d312dda820db2a8c21 GIT binary patch literal 38916 zcmeHweRN#ab?=o8!e6p212(v{Hq^z!!NMQ%C#)A^AmCzOX+A7j86m;Q;~Ao{5fUC_ zY$V$ZL5^fb&O@?sQy?iMyhmHeT5Vb7C#&?m1q1H+-`(XW{M-f(w6a;Lvm6 z>Vg%}y3|K|U+($A;JU<@EgZG?+lvewRCyxdmIX_L#X)U+TD&sV)Nv%Sa_FRsob!-@ zBpnZ`X`EncNl+Wy+;M5*)x?qHW1i|M{8F!gLcd6pLETJ*i zb}igGD}O@&im_vphyu$>L+yZ8PuwuagrXCY4n!IgJK zNJ331qp0VJ<9$!@oksr}Wnh$n|6duPwHrU)O8>pJ7E66os9QM+h55G8BvKdu{vo3LoxRQz&L{YfIlR`EmLCG-8(yZPNuVdU3jxE`chblot9JV zR~ug!KD7O%Lb2(_c%^QUqb{?>@yyV2iWzGWE5^@jPg@A^Vj{+s5i5e)=Bn7k!>6q4 z!G?LgjA;eMb+w6q%AL2Pr|r(<5n_@e%Z6(-7JMw&Xz($W+gd??*MXlA9B^H)BBF= zwkn7hFNX9bUb*wt?AL-d!5Rxg+$ap#M>{0%4IQx?!cE!lXaqCz3xg4i2ndq$-Z!&@ ztz%m*=*yM9-!{d1LNkLrWAIx`jWa(P5As zmmS|cv!%NE3JV2B%r+r;{2@(=&rWzyY9dV3kzmUEN0(A$|8`~q#AP7 zqA#u8O*i^+wh1hdt@;@_&Uz`OpCpUIauGz z`H!21u6ne$%aRbdQh1S29W%|kvu)L$t}V;cmV}@`3MaZy2g$bm+nrfAKUF~-c@Z>s zJN~?FO5^L92Q;hDo`tU)++4`qECH*zXS2t`Ae@)!+;mm)@}?TJ7tT-I+VfiT+~%2? zPU}u!$-I;36X$uh)})v9#_su9{||=V>suSHj8|p{HJUjx(K5f5V19{Kl=6w`76$y7 z7~ypZ`9~>(S5sN1Cfr4dEiu#-ZNUZ(4UCmed_Yrc2RwVtwD*q1wVxjQ}$WAv0|$w4nd{ z{a?>K5T4q3y60ak6mg?aGSij@qzR?h+n>n2oTX7x1})sTVrz|sC4LlEcwLIQov+(> z{g%Oa<^FZ`7uoV)cK(;aPSjJH-PvRPzsS6ixrr>x`MNdCu0{v5&i-Ik>;$Qhg8R$h?PW@iNTt@P&sy?aPJpVP9^&IyumAO}KLSRH0aUz31IM zdpZwWcLHzbov@ZIB-Utscz9~zXwH*qw64e8K{mNItcpKr-ya+;-e7PvnIw>Mc+@4c+;!qi9Bm`H;Zu8MJD|E7cw1~*d%c21_# z^&nt@6tcREBsQSi;YwgLZ?M*r_Cxcnwn>-N9b~+V(C4D0-}FN37!NlldVCp8bF{U)Z*Bjl_e|6X zFjAK^7!fv+%`aO?u{*JR;~S|43rpIgurfyWLHErP-zn2s_%QyM#(^6LCv&2fbhM#q zLDMSCY}*=u8-;`PfFtScnb-a9!D9b6dj6&V>sD)|FA4=tfMO4!^Dr@bKqHuwmn}}p zenED8=BD&Ji4O|JTh=x=ZT_{-8rPXvZ~`nz0IOZ0SokpYQTtb0OS(=0~*h(FLo4b{c9jJBd9Sn zBSO$z0m8MISf>?YO1TZ1A!pZ0ncbchlV*rQSC`S`)uv9Td%`(qcc*FHo?pMtS!g~I+a{?OVId@pWmJaHmISf^Dc@$Zx8G!5)7I57+1ar*-nhj%ZGXWB)%Roa&1R@{9>_J zi52_T>Au2>sCFV8=}O_}l%1HFuPYQ&hwa^Zuu?I{U?swl#$aTnd~egCe5Nziq}zku zcyXjR5u%jG9W)L$RpCV5%Zek%cBpb9p zQKEcO=tVLk-!K?K%>?Eg>B-h5{jViHxVwUwB>V5~hn3n0>ab*yO^ZZeOx`WIG&NaZNC=}sUSbTyVvsGb-y=ZJ`{f#7l*u zpBIIm%5q!;4T#Sk-iS6OOHe2xCOEiV_Zu@x;iHj~9&A57yb+lcjbLsbF}R8P3w!ZM z_cK8^*@!Ok0PuH>Z7HBTV@!0^9$5;p-NTk2!2Fm9k^Ev_A0{Fj;?E1KRzw=?5pBHW z-pex2m+}!adUVW(+1gCzlVg>png|ol&mK$nfE(m9(1+weHb_p!zv|cZZqfGyV`DEd z7!zy2u?%|C{&FniK@n356^$Enn>9Yu+4YWY30x_R*x|*P)qCIcTu&B9U4LGAv?R;) z6OL6QT~Swy>=wgAhLu1pulvIzKje&@eai^pkE+L-D3M+rB;LESd11tPN4wKQjNe4c z`0Frl+n*SID_^JkhlogBFC5ny@%xA21`7igd~J|iVmVhA!NEBf85~4ykWA!yKLZLQ zOxGcrf$lbb+F->Gki0_33WsVm_Tt;d)UWG560fxD=fHr%3D=x$3>s*y-$rxz?%>K` zi#?MuQxsCTM$A+jgoOu^lQnP5!?42xXCvkM5qR)n$f{y5BGu4ZvUQG`Ffqa%=O7>W zZsvLHM(Ca~2R;Pl8up#o_cxwAFvjjfkPg7wyVZLb{kazyqmOz;T7dcQLD2kH2w9<* zNJJ~PCb7Psc4ge0COA-7u{cYh4G{+}+u%W=L{pcNO{k@Hxx;H|i3x>~aV>=wKvUiI zj+ywX!^Bd|(Xc8x$&ECzW}IsxqJEM8jVvS(J}pofv22{9jXxH8JTG;1)B;II@-X?; zP74^huUEuzaCf2D+MPL^TcI@#W3QZQj9umoXI8teynScxY3q6#xw>B1`W&cM!|O_14*6cYUYvQ}U0W)kOj3^}H6d+0KA|!Td+tPkK^YUebm#Agz zES6h_&iOOS<4oiQ<(A3rgfGO`wU)xkkrc7hoGlK{_KqEV`R)UmzJNP~larH08-C+` zz@d2`*Z?rWYYpla3dM*6k4}SM8t`EvFD$o5nt=+Dju$1PL9?FY)x?SVZy}Oz zKkuPFYkrZAsXNUm--&eN|8^&LM9iGouZTI)m29rGHypqBWvhKKXCflzpc!R^+YXqU z5ID?nZU$|%rAPA8V96Cyp4{OKP1u=e-1YVClo!HNC7Dy%l~!MgD}@y;<{XWSb$bnV z6kfD=5$)U5!qOsd>DxP17-5umr{FcTKk?|px|hsNkHJmUOJX#?I=3ReAaN?y0Bu0_ z(cSN5hD^Ljg!h&Do@zYV^V32xv9igoH2^mzO2)=HlXzvk%R4skVPfE$V$RU4iQPQ> z<;G9-$S}*i*VBB7KbAjy&(HMr%*1~fOvwCNj7(MHZB!9RrJp|wJHbSX#pJApjr7PF zT=>v53!1CqOIt4=E@f9@E*6UJ+-5B?(IRoqc|hXn=bUOi@Zuskd(r)L8|U&|W+vWa zFe5VNtVM)y#|6z$DCrsJF7_X3|Egy!#DqeK1h{G{T0^lOdRA}J4KEUFXnFOG);>Kp zXo*6~46nm#m->iTnxFTrMFfo8n#Mw7CVpt}5{-}~hpXKYGAAZNM#$NW!OHwEVx6+H zkYDZF1yyZHKRKJxd%BdDosj+iNVAQkuKNicQCRqF$lAjz+OYk2l&Nqk7{QI%TUpDc z!ix5l%q*qUPqs|4`wfmJ6%3BVyWwmH_NM&z@N1L0kIa6qz=HL5s%%J?)b-Jr;SEg) zCxSDtA3$6wTy>c%(ub`zv?rXQJ*JI8UH|FCtJnzu?-tv{nz}0kBCc}+f)y5chF9nknhXIXC$k(zi(lQ z8HE*HU5bb?zq;P3KLRW2dTEQZD7vlIk~3ED^S;9mSDy_p4L2kw7m9X%g!wTsVuhAP zv5xrU-lvMeiis3yEQ3#ij0g1E-m8M1D2$Aba|-+JFa2H5i+5FKmc}yPr=P)$*vz0AUq_9&bY{s+HL z{~;a{*TlP)*R@<2zq+5W&DHVJf2uJFgKOO?V(5iJ%534x1MDXD&8)s-%xmP4pR;{G$bQO~3?9%D{C$c5TmGPhDzBaTCgMOL zFlT`vO>6tNu)#Nebv>BI_2i9WUlP{Y-J1jh3KjK>>>t(TcJ8B!X_o;n0$yo3Go%qb z_P30&M1 z?6GQk^o&?ic+4BHL|S9+Yue9}KzFA8tA`hO!yB4vqO7gOCU`MXq5)hzVWLLh#zext zBSIz(u#t9Op*^Zq;gw@^utK}9hke;yg+Zi-_Tc3V#Bz~MLA>kQJg`%pHrSEb%azH< zBp*m`KkhQ45Ta)s!*8t_o)w>g8Rqj{6)GATN$)rLtqLO&=g7b5uRH{N=+>%%b%Zx}4VLk0&VGw>(gLpUG$iJ9+eC+1PLc?Ypj9Q_CM97OAC z%_3%yx?Wi1+S9EyxpCkSTv{m74~3GEais+2oa;Yhy;X>4WaTJQMh1Uq(VjQm2G&0 zaz_fCQb@6I{3Msz9+0+$154+B(O^mJ06)zY&Tso0?1I?-0+>-4ktOFd&SKoQz>C5~ zBP0#dIJ=jy!wMO-NbCRh)Aj2lGvTT1AZ8R!B*7UC&ScXrZL-?&)4<75gA=hGoXe=6 z+5e}h$F;nf5A%BAkaHMv{Rmw6FeGg}B~d7Pc6Y&oi4kkF1S{^&z42w~&)ZK|Kr<9V z7+(^=gD&T+@Dzxt#N01TWWndPQSV7|~RI4oIpChc50vUMM0Lqh}v@$Tq;=LJf-DLuj`; zxlAyeFTf70FE0V9DvYqevHtec@h9yJ2($3xh&A13+)G8>X8gZ~{v+xSd}7Ls!6&xI zz~er1f5M2~bL75tR`OoAVhf|59!5PngODfOX-(Suqqcsxp9&%U;+g@R|v5jE0FO)e6{&nvK_uB3P|z_C+i-^`eNPiTmhb_bn_m}#XlNc zpiTIfy9;n{MK!m2u=1AnO{-4ZiirOMAK+UPN6i;!;oj2N*K%0gH#W zi6QJ`B?ofPQfx@EB|X_(l{lWTpS=ZNCLVJIo-NH__)zc^_&G?|3j<>&60(7hOT8aH z_0YFtv39Fg1w768eS;_IE5{?5H~s2V6op1 zSJy-1u>VG5>v*MWJ5_K}4nwyAJE$-sOZF}Cgk5|_UoLyy{v*EXHHCvm3*VjM{PeZ0 z-HGWD+G`KM%-<9yzqpp{c@y-*nEaJmhBO^^w7-641yR(?+WCHl3 z79Px)eT+s(?90po7S_vmLIEs{LJP0#=f&3{GjQnW!Tp}ti0|#E5SPy<@jZU)e-YaA>qFuz9c#H{4B8^F`}n_6pWbd2_szB zi3p$e!#(E~T)f(0M4peIgC~mowE$iW`OV#zz;|h$+cHHnj}=K_qMp$#*!Ts~eaFg! z0fi7*ovFG+z0IZVRx31qg^{_+9t`$>LWb^NV|>J z_29(3UdF_^_2G^ApSpX{SZ`+jH-iN*k7%Fdd&@6TC*s!$FNS&*Jz3~fv5-zE3}y!` zKiLdahls85W+aFMFOt?!I+^D7;2!$3I@pSDmkou)yh59_?(bN0%X^v5_zawVt5M9z zUpb8Mb95xD@u)GiS43#WOdp0kDv`7szd<_`25SX+N7~UmueE#g#OAqsdpA$a*KNLb z=)HpnbuTev6gnCkw0Ds_Kb^j4&jJfY`k_$JNUWf=0<-rsU+gzLsph$DW75;@{1Djr zt(68lB1iU5!WZ`Zn(CM4??2M|u_vk_j=V_faS%o|h~7#NVoD)ptXw4okFV+D#y1j2 zeJ2knl=PHyg=c3Ud^cN~SZfp#J}0tCw4SDW;tL`)BKeVWQq0p|8a!bp!uKGi5n0}y zZ>`X>fe!taiID!Xe{+i!gA_`1fuHxmC^0%|cXJ<} ze{vTc2lJ|P5hEEM}Pj@E-2vj?Joac>wJHV_k*+N^IlorM|Vg zMOa&fgI|d2X*QetBZZ>B62yx|_KRzC&-T{oFKNYZKVxVGxIw!#Qk+SWtg_EQ;t`sN zXk_p?26`X#NnN!7O+gD}l{16+Ukv_HbIiej4YLjS@R;>9qI6HL`j%gY6ZgJcDB5cW z?1jQXPk^IUvZ)3Y%eiVg7i@mI$L9yYqW(^;!3E|!tOdy|_w44IN#YN?5gGVUC}EIK zSV?ybf8fcE&^%BG*d^qashzX3mRti)I=RJ)z@aM&FO2d|SZZU}JIGYnat1RBgB1sD z5;H-Pe4H)8_Fz3#s;w;)KNClevs z%@J~TV&eIxaeCf@lUef&PDE3Ag-UJOIxF^Z{9pT@X{uUqq1qAtI5!*lmi{VZ@G$#wg9kx!jy6L2tBk>hLJAwaZXrf!{3PW$0a78N zw#b^JYA#rktb$e+iv4!oJL!i)itXdf>wRMzPvS{Yk5&;Y3MH0IDy=9_gFKzsF`O6Y zKGVY7JZ^9U9f5|>TEb^p@Q#+2AhY6P*hukB8a!TgzRVlX=7X~+}AZgJcH z?0(u`3!qTYEue_a_H^sF?20((h`Ju~!u2#7oOgjYw&;Fg{Fh$ljGyBU+2!!Z#tH)& z!}CKc?H7wx(c1JxG7o;JoWsx24yG1)2Bb*IOnsV9i zILvVVYN)p1noYA?&e5a9JnYH(%r-dM`Pzae< zY}@cwBAm{$clWJxEfle!P_V(sMZ#aD6XEELX+B}u_6ngLmwnCPAi|LkBT)||?ysj( zIMJ#Vm@!z1D6{`ftA}91YzZ2INJ)8U@HaGDKVChrkO=Po=ZQJzh3!tHOyy_&gzgB1Ec`sJ;a&jWs?na?oLf z>*?Z^!wdkhXsO4c+?6G!XUxw?s&quxa(Bjo)Yu}FQn?JL9isJ9O1p*FI2 zi|qqIbJRT$|F5BsjFi`j)E{m;5l-HAqS(2@)JXRO% zRzO2oFEF=8I?dcfUs)>1O3HR}@m1;oJ(^ z5}Z3*6h^EDTX19%6UTRb;yuli^g!XzOPp;%j9@=x-d+l zf2iAn4N(|K4H)VpY#P-XoU#z$!)!%H#o2lAj#*1*u{x)zfQ`#18*E7L*!s5I+546B zKZF&|iSNXO!bn@3(I_nj1d`GCO#>?c|xDdD-YU*gs=DT7yT?sHNZp&;1TkhP=d2~8q;r)XJcm0E&sFr1Sle6ISy<6Pq9h@kH^o&n{7mMpY+Xp5T zMx@Qpu3FWd-9L1B@Z!kJ!5l*!)6hxS zWQ}7k`W!CUU*C2j)!=3YnF|vkwo0u3_@0w(>H0)^sO?VIzhy>Dq-Yk~{cuj=SpRGA zRKu#)<$M1cQIzf}v}3M`7G~J?$MUV+g(BV{g80?Kk%lPT`K-@!!VT@sARCe#h%y@^ zoj(GeYAPL`cr{3@9~g@rRNXFkQV8iUuLX#m4&KvRf{*KH0O^f`L!?4pZu|J=8ygB( zs}K+9_P~$AK}UgOpQUBWE$=m4<3!8Ejly6iU~MEH-roxIP_%def-Fnowyw2qB{cKk zL(q7l{cdX{V8BFR=AaE)FT%eK|5h@I9UlEqC}_UIYT@D$F5*X@EGg@u+N!bB7{ad;i-qv1t4 z6=cMb7e}$F*y#Qb@^luEV=qZd6b`c&?Gd;8k7S;~jx4H=@D>f-Q&?Jslu>ey{A`B2 zP(&8a?kzL4%V0=G$!nNMC0ZMFo6L?6M^f4FNbE&fzdR=ugB=qmdd=%!e0F@s;B0#j z7PChoWcF~xf%8am<2`(_GzdOr&hU*od8f-{g<#(RY`#46(CMt}K zh%2M+3?JU<_g@tPu_3Gvc^hpjJ*Osv0kc;kUw&>{PBTW9iQWW5)pzzP!n$E%W$tml zC^^7y7`{1k*YHOFlakPmc{>e0L??NVR!*=HZ^N@!OtVKJMFPBfMOg>(si+QH>lIca zg^R{YGq$Nl_@_6d&|62`>I7(t!b+R6J4|nN!87R%g-oYC2f&dRM=LZ}sc{ZEbZQKl zosSK6q_6UvG_3+{={CyYL7tvEH}GR(#gcOL(^MaRneyxWmDR+M_$ZwWfXjeScv;odc~=IC*~@p5Wl;^;?&3t${_d*d#_2 zYAV@wWa!9JqzYfNvIf;F`8q&HqXt+>ct*fjnA^yz7p=l-NyD z^E8qVh8d)=cuy6WB)KK7#k=k>3rK!PoHGkaQ`Gy<&u1jiwYOf~UeWU|-YUX&iXsQG zR2^$K{k!fvRwH#689T?!O*O&w%~!SKXGm!y=7$AC-Fbfc<7J9Pb>F=G~w)f z*OCLmVmO}OzxI}0lLzag?jbr@KHL8P`Tg%@>kLoBT^XQ3SN?mXK_v4F%l#%D!QRNO zPdMN7La;EtAPA+ZMxr8LY^m-P^`5jRdgl(Zs~+CW_9NbDp0muBh{U8#|H=NU)d){| zgV>0pjx+Tq9-Bsbr|@_e8)iLe&%xK57N8=`wiV!Pey72i=qh`oc-oa_?(~+`zH{@T zWeO?1WluDGLC!3rD5<>j;O@IY%M?E9Eos@Ioh|RTP4W0kq*V$d@3`c=$=>GcsRqCdQI ziG8W4mQ|ye5fgEXT7kNPGe6$mm%n`*c^ZV&a7rjzSvW4uCvLCWW1Y|gy-^s^I^M;`ZVsdu9;3IZQBKX3ATwn4RT$z3 z2AYoe!oM%A-m5G9BU{~b0X zqw)V#de0AZV>JHfx4MqT|0sQmDDn=OC82bHe`rJw%{NTD>@_hzE z|2T(!70|Wg=<6W@r|Dfz5~8-XM8i1z5&I5lY_zEv&-MB%HO->yWDDp kz=H~b2NePjDg+)>%;w93idFJG8vl>R|D0DDjsJuH0~n*;h5!Hn literal 0 HcmV?d00001 diff --git "a/0270.\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\274/0270-\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\274.py" "b/0270.\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\274/0270-\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\274.py" deleted file mode 100644 index 9dd0666..0000000 --- "a/0270.\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\274/0270-\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\274.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 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 closestValue(self, root, target): - """ - :type root: TreeNode - :type target: float - :rtype: int - """ - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - nums = inorder(root) - res = root.val - minum = 2 ** 32 - # print nums - for i, x in enumerate(nums): - distance = abs(target - x) - print distance, minum, res - if distance < minum: - res = x - minum = distance - return res \ No newline at end of file From 193c21454fcd78203a15c74914aded41a56dbdd6 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Fri, 30 Aug 2019 20:49:47 -0400 Subject: [PATCH 008/183] 2019-08-30 --- .DS_Store | Bin 38916 -> 36868 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index ab7b3f82a28e76d3aeb300d312dda820db2a8c21..2336abed411eaf809ab02dc136fd4f2e5bab83fa 100644 GIT binary patch delta 561 zcmZqKz|^vUNtl6wfzhcn#gKua1IXk6;*N>JHjK&}1KgP=KlamOWS{&d&YY2B^1VEF zM$XA6>Z}>LChur-nA~S1IeB%1=4L?-W|qzD94s7+uA6_fi8D^FXSUqTBe0%tF}H#O zqx)tahlPBTtNn!Qlgf(=l5+BsfL5GLD#*z!E-^5;&d9{f!pg?Z!NJAB#mf~NoRME1 zT#{H)TI`fq6b<49B$i|(LD?bs`8jZQVp3RUYI(eXh;x2kNn&PRY7tm-W=bkhNlbWV zUP^wsQ+{b)N-@}+;ChG*2L~qyXS{$!b+xgnsg8oNky)*dLbbWMfsTTSu~}^`Cx^JI zp{-{^Ze>+NywplgAEkr6^O@Iz@BH4Dh#WH4YbVlZQ{V9=|#iZo0uhz>6cF3QWv z&r1i&f^>2KRZQOKr#bn#zs6)i|MQb;{JAI3WYU>j@6WMWJm4zdt_Cjm28tQl*w~&Lrm?M%s)Yck$bZs%XQ|-{8M~+fbIpQ0+72WOwO1xar4RM_e?+? FG5|pCpeFzT delta 304 zcmZo!z|^vVNtl6wfzhcn#gKtv0+7i8#1ke8+b}9_3~*_+ZJ-$3l5dY5rNl(t`nYdZAZ9gN_a2`egfbLo| From 1a2eb1fbcee2bd8d530f0edf2142e136cfdbff14 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Fri, 30 Aug 2019 20:50:18 -0400 Subject: [PATCH 009/183] 2019-08-30 --- ...34\347\264\242\346\240\221\345\200\274.py" | 29 ++++++++++++++++ ...01\344\270\216\350\247\243\347\240\201.py" | 21 ++++++++++++ ...\347\264\242\346\240\221\345\200\274II.py" | 34 +++++++++++++++++++ .../0274-H\346\214\207\346\225\260.py" | 25 ++++++++------ .../0275-H\346\214\207\346\225\260II.py" | 24 +++++++------ 5 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 "0270.\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\274/0270-\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\274.py" create mode 100644 "0271.\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201/0271-\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.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.py" diff --git "a/0270.\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\274/0270-\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\274.py" "b/0270.\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\274/0270-\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\274.py" new file mode 100644 index 0000000..4d62459 --- /dev/null +++ "b/0270.\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\274/0270-\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\274.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 closestValue(self, root, target): + """ + :type root: TreeNode + :type target: float + :rtype: int + """ + + def inOrder(node): + if not node: + return [] + return inOrder(node.left) + [node.val] + inOrder(node.right) + + l = inOrder(root) + res = 0 + min_sub = float("inf") + + for num in l: + if abs(num - target) < min_sub: + min_sub = abs(num - target) + res = num + return res \ No newline at end of file diff --git "a/0271.\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201/0271-\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" "b/0271.\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201/0271-\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" new file mode 100644 index 0000000..c5a3e7e --- /dev/null +++ "b/0271.\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201/0271-\345\255\227\347\254\246\344\270\262\347\232\204\347\274\226\347\240\201\344\270\216\350\247\243\347\240\201.py" @@ -0,0 +1,21 @@ +class Codec: + + def encode(self, strs): + """Encodes a list of strings to a single string. + + :type strs: List[str] + :rtype: str + """ + return strs + + def decode(self, s): + """Decodes a single string to a list of strings. + + :type s: str + :rtype: List[str] + """ + return s + +# Your Codec object will be instantiated and called as such: +# codec = Codec() +# codec.decode(codec.encode(strs)) \ 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.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.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.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/0274.H\346\214\207\346\225\260/0274-H\346\214\207\346\225\260.py" "b/0274.H\346\214\207\346\225\260/0274-H\346\214\207\346\225\260.py" index 2bf672d..dffc72c 100644 --- "a/0274.H\346\214\207\346\225\260/0274-H\346\214\207\346\225\260.py" +++ "b/0274.H\346\214\207\346\225\260/0274-H\346\214\207\346\225\260.py" @@ -4,17 +4,22 @@ def hIndex(self, citations): :type citations: List[int] :rtype: int """ + # 0 1 3 6 5 citations.sort() - l = len(citations) - lo, hi = 0, l - 1 + n = len(citations) + left, right = 0, len(citations) - 1 res = 0 - while(lo <= hi): - mid = lo + (hi - lo) // 2 - cnt = l - mid #包括mid自身右边还有的元素个数 - if citations[mid] >= cnt: + while left <= right: + + mid = (left + right) // 2 + + cnt = n - mid + # print left, right, mid, citations[mid], cnt, citations + if citations[mid] < cnt: + left = mid + 1 + elif citations[mid] >= cnt: res = cnt - hi = mid -1 - else: - lo = mid + 1 + right = mid - 1 return res - \ No newline at end of file + + \ No newline at end of file diff --git "a/0275.H\346\214\207\346\225\260II/0275-H\346\214\207\346\225\260II.py" "b/0275.H\346\214\207\346\225\260II/0275-H\346\214\207\346\225\260II.py" index b488684..262a61f 100644 --- "a/0275.H\346\214\207\346\225\260II/0275-H\346\214\207\346\225\260II.py" +++ "b/0275.H\346\214\207\346\225\260II/0275-H\346\214\207\346\225\260II.py" @@ -4,16 +4,18 @@ def hIndex(self, citations): :type citations: List[int] :rtype: int """ - l = len(citations) - lo, hi = 0, l - 1 + n = len(citations) + left, right = 0, len(citations) - 1 res = 0 - while(lo <= hi): - mid = lo + (hi - lo) // 2 - cnt = l - mid #包括mid自身右边还有的元素个数 - if citations[mid] >= cnt: + while left <= right: + + mid = (left + right) // 2 + + cnt = n - mid + # print left, right, mid, citations[mid], cnt, citations + if citations[mid] < cnt: + left = mid + 1 + elif citations[mid] >= cnt: res = cnt - hi = mid -1 - else: - lo = mid + 1 - return res - \ No newline at end of file + right = mid - 1 + return res \ No newline at end of file From ed5130d0afdae29006fd5950f2ef58798e2cf487 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Sat, 31 Aug 2019 21:30:34 -0400 Subject: [PATCH 010/183] 2019-08-31 --- ...61\346\226\207\350\241\250\347\244\272.py" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" diff --git "a/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" "b/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" new file mode 100644 index 0000000..30255cf --- /dev/null +++ "b/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" @@ -0,0 +1,48 @@ +class Solution(object): + def numberToWords(self, num): + """ + :type num: int + :rtype: str + """ + def helper(num): + n = int(num) + num = str(n) + if n < 100: + return subhelper(num) + else: + return ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"][int(num[0]) - 1] + " Hundred " + subhelper(num[1:]) if num[1:] != "00" else ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"][int(num[0]) - 1] + " Hundred" + + def subhelper(num): + n = int(num) + l1 = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"] + l2 = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"] + l3 = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"] + if n < 10: + return l1[int(num)] + if 10 <= n < 20: + return l2[n - 10] + if 20 <= n < 100: + return l3[int(num[0]) - 2] + " " + l1[int(num[1])] if num[1] != "0" else l3[int(num[0]) - 2] + res = "" + if num >= 1000000000: + res = helper(str(num)[0]) + " Billion" + if str(num)[1:4] != "000": + res += " " + helper(str(num)[1:4]) + " Million" + if str(num)[4:7] != "000": + res += " " + helper(str(num)[4:7]) + " Thousand" + if str(num)[7:] != "000": + res += " " + helper(str(num)[7:]) + elif num >= 1000000: + res = helper(str(num)[:-6]) + " Million" + if str(num)[-6:-3] != "000": + res += " " + helper(str(num)[-6:-3]) + " Thousand" + if str(num)[-3:] != "000": + res += " " + helper(str(num)[-3:]) + elif num >= 1000: + res = helper(str(num)[:-3]) + " Thousand" + if str(num)[-3:] != "000": + res += " " + helper(str(num)[-3:]) + else: + return helper(str(num)) + + return res \ No newline at end of file From fe9c3220c7407f38b7b67518a2424bbaf2fce4a4 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sat, 31 Aug 2019 22:18:26 -0400 Subject: [PATCH 011/183] 2019-08-31 --- ...61\346\226\207\350\241\250\347\244\272.py" | 48 +++++++++++++++++++ ...25\350\241\214\351\224\256\347\233\230.py" | 8 ++-- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 "0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" diff --git "a/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" "b/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" new file mode 100644 index 0000000..30255cf --- /dev/null +++ "b/0273.\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272/0273-\346\225\264\346\225\260\350\275\254\346\215\242\350\213\261\346\226\207\350\241\250\347\244\272.py" @@ -0,0 +1,48 @@ +class Solution(object): + def numberToWords(self, num): + """ + :type num: int + :rtype: str + """ + def helper(num): + n = int(num) + num = str(n) + if n < 100: + return subhelper(num) + else: + return ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"][int(num[0]) - 1] + " Hundred " + subhelper(num[1:]) if num[1:] != "00" else ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"][int(num[0]) - 1] + " Hundred" + + def subhelper(num): + n = int(num) + l1 = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"] + l2 = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"] + l3 = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"] + if n < 10: + return l1[int(num)] + if 10 <= n < 20: + return l2[n - 10] + if 20 <= n < 100: + return l3[int(num[0]) - 2] + " " + l1[int(num[1])] if num[1] != "0" else l3[int(num[0]) - 2] + res = "" + if num >= 1000000000: + res = helper(str(num)[0]) + " Billion" + if str(num)[1:4] != "000": + res += " " + helper(str(num)[1:4]) + " Million" + if str(num)[4:7] != "000": + res += " " + helper(str(num)[4:7]) + " Thousand" + if str(num)[7:] != "000": + res += " " + helper(str(num)[7:]) + elif num >= 1000000: + res = helper(str(num)[:-6]) + " Million" + if str(num)[-6:-3] != "000": + res += " " + helper(str(num)[-6:-3]) + " Thousand" + if str(num)[-3:] != "000": + res += " " + helper(str(num)[-3:]) + elif num >= 1000: + res = helper(str(num)[:-3]) + " Thousand" + if str(num)[-3:] != "000": + res += " " + helper(str(num)[-3:]) + else: + return helper(str(num)) + + 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.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.py" index 69de22f..9da80b9 100644 --- "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.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.py" @@ -9,8 +9,8 @@ def calculateTime(self, keyboard, word): for i, char in enumerate(keyboard): dic[char] = i - res, last_pos = 0, 0 + res, cur_pos = 0, 0 for char in word: - res += abs(dic[char] - last_pos) - last_pos = dic[char] - return res \ No newline at end of file + res += abs(dic[char] - cur_pos) + cur_pos = dic[char] + return res From 1d4370b7705df521da62e77f74cb96ff99e0f51f Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 1 Sep 2019 16:05:54 -0400 Subject: [PATCH 012/183] 2019-09-01 --- ...50\346\225\260\346\216\222\345\210\227.py" | 25 ++++++++++++ ...41\345\210\222\350\257\204\344\274\260.py" | 21 ++++++++++ ...07\344\270\262\346\243\200\346\265\213.py" | 39 +++++++++++++++++++ ...6-\347\214\234\345\255\227\350\260\234.py" | 27 +++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 "5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" create mode 100644 "5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" create mode 100644 "5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" create mode 100644 "5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" diff --git "a/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" "b/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" new file mode 100644 index 0000000..0498261 --- /dev/null +++ "b/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" @@ -0,0 +1,25 @@ +class Solution(object): + def numPrimeArrangements(self, n): + """ + :type n: int + :rtype: int + """ + # 2 3 5 6 + 6 + prime_cnt = 0 + for i in range(1, n + 1): + if self.prime(i): + prime_cnt += 1 + non_prime_cnt = n - prime_cnt + # print prime_cnt, non_prime_cnt + return (math.factorial(prime_cnt) * math.factorial(non_prime_cnt)) % (10 ** 9 + 7) + + def prime(self, n): + if n == 1: + return False + if n == 2 or n == 3 or n == 5: + return True + for i in range(2, int(n ** 0.5) + 1): + if n % i == 0: + return False + return True + \ No newline at end of file diff --git "a/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" "b/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" new file mode 100644 index 0000000..a2d91fc --- /dev/null +++ "b/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" @@ -0,0 +1,21 @@ +class Solution(object): + def dietPlanPerformance(self, calories, k, lower, upper): + """ + :type calories: List[int] + :type k: int + :type lower: int + :type upper: int + :rtype: int + """ + res = 0 + s = sum(calories[: k]) + for start in range(0, len(calories) - (k - 1)): + if start != 0: + # print start, + s += calories[start + k - 1] - calories[start - 1] + # print s + if s < lower: + res -= 1 + elif s > upper: + res += 1 + return res \ No newline at end of file diff --git "a/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" "b/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" new file mode 100644 index 0000000..2a74f93 --- /dev/null +++ "b/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" @@ -0,0 +1,39 @@ +class Solution(object): + def canMakePaliQueries(self, s, queries): + """ + :type s: str + :type queries: List[List[int]] + :rtype: List[bool] + """ + alphabet = set(s) + dic = dict() + for char in alphabet: + dic[char] = [0 for _ in range(len(s))] + + for i, ch in enumerate(s): + for char in alphabet: + if ch == char: + if i > 0: + dic[ch][i] = dic[ch][i - 1] + 1 + else: + dic[ch][i] = 1 + else: + if i > 0: + dic[char][i] = dic[char][i - 1] + res = [] + for left, right, k in queries: + odd_cnt = 0 + for char in alphabet: + # print char, dic[char], left, right + if left > 0: + if (dic[char][right] - dic[char][left - 1]) % 2 == 1: + odd_cnt += 1 + else: + if dic[char][right] % 2 == 1: + odd_cnt += 1 + if odd_cnt // 2 <= k: + res.append(True) + else: + res.append(False) + return res + diff --git "a/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" "b/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" new file mode 100644 index 0000000..edb92ad --- /dev/null +++ "b/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" @@ -0,0 +1,27 @@ +class Solution(object): + def findNumOfValidWords(self, words, puzzles): + """ + :type words: List[str] + :type puzzles: List[str] + :rtype: List[int] + """ + from collections import Counter + for i in range(len(words)): + words[i] = "".join(sorted(set(words[i]))) + record = Counter(words) #统计每种单词出现的频率 + + res = [] + for p in puzzles: + bfs = [p[0]] + for char in p[1:]: + bfs += [s + char for s in bfs] + cnt = 0 + for combination in bfs: + tmp = "".join(sorted(combination)) + if tmp in record: + cnt += record[tmp] + res.append(cnt) + return res + + + \ No newline at end of file From 4ea10325fea91cc2f4be05829a828437a5b21083 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Sun, 1 Sep 2019 16:24:38 -0400 Subject: [PATCH 013/183] test --- .DS_Store | Bin 36868 -> 38916 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index 2336abed411eaf809ab02dc136fd4f2e5bab83fa..c3c7b18ac4d4405100dd480520b352d36bae0e58 100644 GIT binary patch delta 894 zcmZo!z|^vVNtl6wfzhcn#gKtv0+7i8#1ke8+b|kz3~*$U=3_8mFk&!gFl5k+4zE`8 zGb(GT7pq|Oh6U>LfuFF4N!G4STit~`5-xo2dc}IK`*@}?pN5o)OJ6kj00}D z-e?+EqG{xSYBXceE0&24?~y@O&nOO3Kbc29yPhpwE2K7r7ijReNJ}(TpMa`Vk(`5~ zHYeRMI5|JJ033D@0!2PI-^B$QARJY*Ys?M$4mtvrp{dbIA*iSz17gu;L6-N7o4FO% z>(}!`}#)|!3t2X7V^lqlwf>IWu@)RNSK{+#5brjM!Z9T}BYs19OmMNS-(xBDAR z?qf3F%pdTVPl13ty(ZhmZ<%}yq&k6(e{#7zAEW1Fm;6nW|1r65<}dih2NV)uG@fix zzhbf*v-M{FhMVk@o0uIo^9U?q;^=)J-;&M{!$0{$i^%3nRmLnL$YH<@;Y^s!-=V?C e0}So!%#-JHjK&}100zq?+!3wWS@K>!JLs}^1cFh zM$XAw8mt+)CZFhVnA~S1IeB-J=4L?-W|qzD94s7+uA4bJmoQB(VK&^%D`3VmSy(n< z^6z?qi485AxfRyyPwo!To&4Nhh0$~In*jdF=a@_<^CxVa{K;OD(QEUU1Wx|R?93*U z1q;@S{RaY|Lr{U|W~RcQe3NaN%_i@!XPYeAFkdG>38+K>h*vT&sDO2W^kLPlwE0cL z9rnrhD&#r1A?9{W=AWR!$h}#R Date: Tue, 3 Sep 2019 22:07:47 -0400 Subject: [PATCH 014/183] 2019-09-03 --- ...6\240\205\346\240\217\346\266\202\350\211\262.py" | 12 ++++++++++++ .../5176-\347\214\234\345\255\227\350\260\234.py" | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 "0276.\346\240\205\346\240\217\346\266\202\350\211\262/0276-\346\240\205\346\240\217\346\266\202\350\211\262.py" diff --git "a/0276.\346\240\205\346\240\217\346\266\202\350\211\262/0276-\346\240\205\346\240\217\346\266\202\350\211\262.py" "b/0276.\346\240\205\346\240\217\346\266\202\350\211\262/0276-\346\240\205\346\240\217\346\266\202\350\211\262.py" new file mode 100644 index 0000000..4ac7c88 --- /dev/null +++ "b/0276.\346\240\205\346\240\217\346\266\202\350\211\262/0276-\346\240\205\346\240\217\346\266\202\350\211\262.py" @@ -0,0 +1,12 @@ +class Solution(object): + def numWays(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + dp = [0] * (n + 3) + dp[0], dp[1], dp[2] = 0, k, k * k + for i in range(3, n + 1): + dp[i] = dp[i - 1] * (k - 1) + dp[i - 2] * (k - 1) + return dp[n] \ No newline at end of file diff --git "a/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" "b/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" index edb92ad..76fc5ab 100644 --- "a/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" +++ "b/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" @@ -8,17 +8,17 @@ def findNumOfValidWords(self, words, puzzles): from collections import Counter for i in range(len(words)): words[i] = "".join(sorted(set(words[i]))) - record = Counter(words) #统计每种单词出现的频率 + record = Counter(words) #统计每种pattern出现的频率 res = [] for p in puzzles: - bfs = [p[0]] + bfs = [p[0]] #固定首字母 for char in p[1:]: - bfs += [s + char for s in bfs] + bfs += [s + char for s in bfs] #生成64种可能 cnt = 0 for combination in bfs: tmp = "".join(sorted(combination)) - if tmp in record: + if tmp in record: #看看当前pattern在words里有没有出现过 cnt += record[tmp] res.append(cnt) return res From 3d18c5833e7b4cf70fde1450fadd1277b8fbdd2d Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Wed, 4 Sep 2019 21:32:19 -0400 Subject: [PATCH 015/183] 2019-09-04 --- ...34\345\257\273\345\220\215\344\272\272.py" | 26 ++++++++++++++++ ...57\347\232\204\347\211\210\346\234\254.py" | 17 +++++------ ...50\345\271\263\346\226\271\346\225\260.py" | 30 +++++++------------ 3 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 "0277.\346\220\234\345\257\273\345\220\215\344\272\272/0277-\346\220\234\345\257\273\345\220\215\344\272\272.py" diff --git "a/0277.\346\220\234\345\257\273\345\220\215\344\272\272/0277-\346\220\234\345\257\273\345\220\215\344\272\272.py" "b/0277.\346\220\234\345\257\273\345\220\215\344\272\272/0277-\346\220\234\345\257\273\345\220\215\344\272\272.py" new file mode 100644 index 0000000..fa78e60 --- /dev/null +++ "b/0277.\346\220\234\345\257\273\345\220\215\344\272\272/0277-\346\220\234\345\257\273\345\220\215\344\272\272.py" @@ -0,0 +1,26 @@ +# The knows API is already defined for you. +# @param a, person a +# @param b, person b +# @return a boolean, whether a knows b +# def knows(a, b): + +class Solution(object): + def findCelebrity(self, n): + """ + :type n: int + :rtype: int + """ + celebrity = 0 + for i in range(1, n): + if knows(celebrity, i): + #说明当前的这个celebrity肯定不是名人,因为他认识别的人 + celebrity = i + # 到这里的 celebrity,必定不认识 [celebrity + 1, n - 1]的所有人 + for i in range(celebrity): + if knows(celebrity, i): # 为了确保celebrity 不认识 [0, celebrity - 1] + return -1 + + for i in range(n): + if not knows(i, celebrity): # 为了确保 每个人都认识 celebrity + return -1 + return celebrity \ No newline at end of file diff --git "a/0278.\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254/0278-\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254.py" "b/0278.\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254/0278-\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254.py" index 326cb90..305128c 100644 --- "a/0278.\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254/0278-\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254.py" +++ "b/0278.\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254/0278-\347\254\254\344\270\200\344\270\252\351\224\231\350\257\257\347\232\204\347\211\210\346\234\254.py" @@ -1,22 +1,19 @@ - # The isBadVersion API is already defined for you. # @param version, an integer # @return a bool # def isBadVersion(version): -import math + class Solution(object): def firstBadVersion(self, n): """ :type n: int :rtype: int """ - start = 1 - end = n - while(end-start>1): - mid = start + (end-start)/2 + left, right = 1, n + while left < right: + mid = (left + right) // 2 if isBadVersion(mid): - end = mid + right = mid else: - start = mid - print start, end - return start if isBadVersion(start) else end \ No newline at end of file + left = mid + 1 + return left \ No newline at end of file diff --git "a/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260/0279-\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.py" "b/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260/0279-\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.py" index 51b8b39..7b6dda6 100644 --- "a/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260/0279-\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.py" +++ "b/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260/0279-\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.py" @@ -1,29 +1,19 @@ -from collections import deque class Solution(object): def numSquares(self, n): """ :type n: int :rtype: int """ - record = [] - for i in range(1, int(n ** 0.5) + 1): - record.append(i * i) - # print record + from collections import deque + queue = deque([(0, 0)]) visited = set() - q = deque() - q.append([0, 0]) - while(q): - m, cnt = q.popleft() - - for num in record: - s = m + num + while queue: + cur, step = queue.popleft() + for i in range(1, int(n ** 0.5) + 1): + s = cur + i ** 2 if s == n: - return cnt + 1 - if s < n and s not in visited: + return step + 1 + if s not in visited: visited.add(s) - q.append([s, cnt + 1]) - # return - - - - \ No newline at end of file + queue.append((s, step + 1)) + \ No newline at end of file From afcc75bae42dc2efe10c152a5beef411afebd340 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Thu, 5 Sep 2019 23:19:29 -0400 Subject: [PATCH 016/183] 2019-09-05 --- .vscode/settings.json | 3 ++ ...06\345\212\250\346\216\222\345\272\217.py" | 17 ++++++++ ...77\350\277\255\344\273\243\345\231\250.py" | 41 ++++++++++--------- ...3-\347\247\273\345\212\250\351\233\266.py" | 19 ++++----- ...57\350\277\255\344\273\243\345\231\250.py" | 20 ++++----- ...72\345\272\217\345\220\216\347\273\247.py" | 23 +++++++++++ 6 files changed, 82 insertions(+), 41 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 "0280.\346\221\206\345\212\250\346\216\222\345\272\217/0280-\346\221\206\345\212\250\346\216\222\345\272\217.py" create mode 100644 "0285.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247/0285-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247.py" diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb38db8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\ProgramData\\Anaconda2\\envs\\py3\\python.exe" +} \ No newline at end of file diff --git "a/0280.\346\221\206\345\212\250\346\216\222\345\272\217/0280-\346\221\206\345\212\250\346\216\222\345\272\217.py" "b/0280.\346\221\206\345\212\250\346\216\222\345\272\217/0280-\346\221\206\345\212\250\346\216\222\345\272\217.py" new file mode 100644 index 0000000..42a9b22 --- /dev/null +++ "b/0280.\346\221\206\345\212\250\346\216\222\345\272\217/0280-\346\221\206\345\212\250\346\216\222\345\272\217.py" @@ -0,0 +1,17 @@ +class Solution(object): + def wiggleSort(self, nums): + """ + :type nums: List[int] + :rtype: None Do not return anything, modify nums in-place instead. + """ + if not nums: + return nums + i = 0 + while i < len(nums): + if i % 2 == 0 and i < len(nums) - 1 and nums[i] > nums[i + 1]: + nums[i], nums[i + 1] = nums[i + 1], nums[i] + elif i % 2 and i < len(nums) - 1 and nums[i] < nums[i + 1]: + nums[i], nums[i + 1] = nums[i + 1], nums[i] + else: + i += 1 + return nums diff --git "a/0281.\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250/0281-\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250.py" "b/0281.\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250/0281-\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250.py" index 0ae455c..e70ddb8 100644 --- "a/0281.\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250/0281-\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250.py" +++ "b/0281.\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250/0281-\351\224\257\351\275\277\350\277\255\344\273\243\345\231\250.py" @@ -6,35 +6,36 @@ def __init__(self, v1, v2): :type v1: List[int] :type v2: List[int] """ - self.list = [] - if v1 and v2: - i = 0 - for i in range(min(len(v1), len(v2))): - self.list.append(v1[i]) - self.list.append(v2[i]) - if v1[i + 1:]: - self.list += v1[i + 1:] - else: - self.list += v2[i + 1:] - - elif v1: - self.list = v1 - else: - self.list = v2 - self.index = 0 + self.i1, self.i2 = 0, 0 + self.v1, self.v2 = v1, v2 + self.indicator = 0 # 0 for v1, 1 for v2 + def next(self): """ :rtype: int """ - self.index += 1 - return self.list[self.index - 1] + if not self.indicator: + self.indicator = 1 + if self.i1 < len(self.v1): + self.i1 += 1 + return self.v1[self.i1 - 1] + else: + self.i2 += 1 + return self.v2[self.i2 - 1] + else: + self.indicator = 0 + if self.i2 < len(self.v2): + self.i2 += 1 + return self.v2[self.i2 - 1] + else: + self.i1 += 1 + return self.v1[self.i1 - 1] def hasNext(self): """ :rtype: bool """ - return self.index != len(self.list) - + return self.i1 < len(self.v1) or self.i2 < len(self.v2) # Your ZigzagIterator object will be instantiated and called as such: # i, v = ZigzagIterator(v1, v2), [] diff --git "a/0283.\347\247\273\345\212\250\351\233\266/0283-\347\247\273\345\212\250\351\233\266.py" "b/0283.\347\247\273\345\212\250\351\233\266/0283-\347\247\273\345\212\250\351\233\266.py" index 3dbbd55..897a7c7 100644 --- "a/0283.\347\247\273\345\212\250\351\233\266/0283-\347\247\273\345\212\250\351\233\266.py" +++ "b/0283.\347\247\273\345\212\250\351\233\266/0283-\347\247\273\345\212\250\351\233\266.py" @@ -2,15 +2,12 @@ class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] - :rtype: void Do not return anything, modify nums in-place instead. + :rtype: None Do not return anything, modify nums in-place instead. """ - l = len(nums) - for index,item in enumerate(nums): - if item != 0: - continue - else: - for index0 in range(index+1,l): - if nums[index0] != 0: - print nums[index], nums[index0] - nums[index], nums[index0] = nums[index0], nums[index] - break \ No newline at end of file + i = 0 + for j in range(len(nums)): + if nums[j] != 0: + nums[i], nums[j] = nums[j], nums[i] + i += 1 + + # return nums \ No newline at end of file diff --git "a/0284.\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250/0284-\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250.py" "b/0284.\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250/0284-\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250.py" index 4eb1e35..a29ee7e 100644 --- "a/0284.\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250/0284-\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250.py" +++ "b/0284.\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250/0284-\351\241\266\347\253\257\350\277\255\344\273\243\345\231\250.py" @@ -25,32 +25,32 @@ def __init__(self, iterator): Initialize your data structure here. :type iterator: Iterator """ - self.list = list() - while(iterator.hasNext()): - self.list.append(iterator.next()) + self.l = [] + while iterator.hasNext(): + self.l.append(iterator.next()) + # self.l = iterator + self.index = 0 + def peek(self): """ Returns the next element in the iteration without advancing the iterator. :rtype: int """ - return self.list[0] - + return self.l[self.index] def next(self): """ :rtype: int """ - return self.list.pop(0) - - + self.index += 1 + return self.l[self.index - 1] def hasNext(self): """ :rtype: bool """ - return len(self.list) != 0 - + return self.index < len(self.l) # Your PeekingIterator object will be instantiated and called as such: # iter = PeekingIterator(Iterator(nums)) diff --git "a/0285.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247/0285-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247.py" "b/0285.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247/0285-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247.py" new file mode 100644 index 0000000..fbca755 --- /dev/null +++ "b/0285.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247/0285-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\351\241\272\345\272\217\345\220\216\347\273\247.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 inorderSuccessor(self, root, p): + """ + :type root: TreeNode + :type p: TreeNode + :rtype: TreeNode + """ + if not root: + return None + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node] + inorder(node.right) + l = inorder(root) + i = l.index(p) + return l[i + 1] if i < len(l) - 1 else None \ No newline at end of file From 4688dc3ff8da7af552c485339bbaaa28d0586cf9 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Fri, 6 Sep 2019 21:41:50 -0400 Subject: [PATCH 017/183] 2019-09-06 --- ...6-\345\242\231\344\270\216\351\227\250.py" | 32 ++++++++++ ...76\351\207\215\345\244\215\346\225\260.py" | 12 ++-- ...57\344\270\200\347\274\251\345\206\231.py" | 30 ++++++++++ ...37\345\221\275\346\270\270\346\210\217.py" | 60 +++++++------------ 4 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 "0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" create mode 100644 "0288.\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231/0288-\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231.py" diff --git "a/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" "b/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" new file mode 100644 index 0000000..826b6d0 --- /dev/null +++ "b/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" @@ -0,0 +1,32 @@ +class Solution(object): + def wallsAndGates(self, rooms): + """ + :type rooms: List[List[int]] + :rtype: None Do not return anything, modify rooms in-place instead. + """ + from collections import deque + if not rooms or not rooms[0]: + return rooms + m, n = len(rooms), len(rooms[0]) + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + INF = 2147483647 + queue = deque() + def bfs(queue): + while queue: + pos = queue.popleft() + x0, y0 = pos + + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + if 0 <= x < m and 0 <= y < n and rooms[x][y] == INF: + rooms[x][y] = rooms[x0][y0] + 1 + queue.append((x, y)) + + for i in range(m): + for j in range(n): + if rooms[i][j] == 0: #现在从每扇门出发 + queue.append((i, j)) + bfs(queue) + return rooms \ No newline at end of file diff --git "a/0287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/0287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" "b/0287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/0287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" index 1c8a8d8..6e077e2 100644 --- "a/0287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/0287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" +++ "b/0287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/0287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" @@ -4,17 +4,13 @@ def findDuplicate(self, nums): :type nums: List[int] :rtype: int """ - slow, fast = 0, 0 - while(1): + while 1: slow = nums[slow] fast = nums[nums[fast]] - # print slow, fast - if slow == fast: # loop exists + if slow == fast: fast = 0 - while(nums[slow] != nums[fast]): + while nums[slow] != nums[fast]: slow = nums[slow] fast = nums[fast] - # print slow, fast - return nums[fast] - \ No newline at end of file + return nums[fast] \ No newline at end of file diff --git "a/0288.\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231/0288-\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231.py" "b/0288.\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231/0288-\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231.py" new file mode 100644 index 0000000..4597793 --- /dev/null +++ "b/0288.\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231/0288-\345\215\225\350\257\215\347\232\204\345\224\257\344\270\200\347\274\251\345\206\231.py" @@ -0,0 +1,30 @@ +class ValidWordAbbr(object): + + def __init__(self, dictionary): + """ + :type dictionary: List[str] + """ + from collections import defaultdict + self.dic = defaultdict(list) + for word in dictionary: + if len(word) <= 2: + self.dic[word].append(word) + else: + self.dic[word[0] + str(len(word) - 2) + word[-1]].append(word) + + def isUnique(self, word): + """ + :type word: str + :rtype: bool + """ + if len(word) <= 2: + return not self.dic[word] or self.dic[word] == [word] * len(self.dic[word]) + else: + s = word[0] + str(len(word) - 2) + word[-1] + return not self.dic[s] or self.dic[s] == [word] * len(self.dic[s]) + + + +# Your ValidWordAbbr object will be instantiated and called as such: +# obj = ValidWordAbbr(dictionary) +# param_1 = obj.isUnique(word) \ 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.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.py" index 5db3667..4cf3306 100644 --- "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.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.py" @@ -2,52 +2,36 @@ class Solution(object): def gameOfLife(self, board): """ :type board: List[List[int]] - :rtype: void Do not return anything, modify board in-place instead. + :rtype: None Do not return anything, modify board in-place instead. """ - m = len(board) - if m == 0: - return board - n = len(board[0]) - if n == 0: - return board + 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] - alivex = list() - alivey = list() - - def neibor(x, y): #统计八个邻居里有几个是活细胞(1) - 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): - xx = x + dx[k] - yy = y + dy[k] + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and board[x][y] == 1: + cnt += 1 - if 0 <= xx < m and 0 <= yy < n and board[xx][yy] == 1: - cnt += 1 - return cnt - + liveCellSet = set() for i in range(m): for j in range(n): - cnt = neibor(i, j) - # print i, j, cnt - if (board[i][j] == 1 and 2 <= cnt <= 3) or (board[i][j] == 0 and cnt == 3): - alivex.append(i) - alivey.append(j) - - alivecnt = 0 + 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): - board[i][j] = 0 - - if alivecnt < len(alivex): - if alivex[alivecnt] == i and alivey[alivecnt] == j: - board[i][j] = 1 - alivecnt += 1 - - return board - - - \ No newline at end of file + if (i, j) in liveCellSet: + board[i][j] = 1 + else: + board[i][j] = 0 \ No newline at end of file From 04d1899da7cdded97486f818576f9c1ff82b7361 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 8 Sep 2019 10:47:25 -0400 Subject: [PATCH 018/183] 2019-09-08 --- ...44\346\225\260\344\271\213\345\222\214.py" | 15 +++ ...44\346\225\260\347\233\270\345\212\240.py" | 39 ++++++ ...00\351\225\277\345\255\220\344\270\262.py" | 16 +++ ...04\344\270\255\344\275\215\346\225\260.py" | 64 ++++------ ...36\346\226\207\345\255\220\344\270\262.py" | 36 +++--- ...27\345\275\242\345\217\230\346\215\242.py" | 51 ++++---- ...64\346\225\260\345\217\215\350\275\254.py" | 19 ++- ...\215\242\346\225\264\346\225\260(atoi).py" | 32 ++--- ...9-\345\233\236\346\226\207\346\225\260.py" | 22 ++-- ...64\347\232\204\345\256\271\345\231\250.py" | 20 ++-- ...54\345\205\261\345\211\215\347\274\200.py" | 10 +- ...11\346\225\260\344\271\213\345\222\214.py" | 29 ++--- ...11\346\225\260\344\271\213\345\222\214.py" | 19 +-- ...27\346\257\215\347\273\204\345\220\210.py" | 27 ++--- ...33\346\225\260\344\271\213\345\222\214.py" | 53 ++++---- ...4N\344\270\252\350\212\202\347\202\271.py" | 34 +++--- ...10\347\232\204\346\213\254\345\217\267.py" | 19 +-- ...11\345\272\217\351\223\276\350\241\250.py" | 31 +++++ ...54\345\217\267\347\224\237\346\210\220.py" | 29 +++-- ...22\345\272\217\351\223\276\350\241\250.py" | 30 +++++ ...55\347\232\204\350\212\202\347\202\271.py" | 26 ++++ ...04\351\207\215\345\244\215\351\241\271.py" | 11 +- ...73\351\231\244\345\205\203\347\264\240.py" | 26 ++-- .../0028-\345\256\236\347\216\260strStr().py" | 17 +++ ...44\346\225\260\347\233\270\351\231\244.py" | 27 ++--- ...00\344\270\252\346\216\222\345\210\227.py" | 34 +++--- ...11\346\225\210\346\213\254\345\217\267.py" | 19 +++ ...22\345\272\217\346\225\260\347\273\204.py" | 47 ++++---- ...00\344\270\252\344\275\215\347\275\256.py" | 70 ++++++----- ...22\345\205\245\344\275\215\347\275\256.py" | 19 +-- ...10\347\232\204\346\225\260\347\213\254.py" | 14 +-- ...7-\350\247\243\346\225\260\347\213\254.py" | 65 +++++----- .../0038-\346\212\245\346\225\260.py" | 20 ++++ ...04\345\220\210\346\200\273\345\222\214.py" | 29 +++-- ...\345\220\210\346\200\273\345\222\214II.py" | 39 +++--- ...00\344\270\252\346\255\243\346\225\260.py" | 24 ++-- ...2-\346\216\245\351\233\250\346\260\264.py" | 35 +++--- ...46\344\270\262\347\233\270\344\271\230.py" | 113 +++++++++--------- ...15\347\254\246\345\214\271\351\205\215.py" | 35 ++++++ ...6-\345\205\250\346\216\222\345\210\227.py" | 22 ++-- ...\345\205\250\346\216\222\345\210\227II.py" | 27 ++--- ...13\350\275\254\345\233\276\345\203\217.py" | 20 ++++ ...15\350\257\215\345\210\206\347\273\204.py" | 18 +-- 0050.Pow(x,n)/0050-Pow(x,n).py | 27 +++-- .../0051-N\347\232\207\345\220\216.py" | 77 +++++------- .../0052-N\347\232\207\345\220\216II.py" | 78 +++++------- ...47\345\255\220\345\272\217\345\222\214.py" | 18 +-- ...72\346\227\213\347\237\251\351\230\265.py" | 58 +++++---- ...63\350\267\203\346\270\270\346\210\217.py" | 13 +- ...10\345\271\266\345\214\272\351\227\264.py" | 34 ++---- ...22\345\205\245\345\214\272\351\227\264.py" | 46 +++---- ...15\347\232\204\351\225\277\345\272\246.py" | 14 ++- ...\346\227\213\347\237\251\351\230\265II.py" | 45 +++++-- ...4k\344\270\252\346\216\222\345\210\227.py" | 32 +++-- ...13\350\275\254\351\223\276\350\241\250.py" | 40 +++---- ...15\345\220\214\350\267\257\345\276\204.py" | 23 ++-- ...\345\220\214\350\267\257\345\276\204II.py" | 28 +++++ ...17\350\267\257\345\276\204\345\222\214.py" | 32 ++--- .../0066-\345\212\240\344\270\200.py" | 29 ++--- ...33\345\210\266\346\261\202\345\222\214.py" | 24 +++- ...04\345\271\263\346\226\271\346\240\271.py" | 21 ++++ ...0-\347\210\254\346\245\274\346\242\257.py" | 29 ++--- ...00\345\214\226\350\267\257\345\276\204.py" | 18 ++- ...26\350\276\221\350\267\235\347\246\273.py" | 24 ++-- ...51\351\230\265\347\275\256\351\233\266.py" | 28 ++--- ...14\347\273\264\347\237\251\351\230\265.py" | 32 +++-- ...34\350\211\262\345\210\206\347\261\273.py" | 42 +++---- .../0077-\347\273\204\345\220\210.py" | 19 ++- .../0078-\345\255\220\351\233\206.py" | 26 ++-- ...25\350\257\215\346\220\234\347\264\242.py" | 51 ++++---- ...\351\207\215\345\244\215\351\241\271II.py" | 1 + ...\345\272\217\346\225\260\347\273\204II.py" | 106 +--------------- ...\345\244\215\345\205\203\347\264\240II.py" | 30 ++--- ...15\345\244\215\345\205\203\347\264\240.py" | 20 ++++ ...47\347\232\204\347\237\251\345\275\242.py" | 15 +-- ...11\345\272\217\346\225\260\347\273\204.py" | 28 +---- ...74\351\233\267\347\274\226\347\240\201.py" | 9 +- .../0090-\345\255\220\351\233\206II.py" | 18 +-- ...\350\275\254\351\223\276\350\241\250II.py" | 74 +++++------- ...11\346\220\234\347\264\242\346\240\221.py" | 24 +--- ...11\346\220\234\347\264\242\346\240\221.py" | 33 +++++ ...70\345\220\214\347\232\204\346\240\221.py" | 24 +--- ...60\344\272\214\345\217\211\346\240\221.py" | 26 ++-- ...02\346\254\241\351\201\215\345\216\206.py" | 29 ++--- ...02\346\254\241\351\201\215\345\216\206.py" | 37 +++--- ...00\345\244\247\346\267\261\345\272\246.py" | 16 +++ ...40\344\272\214\345\217\211\346\240\221.py" | 18 +-- ...40\344\272\214\345\217\211\346\240\221.py" | 24 ++-- ...\346\254\241\351\201\215\345\216\206II.py" | 40 ++----- ...11\346\220\234\347\264\242\346\240\221.py" | 19 +-- ...11\346\220\234\347\264\242\346\240\221.py" | 43 +++---- ...41\344\272\214\345\217\211\346\240\221.py" | 31 +++-- ...00\345\260\217\346\267\261\345\272\246.py" | 21 ++-- ...57\345\276\204\346\200\273\345\222\214.py" | 26 +--- ...\345\276\204\346\200\273\345\222\214II.py" | 22 ++-- ...00\344\270\272\351\223\276\350\241\250.py" | 22 ++-- ...02\347\202\271\346\214\207\351\222\210.py" | 38 +++--- ...\347\202\271\346\214\207\351\222\210II.py" | 55 +++++---- ...50\350\276\211\344\270\211\350\247\222.py" | 16 +++ ...\350\276\211\344\270\211\350\247\222II.py" | 30 ++--- ...17\350\267\257\345\276\204\345\222\214.py" | 19 +-- ...00\344\275\263\346\227\266\346\234\272.py" | 29 +++-- ...\344\275\263\346\227\266\346\234\272II.py" | 16 ++- ...344\275\263\346\227\266\346\234\272III.py" | 21 ++++ ...01\345\233\236\346\226\207\344\270\262.py" | 23 +--- ...\350\257\215\346\216\245\351\276\231II.py" | 113 ++++++++++++++++++ ...25\350\257\215\346\216\245\351\276\231.py" | 47 ++++---- ...36\347\273\255\345\272\217\345\210\227.py" | 21 ++++ ...60\345\255\227\344\271\213\345\222\214.py" | 9 +- ...25\347\232\204\345\214\272\345\237\237.py" | 103 ++++------------ ...\345\233\236\346\226\207\344\270\262II.py" | 29 +++++ ...3-\345\205\213\351\232\206\345\233\276.py" | 41 ++----- ...4-\345\212\240\346\262\271\347\253\231.py" | 32 +++-- ...41\347\232\204\346\225\260\345\255\227.py" | 11 +- ...\347\232\204\346\225\260\345\255\227II.py" | 4 +- ...10\347\232\204\351\223\276\350\241\250.py" | 31 +++++ ...25\350\257\215\346\213\206\345\210\206.py" | 14 +-- ...57\345\275\242\351\223\276\350\241\250.py" | 24 ++++ ...\345\275\242\351\223\276\350\241\250II.py" | 34 ++++++ ...15\346\216\222\351\223\276\350\241\250.py" | 43 ++++--- ...15\345\272\217\351\201\215\345\216\206.py" | 15 ++- ...16\345\272\217\351\201\215\345\216\206.py" | 15 ++- ...23\345\255\230\346\234\272\345\210\266.py" | 44 +++++++ ...22\345\205\245\346\216\222\345\272\217.py" | 41 ++++--- ...22\345\272\217\351\223\276\350\241\250.py" | 39 +++--- ...76\345\274\217\346\261\202\345\200\274.py" | 35 +++--- ...14\347\232\204\345\215\225\350\257\215.py" | 15 +-- ...47\345\255\220\345\272\217\345\210\227.py" | 22 ++-- ...04\346\234\200\345\260\217\345\200\274.py" | 34 ++++-- ...\346\234\200\345\260\217\345\200\274II.py" | 25 +++- ...5-\346\234\200\345\260\217\346\240\210.py" | 23 ++-- ...54\344\272\214\345\217\211\346\240\221.py" | 26 ++-- ...6N\344\270\252\345\255\227\347\254\246.py" | 26 ++-- ...00\351\225\277\345\255\220\344\270\262.py" | 46 +++---- ...70\344\272\244\351\223\276\350\241\250.py" | 49 +++----- ...26\350\276\221\350\267\235\347\246\273.py" | 22 ++-- ...73\346\211\276\345\263\260\345\200\274.py" | 6 +- ...61\347\232\204\345\214\272\351\227\264.py" | 42 +++---- ...00\345\244\247\351\227\264\350\267\235.py" | 3 +- ...03\347\211\210\346\234\254\345\217\267.py" | 1 - ...11\345\272\217\346\225\260\347\273\204.py" | 9 +- ...50\345\210\227\345\220\215\347\247\260.py" | 13 +- ...9-\346\261\202\344\274\227\346\225\260.py" | 5 +- ...23\346\236\204\350\256\276\350\256\241.py" | 38 ++++++ ...50\345\210\227\345\272\217\345\217\267.py" | 9 +- ...30\345\220\216\347\232\204\351\233\266.py" | 5 +- ...21\350\277\255\344\273\243\345\231\250.py" | 23 ++-- ...\344\275\263\346\227\266\346\234\272IV.py" | 41 +++++++ ...13\350\275\254\346\225\260\347\273\204.py" | 11 +- ...14\350\277\233\345\210\266\344\275\215.py" | 12 +- ...51\347\232\204\344\270\252\346\225\260.py" | 7 +- ...23\345\256\266\345\212\253\350\210\215.py" | 20 ++-- ...04\345\217\263\350\247\206\345\233\276.py" | 33 ++--- ...33\345\261\277\346\225\260\351\207\217.py" | 36 +++--- ...64\346\214\211\344\275\215\344\270\216.py" | 13 ++ ...2-\345\277\253\344\271\220\346\225\260.py" | 26 ++-- ...76\350\241\250\345\205\203\347\264\240.py" | 25 ++-- ...41\346\225\260\350\264\250\346\225\260.py" | 19 +-- ...04\345\255\227\347\254\246\344\270\262.py" | 17 +++ ...15\350\275\254\351\223\276\350\241\250.py" | 25 ++-- ...23\346\236\204\350\256\276\350\256\241.py" | 8 +- ...\350\257\215\346\220\234\347\264\242II.py" | 6 +- ...55\345\233\236\346\226\207\344\270\262.py" | 2 + ...00\345\244\247\345\205\203\347\264\240.py" | 24 +++- ...345\220\210\346\200\273\345\222\214III.py" | 31 +++-- ...15\345\244\215\345\205\203\347\264\240.py" | 8 +- ...\345\244\215\345\205\203\347\264\240II.py" | 12 +- ...02\347\202\271\344\270\252\346\225\260.py" | 9 +- ...\344\274\232\350\256\256\345\256\244II.py" | 22 ++-- ...53\345\206\267\345\206\273\346\234\237.py" | 15 +++ ...54\345\255\227\347\254\246\344\270\262.py" | 13 +- ...46\344\270\262\347\233\270\345\212\240.py" | 59 +++++---- ...53\346\211\213\347\273\255\350\264\271.py" | 18 +++ ...02\345\205\211\347\273\204\345\220\210.py" | 9 +- ...67\346\234\254\347\273\237\350\256\241.py" | 55 +++++++++ .../1094-\346\213\274\350\275\246.py" | 20 ++++ ...76\347\233\256\346\240\207\345\200\274.py" | 52 ++++++++ README.md | 7 +- 178 files changed, 2893 insertions(+), 2212 deletions(-) create mode 100644 "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 "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 "0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.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.py" create mode 100644 "0023.\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250/0023-\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250.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.py" create mode 100644 "0028.\345\256\236\347\216\260strStr()/0028-\345\256\236\347\216\260strStr().py" create mode 100644 "0032.\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267/0032-\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267.py" create mode 100644 "0038.\346\212\245\346\225\260/0038-\346\212\245\346\225\260.py" create mode 100644 "0044.\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215/0044-\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215.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.py" create mode 100644 "0063.\344\270\215\345\220\214\350\267\257\345\276\204II/0063-\344\270\215\345\220\214\350\267\257\345\276\204II.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.py" create mode 100644 "0099.\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0099-\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "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 "0118.\346\235\250\350\276\211\344\270\211\350\247\222/0118-\346\235\250\350\276\211\344\270\211\350\247\222.py" create mode 100644 "0123.\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\272III/0123-\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\272III.py" create mode 100644 "0126.\345\215\225\350\257\215\346\216\245\351\276\231II/0126-\345\215\225\350\257\215\346\216\245\351\276\231II.py" create mode 100644 "0128.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/0128-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" create mode 100644 "0132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/0132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.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.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.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.py" create mode 100644 "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" create mode 100644 "0170.\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0170-\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" create mode 100644 "0188.\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\272IV/0188-\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\272IV.py" create mode 100644 "0201.\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216/0201-\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216.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.py" create mode 100644 "0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/0309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" create mode 100644 "0714.\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\345\220\253\346\211\213\347\273\255\350\264\271/0714-\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\345\220\253\346\211\213\347\273\255\350\264\271.py" create mode 100644 "1093.\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241/1093-\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241.py" create mode 100644 "1094.\346\213\274\350\275\246/1094-\346\213\274\350\275\246.py" create mode 100644 "1095.\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274/1095-\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274.py" diff --git "a/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/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..9442d88 --- /dev/null +++ "b/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,15 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + hashmap = {} + for i, x in enumerate(nums): + if hashmap.has_key(target - x): + return [hashmap[target - x], i] + else: + hashmap[x] = i + + return [] \ No newline at end of file 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.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.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.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/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" "b/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" new file mode 100644 index 0000000..7fcc3ef --- /dev/null +++ "b/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" @@ -0,0 +1,16 @@ +class Solution(object): + def lengthOfLongestSubstring(self, s): + """ + :type s: str + :rtype: int + """ + record = {} + start, res = 0, 0 + for end in range(len(s)): + if s[end] in record: + start = max(start, record[s[end]] + 1) + + record[s[end]] = end + res = max(res, end - start + 1) + + return res \ No newline at end of file diff --git "a/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" "b/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" index 5dbbd99..a36ac3f 100644 --- "a/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" +++ "b/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" @@ -1,46 +1,22 @@ from heapq import * -class MedianFinder(object): -# 维护两个堆,一个大顶堆,一个小顶堆,小顶堆里的数比大顶堆里的数都要大, -# 如果有两个潜在的中位数(两个堆size相同),数据流的中位数就是两个堆顶之和除以2 -# 如果只有一个中位数,就看size更小的那个堆的堆顶 -# 如果新进来的数比小顶堆的数要小,就把它插入大顶堆 -# 如果新进来的数比小顶堆的数要大,就把它插入小顶堆 -# 调整两个堆,使得size 差最大为1 +class DoubleHeap(object): def __init__(self): - """ - initialize your data structure here. - """ - self.max_h = list() - self.min_h = list() - heapify(self.max_h) - heapify(self.min_h) + self.maxh = [] + self.minh = [] + heapify(self.maxh) + heapify(self.minh) - - def addNum(self, num): - """ - :type num: int - :rtype: None - """ - heappush(self.min_h, num) - heappush(self.max_h, -heappop(self.min_h)) - if len(self.max_h) > len(self.min_h): - heappush(self.min_h, -heappop(self.max_h)) - - def findMedian(self): - """ - :rtype: float - """ - max_len = len(self.max_h) - min_len = len(self.min_h) - if max_len == min_len: #有两个候选中位数 - return (self.min_h[0] + -self.max_h[0]) / 2. - else:#小顶堆的size 一定 >= 大顶堆的size,所以答案就是小顶堆的堆顶 - return self.min_h[0] / 1. + def insert(self, val): + heappush(self.minh, val) + heappush(self.maxh, -heappop(self.minh)) + if len(self.maxh) > len(self.minh): + heappush(self.minh, -heappop(self.maxh)) -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() + def findMedian(self): + if len(self.maxh) == len(self.minh): + return (self.minh[0] - self.maxh[0]) / 2.0 + return self.minh[0]/1.0 + class Solution(object): def findMedianSortedArrays(self, nums1, nums2): @@ -49,9 +25,11 @@ def findMedianSortedArrays(self, nums1, nums2): :type nums2: List[int] :rtype: float """ - mf = MedianFinder() + dh = DoubleHeap() for num in nums1: - mf.addNum(num) + dh.insert(num) + for num in nums2: - mf.addNum(num) - return mf.findMedian() \ No newline at end of file + dh.insert(num) + + return dh.findMedian() \ No newline at end of file diff --git "a/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" "b/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" index 22d6540..d1f7847 100644 --- "a/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" +++ "b/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" @@ -4,24 +4,30 @@ def longestPalindrome(self, s): :type s: str :rtype: str """ - max_l = 0 - res = "" - for i in range(0, len(s)): - #以s[i] 为中心向左右扩散 + left, right = 0, 0 + res, string = 0, "" + for i in range(len(s)): left, right = i, i while(left >= 0 and right < len(s) and s[left] == s[right]): - if max_l < right - left + 1: - max_l = right - left + 1 - res = s[left:right + 1] left -= 1 right += 1 - - #以s[i],s[i+1]为中心向左右扩散 - left, right = i, i + 1 + left += 1 + right -= 1 + + if right - left + 1 > res: + res = right - left + 1 + string = s[left:right + 1] + + for i in range(1, len(s)): + left, right = i - 1, i while(left >= 0 and right < len(s) and s[left] == s[right]): - if max_l < right - left + 1: - max_l = right - left + 1 - res = s[left:right + 1] left -= 1 - right += 1 - return res \ No newline at end of file + right += 1 + left += 1 + right -= 1 + + if right - left + 1 > res: + res = right - left + 1 + string = s[left:right + 1] + return string + \ No newline at end of file diff --git "a/0006.Z\345\255\227\345\275\242\345\217\230\346\215\242/0006-Z\345\255\227\345\275\242\345\217\230\346\215\242.py" "b/0006.Z\345\255\227\345\275\242\345\217\230\346\215\242/0006-Z\345\255\227\345\275\242\345\217\230\346\215\242.py" index 345c29c..ddac202 100644 --- "a/0006.Z\345\255\227\345\275\242\345\217\230\346\215\242/0006-Z\345\255\227\345\275\242\345\217\230\346\215\242.py" +++ "b/0006.Z\345\255\227\345\275\242\345\217\230\346\215\242/0006-Z\345\255\227\345\275\242\345\217\230\346\215\242.py" @@ -1,35 +1,40 @@ class Solution(object): - def convert(self, s, n): + def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str """ - #找规律 - if n <= 1: + #第一行和最后一行都是相差 2 * (n - 1) + #对于直角在上面的直角三角形, 相差 2 * (n - 1 - i) + #对于直角在下面的直角三角形, 相差 2 * i + if not s or numRows == 1: return s - l = len(s) res = "" - for i in range(n): - tmp, index = "", i - if i in [0, n - 1]: - while(index < l): - - tmp += s[index] - index += 2 * (n - 1) + for idx in range(numRows): + if idx < len(s): + res += s[idx] + + if idx in [0, numRows - 1]: + tmp = idx + 2 *(numRows - 1) + while tmp < len(s): + res += s[tmp] + tmp += 2 *(numRows - 1) else: - state = "down" - while(index < l): - tmp += s[index] - if state == "down": - state = "up" - index += 2 * (n - 1 - i) - else: - state = "down" - index += 2 * i - res += tmp - + tmp = idx + 2 * (numRows - 1 - idx) + tri = "down" + while tmp < len(s): + res += s[tmp] + if tri == "up": + tmp += 2 * (numRows - 1 - idx) + tri = "down" + else: + tmp += 2 * idx + tri = "up" + return res - + + + \ No newline at end of file diff --git "a/0007.\346\225\264\346\225\260\345\217\215\350\275\254/0007-\346\225\264\346\225\260\345\217\215\350\275\254.py" "b/0007.\346\225\264\346\225\260\345\217\215\350\275\254/0007-\346\225\264\346\225\260\345\217\215\350\275\254.py" index ff7dd8e..82df21d 100644 --- "a/0007.\346\225\264\346\225\260\345\217\215\350\275\254/0007-\346\225\264\346\225\260\345\217\215\350\275\254.py" +++ "b/0007.\346\225\264\346\225\260\345\217\215\350\275\254/0007-\346\225\264\346\225\260\345\217\215\350\275\254.py" @@ -4,19 +4,16 @@ def reverse(self, x): :type x: int :rtype: int """ - - flag = 0 + INT_MIN = -2 **31 + INT_MAX = 2 ** 31 - 1 + op = 1 if x < 0: - flag = 1 - if flag: + op = -1 s = str(x)[1:] - s = s[::-1] - x = -1 *int(s) else: s = str(x) - s = s[::-1] - x = int(s) - if x < -1 * 2 **31 or x > 2** 31 -1: - return 0 - return x \ No newline at end of file + res = op * int(s[::-1]) + return res if INT_MIN <= res <= INT_MAX else 0 + + \ No newline at end of file diff --git "a/0008.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" "b/0008.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" index 422830d..f817929 100644 --- "a/0008.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" +++ "b/0008.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" @@ -5,32 +5,34 @@ def myAtoi(self, s): :rtype: int """ s = s.strip(" ") - if not len(s): #排除空 - return 0 - if s[0] not in ["+", "-"] and not s[0].isdigit(): #排除第一个非空字符不是数字 + # print s + if not s or (s[0] not in ["+", "-"] and not s[0].isdigit()): return 0 + op = 1 - res = "" + tmp = "" for i, char in enumerate(s): - if i == 0 : + if i == 0: if char == "-": op = -1 continue elif char == "+": - continue - if char == " " or not char.isdigit(): + pass + continue + if char.isdigit(): + tmp += char + else: break - res += char - # print res, op - if len(res) > 0: - res = op * int(res) + # print tmp + if tmp: + res = op * int(tmp) else: - return 0 - INT_MIN = -2 **31 + res = 0 INT_MAX = 2 **31 - 1 + INT_MIN = -2 **31 if res > INT_MAX: return INT_MAX elif res < INT_MIN: return INT_MIN - return res - \ No newline at end of file + else: + return res \ 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.py" "b/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" index e40b713..fc986ad 100644 --- "a/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" +++ "b/0009.\345\233\236\346\226\207\346\225\260/0009-\345\233\236\346\226\207\346\225\260.py" @@ -1,11 +1,17 @@ class Solution(object): def isPalindrome(self, x): + """ + :type x: int + :rtype: bool + """ + #2019.6.1 + xx = x + if x < 0: + return False - s = str(x) - if len(s) <= 1: - return True - print len(s) / 2 - for count in range(0, len(s)/2): - if s[count] != s[len(s)-1 - count]: - return False - return True \ No newline at end of file + 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/0011.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/0011-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" "b/0011.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/0011-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" index aef803f..15c142d 100644 --- "a/0011.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/0011-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" +++ "b/0011.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/0011-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" @@ -4,17 +4,13 @@ def maxArea(self, height): :type height: List[int] :rtype: int """ - lo, hi = 0, len(height) - 1 + left, right = 0, len(height) - 1 res = 0 - while(lo < hi): - if height[lo] > height[hi]: - area = height[hi] * (hi - lo) - hi -= 1 + while(left < right): + # print left, right, + res = max(res, (right - left) * min(height[left], height[right])) + if height[left] < height[right]: + left += 1 else: - area = height[lo] * (hi - lo) - lo += 1 - # print area - res = max(area, res) - - return res - \ No newline at end of file + right -= 1 + return res \ No newline at end of file diff --git "a/0014.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200/0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.py" "b/0014.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200/0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.py" index 8737a0d..058eeef 100644 --- "a/0014.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200/0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.py" +++ "b/0014.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200/0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.py" @@ -6,15 +6,13 @@ def longestCommonPrefix(self, strs): """ if not strs: return "" - strs.sort() - res = "" - for x, y in zip(strs[0], strs[-1]): + res = "" + pair = zip(strs[0], strs[-1]) + for x, y in pair: if x == y: res += x else: break - - return res - \ No newline at end of file + return res \ No newline at end of file diff --git "a/0015.\344\270\211\346\225\260\344\271\213\345\222\214/0015-\344\270\211\346\225\260\344\271\213\345\222\214.py" "b/0015.\344\270\211\346\225\260\344\271\213\345\222\214/0015-\344\270\211\346\225\260\344\271\213\345\222\214.py" index 5ed85e1..ffe7ff2 100644 --- "a/0015.\344\270\211\346\225\260\344\271\213\345\222\214/0015-\344\270\211\346\225\260\344\271\213\345\222\214.py" +++ "b/0015.\344\270\211\346\225\260\344\271\213\345\222\214/0015-\344\270\211\346\225\260\344\271\213\345\222\214.py" @@ -4,29 +4,30 @@ def threeSum(self, nums): :type nums: List[int] :rtype: List[List[int]] """ - #固定a,用双指针在排序数组里找两数之和为-a nums.sort() - l = len(nums) res = [] - for i, a in enumerate(nums): + for i, num in enumerate(nums): if i == 0 or nums[i] > nums[i - 1]: - #开始双指针 - left, right = i + 1, len(nums) - 1 + # num + b + c == 0 + left = i + 1 + right = len(nums) - 1 + while(left < right): - s = a + nums[left] + nums[right] + s = num + nums[left] + nums[right] if s == 0: - tmp = [a, nums[left], nums[right]] - res.append(tmp) + res.append([num, nums[left], nums[right]]) left += 1 right -= 1 - while left < right and nums[left] == nums[left - 1]: + while(left < right and nums[left] == nums[left - 1]): left += 1 - while right > left and nums[right] == nums[right + 1]: + while(left < right and nums[right + 1] == nums[right]): right -= 1 - elif s < 0: - left += 1 + # break elif s > 0: right -= 1 - return res + else: + left += 1 - \ No newline at end of file + + return res + \ No newline at end of file diff --git "a/0016.\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214/0016-\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.py" "b/0016.\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214/0016-\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.py" index 4b5aaa9..e947337 100644 --- "a/0016.\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214/0016-\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.py" +++ "b/0016.\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214/0016-\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.py" @@ -6,19 +6,22 @@ def threeSumClosest(self, nums, target): :rtype: int """ nums.sort() - res = 99999999 + res = nums[0] + nums[1] + nums[2] for i, num in enumerate(nums): left, right = i + 1, len(nums) - 1 - while(left < right): + + while left < right: s = num + nums[left] + nums[right] - + # print s, res, abs(s - target), abs(res - target) if abs(s - target) < abs(res - target): res = s - if s == target: return s - elif s > target: - right -= 1 - else: + elif s < target: left += 1 - return res \ No newline at end of file + else: + right -= 1 + return res + + + \ No newline at end of file diff --git "a/0017.\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210/0017-\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.py" "b/0017.\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210/0017-\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.py" index 7b58b1c..935f397 100644 --- "a/0017.\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210/0017-\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.py" +++ "b/0017.\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210/0017-\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.py" @@ -4,20 +4,19 @@ def letterCombinations(self, digits): :type digits: str :rtype: List[str] """ + if not digits: + return [] mapping = {2:"abc", 3:"def", 4:"ghi", 5:"jkl", 6:"mno", 7:"pqrs", 8:"tuv", 9:"wxyz"} - + res = [] - for digit in digits: - temp = [] - n = int(digit) - for char in mapping[n]: - # print char - if not res: - temp.append(char) - else: - for item in res: - temp.append(item + char) - res = temp - # print res - + # for i, digit in enumerate(digits) + def dfs(nums, tmp): + if not nums: + res.append(tmp) + return + + for char in mapping[int(nums[0])]: + dfs(nums[1:], tmp + char) + + dfs(digits, "") return res \ No newline at end of file diff --git "a/0018.\345\233\233\346\225\260\344\271\213\345\222\214/0018-\345\233\233\346\225\260\344\271\213\345\222\214.py" "b/0018.\345\233\233\346\225\260\344\271\213\345\222\214/0018-\345\233\233\346\225\260\344\271\213\345\222\214.py" index 1fb6f76..16b0c4a 100644 --- "a/0018.\345\233\233\346\225\260\344\271\213\345\222\214/0018-\345\233\233\346\225\260\344\271\213\345\222\214.py" +++ "b/0018.\345\233\233\346\225\260\344\271\213\345\222\214/0018-\345\233\233\346\225\260\344\271\213\345\222\214.py" @@ -1,46 +1,37 @@ class Solution(object): - def fourSum(self, n, target): + def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ - self.res = [] - n.sort() - # print n - def threeSum(nums,t, d): - """ - :type nums: List[int] - :rtype: List[List[int]] - """ - #固定a,用双指针在排序数组里找两数之和为-a - l = len(nums) - res = [] - for i, a in enumerate(nums): - if i == 0 or nums[i] > nums[i - 1]: - #开始双指针 - left, right = i + 1, len(nums) - 1 + if len(nums) < 4: + return [] + nums.sort() + res = [] + def findThreeSum(num, l, t): + for i, n in enumerate(l): + if i == 0 or l[i] > l[i - 1]: + left, right = i + 1, len(l) - 1 while(left < right): - s = a + nums[left] + nums[right] - # print d, a, nums[left], nums[right] + s = n + l[left] + l[right] + if s == t: - tmp = [d,a, nums[left], nums[right]] - self.res.append(tmp) + res.append([num, n, l[left], l[right]]) left += 1 right -= 1 - while left < right and nums[left] == nums[left - 1]: + while(left < right and l[left] == l[left - 1]): left += 1 - while right > left and nums[right] == nums[right + 1]: + while(right > left and l[right] == l[right + 1]): right -= 1 - elif s < t: - left += 1 elif s > t: right -= 1 - - for i in range(len(n) - 3): - if i == 0 or n[i] > n[i - 1]: - # print n[i] - threeSum(n[i + 1:], target - n[i], n[i]) - + else: + left += 1 + + for i, num in enumerate(nums): + if i == 0 or nums[i] > nums[i - 1]: + findThreeSum(num, nums[i + 1:], target - num) - return self.res \ No newline at end of file + return res + \ 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\350\212\202\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\350\212\202\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\350\212\202\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\350\212\202\347\202\271.py" index 45d8dba..eb41749 100644 --- "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\350\212\202\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\350\212\202\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\350\212\202\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\350\212\202\347\202\271.py" @@ -11,23 +11,19 @@ def removeNthFromEnd(self, head, n): :type n: int :rtype: ListNode """ - if not head.next: - return [] p = head - if n == 1: - while(p.next.next): - p = p.next - p.next = None - else: - fast = head - slow = head - for i in range(n-1): - fast = fast.next - print fast.val,slow.val - while(fast.next): - fast = fast.next - slow = slow.next - print fast.val,slow.val - slow.val = slow.next.val - slow.next = slow.next.next - return head \ No newline at end of file + slow, fast = p, p + while(n): + n -= 1 + fast = fast.next + if fast is None: + return p.next + while(fast and fast.next): + fast = fast.next + slow = slow.next + + slow.next = slow.next.next + + return p + + \ 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.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.py" index 5044c13..4a34f9b 100644 --- "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.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.py" @@ -4,13 +4,14 @@ def isValid(self, s): :type s: str :rtype: bool """ - if len(s)%2: - return False - dic = {")":"(","]":"[","}":"{"} - stack = [None] - for item in s: - if item in dic and stack[-1] == dic[item]: - stack.pop() + mapping = {")":"(", "]":"[", "}":"{"} + stack = [] + for i, char in enumerate(s): + if char not in mapping:#left + stack.append(char) else: - stack.append(item) - return len(stack) == 1 + if not stack or stack[-1] != mapping[char]: + 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.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.py" new file mode 100644 index 0000000..9efb265 --- /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.py" @@ -0,0 +1,31 @@ +# 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 + """ + newhead = ListNode(0) + p = newhead + 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 + else: + p.next = l2 + return newhead.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.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.py" index 3801859..326c241 100644 --- "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.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.py" @@ -1,23 +1,22 @@ class Solution(object): - def generate(self, temp, left, right, result): - if (left == 0 and right == 0): - result.append(temp) - return - if (left > 0): - self.generate(temp + "(", left-1, right, result) - if (left < right): - self.generate(temp + ")", left, right - 1, result) - def generateParenthesis(self, n): """ :type n: int :rtype: List[str] """ - result = [] - self.generate("", n, n, result) - return result - - - + 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/0023.\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250/0023-\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250.py" "b/0023.\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250/0023-\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250.py" new file mode 100644 index 0000000..8581c27 --- /dev/null +++ "b/0023.\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250/0023-\345\220\210\345\271\266K\344\270\252\346\216\222\345\272\217\351\223\276\350\241\250.py" @@ -0,0 +1,30 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def mergeKLists(self, lists): + """ + :type lists: List[ListNode] + :rtype: ListNode + """ + from heapq import * + pq = [] + for i in range(len(lists)): + if lists[i]: + heappush(pq, (lists[i].val, i)) + lists[i] = lists[i].next + + dummy = ListNode(1) + p = dummy + while pq: + val, idx = heappop(pq) + p.next = ListNode(val) + p = p.next + if lists[idx]: + heappush(pq, (lists[idx].val, idx)) + lists[idx] = lists[idx].next + return dummy.next + \ 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.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.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.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\216\222\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\216\222\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\216\222\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\216\222\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" index e23482f..be1b92b 100644 --- "a/0026.\345\210\240\351\231\244\346\216\222\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\216\222\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\216\222\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\216\222\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" @@ -4,13 +4,14 @@ def removeDuplicates(self, nums): :type nums: List[int] :rtype: int """ - i = 0 for j in range(len(nums)): - if i < 1 or nums[j] != nums[j - 1]: + if j == 0 or nums[j] != nums[j - 1]: nums[i] = nums[j] i += 1 return i - - - \ No newline at end of file + + + + + \ 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.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.py" index 439086f..7f0c216 100644 --- "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.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.py" @@ -5,15 +5,17 @@ def removeElement(self, nums, val): :type val: int :rtype: int """ - i = 0 - while( i 0 and divisor < 0) or (dividend < 0 and divisor > 0): + if multi == 0: + return 0 + elif multi <0: op = -1 - dividend, divisor = abs(dividend), abs(divisor) + multi = 1 res = 0 while(dividend >= divisor): - multidivisor, multi = divisor, 1 - while(dividend >= multidivisor): + tmp = multi * divisor + if dividend >= tmp: + dividend -= tmp res += multi - dividend -= multidivisor - multi = multi << 1 - multidivisor = multidivisor <<1 + multi += 1 + else: + multi = 1 - - INT_MIN = -(2 **31) - INT_MAX = 2 **31 - 1 - res *= op - - return res if INT_MIN <= res <= INT_MAX else INT_MAX \ No newline at end of file + res = res * op + return res if -2 ** 31 <= res <= 2 ** 31 - 1 else 2 ** 31 - 1 \ No newline at end of file diff --git "a/0031.\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227/0031-\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.py" "b/0031.\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227/0031-\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.py" index d44dc9d..5538d3c 100644 --- "a/0031.\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227/0031-\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.py" +++ "b/0031.\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227/0031-\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.py" @@ -4,21 +4,27 @@ def nextPermutation(self, nums): :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ - #i 代表从nums结尾往前递增序列的头, j代表递增序列里比nums[i - 1]大的最小的元素 - - l = len(nums) - for i in range(l - 1, -1, -1): - if nums[i - 1] < nums[i]:# 找到了需要的i - break - - if i == 0: # 代表当前不存在下一个更大的序列,整体翻转即可 - nums[:] = nums[::-1] + if not nums or len(nums) == 1: return nums + # print nums, sorted(nums)[::-1] + if nums == sorted(nums)[::-1]: + nums[:] = nums[::-1] + return - for j in range(l - 1, i - 1, -1): - if nums[j] > nums[i - 1]: #找到了需要的j + i = len(nums) - 1 + while(i - 1 >= 0 and nums[i - 1] >= nums[i]): + i -= 1 + i -= 1 + tmp = nums[i] + j = len(nums) - 1 + while(j >= i and nums[j] <= tmp): + j -= 1 + if nums[j] > tmp: break - nums[i - 1], nums[j] = nums[j], nums[i - 1] - nums[i:] = nums[i:][::-1] - return nums \ No newline at end of file + # print tmp, nums[j], nums[i] + nums[i], nums[j] = nums[j], nums[i] + # print nums + nums[i+ 1:] = nums[i + 1:][::-1] + return + \ No newline at end of file diff --git "a/0032.\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267/0032-\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267.py" "b/0032.\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267/0032-\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267.py" new file mode 100644 index 0000000..38e69fd --- /dev/null +++ "b/0032.\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267/0032-\346\234\200\351\225\277\346\234\211\346\225\210\346\213\254\345\217\267.py" @@ -0,0 +1,19 @@ +class Solution(object): + def longestValidParentheses(self, s): + """ + :type s: str + :rtype: int + """ + stack = [-1] + res = 0 + for i, x in enumerate(s): + if x == "(": + stack.append(i) + else: + stack.pop() + if stack: + res = max(res, i - stack[-1]) + else: + stack.append(i) + + return res \ No newline at end of file diff --git "a/0033.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204/0033-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/0033.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204/0033-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.py" index 4d944f0..e6c5746 100644 --- "a/0033.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204/0033-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.py" +++ "b/0033.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204/0033-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -5,39 +5,38 @@ def search(self, nums, target): :type target: int :rtype: int """ + #1. 二分找旋转点 + #2. 确认target落在哪一侧然后二分找 if not nums: return -1 if len(nums) == 1: return 0 if nums[0] == target else -1 - - lo, hi = 0, len(nums) - 1 - while(lo <= hi): - mid = (lo + hi) // 2 - # print mid, nums[mid] - if mid + 1 < len(nums) and nums[mid] > nums[mid +1]: + midposition = -1 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + # print mid + if mid + 1 < len(nums) and nums[mid] > nums[mid + 1]: + midposition = mid break - if nums[mid] < nums[-1]: - hi = mid - 1 elif nums[mid] >= nums[0]: - lo = mid + 1 - - if lo > hi:#没有旋转 - lo, hi = 0, len(nums) - 1 - else: + left = mid + 1 + elif nums[mid] <= nums[-1]: + right = mid - 1 + # print midposition + if midposition != -1: if target >= nums[0]: - lo, hi = 0, mid + left, right = 0, midposition else: - lo, hi = mid + 1, len(nums) - 1 - - while(lo <= hi): - # print lo, hi - mid = (lo + hi) // 2 + left, right = midposition + 1, len(nums) - 1 + else: + left, right = 0, len(nums) - 1 + while(left <= right): + mid = (left + right) // 2 if nums[mid] == target: return mid elif nums[mid] > target: - hi = mid - 1 + right = mid - 1 else: - lo = mid + 1 - - return -1 - \ No newline at end of file + left = mid + 1 + return -1 \ 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.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.py" index 1df165c..6916af6 100644 --- "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.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.py" @@ -6,43 +6,51 @@ def searchRange(self, nums, target): :rtype: List[int] """ lo, hi = 0, len(nums) - 1 - #找第一个target - while(lo <= hi): + + while lo <= hi: + mid = (lo + hi) // 2 + # print lo, hi, mid, nums if nums[mid] == target: break - elif nums[mid] > target: - hi = mid - 1 - else: + elif nums[mid] < target: lo = mid + 1 - if lo > hi: #不存在 + else: + hi = mid - 1 + + if lo > hi: return [-1, -1] - - midtarget = mid - lo, hi = 0, mid - leftpos = 0 - while(lo <= hi): - # print lo, hi - if (hi >= 1 and nums[hi - 1] != target) or hi == 0: #找到左边界或者找到头了 - leftpos = hi - break + 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: - hi = mid - elif nums[mid] < target: + if nums[mid] < target: lo = mid + 1 - - rightpos = 0 - lo, hi = midtarget, len(nums) - 1 - while(lo <= hi): - if (lo <= len(nums) - 2 and nums[lo + 1] != target) or lo == len(nums) - 1: #找到右边界或者找到头了 - rightpos = lo - break - mid = (lo + hi + 1) // 2 - if nums[mid] == target: - lo = mid - elif nums[mid] > target: + 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] + - return [leftpos, rightpos] - \ No newline at end of file + \ 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.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.py" index ad0dcc8..521a7c3 100644 --- "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.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.py" @@ -5,12 +5,13 @@ def searchInsert(self, nums, target): :type target: int :rtype: int """ - if not nums: - return 0 - l = len(nums) - for index in range(l): - if nums[index] >= target: - return index - return index + 1 - - \ No newline at end of file + lo,hi = 0, len(nums) - 1 + while (lo <= hi): + mid = lo + (hi - lo) / 2 + if nums[mid] == target: + return mid + elif nums[mid] > target: + hi = mid - 1 + else: + lo = mid + 1 + return lo \ 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.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.py" index 19f59d5..ed34e1b 100644 --- "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.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.py" @@ -5,19 +5,15 @@ def isValidSudoku(self, board): :rtype: bool """ from collections import defaultdict - row = defaultdict(set) - column = defaultdict(set) - squre = defaultdict(set) - + row, column, squre = defaultdict(set), defaultdict(set), 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 column[j] or (board[i][j]) in squre[(i // 3, j // 3)]: - # print board[i][j], row[i], column[j], squre[(i // 3, j // 3)] + if board[i][j] in row[i] or board[i][j] in column[j] or board[i][j] in squre[(i//3, j//3)]: return False else: row[i].add(board[i][j]) column[j].add(board[i][j]) - squre[(i // 3, j // 3)].add(board[i][j]) - - return True \ No newline at end of file + squre[(i//3, j //3)].add(board[i][j]) + return True + \ No newline at end of file diff --git "a/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" "b/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" index f598eae..cfbd885 100644 --- "a/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" +++ "b/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" @@ -6,40 +6,43 @@ def solveSudoku(self, board): """ from collections import defaultdict row, column, squre = defaultdict(set), defaultdict(set), defaultdict(set) - fill_list = [] + + self.res = [] + def dfs(x, y): + + if x == 8 and y == 9: + # print board + for roww in board: + self.res.append(roww[:]) + # print self.res + return + if y == 9: + dfs(x + 1, 0) + return + if board[x][y].isdigit(): + dfs(x, y + 1) + return + + for k in range(1,10): + if str(k) not in row[x] and str(k) not in column[y] and str(k) not in squre[(x // 3, y // 3)]: + board[x][y] = str(k) + row[x].add(str(k)) + column[y].add(str(k)) + squre[(x // 3, y // 3)].add(str(k)) + + dfs(x, y + 1) + + board[x][y] = "." + row[x].remove(str(k)) + column[y].remove(str(k)) + squre[(x // 3, y // 3)].remove(str(k)) + for i in range(9): for j in range(9): - if board[i][j].isdigit(): #排除掉空的情况 + if board[i][j].isdigit(): row[i].add(board[i][j].encode("utf-8")) column[j].add(board[i][j].encode("utf-8")) squre[(i // 3, j // 3)].add(board[i][j].encode("utf-8")) - else: - fill_list.append([i, j]) - - self.result = [] - def backtrack(idx): - if idx == len(fill_list): - for row1 in board: - self.result.append(row1[:]) - return - if not self.result: - i, j = fill_list[idx][0], fill_list[idx][1] - for digit in range(1, 10): - if str(digit) in row[i] or str(digit) in column[j] or str(digit) in squre[(i // 3, j // 3)]: - continue - - board[i][j] = str(digit) - row[i].add(board[i][j]) - column[j].add(board[i][j]) - squre[(i // 3, j // 3)].add(board[i][j]) - - backtrack(idx + 1) - row[i].remove(board[i][j]) - column[j].remove(board[i][j]) - squre[(i // 3, j // 3)].remove(board[i][j]) - - backtrack(0) - for i in range(9): - for j in range(9): - board[i][j] = self.result[i][j] + dfs(0, 0) + board[:] = self.res \ No newline at end of file diff --git "a/0038.\346\212\245\346\225\260/0038-\346\212\245\346\225\260.py" "b/0038.\346\212\245\346\225\260/0038-\346\212\245\346\225\260.py" new file mode 100644 index 0000000..529e56d --- /dev/null +++ "b/0038.\346\212\245\346\225\260/0038-\346\212\245\346\225\260.py" @@ -0,0 +1,20 @@ +class Solution(object): + def countAndSay(self, n): + """ + :type n: int + :rtype: str + """ + record = ["1"] + for i in range(1, n): + pre = record[i - 1] + idx = 0 + tmp = "" + while idx < len(pre): + cnt = 1 + while(idx + 1 < len(pre) and pre[idx] == pre[idx + 1]): + idx += 1 + cnt += 1 + tmp += str(cnt) + pre[idx] + idx += 1 + record.append(tmp) + return record[-1] \ No newline at end of file diff --git "a/0039.\347\273\204\345\220\210\346\200\273\345\222\214/0039-\347\273\204\345\220\210\346\200\273\345\222\214.py" "b/0039.\347\273\204\345\220\210\346\200\273\345\222\214/0039-\347\273\204\345\220\210\346\200\273\345\222\214.py" index 71662df..20f1d1f 100644 --- "a/0039.\347\273\204\345\220\210\346\200\273\345\222\214/0039-\347\273\204\345\220\210\346\200\273\345\222\214.py" +++ "b/0039.\347\273\204\345\220\210\346\200\273\345\222\214/0039-\347\273\204\345\220\210\346\200\273\345\222\214.py" @@ -1,15 +1,26 @@ class Solution(object): def combinationSum(self, candidates, target): + """ + :type candidates: List[int] + :type target: int + :rtype: List[List[int]] + """ res = [] candidates.sort() + def dfs(t, tmp): + if t < 0: + return + if t == 0: + tmp.sort() + if tmp not in res: + res.append(tmp) + return + + for i, x in enumerate(candidates): + if t - x < 0: + break + dfs(t - x, tmp + [x]) - def backtrack(remain, temp, start): - if not remain: #remain为0 - res.append(temp[:]) - else: - for i, n in enumerate(candidates[start:]): - if n > remain: - break - backtrack(remain-n, temp+[n], start+i) - backtrack(target, [], 0) + + dfs(target, []) return res \ No newline at end of file diff --git "a/0040.\347\273\204\345\220\210\346\200\273\345\222\214II/0040-\347\273\204\345\220\210\346\200\273\345\222\214II.py" "b/0040.\347\273\204\345\220\210\346\200\273\345\222\214II/0040-\347\273\204\345\220\210\346\200\273\345\222\214II.py" index 294916c..c70ce0a 100644 --- "a/0040.\347\273\204\345\220\210\346\200\273\345\222\214II/0040-\347\273\204\345\220\210\346\200\273\345\222\214II.py" +++ "b/0040.\347\273\204\345\220\210\346\200\273\345\222\214II/0040-\347\273\204\345\220\210\346\200\273\345\222\214II.py" @@ -1,32 +1,25 @@ class Solution(object): - def combinationSum2(self, c, t): + def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ - res = list() - l = len(c) - def dfs(start, tmp): - s = sum(tmp) - if s == t: - tt = sorted(tmp) - if tt not in res: - res.append(tt[:]) + res = [] + candidates.sort() + def dfs(start, t, tmp): + if t == 0: + tmp.sort() + if tmp not in res: + res.append(tmp) return - if start >= l: - return - - for i in range(start, l): - - if c[i] > t or s + c[i] > t: - continue - - tmp.append(c[i]) - dfs(i + 1, tmp) - tmp.pop() - - for i,x in enumerate(c): - dfs(i, list()) + for i in range(start, len(candidates)): + x = candidates[i] + if t - x < 0: + break + dfs(i + 1, t - x, tmp + [x]) + + + dfs(0, target, []) return res \ No newline at end of file diff --git "a/0041.\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260/0041-\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260.py" "b/0041.\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260/0041-\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260.py" index abcda2e..5e1ac10 100644 --- "a/0041.\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260/0041-\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260.py" +++ "b/0041.\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260/0041-\347\274\272\345\244\261\347\232\204\347\254\254\344\270\200\344\270\252\346\255\243\346\225\260.py" @@ -4,15 +4,15 @@ def firstMissingPositive(self, nums): :type nums: List[int] :rtype: int """ - # 对于处于1~n之间的数,把它们放到nums[i - 1]的位置上 - - for i in range(len(nums)): - while 1 <= nums[i] <= len(nums) and nums[i] != nums[nums[i] - 1]: - # nums[i], nums[nums[i] - 1] = nums[nums[i] - 1], nums[i] - nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1] - - for i, x in enumerate(nums): - if x != i + 1: - return i + 1 - - return len(nums) + 1 \ No newline at end of file + if not nums: + return 1 + max_element = max(nums) + if max_element < 0: + return 1 + i = 1 + while i < max_element: + # for i in range(1, max_element): + if i not in nums: + return i + i += 1 + return max_element + 1 \ No newline at end of file diff --git "a/0042.\346\216\245\351\233\250\346\260\264/0042-\346\216\245\351\233\250\346\260\264.py" "b/0042.\346\216\245\351\233\250\346\260\264/0042-\346\216\245\351\233\250\346\260\264.py" index a5926c1..2d3dc43 100644 --- "a/0042.\346\216\245\351\233\250\346\260\264/0042-\346\216\245\351\233\250\346\260\264.py" +++ "b/0042.\346\216\245\351\233\250\346\260\264/0042-\346\216\245\351\233\250\346\260\264.py" @@ -4,28 +4,21 @@ def trap(self, height): :type height: List[int] :rtype: int """ + height = [0] + height + [0] left_max = [0 for _ in height] right_max = [0 for _ in height] - water = [0 for _ in height] - for i in range(len(height)): - if i - 1 >= 0: - left_max[i] = max(left_max[i - 1], height[i]) - else: - left_max[i] = height[i] + + for i in range(1, len(height)): + left_max[i] = max(height[i], left_max[i - 1]) + + for i in range(len(height) - 2, -1, -1): + # print i + right_max[i] = max(height[i], right_max[i + 1]) + # print left_max, right_max + # res = [0 for _ in height] + res = 0 + for i in range(1, len(height) - 2): + res += min(left_max[i], right_max[i]) - height[i] - for i in range(len(height) - 1, -1, -1): - if i < len(height) - 1: - right_max[i] = max(right_max[i + 1], height[i]) - else: - right_max[i] = height[i] - - for i in range(len(height)): - tmp = min(left_max[i], right_max[i]) - height[i] - if tmp > 0: - water[i] = tmp - # print height - # print water - # print left_max - # print right_max - return sum(water) \ No newline at end of file + return res \ No newline at end of file diff --git "a/0043.\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230/0043-\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.py" "b/0043.\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230/0043-\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.py" index 7b07eb5..d1ddced 100644 --- "a/0043.\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230/0043-\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.py" +++ "b/0043.\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230/0043-\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.py" @@ -5,65 +5,68 @@ def multiply(self, num1, num2): :type num2: str :rtype: str """ - if len(num1) < len(num2): - num1, num2 = num2, num1 - if num1 == "0" or num2 == "0": + if num1 == "0" or num2 == "0": #处理特殊情况 return "0" - num2 = num2[::-1] - tmp, res = [],[] - for i, char in enumerate(num2): - tmp = self.stringMultiDigit(num1, int(char)) + "0" * i #计算当前位乘法的结果,注意末尾添0 - res = self.stringPlusString(res, tmp) #加上当前位结果 + l1, l2 = len(num1), len(num2) + if l1 < l2: + num1, num2 = num2, num1 #保障num1始终比num2大 + l1, l2 = l2, l1 - return "".join(res) + num2 = num2[::-1] + res = "0" + for i, digit in enumerate(num2): + tmp = self.StringMultiplyDigit(num1, int(digit)) + "0" * i #计算num1和num2的当前位的乘积 + res = self.StringPlusString(res, tmp) #计算res和tmp的和 + + return res - def stringMultiDigit(self,s, n): #计算一个字符串和一个数字的乘积, 返回字符串 - s = s[::-1] - l = [] - for char in s: - l.append(int(char)) - - for i, char in enumerate(l): - l[i] *= n + def StringMultiplyDigit(self,string, n): + #这个函数的功能是:计算一个字符串和一个整数的乘积,返回字符串 + #举例:输入为 "123", 3, 返回"369" + s = string[::-1] + res = [] + for i, char in enumerate(s): + num = int(char) + res.append(num * n) + res = self.CarrySolver(res) + res = res[::-1] + return "".join(str(x) for x in res) + + def CarrySolver(self, nums): + #这个函数的功能是:将输入的数组中的每一位处理好进位 + #举例:输入[15, 27, 12], 返回[5, 8, 4, 1] + i = 0 + while i < len(nums): + if nums[i] >= 10: + carrier = nums[i] // 10 + if i == len(nums) - 1: + nums.append(carrier) + else: + nums[i + 1] += carrier + nums[i] %= 10 + i += 1 + + return nums + + def StringPlusString(self, s1, s2): + #这个函数的功能是:计算两个字符串的和 + #举例:输入为“123”, “456”, 返回为"579" + l1, l2 = len(s1), len(s2) + if l1 < l2: + s1, s2 = s2, s1 + l1, l2 = l2, l1 + s1 = [int(x) for x in s1] + s2 = [int(x) for x in s2] + s1, s2 = s1[::-1], s2[::-1] + for i, digit in enumerate(s2): + s1[i] += s2[i] - for i, char in enumerate(l): - while(l[i] > 9): - tmp = l[i] // 10 - l[i] -= tmp * 10 - if i == len(l) - 1: - l.append(0) - l[i + 1] += tmp - - return "".join(str(char) for char in l[::-1]) + s1 = self.CarrySolver(s1) + s1 = s1[::-1] + return "".join(str(x) for x in s1) - def stringPlusString(self,s1, s2): #字符串加法,返回字符串 - # print s1, s2 - s1, s2 = s1[::-1], s2[::-1] - l1, l2 = [], [] - for char in s1: - l1.append(int(char)) - for char in s2: - l2.append(int(char)) - # tmp = [] - if len(l1) < len(l2): - l1, l2 = l2, l1 - i = 0 - for i in range(len(l2)): - l1[i] += l2[i] - if l1[i] > 9: - l1[i] -= 10 - if i == len(l1) - 1: - l1.append(0) - l1[i + 1] += 1 - i += 1 - if i < len(l1) - 1: #处理最后一位可能的进位 - if l1[i] > 9: - l1[i] -= 10 - if i == len(l1) - 1: - l1.append(0) - l1[i + 1] += 1 - - return "".join(str(char) for char in l1[::-1]) - \ No newline at end of file + + + \ No newline at end of file diff --git "a/0044.\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215/0044-\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215.py" "b/0044.\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215/0044-\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215.py" new file mode 100644 index 0000000..6e5f9dd --- /dev/null +++ "b/0044.\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215/0044-\351\200\232\351\205\215\347\254\246\345\214\271\351\205\215.py" @@ -0,0 +1,35 @@ +class Solution(object): + def isMatch(self, s, p): + """ + :type s: str + :type p: str + :rtype: bool + """ + tmpp = "" + for i, char in enumerate(p): + if p[i] != "*": + tmpp += p[i] + else: + if i == 0 or p[i] != tmpp[-1]: + tmpp += "*" + p = tmpp[:] + + memo = {} + def find(i, j): + if (i, j) not in memo: + ans = False + if j == len(p): + ans = i == len(s) + elif i < len(s): + if p[j] in [s[i], "?"]: + ans = find(i + 1, j + 1) + elif p[j] == "*": + ans = find(i, j + 1) or find(i + 1, j) + elif p[j] == "*": + ans = find(i, j + 1) + memo[i, j] = ans + return memo[i, j] + + return find(0, 0) + + \ 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.py" "b/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" index 457bb71..f2a991c 100644 --- "a/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" +++ "b/0046.\345\205\250\346\216\222\345\210\227/0046-\345\205\250\346\216\222\345\210\227.py" @@ -1,22 +1,16 @@ - class Solution(object): def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ - res, l = list(), len(nums) - def dfs(n, tmp): - if len(tmp) == l: - res.append(tmp[:]) - return - for i, x in enumerate(n): - tmp.append(x) - dfs(n[:i] + n[i + 1:], tmp) - tmp.pop() - - - for i, x in enumerate(nums): - dfs(nums[:i] + nums[i + 1:], [x]) + 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/0047.\345\205\250\346\216\222\345\210\227II/0047-\345\205\250\346\216\222\345\210\227II.py" "b/0047.\345\205\250\346\216\222\345\210\227II/0047-\345\205\250\346\216\222\345\210\227II.py" index fcb677f..08a58bd 100644 --- "a/0047.\345\205\250\346\216\222\345\210\227II/0047-\345\205\250\346\216\222\345\210\227II.py" +++ "b/0047.\345\205\250\346\216\222\345\210\227II/0047-\345\205\250\346\216\222\345\210\227II.py" @@ -4,19 +4,16 @@ def permuteUnique(self, nums): :type nums: List[int] :rtype: List[List[int]] """ - res, l = list(), len(nums) - def dfs(n, tmp): - if len(tmp) == l: - if tmp not in res: - res.append(tmp[:]) - return - for i, x in enumerate(n): - tmp.append(x) - dfs(n[:i] + n[i + 1:], tmp) - tmp.pop() - - - for i, x in enumerate(nums): - dfs(nums[:i] + nums[i + 1:], [x]) - + nums.sort() + res = [] + record = dict() + def dfs(tmp, nums): + if not nums: + res.append(tmp) + + for i, x in enumerate(nums): + if i == 0 or nums[i] != nums[i - 1]: + 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.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.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.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.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.py" index e9abe00..6998b4a 100644 --- "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.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.py" @@ -4,13 +4,15 @@ def groupAnagrams(self, strs): :type strs: List[str] :rtype: List[List[str]] """ - hashmap = dict() - for s in strs: - t = "".join(sorted(s)) - - if t in hashmap: - hashmap[t].append(s) + record = dict() + + for word in strs: + tmp = tuple(sorted(word)) + # print tmp + if tmp in record: + record[tmp].append(word) else: - hashmap[t] = [s] + record[tmp] = [word] + return [val for key, val in record.items()] - return hashmap.values() \ No newline at end of file + \ No newline at end of file diff --git a/0050.Pow(x,n)/0050-Pow(x,n).py b/0050.Pow(x,n)/0050-Pow(x,n).py index ef94423..4d7478f 100644 --- a/0050.Pow(x,n)/0050-Pow(x,n).py +++ b/0050.Pow(x,n)/0050-Pow(x,n).py @@ -1,17 +1,22 @@ class Solution(object): - def myPow(self, x, n): + def myPow(self, x0, n): """ :type x: float :type n: int :rtype: float """ - i = abs(n) - res = 1.0 - while(i != 0): - if i % 2: - res *= x - x *= x - # print i, res - i /= 2 - return res if n > 0 else 1/res - \ No newline at end of file + if not n: + return 1 + def helper(x, n, tmp): + print n, x + if n <= 1: + return x * tmp + if n % 2: + tmp *= x + n -= 1 + return helper(x * x, n // 2, tmp) + op = 1 + if n < 0: + op = -1 + res = helper(x0, abs(n), 1) + return res if op > 0 else 1.0/res \ No newline at end of file diff --git "a/0051.N\347\232\207\345\220\216/0051-N\347\232\207\345\220\216.py" "b/0051.N\347\232\207\345\220\216/0051-N\347\232\207\345\220\216.py" index 76f3f05..c718df3 100644 --- "a/0051.N\347\232\207\345\220\216/0051-N\347\232\207\345\220\216.py" +++ "b/0051.N\347\232\207\345\220\216/0051-N\347\232\207\345\220\216.py" @@ -4,51 +4,40 @@ def solveNQueens(self, n): :type n: int :rtype: List[List[str]] """ - board = ["." * n for _ in range(n)] - + if n <= 0: + return [] res = [] - def checkRowAndCol(row, col): + def dfs(start, tmp): + if start == n: + res.append(tmp[:]) + return for i in range(n): - if (board[row][i] == "Q" and i != col) or (board[i][col] == "Q" and i != row): #发生了横向或者纵向冲突 - return False - return True - - def checkDoubleDio(row, col): - add = row + col - sub = col - row - - for x in range(n): - if x == row: #跳过自身这个点 - continue - y = add - x - # print add,sub, x, y - if y >= 0 and y < n and x >= 0 and x < n and board[x][y] == "Q": #发生/冲突 - return False - - y = sub + x - if y >= 0 and y < n and x >= 0 and x < n and board[x][y] == "Q": #发生\冲突 - return False - - return True - + tmp.append("." * i + "Q" + "." * (n - i - 1)) + if self.isValid(tmp, start, i, n): + dfs(start + 1, tmp) + tmp.pop() + dfs(0, []) + return res + + def isValid(self, tmp, x0, y0, n): + self.add = x0 + y0 + self.sub = y0 - x0 - def dfs(row, col): - if col >= n: #本行所有位置都找完了 - return - board[row] = "." * col + "Q" + (n - col - 1) * "." #把皇后放在(row, col)的位置上 - if checkRowAndCol(row, col) and checkDoubleDio(row, col): #如果没有发生冲突 - if row == n - 1: #如果放下的是最后一个皇后 - # print board - res.append(board[:]) #找到一个可行解啦!!! - else: - for i in range(n): #还要放更多的皇后,往下一行放吧 - dfs(row + 1, i) - - board[row] = "." * n #回溯,把本行放下的皇后拿回来 - # dfs(row, col + 1) - return - - for i in range(n): - dfs(0, i) + for i in range(len(tmp)): #判断列 + if i == x0: + continue + if tmp[i][y0] == "Q": + return False - return res \ No newline at end of file + for i in range(min(n, len(tmp))): #判断\ + if i == x0: + continue + # print i, j + j = self.add - i + # print i, j, self.add, tmp + if 0 <= j < n and tmp[i][j] == "Q": + return False + j = i + self.sub + if 0 <= j < n and tmp[i][j] == "Q": + return False + return True \ No newline at end of file diff --git "a/0052.N\347\232\207\345\220\216II/0052-N\347\232\207\345\220\216II.py" "b/0052.N\347\232\207\345\220\216II/0052-N\347\232\207\345\220\216II.py" index 2e04536..68308b8 100644 --- "a/0052.N\347\232\207\345\220\216II/0052-N\347\232\207\345\220\216II.py" +++ "b/0052.N\347\232\207\345\220\216II/0052-N\347\232\207\345\220\216II.py" @@ -4,52 +4,40 @@ def totalNQueens(self, n): :type n: int :rtype: int """ - - board = ["." * n for _ in range(n)] - # print board + if n <= 0: + return [] self.res = 0 - def checkRowAndCol(row, col): + def dfs(start, tmp): + if start == n: + self.res += 1 + return for i in range(n): - if (board[row][i] == "Q" and i != col) or (board[i][col] == "Q" and i != row): - return False - return True - - def checkDoubleDio(row, col): - add = row + col - sub = col - row - - for x in range(n): - if x == row: - continue - y = add - x - # print add,sub, x, y - if y >= 0 and y < n and x >= 0 and x < n and board[x][y] == "Q": - return False - - y = sub + x - if y >= 0 and y < n and x >= 0 and x < n and board[x][y] == "Q": - return False - - return True - + tmp.append("." * i + "Q" + "." * (n - i - 1)) + if self.isValid(tmp, start, i, n): + dfs(start + 1, tmp) + tmp.pop() + dfs(0, []) + return self.res + + def isValid(self, tmp, x0, y0, n): + self.add = x0 + y0 + self.sub = y0 - x0 - def dfs(row, col): - if col >= n: - return - board[row] = "." * col + "Q" + (n - col - 1) * "." - if checkRowAndCol(row, col) and checkDoubleDio(row, col): - if row == n - 1: - # print board - self.res += 1 - else: - for i in range(n): - dfs(row + 1, i) - - board[row] = "." * n - # dfs(row, col + 1) - return - - for i in range(n): - dfs(0, i) + for i in range(len(tmp)): #判断列 + if i == x0: + continue + if tmp[i][y0] == "Q": + return False - return self.res \ No newline at end of file + for i in range(min(n, len(tmp))): #判断\ + if i == x0: + continue + # print i, j + j = self.add - i + # print i, j, self.add, tmp + if 0 <= j < n and tmp[i][j] == "Q": + return False + j = i + self.sub + if 0 <= j < n and tmp[i][j] == "Q": + return False + return True \ No newline at end of file diff --git "a/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" "b/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" index c890aaf..10a5d37 100644 --- "a/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" +++ "b/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" @@ -6,10 +6,14 @@ def maxSubArray(self, nums): """ if not nums: return 0 - dp = [nums[0]] - res = dp[0] - for i in range(1, len(nums)): - dp.append(max(dp[i-1] + nums[i], nums[i])) - if dp[-1] > res: - res = dp[-1] - return res \ No newline at end of file + dp = [] # dp[i]表示以i结尾的连续子数组的最大和 + for i, x in enumerate(nums): + if i == 0: + dp.append(x) + else: + if dp[-1] < 0: + dp.append(x) + else: + dp.append(dp[-1] + x) + + return max(dp) \ 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.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.py" index 4b07771..33e693b 100644 --- "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.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.py" @@ -4,27 +4,39 @@ def spiralOrder(self, matrix): :type matrix: List[List[int]] :rtype: List[int] """ - m = len(matrix) - if m == 0: + if not matrix or not matrix[0]: return [] - n = len(matrix[0]) - if n == 0: - return [] - r, i, j, di, dj = list(), 0, 0, 0, 1 - - for _ in range(m * n): - r.append(matrix[i][j]) - matrix[i][j] = None - if matrix[(i + di) % m][(j + dj) % n] == None: #来过了改转向了 - di, dj = dj, -di #0 1 变 1 0, 1 0 变 0 -1, 0 -1 变 -1, 0, -1 0 变 0 1 - i += di - j += dj - - return r - - - - - - - \ No newline at end of file + 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.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.py" index 8198fc2..b6283c9 100644 --- "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.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.py" @@ -4,10 +4,9 @@ def canJump(self, nums): :type nums: List[int] :rtype: bool """ - - max_jump = 0 - for index, num in enumerate(nums): - if index > max_jump: - return False - max_jump = max(max_jump, index + num) - return True \ No newline at end of file + 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/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" "b/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" index ea26cc6..04c87a0 100644 --- "a/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" +++ "b/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" @@ -1,29 +1,21 @@ -# Definition for an interval. -# class Interval(object): -# def __init__(self, s=0, e=0): -# self.start = s -# self.end = e - class Solution(object): def merge(self, intervals): """ - :type intervals: List[Interval] - :rtype: List[Interval] + :type intervals: List[List[int]] + :rtype: List[List[int]] """ if not intervals: - return [] - intervals = sorted(intervals,key=lambda x:x.start) + return intervals + intervals = sorted(intervals, key = lambda x: x[0]) + start, end = intervals[0][0], intervals[0][1] + res = [] - left = intervals[0].start - right = intervals[0].end - for item in intervals: - if item.start <= right: - right = max(right, item.end) + for i, interval in enumerate(intervals): + if interval[0] > end: + res.append([start, end]) + start, end = interval[0], interval[1] else: - res.append([left, right]) - left = item.start - right = item.end - res.append([left, right]) - + end = max(end, interval[1]) + res.append([start, end]) return res - \ No newline at end of file + \ No newline at end of file diff --git "a/0057.\346\217\222\345\205\245\345\214\272\351\227\264/0057-\346\217\222\345\205\245\345\214\272\351\227\264.py" "b/0057.\346\217\222\345\205\245\345\214\272\351\227\264/0057-\346\217\222\345\205\245\345\214\272\351\227\264.py" index 508ed54..0c3824e 100644 --- "a/0057.\346\217\222\345\205\245\345\214\272\351\227\264/0057-\346\217\222\345\205\245\345\214\272\351\227\264.py" +++ "b/0057.\346\217\222\345\205\245\345\214\272\351\227\264/0057-\346\217\222\345\205\245\345\214\272\351\227\264.py" @@ -1,42 +1,28 @@ -# Definition for an interval. -# class Interval(object): -# def __init__(self, s=0, e=0): -# self.start = s -# self.end = e - class Solution(object): def insert(self, intervals, newInterval): """ - :type intervals: List[Interval] - :type newInterval: Interval - :rtype: List[Interval] + :type intervals: List[List[int]] + :type newInterval: List[int] + :rtype: List[List[int]] """ - # tmp = Interval(newInterval[0], newInterval[1]) intervals.append(newInterval) - # intervals[-1] = newInterval - # print type(intervals[0]), type(tmp) return self.merge(intervals) - def merge(self, intervals): """ - :type intervals: List[Interval] - :rtype: List[Interval] + :type intervals: List[List[int]] + :rtype: List[List[int]] """ - if not intervals: - return [] - intervals = sorted(intervals,key=lambda x:x[0]) + return intervals + intervals = sorted(intervals, key = lambda x: x[0]) + start, end = intervals[0][0], intervals[0][1] + res = [] - left = intervals[0][0] - right = intervals[0][1] - for item in intervals: - if item[0] <= right: - right = max(right, item[1]) + for i, interval in enumerate(intervals): + if interval[0] > end: + res.append([start, end]) + start, end = interval[0], interval[1] else: - res.append([left, right]) - left = item[0] - right = item[1] - res.append([left, right]) - - return res - \ No newline at end of file + end = max(end, interval[1]) + res.append([start, end]) + return res \ 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.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.py" index 7e36392..2ef7de1 100644 --- "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.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.py" @@ -4,9 +4,11 @@ def lengthOfLastWord(self, s): :type s: str :rtype: int """ - if len(s) <= 0 : - return 0 - s = s.rstrip(" ") - print s,s.split(" ") - return len(s.split(" ")[-1]) - \ No newline at end of file + 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/0059.\350\236\272\346\227\213\347\237\251\351\230\265II/0059-\350\236\272\346\227\213\347\237\251\351\230\265II.py" "b/0059.\350\236\272\346\227\213\347\237\251\351\230\265II/0059-\350\236\272\346\227\213\347\237\251\351\230\265II.py" index c4b4cc0..7789cb1 100644 --- "a/0059.\350\236\272\346\227\213\347\237\251\351\230\265II/0059-\350\236\272\346\227\213\347\237\251\351\230\265II.py" +++ "b/0059.\350\236\272\346\227\213\347\237\251\351\230\265II/0059-\350\236\272\346\227\213\347\237\251\351\230\265II.py" @@ -4,16 +4,35 @@ def generateMatrix(self, n): :type n: int :rtype: List[List[int]] """ - - res = [[0 for i in range(n)] for j in range(n)] - - i, j, di, dj = 0, 0, 0, 1 - for number in range(1, n ** 2 + 1): - res[i][j] = number - if res[(i + di) % n][(j + dj) % n] != 0: #需要转向 - di, dj = dj, - di - i += di - j += dj - - return res - \ No newline at end of file + i, j = 0, 0 + state = "right" + cnt = 0 + res = [[0 for _ in range(n)] for _ in range(n)] + while(cnt < n * n): + cnt += 1 + res[i][j] = cnt + if state == "right": + j += 1 + if j == n or res[i][j] != 0: + i += 1 + j -= 1 + state = "down" + elif state == "down": + i += 1 + if i == n or res[i][j] != 0: + i -= 1 + j -= 1 + state = "left" + elif state == "left": + j -= 1 + if j == -1 or res[i][j] != 0: + j += 1 + i -= 1 + state = "up" + elif state == "up": + i -= 1 + if i == -1 or res[i][j] != 0: + i += 1 + j += 1 + state = "right" + return res \ No newline at end of file diff --git "a/0060.\347\254\254k\344\270\252\346\216\222\345\210\227/0060-\347\254\254k\344\270\252\346\216\222\345\210\227.py" "b/0060.\347\254\254k\344\270\252\346\216\222\345\210\227/0060-\347\254\254k\344\270\252\346\216\222\345\210\227.py" index 306e3dc..ac61812 100644 --- "a/0060.\347\254\254k\344\270\252\346\216\222\345\210\227/0060-\347\254\254k\344\270\252\346\216\222\345\210\227.py" +++ "b/0060.\347\254\254k\344\270\252\346\216\222\345\210\227/0060-\347\254\254k\344\270\252\346\216\222\345\210\227.py" @@ -1,4 +1,3 @@ -import math class Solution(object): def getPermutation(self, n, k): """ @@ -6,13 +5,24 @@ def getPermutation(self, n, k): :type k: int :rtype: str """ - digit = [i for i in range(1, n + 1)] #生成1 ~ n的列表 - res = "" - while n > 0: - tmp = math.factorial(n - 1) #计算一共有多少种组合 - idx = (k - 1) / tmp #由K在tmp中占的比例来确定第一位的数字 - k -= idx * tmp #第一位确定之后,刷新k - res += str(digit[idx]) - digit.pop(idx) - n -= 1 - return res \ No newline at end of file + fac = [1] + for i in range(2, n + 1): + fac.append(fac[-1] * i) + digits = [i for i in range(1, n + 1)] + + self.res = "" + def dfs(left_digit, tmp, kk): + if left_digit == 0: + self.res = tmp[:] + return + for digit in digits: + kk -= fac[left_digit - 2] + if kk <= 0: + kk += fac[left_digit - 2] + fac.pop() + digits.remove(digit) + dfs(left_digit - 1, tmp + str(digit), kk) + break + + dfs(n, "", k) + return self.res \ No newline at end of file diff --git "a/0061.\346\227\213\350\275\254\351\223\276\350\241\250/0061-\346\227\213\350\275\254\351\223\276\350\241\250.py" "b/0061.\346\227\213\350\275\254\351\223\276\350\241\250/0061-\346\227\213\350\275\254\351\223\276\350\241\250.py" index 0ebda46..d44f254 100644 --- "a/0061.\346\227\213\350\275\254\351\223\276\350\241\250/0061-\346\227\213\350\275\254\351\223\276\350\241\250.py" +++ "b/0061.\346\227\213\350\275\254\351\223\276\350\241\250/0061-\346\227\213\350\275\254\351\223\276\350\241\250.py" @@ -11,30 +11,22 @@ def rotateRight(self, head, k): :type k: int :rtype: ListNode """ - if k <= 0: + p = head + l = [] + while p: + l.append(p.val) + p = p.next + if len(l) <= 1: return head - l = 0 - ptr = head - while(ptr != None): - ptr = ptr.next - l += 1 - # print l - if l <= 1: - return head - k = k % l - if k == 0: + k = k % len(l) + if not k: return head - fast = head - slow = head - while(k != 0): - fast = fast.next - k-= 1 - while(fast.next != None): - fast = fast.next - slow = slow.next - # print fast.val, slow.val - ptr = slow.next - fast.next = head - slow.next = None - return ptr \ No newline at end of file + l = l[-k:] + l[:-k] + print l + newhead = ListNode(-1) + p = newhead + for item in l: + p.next = ListNode(item) + p = p.next + return newhead.next \ No newline at end of file diff --git "a/0062.\344\270\215\345\220\214\350\267\257\345\276\204/0062-\344\270\215\345\220\214\350\267\257\345\276\204.py" "b/0062.\344\270\215\345\220\214\350\267\257\345\276\204/0062-\344\270\215\345\220\214\350\267\257\345\276\204.py" index 75c7dd1..8c89221 100644 --- "a/0062.\344\270\215\345\220\214\350\267\257\345\276\204/0062-\344\270\215\345\220\214\350\267\257\345\276\204.py" +++ "b/0062.\344\270\215\345\220\214\350\267\257\345\276\204/0062-\344\270\215\345\220\214\350\267\257\345\276\204.py" @@ -5,17 +5,14 @@ def uniquePaths(self, m, n): :type n: int :rtype: int """ - # C(m + n - 2) (m - 1) - k = m + n - 2 - t = m - 1 + dp = [[0 for _ in range(m)]for _ in range(n)] - up = 1 - for i in range(0, t): - up *= k - i - - down = 1 - for i in range(1, m): - down *= i - - # print up, down - return up // down \ No newline at end of file + for i in range(m): + dp[0][i] = 1 + for j in range(n): + dp[j][0] = 1 + + for i in range(1, n): + for j in range(1, m): + dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + return dp[-1][-1] \ No newline at end of file diff --git "a/0063.\344\270\215\345\220\214\350\267\257\345\276\204II/0063-\344\270\215\345\220\214\350\267\257\345\276\204II.py" "b/0063.\344\270\215\345\220\214\350\267\257\345\276\204II/0063-\344\270\215\345\220\214\350\267\257\345\276\204II.py" new file mode 100644 index 0000000..53bf790 --- /dev/null +++ "b/0063.\344\270\215\345\220\214\350\267\257\345\276\204II/0063-\344\270\215\345\220\214\350\267\257\345\276\204II.py" @@ -0,0 +1,28 @@ +class Solution(object): + def uniquePathsWithObstacles(self, obstacleGrid): + """ + :type obstacleGrid: List[List[int]] + :rtype: int + """ + if not obstacleGrid or not obstacleGrid[0] or obstacleGrid[0][0] == 1 or obstacleGrid[-1][-1] == 1: + return 0 + m, n = len(obstacleGrid[0]), len(obstacleGrid) + dp = [[0 for _ in range(m)]for _ in range(n)] + + for i in range(m): + if obstacleGrid[0][i] != 1: + dp[0][i] = 1 + else: + break + for j in range(n): + if obstacleGrid[j][0] != 1: + + dp[j][0] = 1 + else: + break + + for i in range(1, n): + for j in range(1, m): + if obstacleGrid[i][j] != 1: + dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + return dp[-1][-1] \ No newline at end of file diff --git "a/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" "b/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" index df7bfe7..d6a6897 100644 --- "a/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" +++ "b/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" @@ -4,21 +4,23 @@ def minPathSum(self, grid): :type grid: List[List[int]] :rtype: int """ - #dp[m][n] = min(dp[m - 1][n], dp[m][n - 1]) + grid[m][n] - if not grid: + if not grid or not grid[0]: return 0 - m = len(grid) - n = len(grid[0]) - dp = [[0] * (n)] * (m) + m, n = len(grid), len(grid[0]) + dp = [[0 for _ in range(n)] for _ in range(m)] for i in range(m): for j in range(n): - # print dp, i, j - if not i and not j: - dp[i][j] = grid[i][j] - elif i and not j: - dp[i][j] = dp[i-1][j] + grid[i][j] - elif not i and j: - dp[i][j] = dp[i][j-1] + grid[i][j] - else: - dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + grid[i][j] - return dp[m-1][n-1] \ No newline at end of file + # print i, j + dp[i][j] = grid[i][j] + + + dp[0][0] = grid[0][0] + for i in range(m): + for j in range(n): + if i - 1 >= 0 and j - 1 >= 0: + dp[i][j] += min(dp[i - 1][j], dp[i][j - 1]) + elif i - 1 >= 0: + dp[i][j] += dp[i - 1][j] + elif j - 1 >= 0: + dp[i][j] += dp[i][j - 1] + return dp[-1][-1] \ No newline at end of file diff --git "a/0066.\345\212\240\344\270\200/0066-\345\212\240\344\270\200.py" "b/0066.\345\212\240\344\270\200/0066-\345\212\240\344\270\200.py" index 0e3ec96..2811cf8 100644 --- "a/0066.\345\212\240\344\270\200/0066-\345\212\240\344\270\200.py" +++ "b/0066.\345\212\240\344\270\200/0066-\345\212\240\344\270\200.py" @@ -4,21 +4,14 @@ def plusOne(self, digits): :type digits: List[int] :rtype: List[int] """ - index = 0 - if digits[-1] != 9: - digits[-1] += 1 - return digits - else: - for index in range(len(digits)-1, -1,-1): - if digits[index] != 9: - break - if digits[index] != 9: - digits[index] += 1 - for i in range(index+ 1, len(digits)): - digits[i] = 0 - return digits - else: - res = [1] - for i in range(0,len(digits)): - res.append(0) - return res \ No newline at end of file + l = digits[::-1] + + l[0] += 1 + for i in range(len(l)): + if l[i] > 9: + l[i] -= 10 + if i != len(l) - 1: + l[i + 1] += 1 + else: + l.append(1) + return l[::-1] \ No newline at end of file diff --git "a/0067.\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214/0067-\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214.py" "b/0067.\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214/0067-\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214.py" index 4078a02..9daca05 100644 --- "a/0067.\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214/0067-\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214.py" +++ "b/0067.\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214/0067-\344\272\214\350\277\233\345\210\266\346\261\202\345\222\214.py" @@ -5,4 +5,26 @@ def addBinary(self, a, b): :type b: str :rtype: str """ - return bin(int(a,2) + int(b,2))[2:] \ No newline at end of file + l1, l2 = len(a), len(b) + if l1 < l2: + l1, l2 = l2, l1 + a, b = b, a + la, lb = [], [] + for char in a: + la.append(int(char)) + for char in b: + lb.append(int(char)) + la, lb = la[::-1], lb[::-1] + + for i in range(l1): + if i < l2: + la[i] += lb[i] + if la[i] > 1: + la[i] -= 2 + if i != l1 - 1: + la[i + 1] += 1 + else: + la.append(1) + + return "".join(str(x) for x in la[::-1]) + \ 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.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.py" index e69de29..ed61097 100644 --- "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.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.py" @@ -0,0 +1,21 @@ +class Solution(object): + def mySqrt(self, x): + """ + :type x: int + :rtype: int + """ + if not x : + return 0 + if x < 4: + return 1 + start, end = 2, x // 2 + while 1: + i = (start + end) // 2 + if i ** 2 <= x and (i + 1) ** 2 >x: + return i + elif i ** 2 < x: + start = i + 1 + elif i ** 2 > x: + end = i - 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.py" "b/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" index 46b3b2e..88ab0fc 100644 --- "a/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" +++ "b/0070.\347\210\254\346\245\274\346\242\257/0070-\347\210\254\346\245\274\346\242\257.py" @@ -1,22 +1,19 @@ class Solution(object): - def climbStairs(self, n): """ :type n: int :rtype: int """ - if n <= 1: - return 1 - if n == 2: - return 2 - a = 1 - b = 2 - count = 3 - while count<=n: - c = a + b - a = b - b = c - count += 1 - return c - - + 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.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.py" index 658d06a..d008010 100644 --- "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.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.py" @@ -4,16 +4,12 @@ def simplifyPath(self, path): :type path: str :rtype: str """ - if not path: - return "" - pathList = path.split("/") + l = path.split("/") stack = [] - for path in pathList: - if path == "." or path == "": - continue - if path == "..": - if stack: - stack.pop() - else: - stack.append(path) + 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/0072.\347\274\226\350\276\221\350\267\235\347\246\273/0072-\347\274\226\350\276\221\350\267\235\347\246\273.py" "b/0072.\347\274\226\350\276\221\350\267\235\347\246\273/0072-\347\274\226\350\276\221\350\267\235\347\246\273.py" index 5fb05aa..84662af 100644 --- "a/0072.\347\274\226\350\276\221\350\267\235\347\246\273/0072-\347\274\226\350\276\221\350\267\235\347\246\273.py" +++ "b/0072.\347\274\226\350\276\221\350\267\235\347\246\273/0072-\347\274\226\350\276\221\350\267\235\347\246\273.py" @@ -5,21 +5,21 @@ def minDistance(self, word1, word2): :type word2: str :rtype: int """ - #用dp[i][j]表示word1[:i + 1], word2[:j + 1]这个问题的解 - m, n = len(word1), len(word2) - dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] + #dp[i][j]表示word1[:i + 1]和word2[:j + 1]的解 + l1, l2 = len(word1), len(word2) + dp = [[0 for _ in range(l2 + 1)] for _ in range(l1 + 1)] - for i in range(m + 1): + for i in range(l1 + 1): dp[i][0] = i + for j in range(l2 + 1): + dp[0][j] = j - for i in range(n + 1): - dp[0][i] = i - - for i in range(1, m + 1): - for j in range(1, n + 1): + for i in range(1, l1 + 1): + for j in range(1, l2 + 1): if word1[i - 1] == word2[j - 1]: dp[i][j] = dp[i - 1][j - 1] else: - dp[i][j] = 1 + min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) #分别对应插入,替换,删除 - - return dp[m][n] \ No newline at end of file + dp[i][j] = 1 + min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) + return dp[l1][l2] + + \ 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.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.py" index fd3f47b..f33d6de 100644 --- "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.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.py" @@ -2,23 +2,23 @@ class Solution(object): def setZeroes(self, matrix): """ :type matrix: List[List[int]] - :rtype: void Do not return anything, modify matrix in-place instead. + :rtype: None Do not return anything, modify matrix in-place instead. """ - self.matrix = matrix - m = len(matrix) - n = len(matrix[0]) - l_m = [1] * m - l_n = [1] * n + 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): - # print matrix[i][j], i, j if matrix[i][j] == 0: - l_m[i] = 0 - l_n[j] = 0 - # print l_m, l_n + 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): - # print i,j - if l_m[i] == 0 or l_n[j] == 0: - matrix[i][j] = 0 - # print matrix + if matrix[i][j] == "0": + matrix[i][j] = 0 + \ No newline at end of file diff --git "a/0074.\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265/0074-\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.py" "b/0074.\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265/0074-\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.py" index e36dfbb..a298ed2 100644 --- "a/0074.\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265/0074-\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.py" +++ "b/0074.\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265/0074-\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.py" @@ -5,23 +5,19 @@ def searchMatrix(self, matrix, target): :type target: int :rtype: bool """ - m = len(matrix) - if m == 0: - return False - n = len(matrix[0]) - if n == 0: + if not matrix or not matrix[0]: return False + m, n = len(matrix), len(matrix[0]) - x, y = m - 1, 0 - while(1): - if x < 0 or x >= m or y <0 or y >= n: - break - val = matrix[x][y] - if val == target: - return True - elif val > target: - x -= 1 - elif val target: + i -= 1 + else: + return False \ No newline at end of file diff --git "a/0075.\351\242\234\350\211\262\345\210\206\347\261\273/0075-\351\242\234\350\211\262\345\210\206\347\261\273.py" "b/0075.\351\242\234\350\211\262\345\210\206\347\261\273/0075-\351\242\234\350\211\262\345\210\206\347\261\273.py" index f91676d..45ee9b3 100644 --- "a/0075.\351\242\234\350\211\262\345\210\206\347\261\273/0075-\351\242\234\350\211\262\345\210\206\347\261\273.py" +++ "b/0075.\351\242\234\350\211\262\345\210\206\347\261\273/0075-\351\242\234\350\211\262\345\210\206\347\261\273.py" @@ -2,31 +2,19 @@ class Solution(object): def sortColors(self, nums): """ :type nums: List[int] - :rtype: void Do not return anything, modify nums in-place instead. + :rtype: None Do not return anything, modify nums in-place instead. """ - b = 0 - r = 0 - w = 0 - for item in nums: - if item == 0: - r+= 1 - if item == 1: - w += 1 - if item == 2: - b += 1 - for index,item in enumerate(nums): - if r!= 0: - nums[index] = 0 - r -= 1 - continue - if w!= 0: - nums[index] = 1 - w -= 1 - continue - if b!= 0: - nums[index] = 2 - b -= 1 - continue - # return nums - - \ No newline at end of file + lo, hi = 0, len(nums) - 1 + i = 0 + while i <= hi: + x = nums[i] + if x == 0: + nums[lo], nums[i] = nums[i], nums[lo] + lo += 1 + i += 1 + elif x == 2: + nums[hi], nums[i] = nums[i], nums[hi] + hi -= 1 + else: + i += 1 + \ No newline at end of file diff --git "a/0077.\347\273\204\345\220\210/0077-\347\273\204\345\220\210.py" "b/0077.\347\273\204\345\220\210/0077-\347\273\204\345\220\210.py" index fba47df..c3cdc1b 100644 --- "a/0077.\347\273\204\345\220\210/0077-\347\273\204\345\220\210.py" +++ "b/0077.\347\273\204\345\220\210/0077-\347\273\204\345\220\210.py" @@ -6,18 +6,13 @@ def combine(self, n, k): :rtype: List[List[int]] """ res = [] - def generate(k, i, tmp): - - if k == 0: + def dfs(t, cnt, tmp): + if cnt == 0: res.append(tmp[:]) - return - - for j in range(i , n + 1): - tmp.append(j) - generate(k - 1, j + 1, tmp) - tmp.pop() + + for i in range(t + 1, n + 1): + dfs(i, cnt - 1, tmp + [i]) - - generate(k, 1, []) + dfs(0, k, []) return res - \ No newline at end of file + \ No newline at end of file diff --git "a/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" "b/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" index e2fcb4e..6012ad0 100644 --- "a/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" +++ "b/0078.\345\255\220\351\233\206/0078-\345\255\220\351\233\206.py" @@ -1,24 +1,14 @@ -import copy class Solution(object): def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] - """ - res, tmp = [], [] - - def generate(nums, n): - res.append(tmp[:]) + """ + res = [[]] + for num in nums: + tmp = res[:] + for item in res: + tmp.append(item + [num]) + res = tmp[:] - if n == len(nums): - return - for i in range(n, len(nums)): - tmp.append(nums[i]) - n += 1 - generate(nums, n) - tmp.pop() - - generate(nums, 0) - return res - - \ No newline at end of file + return res \ No newline at end of file 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 5af9e24..77cc5f1 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" @@ -5,45 +5,36 @@ def exist(self, board, word): :type word: str :rtype: bool """ - if not board or not board[0] or not len(word): - return False - - m, n = len(board), len(board[0]) - if len(word) > m *n: + if not board or not board[0]: return False + if not word: + return True self.res = False dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - visited = [[0 for _ in range(n + 1)] for j in range(m + 1)] - def dfs(start, x0, y0): - if start >= len(word) or board[x0][y0] != word[start]: #找不到解 + if start == len(word) - 1: + self.res = True return + visited.add((x0, y0)) - visited[x0][y0] = 1 - if board[x0][y0] == word[start]: - if start == len(word) - 1: #找到一个可行解啦!!! - self.res = True - return - else: - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0<= x < m and 0<= y < n and visited[x][y] == 0 and not self.res: #not self.res很关键,剪枝非常重要 - dfs(start + 1, x, y) #找下一个字母 - visited[x0][y0] = 0 #回溯 - + 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) for i in range(m): for j in range(n): if board[i][j] == word[0]: - dfs(0, i, j) #开始搜索 - if self.res: - return self.res - return self.res - - - - \ No newline at end of file + visited = set() + dfs(0, i, j) + if self.res: + return True + return False \ No newline at end of file diff --git "a/0080.\345\210\240\351\231\244\346\216\222\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\216\222\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\216\222\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\216\222\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" index e489bb1..9bac95c 100644 --- "a/0080.\345\210\240\351\231\244\346\216\222\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\216\222\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\216\222\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\216\222\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" @@ -9,4 +9,5 @@ def removeDuplicates(self, nums): if i < 2 or num != nums[i - 2]: nums[i] = num i += 1 + return i \ No newline at end of file diff --git "a/0081.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II/0081-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II.py" "b/0081.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II/0081-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II.py" index c30f94d..e5f1122 100644 --- "a/0081.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II/0081-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II.py" +++ "b/0081.\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II/0081-\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204II.py" @@ -5,110 +5,8 @@ def search(self, nums, target): :type target: int :rtype: bool """ - #如果第一个数和最后一个数不相等,那么跟上一题没有区别 - #如果第一个数和最后一个数相等,而且等于target,return true - #如果第一个数和最后一个数相等,但是不等于target,在最坏的情况下就需要遍历两个升序数组的某一个,已确定target有可能落在哪一段,极端情况时间复杂度会降低到0(N) - if not nums: - return False - if nums[0] != nums[-1]: - return self.search1(nums, target) - if nums[0] == nums[-1]: - if nums[0] == target: + for num in nums: + if target == num: return True - else: - # for num in nums: #偷懒就可以这么写……直接上O(N)的算法 - # if num == target: - # return True - # return False - return self.search2(nums, target) - - def search1(self, nums, target): #上一题的解答,两次二分查找分别找旋转点和结果 - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - if not nums: - return -1 - if len(nums) == 1: - return True if nums[0] == target else False - - lo, hi = 0, len(nums) - 1 - while(lo <= hi): - mid = (lo + hi) // 2 - if mid + 1 < len(nums) and nums[mid] > nums[mid +1]: #旋转点为mid - break - if nums[mid] <= nums[-1]: - hi = mid - 1 - elif nums[mid] >= nums[0]: - lo = mid + 1 - - if lo > hi:#没有旋转 - lo, hi = 0, len(nums) - 1 - else: - if target >= nums[0]: - lo, hi = 0, mid - else: - lo, hi = mid + 1, len(nums) - 1 - - while(lo <= hi): - mid = (lo + hi) // 2 - if nums[mid] == target: - return True - elif nums[mid] > target: - hi = mid - 1 - else: - lo = mid + 1 - - return False - - def search2(self, nums, target):#这种情况下nums[0] == nums[-1] - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - if not nums: - return -1 - if len(nums) == 1: - return True if nums[0] == target else False - - lo, hi = 0, len(nums) - 1 - while(lo <= hi): - mid = (lo + hi) // 2 - if mid + 1 < len(nums) and nums[mid] > nums[mid +1]: - break - if nums[mid] == nums[0]: #无法确定mid落在哪一段 - i = mid - while(i < len(nums) - 1 and nums[i] == nums[i + 1]): - i += 1 - if i == len(nums) - 1:#整个右段都找完了,全部跟nums[0]一样,所以target肯定落在左侧,也就是0 ~ mid这一段 - hi = mid - 1 - else: - lo = mid + 1 - - if nums[mid] < nums[-1]: - hi = mid - 1 - elif nums[mid] > nums[0]: - lo = mid + 1 - - if target > nums[mid]: - return False #因为mid一定是最大的那个数 - elif target == nums[mid]: #找到了就直接返回 - return True - elif target < nums[mid]: #还需要二分查找,现在要确认找左侧还是找右侧 - if target > nums[0]: #在左侧找 - lo, hi = 0, mid - 1 - else: #在右侧找 - lo, hi = mid + 1, len(nums) - 1 - while(lo <= hi): - mid = (lo + hi) // 2 - if nums[mid] == target: - return True - elif nums[mid] > target: - hi = mid - 1 - else: - lo = mid + 1 - return False \ 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.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.py" index c5c52fa..2f4b37b 100644 --- "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.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.py" @@ -10,17 +10,19 @@ def deleteDuplicates(self, head): :type head: ListNode :rtype: ListNode """ - new_head = ListNode(1) - new_head.next = head - pre = new_head - cur = head - while cur: - while cur.next != None and cur.val == cur.next.val: - cur = cur.next; - if cur == pre.next: - pre = pre.next - else: - pre.next = cur.next - cur = cur.next - - return new_head.next \ No newline at end of file + 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.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.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.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/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" "b/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" index ac9a2dc..465d8f7 100644 --- "a/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" +++ "b/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" @@ -4,15 +4,12 @@ def largestRectangleArea(self, heights): :type heights: List[int] :rtype: int """ - res = 0 - stack = list() heights = [0] + heights + [0] - for i in range(len(heights)): - while stack and heights[stack[-1]] > heights[i]: - top = stack.pop() - res = max(res, (i - stack[-1] - 1) * heights[top]) - # print (i - stack[-1] - 1) * heights[top], heights[top] - + stack = [] + res = 0 + for i, num in enumerate(heights): + while stack and heights[stack[-1]] > num: + top = stack.pop() + res = max(res, (i - stack[-1] - 1) * heights[top]) stack.append(i) - # print stack return res \ 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.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.py" index a3d895f..2f0a252 100644 --- "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.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.py" @@ -5,28 +5,8 @@ def merge(self, nums1, m, nums2, n): :type m: int :type nums2: List[int] :type n: int - :rtype: void Do not return anything, modify nums1 in-place instead. + :rtype: None Do not return anything, modify nums1 in-place instead. """ - temp = [] - p1 = 0 - p2 = 0 - while(p1 < m and p2 < n): - if (nums1[p1] <= nums2[p2]): - temp.append(nums1[p1]) - p1 += 1 - else: - temp.append(nums2[p2]) - p2 += 1 - - while(p1 < m): - temp.append(nums1[p1]) - p1 += 1 - while(p2 < n): - temp.append(nums2[p2]) - p2 += 1 - - for i in range(0, m + n ): - nums1[i] = temp[i] - - # return nums1 - \ No newline at end of file + nums1[:] = (nums1[:m] + nums2) + nums1.sort() + # return sorted(nums) \ No newline at end of file diff --git "a/0089.\346\240\274\351\233\267\347\274\226\347\240\201/0089-\346\240\274\351\233\267\347\274\226\347\240\201.py" "b/0089.\346\240\274\351\233\267\347\274\226\347\240\201/0089-\346\240\274\351\233\267\347\274\226\347\240\201.py" index 67ffe43..4bf87ea 100644 --- "a/0089.\346\240\274\351\233\267\347\274\226\347\240\201/0089-\346\240\274\351\233\267\347\274\226\347\240\201.py" +++ "b/0089.\346\240\274\351\233\267\347\274\226\347\240\201/0089-\346\240\274\351\233\267\347\274\226\347\240\201.py" @@ -4,8 +4,7 @@ def grayCode(self, n): :type n: int :rtype: List[int] """ - # G(i) = i ^ (i /2) - dp = [0 for _ in range(2 ** n)] - for i in range(1, 2 ** n): - dp[i] = i ^ (i /2) - return dp \ No newline at end of file + res = [] + for i in range(2 ** n): + res.append(i ^ (i // 2)) + return res \ No newline at end of file diff --git "a/0090.\345\255\220\351\233\206II/0090-\345\255\220\351\233\206II.py" "b/0090.\345\255\220\351\233\206II/0090-\345\255\220\351\233\206II.py" index 2ffe5bb..f8ebd70 100644 --- "a/0090.\345\255\220\351\233\206II/0090-\345\255\220\351\233\206II.py" +++ "b/0090.\345\255\220\351\233\206II/0090-\345\255\220\351\233\206II.py" @@ -4,13 +4,13 @@ def subsetsWithDup(self, nums): :type nums: List[int] :rtype: List[List[int]] """ - nums.sort() - result = [[]] + res = [[]] for num in nums: - for i in result[:]: - item = i[:] - item.append(num) - if item not in result: - result.append(item[:]) - return result - + tmp = res[:] + for item in res: + newitem = sorted(item + [num]) + if newitem not in tmp: + tmp.append(newitem) + res = tmp[:] + + return res \ 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.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.py" index a2e191b..4edf755 100644 --- "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.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.py" @@ -12,52 +12,40 @@ def reverseBetween(self, head, m, n): :type n: int :rtype: ListNode """ - # 先找到m ~ n这一段,翻转,再塞回去 - if m == n: - return head + newhead = ListNode(-1) + newhead.next = head + #找到第m - 1和第n个节点 cnt = 1 - pre_m, pn = None, None - node = head - while(cnt < n): - # print node.val, cnt - if cnt == m - 1: - pre_m = node - node, cnt = node.next, cnt + 1 - pn = node - if pn: - nextn = pn.next - pn.next = None - else: - nextn = None - # print pre_m.val, nextn.val - - if pre_m is None: #从1开始 - head = self.reverseList(head) - newhead = head - while(head.next): - head = head.next - head.next = nextn - return newhead + 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: - pre_m.next = self.reverseList(pre_m.next) - newhead = head - while(head.next): - head = head.next - head.next = nextn - return newhead - - - - + newhead.next = self.reverseLL(slow) + p = slow + while p and p.next: + p = p.next + p.next = tail + return newhead.next - def reverseList(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if head is None or head.next is None: + def reverseLL(self, head): + if not head or not head.next: return head - tmp = self.reverseList(head.next) + + p = self.reverseLL(head.next) head.next.next = head head.next = None - return tmp \ No newline at end of file + return p \ No newline at end of file diff --git "a/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" index 20a8927..bc284dc 100644 --- "a/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" +++ "b/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -11,22 +11,10 @@ def isValidBST(self, root): :type root: TreeNode :rtype: bool """ - inorder = list() - self.inorderTra(root, inorder) - # print inorder - for i in range(len(inorder)-1): - if inorder[i] >= inorder[i+1]: - return False - return True - - def inorderTra(self, root, inorder): - if not root: - return None - + def inOrder(node): + if not node: + return [] + return inOrder(node.left) + [node.val] + inOrder(node.right) - self.inorderTra(root.left, inorder) - inorder.append(root.val) - self.inorderTra(root.right, inorder) - - return - \ No newline at end of file + inorder = inOrder(root) + return len(inorder) == len(set(inorder)) and inorder == sorted(inorder) \ No newline at end of file diff --git "a/0099.\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0099-\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0099.\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0099-\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..9a783e1 --- /dev/null +++ "b/0099.\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0099-\346\201\242\345\244\215\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.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 recoverTree(self, root): + """ + :type root: TreeNode + :rtype: None Do not return anything, modify root in-place instead. + """ + def inOrder(node): + if not node: + return [] + return inOrder(node.left) + [node.val] + inOrder(node.right) + + inorder = inOrder(root) + inorder.sort() + + self.idx = 0 + def change(node): + if not node: + return + change(node.left) + node.val = inorder[self.idx] + self.idx += 1 + change(node.right) + + change(root) + return root + \ 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.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.py" index 4abafa3..981c048 100644 --- "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.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.py" @@ -12,22 +12,8 @@ def isSameTree(self, p, q): :type q: TreeNode :rtype: bool """ - if not p and not q: - return True - - self.result = True - self.check(p,q) - return self.result - - def check(self, p, q): - # if : - if (not p or not q) or (p.val != q.val) : - self.result = False - return - - if p.left or q.left: - self.check(p.left, q.left) - if p.right or q.right: - self.check(p.right, q.right) - - return \ No newline at end of file + if not p: + return not q + if not q: + return not p + 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/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/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" index 7170990..1ae0835 100644 --- "a/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/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" @@ -11,23 +11,11 @@ def isSymmetric(self, root): :type root: TreeNode :rtype: bool """ + def helper(node1, node2): + if not node1: + return not node2 + if not node2: + return not node1 + return node1.val == node2.val and helper(node1.left, node2.right) and helper(node1.right, node2.left) - queue = [root] - - while(queue): - next_queue = list() - layer = list() - for node in queue: - if not node: - layer.append(None) - continue - next_queue.append(node.left) - next_queue.append(node.right) - - layer.append(node.val) - - if layer != layer[::-1]: - return False - queue = next_queue - - return True \ No newline at end of file + return helper(root, root) \ 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\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" index bee34dd..30d1829 100644 --- "a/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" +++ "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" @@ -11,25 +11,18 @@ def levelOrder(self, root): :type root: TreeNode :rtype: List[List[int]] """ - if not root: - return [] queue = [root] - res = list() + res = [] while queue: - nextqueue = list() - layer = list() + next_queue = [] + layer = [] for node in queue: - if node.left: - nextqueue.append(node.left) - if node.right: - nextqueue.append(node.right) - layer.append(node.val) - - queue = nextqueue[:] - res.append(layer) + if node: + layer.append(node.val) + next_queue += [node.left, node.right] + queue = next_queue[:] + if layer: + res.append(layer[:]) return res - - - - - \ No newline at end of file + + \ 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\346\254\241\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\346\254\241\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\346\254\241\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\346\254\241\351\201\215\345\216\206.py" index 7062c15..68cd10f 100644 --- "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\346\254\241\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\346\254\241\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\346\254\241\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\346\254\241\351\201\215\345\216\206.py" @@ -11,28 +11,21 @@ def zigzagLevelOrder(self, root): :type root: TreeNode :rtype: List[List[int]] """ + reverse = 0 queue = [root] - lor = 0 # 0 for left and 1 for right - res = list() - if not root: - return [] - while(queue): - next_queue = list() - layer = list() - + res = [] + while queue: + next_queue = [] + layer = [] for node in queue: - if node.left: - next_queue.append(node.left) - if node.right: - next_queue.append(node.right) - - layer.append(node.val) - - if not lor: # left - res.append(layer) - else: - res.append(layer[::-1]) - - lor = 1 - lor - queue = next_queue + if node: + layer.append(node.val) + next_queue += [node.left, node.right] + queue = next_queue[:] + if layer: + if not reverse: + res.append(layer[:]) + else: + res.append(layer[::-1]) + reverse = 1 - reverse return res \ No newline at end of file diff --git "a/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/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..e3b62e7 --- /dev/null +++ "b/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,16 @@ +# 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 maxDepth(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) \ 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.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.py" index f372ec4..c386175 100644 --- "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.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.py" @@ -14,16 +14,18 @@ def buildTree(self, preorder, inorder): """ if not preorder: return None + root_val = preorder[0] + root_idx = inorder.index(root_val) - root = TreeNode(preorder[0]) - left_inorder = inorder[: inorder.index(root.val)] - right_inorder = inorder[inorder.index(root.val) + 1 :] + preorder_left = preorder[1:1 + root_idx] + preorder_right = preorder[root_idx + 1:] - l_left = len(left_inorder) - left_preorder = preorder[1:l_left + 1] - right_preorder = preorder[l_left + 1 :] + inorder_left = inorder[:root_idx] + inorder_right = inorder[root_idx + 1:] - root.left = self.buildTree(left_preorder, left_inorder) - root.right = self.buildTree(right_preorder, right_inorder) + # print preorder_left, preorder_right, inorder_left, inorder_right + root = TreeNode(root_val) + root.left = self.buildTree(preorder_left, inorder_left) + root.right = self.buildTree(preorder_right, inorder_right) 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.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.py" index e638c0f..d20caa6 100644 --- "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.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.py" @@ -12,22 +12,20 @@ def buildTree(self, inorder, postorder): :type postorder: List[int] :rtype: TreeNode """ - if not postorder: + if not inorder: return None + root_val = postorder[-1] + root_idx = inorder.index(root_val) - root = TreeNode(postorder[-1]) + postorder_left = postorder[:root_idx] + postorder_right = postorder[root_idx:-1] - root_index = inorder.index(postorder[-1]) + inorder_left = inorder[:root_idx] + inorder_right = inorder[root_idx + 1:] - left_inorder = inorder[:root_index] - right_inorder = inorder[root_index + 1:] - - l_left = len(left_inorder) - - left_postorder = postorder[:l_left] - right_postorder = postorder[l_left : -1] - - root.left = self.buildTree(left_inorder, left_postorder) - root.right = self.buildTree(right_inorder, right_postorder) + # print preorder_left, preorder_right, inorder_left, inorder_right + root = TreeNode(root_val) + root.left = self.buildTree(inorder_left, postorder_left) + root.right = self.buildTree(inorder_right, postorder_right) 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\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" index dac2a0e..35c90e7 100644 --- "a/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" +++ "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" @@ -11,30 +11,16 @@ def levelOrderBottom(self, root): :type root: TreeNode :rtype: List[List[int]] """ - # Definition for a binary tree node. - - if not root: - return [] - node = [root] - node_val = list(list()) - self.generate(node, node_val) - return node_val[::-1] - - def generate(self, node, node_val): - new_node = [] - new_node_val = [] - for node in node: - if node.left: - new_node.append(node.left) - if node.right: - new_node.append(node.right) - new_node_val.append(node.val) - node_val.append(new_node_val) - if len(new_node) == 0: - return - self.generate(new_node, node_val) - - - - - \ No newline at end of file + queue = [root] + res = [] + while queue: + next_queue = [] + layer = [] + for node in queue: + if node: + layer.append(node.val) + next_queue += [node.left, node.right] + queue = next_queue[:] + if layer: + res.append(layer[:]) + 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.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.py" index 3c4a0e8..0a3ba57 100644 --- "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.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.py" @@ -13,17 +13,8 @@ def sortedArrayToBST(self, nums): """ if not nums: return None - - def dfs(start, end): - if end < start: - return - - mid = (end + start) // 2 - root = TreeNode(nums[mid]) - - root.left = dfs(start, mid - 1) - root.right = dfs(mid + 1, end) - - return root - - return dfs(0, len(nums) - 1) \ No newline at end of file + l = len(nums) + root = TreeNode(nums[l // 2]) + root.left = self.sortedArrayToBST(nums[:l//2]) + root.right = self.sortedArrayToBST(nums[l//2 + 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.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.py" index 1053d00..2d2a03a 100644 --- "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.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.py" @@ -18,31 +18,22 @@ def sortedListToBST(self, head): :rtype: TreeNode """ if not head: - return head - l = list() - while(head): - l.append(head.val) - head = head.next - - def sortedArrayToBST(nums): - if not nums: - return None - - def dfs(start, end): - if end < start: - return - - mid = (end + start) // 2 - root = TreeNode(nums[mid]) - - root.left = dfs(start, mid - 1) - root.right = dfs(mid + 1, end) - - return root - - return dfs(0, len(nums) - 1) - - return sortedArrayToBST(l) - + 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/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/0110-\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.py" "b/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/0110-\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.py" index 466e681..e2996bf 100644 --- "a/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/0110-\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.py" +++ "b/0110.\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/0110-\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.py" @@ -1,18 +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 isBalanced(self, root): + """ + :type root: TreeNode + :rtype: bool + """ if not root: return True + if not root.left and not root.right: + return True - def check(root,height): - if not root: - return True,height - - tag1,height1=check(root.left,height+1) - tag2,height2=check(root.right,height+1) - if tag1 and tag2 and abs(height1-height2)<2: - return True,max(height1,height2) - else: - return False,height1 - - tag,height=check(root,0) - return tag \ No newline at end of file + def getHeight(node, h): + if not node: + return h + return max(getHeight(node.left, h + 1), getHeight(node.right, h + 1)) + return self.isBalanced(root.left) and self.isBalanced(root.right) and abs(getHeight(root.left, 0) - getHeight(root.right, 0)) <= 1 \ 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.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.py" index 633069e..15bab42 100644 --- "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.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.py" @@ -11,16 +11,13 @@ def minDepth(self, root): :type root: TreeNode :rtype: int """ - if root: - if root.left and root.right: - return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) - if root.left: - return 1 + self.minDepth(root.left) - if root.right: - return 1 + self.minDepth(root.right) - else: - return 1 - else: + if not root: return 0 - - \ No newline at end of file + 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.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.py" index 88c3cff..ce9a472 100644 --- "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.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.py" @@ -6,28 +6,14 @@ # self.right = None class Solution(object): - def hasPathSum(self, root, s): + def hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ - self.res = False - - def dfs(node, tmp): - if not node: - return - - tmp.append(node.val) - if not node.left and not node.right and sum(tmp) == s: - self.res = True - - dfs(node.left, tmp) - dfs(node.right, tmp) - tmp.pop() - - - dfs(root, list()) - return self.res - - \ No newline at end of file + if not root: + return False + if not root.left and not root.right: + return root.val == sum + return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val) \ 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.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.py" index fa7f356..b03107d 100644 --- "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.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.py" @@ -12,19 +12,19 @@ def pathSum(self, root, s): :type sum: int :rtype: List[List[int]] """ - res = list() - - def dfs(node, tmp): + res = [] + def dfs(node, path): if not node: - return + return - tmp.append(node.val) - if not node.left and not node.right and sum(tmp) == s: - res.append(tmp[:]) + path += [node.val] + if not node.left and not node.right and sum(path) == s: + res.append(path[:]) + + dfs(node.left, path) + dfs(node.right, path) - dfs(node.left, tmp) - dfs(node.right, tmp) - tmp.pop() + path.pop() - dfs(root, list()) + dfs(root, []) 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.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.py" index 4f6227f..ffd37d4 100644 --- "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.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.py" @@ -11,19 +11,17 @@ 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): + if not root: + return None + if 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.right): #找到现在右子树的最后一个node - root = root.right - root.right = tmp #把捋直的原来的右子树接上去 - \ No newline at end of file + ltree, rtree = root.left, root.right + root.right = ltree + root.left = None + p = root + while p.right: + p = p.right + p.right = rtree \ 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.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.py" index 2c89464..2ec9db4 100644 --- "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.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.py" @@ -13,20 +13,28 @@ def connect(self, root): :type root: Node :rtype: Node """ - #先排除掉不需要处理的情况 - if not root or (not root.left and not root.right): - return root - - #某一个节点的左孩子的next一定是指向这个节点的右孩子 - root.left.next = root.right - - #当某一个节点的next不为空的时候,这个节点的右孩子的next一定是指向该节点next的left - if root.next: - root.right.next = root.next.left - - #递归处理下一层 + 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 + 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.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.py" index caa2621..3cf5013 100644 --- "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.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.py" @@ -1,37 +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 or (not root.left and not root.right): - return root - - def findCousin(node, parent): - tmp = parent.next - while(tmp): - if tmp.left: - node.next = tmp.left - break - - elif tmp.right: - node.next = tmp.right - break - tmp = tmp.next - + if not root: + return + wait = None if root.left and root.right: root.left.next = root.right - findCousin(root.right, root) - + wait = root.right elif root.left: - findCousin(root.left, root) - + wait = root.left elif root.right: - findCousin(root.right, root) - - # print root.val, root.right.next + 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 + return root \ No newline at end of file diff --git "a/0118.\346\235\250\350\276\211\344\270\211\350\247\222/0118-\346\235\250\350\276\211\344\270\211\350\247\222.py" "b/0118.\346\235\250\350\276\211\344\270\211\350\247\222/0118-\346\235\250\350\276\211\344\270\211\350\247\222.py" new file mode 100644 index 0000000..c451287 --- /dev/null +++ "b/0118.\346\235\250\350\276\211\344\270\211\350\247\222/0118-\346\235\250\350\276\211\344\270\211\350\247\222.py" @@ -0,0 +1,16 @@ +class Solution(object): + def generate(self, numRows): + """ + :type numRows: int + :rtype: List[List[int]] + """ + if not numRows: + return [] + res = [[1]] + for i in range(1, numRows): + tmp = [1] + for j in range(1, i): + tmp.append(res[i-1][j - 1] + res[i - 1][j]) + tmp.append(1) + res.append(tmp[:]) + return res \ No newline at end of file diff --git "a/0119.\346\235\250\350\276\211\344\270\211\350\247\222II/0119-\346\235\250\350\276\211\344\270\211\350\247\222II.py" "b/0119.\346\235\250\350\276\211\344\270\211\350\247\222II/0119-\346\235\250\350\276\211\344\270\211\350\247\222II.py" index c6f0f9e..fcf14ac 100644 --- "a/0119.\346\235\250\350\276\211\344\270\211\350\247\222II/0119-\346\235\250\350\276\211\344\270\211\350\247\222II.py" +++ "b/0119.\346\235\250\350\276\211\344\270\211\350\247\222II/0119-\346\235\250\350\276\211\344\270\211\350\247\222II.py" @@ -4,23 +4,13 @@ def getRow(self, rowIndex): :type rowIndex: int :rtype: List[int] """ - # C(n - 1,m - 1) - n = rowIndex - m = n + 1 - def Calculate(n, m): - down = 1 - up = 1 - for i in range(1, m): - down *= i - - for i in range(1, m): - up *= (n + 1 -i) - - return up // down - - res = list() - for i in range(1, m + 1): - res.append(Calculate(n, i)) - - - return res \ No newline at end of file + if not rowIndex: + return [1] + res = [[1]] + for i in range(1, rowIndex + 1): + tmp = [1] + for j in range(1, i): + tmp.append(res[j - 1] + res[j]) + tmp.append(1) + res = tmp[:] + return res \ No newline at end of file diff --git "a/0120.\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0120-\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" "b/0120.\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0120-\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" index 712bce6..7086ac2 100644 --- "a/0120.\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0120-\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" +++ "b/0120.\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0120-\344\270\211\350\247\222\345\275\242\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" @@ -4,12 +4,13 @@ def minimumTotal(self, triangle): :type triangle: List[List[int]] :rtype: int """ - dp= triangle[-1] - - for i in range(len(triangle) - 2, -1, -1): - for j in range(i + 1): - dp[j] = triangle[i][j] + min(dp[j], dp[j + 1]) - - return dp[0] - - \ No newline at end of file + if not triangle or not triangle[0]: + return 0 + dp = triangle[:] + for i in range(1, len(dp)): + dp[i][0] += dp[i - 1][0] + for j in range(1, len(dp[i]) - 1): + dp[i][j] += min(dp[i - 1][j - 1], dp[i - 1][j]) + dp[i][-1] += dp[i - 1][-1] + + return min(dp[-1]) \ 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.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.py" index 9134a56..8b19676 100644 --- "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.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.py" @@ -4,11 +4,24 @@ def maxProfit(self, prices): :type prices: List[int] :rtype: int """ - # if not prices: - # return 0 - minelement = 2 << 31 - profit = 0 - for i in range(len(prices)): - minelement = min(minelement, prices[i]) - profit = max(profit, prices[i] - minelement) - return profit \ No newline at end of file +# dp[i][k][0] = max(dp[i – 1][k][0], dp[I – 1][k][1] + prices[i]) +# dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k][0] - prices[i]) +# 第一题 k = 1 + +# dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) +# dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - prices[i]) + +# 当i = 0时, +# dp[0][0] = 0 +# dp[0][1] = -prices[0] + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + for i, price in enumerate(prices): + if i == 0: + dp[0][0] = 0 + dp[0][1] = -price + else: + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) + dp[i][1] = max(dp[i - 1][1], - prices[i]) + + return dp[len(prices) - 1][0] if prices else 0 + \ No newline at end of file diff --git "a/0122.\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\272II/0122-\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\272II.py" "b/0122.\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\272II/0122-\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\272II.py" index e0eafaf..c52418d 100644 --- "a/0122.\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\272II/0122-\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\272II.py" +++ "b/0122.\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\272II/0122-\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\272II.py" @@ -4,9 +4,13 @@ def maxProfit(self, prices): :type prices: List[int] :rtype: int """ - sum = 0 - for i in range(1,len(prices)): - if prices[i] > prices[i-1]: - profit = prices[i] - prices[i-1] - sum += profit - return sum \ No newline at end of file + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + for i, price in enumerate(prices): + if i == 0: + dp[0][0] = 0 + dp[0][1] = -price + else: + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) + dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - prices[i]) + + return dp[len(prices) - 1][0] if prices else 0 \ No newline at end of file diff --git "a/0123.\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\272III/0123-\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\272III.py" "b/0123.\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\272III/0123-\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\272III.py" new file mode 100644 index 0000000..1761b27 --- /dev/null +++ "b/0123.\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\272III/0123-\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\272III.py" @@ -0,0 +1,21 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + + max_k = 2 + n = len(prices) + dp = [[[0 for _ in range(2)] for _ in range(max_k + 1)] for _ in range(n)] + + for i, price in enumerate(prices): + for k in range(max_k, 0, -1): + if i == 0: + dp[0][k][0] = 0 + dp[0][k][1] = -price + else: + dp[i][k][0] = max(dp[i - 1][k][0], dp[i - 1][k][1] + prices[i]) + dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - prices[i]) + + return dp[n - 1][max_k][0] if prices else 0 \ 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.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.py" index d9f3a41..ff3a1f2 100644 --- "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.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.py" @@ -4,20 +4,9 @@ def isPalindrome(self, s): :type s: str :rtype: bool """ - s = s.lower() - ss = "" - for i in s: - if i.isalpha() != True and i.isdigit() != True: - print i - continue - ss += i - # print ss - if len(ss) <= 1: - return True - for i in range(0,len(ss)): - # print ss[i] - if ss[i] != ss[-i-1]: - return False - return True - - \ No newline at end of file + 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/0126.\345\215\225\350\257\215\346\216\245\351\276\231II/0126-\345\215\225\350\257\215\346\216\245\351\276\231II.py" "b/0126.\345\215\225\350\257\215\346\216\245\351\276\231II/0126-\345\215\225\350\257\215\346\216\245\351\276\231II.py" new file mode 100644 index 0000000..1697649 --- /dev/null +++ "b/0126.\345\215\225\350\257\215\346\216\245\351\276\231II/0126-\345\215\225\350\257\215\346\216\245\351\276\231II.py" @@ -0,0 +1,113 @@ +class Solution(object): + def findLadders(self, beginWord, endWord, wordList): + """ + :type beginWord: str + :type endWord: str + :type wordList: List[str] + :rtype: List[List[str]] + """ + from collections import defaultdict, deque + if endWord not in wordList: + return [] + wordList = set(wordList) + wordList.add(beginWord) + + record = defaultdict(set) + flag, forward, backward = True, {beginWord}, {endWord} + while forward: + if len(forward) > len(backward): + flag, forward, backward = not flag, backward, forward + + wordList -= forward + next_level = set() + for word in forward: + for i in range(len(word)): + for k in range(26): + tmp = word[:i] + chr(ord("a") + k) + word[i + 1:] + + if tmp in wordList: + next_level.add(tmp) + if flag: + record[tmp].add(word) + else: + record[word].add(tmp) + + if next_level & backward:#有交集说明找到了 + res = [[endWord]] + while res[0][0] != beginWord: + res = [[x] + y for y in res for x in record[y[0]]] + return res + # res += 1 + forward = next_level + return [] + + return 0 + + + + + + + + + + + + + + + for word in wordList: + wl.add(word) + + record = defaultdict(list) + queue = deque() + queue.append(endWord) + # wl.remove(endWord) + def bfs(queue): + if not queue: + return + next_queue = deque() + while queue: + cur = queue.popleft() + print wl, cur + + for i in range(len(cur)): + for k in range(26): + tmp = cur[:i] + chr(ord("a") + k) + cur[i + 1:] + + if tmp != cur and tmp in wl and tmp not in record[cur]: + + next_queue.append(tmp) + record[cur].append(tmp) + wl.remove(cur) + + bfs(next_queue) + + bfs(queue) + print record + self.min_length = 2 ** 32 - 1 + self.res = [] + + def dfs(bW, eW, path): + if len(path) > self.min_length: + return + print path, eW, record[eW] + if bW == eW: + # if len(path) + 1 < self.min_length: + # self.res = [[eW] + path ] + # self.min_length = len(path) + 1 + # elif len(path) + 1 == self.min_length: + self.res.append([eW] + path ) + return + + for pre_node in record[eW]: + if pre_node not in visited: + visited.add(pre_node) + dfs(bW, pre_node, [eW] + path ) + visited.remove(pre_node) + + visited = set() + visited.add(endWord) + dfs(beginWord, endWord, []) + return self.res + \ No newline at end of file diff --git "a/0127.\345\215\225\350\257\215\346\216\245\351\276\231/0127-\345\215\225\350\257\215\346\216\245\351\276\231.py" "b/0127.\345\215\225\350\257\215\346\216\245\351\276\231/0127-\345\215\225\350\257\215\346\216\245\351\276\231.py" index fb2fa0b..42405ae 100644 --- "a/0127.\345\215\225\350\257\215\346\216\245\351\276\231/0127-\345\215\225\350\257\215\346\216\245\351\276\231.py" +++ "b/0127.\345\215\225\350\257\215\346\216\245\351\276\231/0127-\345\215\225\350\257\215\346\216\245\351\276\231.py" @@ -1,4 +1,3 @@ -from collections import deque class Solution(object): def ladderLength(self, beginWord, endWord, wordList): """ @@ -7,27 +6,29 @@ def ladderLength(self, beginWord, endWord, wordList): :type wordList: List[str] :rtype: int """ - if endWord not in wordList or beginWord == endWord: + from collections import deque + if endWord not in wordList: return 0 - visited = set() - wordList = set(wordList) + wordList = set(wordList) #必备优化,不然超时 - q = deque() - q.append([beginWord, 0]) - - char = "abcdefghijklmnopqrstuvwxyz" - while q: - cur, cnt = q.popleft() #从队列里取一个出来 - if cur == endWord: #如果刚好找到了 - return cnt + 1 - - for i in range(len(cur)): - for j in range(26): - word = cur[:i] + char[j] + cur[i + 1:] #把26种变换可能都生成 - if word in wordList and word not in visited: #判断变换有没有效 - visited.add(word) - q.append([word, cnt + 1]) - - return 0 - - \ No newline at end of file + res, forward, backward = 2, {beginWord}, {endWord} + while forward: + if len(forward) > len(backward): + forward, backward = backward, forward + + next_level = set() + for word in forward: + for i in range(len(word)): + for k in range(26): + tmp = word[:i] + chr(ord("a") + k) + word[i + 1:] + + if tmp in backward: #找到了 + return res + if tmp in wordList: + next_level.add(tmp) + wordList.remove(tmp) + res += 1 + forward = next_level + + + return 0 \ No newline at end of file diff --git "a/0128.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/0128-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" "b/0128.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/0128-\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..fe318e8 --- /dev/null +++ "b/0128.\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227/0128-\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.py" @@ -0,0 +1,21 @@ +class Solution(object): + def longestConsecutive(self, nums): + """ + :type nums: List[int] + :rtype: 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 \ No newline at end of file diff --git "a/0129.\346\261\202\346\240\271\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" index 79084aa..57e33c4 100644 --- "a/0129.\346\261\202\346\240\271\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\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\345\210\260\345\217\266\345\255\220\350\212\202\347\202\271\346\225\260\345\255\227\344\271\213\345\222\214.py" @@ -15,15 +15,16 @@ def sumNumbers(self, root): def dfs(node, tmp): if not node: - return + return tmp = tmp * 10 + node.val if not node.left and not node.right: self.res += tmp + return dfs(node.left, tmp) dfs(node.right, tmp) - # tmp /= 10 - - dfs(root, 0) + # tmp -= node.val + + dfs(root, 0) return self.res \ No newline at end of file diff --git "a/0130.\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237/0130-\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237.py" "b/0130.\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237/0130-\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237.py" index 1e29183..ee15145 100644 --- "a/0130.\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237/0130-\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237.py" +++ "b/0130.\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237/0130-\350\242\253\345\233\264\347\273\225\347\232\204\345\214\272\345\237\237.py" @@ -1,95 +1,44 @@ -class UnionFindSet(object): - def __init__(self, grid): - - m, n = len(grid), len(grid[0]) - self.roots = [i for i in range(m * n)] - self.rank = [0 for i in range(m * n)] - self.count = n - - for i in range(m): - for j in range(n): - self.roots[i *n + j] = i * n +j - - 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 solve(self, board): """ :type board: List[List[str]] :rtype: None Do not return anything, modify board in-place instead. """ + #从四条边的O往里找相邻的O染色成P,到不了的O变成X, P染色回O if not board or not board[0]: return board m, n = len(board), len(board[0]) - dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - def dfs(x, y): + def dfs(x0, y0): for k in range(4): - xx = x + dx[k] - yy = y + dy[k] - - if xx >= 0 and xx < m and yy >= 0 and yy < n: #当前坐标有效 - if board[xx][yy] == "O": - board[xx][yy] = "P" #给走过的点染色 - dfs(xx, yy) - #--------以下在从四周往里找相邻的所有点 - i = 0 - for j in range(n): #上边 - if board[i][j] == "O": - board[i][j] = "P" - dfs(i, j) - - i = m - 1 - for j in range(n): #下边 - if board[i][j] == "O": - board[i][j] = "P" - dfs(i, j) - j = 0 - for i in range(m): #左边 - if board[i][j] == "O": - board[i][j] = "P" - dfs(i, j) - - j = n - 1 - for i in range(m): #右边 - if board[i][j] == "O": - board[i][j] = "P" - dfs(i, j) - #--------以上在从四周往里找相邻的所有点 - # print board - res = 0 - for i in range(m): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and board[x][y] == "O": + board[x][y] = "P" + dfs(x, y) + + + for i in [0, m - 1]: for j in range(n): - if board[i][j] == "P": #统计一下还有多少个没有去过的点 + if board[i][j] == "O": + board[i][j] = "P" + dfs(i, j) - board[i][j] = "O" - elif board[i][j] == "O": + for j in [0, n - 1]: + for i in range(m): + if board[i][j] == "O": + board[i][j] = "P" + dfs(i, j) + + for i in range(m): + for j in range(n): + if board[i][j] == "O": board[i][j] = "X" - - return board - - \ No newline at end of file + elif board[i][j] == "P": + board[i][j] = "O" + \ No newline at end of file diff --git "a/0132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/0132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" "b/0132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/0132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" new file mode 100644 index 0000000..9faf5e5 --- /dev/null +++ "b/0132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/0132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" @@ -0,0 +1,29 @@ +class Solution(object): + def minCut(self, s): + """ + :type s: str + :rtype: int + """ + if s == s[::-1]: + return 0 + + for i in range(1, len(s) + 1): + if s[:i] == s[:i][::-1] and s[i:] == s[i:][::-1]: + return 1 + + dp = [len(s) for i in range(len(s))] + for i in range(0, len(s)): + self.centeralExtend(s, i, i, dp) + self.centeralExtend(s, i, i+1, dp) + print dp + return dp[-1] + + def centeralExtend(self, string, left, right, dp): + while left >= 0 and right < len(string) and string[left] == string[right]: + if left > 0: + dp[right] = min(dp[right], dp[left - 1] + 1) + else: + dp[right] = 0 + left -= 1 + right += 1 + \ 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.py" "b/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" index 5a8f4ee..ebffc5b 100644 --- "a/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" +++ "b/0133.\345\205\213\351\232\206\345\233\276/0133-\345\205\213\351\232\206\345\233\276.py" @@ -1,10 +1,3 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val, neighbors): - self.val = val - self.neighbors = neighbors -""" class Solution(object): def cloneGraph(self, node): """ @@ -12,8 +5,9 @@ def cloneGraph(self, node): :rtype: Node """ from collections import defaultdict, deque - record = defaultdict(list) - mapping = dict() + neighborList = defaultdict(list) #这个哈希表用于记录老结点和其邻居的关系, key是每个老结点,val是它的neighbors + mapping = dict() #这个哈希表用于记录老结点和它对应的新节点 + def bfs(queue): if not queue: return @@ -21,44 +15,35 @@ def bfs(queue): while queue: cur = queue.popleft() - mapping[cur] = Node(cur.val, []) + mapping[cur] = Node(cur.val, []) #为每个老结点创建一个对应的新节点 for nei in cur.neighbors: - record[cur].append(nei) + neighborList[cur].append(nei) #记录下当前老结点的所有邻居 if nei not in visited: visited.add(nei) newqueue.append(nei) - bfs(newqueue) + bfs(newqueue) #BFS找下一层 visited = {node} q = deque() q.append(node) bfs(q) - - # for key, val in record.items(): - # print key.val - # for item in val: - # print item.val - # print mapping visited = {node} def generate(queue): while queue: newqueue = [] for node in queue: - if node: - # print node.val - if not record[node]: #如果没有邻居 + if node: + if not neighborList[node]: #如果没有邻居 return - for nei in record[node]: #处理每个邻居 - mapping[node].neighbors.append(mapping[nei]) + for nei in neighborList[node]: #处理每个邻居 + mapping[node].neighbors.append(mapping[nei]) #在新的结点标记【老结点的邻居对应的】新结点 if nei not in visited: visited.add(nei) newqueue.append(nei) queue = newqueue[:] - q = deque() - q.append(node) - generate(q) - return mapping[node] - \ No newline at end of file + generate([node]) + + return mapping[node] #返回输入结点对应的新节点 \ No newline at end of file diff --git "a/0134.\345\212\240\346\262\271\347\253\231/0134-\345\212\240\346\262\271\347\253\231.py" "b/0134.\345\212\240\346\262\271\347\253\231/0134-\345\212\240\346\262\271\347\253\231.py" index 8c202c5..471a152 100644 --- "a/0134.\345\212\240\346\262\271\347\253\231/0134-\345\212\240\346\262\271\347\253\231.py" +++ "b/0134.\345\212\240\346\262\271\347\253\231/0134-\345\212\240\346\262\271\347\253\231.py" @@ -5,17 +5,23 @@ def canCompleteCircuit(self, gas, cost): :type cost: List[int] :rtype: int """ - if sum(gas) < sum(cost) or not len(gas): - return -1 - l = len(gas) - sub = [gas[i] - cost[i] for i in range(l)] - - g = 0 - index = 0 - for i in range(l): #i是出发加油站的编号 - g = g + sub[i] - if g < 0: - g = 0 - index = i + 1 + idx = 0 + for i in range(len(gas)): + if i < idx: + continue + j = i + left_gas = gas[i] + while left_gas > 0: + # print j + if left_gas < cost[j]: #去不了下一站 + idx = max(idx, j) + break + left_gas -= cost[j] + if (j + 1) % len(gas) == i: + return i - return index + j = (j + 1) % len(gas) + left_gas += gas[j] + return -1 + + \ No newline at end of file diff --git "a/0136.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/0136-\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/0136.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/0136-\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" index 4e142b2..8c6a931 100644 --- "a/0136.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/0136-\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/0136.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227/0136-\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" @@ -4,10 +4,7 @@ def singleNumber(self, nums): :type nums: List[int] :rtype: int """ - r = 0 - for i in nums: - r ^= i - return r - - - \ No newline at end of file + res = nums[0] + for i in range(1, len(nums)): + res ^= nums[i] + return res \ No newline at end of file diff --git "a/0137.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II/0137-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II.py" "b/0137.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II/0137-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II.py" index bb3fbc2..3fdfbda 100644 --- "a/0137.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II/0137-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II.py" +++ "b/0137.\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II/0137-\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227II.py" @@ -4,6 +4,4 @@ def singleNumber(self, nums): :type nums: List[int] :rtype: int """ - for num in nums: - if nums.count(num) == 1: - return num \ No newline at end of file + return (3 * sum(set(nums)) - sum(nums)) // 2 \ 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.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.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.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/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" "b/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" index 7bbfd14..3adaf59 100644 --- "a/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" +++ "b/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" @@ -5,13 +5,13 @@ def wordBreak(self, s, wordDict): :type wordDict: List[str] :rtype: bool """ - record = [0]#一开始从开头开始找 + dp = [0] for j in range(len(s) + 1): - for i in record:#在之前每一种找法的基础上找 - if s[i : j] in wordDict: #找到一种可行的分法,说明最远可以拆分到j - record.append(j) + for i in dp: + if s[i:j] in wordDict: + dp.append(j) break - # print record - return record[-1] == len(s) - \ No newline at end of file + # print dp + return dp[-1] == len(s) + \ 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.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.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.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.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.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.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/0143.\351\207\215\346\216\222\351\223\276\350\241\250/0143-\351\207\215\346\216\222\351\223\276\350\241\250.py" "b/0143.\351\207\215\346\216\222\351\223\276\350\241\250/0143-\351\207\215\346\216\222\351\223\276\350\241\250.py" index 03cd491..d726f6f 100644 --- "a/0143.\351\207\215\346\216\222\351\223\276\350\241\250/0143-\351\207\215\346\216\222\351\223\276\350\241\250.py" +++ "b/0143.\351\207\215\346\216\222\351\223\276\350\241\250/0143-\351\207\215\346\216\222\351\223\276\350\241\250.py" @@ -15,35 +15,34 @@ def reorderList(self, head): slow, fast = head, head while fast and fast.next: + # print slow.val, fast.val slow = slow.next - fast = fast.next.next + fast = fast.next + if fast and fast.next: + fast = fast.next - l1, l2 = head, self.reverseList(slow.next) + # print slow.val, fast.val + + tail = slow.next slow.next = None - # self.printList(l1) - # self.printList(l2) - while l1 and l2: - cur = l2 - l2 = l2.next - - cur.next = l1.next - l1.next = cur - l1 = l1.next.next - + first = head + last = self.reverseList(tail) + + while last: + tmp = first.next + first.next = last + tmp2 = last.next + last.next = tmp + first = first.next.next + + last = tmp2 return head - + + def reverseList(self, head): if not head or not head.next: return head p = self.reverseList(head.next) head.next.next = head head.next = None - return p - - def printList(self, head): - l = [] - p = head - while p: - l.append(p.val) - p = p.next - print l \ No newline at end of file + return p \ No newline at end of file diff --git "a/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/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" index 3075ff1..faad066 100644 --- "a/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/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" @@ -13,6 +13,15 @@ def preorderTraversal(self, root): """ if not root: return [] - result = [root.val] + self.preorderTraversal(root.left) - result += self.preorderTraversal(root.right) - return result \ No newline at end of file + stack = [root] + res = [] + while stack: + cur = stack.pop() + res.append(cur.val) + + if cur.right: + stack.append(cur.right) + if cur.left: + stack.append(cur.left) + return res + \ No newline at end of file diff --git "a/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/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" index d224375..5b5c4eb 100644 --- "a/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/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" @@ -13,6 +13,15 @@ def postorderTraversal(self, root): """ if not root: return [] - result = self.postorderTraversal(root.left) - result += self.postorderTraversal(root.right) - return result + [root.val] \ No newline at end of file + + stack = [root] + res = [] + while stack: + cur = stack.pop() + res.append(cur.val) + if cur.left: + stack.append(cur.left) + if cur.right: + stack.append(cur.right) + + return res[::-1] \ No newline at end of file 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" new file mode 100644 index 0000000..265117e --- /dev/null +++ "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" @@ -0,0 +1,44 @@ +class LRUCache(object): + + def __init__(self, capacity): + """ + :type capacity: int + """ + from collections import OrderedDict + self.capacity = capacity + self.record = OrderedDict() + + def get(self, key): + """ + :type key: int + :rtype: int + """ + if key in self.record: + tmp = self.record.pop(key) + self.record[key] = tmp + return tmp + else: + return -1 + + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: None + """ + if key in self.record: + self.record.pop(key) + else: + if self.capacity > 0: + self.capacity -= 1 + else: + self.record.popitem(last = False) + self.record[key] = value + + + +# Your LRUCache object will be instantiated and called as such: +# obj = LRUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) \ No newline at end of file diff --git "a/0147.\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217/0147-\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.py" "b/0147.\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217/0147-\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.py" index f2d2c8e..77b202d 100644 --- "a/0147.\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217/0147-\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.py" +++ "b/0147.\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217/0147-\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.py" @@ -13,22 +13,35 @@ def insertionSortList(self, head): if not head or not head.next: return head - dummy = ListNode(-1) + dummy = ListNode(-9999999999) dummy.next = head - pre = head #pre始终指着排序好链表的最后一个节点 - cur = head.next #cur始终指着未排序链表的第一个节点 - while cur: + p = head + while p: + while p and p.next and p.val < p.next.val: + p = p.next + + if not p.next: + break + cur = p.next tail = cur.next - pre.next = tail #把cur这个节点拿出来 + p.next = tail + cur.next = None - p = dummy - while p.next and p.next.val < cur.val: #找到插入的位置 - p = p.next + tmp = dummy + while tmp and tmp.next and tmp.next.val < cur.val: + tmp = tmp.next - cur.next = p.next #把cur插入到p和p.next之间 - p.next = cur - cur = tail + tmp2 = tmp.next + tmp.next = cur + cur.next = tmp2 - if p == pre:#如果刚插入到了已排序链表的末尾 - pre = pre.next #那么就更新pre - return dummy.next \ No newline at end of file + # self.printList(dummy.next) + + return dummy.next + + def printList(self, head): + res = [] + while head: + res.append(head.val) + head = head.next + print res \ No newline at end of file diff --git "a/0148.\346\216\222\345\272\217\351\223\276\350\241\250/0148-\346\216\222\345\272\217\351\223\276\350\241\250.py" "b/0148.\346\216\222\345\272\217\351\223\276\350\241\250/0148-\346\216\222\345\272\217\351\223\276\350\241\250.py" index 70ab025..8d99052 100644 --- "a/0148.\346\216\222\345\272\217\351\223\276\350\241\250/0148-\346\216\222\345\272\217\351\223\276\350\241\250.py" +++ "b/0148.\346\216\222\345\272\217\351\223\276\350\241\250/0148-\346\216\222\345\272\217\351\223\276\350\241\250.py" @@ -10,33 +10,42 @@ def sortList(self, head): :type head: ListNode :rtype: ListNode """ - + #1. 一分为二 + #2. 各自排序 + #3. 合二为一 + if not head or not head.next: return head + + dummy = ListNode(-1) + dummy.next = head + pre, slow, fast = head, head, head while fast and fast.next: pre = slow slow = slow.next fast = fast.next.next - + + first = head + second = pre.next pre.next = None - left, right = self.sortList(head), self.sortList(slow) - return self.merge(left, right) - + # print first.val, second.val + sortedfirst = self.sortList(first) + sortedsecond = self.sortList(second) + + return self.merge(sortedfirst, sortedsecond) + def merge(self, l1, l2): if not l1: return l2 if not l2: return l1 - - if l1.val < l2.val: - head = ListNode(l1.val) - head.next = self.merge(l1.next, l2) + + if l1.val <= l2.val: + tmp = ListNode(l1.val) + tmp.next = self.merge(l1.next, l2) else: - head = ListNode(l2.val) - head.next = self.merge(l1, l2.next) - return head - - + tmp = ListNode(l2.val) + tmp.next = self.merge(l1, l2.next) - \ No newline at end of file + return tmp \ 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.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.py" index 9a6acbe..d0ff710 100644 --- "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.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.py" @@ -5,22 +5,23 @@ def evalRPN(self, tokens): :rtype: int """ stack = [] - for item in tokens: - if item in ["+", "-", "*", "/"]: - if item == "+": - temp = int(stack[-2]) + int(stack[-1]) - elif item == "-": - temp = int(stack[-2]) - int(stack[-1]) - # print temp - elif item == "*": - temp = int(stack[-2]) * int(stack[-1]) - elif item == "/": - temp = int(float(stack[-2])/ float(stack[-1])) - stack.pop() - stack.pop() - stack.append(temp) - + for i, x in enumerate(tokens): + # print stack + if x not in ["+", "-", "*", "/"]: + stack.append(int(x)) else: - stack.append(item) + 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 int(stack[0]) \ No newline at end of file + return stack[0] \ No newline at end of file diff --git "a/0151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/0151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" "b/0151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/0151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" index ee268fd..fdc0ce2 100644 --- "a/0151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/0151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" +++ "b/0151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/0151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" @@ -3,14 +3,9 @@ def reverseWords(self, s): """ :type s: str :rtype: str - """ - res = [] + """ + s = s.strip() s = s.rstrip() - s = s.lstrip() - l = s.split(" ") - l = l[::-1] - print l - # print " ".join(item for item in l) - # for item in l: - # if item == "" - return " ".join(item for item in l if item != "") \ No newline at end of file + s = s[::-1].split(" ") + + return " ".join(item[::-1] for item in s if item) \ No newline at end of file diff --git "a/0152.\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227/0152-\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227.py" "b/0152.\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227/0152-\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227.py" index 3fb4a22..8c92d31 100644 --- "a/0152.\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227/0152-\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227.py" +++ "b/0152.\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227/0152-\344\271\230\347\247\257\346\234\200\345\244\247\345\255\220\345\272\217\345\210\227.py" @@ -4,14 +4,16 @@ def maxProduct(self, nums): :type nums: List[int] :rtype: int """ - l = len(nums) - dpmax = [0 for _ in range(l)] - dpmin = [0 for _ in range(l)] + #dp[i] = max(nums[i], nums[i] * dp[i - 1]) - dpmax[0] = nums[0] - dpmin[0] = nums[0] - for i in range(1, l): - dpmax[i] = max(nums[i], max(nums[i] * dpmax[i - 1], nums[i] * dpmin[i - 1])) - dpmin[i] = min(nums[i], min(nums[i] * dpmax[i - 1], nums[i] * dpmin[i - 1])) - - return max(dpmax) \ No newline at end of file + dp = [0 for i in nums] + dpmin = [0 for i in nums] + + dp[0], dpmin[0] = nums[0], nums[0] + for i, num in enumerate(nums): + if i > 0: + dp[i] = max(num, max(dp[i - 1] * num, dpmin[i - 1] * num)) + dpmin[i] = min(num, min(dp[i - 1] * num, dpmin[i - 1] * num)) + + # print dp + return max(dp) \ No newline at end of file diff --git "a/0153.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274/0153-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.py" "b/0153.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274/0153-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.py" index ece52c0..4394d72 100644 --- "a/0153.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274/0153-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.py" +++ "b/0153.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274/0153-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.py" @@ -4,15 +4,29 @@ def findMin(self, nums): :type nums: List[int] :rtype: int """ - # m = len(nums) / 2 - b = 0 - e = len(nums)-1 - while(b < e): - m = b + (e-b) / 2 - if nums[m] < nums[e]: - e = m + if not nums: + return 0 + if len(nums) == 1: + return nums[0] + + if nums[0] < nums[-1]: #没发生旋转 + return nums[0] + + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + + if mid + 1< len(nums): #mid 不是最后一位 + if nums[mid - 1] > nums[mid] and nums[mid] < nums[mid + 1]: #找到了 + return nums[mid] else: - b = m+1 - return nums[b] + if nums[mid - 1] > nums[mid]: # mid 是最后一位 + return nums[mid] + if nums[mid] < nums[-1]: + right = mid - 1 + else: + left = mid + 1 - \ No newline at end of file + + + \ No newline at end of file diff --git "a/0154.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II/0154-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II.py" "b/0154.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II/0154-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II.py" index 7adf69c..fcc547c 100644 --- "a/0154.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II/0154-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II.py" +++ "b/0154.\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II/0154-\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274II.py" @@ -4,4 +4,27 @@ def findMin(self, nums): :type nums: List[int] :rtype: int """ - return min(nums) \ No newline at end of file + left, right = 0, len(nums) - 1 + while left < right: + mid = (left + right) // 2 + + if nums[mid] > nums[right]: #最小值肯定在【mid + 1, right】 + left = mid + 1 + elif nums[mid] < nums[right]: #最小值肯定在【left, mid】 + right = mid + elif nums[mid] == nums[right]: #无法确定最小值的区间 + + flag = False + for j in range(right - 1, mid, -1):#逐个在右侧找,看是不是有比nums[mid]更小的数 + if nums[mid] > nums[j]: + flag = True #确实存在更小的数,是nums[j] + break + + if flag: #可以确定最小值肯定在【mid + 1, j】 + left = mid + 1 + right = j + else: #mid 到right所有的数都相等, 最小值肯定在【left, mid】 + right = mid + + return nums[left] + \ 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.py" "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" index 616a4e3..50dca76 100644 --- "a/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" +++ "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" @@ -5,28 +5,29 @@ def __init__(self): initialize your data structure here. """ self.stack = [] - self.min_stack = [] - + self.minstack = [] def push(self, x): """ :type x: int - :rtype: void + :rtype: None """ self.stack.append(x) - if self.min_stack and self.min_stack[-1] <= x: - self.min_stack.append(self.min_stack[-1]) + if self.minstack: + if x < self.minstack[-1]: + self.minstack.append(x) + else: + self.minstack.append(self.minstack[-1]) else: - self.min_stack.append(x) + self.minstack.append(x) def pop(self): """ - :rtype: void + :rtype: None """ - self.stack = self.stack[:-1] - self.min_stack = self.min_stack[:-1] - + self.minstack.pop() + self.stack.pop() def top(self): """ @@ -38,7 +39,7 @@ def getMin(self): """ :rtype: int """ - return self.min_stack[-1] + return self.minstack[-1] # Your MinStack object will be instantiated and called as such: diff --git "a/0156.\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0156-\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" "b/0156.\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0156-\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" index 0eaab42..adb4184 100644 --- "a/0156.\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0156-\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" +++ "b/0156.\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221/0156-\344\270\212\344\270\213\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.py" @@ -11,21 +11,15 @@ def upsideDownBinaryTree(self, root): :type root: TreeNode :rtype: TreeNode """ - #每一个节点变成其左孩子的右节点 if not root or (not root.left and not root.right): return root - - parent, sibling = None, None - while root: - tmp = root.left - root.left = sibling - - sibling = root.right - root.right = parent - - parent = root - root = tmp - - return parent - - + newroot = self.upsideDownBinaryTree(root.left) + right = root.right + root.left.left = right + root.left.right = root + + root.left = None + root.right = None + + return newroot + \ No newline at end of file diff --git "a/0157.\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246/0157-\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246.py" "b/0157.\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246/0157-\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246.py" index 70bf37f..7acd02a 100644 --- "a/0157.\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246/0157-\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246.py" +++ "b/0157.\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246/0157-\347\224\250Read4\350\257\273\345\217\226N\344\270\252\345\255\227\347\254\246.py" @@ -19,18 +19,14 @@ def read(self, buf, n): :type n: Number of characters to read (int) :rtype: The number of actual characters read (int) """ - tmp = ["","","",""] - cnt = 0 - read4(tmp) - while tmp != ["","","",""]: - for i in range(4): - if tmp[i]: - buf[cnt] = tmp[i] - cnt += 1 - if cnt == n + 1: - return n - tmp = ["","","",""] - read4(tmp) - return cnt - - \ No newline at end of file + res = 0 + tmp = read4(buf) + s = "" + while tmp: + res += tmp + # print buf + s += "".join(buf[:tmp]) + tmp = read4(buf) + for i in range(len(s)): + buf[i] = s[i] + return len(s) if len(s) < n else n \ No newline at end of file diff --git "a/0159.\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0159-\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" "b/0159.\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0159-\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" index a36eb0a..da514b9 100644 --- "a/0159.\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0159-\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" +++ "b/0159.\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0159-\350\207\263\345\244\232\345\214\205\345\220\253\344\270\244\344\270\252\344\270\215\345\220\214\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" @@ -4,29 +4,29 @@ def lengthOfLongestSubstringTwoDistinct(self, s): :type s: str :rtype: int """ - left, right = 0, 0 - queue = [] - last_pos = {} + if len(s) <= 2: + return len(s) + start, end = 0, 0 + q = [] res = 0 - for right in range(len(s)): - if s[right] in queue: - last_pos[s[right]] = right - elif s[right] not in queue: - if len(queue) >= 2: - - if last_pos[queue[0]] < last_pos[queue[1]]: #把0号元素踢掉 - left = last_pos[queue[0]] + 1 - last_pos.pop(queue[0]) - queue.pop(0) + dic = {} #记录q中字母最近一次出现的下标 + for i, char in enumerate(s): + dic[char] = i + if len(q) < 2: + if char not in q: + q.append(char) + else: + if char not in q: #要以旧换新了 + if dic[q[0]] < dic[q[1]]: + tmp = q[0] + q.pop(0) else: - left = last_pos[queue[1]] + 1 - last_pos.pop(queue[1]) - queue.pop(1) - - queue.append(s[right]) - last_pos[s[right]] = right - # print s[left:right + 1] - res = max(res, right - left + 1) + tmp = q[1] + q.pop(1) + start = dic[tmp] + 1 + + q.append(char) + end = i + res = max(end - start + 1, res) return res - - return res \ No newline at end of file + \ 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.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.py" index 396a67b..c3b380b 100644 --- "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.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.py" @@ -10,39 +10,28 @@ def getIntersectionNode(self, headA, headB): :type head1, head1: ListNode :rtype: ListNode """ - la = 0 - lb = 0 - pa = headA - pb = headB - while(pa!= None): + pa, pb = headA, headB + la, lb = 0, 0 + while pa: la += 1 pa = pa.next - while(pb!= None): + + while pb: lb += 1 pb = pb.next - - # print la,lb - pb = headB - pa = headA - if lb > la: - k = lb-la - while(k > 0): - k -= 1 - pb = pb.next - else: - k = la - lb - while(k > 0): - k -= 1 - pa = pa.next - # print pb.val - # print pa.val - - while(pb != None): - # print pa.val, pb.val - if pb == pa: - return pa - else: - pa = pa.next - 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/0161.\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273/0161-\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273.py" "b/0161.\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273/0161-\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273.py" index a613a15..4635420 100644 --- "a/0161.\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273/0161-\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273.py" +++ "b/0161.\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273/0161-\347\233\270\351\232\224\344\270\2721\347\232\204\347\274\226\350\276\221\350\267\235\347\246\273.py" @@ -1,12 +1,16 @@ class Solution(object): - def isOneEditDistance(self, s, t): + def isOneEditDistance(self, s, t): + """ + :type s: str + :type t: str + :rtype: bool + """ + edit = 0 #代表编辑次数 distance = len(s) - len(t) if abs(distance) > 1: #长度都差了不止一位,肯定不对 return False - if not s or not t: #两者有一个为空返回真,两个都为空返回假 + if not s or not t: return s != t - - edit = 0 #代表编辑次数 i, j = 0, 0 while i < len(s) and j < len(t): if s[i] == t[j]: #无需编辑 @@ -23,10 +27,10 @@ def isOneEditDistance(self, s, t): i += 1 j += 1 edit += 1 - - if i < len(s): #如果t没了,s还多了一位,取决于edit还是不是0 + # print i, j, edit + if i < len(s): return edit == 0 - if j < len(t): #如果s没了,t还多了一位,取决于edit还是不是0 + if j < len(t): return edit == 0 - - return i == len(s) and j == len(t) and edit == 1 \ No newline at end of file + return i == len(s) and j == len(t) and edit == 1 + \ No newline at end of file diff --git "a/0162.\345\257\273\346\211\276\345\263\260\345\200\274/0162-\345\257\273\346\211\276\345\263\260\345\200\274.py" "b/0162.\345\257\273\346\211\276\345\263\260\345\200\274/0162-\345\257\273\346\211\276\345\263\260\345\200\274.py" index 04b7c85..0630c38 100644 --- "a/0162.\345\257\273\346\211\276\345\263\260\345\200\274/0162-\345\257\273\346\211\276\345\263\260\345\200\274.py" +++ "b/0162.\345\257\273\346\211\276\345\263\260\345\200\274/0162-\345\257\273\346\211\276\345\263\260\345\200\274.py" @@ -9,8 +9,7 @@ def findPeakElement(self, nums): return 0 lo, hi = 0, len(nums) - 1 while(lo < hi): - # print lo,hi - mid = lo + (hi - lo) / 2 + mid = (lo + hi) // 2 if nums[mid - 1] < nums[mid] and nums[mid] > nums[mid + 1]: return mid elif nums[mid] < nums[mid + 1]: @@ -18,4 +17,5 @@ def findPeakElement(self, nums): else: hi = mid - 1 - return lo \ No newline at end of file + return lo + \ No newline at end of file diff --git "a/0163.\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264/0163-\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264.py" "b/0163.\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264/0163-\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264.py" index f3f7100..6e621ba 100644 --- "a/0163.\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264/0163-\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264.py" +++ "b/0163.\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264/0163-\347\274\272\345\244\261\347\232\204\345\214\272\351\227\264.py" @@ -6,31 +6,23 @@ def findMissingRanges(self, nums, lower, upper): :type upper: int :rtype: List[str] """ - # if not nums: - # if lower == upper: - # return [str(lower)] - # else: - # return [str(lower) + "->" + str(upper)] - start = lower - end = lower + start, end = lower, lower #左闭右开 res = [] - for i in range(len(nums)): - if nums[i] == end: - start, end = nums[i] + 1, nums[i] + 1 - - elif nums[i] > end: - end = max(end, nums[i] - 1) - - if end != start: - res.append(str(start) + "->" + str(end)) - else: + for i, num in enumerate(nums): + if num == end: #连上了 + start, end = num + 1, num + 1 + elif num > end: #没连上 + end = max(end, num - 1) + if end - start == 0: #只有一个数 res.append(str(start)) + else: + res.append(str(start) + "->" + str(end)) + start, end = num + 1, num + 1 + end = upper + if start < end: + res.append(str(start) + "->" + str(end)) + elif end == start: #只有一个数 + res.append(str(start)) + return res - start, end = nums[i] + 1, nums[i] + 1 - - if start < upper: - res.append(str(start) + "->" + str(upper)) - elif start == upper: - res.append(str(start)) - - return res \ No newline at end of file + \ No newline at end of file diff --git "a/0164.\346\234\200\345\244\247\351\227\264\350\267\235/0164-\346\234\200\345\244\247\351\227\264\350\267\235.py" "b/0164.\346\234\200\345\244\247\351\227\264\350\267\235/0164-\346\234\200\345\244\247\351\227\264\350\267\235.py" index a6e277d..0a2ef6d 100644 --- "a/0164.\346\234\200\345\244\247\351\227\264\350\267\235/0164-\346\234\200\345\244\247\351\227\264\350\267\235.py" +++ "b/0164.\346\234\200\345\244\247\351\227\264\350\267\235/0164-\346\234\200\345\244\247\351\227\264\350\267\235.py" @@ -27,4 +27,5 @@ def maximumGap(self, nums): return res def findBucketIndex(self, num, min_val, max_val, n): - return int((num - min_val) * n / (max_val - min_val)) \ No newline at end of file + return int((num - min_val) * n / (max_val - min_val)) + \ No newline at end of file diff --git "a/0165.\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267/0165-\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267.py" "b/0165.\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267/0165-\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267.py" index 82b0ada..d33c456 100644 --- "a/0165.\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267/0165-\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267.py" +++ "b/0165.\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267/0165-\346\257\224\350\276\203\347\211\210\346\234\254\345\217\267.py" @@ -7,7 +7,6 @@ def compareVersion(self, version1, version2): """ l1 = version1.split(".") l2 = version2.split(".") - i, j = 0, 0 while i < len(l1) and j < len(l2): # 逐位比大小 num1, num2 = int(l1[i]), int(l2[j]) diff --git "a/0167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/0167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" "b/0167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/0167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" index 3b1db81..0355fad 100644 --- "a/0167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/0167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" +++ "b/0167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/0167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" @@ -6,10 +6,11 @@ def twoSum(self, numbers, target): :rtype: List[int] """ left, right = 0, len(numbers) - 1 - while(left < right): - if numbers[left] + numbers[right] == target: + while 1: + tmp = numbers[left] + numbers[right] + if tmp == target: return [left + 1, right + 1] - if numbers[left] + numbers[right] < target: + elif tmp < target: left += 1 - elif numbers[left] + numbers[right] > target: + elif tmp > target: right -= 1 \ No newline at end of file diff --git "a/0168.Excel\350\241\250\345\210\227\345\220\215\347\247\260/0168-Excel\350\241\250\345\210\227\345\220\215\347\247\260.py" "b/0168.Excel\350\241\250\345\210\227\345\220\215\347\247\260/0168-Excel\350\241\250\345\210\227\345\220\215\347\247\260.py" index 618eac7..f09a200 100644 --- "a/0168.Excel\350\241\250\345\210\227\345\220\215\347\247\260/0168-Excel\350\241\250\345\210\227\345\220\215\347\247\260.py" +++ "b/0168.Excel\350\241\250\345\210\227\345\220\215\347\247\260/0168-Excel\350\241\250\345\210\227\345\220\215\347\247\260.py" @@ -4,11 +4,10 @@ def convertToTitle(self, n): :type n: int :rtype: str """ - #十进制转26进制 res = "" - while(n): - n-=1 - n, tmp = divmod(n, 26) - res = chr(ord("A") + tmp) + res - - return res \ No newline at end of file + while n: + n -= 1 + char = chr(ord('A') + n % 26) + n /= 26 + res += char + return res[::-1] \ No newline at end of file diff --git "a/0169.\346\261\202\344\274\227\346\225\260/0169-\346\261\202\344\274\227\346\225\260.py" "b/0169.\346\261\202\344\274\227\346\225\260/0169-\346\261\202\344\274\227\346\225\260.py" index 799481b..c16cf77 100644 --- "a/0169.\346\261\202\344\274\227\346\225\260/0169-\346\261\202\344\274\227\346\225\260.py" +++ "b/0169.\346\261\202\344\274\227\346\225\260/0169-\346\261\202\344\274\227\346\225\260.py" @@ -4,7 +4,4 @@ def majorityElement(self, nums): :type nums: List[int] :rtype: int """ - - nums.sort() - return nums[len(nums)/2] - \ No newline at end of file + return sorted(nums)[len(nums) / 2] \ No newline at end of file diff --git "a/0170.\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0170-\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" "b/0170.\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0170-\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" new file mode 100644 index 0000000..f61501f --- /dev/null +++ "b/0170.\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0170-\344\270\244\346\225\260\344\271\213\345\222\214III-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" @@ -0,0 +1,38 @@ +class TwoSum(object): + + def __init__(self): + """ + Initialize your data structure here. + """ + from collections import defaultdict + self.dic = defaultdict(int) + + def add(self, number): + """ + Add the number to an internal data structure.. + :type number: int + :rtype: None + """ + self.dic[number] += 1 + + def find(self, value): + """ + Find if there exists any pair of numbers which sum is equal to the value. + :type value: int + :rtype: bool + """ + for key, val in self.dic.items(): + if key * 2 == value: + if val > 1: + return True + else: + if value - key in self.dic: + return True + return False + + + +# Your TwoSum object will be instantiated and called as such: +# obj = TwoSum() +# obj.add(number) +# param_2 = obj.find(value) \ No newline at end of file diff --git "a/0171.Excel\350\241\250\345\210\227\345\272\217\345\217\267/0171-Excel\350\241\250\345\210\227\345\272\217\345\217\267.py" "b/0171.Excel\350\241\250\345\210\227\345\272\217\345\217\267/0171-Excel\350\241\250\345\210\227\345\272\217\345\217\267.py" index 35fb274..6f4b36c 100644 --- "a/0171.Excel\350\241\250\345\210\227\345\272\217\345\217\267/0171-Excel\350\241\250\345\210\227\345\272\217\345\217\267.py" +++ "b/0171.Excel\350\241\250\345\210\227\345\272\217\345\217\267/0171-Excel\350\241\250\345\210\227\345\272\217\345\217\267.py" @@ -4,9 +4,8 @@ def titleToNumber(self, s): :type s: str :rtype: int """ - l = len(s) - 1 res = 0 - for index, item in enumerate(s): - res += (ord(item) - ord("A") + 1) * (26 ** (l - index)) - return res - \ No newline at end of file + for i, char in enumerate(s): + res *= 26 + res += 1 + ord(char) - ord("A") + return res \ No newline at end of file diff --git "a/0172.\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266/0172-\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266.py" "b/0172.\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266/0172-\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266.py" index 5f4c466..d80bb7a 100644 --- "a/0172.\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266/0172-\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266.py" +++ "b/0172.\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266/0172-\351\230\266\344\271\230\345\220\216\347\232\204\351\233\266.py" @@ -6,7 +6,6 @@ def trailingZeroes(self, n): """ res = 0 while n > 4: + res += n //5 n //= 5 - res += n - return res - \ No newline at end of file + return res \ No newline at end of file diff --git "a/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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" index eb457d5..b38a445 100644 --- "a/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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" @@ -11,30 +11,27 @@ def __init__(self, root): """ :type root: TreeNode """ - self.stack = [] - self.pushLeft(root) - + + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + self.l = inorder(root) + self.idx = 0 def next(self): """ @return the next smallest number :rtype: int """ - popedNode = self.stack.pop() - self.pushLeft(popedNode.right) - return popedNode.val + self.idx += 1 + return self.l[self.idx - 1] def hasNext(self): """ @return whether we have a next smallest number :rtype: bool """ - return len(self.stack) != 0 - - def pushLeft(self, node): - while(node): - self.stack.append(node) - node = node.left - + return self.idx < len(self.l) # Your BSTIterator object will be instantiated and called as such: diff --git "a/0188.\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\272IV/0188-\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\272IV.py" "b/0188.\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\272IV/0188-\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\272IV.py" new file mode 100644 index 0000000..84d748c --- /dev/null +++ "b/0188.\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\272IV/0188-\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\272IV.py" @@ -0,0 +1,41 @@ +class Solution(object): + def maxProfit(self, k, prices): + """ + :type k: int + :type prices: List[int] + :rtype: int + """ + max_k = k + if k > len(prices): + return self.maxProfit2(prices) + + n = len(prices) + dp = [[[0 for _ in range(2)] for _ in range(max_k + 1)] for _ in range(n)] + + for i, price in enumerate(prices): + for k in range(max_k, 0, -1): + if i == 0: + dp[0][k][0] = 0 + dp[0][k][1] = -price + else: + dp[i][k][0] = max(dp[i - 1][k][0], dp[i - 1][k][1] + prices[i]) + dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - prices[i]) + + return dp[n - 1][max_k][0] if prices else 0 + + + def maxProfit2(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + for i, price in enumerate(prices): + if i == 0: + dp[0][0] = 0 + dp[0][1] = -price + else: + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) + dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - prices[i]) + + return dp[len(prices) - 1][0] if prices else 0 \ No newline at end of file diff --git "a/0189.\346\227\213\350\275\254\346\225\260\347\273\204/0189-\346\227\213\350\275\254\346\225\260\347\273\204.py" "b/0189.\346\227\213\350\275\254\346\225\260\347\273\204/0189-\346\227\213\350\275\254\346\225\260\347\273\204.py" index 0f9436d..c7c127f 100644 --- "a/0189.\346\227\213\350\275\254\346\225\260\347\273\204/0189-\346\227\213\350\275\254\346\225\260\347\273\204.py" +++ "b/0189.\346\227\213\350\275\254\346\225\260\347\273\204/0189-\346\227\213\350\275\254\346\225\260\347\273\204.py" @@ -3,8 +3,11 @@ def rotate(self, nums, k): """ :type nums: List[int] :type k: int - :rtype: void Do not return anything, modify nums in-place instead. + :rtype: None Do not return anything, modify nums in-place instead. """ - l = len(nums) - k = k % l - nums[:] = nums[l-k:] + nums[:l-k] + #每次把最后一个数放到最前面,放k次 + for i in range(k): + # tmp = nums[0] + tmp = nums.pop() + nums.insert(0, tmp) + \ No newline at end of file diff --git "a/0190.\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215/0190-\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215.py" "b/0190.\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215/0190-\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215.py" index e58bbb8..a2bf6fc 100644 --- "a/0190.\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215/0190-\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215.py" +++ "b/0190.\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215/0190-\351\242\240\345\200\222\344\272\214\350\277\233\345\210\266\344\275\215.py" @@ -2,9 +2,9 @@ class Solution: # @param n, an integer # @return an integer def reverseBits(self, n): - b = bin(n)[2:] - b = "0" * (32 - len(b)) + b - # print b - # print b[::-1] - return int(b[::-1], 2) - \ No newline at end of file + res = 0 + for i in range(32): + res <<= 1 + res += n & 1 + n >>= 1 + return res \ No newline at end of file diff --git "a/0191.\344\275\2151\347\232\204\344\270\252\346\225\260/0191-\344\275\2151\347\232\204\344\270\252\346\225\260.py" "b/0191.\344\275\2151\347\232\204\344\270\252\346\225\260/0191-\344\275\2151\347\232\204\344\270\252\346\225\260.py" index 944a2e5..1e7ce05 100644 --- "a/0191.\344\275\2151\347\232\204\344\270\252\346\225\260/0191-\344\275\2151\347\232\204\344\270\252\346\225\260.py" +++ "b/0191.\344\275\2151\347\232\204\344\270\252\346\225\260/0191-\344\275\2151\347\232\204\344\270\252\346\225\260.py" @@ -4,9 +4,4 @@ def hammingWeight(self, n): :type n: int :rtype: int """ - sum = 0 - while(n > 0): - if (n & 1): - sum += 1 - n >>= 1 - return sum \ No newline at end of file + return bin(n).count("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.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.py" index 4dee799..515cd58 100644 --- "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.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.py" @@ -4,15 +4,15 @@ def rob(self, nums): :type nums: List[int] :rtype: int """ + # return 0 if not nums: return 0 - dp = [nums[0]] - if len(nums) == 1: - return dp[0] - dp.append(max(nums[0], nums[1])) - # if len(nums) == 2: - # return dp[1] - for i in range(2, len(nums)): - dp.append(max(dp[i-2] + nums[i], dp[i-1])) - # print dp - return dp[-1] \ No newline at end of file + 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/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/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" index 2e25954..6a266c3 100644 --- "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.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.py" @@ -11,26 +11,15 @@ def rightSideView(self, root): :type root: TreeNode :rtype: List[int] """ - if not root: - return [] - next_layer = [root] - result = [root.val] - while(next_layer): - temp_next_layer = [] - for node in next_layer: - if not node: - continue - if node.left: - temp_next_layer.append(node.left) - if node.right: - temp_next_layer.append(node.right) - # print temp_next_layer[0].val - if temp_next_layer: - next_layer = temp_next_layer - result.append(temp_next_layer[-1].val) - # print result - else: - break + res = [] + def dfs(node, depth): + if not node: + return + if depth > len(res): + res.append(node.val) + dfs(node.right, depth + 1) + dfs(node.left, depth +1) - return result - \ No newline at end of file + + dfs(root, 1) + return res \ No newline at end of file diff --git "a/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" "b/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" index 5e1ec45..0da7d96 100644 --- "a/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" +++ "b/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" @@ -1,33 +1,29 @@ class Solution(object): - def numIslands(self, M): + def numIslands(self, grid): """ :type grid: List[List[str]] :rtype: int """ - if not M or not M[0]: + if not grid or not grid[0]: return 0 - m, n = len(M), len(M[0]) - visited = [[0 for j in range(n)] for i in range(m)] - # print visited + m, n = len(grid), len(grid[0]) dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - res = 0 - - def dfs(x0, y0): + def dfs(x, y): 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 M[x][y] == '1' and visited[x][y] ==0: - visited[x][y] = 1 - dfs(x, y) - + xx = x + dx[k] + yy = y + dy[k] + + if 0 <= xx < m and 0 <= yy < n and grid[xx][yy] == "1": + grid[xx][yy] = "0" + dfs(xx, yy) + + + res = 0 for i in range(m): for j in range(n): - if M[i][j] == '1' and visited[i][j] == 0: - res += 1 - visited[i][j] = 1 + if grid[i][j] == "1": + grid[i][j] = "0" dfs(i, j) - # print visited - + res += 1 return res \ No newline at end of file diff --git "a/0201.\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216/0201-\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216.py" "b/0201.\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216/0201-\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216.py" new file mode 100644 index 0000000..fba5811 --- /dev/null +++ "b/0201.\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216/0201-\346\225\260\345\255\227\350\214\203\345\233\264\346\214\211\344\275\215\344\270\216.py" @@ -0,0 +1,13 @@ +class Solution(object): + def rangeBitwiseAnd(self, m, n): + """ + :type m: int + :type n: int + :rtype: int + """ + if m == 0 or m == n: + return m + else: #当n > m的时候,因为相邻两个数 &的结果的最后一位必定为1,因此可以递归处理 + return self.rangeBitwiseAnd(m >> 1, n >> 1) << 1 + + \ No newline at end of file diff --git "a/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" "b/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" index 0ec75fb..b376561 100644 --- "a/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" +++ "b/0202.\345\277\253\344\271\220\346\225\260/0202-\345\277\253\344\271\220\346\225\260.py" @@ -4,15 +4,17 @@ def isHappy(self, n): :type n: int :rtype: bool """ - l = set() - while(n!= 1): - l.add(n) - temp = 0 - while(n > 0): - temp += (n % 10) ** 2 - n /= 10 - n = temp - if n in l: - return False - - return n == 1 \ No newline at end of file + 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/0203.\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240/0203-\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.py" "b/0203.\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240/0203-\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.py" index b1d673f..8edf91a 100644 --- "a/0203.\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240/0203-\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.py" +++ "b/0203.\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240/0203-\347\247\273\351\231\244\351\223\276\350\241\250\345\205\203\347\264\240.py" @@ -11,17 +11,18 @@ def removeElements(self, head, val): :type val: int :rtype: ListNode """ - dummy = ListNode(0) + if not head: + return head + dummy = ListNode(-1) dummy.next = head - pre = dummy - ptr = head - while(ptr != None): - if ptr.val != val: - pre = pre.next - ptr = ptr.next + + pre, cur = dummy, head + while cur: + if cur.val == val: #需要被删除 + pre.next = cur.next + cur.next = None + cur = pre.next else: - # print pre.val, ptr.val - pre.next = ptr.next - ptr = pre.next - return dummy.next - \ No newline at end of file + pre = pre.next + cur = cur.next + return dummy.next \ No newline at end of file diff --git "a/0204.\350\256\241\346\225\260\350\264\250\346\225\260/0204-\350\256\241\346\225\260\350\264\250\346\225\260.py" "b/0204.\350\256\241\346\225\260\350\264\250\346\225\260/0204-\350\256\241\346\225\260\350\264\250\346\225\260.py" index afa9f29..c9852a5 100644 --- "a/0204.\350\256\241\346\225\260\350\264\250\346\225\260/0204-\350\256\241\346\225\260\350\264\250\346\225\260.py" +++ "b/0204.\350\256\241\346\225\260\350\264\250\346\225\260/0204-\350\256\241\346\225\260\350\264\250\346\225\260.py" @@ -4,16 +4,9 @@ def countPrimes(self, n): :type n: int :rtype: int """ - # print int(n**0.5 +1) - if n <= 2: - return 0 - temp =[1 for i in range(1,n+1)] - temp[0], temp[1] = 0,0 - for i in range(2, int(n**0.5 +1)): - if temp[i] == 1: - for j in range(i*i, n, i): - temp[j] = 0 - # print temp - return sum(temp) - - \ No newline at end of file + record = [1] * n + for i in range(2, n): + if record[i] == 1: + for j in range(i * 2, n, i): + record[j] = 0 + return sum(record) - 2 if n > 1 else 0 \ 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.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.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.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/0206.\345\217\215\350\275\254\351\223\276\350\241\250/0206-\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/0206.\345\217\215\350\275\254\351\223\276\350\241\250/0206-\345\217\215\350\275\254\351\223\276\350\241\250.py" index 96678b3..ace8b9e 100644 --- "a/0206.\345\217\215\350\275\254\351\223\276\350\241\250/0206-\345\217\215\350\275\254\351\223\276\350\241\250.py" +++ "b/0206.\345\217\215\350\275\254\351\223\276\350\241\250/0206-\345\217\215\350\275\254\351\223\276\350\241\250.py" @@ -10,21 +10,14 @@ def reverseList(self, head): :type head: ListNode :rtype: ListNode """ - if head is None or head.next is None : + if not head or not head.next: return head - - dummyhead = ListNode(0) - dummyhead.next = pre = head - cur = pre.next - while(cur): - # print cur.val, cur.next.val, pre.val - pre.next = cur.next - cur.next = dummyhead.next - dummyhead.next = cur - cur = pre.next - - return dummyhead.next - - - + pre, cur = None, head + while cur: + tmp = cur.next #保存尾部 + cur.next = pre #逆转局部 + pre = cur #pre后移 + cur = tmp #cur后移 + return pre + \ No newline at end of file diff --git "a/0211.\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0211-\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" "b/0211.\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0211-\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" index 60ea337..db66ffb 100644 --- "a/0211.\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0211-\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" +++ "b/0211.\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241/0211-\346\267\273\345\212\240\344\270\216\346\220\234\347\264\242\345\215\225\350\257\215-\346\225\260\346\215\256\347\273\223\346\236\204\350\256\276\350\256\241.py" @@ -1,11 +1,11 @@ class WordDictionary(object): - + def __init__(self): """ Initialize your data structure here. """ self.roots = {} - + def addWord(self, word): """ Adds a word into the data structure. @@ -17,7 +17,7 @@ def addWord(self, word): for char in word: node = node.setdefault(char, {}) node["end"] = True - + def search(self, word): """ Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter. @@ -27,7 +27,7 @@ def search(self, word): self.res = False self.searchHelper(self.roots, word) return self.res - + def searchHelper(self, dic, word): if not word: self.res |= "end" in dic diff --git "a/0212.\345\215\225\350\257\215\346\220\234\347\264\242II/0212-\345\215\225\350\257\215\346\220\234\347\264\242II.py" "b/0212.\345\215\225\350\257\215\346\220\234\347\264\242II/0212-\345\215\225\350\257\215\346\220\234\347\264\242II.py" index c7b72a7..7ddeda8 100644 --- "a/0212.\345\215\225\350\257\215\346\220\234\347\264\242II/0212-\345\215\225\350\257\215\346\220\234\347\264\242II.py" +++ "b/0212.\345\215\225\350\257\215\346\220\234\347\264\242II/0212-\345\215\225\350\257\215\346\220\234\347\264\242II.py" @@ -59,10 +59,10 @@ def findWords(self, board, words): for word in words: tree.insert(word) words = set(words) - res = set() def dfs(x0, y0, node, tmpword): visited.add((x0, y0)) + # print tmpword, x0, y0 for k in range(4): x = x0 + dx[k] y = y0 + dy[k] @@ -72,8 +72,8 @@ def dfs(x0, y0, node, tmpword): dfs(x, y, node[board[x][y]], tmpword + board[x][y]) visited.remove((x,y)) - if tmpword in words: #找到一个单词了 - res.add(tmpword) #用集合避免重复 + if tmpword in words: + res.add(tmpword) for i in range(m): for j in range(n): diff --git "a/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" "b/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" index 5f42c1c..86e9798 100644 --- "a/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" +++ "b/0214.\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262/0214-\346\234\200\347\237\255\345\233\236\346\226\207\344\270\262.py" @@ -5,8 +5,10 @@ def shortestPalindrome(self, s): :rtype: str """ reversedS = s[::-1] + # print reversedS i = 0 for i in range(len(s)): + # print reversedS[i:], s[:len(s) - i] if reversedS[i:] == s[:len(s) - i]: return reversedS[:i] + s return "" \ 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.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.py" index 54fb400..6c62036 100644 --- "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.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.py" @@ -5,4 +5,26 @@ def findKthLargest(self, nums, k): :type k: int :rtype: int """ - return sorted(nums, reverse = True)[k-1] \ No newline at end of file + 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/0216.\347\273\204\345\220\210\346\200\273\345\222\214III/0216-\347\273\204\345\220\210\346\200\273\345\222\214III.py" "b/0216.\347\273\204\345\220\210\346\200\273\345\222\214III/0216-\347\273\204\345\220\210\346\200\273\345\222\214III.py" index 6db4e39..c710340 100644 --- "a/0216.\347\273\204\345\220\210\346\200\273\345\222\214III/0216-\347\273\204\345\220\210\346\200\273\345\222\214III.py" +++ "b/0216.\347\273\204\345\220\210\346\200\273\345\222\214III/0216-\347\273\204\345\220\210\346\200\273\345\222\214III.py" @@ -5,21 +5,20 @@ def combinationSum3(self, k, n): :type n: int :rtype: List[List[int]] """ - if not k or not n: - return [] - - res = [] - def dfs(k, n, tmp, start): - if n == 0 and k == 0: - res.append(tmp[:]) + res = [] + def dfs(start, cnt, target, tmp): + if target < 0: return - if k <= 0 or n <= 0: - return - - for i in range(start, 10): - tmp.append(i) - dfs(k - 1, n - i, tmp, i + 1) - tmp.pop() - - dfs(k, n, [], 1) + if target == 0: + if cnt == 0: + res.append(tmp) + else: + return + + for num in range(start, 10): + visited.add(num) + dfs(num + 1, cnt - 1, target - num, tmp + [num]) + visited.remove(num) + visited = set() + dfs(1, k, n, []) return res \ No newline at end of file diff --git "a/0217.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240/0217-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240.py" "b/0217.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240/0217-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240.py" index 159c7f0..6570342 100644 --- "a/0217.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240/0217-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240.py" +++ "b/0217.\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240/0217-\345\255\230\345\234\250\351\207\215\345\244\215\345\205\203\347\264\240.py" @@ -4,10 +4,4 @@ def containsDuplicate(self, nums): :type nums: List[int] :rtype: bool """ - if len(nums) <= 1: - return False - nums.sort() - for index in range(0,len(nums)-1): - if nums[index] == nums[index +1]:#or nums[index] == nums[index-1]: - return True - return False \ No newline at end of file + return len(nums) != len(set(nums)) \ 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.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.py" index 47b4e95..5d2aa7a 100644 --- "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.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.py" @@ -5,12 +5,10 @@ def containsNearbyDuplicate(self, nums, k): :type k: int :rtype: bool """ - record = dict() + dic = dict() for i, num in enumerate(nums): - # print record - if record.get(num, -1) != -1: - if i - record[num] <= k: + if num in dic: + if i - dic[num] <= k: return True - record[num] = i - return False - \ No newline at end of file + 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.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.py" index 449e4ed..a04b18b 100644 --- "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.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.py" @@ -11,6 +11,9 @@ def countNodes(self, root): :type root: TreeNode :rtype: int """ - if not root: - return 0 - return 1 + self.countNodes(root.left) + self.countNodes(root.right) \ No newline at end of file + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + return len(inorder(root)) + \ No newline at end of file diff --git "a/0253.\344\274\232\350\256\256\345\256\244II/0253-\344\274\232\350\256\256\345\256\244II.py" "b/0253.\344\274\232\350\256\256\345\256\244II/0253-\344\274\232\350\256\256\345\256\244II.py" index 35d0b7b..b66bc55 100644 --- "a/0253.\344\274\232\350\256\256\345\256\244II/0253-\344\274\232\350\256\256\345\256\244II.py" +++ "b/0253.\344\274\232\350\256\256\345\256\244II/0253-\344\274\232\350\256\256\345\256\244II.py" @@ -6,16 +6,18 @@ def minMeetingRooms(self, intervals): """ if not intervals: return 0 - intervals = sorted(intervals, key = lambda x :x[1]) - record = [0 for _ in range(intervals[-1][1] + 2)] + if not intervals[0]: + return 1 + intervals = sorted(intervals, key = lambda x: x[1]) + record = [0 for _ in range(intervals[-1][1] + 1)] - for i, interval in enumerate(intervals): - start, end = interval[0], interval[1] - record[start] += 1 + for interval in intervals: + # print record + begin, end = interval[0], interval[1] + record[begin] += 1 record[end] -= 1 - - # print record - for i in range(1, len(record)): - record[i] += record[i - 1] - + + for i, x in enumerate(record): + if i > 0: + record[i] += record[i - 1] return max(record) \ No newline at end of file diff --git "a/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/0309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" "b/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/0309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" new file mode 100644 index 0000000..b8f03fc --- /dev/null +++ "b/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/0309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" @@ -0,0 +1,15 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + for i, price in enumerate(prices): + if i == 0: + dp[0][0] = 0 + dp[0][1] = -price + else: + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) + dp[i][1] = max(dp[i - 1][1], dp[i - 2][0] - prices[i]) #前天买的今天才能卖 + return dp[i][0] if prices else 0 \ 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.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.py" index 6a23614..ceb97e9 100644 --- "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.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.py" @@ -1,8 +1,15 @@ class Solution(object): def reverseString(self, s): """ - :type s: str - :rtype: str + :type s: List[str] + :rtype: None Do not return anything, modify s in-place instead. """ - return s[::-1] + 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/0415.\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240/0415-\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240.py" "b/0415.\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240/0415-\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240.py" index 4c2a9a0..86f7c94 100644 --- "a/0415.\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240/0415-\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240.py" +++ "b/0415.\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240/0415-\345\255\227\347\254\246\344\270\262\347\233\270\345\212\240.py" @@ -1,41 +1,36 @@ class Solution(object): - def addStrings(self, nums1, nums2): + def addStrings(self, s1, s2): """ :type num1: str :type num2: str :rtype: str """ - if not nums1: - return nums2 - elif not nums2: - return nums1 - elif not nums1 and not nums2: - return "" - - l1, l2 = len(nums1), len(nums2) - if l1 > l2: #保证 l1 较短 + l1, l2 = len(s1), len(s2) + if l1 < l2: + s1, s2 = s2, s1 l1, l2 = l2, l1 - nums1, nums2 = nums2, nums1 - n1 = list(nums1)[::-1] - n2 = list(nums2)[::-1] - - res = list() - for i in range(0, l2): - if i < l1: - res.append(int(n1[i]) + int(n2[i])) - else: - res.append(int(n2[i])) - - # print res - for i in range(0, l2): - while(res[i] > 9): - res[i] -= 10 - if i != l2 - 1: - res[i + 1] += 1 + s1 = [int(x) for x in s1] + s2 = [int(x) for x in s2] + s1, s2 = s1[::-1], s2[::-1] + for i, digit in enumerate(s2): + s1[i] += s2[i] + + s1 = self.CarrySolver(s1) + s1 = s1[::-1] + return "".join(str(x) for x in s1) + + def CarrySolver(self, nums): + #这个函数的功能是:将输入的数组中的每一位处理好进位 + #举例:输入[15, 27, 12], 返回[5, 8, 4, 1] + i = 0 + while i < len(nums): + if nums[i] >= 10: + carrier = nums[i] // 10 + if i == len(nums) - 1: + nums.append(carrier) else: - res.append(1) - l2 += 1 + nums[i + 1] += carrier + nums[i] %= 10 + i += 1 - return "".join(str(res[i]) for i in range(l2 - 1, -1, -1)) - - \ No newline at end of file + return nums \ No newline at end of file diff --git "a/0714.\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\345\220\253\346\211\213\347\273\255\350\264\271/0714-\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\345\220\253\346\211\213\347\273\255\350\264\271.py" "b/0714.\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\345\220\253\346\211\213\347\273\255\350\264\271/0714-\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\345\220\253\346\211\213\347\273\255\350\264\271.py" new file mode 100644 index 0000000..f55fa80 --- /dev/null +++ "b/0714.\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\345\220\253\346\211\213\347\273\255\350\264\271/0714-\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\345\220\253\346\211\213\347\273\255\350\264\271.py" @@ -0,0 +1,18 @@ +class Solution(object): + def maxProfit(self, prices, fee): + """ + :type prices: List[int] + :type fee: int + :rtype: int + """ + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + for i, price in enumerate(prices): + if i == 0: + dp[0][0] = 0 + dp[0][1] = -price + else: + # tmp = dp[i][0] + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i] - fee) + dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - prices[i]) + # print dp + return dp[i][0] if prices else 0 \ No newline at end of file diff --git "a/1014.\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210/1014-\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210.py" "b/1014.\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210/1014-\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210.py" index 98c66fa..7c69fc9 100644 --- "a/1014.\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210/1014-\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210.py" +++ "b/1014.\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210/1014-\346\234\200\344\275\263\350\247\202\345\205\211\347\273\204\345\220\210.py" @@ -5,12 +5,9 @@ def maxScoreSightseeingPair(self, A): :rtype: int """ res = 0 - mmax = A[0] - mmax_index = 0 + pre_max = A[0] + 0 #初始值 for j in range(1, len(A)): - res = max(res, mmax + A[j] + mmax_index - j) - if A[j] + j > mmax + mmax_index: - mmax = A[j] - mmax_index = j + res = max(res, pre_max + A[j] - j) #判断能否刷新res + pre_max = max(pre_max, A[j] + j) #判断能否刷新pre_max, 得到更大的A[i] + i return res \ No newline at end of file diff --git "a/1093.\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241/1093-\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241.py" "b/1093.\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241/1093-\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241.py" new file mode 100644 index 0000000..153b96b --- /dev/null +++ "b/1093.\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241/1093-\345\244\247\346\240\267\346\234\254\347\273\237\350\256\241.py" @@ -0,0 +1,55 @@ +class Solution(object): + def sampleStats(self, count): + """ + :type count: List[int] + :rtype: List[float] + """ + s = 0 + total_cnt = sum(count) + cnt = 0 + avg, median, mean, mean_cnt = 0, 0, 0, 0 + min_element, max_element = 0, 0 + #找最小值 + for i in range(len(count)): + if count[i] != 0: + min_element = i + break + #找最大值 + for i in range(len(count) - 1, -1, -1): + if count[i] != 0: + max_element = i + break + + #找一共统计了多少个数字 + geshu = 0 + for i in count: + if i > 0: + geshu += i + + find = False + for i, num in enumerate(count): + s += num * i #计算总和 + if mean_cnt < num: #找count数组最大值的下标 + mean = i + mean_cnt = num + + cnt += num #找目前出现了多少个数字 + if cnt > total_cnt // 2 and find == False: + if total_cnt % 2: #中位数肯定是一个数 + median = i + find = True + else: + if cnt - num == total_cnt // 2: #中位数有两个不同的数 + for j in range(i - 1, -1, -1): #往前找上一个数 + if count[j] > 0: + median = (i + j) /2.0 + find = True + break + else:#中位数有两个相同的数 + median = i + find = True + + return [min_element, max_element, 1.0 * s /geshu, median, mean ] + + + \ No newline at end of file diff --git "a/1094.\346\213\274\350\275\246/1094-\346\213\274\350\275\246.py" "b/1094.\346\213\274\350\275\246/1094-\346\213\274\350\275\246.py" new file mode 100644 index 0000000..83d63f5 --- /dev/null +++ "b/1094.\346\213\274\350\275\246/1094-\346\213\274\350\275\246.py" @@ -0,0 +1,20 @@ +class Solution(object): + def carPooling(self, trips, capacity): + """ + :type trips: List[List[int]] + :type capacity: int + :rtype: bool + """ + time = [0 for _ in range(1005)] + + for num, start, end in trips: + time[start] += num + time[end] -= num + + for i, x in enumerate(time): + time[i] += time[i - 1] + if time[i] > capacity: + return False + + return True + \ No newline at end of file diff --git "a/1095.\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274/1095-\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274.py" "b/1095.\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274/1095-\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274.py" new file mode 100644 index 0000000..9968a55 --- /dev/null +++ "b/1095.\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274/1095-\345\261\261\350\204\211\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\347\233\256\346\240\207\345\200\274.py" @@ -0,0 +1,52 @@ +class Solution(object): + def findInMountainArray(self, target, mountain_arr): + """ + :type target: integer + :type mountain_arr: MountainArray + :rtype: integer + """ + # 得到数组长度 + n = mountain_arr.length() + #找山顶 + left, right = 0, n - 1 + while 1: + mid = (left + right) // 2 + val = mountain_arr.get(mid) + lval, rval = mountain_arr.get(mid - 1), mountain_arr.get(mid + 1) + + if val > lval and val > rval: + peak = val + peak_idx = mid + break + if val < rval: + left = mid + 1 + else: + right = mid + if target == peak: + return mid + + #找左侧 + left, right = 0, peak_idx - 1 + while left <= right: + mid = (left + right) // 2 + val = mountain_arr.get(mid) + if val == target: + return mid + elif val > target: + right = mid - 1 + else: + left = mid + 1 + + #找右侧 + left, right = peak_idx + 1, n - 1 + while left <= right: + mid = (left + right) // 2 + val = mountain_arr.get(mid) + if val == target: + return mid + elif val > target: + left = mid + 1 + else: + right = mid - 1 + + return -1 diff --git a/README.md b/README.md index 2a42799..4d70f6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1 @@ -# LeetCode-Python -杩欎釜鏂囦欢澶归噷瀛樻斁鐨勬槸鎴戝湪Leetcode-cn涓婄殑绗竴杞埛棰樼殑AC浠g爜銆 - -棰樼洰鍒嗘瀽瑙g瓟鍙互鍙傝冩垜鐨勪釜浜哄崥瀹細https://blog.csdn.net/qq_32424059 - -鏈枃浠跺す鐢県ttps://github.com/JiayangWu/LeetCodeCN-Submissions-Crawler 鑷姩鐢熸垚銆 +# LeetCode-Solutions From 2a8d3c1a26fda47c5e6823fc42aa00e0bd600bf5 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sun, 8 Sep 2019 21:01:45 -0400 Subject: [PATCH 019/183] 2019-09-08 --- ...25\350\257\215\350\247\204\345\276\213.py" | 29 +++++++------------ ...73\350\275\254\346\270\270\346\210\217.py" | 4 +-- 2 files changed, 12 insertions(+), 21 deletions(-) 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.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.py" index 1b425aa..93a230e 100644 --- "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.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.py" @@ -1,29 +1,20 @@ class Solution(object): - def wordPattern(self, pattern, str): + def wordPattern(self, pattern, s): """ :type pattern: str :type str: str :rtype: bool """ - s = str.split(" ") + s = s.split(" ") if len(pattern) != len(s): return False - record = [0 for i in range(0, 26)] #记录下pattern里每个字母出现的次数 - hashmap = dict() - - for i, word in enumerate(s): - t = ord(pattern[i]) - ord("a") - - if word not in hashmap.keys(): - if record[t] > 0: - return False - hashmap[word] = pattern[i] - record[t] = 1 + dic = {} + for i, char in enumerate(pattern): + if char not in dic: + dic[char] = s[i] else: - if hashmap[word] != pattern[i]: + if dic[char] != s[i]: return False - - return True - - - \ No newline at end of file + + return len(set(dic.values())) == len(dic.values()) + \ No newline at end of file diff --git "a/0293.\347\277\273\350\275\254\346\270\270\346\210\217/0293-\347\277\273\350\275\254\346\270\270\346\210\217.py" "b/0293.\347\277\273\350\275\254\346\270\270\346\210\217/0293-\347\277\273\350\275\254\346\270\270\346\210\217.py" index 0d67248..3b268c1 100644 --- "a/0293.\347\277\273\350\275\254\346\270\270\346\210\217/0293-\347\277\273\350\275\254\346\270\270\346\210\217.py" +++ "b/0293.\347\277\273\350\275\254\346\270\270\346\210\217/0293-\347\277\273\350\275\254\346\270\270\346\210\217.py" @@ -6,6 +6,6 @@ def generatePossibleNextMoves(self, s): """ res = [] for i in range(len(s) - 1): - if s[i:i+2] == "++": - res.append(s[:i] + "--" + s[i+2:]) + if s[i:i + 2] == "++": + res.append(s[:i] + "--" + s[i + 2:]) return res \ No newline at end of file From 483497f08c6f2ebc6aa79c6557dbf416bd4f8b39 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Tue, 10 Sep 2019 22:11:47 -0400 Subject: [PATCH 020/183] 2019-09-10 --- ...0\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" | 1 + 1 file changed, 1 insertion(+) diff --git "a/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" "b/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" index 3d15c44..f49d843 100644 --- "a/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" +++ "b/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" @@ -13,3 +13,4 @@ def intToRoman(self, num): if num == 0: break return res + From 8b8242632cad464124f81e6c7f79700819983e8e Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Wed, 11 Sep 2019 23:20:59 -0400 Subject: [PATCH 021/183] 2019-09-11 --- ...\350\275\254\346\270\270\346\210\217II.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "0294.\347\277\273\350\275\254\346\270\270\346\210\217II/0294-\347\277\273\350\275\254\346\270\270\346\210\217II.py" diff --git "a/0294.\347\277\273\350\275\254\346\270\270\346\210\217II/0294-\347\277\273\350\275\254\346\270\270\346\210\217II.py" "b/0294.\347\277\273\350\275\254\346\270\270\346\210\217II/0294-\347\277\273\350\275\254\346\270\270\346\210\217II.py" new file mode 100644 index 0000000..0bfa03a --- /dev/null +++ "b/0294.\347\277\273\350\275\254\346\270\270\346\210\217II/0294-\347\277\273\350\275\254\346\270\270\346\210\217II.py" @@ -0,0 +1,19 @@ +class Solution(object): + def canWin(self, string): + """ + :type s: str + :rtype: bool + """ + record = {} + def helper(s): + if s in record: + return record[s] + for i in range(len(s) - 1): + if s[i:i + 2] == "++": + next_s = s[:i] + "--" + s[i + 2:] + if not helper(next_s): + record[next_s] = False + return True + return False # ++不存在 + + return helper(string) \ No newline at end of file From 540a28ddbe47fb344fdf838348f917183878c1d5 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Fri, 13 Sep 2019 22:41:44 -0400 Subject: [PATCH 022/183] 2019-09-13 --- ...04\344\270\255\344\275\215\346\225\260.py" | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git "a/0295.\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260/0295-\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260.py" "b/0295.\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260/0295-\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260.py" index 30e181d..2abe054 100644 --- "a/0295.\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260/0295-\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260.py" +++ "b/0295.\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260/0295-\346\225\260\346\215\256\346\265\201\347\232\204\344\270\255\344\275\215\346\225\260.py" @@ -1,41 +1,42 @@ from heapq import * +# class Heaps(object): +# def __init__(self): +# self.min_heap = [] +# self.max_heap = [] + +# def __ class MedianFinder(object): -# 维护两个堆,一个大顶堆,一个小顶堆,小顶堆里的数比大顶堆里的数都要大, -# 如果有两个潜在的中位数(两个堆size相同),数据流的中位数就是两个堆顶之和除以2 -# 如果只有一个中位数,就看size更小的那个堆的堆顶 -# 如果新进来的数比小顶堆的数要小,就把它插入大顶堆 -# 如果新进来的数比小顶堆的数要大,就把它插入小顶堆 -# 调整两个堆,使得size 差最大为1 + def __init__(self): """ initialize your data structure here. """ - self.max_h = list() - self.min_h = list() - heapify(self.max_h) - heapify(self.min_h) - + self.min_heap = [] + self.max_heap = [] + heapify(self.min_heap) + heapify(self.max_heap) def addNum(self, num): """ :type num: int :rtype: None """ - heappush(self.min_h, num) - heappush(self.max_h, -heappop(self.min_h)) - if len(self.max_h) > len(self.min_h): - heappush(self.min_h, -heappop(self.max_h)) + heappush(self.min_heap, num) + heappush(self.max_heap, -heappop(self.min_heap)) + if len(self.max_heap) > len(self.min_heap): + heappush(self.min_heap, -heappop(self.max_heap)) + def findMedian(self): """ :rtype: float """ - max_len = len(self.max_h) - min_len = len(self.min_h) - if max_len == min_len: #有两个候选中位数 - return (self.min_h[0] + -self.max_h[0]) / 2. - else:#小顶堆的size 一定 >= 大顶堆的size,所以答案就是小顶堆的堆顶 - return self.min_h[0] / 1. + l_min_heap = len(self.min_heap) + l_max_heap = len(self.max_heap) + if l_min_heap == l_max_heap: + return (self.min_heap[0] - self.max_heap[0]) /2. + else: + return self.min_heap[0]/1. From df8939f35b2e563cc77976d565724df72c165874 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sat, 14 Sep 2019 23:22:41 -0400 Subject: [PATCH 023/183] 2019-09-14 --- ...\264\347\232\204\345\255\220\344\270\262.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" diff --git "a/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" "b/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" new file mode 100644 index 0000000..3ad2040 --- /dev/null +++ "b/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" @@ -0,0 +1,17 @@ +class Solution(object): + def reverseParentheses(self, s): + """ + :type s: str + :rtype: str + """ + if not s or ")" not in s: + return s + stack = [] + for i, char in enumerate(s): + if char == "(": + stack.append(i) + elif char == ")": + left = stack.pop() + right = i + return self.reverseParentheses(s[:left] + s[left + 1:right][::-1] + s[right + 1:]) + \ No newline at end of file From 6f2e5a93d16fd32a28075d6dd70450318b949c6a Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Sat, 14 Sep 2019 23:26:05 -0400 Subject: [PATCH 024/183] 2019-09-14 --- ...00\345\244\247\346\225\260\351\207\217.py" | 15 ++++++++ ...60\347\273\204\344\271\213\345\222\214.py" | 36 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 "5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" create mode 100644 "5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" diff --git "a/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" "b/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" new file mode 100644 index 0000000..d59b097 --- /dev/null +++ "b/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" @@ -0,0 +1,15 @@ +class Solution(object): + def maxNumberOfBalloons(self, text): + """ + :type text: str + :rtype: int + """ + dic = collections.Counter(text) + #balloon + min_count = 99999999 + for char in "balon": + tmp = dic[char] + if char in "lo": + tmp /= 2 + min_count = min(min_count, tmp) + return min_count \ No newline at end of file diff --git "a/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" "b/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" new file mode 100644 index 0000000..6706434 --- /dev/null +++ "b/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" @@ -0,0 +1,36 @@ +class Solution(object): + def kConcatenationMaxSum(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: int + """ + if max(arr) < 0: + return 0 + if sum(arr) > 0: + res = sum(arr) * (k - 2) + dp = [0] * len(arr) + dp[0] = arr[0] + for i in range(1,len(arr)): + dp[i] = dp[i - 1] + arr[i] + + res += max(dp) + dp = [0] * len(arr) + dp[-1] = arr[-1] + for i in range(len(arr) - 2, -1, -1): + dp[i] = dp[i + 1] + arr[i] + + res += max(dp) + return (res)% (10 ** 9 + 7) + + arr = arr + arr + dp = [0] * len(arr) + dp[0] = arr[0] + for i in range(1,len(arr)): + if dp[i - 1] > 0: + dp[i] = dp[i - 1] + arr[i] + else: + dp[i] = arr[i] + + return max(dp) % (10 ** 9 + 7) + \ No newline at end of file From c8002e532fef3c57dccc19a75d2cc1b3c5162848 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Mon, 16 Sep 2019 22:15:57 -0400 Subject: [PATCH 025/183] 2019-09-16 --- ...0\260\350\276\276\347\273\210\347\202\271.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "0780.\345\210\260\350\276\276\347\273\210\347\202\271/0780-\345\210\260\350\276\276\347\273\210\347\202\271.py" diff --git "a/0780.\345\210\260\350\276\276\347\273\210\347\202\271/0780-\345\210\260\350\276\276\347\273\210\347\202\271.py" "b/0780.\345\210\260\350\276\276\347\273\210\347\202\271/0780-\345\210\260\350\276\276\347\273\210\347\202\271.py" new file mode 100644 index 0000000..aaf515f --- /dev/null +++ "b/0780.\345\210\260\350\276\276\347\273\210\347\202\271/0780-\345\210\260\350\276\276\347\273\210\347\202\271.py" @@ -0,0 +1,16 @@ +class Solution(object): + def reachingPoints(self, sx, sy, tx, ty): + """ + :type sx: int + :type sy: int + :type tx: int + :type ty: int + :rtype: bool + """ + if tx < sx or ty < sy: + return False + if tx == sx and (ty - sy) % sx == 0: + return True + if ty == sy and (tx - sx) % sy == 0: + return True + return self.reachingPoints(sx, sy, tx % ty, ty % tx) \ No newline at end of file From 59c6fc5671e2580c4da89d3b54788c9cbf8356e6 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Tue, 12 Nov 2019 22:37:13 -0500 Subject: [PATCH 026/183] 2019-11-12 --- ...76\345\217\263\345\214\272\351\227\264.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "0436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/0436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" diff --git "a/0436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/0436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" "b/0436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/0436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" new file mode 100644 index 0000000..cffe9ed --- /dev/null +++ "b/0436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/0436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" @@ -0,0 +1,23 @@ +class Solution(object): + def findRightInterval(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: List[int] + """ + dic = {} + for i, (start, end) in enumerate(intervals): + dic[start] = i + + res = [-1 for _ in range(len(intervals))] + + l = [interval[0] for interval in intervals] + l = sorted(l, key = lambda x:x) + + for i, (start, end) in enumerate(intervals): + idx = bisect.bisect_left(l, end) + if idx < len(l): + res[i] = dic[l[idx]] + + return res + + \ No newline at end of file From 3d8c2a42dd2944896f34e322428902cfb3a91ae4 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Tue, 12 Nov 2019 22:46:01 -0500 Subject: [PATCH 027/183] 2019-11-12 --- ...56\350\277\236\346\216\245\343\200\215.py" | 41 +++++++++++++++++++ ...61\347\232\204\346\225\260\345\255\227.py" | 14 +++++++ ...32\350\256\256\346\227\245\347\250\213.py" | 31 ++++++++++++++ ...33\346\216\267\347\241\254\345\270\201.py" | 27 ++++++++++++ ...53\345\267\247\345\205\213\345\212\233.py" | 27 ++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 "1192.\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215/1192-\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215.py" create mode 100644 "1228.\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/1228-\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" create mode 100644 "1229.\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213/1229-\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213.py" create mode 100644 "1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.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.py" diff --git "a/1192.\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215/1192-\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215.py" "b/1192.\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215/1192-\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215.py" new file mode 100644 index 0000000..38f0e66 --- /dev/null +++ "b/1192.\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215/1192-\346\237\245\346\211\276\351\233\206\347\276\244\345\206\205\347\232\204\343\200\214\345\205\263\351\224\256\350\277\236\346\216\245\343\200\215.py" @@ -0,0 +1,41 @@ +from collections import defaultdict +class Solution(object): + def criticalConnections(self, n, connections): + """ + :type n: int + :type connections: List[List[int]] + :rtype: List[List[int]] + """ + visited = set() + low = [9999999] * n + discover = [999999] * n + parent = [-1] * n + + graph = defaultdict(list) + self.time = 0 + res = [] + for u, v in connections: + graph[u].append(v) + graph[v].append(u) + + def dfs(u): + visited.add(u) + discover[u] = self.time + low[u] = self.time + self.time += 1 + + for v in graph[u]: + if v not in visited: + parent[v] = u + dfs(v) + low[u] = min(low[u], low[v]) + + if low[v] > discover[u]: + res.append([u, v]) + elif v != parent[u]: + low[u] = min(low[u], discover[v]) + + for i in range(n): + if i not in visited: + dfs(i) + return res diff --git "a/1228.\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/1228-\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/1228.\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/1228-\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..d31e33b --- /dev/null +++ "b/1228.\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/1228-\347\255\211\345\267\256\346\225\260\345\210\227\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,14 @@ +class Solution(object): + def missingNumber(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + d = (arr[-1] - arr[0]) // len(arr) + + k = arr[0] + for num in arr: + if num != k: + return k + k += d + return k \ No newline at end of file diff --git "a/1229.\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213/1229-\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213.py" "b/1229.\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213/1229-\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213.py" new file mode 100644 index 0000000..6547a61 --- /dev/null +++ "b/1229.\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213/1229-\345\256\211\346\216\222\344\274\232\350\256\256\346\227\245\347\250\213.py" @@ -0,0 +1,31 @@ +class Solution(object): + def minAvailableDuration(self, slots1, slots2, duration): + """ + :type slots1: List[List[int]] + :type slots2: List[List[int]] + :type duration: int + :rtype: List[int] + """ + slots1 = sorted(slots1, key = lambda x:x[0]) + slots2 = sorted(slots2, key = lambda x:x[0]) + slots = [] + i, j = 0, 0 + while i < len(slots1) and j < len(slots2): + if slots1[i][1] < slots2[j][0]: + i += 1 + continue + elif slots1[i][0] > slots2[j][1]: + j += 1 + continue + start = max(slots1[i][0], slots2[j][0]) + end = min(slots1[i][1], slots2[j][1]) + slots.append([start, end]) + i += 1 + + print(slots) + for start, end in slots: + if end - start >= duration: + return [start, start + duration] + return [] + + diff --git "a/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" new file mode 100644 index 0000000..d928eef --- /dev/null +++ "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" @@ -0,0 +1,27 @@ +class Solution(object): + def probabilityOfHeads(self, prob, target): + """ + :type prob: List[float] + :type target: int + :rtype: float + """ + dp = [0 for _ in range(len(prob) + 1)] + dp[1] = prob[0] + dp[0] = 1 - prob[0] + for i in range(1, len(prob)): + new_dp = [0 for _ in range(len(prob) + 1)] + for j in range(target + 1): + new_dp[j] = dp[j] * (1 - prob[i]) + dp[j - 1] * prob[i] + dp = new_dp[:] + return dp[target] + + # dp = [[0 for _ in range(len(prob) + 1)] for _ in range(len(prob))] + # # dp[i][j] 表示前i个硬币里,有j个硬币正面朝上的概率 + # dp[0][1] = prob[0] + # dp[0][0] = 1 - prob[0] + # for i, p in enumerate(prob): + # for j in range(target + 1): + # if i > 0: + # dp[i][j] += dp[i - 1][j] * (1 - p) + # dp[i][j] += dp[i - 1][j - 1] * (p) + # return dp[-1][target] \ 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.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.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.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 From 291ca5656b535f5745a0bbf913b863af30f7b2c0 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Wed, 13 Nov 2019 00:04:09 -0500 Subject: [PATCH 028/183] 2019-11-13 --- ...55\345\255\220\345\272\217\345\210\227.py" | 13 +++++ ...35\347\246\273\346\200\273\345\222\214.py" | 20 ++++++++ ...21\347\232\204\347\233\264\345\276\204.py" | 26 ++++++++++ ...77\346\225\260\345\257\271\351\223\276.py" | 16 ++++++ ...04\345\215\225\350\257\215\346\225\260.py" | 31 ++++++++++++ ...15\347\232\204\345\255\220\344\270\262.py" | 14 ++++++ ...72\347\216\260\346\254\241\346\225\260.py" | 8 +++ ...04\347\232\204\344\272\244\351\233\206.py" | 18 +++++++ ...41\345\255\227\347\254\246\344\270\262.py" | 21 ++++++++ ...00\347\202\271\346\210\220\347\272\277.py" | 22 ++++++++ ...60\347\273\204\345\217\230\346\215\242.py" | 20 ++++++++ ...43\346\216\222\350\241\214\346\246\234.py" | 40 +++++++++++++++ ...21\347\232\204\347\233\264\345\276\204.py" | 32 ++++++++++++ ...46\344\270\262\347\233\270\345\220\214.py" | 21 ++++++++ ...20\346\225\260\347\273\204\343\200\215.py" | 36 +++++++++++++ ...10\347\232\204\346\213\254\345\217\267.py" | 23 +++++++++ ...75\346\225\260\347\273\204\343\200\215.py" | 14 ++++++ ...74\347\232\204\346\225\260\347\233\256.py" | 22 ++++++++ ...77\347\232\204\346\225\260\347\233\256.py" | 37 ++++++++++++++ ...25\350\257\215\351\233\206\345\220\210.py" | 50 +++++++++++++++++++ 20 files changed, 484 insertions(+) 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.py" create mode 100644 "0477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/0477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" create mode 100644 "0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" create mode 100644 "0646.\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276/0646-\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276.py" create mode 100644 "0792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/0792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.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.py" create mode 100644 "1207.\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260/1207-\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260.py" create mode 100644 "1213.\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/1213-\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.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.py" create mode 100644 "1232.\347\274\200\347\202\271\346\210\220\347\272\277/1232-\347\274\200\347\202\271\346\210\220\347\272\277.py" create mode 100644 "1243.\346\225\260\347\273\204\345\217\230\346\215\242/1243-\346\225\260\347\273\204\345\217\230\346\215\242.py" create mode 100644 "1244.\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234/1244-\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234.py" create mode 100644 "1245.\346\240\221\347\232\204\347\233\264\345\276\204/1245-\346\240\221\347\232\204\347\233\264\345\276\204.py" create mode 100644 "1247.\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214/1247-\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214.py" create mode 100644 "1248.\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215/1248-\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215.py" create mode 100644 "1249.\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267/1249-\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267.py" create mode 100644 "1250.\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215/1250-\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215.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.py" create mode 100644 "1254.\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256/1254-\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256.py" create mode 100644 "1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" 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.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.py" new file mode 100644 index 0000000..fb0353b --- /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.py" @@ -0,0 +1,13 @@ +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 + return i == len(s) \ No newline at end of file diff --git "a/0477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/0477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" "b/0477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/0477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" new file mode 100644 index 0000000..9ce810a --- /dev/null +++ "b/0477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/0477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" @@ -0,0 +1,20 @@ +class Solution(object): + def totalHammingDistance(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if not nums: + return 0 + res = 0 + mask = 1 + for i in range(32): + cnt_one = 0 + for num in nums: + cnt_one += 1 if num & mask else 0 + + res += cnt_one * (len(nums) - cnt_one) + mask = mask << 1 + return res + + \ No newline at end of file diff --git "a/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" "b/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" new file mode 100644 index 0000000..49542b5 --- /dev/null +++ "b/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.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 diameterOfBinaryTree(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + self.res = 0 + def height(node): + if not node: + return 0 + left_h = height(node.left) + right_h = height(node.right) + + self.res = max(self.res, left_h + right_h) + return 1 + max(left_h, right_h) + height(root) + return self.res \ No newline at end of file diff --git "a/0646.\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276/0646-\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276.py" "b/0646.\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276/0646-\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276.py" new file mode 100644 index 0000000..fc77aab --- /dev/null +++ "b/0646.\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276/0646-\346\234\200\351\225\277\346\225\260\345\257\271\351\223\276.py" @@ -0,0 +1,16 @@ +class Solution(object): + def findLongestChain(self, pairs): + """ + :type pairs: List[List[int]] + :rtype: int + """ + pairs = sorted(pairs, key = lambda x: x[1]) + + end = pairs[0][0] - 1 + res = 0 + for pair in pairs: + if pair[0] > end: + res += 1 + end = pair[1] + + return res \ No newline at end of file diff --git "a/0792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/0792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" "b/0792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/0792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" new file mode 100644 index 0000000..81e7c4a --- /dev/null +++ "b/0792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/0792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" @@ -0,0 +1,31 @@ +class Solution(object): + def numMatchingSubseq(self, S, words): + """ + :type S: str + :type words: List[str] + :rtype: int + """ + from collections import defaultdict + + dic = defaultdict(list) + for i, ch in enumerate(S): + dic[ch].append(i) + + res = 0 + for word in words: + pre = -1 + flag = True + for i, ch in enumerate(word): + l = dic[ch] + # 在l找第一个比pre大的元素 + idx = bisect.bisect(l, pre) + + if idx == len(l):# 没找到 + flag = False + break + pre = l[idx] + + if flag: + res += 1 + + return res \ No newline at end of file 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.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.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.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/1207.\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260/1207-\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260.py" "b/1207.\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260/1207-\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260.py" new file mode 100644 index 0000000..76dc9b9 --- /dev/null +++ "b/1207.\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260/1207-\347\213\254\344\270\200\346\227\240\344\272\214\347\232\204\345\207\272\347\216\260\346\254\241\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution(object): + def uniqueOccurrences(self, arr): + """ + :type arr: List[int] + :rtype: bool + """ + d = collections.Counter(arr) + return len(d.values()) == len(set(d.values())) \ No newline at end of file diff --git "a/1213.\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/1213-\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" "b/1213.\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/1213-\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" new file mode 100644 index 0000000..7e4fb9a --- /dev/null +++ "b/1213.\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206/1213-\344\270\211\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206.py" @@ -0,0 +1,18 @@ +class Solution(object): + def arraysIntersection(self, arr1, arr2, arr3): + """ + :type arr1: List[int] + :type arr2: List[int] + :type arr3: List[int] + :rtype: List[int] + """ + res = [] + record = [0 for _ in range(2005)] + for num in arr1 + arr2 + arr3: + record[num] += 1 + + for i in range(len(record)): + if record[i] == 3: + res.append(i) + + return res \ 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.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.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.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/1232.\347\274\200\347\202\271\346\210\220\347\272\277/1232-\347\274\200\347\202\271\346\210\220\347\272\277.py" "b/1232.\347\274\200\347\202\271\346\210\220\347\272\277/1232-\347\274\200\347\202\271\346\210\220\347\272\277.py" new file mode 100644 index 0000000..0c166b1 --- /dev/null +++ "b/1232.\347\274\200\347\202\271\346\210\220\347\272\277/1232-\347\274\200\347\202\271\346\210\220\347\272\277.py" @@ -0,0 +1,22 @@ +class Solution(object): + def checkStraightLine(self, coordinates): + """ + :type coordinates: List[List[int]] + :rtype: bool + """ + c = sorted(coordinates, key = lambda x:x[0]) + k = None + for i in range(len(c)): + if i: + x0, y0 = c[i - 1][0], c[i - 1][1] + x1, y1 = c[i][0], c[i][1] + + if x0 == x1: + return False + new_k = 1.0 * (y1 - y0) / (x1 - x0) + if k and k != new_k: + return False + k = new_k + + return True + \ No newline at end of file diff --git "a/1243.\346\225\260\347\273\204\345\217\230\346\215\242/1243-\346\225\260\347\273\204\345\217\230\346\215\242.py" "b/1243.\346\225\260\347\273\204\345\217\230\346\215\242/1243-\346\225\260\347\273\204\345\217\230\346\215\242.py" new file mode 100644 index 0000000..3cdc0ae --- /dev/null +++ "b/1243.\346\225\260\347\273\204\345\217\230\346\215\242/1243-\346\225\260\347\273\204\345\217\230\346\215\242.py" @@ -0,0 +1,20 @@ +class Solution(object): + def transformArray(self, arr): + """ + :type arr: List[int] + :rtype: List[int] + """ + flag = 1 + while flag: + flag = 0 + res = [num for num in arr] + for i in range(1, len(arr) - 1): + if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]: + res[i] -= 1 + flag = 1 + elif arr[i - 1] > arr[i] and arr[i] < arr[i + 1]: + res[i] += 1 + flag = 1 + arr = res[:] + return res + \ No newline at end of file diff --git "a/1244.\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234/1244-\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234.py" "b/1244.\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234/1244-\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234.py" new file mode 100644 index 0000000..4cc49f1 --- /dev/null +++ "b/1244.\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234/1244-\345\212\233\346\211\243\346\216\222\350\241\214\346\246\234.py" @@ -0,0 +1,40 @@ +from collections import defaultdict +from heapq import * +class Leaderboard(object): + + def __init__(self): + self.dic = defaultdict(int) + + def addScore(self, playerId, score): + """ + :type playerId: int + :type score: int + :rtype: None + """ + self.dic[playerId] += score + + def top(self, K): + """ + :type K: int + :rtype: int + """ + self.l = [] + heapify(self.l) + for pid, score in self.dic.items(): + if len(self.l) >= K: + if score > self.l[0]: + heappush(self.l, score) + heappop(self.l) + else: + heappush(self.l, score) + + return sum(self.l) + + + def reset(self, playerId): + """ + :type playerId: int + :rtype: None + """ + self.dic[playerId] = 0 + diff --git "a/1245.\346\240\221\347\232\204\347\233\264\345\276\204/1245-\346\240\221\347\232\204\347\233\264\345\276\204.py" "b/1245.\346\240\221\347\232\204\347\233\264\345\276\204/1245-\346\240\221\347\232\204\347\233\264\345\276\204.py" new file mode 100644 index 0000000..dcb279d --- /dev/null +++ "b/1245.\346\240\221\347\232\204\347\233\264\345\276\204/1245-\346\240\221\347\232\204\347\233\264\345\276\204.py" @@ -0,0 +1,32 @@ +from collections import defaultdict +class Solution(object): + def treeDiameter(self, edges): + """ + :type edges: List[List[int]] + :rtype: int + """ + if not edges: + return 0 + + self.neibors = defaultdict(set) + self.res = 0 + + for start, end in edges: # 建树 + self.neibors[start].add(end) + + def getHeight(node): + res = [] + for neibor in self.neibors[node]: + res.append(getHeight(neibor)) + + while len(res) < 2: # 如果孩子少于两个,就给它补空的上去 + res.append(0) + + res = sorted(res) + self.res = max(self.res, sum(res[-2:])) # 取最长的两个子树长度 + return 1 + max(res) + + getHeight(edges[0][0]) + return self.res + + \ No newline at end of file diff --git "a/1247.\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214/1247-\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214.py" "b/1247.\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214/1247-\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214.py" new file mode 100644 index 0000000..2ac2df1 --- /dev/null +++ "b/1247.\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214/1247-\344\272\244\346\215\242\345\255\227\347\254\246\344\275\277\345\276\227\345\255\227\347\254\246\344\270\262\347\233\270\345\220\214.py" @@ -0,0 +1,21 @@ +class Solution(object): + def minimumSwap(self, s1, s2): + """ + :type s1: str + :type s2: str + :rtype: int + """ + s = s1 + s2 + x = s.count("x") + if len(s1) != len(s2) or x % 2 == 1 or (len(s) - x) % 2 == 1: + return -1 + + pair1 = 0 + pair2 = 0 + for i in range(len(s1)): + if s1[i] == "y" and s2[i] == "x": + pair1 += 1 + elif s1[i] == "x" and s2[i] == "y": + pair2 += 1 + + return pair1 // 2 + pair2 // 2 + pair1 % 2 + pair2 % 2 \ No newline at end of file diff --git "a/1248.\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215/1248-\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215.py" "b/1248.\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215/1248-\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215.py" new file mode 100644 index 0000000..0101e1d --- /dev/null +++ "b/1248.\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215/1248-\347\273\237\350\256\241\343\200\214\344\274\230\347\276\216\345\255\220\346\225\260\347\273\204\343\200\215.py" @@ -0,0 +1,36 @@ +class Solution(object): + def numberOfSubarrays(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: int + """ + if not nums: + return 0 + res = 0 + odd = [] + for i, num in enumerate(nums): + if num % 2: + odd.append(i) + + if len(odd) < k: + return 0 + + + for i in range(len(odd)): + if i + k > len(odd): + break + if i: + last = odd[i - 1] + else: + last = -1 + + if i + k < len(odd): + nxt = odd[i + k] + else: + nxt = len(nums) + + left = odd[i] - last + right = nxt - odd[i + k - 1] + res += left * right + return res \ No newline at end of file diff --git "a/1249.\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267/1249-\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267.py" "b/1249.\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267/1249-\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267.py" new file mode 100644 index 0000000..29ef926 --- /dev/null +++ "b/1249.\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267/1249-\347\247\273\351\231\244\346\227\240\346\225\210\347\232\204\346\213\254\345\217\267.py" @@ -0,0 +1,23 @@ +class Solution(object): + def minRemoveToMakeValid(self, s): + """ + :type s: str + :rtype: str + """ + left, right = 0, 0 + stack = [] + remove = set() + for i, ch in enumerate(s): + if ch == "(": + stack.append(i) + elif ch == ")": + if stack: + stack.pop() + else: + remove.add(i) + stack = set(stack) + res = "" + for i, ch in enumerate(s): + if i not in stack and i not in remove: + res += ch + return res \ No newline at end of file diff --git "a/1250.\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215/1250-\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215.py" "b/1250.\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215/1250-\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215.py" new file mode 100644 index 0000000..64a8190 --- /dev/null +++ "b/1250.\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215/1250-\346\243\200\346\237\245\343\200\214\345\245\275\346\225\260\347\273\204\343\200\215.py" @@ -0,0 +1,14 @@ +class Solution(object): + def isGoodArray(self, nums): + """ + :type nums: List[int] + :rtype: bool + """ + def gcd(x, y): + while y: + x, y = y, x % y + return x + g = nums[0] + for num in nums: + g = gcd(g, num) + return g == 1 \ No newline at end of file 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.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.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.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/1254.\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256/1254-\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256.py" "b/1254.\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256/1254-\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..4718739 --- /dev/null +++ "b/1254.\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256/1254-\347\273\237\350\256\241\345\260\201\351\227\255\345\262\233\345\261\277\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,37 @@ +class Solution(object): + def closedIsland(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + m, n = len(grid), len(grid[0]) + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + def dfs(x0, y0): + if grid[x0][y0] == 0: + grid[x0][y0] = -1 + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 < x < m and 0 < y < n and grid[x][y] == 0: + dfs(x, y) + + for j in range(n): + dfs(0, j) + for j in range(n): + dfs(m - 1, j) + for i in range(m): + dfs(i, 0) + for i in range(m): + dfs(i, n - 1) + + res = 0 + for i in range(m): + for j in range(n): + if grid[i][j] == 0: + res += 1 + dfs(i, j) + return res + + \ No newline at end of file diff --git "a/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" new file mode 100644 index 0000000..32f2f05 --- /dev/null +++ "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" @@ -0,0 +1,50 @@ +class Solution(object): + def maxScoreWords(self, words, letters, score): + """ + :type words: List[str] + :type letters: List[str] + :type score: List[int] + :rtype: int + """ + from collections import defaultdict, Counter + dic = dict() + letter_dic = defaultdict(int) + for i, val in enumerate(score):#构建一个字典 + dic[chr(ord("a") + i)] = val #key是 字母,val是字母对应的分数 + + letter_dic = Counter(letters)#构建另一个字典, key是字母, val是每次字母剩余的个数 + + s = set(letters) + v_words = [] + for word in words:#删掉所有根本不可能被构成的单词 + flag = 0 + for char in word: + if char not in s: + flag = 1 + if flag: # 如果一个单词里存在某个在letters里找不到的字母,则无需考虑这个单词 + continue + v_words.append(word) + self.res = 0 + + def helper(word, letter_dic): + # return True 如果word能用letter_dic里的letter构成,否则返回False + dicc = collections.Counter(word) + for key in dicc: + if dicc[key] > letter_dic[key]: + return False + return True + + def dfs(start, tmp): + self.res = max(self.res, tmp) + if start >= len(v_words): + return + + for i in range(start, len(v_words)):#从start开始找,避免重复 + if helper(v_words[i], letter_dic):#如果当前单词可以被构成 + for char in v_words[i]: #构成它,更新字典 + letter_dic[char] -= 1 + dfs(i + 1, tmp + sum([dic[char] for char in v_words[i]])) #dfs下一层 + for char in v_words[i]: #回溯,复原所有状态 + letter_dic[char] += 1 + dfs(0, 0) + return self.res \ No newline at end of file From e96fab65f4b40eb2f2d2b7a5556f81417f41cf79 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Wed, 13 Nov 2019 22:06:51 -0500 Subject: [PATCH 029/183] 2019-11-13 --- .DS_Store | Bin 38916 -> 38916 bytes ...76\345\217\263\345\214\272\351\227\264.py" | 23 +++++++++++ ...45\346\240\274\345\274\217\345\214\226.py" | 18 +++++++++ ...00\347\237\255\350\267\257\345\276\204.py" | 37 ++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 "0436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/0436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" create mode 100644 "0482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/0482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" create mode 100644 "1055.\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1055-\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" diff --git a/.DS_Store b/.DS_Store index c3c7b18ac4d4405100dd480520b352d36bae0e58..f6c8d190892599e1f476613744d4dcdcb1475e9d 100644 GIT binary patch delta 142 zcmZqKz|^vVX~R>VWvf_e3x*!8t V-)5!8F0RdbJ*PP~m$z^;0|0=}B)R|q delta 207 zcmZqKz|^vVX~R Date: Wed, 13 Nov 2019 22:25:53 -0500 Subject: [PATCH 030/183] 2019-11-13 --- githubkey | 27 +++++++++++++++++++++++++++ githubkey.pub | 1 + 2 files changed, 28 insertions(+) create mode 100644 githubkey create mode 100644 githubkey.pub diff --git a/githubkey b/githubkey new file mode 100644 index 0000000..e920a2c --- /dev/null +++ b/githubkey @@ -0,0 +1,27 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn +NhAAAAAwEAAQAAAQEArhQFBiTLIuhd0tytIH8Pfp+sjyN7poF35OSAjoLjZnj0Ht+2tZ5d +HFCySGIIJD9diZxPTXna9hcPL/7/GQcm1XeY7Dw6BgxiECkQPhhbdCbIGx9Ykh8ihBVduQ +z7oq7nMjYHksMZTl5NjUV2bj46e3SeqqGGTAJciRBYhgGbNjN2Tuft+on4dShhotvvXFwH +xaBrY3RvyFDr5aE5os5XD4UTRekr8M2sBIOUzYgFhLzGU8WdEwWfAj4PcaZZXI5Jrsyxob +CGHE43Ec/reB7qpYnbeoJRdE5DjTnUCmx7f5VqvFrWJtVcIruxhJRmlU/eOfl0TSBrVYcf +byygOpcu7wAAA8gWXF7jFlxe4wAAAAdzc2gtcnNhAAABAQCuFAUGJMsi6F3S3K0gfw9+n6 +yPI3umgXfk5ICOguNmePQe37a1nl0cULJIYggkP12JnE9Nedr2Fw8v/v8ZBybVd5jsPDoG +DGIQKRA+GFt0JsgbH1iSHyKEFV25DPuirucyNgeSwxlOXk2NRXZuPjp7dJ6qoYZMAlyJEF +iGAZs2M3ZO5+36ifh1KGGi2+9cXAfFoGtjdG/IUOvloTmizlcPhRNF6SvwzawEg5TNiAWE +vMZTxZ0TBZ8CPg9xpllcjkmuzLGhsIYcTjcRz+t4Huqlidt6glF0TkONOdQKbHt/lWq8Wt +Ym1Vwiu7GElGaVT945+XRNIGtVhx9vLKA6ly7vAAAAAwEAAQAAAQBUhF3IFNcXlK/w77mS +vH3+YXH7cSPYvKVEWXjdOElF+FW2I7HmzgOw+rEEmawQRT+Zz21lVVNtBdcW23xpX2KIY+ ++4Sql1RE/cPsOnElZct3OST47GKx2r+V+ut9H4s2iGpVrZ86V2uix2+ZG9hrMIO5/JgnDc +uIzK80e3kFIWZur9tQB1rmu2t1Z18jo3AlLGqNKYsWa/c8dOEGIz9XYi684yW1DdwS7Cb7 +6mpzmWYYZhld0S6ZieDwE1gMC2FyRUVnj1n1nP1Xm5L8JeVxU6B4t+f4+S1KBp+yQ9ZDa8 +M23LONJ6gYvFQsf6ShWsOLPHgQRKAFe5cCiAV/SDyxsJAAAAgG7GAZf0ygKmyvpQHARGw9 +lw450CPy51rldOBiYRRlXmQxI1VcRJtzPYfoYRw6qXBlhjGdOwYhjn64wWo0p2nYtN45ee +AoWbsku/nBSsplMzSKzc7/RI6LZIgRWuNIClCgfyMd6ogzKsh/+ljDnhtp7+dx+jnzPEbN +a0V1mUc17SAAAAgQDTzVBBaq9v6CJQx3242JX4GUNFH3DbUju3ZPV44Sp2oSZoUxIVIPlH +LR16bY5EA6Hj4rVggDSmUmjJuuyU+Ml2NRstceautGD07cMe/BZR+RNfanM11kBf2Jsrdu +RSQo0sFyK636LUJGYdwLf9DvDerh7B3BrWVzFIHrfuJnkSmwAAAIEA0md18iqJm8dOEEyq +2Fkk7XKmDDnsyJCtUs2jAV37r0EAa/eRG4SUY0R96sIl3AJnSV3v8dcwjku74veYzZAXvV +zJmiqObg59mSv6npeV96yTyknyLPfptPTNZq/2B457zWhdtKORUjgIP/qFi5AehYKo7+7j +gOGpfZ5yAGM1QD0AAAAQNTMwMDgxOTk5QHFxLmNvbQECAw== +-----END OPENSSH PRIVATE KEY----- diff --git a/githubkey.pub b/githubkey.pub new file mode 100644 index 0000000..7f26407 --- /dev/null +++ b/githubkey.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuFAUGJMsi6F3S3K0gfw9+n6yPI3umgXfk5ICOguNmePQe37a1nl0cULJIYggkP12JnE9Nedr2Fw8v/v8ZBybVd5jsPDoGDGIQKRA+GFt0JsgbH1iSHyKEFV25DPuirucyNgeSwxlOXk2NRXZuPjp7dJ6qoYZMAlyJEFiGAZs2M3ZO5+36ifh1KGGi2+9cXAfFoGtjdG/IUOvloTmizlcPhRNF6SvwzawEg5TNiAWEvMZTxZ0TBZ8CPg9xpllcjkmuzLGhsIYcTjcRz+t4Huqlidt6glF0TkONOdQKbHt/lWq8WtYm1Vwiu7GElGaVT945+XRNIGtVhx9vLKA6ly7v 530081999@qq.com From 3cd8b24e834e39b1bbae677335ab84fd798f30c8 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Wed, 13 Nov 2019 22:31:02 -0500 Subject: [PATCH 031/183] 2019-11-13 --- .../0326-3\347\232\204\345\271\202.py" | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git "a/0326.3\347\232\204\345\271\202/0326-3\347\232\204\345\271\202.py" "b/0326.3\347\232\204\345\271\202/0326-3\347\232\204\345\271\202.py" index aedc50d..513bb5a 100644 --- "a/0326.3\347\232\204\345\271\202/0326-3\347\232\204\345\271\202.py" +++ "b/0326.3\347\232\204\345\271\202/0326-3\347\232\204\345\271\202.py" @@ -4,9 +4,7 @@ def isPowerOfThree(self, n): :type n: int :rtype: bool """ - i = 1 - while(i Date: Wed, 13 Nov 2019 22:39:50 -0500 Subject: [PATCH 032/183] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 4d70f6c..8367a0e 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ # LeetCode-Solutions +This is my repo for my solutions of LeetCode Problems in Python2. + +You can access my Chinese Analysis in my blog:https://blog.csdn.net/qq_32424059 + +This repo is generated automatically using my script :https://github.com/JiayangWu/LeetCodeCN-Submissions-Crawler From 6e6724c5b16ef3acf90e4cd1ffa7206305317776 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Wed, 13 Nov 2019 22:40:02 -0500 Subject: [PATCH 033/183] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8367a0e..763336d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LeetCode-Solutions This is my repo for my solutions of LeetCode Problems in Python2. -You can access my Chinese Analysis in my blog:https://blog.csdn.net/qq_32424059 +You can access my Chinese Analysis in my blog: https://blog.csdn.net/qq_32424059 -This repo is generated automatically using my script :https://github.com/JiayangWu/LeetCodeCN-Submissions-Crawler +This repo is generated automatically using my script: https://github.com/JiayangWu/LeetCodeCN-Submissions-Crawler From b29c26b2594b340b1f0cba9b23efe303d23a6a1d Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Thu, 14 Nov 2019 17:37:07 -0500 Subject: [PATCH 034/183] 2019-11-14 --- ...60\345\255\227\346\270\270\346\210\217.py" | 22 ++++++++++ ...40\347\232\204\344\270\252\346\225\260.py" | 35 +++++++++++++++ ...00\347\237\255\350\267\257\345\276\204.py" | 44 +++++++------------ 3 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 "0299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/0299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" create mode 100644 "0315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/0315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" diff --git "a/0299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/0299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" "b/0299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/0299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" new file mode 100644 index 0000000..13447ba --- /dev/null +++ "b/0299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/0299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" @@ -0,0 +1,22 @@ +class Solution(object): + def getHint(self, secret, guess): + """ + :type secret: str + :type guess: str + :rtype: str + """ + from collections import Counter + dic_s = Counter(secret) + dic_g = Counter(guess) + + a, b = 0, 0 + for i in range(len(secret)): + if secret[i] == guess[i]: + a += 1 + dic_s[secret[i]] -= 1 + dic_g[secret[i]] -= 1 + + for i in dic_s & dic_g: + b += min(dic_s[i], dic_g[i]) + + return "{}A{}B".format(a, b) \ No newline at end of file diff --git "a/0315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/0315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" "b/0315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/0315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" new file mode 100644 index 0000000..4abc475 --- /dev/null +++ "b/0315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/0315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" @@ -0,0 +1,35 @@ +class TreeNode(object): + def __init__(self, val): + self.left = None + self.right = None + self.val = val + self.left_subtree_cnt = 0 + +class Solution(object): + def countSmaller(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + + # 浠庡乏寰鍙冲鐞嗭紝鍙宠竟鏄湭鐭ョ殑锛屾墍浠ヤ笉濂藉紕 + # 浠庡彸寰宸﹀鐞嗭紝鍒欏浜庢瘡涓暟锛屽叾鍙宠竟鐨勬暟閮藉凡鐭 + res = [0 for _ in nums] + root = None + for i, num in enumerate(nums[::-1]): + root = self.insert(root, num, i, res) + return res[::-1] + + def insert(self, root, val, i, res): + if not root: + root = TreeNode(val) + elif root.val >= val: + root.left_subtree_cnt += 1 + root.left = self.insert(root.left, val, i, res) + elif root.val < val: + res[i] += root.left_subtree_cnt + 1 + root.right = self.insert(root.right, val, i, res) + + return root + + \ No newline at end of file diff --git "a/1055.\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1055-\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" "b/1055.\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1055-\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" index 38b3451..6562a70 100644 --- "a/1055.\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1055-\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" +++ "b/1055.\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/1055-\345\275\242\346\210\220\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" @@ -5,33 +5,21 @@ def shortestWay(self, source, target): :type target: str :rtype: int """ - - import collections - dicse = collections.Counter(source) - dictt = collections.Counter(target) - - for key, val in dictt.items(): - if dicse.get(key, 0) == 0: + s = set(source) + t = set(target) + for ch in t: + if ch not in s: return -1 - - cnt = 0 - start, end = 0, 0 - i = 0 - while(i < len(target)): - char = target[i] - while(source[start] != char): #鎵捐捣鐐癸紝涓瀹氳兘鎵惧埌 - start += 1 - end = start + 1 - - i += 1 - while(i < len(target) and end < len(source)): - if source[end] == target[i]: #鎵炬渶闀跨殑瀛愬簭鍒 - i += 1 - end += 1 - - cnt += 1 - start = 0 #閲嶇疆璧风偣锛屼负涓嬩竴杞仛鍑嗗 - return cnt - - \ No newline at end of file + i, j = 0, 0 + res = 0 + while j < len(target): + i = 0 + while i < len(source) and j < len(target): + if source[i] == target[j]: + i += 1 + j += 1 + else: + i += 1 + res += 1 + return res \ No newline at end of file From 585ee222df066bd650b26cd03d868237400166ed Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Thu, 14 Nov 2019 22:54:17 -0500 Subject: [PATCH 035/183] 2019-11-14 --- ...14\345\220\221\351\223\276\350\241\250.py" | 38 +++++++++++++++++++ ...14\347\232\204\346\226\207\345\255\227.py" | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 "0430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/0430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "0809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/0809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" diff --git "a/0430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/0430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/0430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/0430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..08d25c6 --- /dev/null +++ "b/0430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/0430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,38 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, prev, next, child): + self.val = val + self.prev = prev + self.next = next + self.child = child +""" +class Solution(object): + def flatten(self, head): + """ + :type head: Node + :rtype: Node + """ + if not head: + return head + + def helper(node): + # 杩斿洖鐨勬槸鏈鍚庝竴涓妭鐐 + if not node: + return + while node: + nxt = node.next # 澶囦唤 next + if not nxt: + tail = node # 璁板綍 tail锛岀敤浜庤繑鍥 + if node.child: + node.next = node.child # 鎶奵hild 鍙樻垚next + node.next.prev = node + t = helper(node.child) # 閫掑綊澶勭悊锛宼 鏄鐞嗕箣鍚庣殑 鍘熸潵鐨刢hild 鐨勬渶鍚庝竴涓妭鐐 + node.child = None # 鎶奵hild 缃┖ + if nxt: # 濡傛灉鏈塶ext 閮ㄥ垎锛屽氨璁﹏ext鐨刾rev鎸囧悜 鍘熸潵鐨刢hild 澶勭悊涔嬪悗鐨勬渶鍚庝竴涓妭鐐 + nxt.prev = t + t.next = nxt # 璁 t.next 鎸囧悜鍘熸潵鐨 next + node = node.next + return tail + helper(head) + return head \ No newline at end of file diff --git "a/0809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/0809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" "b/0809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/0809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" new file mode 100644 index 0000000..59c336c --- /dev/null +++ "b/0809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/0809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" @@ -0,0 +1,38 @@ +class Solution(object): + def expressiveWords(self, S, words): + """ + :type S: str + :type words: List[str] + :rtype: int + """ + + s = set(S) + res = 0 + for word in words: + if len(S) < len(word): + continue + + i, j = 0, 0 + flag = 0 + while i < len(S) and j < len(word): + if S[i] != word[j]: + flag = 1 + break + pre = S[i] + cnt_i = 0 + while i < len(S) and S[i] == pre: + i += 1 + cnt_i += 1 + + cnt_j = 0 + while j < len(word) and word[j] == pre: + j += 1 + cnt_j += 1 + + # print cnt_i, cnt_j + if (cnt_i < 3 and cnt_i != cnt_j) or cnt_i < cnt_j: + flag = 1 + + if not flag and i == len(S): + res += 1 + return res \ No newline at end of file From ea296fdc7188d64b331e4d69c9679ee60c28d346 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Mon, 18 Nov 2019 21:01:37 -0500 Subject: [PATCH 036/183] delete --- ...8-\344\270\215\345\212\250\347\202\271.py" | 11 --- ...\350\275\246\345\210\206\351\205\215II.py" | 63 ---------------- ...04\347\264\242\345\274\225\345\257\271.py" | 34 --------- ...44\346\225\260\344\271\213\345\222\214.py" | 23 ------ ...27\347\254\246\345\255\220\344\270\262.py" | 28 -------- ...00\346\227\251\346\227\266\351\227\264.py" | 50 ------------- ...57\347\211\271\346\234\227\346\225\260.py" | 13 ---- ...47\345\224\257\344\270\200\346\225\260.py" | 15 ---- ...30\347\232\204\350\267\257\345\276\204.py" | 33 --------- ...00\346\234\211\345\237\216\345\270\202.py" | 61 ---------------- ...63\350\241\214\350\257\276\347\250\213.py" | 36 ---------- ...47\345\205\254\345\233\240\345\255\220.py" | 29 -------- ...66\346\225\260\347\233\270\345\212\240.py" | 36 ---------- ...00\346\227\240\346\225\210\345\214\226.py" | 8 --- ...04\350\256\242\347\273\237\350\256\241.py" | 17 ----- ...40\347\202\271\346\210\220\346\236\227.py" | 57 --------------- ...14\345\245\227\346\267\261\345\272\246.py" | 17 ----- ...70\345\257\271\346\216\222\345\272\217.py" | 25 ------- ...54\345\205\261\347\245\226\345\205\210.py" | 71 ------------------- ...77\346\227\266\351\227\264\346\256\265.py" | 27 ------- ...71\347\232\204\346\225\260\351\207\217.py" | 17 ----- ...00\347\237\255\350\267\257\345\276\204.py" | 40 ----------- ...04\346\234\200\345\244\247\345\200\274.py" | 34 --------- ...12\347\232\204\350\267\257\345\276\204.py" | 50 ------------- ...50\346\225\260\346\216\222\345\210\227.py" | 25 ------- ...41\345\210\222\350\257\204\344\274\260.py" | 21 ------ ...07\344\270\262\346\243\200\346\265\213.py" | 39 ---------- ...6-\347\214\234\345\255\227\350\260\234.py" | 27 ------- ...00\345\244\247\346\225\260\351\207\217.py" | 15 ---- ...64\347\232\204\345\255\220\344\270\262.py" | 17 ----- ...60\347\273\204\344\271\213\345\222\214.py" | 36 ---------- 31 files changed, 975 deletions(-) delete mode 100644 "5008.\344\270\215\345\212\250\347\202\271/5008-\344\270\215\345\212\250\347\202\271.py" delete mode 100644 "5009.\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II/5009-\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II.py" delete mode 100644 "5013.\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271/5013-\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271.py" delete mode 100644 "5021.\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214/5021-\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214.py" delete mode 100644 "5022.\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262/5022-\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262.py" delete mode 100644 "5023.\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264/5023-\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264.py" delete mode 100644 "5028.\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260/5028-\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260.py" delete mode 100644 "5034.\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260/5034-\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260.py" delete mode 100644 "5035.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204/5035-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204.py" delete mode 100644 "5036.\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202/5036-\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202.py" delete mode 100644 "5037.\345\271\263\350\241\214\350\257\276\347\250\213/5037-\345\271\263\350\241\214\350\257\276\347\250\213.py" delete mode 100644 "5076.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/5076-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" delete mode 100644 "5078.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/5078-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" delete mode 100644 "5117.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/5117-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" delete mode 100644 "5118.\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241/5118-\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241.py" delete mode 100644 "5119.\345\210\240\347\202\271\346\210\220\346\236\227/5119-\345\210\240\347\202\271\346\210\220\346\236\227.py" delete mode 100644 "5120.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/5120-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" delete mode 100644 "5127.\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217/5127-\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.py" delete mode 100644 "5128.\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/5128-\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" delete mode 100644 "5129.\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265/5129-\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265.py" delete mode 100644 "5130.\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217/5130-\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217.py" delete mode 100644 "5132.\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/5132-\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" delete mode 100644 "5133.\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/5133-\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" delete mode 100644 "5140.\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204/5140-\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204.py" delete mode 100644 "5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" delete mode 100644 "5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" delete mode 100644 "5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" delete mode 100644 "5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" delete mode 100644 "5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" delete mode 100644 "5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" delete mode 100644 "5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" diff --git "a/5008.\344\270\215\345\212\250\347\202\271/5008-\344\270\215\345\212\250\347\202\271.py" "b/5008.\344\270\215\345\212\250\347\202\271/5008-\344\270\215\345\212\250\347\202\271.py" deleted file mode 100644 index 3d497e6..0000000 --- "a/5008.\344\270\215\345\212\250\347\202\271/5008-\344\270\215\345\212\250\347\202\271.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def fixedPoint(self, A): - """ - :type A: List[int] - :rtype: int - """ - for i, x in enumerate(A): - if i == x: - return i - return -1 - \ No newline at end of file diff --git "a/5009.\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II/5009-\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II.py" "b/5009.\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II/5009-\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II.py" deleted file mode 100644 index 8e33d41..0000000 --- "a/5009.\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II/5009-\346\240\241\345\233\255\350\207\252\350\241\214\350\275\246\345\210\206\351\205\215II.py" +++ /dev/null @@ -1,63 +0,0 @@ -class Solution(object): - def assignBikes(self, workers, bikes): - """ - :type workers: List[List[int]] - :type bikes: List[List[int]] - :rtype: int - """ - if workers[-1] == [7,0] and bikes[-1] == [9, 999]: - return 7992 - if workers[-1] == [8,0] and bikes[-1] == [8, 999]: - return 8991 - if workers[-1] == [8,0] and bikes[-1] == [9, 999]: - return 8991 - if workers[-1] == [9,0] and bikes[-1] == [9, 999]: - return 9990 - if workers[-1] == [955,855] and bikes[-1] == [577, 936]: - return 3320 - if workers[-1] == [941,916] and bikes[-1] == [374, 822]: - return 1902 - ans = [-1] * len(workers) - record = dict() - n, m = len(workers), len(bikes) - dp = [[0 for _ in range(m)] for _ in range(n)] - - - for w, worker in enumerate(workers): - xw, yw = worker[0], worker[1] - - for b, bike in enumerate(bikes): - xb, yb = bike[0], bike[1] - distance = abs(xb - xw) + abs(yb - yw) - dp[w][b] = distance - # print record - - - def findRes(wid, tmp): - if wid >= n: - return - for bid in range(m): - if usedbike[bid] == 1: - continue - - usedbike[bid] = 1 - tmp += dp[wid][bid] - - if wid >= n - 1:#找完了 - self.res = min(self.res, tmp) - - if tmp > self.res:#剪枝 - usedbike[bid] = 0 - tmp -= dp[wid][bid] - continue - - findRes(wid + 1, tmp) - - usedbike[bid] = 0 - tmp -= dp[wid][bid] - - - self.res = 999999 - usedbike = [0 for _ in range(m)] - findRes(0, 0) - return self.res \ No newline at end of file diff --git "a/5013.\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271/5013-\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271.py" "b/5013.\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271/5013-\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271.py" deleted file mode 100644 index fe6b7ed..0000000 --- "a/5013.\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271/5013-\345\255\227\347\254\246\344\270\262\347\232\204\347\264\242\345\274\225\345\257\271.py" +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def indexPairs(self, text, words): - """ - :type text: str - :type words: List[str] - :rtype: List[List[int]] - """ - res = [] - record = {} - for word in words: - if record.get(len(word), -1) == -1: - record[len(word)] = [word] - else: - record[len(word)].append(word) - # min_l, max_l = min(record.keys()), min(record) - l = len(text) - for i in range(l): - for j in range(i + 1, l + 1): - # print j - if record.get(j - i, -1) == -1: - continue - - tmp = text[i:j] - # print tmp - for word in record[j - i]: - if word == tmp: - res.append([i, j - 1]) - # flag = 1 - break - - return res - - - \ No newline at end of file diff --git "a/5021.\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214/5021-\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214.py" "b/5021.\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214/5021-\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214.py" deleted file mode 100644 index aefb992..0000000 --- "a/5021.\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214/5021-\345\260\217\344\272\216K\347\232\204\344\270\244\346\225\260\344\271\213\345\222\214.py" +++ /dev/null @@ -1,23 +0,0 @@ -class Solution(object): - def twoSumLessThanK(self, A, K): - """ - :type A: List[int] - :type K: int - :rtype: int - """ - if len(A) < 2: - return -1 - tmp = [] - for i in range(len(A)): - for j in range(i + 1, len(A)): - tmp.append(A[i] + A[j]) - - tmp.sort() - if tmp[0] > K: - return -1 - # print tmp - res = tmp[0] - for item in tmp: - if item < K and abs(item - K) < abs(res - K): - res = item - return res \ No newline at end of file diff --git "a/5022.\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262/5022-\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262.py" "b/5022.\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262/5022-\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262.py" deleted file mode 100644 index b7138d2..0000000 --- "a/5022.\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262/5022-\351\225\277\345\272\246\344\270\272K\347\232\204\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\345\255\220\344\270\262.py" +++ /dev/null @@ -1,28 +0,0 @@ -class Solution(object): - def numKLenSubstrNoRepeats(self, S, K): - """ - :type S: str - :type K: int - :rtype: int - """ - if len(S) < K: - return 0 - res = 0 - for i in range(len(S) - K + 1): - # for j in range(i + K, len(S)): - tmp = S[i:i + K] - if self.check(tmp): - res += 1 - return res - - - def check(self, string): - # record = {} - from collections import Counter - record = Counter(string) - # print record - for key, val in record.items(): - if val > 1: - return False - # print string - return True \ No newline at end of file diff --git "a/5023.\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264/5023-\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264.py" "b/5023.\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264/5023-\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264.py" deleted file mode 100644 index e0ebb78..0000000 --- "a/5023.\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264/5023-\345\275\274\346\255\244\347\206\237\350\257\206\347\232\204\346\234\200\346\227\251\346\227\266\351\227\264.py" +++ /dev/null @@ -1,50 +0,0 @@ -class UnionFindSet(object): - def __init__(self, n): - self.roots = [i for i in range(n)] - self.rank = [0 for i in range(n)] - self.count = 0 - - 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 - - def check(self): - print self.roots - flag = self.find(self.roots[0]) - for i in self.roots: - if self.find(i) != flag: - return False - return True - -class Solution(object): - def earliestAcq(self, logs, N): - """ - :type logs: List[List[int]] - :type N: int - :rtype: int - """ - logs = sorted(logs, key = lambda x:x[0]) - ufs = UnionFindSet(N) - for time, x, y in logs: - ufs.union(x, y) - if ufs.check(): - return time - return -1 \ No newline at end of file diff --git "a/5028.\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260/5028-\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260.py" "b/5028.\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260/5028-\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260.py" deleted file mode 100644 index 513bcf2..0000000 --- "a/5028.\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260/5028-\351\230\277\345\247\206\346\226\257\347\211\271\346\234\227\346\225\260.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def isArmstrong(self, N): - """ - :type N: int - :rtype: bool - """ - k = len(str(N)) - n = N - s = 0 - while N: - N, tmp = divmod(N, 10) - s += tmp ** k - return s == n \ No newline at end of file diff --git "a/5034.\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260/5034-\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260.py" "b/5034.\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260/5034-\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260.py" deleted file mode 100644 index d47dfe7..0000000 --- "a/5034.\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260/5034-\346\234\200\345\244\247\345\224\257\344\270\200\346\225\260.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def largestUniqueNumber(self, A): - """ - :type A: List[int] - :rtype: int - """ - from collections import Counter - dic = Counter(A) - - res = -1 - for key, val in dic.items(): - if val == 1: - res = max(res, key) - return res - \ No newline at end of file diff --git "a/5035.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204/5035-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204.py" "b/5035.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204/5035-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204.py" deleted file mode 100644 index b9846e6..0000000 --- "a/5035.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204/5035-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\350\267\257\345\276\204.py" +++ /dev/null @@ -1,33 +0,0 @@ -class Solution(object): - def maximumMinimumPath(self, A): - """ - :type A: List[List[int]] - :rtype: int - """ - from heapq import * - if not A or not A[0]: - return 0 - - m, n = len(A), len(A[0]) - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - - res = 0 - queue = [[-A[0][0], 0, 0]] - visited = set([0,0]) - heapify(queue) - while queue: - score, x0, y0 = heappop(queue) #把目前队里最优的点找出来 - if [x0, y0] == [m - 1, n - 1]: #如果已经到终点了 - return -score - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x < m and 0 <= y < n and (x, y) not in visited: - visited.add((x, y)) - heappush(queue, [max(score, -A[x][y]), x, y]) #邻居点入队 - - - \ No newline at end of file diff --git "a/5036.\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202/5036-\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202.py" "b/5036.\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202/5036-\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202.py" deleted file mode 100644 index dabb4c7..0000000 --- "a/5036.\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202/5036-\346\234\200\344\275\216\346\210\220\346\234\254\350\201\224\351\200\232\346\211\200\346\234\211\345\237\216\345\270\202.py" +++ /dev/null @@ -1,61 +0,0 @@ -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 minimumCost(self, N, connections): - """ - :type N: int - :type conections: List[List[int]] - :rtype: int - """ - from collections import deque - from heapq import * - ufs = UnionFindSet(N) - queue = [] - - for start, end, cost in connections: - ufs.union(start, end) - queue.append([cost, start, end]) - - if ufs.count != 1: - return -1 #无法连接在一起 - #到这里可以保证一定可以把所有城市连在一起 - ufs2 = UnionFindSet(N) - heapify(queue) - res = 0 - while ufs2.count > 1: - cost, start, end = heappop(queue) - if ufs2.find(start) == ufs2.find(end): - continue - ufs2.union(start, end) - res += cost - return res - - \ No newline at end of file diff --git "a/5037.\345\271\263\350\241\214\350\257\276\347\250\213/5037-\345\271\263\350\241\214\350\257\276\347\250\213.py" "b/5037.\345\271\263\350\241\214\350\257\276\347\250\213/5037-\345\271\263\350\241\214\350\257\276\347\250\213.py" deleted file mode 100644 index 175126c..0000000 --- "a/5037.\345\271\263\350\241\214\350\257\276\347\250\213/5037-\345\271\263\350\241\214\350\257\276\347\250\213.py" +++ /dev/null @@ -1,36 +0,0 @@ -class Solution(object): - def minimumSemesters(self, N, relations): - """ - :type N: int - :type relations: List[List[int]] - :rtype: int - """ - indegree = [0 for i in range(N + 1)] - adj = [set() for _ in range(N + 1)] - for pre, cur in relations: - indegree[cur] += 1 - adj[pre].add(cur) - - from collections import deque - queue = deque() - for i, x in enumerate(indegree): - if x == 0 and i > 0: - queue.append(i) - print queue - cnt, res = 0, 0 - out = 0 - while queue: - next_queue = deque() - cnt += 1 - for cur in queue: - out += 1 - for neighbor in adj[cur]: - indegree[neighbor] -= 1 - - if indegree[neighbor] == 0: - next_queue.append(neighbor) - queue = next_queue - return cnt if out == N else -1 - - - \ No newline at end of file diff --git "a/5076.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/5076-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" "b/5076.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/5076-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" deleted file mode 100644 index 0acd271..0000000 --- "a/5076.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/5076-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def gcdOfStrings(self, str1, str2): - """ - :type str1: str - :type str2: str - :rtype: str - """ - l1,l2 = len(str1), len(str2) - set1, set2 = set(), set() - for i in range(l1 + 1): - # print str1[:i] - if self.find(str1, str1[:i]): - set1.add(str1[:i]) - - for i in range(l2 + 1): - if self.find(str2, str2[:i]): - set2.add(str2[:i]) - - # print set1, set2 - res = list(set1 & set2) - res = sorted(res, key = lambda x:-len(x)) - return res[0] if res else "" - - def find(self, string, tmp): - # if not tmp: - # print tmp - string = string.replace(tmp, "") - # print string - return len(string) == 0 \ No newline at end of file diff --git "a/5078.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/5078-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" "b/5078.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/5078-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" deleted file mode 100644 index 06a9285..0000000 --- "a/5078.\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240/5078-\350\264\237\344\272\214\350\277\233\345\210\266\346\225\260\347\233\270\345\212\240.py" +++ /dev/null @@ -1,36 +0,0 @@ -class Solution(object): - def addNegabinary(self, arr1, arr2): - """ - :type arr1: List[int] - :type arr2: List[int] - :rtype: List[int] - """ - def convertInt(string): - tmp = 1 - string = string[::-1] - res = 0 - for i, x in enumerate(string): - res += tmp * int(x) - tmp *= -2 - - return res - n1 = convertInt(arr1) - n2 = convertInt(arr2) - # print n1, n2, convertInt(self.baseNeg2(n1 + n2)) - return self.baseNeg2(n1 + n2) - - - - def baseNeg2(self, N): - """ - :type N: int - :rtype: str - """ - res = [] - # n = N - while N: - 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/5117.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/5117-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" "b/5117.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/5117-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" deleted file mode 100644 index 8a7cf16..0000000 --- "a/5117.IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226/5117-IP\345\234\260\345\235\200\346\227\240\346\225\210\345\214\226.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def defangIPaddr(self, address): - """ - :type address: str - :rtype: str - """ - address = address.replace(".", "[.]") - return address \ No newline at end of file diff --git "a/5118.\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241/5118-\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241.py" "b/5118.\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241/5118-\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241.py" deleted file mode 100644 index 523cb8f..0000000 --- "a/5118.\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241/5118-\350\210\252\347\217\255\351\242\204\350\256\242\347\273\237\350\256\241.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def corpFlightBookings(self, bookings, n): - """ - :type bookings: List[List[int]] - :type n: int - :rtype: List[int] - """ - f = [0 for _ in range(n + 1)] - - for i, j, k in bookings: - f[i - 1] += k - f[j] -= k - # print f - for i in range(1, n + 1): - f[i] += f[i - 1] - # print f - return f[:-1] \ No newline at end of file diff --git "a/5119.\345\210\240\347\202\271\346\210\220\346\236\227/5119-\345\210\240\347\202\271\346\210\220\346\236\227.py" "b/5119.\345\210\240\347\202\271\346\210\220\346\236\227/5119-\345\210\240\347\202\271\346\210\220\346\236\227.py" deleted file mode 100644 index c912ec1..0000000 --- "a/5119.\345\210\240\347\202\271\346\210\220\346\236\227/5119-\345\210\240\347\202\271\346\210\220\346\236\227.py" +++ /dev/null @@ -1,57 +0,0 @@ -# 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 delNodes(self, root, to_delete): - """ - :type root: TreeNode - :type to_delete: List[int] - :rtype: List[TreeNode] - """ - if not root: - return [] - to_delete = set(to_delete) - - res = [] - - self.roots = [] - if root.val not in to_delete: - self.roots = [root] - else: #如果连根节点都要删掉 - if root.left and root.left.val not in to_delete: - self.roots += [root.left] - if root.right and root.right.val not in to_delete: - self.roots += [root.right] - - def dfs(node): - if not node: - return - - if node.left and node.left.val in to_delete: #左节点要删 - dfs(node.left) - if node.left.left: #左节点的左节点还在,不需要删 - self.roots += [node.left.left] - if node.left.right: #左节点的右节点还在,不需要删 - self.roots += [node.left.right] - - node.left = None - - if node.right and node.right.val in to_delete:#右节点要删 - dfs(node.right) - if node.right.left: #右节点的左节点还在,不需要删 - self.roots += [node.right.left] - if node.right.right: #右节点的右节点还在,不需要删 - self.roots += [node.right.right] - - node.right = None - - dfs(node.left) - dfs(node.right) - - dfs(root) - return self.roots diff --git "a/5120.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/5120-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" "b/5120.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/5120-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" deleted file mode 100644 index 84f2bc1..0000000 --- "a/5120.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/5120-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def maxDepthAfterSplit(self, seq): - """ - :type seq: str - :rtype: List[int] - """ - # print self.depth("((()))") - res = [0 for _ in range(len(seq))] - cnt = 0 - for i, x in enumerate(seq): - if x == "(": - cnt += 1 - res[i] = cnt % 2 - else: - res[i] = cnt % 2 - cnt -= 1 - return res diff --git "a/5127.\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217/5127-\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.py" "b/5127.\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217/5127-\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.py" deleted file mode 100644 index a773b8d..0000000 --- "a/5127.\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217/5127-\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def relativeSortArray(self, arr1, arr2): - """ - :type arr1: List[int] - :type arr2: List[int] - :rtype: List[int] - """ - from collections import defaultdict - res = [] - left = [] #存放没有在arr2里出现过的数字 - set2 = set(arr2) #把arr2转成set,让查找的时间复杂度降低到O(1) - - dic = defaultdict(int) #记录arr1中数字出现的频率 - for num in arr1: - if num in set2: - dic[num] += 1 - else: - left.append(num) - - for num in arr2: - res += [num] * dic[num] - - left.sort() #按照题目要求把没出现过的元素排序 - return res + left - \ No newline at end of file diff --git "a/5128.\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/5128-\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/5128.\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/5128-\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" deleted file mode 100644 index 79145a8..0000000 --- "a/5128.\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/5128-\346\234\200\346\267\261\345\217\266\350\212\202\347\202\271\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" +++ /dev/null @@ -1,71 +0,0 @@ -# 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 lcaDeepestLeaves(self, root): - """ - :type root: TreeNode - :rtype: TreeNode - """ - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - # print inorder(root) - if not root or (not root.left and not root.right): - return root - - dic = {} - def depth(node, tmp): - if not node: - return - dic[node] = tmp + 1 - depth(node.left, tmp + 1) - depth(node.right, tmp + 1) - - depth(root, 0) - # print dic - l = [] - max_depth = max(dic.values()) - for key, val in dic.items(): - if val == max_depth: - l.append(key) - - if len(l) == 1: - return l[0] - # print l - tmpAncestor = None - if len(l) >= 2: - tmpAncestor = self.lowestCommonAncestor(root, l[0], l[1]) - for i in range(2, len(l), 1): - tmpAncestor = self.lowestCommonAncestor(root, tmpAncestor, l[i]) - return tmpAncestor - - - - def lowestCommonAncestor(self, root, p, q): - """ - :type root: TreeNode - :type p: TreeNode - :type q: TreeNode - :rtype: TreeNode - """ - - if not root or root == p or root == q: - return root - else: - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - - if left and right: #一个在左子树,一个在右子树 - return root - elif left:#都在左子树 - return left - elif right:#都在右子树 - return right - else: - return \ No newline at end of file diff --git "a/5129.\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265/5129-\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265.py" "b/5129.\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265/5129-\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265.py" deleted file mode 100644 index 31f4dc7..0000000 --- "a/5129.\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265/5129-\350\241\250\347\216\260\350\211\257\345\245\275\347\232\204\346\234\200\351\225\277\346\227\266\351\227\264\346\256\265.py" +++ /dev/null @@ -1,27 +0,0 @@ -class Solution(object): - def longestWPI(self, hours): - """ - :type hours: List[int] - :rtype: int - """ - n = len(hours) - a = [0]*n - for i,hour in enumerate(hours): - if hour>8: - a[i]=1 - else: - a[i]=-1 - for i in range(1,n): - a[i]+=a[i-1] - b={} - res = 0 - for i in range(n): - if a[i]>0: - res = max(res,i+1) - else: - if a[i]-1 in b: - res = max(res,i-b[a[i]-1]) - if a[i] not in b: - b[a[i]]=i - return res - \ No newline at end of file diff --git "a/5130.\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217/5130-\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217.py" "b/5130.\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217/5130-\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217.py" deleted file mode 100644 index a4e29c2..0000000 --- "a/5130.\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217/5130-\347\255\211\344\273\267\345\244\232\347\261\263\350\257\272\351\252\250\347\211\214\345\257\271\347\232\204\346\225\260\351\207\217.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def numEquivDominoPairs(self, dominoes): - """ - :type dominoes: List[List[int]] - :rtype: int - """ - from collections import defaultdict - dic = defaultdict(int) - res = 0 - for i, x in enumerate(dominoes): - pair = (x[1], x[0]) - if x[0] < x[1]: - pair = (x[0], x[1]) - res += dic[pair] - dic[pair] += 1 - - return res \ No newline at end of file diff --git "a/5132.\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/5132-\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" "b/5132.\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/5132-\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" deleted file mode 100644 index a957f4c..0000000 --- "a/5132.\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204/5132-\351\242\234\350\211\262\344\272\244\346\233\277\347\232\204\346\234\200\347\237\255\350\267\257\345\276\204.py" +++ /dev/null @@ -1,40 +0,0 @@ -class Solution(object): - def shortestAlternatingPaths(self, n, red_edges, blue_edges): - """ - :type n: int - :type red_edges: List[List[int]] - :type blue_edges: List[List[int]] - :rtype: List[int] - """ - from collections import defaultdict, deque - red_nei, blue_nei = defaultdict(set), defaultdict(set) - - for start, end in red_edges: #记录下所有的从红色路径可以到达的邻居节点 - red_nei[start].add(end) - for start, end in blue_edges: #记录下所有的从蓝色路径可以到达的邻居节点 - blue_nei[start].add(end) - - visited = set() - queue = deque() - queue.append((0, -1)) # -1 无色, 0 红色, 1蓝色 - distance = 0 - res = [-1] * n - while queue: - next_queue = deque() - for cur, color in queue: - if res[cur] == -1: #BFS保障了第一次到达终点时的距离一定是最短距离 - res[cur] = distance - if color == -1 or color == 0: #当前是红色,下一次在蓝色里找 - for nei in blue_nei[cur]: - if (cur, nei, 1) not in visited: - visited.add((cur, nei, 1)) - next_queue.append((nei, 1)) - if color == -1 or color == 1: #当前是蓝色,下一次在红色里找 - for nei in red_nei[cur]: - if (cur, nei, 0) not in visited: - visited.add((cur, nei, 0)) - next_queue.append((nei, 0)) - queue = next_queue - distance += 1 - return res - \ No newline at end of file diff --git "a/5133.\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/5133-\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/5133.\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/5133-\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" deleted file mode 100644 index 191c629..0000000 --- "a/5133.\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/5133-\347\273\235\345\257\271\345\200\274\350\241\250\350\276\276\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def maxAbsValExpr(self, arr1, arr2): - """ - :type arr1: List[int] - :type arr2: List[int] - :rtype: int - """ - record = [-2 ** 31] * 8 - - for i in range(len(arr1)): - for k in range(8): #生成八种可能的结果 - t = 0 - if k & 1: - t += arr1[i] - else: - t -= arr1[i] - if k & 2: - t += arr2[i] - else: - t -= arr2[i] - if k & 4: - t += i - else: - t -= i - # print k, t - record[k] = max(record[k], t) - # print record - res = 0 - for k in range(8): - # print k, ~k - res = max(res, record[k] + record[-k-1]) #第一项和最后一项,第二项和倒数第二项,两项之和一定是满足表达式的 - return res - - \ No newline at end of file diff --git "a/5140.\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204/5140-\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204.py" "b/5140.\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204/5140-\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204.py" deleted file mode 100644 index eaf1121..0000000 --- "a/5140.\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204/5140-\345\255\227\346\257\215\346\235\277\344\270\212\347\232\204\350\267\257\345\276\204.py" +++ /dev/null @@ -1,50 +0,0 @@ -class Solution(object): - def alphabetBoardPath(self, target): - """ - :type target: str - :rtype: str - """ - board = ["abcde", - "fghij", - "klmno", - "pqrst", - "uvwxy", - "z"] - - dic = dict() - for i in range(len(board)): - for j in range(len(board[0])): - - dic[board[i][j]] = [i, j] - if i == 5: - break - - x0, y0 = 0,0 - res = "" - for char in target: - tmp = "" - des = dic[char] - x1, y1 = des[0], des[1] - if x0 == x1 and y0 == y1: - res += "!" - continue - if x0 < x1: - tmp += "D" * (x1 - x0) - elif x0 > x1: - tmp += "U" * (x0 - x1) - if x1 == 5 and tmp and tmp[-1] == "D": - tmp = tmp[:-1] - if y0 < y1: - tmp += "R" * (y1 - y0) - elif y1 < y0: - tmp += "L" * (y0 - y1) - x0 = x1 - y0 = y1 - if x1 == 5: - tmp += "D" - tmp += "!" - res += tmp - return res - - - \ No newline at end of file diff --git "a/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" "b/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" deleted file mode 100644 index 0498261..0000000 --- "a/5173.\350\264\250\346\225\260\346\216\222\345\210\227/5173-\350\264\250\346\225\260\346\216\222\345\210\227.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def numPrimeArrangements(self, n): - """ - :type n: int - :rtype: int - """ - # 2 3 5 6 + 6 - prime_cnt = 0 - for i in range(1, n + 1): - if self.prime(i): - prime_cnt += 1 - non_prime_cnt = n - prime_cnt - # print prime_cnt, non_prime_cnt - return (math.factorial(prime_cnt) * math.factorial(non_prime_cnt)) % (10 ** 9 + 7) - - def prime(self, n): - if n == 1: - return False - if n == 2 or n == 3 or n == 5: - return True - for i in range(2, int(n ** 0.5) + 1): - if n % i == 0: - return False - return True - \ No newline at end of file diff --git "a/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" "b/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" deleted file mode 100644 index a2d91fc..0000000 --- "a/5174.\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260/5174-\345\201\245\350\272\253\350\256\241\345\210\222\350\257\204\344\274\260.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def dietPlanPerformance(self, calories, k, lower, upper): - """ - :type calories: List[int] - :type k: int - :type lower: int - :type upper: int - :rtype: int - """ - res = 0 - s = sum(calories[: k]) - for start in range(0, len(calories) - (k - 1)): - if start != 0: - # print start, - s += calories[start + k - 1] - calories[start - 1] - # print s - if s < lower: - res -= 1 - elif s > upper: - res += 1 - return res \ No newline at end of file diff --git "a/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" "b/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" deleted file mode 100644 index 2a74f93..0000000 --- "a/5175.\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213/5175-\346\236\204\345\273\272\345\233\236\346\226\207\344\270\262\346\243\200\346\265\213.py" +++ /dev/null @@ -1,39 +0,0 @@ -class Solution(object): - def canMakePaliQueries(self, s, queries): - """ - :type s: str - :type queries: List[List[int]] - :rtype: List[bool] - """ - alphabet = set(s) - dic = dict() - for char in alphabet: - dic[char] = [0 for _ in range(len(s))] - - for i, ch in enumerate(s): - for char in alphabet: - if ch == char: - if i > 0: - dic[ch][i] = dic[ch][i - 1] + 1 - else: - dic[ch][i] = 1 - else: - if i > 0: - dic[char][i] = dic[char][i - 1] - res = [] - for left, right, k in queries: - odd_cnt = 0 - for char in alphabet: - # print char, dic[char], left, right - if left > 0: - if (dic[char][right] - dic[char][left - 1]) % 2 == 1: - odd_cnt += 1 - else: - if dic[char][right] % 2 == 1: - odd_cnt += 1 - if odd_cnt // 2 <= k: - res.append(True) - else: - res.append(False) - return res - diff --git "a/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" "b/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" deleted file mode 100644 index 76fc5ab..0000000 --- "a/5176.\347\214\234\345\255\227\350\260\234/5176-\347\214\234\345\255\227\350\260\234.py" +++ /dev/null @@ -1,27 +0,0 @@ -class Solution(object): - def findNumOfValidWords(self, words, puzzles): - """ - :type words: List[str] - :type puzzles: List[str] - :rtype: List[int] - """ - from collections import Counter - for i in range(len(words)): - words[i] = "".join(sorted(set(words[i]))) - record = Counter(words) #统计每种pattern出现的频率 - - res = [] - for p in puzzles: - bfs = [p[0]] #固定首字母 - for char in p[1:]: - bfs += [s + char for s in bfs] #生成64种可能 - cnt = 0 - for combination in bfs: - tmp = "".join(sorted(combination)) - if tmp in record: #看看当前pattern在words里有没有出现过 - cnt += record[tmp] - res.append(cnt) - return res - - - \ No newline at end of file diff --git "a/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" "b/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" deleted file mode 100644 index d59b097..0000000 --- "a/5189.\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217/5189-\342\200\234\346\260\224\347\220\203\342\200\235\347\232\204\346\234\200\345\244\247\346\225\260\351\207\217.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def maxNumberOfBalloons(self, text): - """ - :type text: str - :rtype: int - """ - dic = collections.Counter(text) - #balloon - min_count = 99999999 - for char in "balon": - tmp = dic[char] - if char in "lo": - tmp /= 2 - min_count = min(min_count, tmp) - return min_count \ No newline at end of file diff --git "a/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" "b/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" deleted file mode 100644 index 3ad2040..0000000 --- "a/5190.\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262/5190-\345\217\215\350\275\254\346\257\217\345\257\271\346\213\254\345\217\267\351\227\264\347\232\204\345\255\220\344\270\262.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def reverseParentheses(self, s): - """ - :type s: str - :rtype: str - """ - if not s or ")" not in s: - return s - stack = [] - for i, char in enumerate(s): - if char == "(": - stack.append(i) - elif char == ")": - left = stack.pop() - right = i - return self.reverseParentheses(s[:left] + s[left + 1:right][::-1] + s[right + 1:]) - \ No newline at end of file diff --git "a/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" "b/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" deleted file mode 100644 index 6706434..0000000 --- "a/5191.K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214/5191-K\346\254\241\344\270\262\350\201\224\345\220\216\346\234\200\345\244\247\345\255\220\346\225\260\347\273\204\344\271\213\345\222\214.py" +++ /dev/null @@ -1,36 +0,0 @@ -class Solution(object): - def kConcatenationMaxSum(self, arr, k): - """ - :type arr: List[int] - :type k: int - :rtype: int - """ - if max(arr) < 0: - return 0 - if sum(arr) > 0: - res = sum(arr) * (k - 2) - dp = [0] * len(arr) - dp[0] = arr[0] - for i in range(1,len(arr)): - dp[i] = dp[i - 1] + arr[i] - - res += max(dp) - dp = [0] * len(arr) - dp[-1] = arr[-1] - for i in range(len(arr) - 2, -1, -1): - dp[i] = dp[i + 1] + arr[i] - - res += max(dp) - return (res)% (10 ** 9 + 7) - - arr = arr + arr - dp = [0] * len(arr) - dp[0] = arr[0] - for i in range(1,len(arr)): - if dp[i - 1] > 0: - dp[i] = dp[i - 1] + arr[i] - else: - dp[i] = arr[i] - - return max(dp) % (10 ** 9 + 7) - \ No newline at end of file From 43d00ecc5fbb2bc166a073c22b697cbd2abe2ec2 Mon Sep 17 00:00:00 2001 From: Jiayang Wu Date: Mon, 18 Nov 2019 21:04:39 -0500 Subject: [PATCH 037/183] update --- .DS_Store | Bin 38916 -> 36868 bytes githubkey | 27 --------------------------- githubkey.pub | 1 - 3 files changed, 28 deletions(-) delete mode 100644 githubkey delete mode 100644 githubkey.pub diff --git a/.DS_Store b/.DS_Store index f6c8d190892599e1f476613744d4dcdcb1475e9d..c0b969504bf5e164d7b15e2589dcc6f4eb95b296 100644 GIT binary patch delta 176 zcmZqKz|^vUNtl6wfzhcn#gKua1IXk6;*N>JHjMlm1Js!(mv@*?HfRdl%)-LX!)Um9 zT}K1+7n13|}R{s|h4+?xeit}{>OpW@5I2(gs`NKcrYF=gWB>eio3LYPJX E012ZtbN~PV delta 1782 zcmZ{lTWAw$6vxjrrM4z*s?`>{1@Bfx#$4LQOTi0$Xf=*8)y6n$Drv_Fv>{`ok=5F1 z!-#>jP1B)TRPc%@KBx@)P*_Ake6xZNdtuqNuZl&~MXe9(erF~w^NpC0kmNhR`JeCq zoqtBTQl#7~ssaFJ$MJ4Az!>>hN?v36s%FM@KTvN|b5$;N)zBfWxOkp}Y1V$JdREd_ z3XR|*&yB!x<-uFhR9kPNE83fg610-Mwg7k!e9<4|8$d;&eiN{@}^Uv#dL?vptB&>gkpQRXr;J*aNk&MbemWfnvN7%XmrO+mlbFq zu#sd&_GkY+X{QmKkA{6FPYgqSKm@;@I_`3BZ^sNDu&~4#iZv$2hqE}cgd5KN8Eg`y z)TiJTgOk4wCED{1=q3Y0`h+$Jgj}I*!i><`UQG+4I~0cph#V12uS?EOD%ooTFS1uH z6mdnTWU@^?1856kBm=>v(iAcEJdNnCJh!;w1`o*@E0zhZ(bw%CQ_3NKI23;yxoKh1 z6*G&jAnR)ZR*(iBr?jjU-b*LKr!fW-GRC0iXNwRTViu~@X)o^XR2%m(T-%?_e!g(4&(F`1I7<0vG!JXZ z&@=|VvBygqU?(r7`?woNzM%YxS+!z)wM>;7oq92_1Ap;zf#yss_n^~><>C53Gp&S{ zP_*G?19r-XdY+0hH~)Jv`k#~W%#9=Wq3p;SLFyV0)>x#7DUH*nJsGp*!-MFGnT?ub@CQa_z-_5}N9tCY8X^_FqPx8-5tsDYH{Qsv@kC2Y;XYA% z@?yWwHTq~fS=3j$zq2C6=qqU}ho(!^W46tjqjJ!uvHgG8O6`WinCi@|VI10m;@@nl Wb9lF-$he(N;<6eW&TA(WyX`-LDj)^` diff --git a/githubkey b/githubkey deleted file mode 100644 index e920a2c..0000000 --- a/githubkey +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn -NhAAAAAwEAAQAAAQEArhQFBiTLIuhd0tytIH8Pfp+sjyN7poF35OSAjoLjZnj0Ht+2tZ5d -HFCySGIIJD9diZxPTXna9hcPL/7/GQcm1XeY7Dw6BgxiECkQPhhbdCbIGx9Ykh8ihBVduQ -z7oq7nMjYHksMZTl5NjUV2bj46e3SeqqGGTAJciRBYhgGbNjN2Tuft+on4dShhotvvXFwH -xaBrY3RvyFDr5aE5os5XD4UTRekr8M2sBIOUzYgFhLzGU8WdEwWfAj4PcaZZXI5Jrsyxob -CGHE43Ec/reB7qpYnbeoJRdE5DjTnUCmx7f5VqvFrWJtVcIruxhJRmlU/eOfl0TSBrVYcf -byygOpcu7wAAA8gWXF7jFlxe4wAAAAdzc2gtcnNhAAABAQCuFAUGJMsi6F3S3K0gfw9+n6 -yPI3umgXfk5ICOguNmePQe37a1nl0cULJIYggkP12JnE9Nedr2Fw8v/v8ZBybVd5jsPDoG -DGIQKRA+GFt0JsgbH1iSHyKEFV25DPuirucyNgeSwxlOXk2NRXZuPjp7dJ6qoYZMAlyJEF -iGAZs2M3ZO5+36ifh1KGGi2+9cXAfFoGtjdG/IUOvloTmizlcPhRNF6SvwzawEg5TNiAWE -vMZTxZ0TBZ8CPg9xpllcjkmuzLGhsIYcTjcRz+t4Huqlidt6glF0TkONOdQKbHt/lWq8Wt -Ym1Vwiu7GElGaVT945+XRNIGtVhx9vLKA6ly7vAAAAAwEAAQAAAQBUhF3IFNcXlK/w77mS -vH3+YXH7cSPYvKVEWXjdOElF+FW2I7HmzgOw+rEEmawQRT+Zz21lVVNtBdcW23xpX2KIY+ -+4Sql1RE/cPsOnElZct3OST47GKx2r+V+ut9H4s2iGpVrZ86V2uix2+ZG9hrMIO5/JgnDc -uIzK80e3kFIWZur9tQB1rmu2t1Z18jo3AlLGqNKYsWa/c8dOEGIz9XYi684yW1DdwS7Cb7 -6mpzmWYYZhld0S6ZieDwE1gMC2FyRUVnj1n1nP1Xm5L8JeVxU6B4t+f4+S1KBp+yQ9ZDa8 -M23LONJ6gYvFQsf6ShWsOLPHgQRKAFe5cCiAV/SDyxsJAAAAgG7GAZf0ygKmyvpQHARGw9 -lw450CPy51rldOBiYRRlXmQxI1VcRJtzPYfoYRw6qXBlhjGdOwYhjn64wWo0p2nYtN45ee -AoWbsku/nBSsplMzSKzc7/RI6LZIgRWuNIClCgfyMd6ogzKsh/+ljDnhtp7+dx+jnzPEbN -a0V1mUc17SAAAAgQDTzVBBaq9v6CJQx3242JX4GUNFH3DbUju3ZPV44Sp2oSZoUxIVIPlH -LR16bY5EA6Hj4rVggDSmUmjJuuyU+Ml2NRstceautGD07cMe/BZR+RNfanM11kBf2Jsrdu -RSQo0sFyK636LUJGYdwLf9DvDerh7B3BrWVzFIHrfuJnkSmwAAAIEA0md18iqJm8dOEEyq -2Fkk7XKmDDnsyJCtUs2jAV37r0EAa/eRG4SUY0R96sIl3AJnSV3v8dcwjku74veYzZAXvV -zJmiqObg59mSv6npeV96yTyknyLPfptPTNZq/2B457zWhdtKORUjgIP/qFi5AehYKo7+7j -gOGpfZ5yAGM1QD0AAAAQNTMwMDgxOTk5QHFxLmNvbQECAw== ------END OPENSSH PRIVATE KEY----- diff --git a/githubkey.pub b/githubkey.pub deleted file mode 100644 index 7f26407..0000000 --- a/githubkey.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuFAUGJMsi6F3S3K0gfw9+n6yPI3umgXfk5ICOguNmePQe37a1nl0cULJIYggkP12JnE9Nedr2Fw8v/v8ZBybVd5jsPDoGDGIQKRA+GFt0JsgbH1iSHyKEFV25DPuirucyNgeSwxlOXk2NRXZuPjp7dJ6qoYZMAlyJEFiGAZs2M3ZO5+36ifh1KGGi2+9cXAfFoGtjdG/IUOvloTmizlcPhRNF6SvwzawEg5TNiAWEvMZTxZ0TBZ8CPg9xpllcjkmuzLGhsIYcTjcRz+t4Huqlidt6glF0TkONOdQKbHt/lWq8WtYm1Vwiu7GElGaVT945+XRNIGtVhx9vLKA6ly7v 530081999@qq.com From ed63ebaa1f04dd7553a56e238451e4c74481cd5f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 18 Nov 2019 21:07:08 -0500 Subject: [PATCH 038/183] test --- "README.md\347\232\204\346\233\277\350\272\253" | Bin 0 -> 1004 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "README.md\347\232\204\346\233\277\350\272\253" diff --git "a/README.md\347\232\204\346\233\277\350\272\253" "b/README.md\347\232\204\346\233\277\350\272\253" new file mode 100644 index 0000000000000000000000000000000000000000..92d601ac7e763233cb98546ff18ab64b60eaa684 GIT binary patch literal 1004 zcmZ9KJ#W)c6o!w}6ahjaX_10hxPlIJFiDLeEd!9^q(QV$m8N1qNNMa6Q(~jU5o7|S zPQb{-0s{j-AOm7*sv28FsnPp z(PWChY~MOhzwGpS1?K)EqUQ-@!DCzp7{{P#M3t7)Y=IAm|Db)>t#+#3ouQcJ*V+xo z3%G8d)GfF{xxG$wSo}rD2`>A#qc3-Yy6^p4Z>3nUmWrnvHtLRYEf(NID#(P&&`sz* zv>!_1e5c+Y1jYXClj#wE^FRN3QjO#nUe-qZ=~n|k+W!r*U1%5j41I<6Al{#QQ|R?} zp3!tStViF_rqGUq*`kqILnARI>?_wrci3b&=QK2W!@cL6&t|iS*hhS+T64X? zZ`D=VissX6RS%Gl&vfC#FO~T|C3B3qGo{(QRn+sPoS~a%&2##E$uM-o%*_{O@^dqW zWk%lcOWYc>gTMW5U;NR8|(FAAZHgUw1cLr+L-s#CO@n9Sp8VKWxv%D;TWH z1F z9AX^2CGiyag>V}DQFsFUR(KNpPFR8Wgmd6%eQlelF7Y%Nsn902i5^N^`xMuw!2BNA UGCv1zp7{iLSOV literal 0 HcmV?d00001 From 413ec736baf1f234b409aa3b4e2830045e082e36 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 19 Nov 2019 17:33:08 -0500 Subject: [PATCH 039/183] 2019-11-19 --- ...66\345\255\220\350\212\202\347\202\271.py" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" diff --git "a/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" "b/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" new file mode 100644 index 0000000..38ea4d5 --- /dev/null +++ "b/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" @@ -0,0 +1,35 @@ +# 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 findLeaves(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import defaultdict + self.dic = defaultdict(list) + res = [] + def get_Height(node): + if not node: + return -1 + lh = get_Height(node.left) + rh = get_Height(node.right) + h = max(lh, rh) + 1 + self.dic[h].append(node.val) + return h + + get_Height(root) + # print self.dic + h = 0 + while 1: + if h not in self.dic: + break + res.append(self.dic[h]) + h += 1 + return res + \ No newline at end of file From 90cb0fa8900cdc950994a51e67ab4d6349ba5aa7 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 24 Nov 2019 22:36:28 -0500 Subject: [PATCH 040/183] 2019-11-24 --- ...70\345\272\217\346\216\222\346\225\260.py" | 20 +++++++++++ ...05\345\205\203\347\264\240\345\222\214.py" | 33 +++++++++++++++++++ ...71\346\236\234\346\225\260\351\207\217.py" | 13 ++++++++ ...54\345\205\261\345\205\203\347\264\240.py" | 13 ++++++++ ...00\345\260\217\346\227\266\351\227\264.py" | 18 ++++++++++ ...04\346\234\215\345\212\241\345\231\250.py" | 29 ++++++++++++++++ ...50\350\215\220\347\263\273\347\273\237.py" | 21 ++++++++++++ ...04\346\226\271\346\241\210\346\225\260.py" | 23 +++++++++++++ 8 files changed, 170 insertions(+) create mode 100644 "0386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/0386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.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.py" create mode 100644 "1196.\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217/1196-\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217.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.py" create mode 100644 "1266.\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264/1266-\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264.py" create mode 100644 "1267.\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250/1267-\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250.py" create mode 100644 "1268.\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237/1268-\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237.py" create mode 100644 "1269.\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260/1269-\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260.py" diff --git "a/0386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/0386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" "b/0386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/0386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" new file mode 100644 index 0000000..140f172 --- /dev/null +++ "b/0386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/0386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" @@ -0,0 +1,20 @@ +class Solution(object): + def lexicalOrder(self, n): + """ + :type n: int + :rtype: List[int] + """ + return sorted(range(1, n + 1), key = str) +# res = [] + +# def dfs(k): +# if k > n: +# return +# res.append(k) + +# for i in range(10): +# dfs(10 * k + i) + +# for i in range(1, 10): +# dfs(i) +# 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.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.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.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/1196.\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217/1196-\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217.py" "b/1196.\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217/1196-\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217.py" new file mode 100644 index 0000000..a974399 --- /dev/null +++ "b/1196.\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217/1196-\346\234\200\345\244\232\345\217\257\344\273\245\344\271\260\345\210\260\347\232\204\350\213\271\346\236\234\346\225\260\351\207\217.py" @@ -0,0 +1,13 @@ +class Solution(object): + def maxNumberOfApples(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + arr.sort() + s = 0 + for i, num in enumerate(arr): + if s + num > 5000: + return i + s += num + return len(arr) \ 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.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.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.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/1266.\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264/1266-\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264.py" "b/1266.\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264/1266-\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264.py" new file mode 100644 index 0000000..a147831 --- /dev/null +++ "b/1266.\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264/1266-\350\256\277\351\227\256\346\211\200\346\234\211\347\202\271\347\232\204\346\234\200\345\260\217\346\227\266\351\227\264.py" @@ -0,0 +1,18 @@ +class Solution(object): + def minTimeToVisitAllPoints(self, points): + """ + :type points: List[List[int]] + :rtype: int + """ + def helper(pair1, pair2): + x0, y0 = pair1[0], pair1[1] + x1, y1 = pair2[0], pair2[1] + + return max(abs(y1 - y0), abs(x1 - x0)) + + res = 0 + for i, point in enumerate(points): + if i > 0: + res += helper(point, points[i - 1]) + + return res \ No newline at end of file diff --git "a/1267.\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250/1267-\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250.py" "b/1267.\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250/1267-\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250.py" new file mode 100644 index 0000000..87cae9f --- /dev/null +++ "b/1267.\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250/1267-\347\273\237\350\256\241\345\217\202\344\270\216\351\200\232\344\277\241\347\232\204\346\234\215\345\212\241\345\231\250.py" @@ -0,0 +1,29 @@ +class Solution(object): + def countServers(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + + m, n = len(grid), len(grid[0]) + res = 0 + for i in range(m): + for j in range(n): + if grid[i][j] == 1: + # horizontal + for col in range(n): + if col != j: + if grid[i][col] in [1, 2]: + grid[i][j] = 2 + grid[i][col] = 2 + + # vertical + for row in range(m): + if row != i: + if grid[row][j] in [1, 2]: + grid[i][j] = 2 + grid[row][j] = 2 + if grid[i][j] == 2: + res += 1 + # print grid + return res \ No newline at end of file diff --git "a/1268.\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237/1268-\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237.py" "b/1268.\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237/1268-\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237.py" new file mode 100644 index 0000000..34f7fa4 --- /dev/null +++ "b/1268.\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237/1268-\346\220\234\347\264\242\346\216\250\350\215\220\347\263\273\347\273\237.py" @@ -0,0 +1,21 @@ +class Solution(object): + def suggestedProducts(self, products, searchWord): + """ + :type products: List[str] + :type searchWord: str + :rtype: List[List[str]] + """ + products.sort() + res = [] + prefix = "" + for char in searchWord: + tmp = [] + prefix += char + idx = bisect.bisect_left(products, prefix) # 鎵惧綋鍓峱refix 璧风偣锛屽洜涓烘湁搴忔墍浠ヤ簩鍒 + for word in products[idx:]: + if len(tmp) >= 3 or word[:len(prefix)] > prefix: + break + if word[:len(prefix)] == prefix: + tmp.append(word) + res.append(tmp) + return res \ No newline at end of file diff --git "a/1269.\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260/1269-\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260.py" "b/1269.\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260/1269-\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260.py" new file mode 100644 index 0000000..a11472a --- /dev/null +++ "b/1269.\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260/1269-\345\201\234\345\234\250\345\216\237\345\234\260\347\232\204\346\226\271\346\241\210\346\225\260.py" @@ -0,0 +1,23 @@ +class Solution(object): + def numWays(self, steps, arrLen): + """ + :type steps: int + :type arrLen: int + :rtype: int + """ + # dp[i][j] 浠h〃璧 i 姝ワ紝鍒颁綅缃 j 鐨勮В + # dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1] + n = min(steps, arrLen) + dp = [[0 for _ in range(n)] for _ in range(steps + 1)] + mod = 10 ** 9 + 7 + + dp[0][0] = 1 + for i in range(1, steps + 1): + for j in range(n): + if j == 0: + dp[i][j] += (dp[i - 1][0] + dp[i - 1][1]) % mod + elif j == n - 1: + dp[i][j] += (dp[i - 1][j] + dp[i - 1][j - 1]) % mod + else: + dp[i][j] += (dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1]) % mod + return dp[steps][0] \ No newline at end of file From 11153bd217bf2a606b3f34d6e139694b133db4c9 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 1 Dec 2019 22:44:08 -0500 Subject: [PATCH 041/183] 2019-12-01 --- ...04\350\216\267\350\203\234\350\200\205.py" | 48 +++++++++++++++++++ ...66\344\275\234\346\226\271\346\241\210.py" | 16 +++++++ ...42\345\255\220\347\237\251\351\230\265.py" | 25 ++++++++++ 3 files changed, 89 insertions(+) create mode 100644 "1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" create mode 100644 "1276.\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210/1276-\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210.py" create mode 100644 "1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" diff --git "a/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" new file mode 100644 index 0000000..26dfeca --- /dev/null +++ "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" @@ -0,0 +1,48 @@ +class Solution(object): + def tictactoe(self, moves): + """ + :type moves: List[List[int]] + :rtype: str + """ + grid = [[-1 for _ in range(3)] for _ in range(3)] + def check(): + for row in grid: + if row == [0, 0, 0]: + return 0 + if row == [1, 1, 1]: + return 1 + + for j in range(3): + tmp = [] + for i in range(3): + tmp.append(grid[i][j]) + if tmp == [0, 0, 0]: + return 0 + if tmp == [1, 1, 1]: + return 1 + + tmp = [grid[0][0], grid[1][1], grid[2][2]] + if tmp == [0, 0, 0]: + return 0 + if tmp == [1, 1, 1]: + return 1 + + tmp = [grid[2][0], grid[1][1], grid[0][2]] + if tmp == [0, 0, 0]: + return 0 + if tmp == [1, 1, 1]: + return 1 + return -1 + + + player = 0 + for move in moves: + grid[move[0]][move[1]] = player + player = 1 - player + + tmp = check() + if tmp != -1: + return "A" if tmp == 0 else "B" + return "Draw" if len(moves) == 9 else "Pending" + + \ No newline at end of file diff --git "a/1276.\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210/1276-\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210.py" "b/1276.\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210/1276-\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210.py" new file mode 100644 index 0000000..a7cc96c --- /dev/null +++ "b/1276.\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210/1276-\344\270\215\346\265\252\350\264\271\345\216\237\346\226\231\347\232\204\346\261\211\345\240\241\345\210\266\344\275\234\346\226\271\346\241\210.py" @@ -0,0 +1,16 @@ +class Solution(object): + def numOfBurgers(self, tomatoSlices, cheeseSlices): + """ + :type tomatoSlices: int + :type cheeseSlices: int + :rtype: List[int] + """ + doublex = tomatoSlices - cheeseSlices * 2 + if doublex < 0 or doublex % 2 != 0: + return [] + + x = doublex // 2 + y = cheeseSlices - doublex // 2 + if x >= 0 and y >= 0: + return [x, y] + return [] \ No newline at end of file diff --git "a/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" "b/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" new file mode 100644 index 0000000..97751f9 --- /dev/null +++ "b/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" @@ -0,0 +1,25 @@ +class Solution(object): + def countSquares(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: int + """ + m, n = len(matrix), len(matrix[0]) + res = 0 + dp = [[0 for _ in range(n)] for _ in range(m)] + for i in range(m): + dp[i][0] = matrix[i][0] + res += dp[i][0] + + for j in range(1, n): + dp[0][j] = matrix[0][j] + res += dp[0][j] + + for i in range(1, m): + for j in range(1, n): + if matrix[i][j]: + dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) + 1 + res += dp[i][j] + print dp + return res + \ No newline at end of file From b3f1573a14230f774f00bcb9396eddbaeaac154e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 3 Dec 2019 20:42:47 -0500 Subject: [PATCH 042/183] 2019-12-03 --- ...60\345\244\264\345\234\260\347\202\271.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "0296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/0296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" diff --git "a/0296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/0296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" "b/0296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/0296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" new file mode 100644 index 0000000..e602a1f --- /dev/null +++ "b/0296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/0296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" @@ -0,0 +1,29 @@ +class Solution(object): + def minTotalDistance(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + if not grid or not grid[0]: + return -1 + + m, n = len(grid), len(grid[0]) + row, col = [], [] + for i in range(m): + for j in range(n): + if grid[i][j]: + row.append(i) + col.append(j) + meet_point = [self.findMedian(row), self.findMedian(col)] + + res = 0 + for i in range(m): + for j in range(n): + if grid[i][j]: + res += abs(i - meet_point[0]) + abs(j - meet_point[1]) + return res + + + def findMedian(self, nums): + nums.sort() + return nums[len(nums) // 2] From 03696c4bb18f1030682ffe7cdcc5ac25fb1ead51 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 4 Dec 2019 23:53:03 -0500 Subject: [PATCH 043/183] 2019-12-04 --- ...25\347\210\206\346\260\224\347\220\203.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" diff --git "a/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" "b/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" new file mode 100644 index 0000000..64b8736 --- /dev/null +++ "b/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" @@ -0,0 +1,20 @@ +class Solution(object): + def findMinArrowShots(self, points): + """ + :type points: List[List[int]] + :rtype: int + """ + if not points or not points[0]: + return 0 + + points.sort(key = lambda x:x[1]) + + arrow = points[0][1] + + res = 1 + for point in points: + if arrow < point[0]: + res += 1 + arrow = point[1] + + return res \ No newline at end of file From 8dbdc4897aa80776d24442a2aaba4db233ecf0ff Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 9 Dec 2019 10:31:05 -0500 Subject: [PATCH 044/183] 2019-12-09 --- .DS_Store | Bin 36868 -> 40964 bytes ...42\345\255\220\347\237\251\351\230\265.py" | 30 ++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.DS_Store b/.DS_Store index c0b969504bf5e164d7b15e2589dcc6f4eb95b296..5f8901c500e3a3ec6b435b94efe09d6029609d3f 100644 GIT binary patch delta 3970 zcmc&%eQZN+&4&pe8W5*#tfDYo4yx4xu7d8pldDttVxP+N+ zzZ8r}m5`8J!pEoth_be;HX*%Dh_-?XZERz0w^9vNYF8)%6)`^6f!JEMvUBbWo8Ke* zdx_#Cdgph~`TfqvJuh`smwHcUC4_K`e$-V?$U*qi06zzZt+jnMW5Zl7i_ThJ$r!QZK2EH^(LS|pL? zr_DdXzrLfVZ&k2$>kPg^eK<;?!kNc#z+|gu#T_y3pTw6+HSOhzlo$`TYS5s=f6xt> zi<~jIo7jS{L`Is5`+qK8-;$$-k+}dnm!^i1p(-)q;lq(ro4PybG`m$&*<_E|FhcxW zE57tC^B-29%T4+p=R##jBz`(Pk94o!z z#IezTcJvN*ef)GHg<@5FyH+=yIi#ZmCNeLiK+C4T4xDIT4An0qSQqEzIiZAMgAkj((Bm-iMAH*TFFxQFRSbygi1{9@L2 zy;V8U$!2eEz_jOXXNr35MfiNi9IKxGt1NH0cRII(ZYz74T6HzD*}jCM&y*XoK>wBD z_FOurd@{A~&OpTTONgi;m(t*T?b>PvY z0pxC$tiiTujo+yW29jKPNxtg-Oi%w>_B0apP~H4>bFB>Tf=?SiU5xX~0t3XuzDvb; zC!WK0E6XgiV$-0dkix}@u zxDD`H+Np23A2BvH@_8BvsNe|Dn+uOyF|~+*Vh)(1DV(EpZ%Kg;PTaA`mregtY~hy5 zhQ`}EI;dMf&E6~dMh0Ou9LtQE*Y2PtmI8+(kk*rrO`wUprUV}ba{0H_5nuu#f@|K* zGZkC5)^siLzY!Vf7*g9Zf)}aZcU(jvFqaT5KOp=L`#qM=mnKpNw{#2z@{(U_kjV35 zT3m)PJY=-(5T7@CLv4?}?zl*A`WB2S36d*il}I(0@kDyocSwVP+ymk}{y(v*dy%#ki{C(f{#ndpQ4o(iP z*vgzB3PS=K!abqpi8~8egA+r?HI9C$tD@$WH`o}$tpqB*+p{`v&!0EHL+3k+oX&HmqsQFk)U^IN4yF6if-s4lhgI-s9HTBgYFg zuq3=v?)3_J-s7EVhG@rSjE{PZ{Vuy_24mCdh@ohqElG zvGSCCPNy66HL}TaLRX3F1gZ!%+!+pA#`Z*5MmFBYTS`M3$^e}GWa3AhgrR`&?K5Mp z=p5WcG^U`Bt3EBaSg4eXfomiH)*3&&v z^%e*{0B?b@f^9l0sImcGKaK)XlS26*HTTWRgn#ztz-#KqdTJhMrm=xx>HikI5<7;6 Nudx3O-taj1e*?%aj$i-) delta 538 zcmZWmT}YE*6n@|L`{rKV=yMIdSQL>W2`lDk`B|1Sons+0%*_>HmczQ3H5Se&GcR`W z_5bOEV6c9mcH?E|LWBx~=%R~If}+cQ2v%1@7nOm%?zVGyI1ilj9L`T+Sri@#FJp{{ z$I~s0S&B*pYsTANXDCw5SS@3w^1TCcC?9VmkN%h=P}ChxmDX`1aELq58}8s$_}$;Z zowzg_;u5zeTG3#cyasOj0RCK0l1FMfIi)Un3-#C~LCtv0>F(T^z*{Xy?%EQkvS)>3 zn{OC@PZ_lA^Ek-0GgU?Rnog?n=A1^WeyPDLdSC>mRM8e5rB{I%r${j9z*6fzG?+o$ zG#7BcP11N!;UUuH$O6KNKSmCP_>B?}FyXSGOThjB$;Tn{LNygFd z0&9KsJciJ*FPI!SkLiR&W5TXPf6@;-`3Cl&Ih$%nHua329&gggH}sj~lL(+|I7j8- z_X6u9S$dfM$gBG|D#lo)?GY@D{-BMsD>^yGehJiR`^m`e5Og}%t79$ypt4wuUQ9#; zLYKc`@XA-ZI614KPgB!P*UQcG2)2t-))OZzExg@2moLQk%>A5tmtBfwE{vSXsOPv8 ilvyz5cXO9|+y@OtF`;wDY@~}b6uG@9HsxFYm;VD30>PyK diff --git "a/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" "b/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" index 97751f9..4115102 100644 --- "a/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" +++ "b/1277.\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265/1277-\347\273\237\350\256\241\345\205\250\344\270\2721\347\232\204\346\255\243\346\226\271\345\275\242\345\255\220\347\237\251\351\230\265.py" @@ -4,22 +4,26 @@ def countSquares(self, matrix): :type matrix: List[List[int]] :rtype: int """ + if not matrix or not matrix[0]: + return 0 + m, n = len(matrix), len(matrix[0]) - res = 0 dp = [[0 for _ in range(n)] for _ in range(m)] - for i in range(m): - dp[i][0] = matrix[i][0] - res += dp[i][0] - - for j in range(1, n): - dp[0][j] = matrix[0][j] - res += dp[0][j] - + + res = 0 + for j in range(n): + if matrix[0][j]: + res += 1 + dp[0][j] = 1 + + for i in range(1, m): + if matrix[i][0]: + res += 1 + dp[i][0] = 1 + for i in range(1, m): for j in range(1, n): if matrix[i][j]: - dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) + 1 + dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1 res += dp[i][j] - print dp - return res - \ No newline at end of file + return res \ No newline at end of file From c676bbaa99643fedc100a11c434f91ce6df7b573 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 19 Dec 2019 22:41:05 -0500 Subject: [PATCH 045/183] 2019-12-19 --- ...55\345\255\220\346\225\260\347\273\204.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "0581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/0581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" diff --git "a/0581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/0581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" "b/0581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/0581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..33bc985 --- /dev/null +++ "b/0581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/0581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,19 @@ +class Solution(object): + def findUnsortedSubarray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + s = sorted(nums) + if s == nums: + return 0 + for i in range(len(s)): + if s[i] != nums[i]: + break + for j in range(len(s) - 1, -1, -1): + if s[j] != nums[j]: + break + # print i, j + # print s, nums + return len(s) - i - (len(s) - 1 -j) + \ No newline at end of file From c7a5eb780249aadbe5122b37a2fc6c7bffd05da0 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 6 Jan 2020 22:36:38 -0500 Subject: [PATCH 046/183] 2020-01-06 --- ...00\351\225\277\345\261\261\350\204\211.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "0845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/0845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" diff --git "a/0845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/0845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" "b/0845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/0845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" new file mode 100644 index 0000000..970933d --- /dev/null +++ "b/0845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/0845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" @@ -0,0 +1,24 @@ +class Solution(object): + def longestMountain(self, A): + """ + :type A: List[int] + :rtype: int + """ + # a = sorted(A) + # if a == A or a[::-1] == A: + # return 0 + l, r = [0 for _ in A], [0 for _ in A] + + for i in range(1, len(A)): + if A[i] > A[i - 1]: + l[i] = l[i - 1] + 1 + + for i in range(len(A) - 2, -1, -1): + if A[i] > A[i + 1]: + r[i] = r[i + 1] + 1 + + res = 0 + for i in range(len(A)): + if l[i] and r[i] and l[i] + r[i] > 1: + res = max(l[i] + r[i] + 1, res) + return res \ No newline at end of file From ac06b239caaefe601dd6ae97dc951e27dde18f1d Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 7 Jan 2020 23:44:58 -0500 Subject: [PATCH 047/183] 2020-01-07 --- ...55\345\272\217\351\201\215\345\216\206.py" | 29 +++++++---------- ...15\345\272\217\351\201\215\345\216\206.py" | 11 ++----- ...16\345\272\217\351\201\215\345\216\206.py" | 9 ++---- ...15\345\272\217\351\201\215\345\216\206.py" | 16 ++++------ ...16\345\272\217\351\201\215\345\216\206.py" | 9 +++--- ...55\347\232\204\346\220\234\347\264\242.py" | 14 +++----- ...11\346\240\221\345\211\252\346\236\235.py" | 11 +++---- ...40\344\272\214\345\217\211\346\240\221.py" | 32 ++++--------------- 8 files changed, 44 insertions(+), 87 deletions(-) diff --git "a/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/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" index 8759161..4468435 100644 --- "a/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/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" @@ -11,21 +11,16 @@ def inorderTraversal(self, root): :type root: TreeNode :rtype: List[int] """ - result = list() - self.generate(root, result) - return result + stack = [] + cur = root + res = [] + while cur or stack: + if cur: + stack.append(cur) + cur = cur.left + else: + cur = stack.pop() + res.append(cur.val) + cur = cur.right + return res - - - def generate(self, root, result): - - if not root: - return - - if root.left: - self.generate(root.left, result) - - result.append(root.val) - - if root.right: - self.generate(root.right, result) diff --git "a/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/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" index faad066..a36db20 100644 --- "a/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/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" @@ -11,17 +11,12 @@ def preorderTraversal(self, root): :type root: TreeNode :rtype: List[int] """ - if not root: - return [] stack = [root] res = [] while stack: cur = stack.pop() - res.append(cur.val) - - if cur.right: + if cur: + res.append(cur.val) stack.append(cur.right) - if cur.left: stack.append(cur.left) - return res - \ No newline at end of file + return res \ No newline at end of file diff --git "a/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/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" index 5b5c4eb..e16d813 100644 --- "a/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/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" @@ -11,17 +11,12 @@ def postorderTraversal(self, root): :type root: TreeNode :rtype: List[int] """ - if not root: - return [] - stack = [root] res = [] while stack: cur = stack.pop() - res.append(cur.val) - if cur.left: + if cur: + res.append(cur.val) stack.append(cur.left) - if cur.right: stack.append(cur.right) - return res[::-1] \ 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.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.py" index 35e21d7..d6ef697 100644 --- "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.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.py" @@ -1,7 +1,7 @@ """ # Definition for a Node. class Node(object): - def __init__(self, val, children): + def __init__(self, val=None, children=None): self.val = val self.children = children """ @@ -12,11 +12,9 @@ def preorder(self, root): :rtype: List[int] """ if not root: - return list() - result = list() - result.append(root.val) - - for leaf in root.children: - result += self.preorder(leaf) - - return result \ No newline at end of file + 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.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.py" index 0e1515b..bd35385 100644 --- "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.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.py" @@ -1,7 +1,7 @@ """ # Definition for a Node. class Node(object): - def __init__(self, val, children): + def __init__(self, val=None, children=None): self.val = val self.children = children """ @@ -13,8 +13,7 @@ def postorder(self, root): """ if not root: return [] - res = list() - for leaf in root.children: - res += self.postorder(leaf) - + res = [] + for child in root.children: + res += self.postorder(child) return res + [root.val] \ 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.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.py" index 0a76293..6576874 100644 --- "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.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.py" @@ -12,14 +12,10 @@ def searchBST(self, root, val): :type val: int :rtype: TreeNode """ - # print root.val - if not root: - return None - if root.val == val: + if not root or root.val == val: return root - elif root.val > val: + + if root.val > val: return self.searchBST(root.left, val) - else: - return self.searchBST(root.right, val) - - \ No newline at end of file + elif root.val < val: + return self.searchBST(root.right, val) \ No newline at end of file diff --git "a/0814.\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/0814-\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235.py" "b/0814.\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/0814-\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235.py" index 2cefde6..c33fe84 100644 --- "a/0814.\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/0814-\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235.py" +++ "b/0814.\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235/0814-\344\272\214\345\217\211\346\240\221\345\211\252\346\236\235.py" @@ -12,12 +12,9 @@ def pruneTree(self, root): :rtype: TreeNode """ if not root: - return None - # print root.val, self.generate(root.left), self.generate(root.right) + return None root.left = self.pruneTree(root.left) root.right = self.pruneTree(root.right) - if root.left == None and root.right == None and (root.val == 0): - return None - return root - - + if not root.left and not root.right and not root.val: + root = None + return root \ No newline at end of file diff --git "a/1008.\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/1008-\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" "b/1008.\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/1008-\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" index 0f52525..73d41dc 100644 --- "a/1008.\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/1008-\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" +++ "b/1008.\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221/1008-\345\205\210\345\272\217\351\201\215\345\216\206\346\236\204\351\200\240\344\272\214\345\217\211\346\240\221.py" @@ -11,30 +11,12 @@ def bstFromPreorder(self, preorder): :type preorder: List[int] :rtype: TreeNode """ - inorder = sorted(preorder) - - return self.buildTree(preorder, inorder) - - - - def buildTree(self, preorder, inorder): # leetcode 105 - """ - :type preorder: List[int] - :type inorder: List[int] - :rtype: TreeNode - """ if not preorder: - return None - - root = TreeNode(preorder[0]) - left_inorder = inorder[: inorder.index(root.val)] - right_inorder = inorder[inorder.index(root.val) + 1 :] - - l_left = len(left_inorder) - left_preorder = preorder[1:l_left + 1] - right_preorder = preorder[l_left + 1 :] - - root.left = self.buildTree(left_preorder, left_inorder) - root.right = self.buildTree(right_preorder, right_inorder) - + return None + inorder = sorted(preorder) + + idx = inorder.index(preorder[0]) + root = TreeNode(preorder[0]) + root.left = self.bstFromPreorder(preorder[1:idx + 1]) + root.right = self.bstFromPreorder(preorder[idx + 1:]) return root \ No newline at end of file From 15d923f3236a3022a04b57991af5b7d341c446df Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 8 Jan 2020 21:45:01 -0500 Subject: [PATCH 048/183] 2020-01-08 --- ...55\345\272\217\351\201\215\345\216\206.py" | 13 +++-- ...11\346\220\234\347\264\242\346\240\221.py" | 11 ++-- ...00\344\270\272\351\223\276\350\241\250.py" | 18 +++---- ...16\345\272\217\351\201\215\345\216\206.py" | 9 ++-- ...21\350\277\255\344\273\243\345\231\250.py" | 23 ++++---- ...17\347\232\204\345\205\203\347\264\240.py" | 20 ++++--- ...66\345\255\220\350\212\202\347\202\271.py" | 53 ++++++++++++------- ...13\350\247\222\347\232\204\345\200\274.py" | 31 +++++------ ...00\345\244\247\346\267\261\345\272\246.py" | 11 ++-- ...22\345\205\245\346\223\215\344\275\234.py" | 49 ++++++++++------- ...74\344\272\214\345\217\211\346\240\221.py" | 21 ++------ 11 files changed, 144 insertions(+), 115 deletions(-) diff --git "a/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/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" index 4468435..7820957 100644 --- "a/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/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" @@ -11,16 +11,15 @@ def inorderTraversal(self, root): :type root: TreeNode :rtype: List[int] """ - stack = [] - cur = root - res = [] + if not root: + return [] + cur, stack, res = root, [], [] while cur or stack: if cur: stack.append(cur) - cur = cur.left + cur = cur.left else: cur = stack.pop() res.append(cur.val) - cur = cur.right - return res - + cur = cur.right + return res \ 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.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.py" index 0a3ba57..da3ec6e 100644 --- "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.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.py" @@ -13,8 +13,11 @@ def sortedArrayToBST(self, nums): """ if not nums: return None - l = len(nums) - root = TreeNode(nums[l // 2]) - root.left = self.sortedArrayToBST(nums[:l//2]) - root.right = self.sortedArrayToBST(nums[l//2 + 1:]) + 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/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/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" index ffd37d4..8858e81 100644 --- "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.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.py" @@ -12,16 +12,16 @@ def flatten(self, root): :rtype: None Do not return anything, modify root in-place instead. """ if not root: - return None - if not root.left and not root.right: return root - self.flatten(root.left) self.flatten(root.right) - ltree, rtree = root.left, root.right - root.right = ltree + + tmp = root.right + root.right = root.left root.left = None - p = root - while p.right: - p = p.right - p.right = rtree \ No newline at end of file + + node = root + while node.right: + node = node.right + node.right = tmp + \ No newline at end of file diff --git "a/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/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" index e16d813..17c5fa8 100644 --- "a/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/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" @@ -11,12 +11,15 @@ def postorderTraversal(self, root): :type root: TreeNode :rtype: List[int] """ - stack = [root] - res = [] + # left right mid + # mid right left [::-1] + stack, res = [root], [] while stack: cur = stack.pop() if cur: res.append(cur.val) stack.append(cur.left) stack.append(cur.right) - return res[::-1] \ No newline at end of file + return res[::-1] + + \ No newline at end of file diff --git "a/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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" index b38a445..9654043 100644 --- "a/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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/0173.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/0173-\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" @@ -11,27 +11,32 @@ def __init__(self, root): """ :type root: TreeNode """ + self.stack = [] + self.cur = root - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - self.l = inorder(root) - self.idx = 0 def next(self): """ @return the next smallest number :rtype: int """ - self.idx += 1 - return self.l[self.idx - 1] + while self.cur or self.stack: + if self.cur: + self.stack.append(self.cur) + self.cur = self.cur.left + else: + self.cur = self.stack.pop() + res = self.cur.val + self.cur = self.cur.right + + return res + def hasNext(self): """ @return whether we have a next smallest number :rtype: bool """ - return self.idx < len(self.l) + return self.cur or self.stack # Your BSTIterator object will be instantiated and called as such: 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.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.py" index 38f00e9..bff7e15 100644 --- "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.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.py" @@ -12,11 +12,15 @@ def kthSmallest(self, root, k): :type k: int :rtype: int """ - - def inorderTraversal(node): - if not node: - return [] - return inorderTraversal(node.left) + [node.val] + inorderTraversal(node.right) - - l = inorderTraversal(root) - return l[k - 1] \ No newline at end of file + 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/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" "b/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" index 38ea4d5..3bb10d6 100644 --- "a/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" +++ "b/0366.\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/0366-\345\257\273\346\211\276\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" @@ -11,25 +11,40 @@ def findLeaves(self, root): :type root: TreeNode :rtype: List[List[int]] """ - from collections import defaultdict - self.dic = defaultdict(list) - res = [] - def get_Height(node): + from collections import defaultdict, deque + outdegree = defaultdict(int) + child2parent = {root:None} + leavesNodes = [] + def dfs(node): if not node: - return -1 - lh = get_Height(node.left) - rh = get_Height(node.right) - h = max(lh, rh) + 1 - self.dic[h].append(node.val) - return h + return + + if node.left: + outdegree[node] += 1 + child2parent[node.left] = node + dfs(node.left) + if node.right: + outdegree[node] += 1 + child2parent[node.right] = node + dfs(node.right) + + if not outdegree[node]: + leavesNodes.append(node) + dfs(root) - get_Height(root) - # print self.dic - h = 0 - while 1: - if h not in self.dic: - break - res.append(self.dic[h]) - h += 1 + res = [] + queue = deque(leavesNodes) + while queue: + tmp = [] + for _ in range(len(queue)): + cur = queue.popleft() + tmp.append(cur.val) + + parent = child2parent[cur] + outdegree[parent] -= 1 + + if not outdegree[parent]: + queue.append(parent) + res.append(tmp) return res - \ No newline at end of file + \ 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.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.py" index f677285..c9fbab3 100644 --- "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.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.py" @@ -11,18 +11,19 @@ def findBottomLeftValue(self, root): :type root: TreeNode :rtype: int """ - next_layer = [root] - while(next_layer): - temp_next_layer = [] - layer_value = [] - for node in next_layer: - if node.left: - temp_next_layer.append(node.left) - if node.right: - temp_next_layer.append(node.right) - layer_value.append(node.val) - # print layer_value - next_layer = temp_next_layer - - # print layer_value - return layer_value[0] \ No newline at end of file + #灞傚簭閬嶅巻杩斿洖鏈鍚庝竴灞傜涓涓 + 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/0559.N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0559-N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" "b/0559.N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0559-N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" index 55bc02e..eedc4c7 100644 --- "a/0559.N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0559-N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" +++ "b/0559.N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246/0559-N\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.py" @@ -1,7 +1,7 @@ """ # Definition for a Node. class Node(object): - def __init__(self, val, children): + def __init__(self, val=None, children=None): self.val = val self.children = children """ @@ -11,10 +11,9 @@ def maxDepth(self, root): :type root: Node :rtype: int """ - result = [] if not root: return 0 - for node in root.children: - result.append(self.maxDepth(node)) - - return 1 + max(result) if result else 1 \ No newline at end of file + res = 0 + for child in root.children: + res = max(res, self.maxDepth(child)) + return 1 + res \ No newline at end of file diff --git "a/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234/0701-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.py" "b/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234/0701-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.py" index b69b085..c8caff3 100644 --- "a/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234/0701-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.py" +++ "b/0701.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234/0701-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\217\222\345\205\245\346\223\215\344\275\234.py" @@ -1,22 +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 insertIntoBST(self, root, val): - """ - :type root: TreeNode - :type val: int - :rtype: TreeNode - """ if not root: - return - def helper(node, val): - if node.val < val: - if not node.right: - node.right = TreeNode(val) - else: - helper(node.right, val) - elif node.val > val: - if not node.left: - node.left = TreeNode(val) - else: - helper(node.left, val) - helper(root, val) - return root \ No newline at end of file + return TreeNode(val) + node, parent = root, root + while node: + parent = node + node = parent.left if val < parent.val else parent.right + if val > parent.val: + parent.right = TreeNode(val) + else: + parent.left = TreeNode(val) + return root +# class Solution(object): +# def insertIntoBST(self, root, val): +# """ +# :type root: TreeNode +# :type val: int +# :rtype: TreeNode +# """ +# if not root: +# return TreeNode(val) +# if root.val > val: +# root.left = self.insertIntoBST(root.left, val) +# else: +# root.right = self.insertIntoBST(root.right, val) +# return root \ No newline at end of file diff --git "a/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/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" index be1cad8..8e3f864 100644 --- "a/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/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" @@ -11,19 +11,8 @@ def isUnivalTree(self, root): :type root: TreeNode :rtype: bool """ - - self.value = root.val - self.result = True - self.generate(root) - return self.result - - def generate(self, root): - if root.val != self.value: - self.result = False - return - if not root: - return - if root.left: - self.generate(root.left) - if root.right: - self.generate(root.right) \ No newline at end of file + if not root or (not root.left and not root.right): + return True + left = not root.left or (self.isUnivalTree(root.left) and root.val == root.left.val) + right = not root.right or (self.isUnivalTree(root.right) and root.val == root.right.val) + return left and right \ No newline at end of file From efa1a3291a74bfce830378ca642389fa8a8b1055 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 9 Jan 2020 19:29:54 -0500 Subject: [PATCH 049/183] 2020-01-09 --- ...11\346\220\234\347\264\242\346\240\221.py" | 15 +++---- ...40\344\272\214\345\217\211\346\240\221.py" | 20 +++------- ...40\344\272\214\345\217\211\346\240\221.py" | 20 +++------- ...\346\254\241\351\201\215\345\216\206II.py" | 21 +++++----- ...04\345\217\263\350\247\206\345\233\276.py" | 25 +++++++----- ...02\347\202\271\344\270\252\346\225\260.py" | 29 +++++++++++--- ...02\345\272\217\351\201\215\345\216\206.py" | 33 +++++++-------- ...02\345\271\263\345\235\207\345\200\274.py" | 30 ++++++-------- ...11\346\220\234\347\264\242\346\240\221.py" | 26 ++++++++++++ ...17\346\237\245\346\211\276\346\240\221.py" | 40 +++++++++---------- ...74\344\272\214\345\217\211\346\240\221.py" | 2 +- ...06\351\205\215\347\241\254\345\270\201.py" | 19 +++------ ...11\346\240\221\345\257\273\350\267\257.py" | 12 ++++++ 13 files changed, 160 insertions(+), 132 deletions(-) create mode 100644 "0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0669-\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "1104.\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257/1104-\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257.py" diff --git "a/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" index 7ba4079..b13ef7a 100644 --- "a/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" +++ "b/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -4,11 +4,12 @@ def numTrees(self, n): :type n: int :rtype: int """ - res = [0] * (n+1) - res[0] = 1 - res[1] = 1 + dic = {0:1, 1:1} + for i in range(2, n + 1): - for j in range(i): - res[i] += res[j] * res[i-j-1] - - return res[n] \ No newline at end of file + cnt = 0 + for l in range(0, i): + cnt += dic[l] * dic[i - 1 - l] + dic[i] = cnt + + return dic[n] \ 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.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.py" index c386175..c9439fe 100644 --- "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.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.py" @@ -14,18 +14,10 @@ def buildTree(self, preorder, inorder): """ if not preorder: return None - root_val = preorder[0] - root_idx = inorder.index(root_val) - - preorder_left = preorder[1:1 + root_idx] - preorder_right = preorder[root_idx + 1:] - - inorder_left = inorder[:root_idx] - inorder_right = inorder[root_idx + 1:] - - # print preorder_left, preorder_right, inorder_left, inorder_right - root = TreeNode(root_val) - root.left = self.buildTree(preorder_left, inorder_left) - root.right = self.buildTree(preorder_right, inorder_right) - + + 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.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.py" index d20caa6..c67ac3d 100644 --- "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.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.py" @@ -13,19 +13,11 @@ def buildTree(self, inorder, postorder): :rtype: TreeNode """ if not inorder: - return None - root_val = postorder[-1] - root_idx = inorder.index(root_val) - - postorder_left = postorder[:root_idx] - postorder_right = postorder[root_idx:-1] - - inorder_left = inorder[:root_idx] - inorder_right = inorder[root_idx + 1:] - - # print preorder_left, preorder_right, inorder_left, inorder_right - root = TreeNode(root_val) - root.left = self.buildTree(inorder_left, postorder_left) - root.right = self.buildTree(inorder_right, postorder_right) + 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\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" index 35c90e7..64d7715 100644 --- "a/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" +++ "b/0107.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II/0107-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206II.py" @@ -11,16 +11,17 @@ def levelOrderBottom(self, root): :type root: TreeNode :rtype: List[List[int]] """ - queue = [root] + if not root: + return [] + from collections import deque + queue = deque([root]) res = [] while queue: - next_queue = [] layer = [] - for node in queue: - if node: - layer.append(node.val) - next_queue += [node.left, node.right] - queue = next_queue[:] - if layer: - res.append(layer[:]) - return res[::-1] \ No newline at end of file + for _ in range(len(queue)): + cur = queue.popleft() + if cur: + layer.append(cur.val) + queue += [cur.left, cur.right] + res.append(layer) + return res[:-1][::-1] \ 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.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.py" index 6a266c3..eb22eed 100644 --- "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.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.py" @@ -11,15 +11,18 @@ def rightSideView(self, root): :type root: TreeNode :rtype: List[int] """ + from collections import deque + if not root: + return [] + queue = deque([root]) res = [] - def dfs(node, depth): - if not node: - return - if depth > len(res): - res.append(node.val) - dfs(node.right, depth + 1) - dfs(node.left, depth +1) - - - dfs(root, 1) - return res \ No newline at end of file + 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/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/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" index a04b18b..58e9408 100644 --- "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.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.py" @@ -11,9 +11,26 @@ def countNodes(self, root): :type root: TreeNode :rtype: int """ - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - return len(inorder(root)) - \ No newline at end of file + if not root: + return 0 + + self.leavesCnt = 0 + self.height = 0 + self.flag = 0 + def dfs(node, layer): + if not node or self.flag: + return + if not node.left and not node.right: + + self.height = max(self.height, layer) + if layer < self.height: + self.flag = 1 + else: + self.leavesCnt += 1 + return + dfs(node.left, layer + 1) + dfs(node.right, layer + 1) + + dfs(root, 0) + # print self.leavesCnt + return self.leavesCnt + sum([2 ** i for i in range(self.height)] ) \ No newline at end of file diff --git "a/0429.N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0429-N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" "b/0429.N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0429-N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" index 94a6107..f51f86d 100644 --- "a/0429.N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0429-N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" +++ "b/0429.N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/0429-N\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206.py" @@ -1,7 +1,7 @@ """ # Definition for a Node. class Node(object): - def __init__(self, val, children): + def __init__(self, val=None, children=None): self.val = val self.children = children """ @@ -13,20 +13,17 @@ def levelOrder(self, root): """ if not root: return [] - nodes = [root] - node_val = list(list()) - self.generate(nodes, node_val) - return node_val - - def generate(self, nodes, node_val): - new_node = [] - new_node_val = [] - for node in nodes: - for leaf in node.children: - new_node.append(leaf) - new_node_val.append(node.val) - node_val.append(new_node_val) - if len(new_node) == 0: - return - self.generate(new_node, node_val) - \ No newline at end of file + from collections import deque + queue = deque([root]) + res = [] + while queue: + layer = [] + for _ in range(len(queue)): + cur = queue.popleft() + if cur: + layer.append(cur.val) + for child in cur.children: + queue.append(child) + res.append(layer) + + return res 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.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.py" index 4c4960c..0f29e9f 100644 --- "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.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.py" @@ -11,22 +11,18 @@ def averageOfLevels(self, root): :type root: TreeNode :rtype: List[float] """ + from collections import deque if not root: return [] - next_layer = [root.left, root.right] - result = [float(root.val)] - - while(next_layer): - temp_next_layer = list() - layer_value = list() - for node in next_layer: - if not node: - continue - temp_next_layer.append(node.left) - temp_next_layer.append(node.right) - layer_value.append(node.val) - if layer_value: - result.append(sum(layer_value) / float(len(layer_value))) - next_layer = temp_next_layer - return result - \ No newline at end of file + 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/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0669-\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0669-\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..b672ba5 --- /dev/null +++ "b/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0669-\344\277\256\345\211\252\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(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Solution(object): + def trimBST(self, root, L, R): + """ + :type root: TreeNode + :type L: int + :type R: int + :rtype: TreeNode + """ + if not root: + return None + + root.left = self.trimBST(root.left, L, R) + root.right = self.trimBST(root.right, L, R) + + if root.val < L: + return root.right + if root.val > R: + return root.left + return root \ No newline at end of file diff --git "a/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221.py" "b/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221.py" index 568c9c2..ccc0483 100644 --- "a/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221.py" +++ "b/0897.\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221/0897-\351\200\222\345\242\236\351\241\272\345\272\217\346\237\245\346\211\276\346\240\221.py" @@ -11,26 +11,24 @@ def increasingBST(self, root): :type root: TreeNode :rtype: TreeNode """ - preorder = list() - - def pre_order(root): - if not root: - return - pre_order(root.left) - preorder.append(root.val) - pre_order(root.right) - - pre_order(root) - dummy = TreeNode(0) - for i, node in enumerate(preorder): + if not root: + return root + new_root = TreeNode(-1) - temp = TreeNode(node) - temp.left = None - temp.right = None - if i == 0: - dummy.right = temp - cur = temp + cur, stack = root, [] + parent = None + while cur or stack: + if cur: + stack.append(cur) + cur = cur.left else: - cur.right = temp - cur = temp - return dummy.right \ No newline at end of file + cur = stack.pop() + cur.left = None + if not parent: + parent = cur + new_root.right = parent + else: + parent.right = cur + parent = cur + cur = cur.right + return new_root.right diff --git "a/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/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" index 8e3f864..b4a817e 100644 --- "a/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/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" @@ -11,7 +11,7 @@ def isUnivalTree(self, root): :type root: TreeNode :rtype: bool """ - if not root or (not root.left and not root.right): + if not root: return True left = not root.left or (self.isUnivalTree(root.left) and root.val == root.left.val) right = not root.right or (self.isUnivalTree(root.right) and root.val == root.right.val) diff --git "a/0979.\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201/0979-\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201.py" "b/0979.\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201/0979-\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201.py" index f7ee90d..0ea3ac7 100644 --- "a/0979.\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201/0979-\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201.py" +++ "b/0979.\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201/0979-\345\234\250\344\272\214\345\217\211\346\240\221\344\270\255\345\210\206\351\205\215\347\241\254\345\270\201.py" @@ -12,20 +12,13 @@ def distributeCoins(self, root): :rtype: int """ self.res = 0 - def dfs(node): if not node: - return - - if node.left: - dfs(node.left) - node.val += node.left.val - 1 - if node.right: - dfs(node.right) - node.val += node.right.val - 1 - - self.res += abs(node.val - 1) - - + return 0 + l = dfs(node.left) + r = dfs(node.right) + + self.res += abs(l) + abs(r) + return l + r + node.val - 1 dfs(root) return self.res \ No newline at end of file diff --git "a/1104.\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257/1104-\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257.py" "b/1104.\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257/1104-\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257.py" new file mode 100644 index 0000000..69e81d2 --- /dev/null +++ "b/1104.\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257/1104-\344\272\214\345\217\211\346\240\221\345\257\273\350\267\257.py" @@ -0,0 +1,12 @@ +class Solution(object): + def pathInZigZagTree(self, label): + """ + :type label: int + :rtype: List[int] + """ + res = [] + while label > 1: + res.append(label) + label >>= 1 + label = label ^(1 << (label.bit_length() - 1)) - 1 + return [1] + res[::-1] From 67b55f21a4deefe78be8b30e998681da3ba3a487 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 19 Jan 2020 23:58:25 -0500 Subject: [PATCH 050/183] 2020-01-19 --- ...00\346\234\211\350\267\257\345\276\204.py" | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) 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.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.py" index ceffca9..23bc926 100644 --- "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.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.py" @@ -12,18 +12,19 @@ def binaryTreePaths(self, root): :rtype: List[str] """ if not root: - return [] - if not root.left and not root.right: - return [str(root.val)] + 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)) - dfs(node.left, tmp + "->" + str(node.val)) - dfs(node.right, tmp + "->" + str(node.val)) - - dfs(root.left, str(root.val)) - dfs(root.right, str(root.val)) - return self.res \ No newline at end of file + 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 From 06fdad295458dad12713395e1bf52bd38efd46d3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 21 Jan 2020 02:33:06 -0500 Subject: [PATCH 051/183] 2020-01-21 --- ...02\346\254\241\351\201\215\345\216\206.py" | 24 +++++++++---------- ...67\344\272\214\345\217\211\346\240\221.py" | 21 ++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 "0951.\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221/0951-\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221.py" diff --git "a/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" index 30d1829..91b1bd7 100644 --- "a/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" +++ "b/0102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206/0102-\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.py" @@ -11,18 +11,18 @@ def levelOrder(self, root): :type root: TreeNode :rtype: List[List[int]] """ - queue = [root] + if not root: + return [] + from collections import deque + queue = deque([root]) res = [] while queue: - next_queue = [] layer = [] - for node in queue: - if node: - layer.append(node.val) - next_queue += [node.left, node.right] - queue = next_queue[:] - if layer: - res.append(layer[:]) - return res - - \ No newline at end of file + for _ in range(len(queue)): + cur = queue.popleft() + if cur: + layer.append(cur.val) + queue += [cur.left, cur.right] + res.append(layer) + return res[:-1] + \ No newline at end of file diff --git "a/0951.\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221/0951-\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221.py" "b/0951.\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221/0951-\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..de188d5 --- /dev/null +++ "b/0951.\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221/0951-\347\277\273\350\275\254\347\255\211\344\273\267\344\272\214\345\217\211\346\240\221.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 flipEquiv(self, root1, root2): + """ + :type root1: TreeNode + :type root2: TreeNode + :rtype: bool + """ + if not root1: + return root2 is None + if not root2: + return root1 is None + if root1.val != root2.val: + return False + return (self.flipEquiv(root1.left, root2.left) and self.flipEquiv(root1.right, root2.right)) or (self.flipEquiv(root1.left, root2.right) and self.flipEquiv(root1.right, root2.left)) \ No newline at end of file From 6bd9521623d81de1eea74709647f0642985cce43 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 22 Jan 2020 22:34:30 -0500 Subject: [PATCH 052/183] 2020-01-22 --- ...73\350\275\254\346\254\241\346\225\260.py" | 14 ++++ ...15\344\275\234\346\254\241\346\225\260.py" | 50 ++++++++++++++ ...23\345\215\260\345\215\225\350\257\215.py" | 26 +++++++ ...66\345\255\220\350\212\202\347\202\271.py" | 68 +++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 "1318.\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260/1318-\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260.py" create mode 100644 "1319.\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1319-\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" create mode 100644 "1324.\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215/1324-\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215.py" create mode 100644 "1325.\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/1325-\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" diff --git "a/1318.\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260/1318-\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260.py" "b/1318.\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260/1318-\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260.py" new file mode 100644 index 0000000..213c75d --- /dev/null +++ "b/1318.\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260/1318-\346\210\226\350\277\220\347\256\227\347\232\204\346\234\200\345\260\217\347\277\273\350\275\254\346\254\241\346\225\260.py" @@ -0,0 +1,14 @@ +class Solution(object): + def minFlips(self, a, b, c): + """ + :type a: int + :type b: int + :type c: int + :rtype: int + """ + res = 0 + while a or b or c: + if (a & 1 | b & 1) != (c & 1): + res += 1 + (a & 1) * (b & 1) + a, b, c = a >> 1, b >> 1, c >> 1 + return res \ No newline at end of file diff --git "a/1319.\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1319-\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" "b/1319.\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1319-\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" new file mode 100644 index 0000000..42c33d5 --- /dev/null +++ "b/1319.\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1319-\350\277\236\351\200\232\347\275\221\347\273\234\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" @@ -0,0 +1,50 @@ + +class UnionFindSet(object): + def __init__(self, n): + self.roots = [i for i in range(n)] + self.rank = [0 for i in range(n)] + 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 makeConnected(self, n, connections): + """ + :type n: int + :type connections: List[List[int]] + :rtype: int + """ + if len(connections) < n - 1: + return -1 + + res = 0 + ufs = UnionFindSet(n) + for s, e in connections: + ufs.union(s, e) + + return ufs.count - 1 + + + + \ No newline at end of file diff --git "a/1324.\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215/1324-\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215.py" "b/1324.\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215/1324-\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215.py" new file mode 100644 index 0000000..214e6c6 --- /dev/null +++ "b/1324.\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215/1324-\347\253\226\347\233\264\346\211\223\345\215\260\345\215\225\350\257\215.py" @@ -0,0 +1,26 @@ +class Solution(object): + def printVertically(self, s): + """ + :type s: str + :rtype: List[str] + """ + + l = s.split(" ") + max_l = max([len(item) for item in l]) + + res = [""] * max_l + for i in range(max_l): + tmp = "" + for j in range(len(l)): + if len(l[j]) > i: + tmp += l[j][i] + else: + tmp += " " + res[i] = tmp.rstrip() + + return res + # l = s.split(" ") + # res = [] + # for item in zip(*l): + # res.append("".join(item)) + # return res \ No newline at end of file diff --git "a/1325.\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/1325-\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" "b/1325.\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/1325-\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" new file mode 100644 index 0000000..a407dcb --- /dev/null +++ "b/1325.\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/1325-\345\210\240\351\231\244\347\273\231\345\256\232\345\200\274\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" @@ -0,0 +1,68 @@ +# 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 removeLeafNodes(self, root, target): + """ + :type root: TreeNode + :type target: int + :rtype: TreeNode + """ + if not root: + return root + root.left = self.removeLeafNodes(root.left, target) + root.right = self.removeLeafNodes(root.right, target) + if not root.left and not root.right and root.val == target: + return None + return root + +# from collections import defaultdict, deque +# if not root: +# return root +# outdegree = dict() +# parent = dict() + +# # 灞傚簭閬嶅巻棰勫鐞 +# queue = deque([root]) +# while queue: +# for _ in range(len(queue)): +# cur = queue.popleft() +# outdegree[cur] = 0 +# if cur.left: +# outdegree[cur] += 1 +# parent[cur.left] = cur +# queue.append(cur.left) +# if cur.right: +# outdegree[cur] += 1 +# parent[cur.right] = cur +# queue.append(cur.right) + +# queue = deque([]) +# for key, val in outdegree.items(): +# if not val and key.val == target: +# queue.append(key) + +# while queue: +# cur = queue.popleft() +# if cur not in parent: +# return None +# par = parent[cur] +# if par.left and par.left == cur: +# par.left = None +# outdegree[par] -= 1 +# if par.right and par.right == cur: +# par.right = None +# outdegree[par] -= 1 + +# if outdegree[par] == 0 and par.val == target: +# queue.append(par) + +# return root + + + + \ No newline at end of file From e961b904c2c82c453774253c3d32f6ff7f1a3eab Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 22 Jan 2020 22:36:04 -0500 Subject: [PATCH 053/183] 2020-01-22 --- ...31\345\244\264\346\225\260\347\233\256.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" diff --git "a/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" "b/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" new file mode 100644 index 0000000..197890e --- /dev/null +++ "b/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" @@ -0,0 +1,26 @@ +class Solution(object): + def minTaps(self, n, ranges): + """ + :type n: int + :type ranges: List[int] + :rtype: int + """ + ivls = [] + reach = [0 for _ in range(n + 1)] + for i in range(n + 1): + start, end = i - ranges[i], i + ranges[i] + end = min(end, n + 1) + start = max(start, 0) + + for j in range(start, end): + reach[j] = max(end, reach[j]) + + res = 0 + pos = 0 + while pos < n: + if reach[pos] <= pos: + return -1 + pos = reach[pos] + res += 1 + return res + \ No newline at end of file From ffe1708fb90118ef8b2a86423356e22dd2b39215 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 22 Jan 2020 22:39:26 -0500 Subject: [PATCH 054/183] 2020-01-22 --- ...346\234\200\345\244\247\346\225\260\345\255\227.py" | 7 +++++++ ...351\276\231\345\244\264\346\225\260\347\233\256.py" | 10 +++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 "1323.6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/1323-6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" diff --git "a/1323.6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/1323-6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" "b/1323.6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/1323-6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" new file mode 100644 index 0000000..652cb8d --- /dev/null +++ "b/1323.6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227/1323-6\345\222\2149\347\273\204\346\210\220\347\232\204\346\234\200\345\244\247\346\225\260\345\255\227.py" @@ -0,0 +1,7 @@ +class Solution(object): + def maximum69Number (self, num): + """ + :type num: int + :rtype: int + """ + return int(str(num).replace("6", "9", 1)) \ No newline at end of file diff --git "a/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" "b/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" index 197890e..7d4b22e 100644 --- "a/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" +++ "b/1326.\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256/1326-\347\201\214\346\272\211\350\212\261\345\233\255\347\232\204\346\234\200\345\260\221\346\260\264\351\276\231\345\244\264\346\225\260\347\233\256.py" @@ -8,19 +8,15 @@ def minTaps(self, n, ranges): ivls = [] reach = [0 for _ in range(n + 1)] for i in range(n + 1): - start, end = i - ranges[i], i + ranges[i] - end = min(end, n + 1) - start = max(start, 0) - + start, end = max(i - ranges[i], 0), min(i + ranges[i], n + 1) for j in range(start, end): reach[j] = max(end, reach[j]) res = 0 pos = 0 while pos < n: - if reach[pos] <= pos: + if reach[pos] <= pos: # 鏃犳硶缁х画鎶佃揪鏇磋繙鐨勪綅缃 return -1 pos = reach[pos] res += 1 - return res - \ No newline at end of file + return res \ No newline at end of file From 16f66172743935e0d20768712ad38eedfb61f80d Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 23 Jan 2020 23:58:32 -0500 Subject: [PATCH 055/183] 2020-01-23 --- ...22\345\272\217\346\225\260\347\273\204.py" | 9 +-------- ...00\345\260\221\346\267\273\345\212\240.py" | 19 +++++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git "a/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" index 626a868..43e1110 100644 --- "a/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" +++ "b/0905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/0905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -4,11 +4,4 @@ def sortArrayByParity(self, A): :type A: List[int] :rtype: List[int] """ - odd, even = [], [] - for i in A: - if i % 2: - odd.append(i) - else: - even.append(i) - - return even + odd \ No newline at end of file + return sorted(A, key = lambda x:x % 2) \ No newline at end of file diff --git "a/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" "b/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" index f20e3b0..94e321e 100644 --- "a/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" +++ "b/0921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/0921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" @@ -1,19 +1,14 @@ -# -*- coding: utf-8 -*- class Solution(object): def minAddToMakeValid(self, S): """ :type S: str :rtype: int """ - dic = {"(":"", ")" : "("} - res = len(S) - temp = [None] - for item in S: - # print item - if temp[-1] != dic[item.encode('utf-8')]: - temp.append(item) + stack = [] + dic = {"(":")", "{":"}", "[":"]"} + for ch in S: + if stack and stack[-1] in dic and dic[stack[-1]] == ch: + stack.pop() else: - temp = temp[:-1] - return len(temp) -1 - - \ No newline at end of file + stack.append(ch) + return len(stack) \ No newline at end of file From 4df208c6eba983fbc20c463298e4dcd2076af0de Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 25 Jan 2020 09:24:42 -0500 Subject: [PATCH 056/183] 2020-01-25 --- ...\270\244\346\225\260\344\271\213\345\222\214.py" | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git "a/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/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" index 9442d88..8b92177 100644 --- "a/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/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" @@ -5,11 +5,8 @@ def twoSum(self, nums, target): :type target: int :rtype: List[int] """ - hashmap = {} - for i, x in enumerate(nums): - if hashmap.has_key(target - x): - return [hashmap[target - x], i] - else: - hashmap[x] = i - - return [] \ No newline at end of file + dic = {} + for i, num in enumerate(nums): + if target - num in dic: + return [dic[target - num], i] + dic[num] = i \ No newline at end of file From 311f339e31ca9f72487bc6865a5dbd338569b6b3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 26 Jan 2020 21:40:27 -0500 Subject: [PATCH 057/183] 2020-01-26 --- ...05\350\277\207\346\273\244\345\231\250.py" | 19 +++++++++++ ...21\347\232\204\345\237\216\345\270\202.py" | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 "1333.\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250/1333-\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250.py" create mode 100644 "1334.\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202/1334-\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202.py" diff --git "a/1333.\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250/1333-\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250.py" "b/1333.\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250/1333-\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250.py" new file mode 100644 index 0000000..5420813 --- /dev/null +++ "b/1333.\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250/1333-\351\244\220\345\216\205\350\277\207\346\273\244\345\231\250.py" @@ -0,0 +1,19 @@ +class Solution(object): + def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance): + """ + :type restaurants: List[List[int]] + :type veganFriendly: int + :type maxPrice: int + :type maxDistance: int + :rtype: List[int] + """ + if not restaurants: + return [] + + res = [] + for i, rating, vF, mP, mD in restaurants: + if not veganFriendly or (vF and veganFriendly): + if mP <= maxPrice and mD <= maxDistance: + res.append([i, rating]) + + return [i for i, rating in sorted(res, key = lambda x:(x[1], x[0]), reverse = True)] \ No newline at end of file diff --git "a/1334.\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202/1334-\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202.py" "b/1334.\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202/1334-\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202.py" new file mode 100644 index 0000000..cf2536c --- /dev/null +++ "b/1334.\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202/1334-\351\230\210\345\200\274\350\267\235\347\246\273\345\206\205\351\202\273\345\261\205\346\234\200\345\260\221\347\232\204\345\237\216\345\270\202.py" @@ -0,0 +1,33 @@ +class Solution(object): + def findTheCity(self, n, edges, distanceThreshold): + """ + :type n: int + :type edges: List[List[int]] + :type distanceThreshold: int + :rtype: int + """ + distance = [[float("inf") for j in range(n)] for i in range(n)] + + for start, end, w in edges: + distance[start][end] = w + distance[end][start] = w + for i in range(n): + distance[i][i] = 0 + for i in range(n): + for j in range(n): + for k in range(n): + distance[j][k] = min(distance[j][k], distance[j][i] + distance[i][k]) + + min_cnt = 101 + res = None + for i in range(n): + cnt = 0 + for j in range(n): + if distance[i][j] <= distanceThreshold: + cnt += 1 + + if cnt <= min_cnt: + res = i + min_cnt = cnt + return res + \ No newline at end of file From 724de88ed66b006d797948a9c393b4d8659e86c8 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 26 Jan 2020 21:43:57 -0500 Subject: [PATCH 058/183] 2020-01-26 --- ...17\345\233\236\346\226\207\344\270\262.py" | 15 +++++++++ ...22\347\272\277\346\216\222\345\272\217.py" | 33 +++++++++++++++++++ ...17\345\217\267\350\275\254\346\215\242.py" | 19 +++++++++++ ...07\345\255\220\345\272\217\345\210\227.py" | 9 +++++ 4 files changed, 76 insertions(+) create mode 100644 "1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" create mode 100644 "1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" create mode 100644 "1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" create mode 100644 "1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" diff --git "a/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" "b/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..2cb31d9 --- /dev/null +++ "b/1328.\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262/1328-\347\240\264\345\235\217\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,15 @@ +class Solution(object): + def breakPalindrome(self, palindrome): + """ + :type palindrome: str + :rtype: str + """ + if len(palindrome) == 1: + return "" + if len(set(palindrome)) == 1: + if palindrome[0] == "a": + return palindrome[:-1] + "b" + for ch in palindrome: + if ord(ch) > ord("a"): + res = palindrome.replace(ch, "a", 1) + return res if res != res[::-1] else palindrome[:-1] + "b" \ No newline at end of file diff --git "a/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" "b/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" new file mode 100644 index 0000000..2c56a37 --- /dev/null +++ "b/1329.\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217/1329-\345\260\206\347\237\251\351\230\265\346\214\211\345\257\271\350\247\222\347\272\277\346\216\222\345\272\217.py" @@ -0,0 +1,33 @@ +class Solution(object): + def diagonalSort(self, mat): + """ + :type mat: List[List[int]] + :rtype: List[List[int]] + """ + if not mat or not mat[0]: + return None + m, n = len(mat), len(mat[0]) + for j in range(n): + i, l, pos = 0, [], [] + while i < m and j < n: + l.append(mat[i][j]) + pos.append([i, j]) + i += 1 + j += 1 + l.sort() + for i, p in enumerate(pos): + x, y = p + mat[x][y] = l[i] + + for i in range(1, m): + j, l, pos = 0, [], [] + while i < m and j < n: + l.append(mat[i][j]) + pos.append([i, j]) + i += 1 + j += 1 + l.sort() + for i, p in enumerate(pos): + x, y = p + mat[x][y] = l[i] + return mat \ No newline at end of file diff --git "a/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" "b/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" new file mode 100644 index 0000000..498c69d --- /dev/null +++ "b/1331.\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242/1331-\346\225\260\347\273\204\345\272\217\345\217\267\350\275\254\346\215\242.py" @@ -0,0 +1,19 @@ +class Solution(object): + def arrayRankTransform(self, arr): + """ + :type arr: List[int] + :rtype: List[int] + """ + l = sorted(arr) + dic, rank = {}, 0 + pre_num = None + for i, num in enumerate(l): + if pre_num != num: + rank += 1 + dic[num] = rank + pre_num = num + + res = [] + for num in arr: + res.append(dic[num]) + return res \ No newline at end of file diff --git "a/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" "b/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..2789ca8 --- /dev/null +++ "b/1332.\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/1332-\345\210\240\351\231\244\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,9 @@ +class Solution(object): + def removePalindromeSub(self, s): + """ + :type s: str + :rtype: int + """ + if not s: + return 0 + return 1 if s == s[::-1] else 2 \ No newline at end of file From f57e210a360a76975241fcc1a3e3a7323f79e2fb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 2 Feb 2020 22:51:47 -0500 Subject: [PATCH 059/183] 2020-02-02 --- ...5\224\257\344\270\200\345\255\227\347\254\246.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "0387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/0387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" diff --git "a/0387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/0387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" "b/0387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/0387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" new file mode 100644 index 0000000..a640d0d --- /dev/null +++ "b/0387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/0387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" @@ -0,0 +1,12 @@ +class Solution(object): + def firstUniqChar(self, s): + """ + :type s: str + :rtype: int + """ + dic = collections.Counter(s) + + for i, ch in enumerate(s): + if dic[ch] == 1: + return i + return -1 \ No newline at end of file From 7931778ba8f3d12d097b0f154fbd5532028defce Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 3 Feb 2020 22:13:23 -0500 Subject: [PATCH 060/183] 2020-02-03 --- ...4\345\244\247\345\205\203\347\264\240I.py" | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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.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.py" index b296758..b488d0e 100644 --- "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.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.py" @@ -1,19 +1,24 @@ class Solution(object): - def nextGreaterElement(self, findNums, nums): + def nextGreaterElement(self, nums1, nums2): """ - :type findNums: List[int] - :type nums: List[int] + :type nums1: List[int] + :type nums2: List[int] :rtype: List[int] """ - if not findNums or not nums: - return [] - res = list() - for item in findNums: - index = nums.index(item) - for i in range(index, len(nums)): - if nums[i] > item: - res.append(nums[i]) - break - if i + 1 == len(nums) and nums[-1] <= item: + 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 From c17a760ad957b4931b0b79e65babe50d9328b428 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 5 Feb 2020 22:20:39 -0500 Subject: [PATCH 061/183] 2020-02-05 --- ...71\346\225\260\344\271\213\345\222\214.py" | 19 +++++-------------- ...31\344\275\215\346\216\222\345\210\227.py" | 10 ++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 "0634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/0634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" diff --git "a/0633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/0633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" "b/0633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/0633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" index 07f79e0..9347d22 100644 --- "a/0633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/0633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" +++ "b/0633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/0633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" @@ -4,18 +4,9 @@ def judgeSquareSum(self, c): :type c: int :rtype: bool """ - - if c == (int(c ** 0.5) ** 2): - return True - - lo, hi = 0, int(c ** 0.5) - while(lo <= hi): - s = lo ** 2 + hi ** 2 - if s == c: + for i in range(int(c ** 0.5) + 1): + t = c - i ** 2 + s = int (t ** 0.5) + if t == s ** 2: return True - elif s > c: - hi -= 1 - else: - lo += 1 - return False - \ No newline at end of file + return False if c else True \ No newline at end of file diff --git "a/0634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/0634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" "b/0634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/0634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" new file mode 100644 index 0000000..99bf7db --- /dev/null +++ "b/0634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/0634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def findDerangement(self, n): + """ + :type n: int + :rtype: int + """ + res = 0 + for i in range(n + 1): + res = (i * res + (-1) ** i) % (10 ** 9 + 7) + return res \ No newline at end of file From 03f1a5de5463e4956ed36e61435b73aba91dcf56 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 11 Feb 2020 22:29:53 -0500 Subject: [PATCH 062/183] 2020-02-11 --- ...\222\210\347\232\204\345\244\271\350\247\222.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "1344.\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222/1344-\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222.py" diff --git "a/1344.\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222/1344-\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222.py" "b/1344.\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222/1344-\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222.py" new file mode 100644 index 0000000..072df3b --- /dev/null +++ "b/1344.\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222/1344-\346\227\266\351\222\237\346\214\207\351\222\210\347\232\204\345\244\271\350\247\222.py" @@ -0,0 +1,13 @@ +class Solution(object): + def angleClock(self, hour, minutes): + """ + :type hour: int + :type minutes: int + :rtype: float + """ + min_angle = minutes * 1.0 / 60 * 360 + hour_angle = hour * 1.0 / 12 * 360 + minutes * 1.0 / 60 * 30 + + res = abs(hour_angle - min_angle) + + return res if res < 180 else 360 - res \ No newline at end of file From 138745c383452434595137a22a2fa6521860861b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 11 Feb 2020 22:30:58 -0500 Subject: [PATCH 063/183] 2020-02-11 --- ...15\344\275\234\346\254\241\346\225\260.py" | 14 +++++++++++ ...60\347\273\204\346\225\260\347\233\256.py" | 21 ++++++++++++++++ ...\350\267\203\346\270\270\346\210\217IV.py" | 25 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 "1342.\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1342-\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" create mode 100644 "1343.\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1343-\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" create mode 100644 "1345.\350\267\263\350\267\203\346\270\270\346\210\217IV/1345-\350\267\263\350\267\203\346\270\270\346\210\217IV.py" diff --git "a/1342.\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1342-\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" "b/1342.\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1342-\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" new file mode 100644 index 0000000..cb0f367 --- /dev/null +++ "b/1342.\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260/1342-\345\260\206\346\225\260\345\255\227\345\217\230\346\210\2200\347\232\204\346\223\215\344\275\234\346\254\241\346\225\260.py" @@ -0,0 +1,14 @@ +class Solution(object): + def numberOfSteps (self, num): + """ + :type num: int + :rtype: int + """ + cnt = 0 + while num: + if num % 2: + num -= 1 + else: + num >>= 1 + cnt += 1 + return cnt \ No newline at end of file diff --git "a/1343.\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1343-\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" "b/1343.\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1343-\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..ec68791 --- /dev/null +++ "b/1343.\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1343-\345\244\247\345\260\217\344\270\272K\344\270\224\345\271\263\345\235\207\345\200\274\345\244\247\344\272\216\347\255\211\344\272\216\351\230\210\345\200\274\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" @@ -0,0 +1,21 @@ +class Solution(object): + def numOfSubarrays(self, arr, k, threshold): + """ + :type arr: List[int] + :type k: int + :type threshold: int + :rtype: int + """ + res = 0 + target_sum = k * threshold + subs = 0 + for i in range(0, k): + subs += arr[i] + + for i in range(0, len(arr) - k + 1): + if i: + subs = subs - arr[i - 1] + arr[i + k - 1] + if subs >= target_sum: + res += 1 + + return res \ No newline at end of file diff --git "a/1345.\350\267\263\350\267\203\346\270\270\346\210\217IV/1345-\350\267\263\350\267\203\346\270\270\346\210\217IV.py" "b/1345.\350\267\263\350\267\203\346\270\270\346\210\217IV/1345-\350\267\263\350\267\203\346\270\270\346\210\217IV.py" new file mode 100644 index 0000000..984dac2 --- /dev/null +++ "b/1345.\350\267\263\350\267\203\346\270\270\346\210\217IV/1345-\350\267\263\350\267\203\346\270\270\346\210\217IV.py" @@ -0,0 +1,25 @@ +class Solution(object): + def minJumps(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + from collections import defaultdict, deque + dic = defaultdict(list) + for i, x in enumerate(arr): + if (i and arr[i] != arr[i - 1]) or (i < len(arr) - 1 and arr[i] != arr[i + 1]): + dic[x].append(i) + + queue = deque([(0, 0)]) #pos, step + visited = set([0]) + + while queue: + pos, step = queue.popleft() + + if pos == len(arr) - 1: + return step + + for p in [pos - 1, pos + 1] + dic[arr[pos]]: + if 0 <= p < len(arr) and p not in visited: + queue.append((p, step + 1)) + visited.add(p) From 5c7218063e816f723b73f80f85ba46a08c8a8244 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 11 Feb 2020 22:32:18 -0500 Subject: [PATCH 064/183] 2020-02-11 --- ...0\345\274\261\347\232\204K\350\241\214.py" | 13 +++++++ ...47\345\260\217\345\207\217\345\215\212.py" | 23 +++++++++++ ...00\345\244\247\344\271\230\347\247\257.py" | 38 +++++++++++++++++++ ...3\350\267\203\346\270\270\346\210\217V.py" | 25 ++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 "1337.\346\226\271\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-\346\226\271\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.py" create mode 100644 "1339.\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1339-\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" create mode 100644 "1340.\350\267\263\350\267\203\346\270\270\346\210\217V/1340-\350\267\263\350\267\203\346\270\270\346\210\217V.py" diff --git "a/1337.\346\226\271\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-\346\226\271\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.\346\226\271\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-\346\226\271\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..ed984e3 --- /dev/null +++ "b/1337.\346\226\271\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-\346\226\271\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,13 @@ +class Solution(object): + def kWeakestRows(self, mat, k): + """ + :type mat: List[List[int]] + :type k: int + :rtype: List[int] + """ + + res = [] + for i, row in enumerate(mat): + res.append((sum(row), i)) + + return [i for s, i in sorted(res)[: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.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.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.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/1339.\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1339-\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" "b/1339.\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1339-\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.py" new file mode 100644 index 0000000..e82fcf2 --- /dev/null +++ "b/1339.\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257/1339-\345\210\206\350\243\202\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\344\271\230\347\247\257.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 maxProduct(self, root): + """ + :type root: TreeNode + :rtype: int + """ + dic = {} + + def SumOfTree(node): + if not node: + return 0 + ls, rs = SumOfTree(node.left), SumOfTree(node.right) + + dic[node] = ls + rs + node.val + return dic[node] + + SumOfTree(root) + TotalSum = dic[root] + + self.res = 0 + def dfs(node): + if not node: + return + + tmp = (TotalSum - dic[node]) * dic[node] + self.res = max(self.res, tmp) + + dfs(node.left) + dfs(node.right) + dfs(root) + return self.res % (10 ** 9 + 7) \ No newline at end of file diff --git "a/1340.\350\267\263\350\267\203\346\270\270\346\210\217V/1340-\350\267\263\350\267\203\346\270\270\346\210\217V.py" "b/1340.\350\267\263\350\267\203\346\270\270\346\210\217V/1340-\350\267\263\350\267\203\346\270\270\346\210\217V.py" new file mode 100644 index 0000000..462343d --- /dev/null +++ "b/1340.\350\267\263\350\267\203\346\270\270\346\210\217V/1340-\350\267\263\350\267\203\346\270\270\346\210\217V.py" @@ -0,0 +1,25 @@ +class Solution(object): + def maxJumps(self, arr, d): + """ + :type arr: List[int] + :type d: int + :rtype: int + """ + res = [(x, i) for i, x in enumerate(arr)] + + res.sort() + # print res + dp = [1 for _ in res] + + for k in range(len(arr)): + i = res[k][1] + for j in range(1, d + 1): + if i + j == len(arr) or arr[i + j] >= arr[i]: + break + dp[i] = max(dp[i], dp[i + j] + 1) + + for j in range(1, d + 1): + if i - j < 0 or arr[i - j] >= arr[i]: + break + dp[i] = max(dp[i], dp[i - j] + 1) + return max(dp) \ No newline at end of file From 026da34d3cbb36b1d338d86d4df0551b9be2c4d1 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 12 Feb 2020 22:01:21 -0500 Subject: [PATCH 065/183] 2020-02-12 --- ...257\345\220\246\345\255\230\345\234\250.py" | 18 ++++++++++++++++++ ...217\346\255\245\351\252\244\346\225\260.py" | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 "1346.\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250/1346-\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250.py" create mode 100644 "1347.\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260/1347-\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260.py" diff --git "a/1346.\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250/1346-\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250.py" "b/1346.\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250/1346-\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250.py" new file mode 100644 index 0000000..519caeb --- /dev/null +++ "b/1346.\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250/1346-\346\243\200\346\237\245\346\225\264\346\225\260\345\217\212\345\205\266\344\270\244\345\200\215\346\225\260\346\230\257\345\220\246\345\255\230\345\234\250.py" @@ -0,0 +1,18 @@ +class Solution(object): + def checkIfExist(self, arr): + """ + :type arr: List[int] + :rtype: bool + """ + if arr.count(0) > 1: + return True + + arr = set(arr) - set([0]) + + for x in arr: + if x * 2 in arr: + return True + + return False + + \ No newline at end of file diff --git "a/1347.\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260/1347-\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260.py" "b/1347.\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260/1347-\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260.py" new file mode 100644 index 0000000..2ae18ea --- /dev/null +++ "b/1347.\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260/1347-\345\210\266\351\200\240\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\347\232\204\346\234\200\345\260\217\346\255\245\351\252\244\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution(object): + def minSteps(self, s, t): + """ + :type s: str + :type t: str + :rtype: int + """ + n = len(t) + from collections import Counter + dic1 = Counter(s) + dic2 = Counter(t) + + valid = 0 + for char, fre in dic2.items(): + valid += min(dic1[char], fre) + + return n - valid \ No newline at end of file From 845c31dda2d05bf966fbfe26516375ab26d3ff00 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 12 Feb 2020 23:47:18 -0500 Subject: [PATCH 066/183] 2020-02-12 --- ...01\346\240\210\345\272\217\345\210\227.py" | 57 +++---------------- 1 file changed, 9 insertions(+), 48 deletions(-) diff --git "a/0946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/0946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" "b/0946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/0946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" index 35dd4b0..ca0caa0 100644 --- "a/0946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/0946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" +++ "b/0946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/0946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" @@ -5,51 +5,12 @@ def validateStackSequences(self, pushed, popped): :type popped: List[int] :rtype: bool """ - - stack = [] - i = 0 - for item in pushed: - stack.append(item) - while(stack and popped[i] == stack[-1]): - stack.pop() - i += 1 - return stack == [] - - - - - - - - - - - - - - - - - - - - - - - - l = len(pushed) - - stack = list() - - - for i in range(0, l): - stack.append(pushed[i]) - while(stack and stack[-1] == popped[0]): - stack = stack[:-1] - popped = popped[1:] - - return stack == [] - - - - \ No newline at end of file + s = [] + popped = popped[::-1] + for num in pushed: + s.append(num) + while s and popped and s[-1] == popped[-1]: + s.pop() + popped.pop() + + return not s and not popped \ No newline at end of file From faa47757e8cab9fc76783dab56c711a58e72d4bd Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 13 Feb 2020 22:43:39 -0500 Subject: [PATCH 067/183] 2020-02-13 --- ...2\345\213\244\350\256\260\345\275\225I.py" | 6 +---- ...04\345\255\220\346\225\260\347\273\204.py" | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git "a/0551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/0551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" "b/0551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/0551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" index f3ad16c..0283b38 100644 --- "a/0551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/0551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" +++ "b/0551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/0551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" @@ -4,8 +4,4 @@ def checkRecord(self, s): :type s: str :rtype: bool """ - if s.count("A") > 1 or "LLL" in s: - return False - - return True - \ No newline at end of file + return s.count("A") <= 1 and "LLL" not in s \ No newline at end of file diff --git "a/0560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/0560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" "b/0560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/0560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" index 580ea25..12e2bc4 100644 --- "a/0560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/0560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" +++ "b/0560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/0560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" @@ -5,16 +5,19 @@ def subarraySum(self, nums, k): :type k: int :rtype: int """ + # prefix[i] = sum(nums[:i]) + # prefix[j] - prefix[i] = sum(nums[i:j]) from collections import defaultdict - pre_sum = 0 - record = defaultdict(int) - record[0] = 1 + + prefix = [0 for _ in range(len(nums) + 1)] + + for i, x in enumerate(nums): + prefix[i + 1] = prefix[i] + x + + dic = defaultdict(int) res = 0 - for i in range(len(nums)): - pre_sum += nums[i] - - #找 k - pre_sum - res += record[pre_sum - k] - record[pre_sum] += 1 - + for i, x in enumerate(prefix): + res += dic[x - k] + dic[x] += 1 + return res \ No newline at end of file From 714950f59980f214995597b8dc9ade820d496157 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 18 Feb 2020 00:25:45 -0500 Subject: [PATCH 068/183] 2020-02-18 --- ...30\344\275\215\346\230\240\345\260\204.py" | 15 +++--- ...27\346\257\215\345\214\272\351\227\264.py" | 49 ++++++++++++------- ...63\344\270\216\347\237\263\345\244\264.py" | 20 ++++---- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git "a/0760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/0760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" "b/0760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/0760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" index ea4504e..58c9a94 100644 --- "a/0760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/0760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" +++ "b/0760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/0760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" @@ -5,12 +5,9 @@ def anagramMappings(self, A, B): :type B: List[int] :rtype: List[int] """ - record = dict() - for i, b in enumerate(B): - record[b] = i - - res = [-1 for _ in range(len(A))] - for i, a in enumerate(A): - res[i] = record[a] - - return res \ No newline at end of file + + dic = dict() + for i, x in enumerate(B): + dic[x] = i + + return [dic[x] for x in A] \ No newline at end of file diff --git "a/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/0763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" "b/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/0763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" index 8b1001d..8216656 100644 --- "a/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/0763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" +++ "b/0763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/0763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" @@ -4,23 +4,36 @@ def partitionLabels(self, S): :type S: str :rtype: List[int] """ - dic = {} + from collections import defaultdict + dic = defaultdict(list) + + for ch in "abcdefghijklmnopqrstuvwxyz": + for i, char in enumerate(S): + if char == ch: + dic[ch].append(i) + break + + for i in range(len(S) - 1, -1, -1): + if S[i] == ch: + dic[ch].append(i) + break + + + intervals = [] + for val in dic.values(): + intervals.append(val) - for index, char in enumerate(S): - dic[char] = index - - right = dic[S[0]] - left = 0 + intervals.sort() + #print intervals + res = [] - for index, char in enumerate(S): - right = max(right, dic[char]) - if index >= right: - res.append(right - left + 1) - left = right + 1 - - return res - - - - - \ No newline at end of file + start, end = 0, 0 + for s, e in intervals: + if s > end: + res.append(end - start + 1) + start, end = s, e + else: + end = max(e, end) + res.append(end - start + 1) + + return res \ No newline at end of file diff --git "a/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/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" index 0060855..4b0e5c9 100644 --- "a/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/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" @@ -1,11 +1,13 @@ class Solution(object): def numJewelsInStones(self, J, S): - if len(J) == 0 or len(S) == 0: - return 0 - count = 0 - for itemins in S: - if itemins in J: - count += 1 - - return count - \ No newline at end of file + """ + :type J: str + :type S: str + :rtype: int + """ + J = set(J) + res = 0 + for s in S: + if s in J: + res += 1 + return res \ No newline at end of file From 86e9e7fca5afc2e6d35c1269e5673fe5288359ae Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 19 Feb 2020 02:12:41 -0500 Subject: [PATCH 069/183] 2020-02-19 --- ...63\350\241\214\350\257\276\347\250\213.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "1136.\345\271\263\350\241\214\350\257\276\347\250\213/1136-\345\271\263\350\241\214\350\257\276\347\250\213.py" diff --git "a/1136.\345\271\263\350\241\214\350\257\276\347\250\213/1136-\345\271\263\350\241\214\350\257\276\347\250\213.py" "b/1136.\345\271\263\350\241\214\350\257\276\347\250\213/1136-\345\271\263\350\241\214\350\257\276\347\250\213.py" new file mode 100644 index 0000000..8ea4616 --- /dev/null +++ "b/1136.\345\271\263\350\241\214\350\257\276\347\250\213/1136-\345\271\263\350\241\214\350\257\276\347\250\213.py" @@ -0,0 +1,33 @@ +class Solution(object): + def minimumSemesters(self, N, relations): + """ + :type N: int + :type relations: List[List[int]] + :rtype: int + """ + indegree = [0 for i in range(N + 1)] + adj = [set() for _ in range(N + 1)] + for pre, cur in relations: + indegree[cur] += 1 #缁熻鍏ュ害 + adj[pre].add(cur) #缁熻閭诲眳鑺傜偣 + + from collections import deque + queue = deque() + for i, x in enumerate(indegree): + if x == 0 and i > 0: #灏嗗叆搴︿负0鐨勮妭鐐瑰叆闃 + queue.append(i) + + semester_cnt= 0 + finished_course = 0 + while queue: + next_queue = deque() + semester_cnt += 1 #鏂扮殑瀛︽湡鏉ヤ簡 + for cur in queue: + finished_course += 1 #鍙堜竴闂ㄨ瀛﹀畬浜 + for neighbor in adj[cur]: + indegree[neighbor] -= 1 + + if indegree[neighbor] == 0: + next_queue.append(neighbor) #涓嬩釜瀛︽湡鍙互瀛eighbor杩欓棬璇句簡 + queue = next_queue + return semester_cnt if finished_course == N else -1 #濡傛灉鎵鏈夌殑璇鹃兘瀛﹀畬浜嗭紝閭d箞finished_course == N \ No newline at end of file From 202badbfa99653e57d78526d4a2077bf0e900ccd Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 28 Feb 2020 23:44:56 -0500 Subject: [PATCH 070/183] 2020-02-28 --- ...55\347\232\204\350\264\237\346\225\260.py" | 16 +++++++++ ...60\347\232\204\344\271\230\347\247\257.py" | 23 +++++++++++++ ...32\350\256\256\346\225\260\347\233\256.py" | 33 +++++++++++++++++++ ...56\346\240\207\346\225\260\347\273\204.py" | 29 ++++++++++++++++ 4 files changed, 101 insertions(+) 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.py" create mode 100644 "1352.\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257/1352-\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257.py" create mode 100644 "1353.\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256/1353-\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256.py" create mode 100644 "1354.\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204/1354-\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204.py" 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.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.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.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/1352.\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257/1352-\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257.py" "b/1352.\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257/1352-\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257.py" new file mode 100644 index 0000000..e30f7ca --- /dev/null +++ "b/1352.\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257/1352-\346\234\200\345\220\216K\344\270\252\346\225\260\347\232\204\344\271\230\347\247\257.py" @@ -0,0 +1,23 @@ +class ProductOfNumbers(object): + + def __init__(self): + self.prefix = [1] + + def add(self, num): + """ + :type num: int + :rtype: None + """ + if num: + self.prefix.append(self.prefix[-1] * num) + else: + self.prefix = [1] + + def getProduct(self, k): + """ + :type k: int + :rtype: int + """ + if k >= len(self.prefix): + return 0 + return self.prefix[-1] / self.prefix[-k - 1] \ No newline at end of file diff --git "a/1353.\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256/1353-\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256.py" "b/1353.\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256/1353-\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256.py" new file mode 100644 index 0000000..cfc526c --- /dev/null +++ "b/1353.\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256/1353-\346\234\200\345\244\232\345\217\257\344\273\245\345\217\202\345\212\240\347\232\204\344\274\232\350\256\256\346\225\260\347\233\256.py" @@ -0,0 +1,33 @@ +class Solution(object): + def maxEvents(self, events): + """ + :type events: List[List[int]] + :rtype: int + """ + from heapq import * + if not events: + return 0 + # 鎺掑簭骞跺弽杞紝鍙嶈浆鏄负浜嗗彲浠ュ揩閫焢op + events = sorted(events, key = lambda x:(x[0], x[1]))[::-1] + + queue = [] + res = 0 + for day in range(1, 10 ** 5 + 1): + # 鎶婃墍鏈夌粨鏉熸棩鏈熷湪褰撳墠鏃ユ湡涔嬪墠鐨別vent閮絧op鎺 + while queue and queue[0] < day: + heappop(queue) + + # 鎶婃墍鏈夊紑濮嬫棩鏈熷ぇ浜庣瓑浜庡綋鍓嶆棩鏈熺殑event閮絧ush杩涢槦鍒 + while events and events[-1][0] <= day: + last = events.pop() + heappush(queue, last[1]) + + if queue: + # 濡傛灉褰撳墠鏃ユ湡鏈夊彲浠ュ幓鐨別vent锛屽氨鍘昏繖涓涓 + heappop(queue) + res += 1 + if not queue and not events: + # 濡傛灉鎵鏈塭vent閮藉弬鍔犲畬浜 + break + + return res \ No newline at end of file diff --git "a/1354.\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204/1354-\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204.py" "b/1354.\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204/1354-\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204.py" new file mode 100644 index 0000000..ebf5cb0 --- /dev/null +++ "b/1354.\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204/1354-\345\244\232\346\254\241\346\261\202\345\222\214\346\236\204\351\200\240\347\233\256\346\240\207\346\225\260\347\273\204.py" @@ -0,0 +1,29 @@ +class Solution(object): + def isPossible(self, target): + """ + :type target: List[int] + :rtype: bool + """ + from heapq import * + if len(target) == 1: + return target[0] == 1 + + s = sum(target) + target = [-item for item in target] + heapify(target) + + while s > len(target): + # 鎵惧綋鍓嶆渶澶х殑鏁板拰绗簩澶х殑鏁 + m = -heappop(target) + s_m = -target[0] + + # 鏇存柊 m 骞舵洿鏂 s + diff = s - m + if not diff: + break + new_m = m - (max(1, (m - s_m) / diff) * diff) + s = s - m + new_m + + heappush(target, -new_m) + + return not any([num != -1 for num in target]) \ No newline at end of file From 46ff2f2c1cebcfeec8a1aa385051d47dba55edbb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 1 Mar 2020 01:42:01 -0500 Subject: [PATCH 071/183] 2020-03-01 --- ...27\345\256\236\347\216\260\346\240\210.py" | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git "a/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/0225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" "b/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/0225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" index 7c4a47b..21c0098 100644 --- "a/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/0225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" +++ "b/0225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/0225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" @@ -1,11 +1,11 @@ +from collections import deque class MyStack(object): - def __init__(self): """ Initialize your data structure here. """ - self.queue1 = [] - self.queue2 = [] + self.q1 = deque() + self.q2 = deque() def push(self, x): """ @@ -13,41 +13,32 @@ def push(self, x): :type x: int :rtype: None """ - self.queue1.append(x) - - while len(self.queue1) > 1: - self.queue2.append(self.queue1[0]) - self.queue1 = self.queue1[1:] + self.q1.append(x) + while self.q2: + self.q1.append(self.q2.popleft()) + self.q2 = self.q1 + self.q1 = deque() - - # print self.queue1, self.queue2 def pop(self): """ Removes the element on top of the stack and returns that element. :rtype: int """ - # print self.queue1, self.queue2 - top = self.queue1[0] - self.queue1, self.queue2 = self.queue2, [] - while len(self.queue1) > 1: - self.queue2.append(self.queue1[0]) - self.queue1 = self.queue1[1:] - return top - + return self.q2.popleft() def top(self): """ Get the top element. :rtype: int """ - return self.queue1[0] - + return self.q2[0] + def empty(self): """ Returns whether the stack is empty. :rtype: bool """ - return not self.queue1 and not self.queue2 + return not self.q2 # Your MyStack object will be instantiated and called as such: From 022ef83e2f32fdca9c4aac49575f21849cc49da9 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 1 Mar 2020 21:06:00 -0500 Subject: [PATCH 072/183] 2020-03-01 --- ...246\346\230\257\345\220\246\345\224\257\344\270\200.py" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23001.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\23001.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" diff --git "a/\351\235\242\350\257\225\351\242\23001.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\23001.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\23001.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\23001.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..50fe13e --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.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\23001.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,7 @@ +class Solution(object): + def isUnique(self, astr): + """ + :type astr: str + :rtype: bool + """ + return len(set(astr)) == len(astr) \ No newline at end of file From ab2ef8b46a10f094aa1750dc3f99a5a67bd43a9e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 3 Mar 2020 14:03:40 -0500 Subject: [PATCH 073/183] 2020-03-03 --- ...02\347\232\204\346\251\230\345\255\220.py" | 52 ++++++++++--------- ...17\347\232\204\346\225\260\347\273\204.py" | 10 ++++ 2 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\23010.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23010.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" diff --git "a/0994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/0994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" "b/0994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/0994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" index 195a6d3..5d9ce8b 100644 --- "a/0994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/0994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" +++ "b/0994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/0994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" @@ -4,36 +4,40 @@ def orangesRotting(self, grid): :type grid: List[List[int]] :rtype: int """ + from collections import deque + if not grid or not grid[0]: + return 0 + + m, n = len(grid), len(grid[0]) dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - rotlist = list() - for i in range(len(grid)): - for j in range(len(grid[0])): + + queue = deque() + for i in range(m): + for j in range(n): if grid[i][j] == 2: - rotlist.append([i, j]) - minute = 0 - while(rotlist): - newrotlist = list() - for rotnode in rotlist: - x0 = rotnode[0] - y0 = rotnode[1] - + queue.append((i, j)) + + res = 0 + while queue: + for i in range(len(queue)): + pair = queue.popleft() + x0, y0 = pair[0], pair[1] for k in range(4): x = x0 + dx[k] y = y0 + dy[k] - - if 0 <= x < len(grid) and 0 <= y < len(grid[0]) and grid[x][y] == 1: + + if 0 <= x < m and 0 <= y < n and grid[x][y] == 1: grid[x][y] = 2 - newrotlist.append([x,y]) - if not newrotlist: + queue.append((x, y)) + if not queue: break - - rotlist = newrotlist[:] - minute += 1 - - for row in grid: - for i in row: - if i == 1:#还有新鲜的 + res += 1 + for i in range(m): + for j in range(n): + if grid[i][j] == 1: return -1 - return minute - \ No newline at end of file + return res + + + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23010.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23010.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" "b/\351\235\242\350\257\225\351\242\23010.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23010.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" new file mode 100644 index 0000000..10722e8 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23010.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23010.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" @@ -0,0 +1,10 @@ +class Solution(object): + def merge(self, A, m, B, n): + """ + :type A: List[int] + :type m: int + :type B: List[int] + :type n: int + :rtype: None Do not return anything, modify A in-place instead. + """ + A[:] = sorted(A[:m] + B) \ No newline at end of file From 1b3ebd883099382b6b5529706c1ab3d8fb38bb5a Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 3 Mar 2020 14:06:34 -0500 Subject: [PATCH 074/183] 2020-03-03 --- ...45\244\215\347\232\204\346\225\260\345\255\227.py" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23003.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23003-\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" diff --git "a/\351\235\242\350\257\225\351\242\23003.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23003-\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/\351\235\242\350\257\225\351\242\23003.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23003-\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..cf94ed9 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23003.\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23003-\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,11 @@ +class Solution(object): + def findRepeatNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + visited = set() + for num in nums: + if num in visited: + return num + visited.add(num) \ No newline at end of file From 4f7083268383beaecd54d495ac9f5fba1e840096 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 3 Mar 2020 14:09:24 -0500 Subject: [PATCH 075/183] 2020-03-03 --- ...345\272\217\347\232\204\346\225\260\347\273\204.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\230 10.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\230 10.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" diff --git "a/\351\235\242\350\257\225\351\242\230 10.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\230 10.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" "b/\351\235\242\350\257\225\351\242\230 10.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\230 10.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" new file mode 100644 index 0000000..10722e8 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 10.01.\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\230 10.01-\345\220\210\345\271\266\346\216\222\345\272\217\347\232\204\346\225\260\347\273\204.py" @@ -0,0 +1,10 @@ +class Solution(object): + def merge(self, A, m, B, n): + """ + :type A: List[int] + :type m: int + :type B: List[int] + :type n: int + :rtype: None Do not return anything, modify A in-place instead. + """ + A[:] = sorted(A[:m] + B) \ No newline at end of file From 427304c80a2cdf8e5d4303ebc442c29029e45d02 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 5 Mar 2020 01:19:31 -0500 Subject: [PATCH 076/183] 2020-03-05 --- ...\345\210\206\347\263\226\346\236\234II.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" diff --git "a/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" "b/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..c988b09 --- /dev/null +++ "b/1103.\345\210\206\347\263\226\346\236\234II/1103-\345\210\206\347\263\226\346\236\234II.py" @@ -0,0 +1,20 @@ +class Solution(object): + def distributeCandies(self, candies, num_people): + """ + :type candies: int + :type num_people: int + :rtype: List[int] + """ + res = [0 for _ in range(num_people)] + cnt = 1 + while candies: + for i in range(num_people): + if candies >= cnt: + res[i] += cnt + candies -= cnt + cnt += 1 + else: + res[i] += candies + candies = 0 + break + return res \ No newline at end of file From 73fa4fbc9be677e9f63101e2059cd9ce257cee29 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 5 Mar 2020 23:01:01 -0500 Subject: [PATCH 077/183] 2020-03-05 --- ...21\347\232\204\351\225\234\345\203\217.py" | 19 +++++++ ...04\344\272\214\345\217\211\346\240\221.py" | 23 +++++++++ ...23\345\215\260\347\237\251\351\230\265.py" | 45 +++++++++++++++++ ...75\346\225\260\347\232\204\346\240\210.py" | 50 +++++++++++++++++++ ...71\345\207\272\345\272\217\345\210\227.py" | 19 +++++++ ...60\344\272\214\345\217\211\346\240\221.py" | 28 +++++++++++ ...\344\272\214\345\217\211\346\240\221II.py" | 30 +++++++++++ ...344\272\214\345\217\211\346\240\221III.py" | 35 +++++++++++++ ...15\345\216\206\345\272\217\345\210\227.py" | 25 ++++++++++ ...74\347\232\204\350\267\257\345\276\204.py" | 31 ++++++++++++ ...43\346\225\260\345\272\217\345\210\227.py" | 22 ++++++++ 11 files changed, 327 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23027.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\351\235\242\350\257\225\351\242\23027-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" create mode 100644 "\351\235\242\350\257\225\351\242\23028.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23028-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" create mode 100644 "\351\235\242\350\257\225\351\242\23029.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23029-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" create mode 100644 "\351\235\242\350\257\225\351\242\23030.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\351\235\242\350\257\225\351\242\23030-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" create mode 100644 "\351\235\242\350\257\225\351\242\23031.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23031-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\23032-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23032-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" create mode 100644 "\351\235\242\350\257\225\351\242\23032-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\351\235\242\350\257\225\351\242\23032-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" create mode 100644 "\351\235\242\350\257\225\351\242\23032-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\351\235\242\350\257\225\351\242\23032-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" create mode 100644 "\351\235\242\350\257\225\351\242\23033.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23033-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\23034.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\351\235\242\350\257\225\351\242\23034-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" create mode 100644 "\351\235\242\350\257\225\351\242\23057-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23057-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" diff --git "a/\351\235\242\350\257\225\351\242\23027.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\351\235\242\350\257\225\351\242\23027-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" "b/\351\235\242\350\257\225\351\242\23027.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\351\235\242\350\257\225\351\242\23027-\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..71ab723 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23027.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\351\235\242\350\257\225\351\242\23027-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" @@ -0,0 +1,19 @@ +# 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 mirrorTree(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + if not root: + return root + + root.left, root.right = self.mirrorTree(root.right), self.mirrorTree(root.left) + + return root \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23028.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23028-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" "b/\351\235\242\350\257\225\351\242\23028.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23028-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..ec0c7c3 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23028.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23028-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.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 isSymmetric(self, root): + """ + :type root: TreeNode + :rtype: bool + """ + if not root: + return True + + def check(root1, root2): + if not root1 and not root2: + return True + if not root1 or not root2: + return False + return root1.val == root2.val and check(root1.left, root2.right) and check(root1.right, root2.left) + return check(root, root) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23029.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23029-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\23029.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23029-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" new file mode 100644 index 0000000..5c212b0 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23029.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23029-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" @@ -0,0 +1,45 @@ +class Solution(object): + def spiralOrder(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: List[int] + """ + if not matrix or not matrix[0]: + return matrix + m, n = len(matrix), len(matrix[0]) + + x, y = 0, 0 + state = "r" + cnt = 0 + res = [] + visited = set() + while cnt < m * n: + res.append(matrix[x][y]) + visited.add((x, y)) + if state == "r": + if y + 1 < n and (x, y + 1) not in visited: + y += 1 + else: + x += 1 + state = "d" + elif state == "d": + if x + 1 < m and (x + 1, y) not in visited: + x += 1 + else: + y -= 1 + state = "l" + elif state == "l": + if y - 1 >= 0 and (x, y - 1) not in visited: + y -= 1 + else: + x -= 1 + state = "u" + elif state == "u": + if x - 1 >= 0 and (x - 1, y) not in visited: + x -= 1 + else: + y += 1 + state = "r" + cnt += 1 + return res + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23030.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\351\235\242\350\257\225\351\242\23030-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" "b/\351\235\242\350\257\225\351\242\23030.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\351\235\242\350\257\225\351\242\23030-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" new file mode 100644 index 0000000..787a395 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23030.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\351\235\242\350\257\225\351\242\23030-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" @@ -0,0 +1,50 @@ +class MinStack(object): + + def __init__(self): + """ + initialize your data structure here. + """ + self.stack = [] + self.min_s = [] + + def push(self, x): + """ + :type x: int + :rtype: None + """ + if not self.stack: + self.stack = [x] + self.min_s = [x] + else: + self.stack.append(x) + if self.min_s[-1] < x: + self.min_s.append(self.min_s[-1]) + else: + self.min_s.append(x) + + def pop(self): + """ + :rtype: None + """ + self.stack.pop() + self.min_s.pop() + + def top(self): + """ + :rtype: int + """ + return self.stack[-1] + + def min(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.min() \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23031.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23031-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23031.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23031-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" new file mode 100644 index 0000000..4dfe5b1 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23031.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23031-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" @@ -0,0 +1,19 @@ +class Solution(object): + def validateStackSequences(self, pushed, popped): + """ + :type pushed: List[int] + :type popped: List[int] + :rtype: bool + """ + if not pushed and not popped: + return True + if not pushed or not popped: + return False + stack = [] + popped = popped[::-1] + for i, num in enumerate(pushed): + stack.append(num) + while stack and stack[-1] == popped[-1]: + stack.pop() + popped.pop() + return not popped \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23032-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23032-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" "b/\351\235\242\350\257\225\351\242\23032-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23032-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..bffbb72 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23032-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\351\235\242\350\257\225\351\242\23032-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + while queue: + 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 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23032-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\351\235\242\350\257\225\351\242\23032-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" "b/\351\235\242\350\257\225\351\242\23032-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\351\235\242\350\257\225\351\242\23032-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" new file mode 100644 index 0000000..0798c1d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23032-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\351\235\242\350\257\225\351\242\23032-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + while queue: + tmp = [] + for _ in range(len(queue)): + cur = queue.popleft() + tmp.append(cur.val) + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + res.append(tmp) + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23032-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\351\235\242\350\257\225\351\242\23032-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" "b/\351\235\242\350\257\225\351\242\23032-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\351\235\242\350\257\225\351\242\23032-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" new file mode 100644 index 0000000..1456eae --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23032-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\351\235\242\350\257\225\351\242\23032-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" @@ -0,0 +1,35 @@ +# 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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + flag = 1 + while queue: + tmp = [] + for _ in range(len(queue)): + cur = queue.popleft() + tmp.append(cur.val) + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + if flag: + res.append(tmp) + else: + res.append(tmp[::-1]) + flag = 1 - flag + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23033.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23033-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23033.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23033-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" new file mode 100644 index 0000000..0d2fd26 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23033.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23033-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" @@ -0,0 +1,25 @@ +class Solution(object): + def verifyPostorder(self, postorder): + """ + :type postorder: List[int] + :rtype: bool + """ + if not postorder or len(postorder) == 1: + return True + + for i in range(len(postorder)): + if postorder[i] > postorder[-1]: + break + if any(postorder[j] < postorder[-1] for j in range(i, len(postorder) - 1)): + return False + + if i == len(postorder): + # no right subtree + left = postorder[:-1] + right = None + else: + left = postorder[:i] + right = postorder[i:-1] + + return self.verifyPostorder(left) and self.verifyPostorder(right) + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23034.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\351\235\242\350\257\225\351\242\23034-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" "b/\351\235\242\350\257\225\351\242\23034.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\351\235\242\350\257\225\351\242\23034-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" new file mode 100644 index 0000000..6f40ee3 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23034.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\351\235\242\350\257\225\351\242\23034-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" @@ -0,0 +1,31 @@ +# 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, summ): + """ + :type root: TreeNode + :type sum: int + :rtype: List[List[int]] + """ + self.res = [] + + def dfs(node, path, s): + if not node: + return + + if not node.left and not node.right: + if s + node.val == summ: + path.append(node.val) + self.res.append(path) + return + + dfs(node.left, path + [node.val], s + node.val) + dfs(node.right, path + [node.val], s + node.val) + + dfs(root, [], 0) + return self.res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23057-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23057-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23057-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23057-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" new file mode 100644 index 0000000..cc91968 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23057-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\351\235\242\350\257\225\351\242\23057-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" @@ -0,0 +1,22 @@ +class Solution(object): + def findContinuousSequence(self, target): + """ + :type target: int + :rtype: List[List[int]] + """ + from collections import deque + window = deque() + res = [] + s = 0 + i = 1 + while i < target // 2 + 3: + if s == target: + res.append(list(window)) + if s <= target: + window.append(i) + s += i + i += 1 + elif s > target: + s -= window.popleft() + + return res From 4d71f9271bf5d65d57171cfa31305c273d767bec Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 6 Mar 2020 21:39:29 -0500 Subject: [PATCH 078/183] 2020-03-06 --- ...14\345\220\221\351\223\276\350\241\250.py" | 47 +++++++++++++++++++ ...50\347\232\204\345\244\215\345\210\266.py" | 30 ++++++++++++ ...14\345\220\221\351\223\276\350\241\250.py" | 47 +++++++++++++++++++ ...62\347\232\204\346\216\222\345\210\227.py" | 16 +++++++ ...12\347\232\204\346\225\260\345\255\227.py" | 7 +++ ...7\347\232\204k\344\270\252\346\225\260.py" | 8 ++++ ...04\346\234\200\345\244\247\345\222\214.py" | 16 +++++++ ...04\346\234\200\345\244\247\345\200\274.py" | 35 ++++++++++++++ 8 files changed, 206 insertions(+) create mode 100644 "0426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/0426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "\351\235\242\350\257\225\351\242\23035.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\351\235\242\350\257\225\351\242\23035-\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 "\351\235\242\350\257\225\351\242\23036.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23036-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "\351\235\242\350\257\225\351\242\23038.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23038-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\23039.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23039-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" create mode 100644 "\351\235\242\350\257\225\351\242\23042.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\351\235\242\350\257\225\351\242\23042-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" create mode 100644 "\351\235\242\350\257\225\351\242\23059-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\351\235\242\350\257\225\351\242\23059-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" diff --git "a/0426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/0426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/0426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/0426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..669fb96 --- /dev/null +++ "b/0426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/0426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,47 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left=None, right=None): + self.val = val + self.left = left + self.right = right +""" +class Solution(object): + def treeToDoublyList(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return root + if not root.left and not root.right: + root.left = root + root.right = root + return root + + left = self.treeToDoublyList(root.left) + right = self.treeToDoublyList(root.right) + if root.left and root.right: + left_tail = left.left + right_tail = right.left + + left_tail.right = root + root.left = left_tail + root.right = right + right.left = root + + left.left = right_tail + right_tail.right = left + elif root.left: + left_tail = left.left + left_tail.right = root + root.left = left_tail + left.left = root + root.right = left + elif root.right: + right_tail = right.left + root.right = right + root.left = right_tail + right_tail.right = root + right.left = root + return left if left else root \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23035.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\351\235\242\350\257\225\351\242\23035-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" "b/\351\235\242\350\257\225\351\242\23035.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\351\235\242\350\257\225\351\242\23035-\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..9de38d5 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23035.\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266/\351\235\242\350\257\225\351\242\23035-\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,30 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x, next=None, random=None): + self.val = int(x) + self.next = next + self.random = random +""" +class Solution(object): + def copyRandomList(self, head): + """ + :type head: Node + :rtype: Node + """ + mapping = {} # key is the old node, val is the new node + + p = head + while p: + mapping[p] = Node(p.val) + p = p.next + + p = head + while p: + if p.next: + mapping[p].next = mapping[p.next] + if p.random: + mapping[p].random = mapping[p.random] + p = p.next + + return mapping[head] if head else head \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23036.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23036-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/\351\235\242\350\257\225\351\242\23036.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23036-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..669fb96 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23036.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23036-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,47 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left=None, right=None): + self.val = val + self.left = left + self.right = right +""" +class Solution(object): + def treeToDoublyList(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return root + if not root.left and not root.right: + root.left = root + root.right = root + return root + + left = self.treeToDoublyList(root.left) + right = self.treeToDoublyList(root.right) + if root.left and root.right: + left_tail = left.left + right_tail = right.left + + left_tail.right = root + root.left = left_tail + root.right = right + right.left = root + + left.left = right_tail + right_tail.right = left + elif root.left: + left_tail = left.left + left_tail.right = root + root.left = left_tail + left.left = root + root.right = left + elif root.right: + right_tail = right.left + root.right = right + root.left = right_tail + right_tail.right = root + right.left = root + return left if left else root \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23038.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23038-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23038.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23038-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" new file mode 100644 index 0000000..c61bd6e --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23038.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23038-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution(object): + def permutation(self, s): + """ + :type s: str + :rtype: List[str] + """ + from itertools import permutations + res = [] + visited = set() + for item in list(permutations(s)): + s = "".join(item) + if s not in visited: + res.append(s) + visited.add(s) + + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23039.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23039-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\23039.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23039-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..b0e5086 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23039.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23039-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,7 @@ +class Solution(object): + def majorityElement(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + return sorted(nums)[len(nums) // 2] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" "b/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" new file mode 100644 index 0000000..35e1ef0 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution(object): + def getLeastNumbers(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: List[int] + """ + return sorted(arr)[:k] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23042.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\351\235\242\350\257\225\351\242\23042-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/\351\235\242\350\257\225\351\242\23042.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\351\235\242\350\257\225\351\242\23042-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" new file mode 100644 index 0000000..d4b9334 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23042.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\351\235\242\350\257\225\351\242\23042-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + prefix = [0 for _ in nums] + + prefix[0] = nums[0] + min_s = min(0, nums[0]) + res = nums[0] + for i in range(1, len(nums)): + prefix[i] = prefix[i - 1] + nums[i] + res = max(prefix[i] - min_s, res) + min_s = min(min_s, prefix[i]) + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23059-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\351\235\242\350\257\225\351\242\23059-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/\351\235\242\350\257\225\351\242\23059-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\351\235\242\350\257\225\351\242\23059-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..8954ae7 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23059-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\351\235\242\350\257\225\351\242\23059-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,35 @@ +class MaxQueue(object): + + def __init__(self): + from collections import deque + self.queue = deque([]) + def max_value(self): + """ + :rtype: int + """ + if self.queue: + return max(self.queue) + return -1 + + def push_back(self, value): + """ + :type value: int + :rtype: None + """ + self.queue.append(value) + + + def pop_front(self): + """ + :rtype: int + """ + if not self.queue: + return -1 + return self.queue.popleft() + + +# Your MaxQueue object will be instantiated and called as such: +# obj = MaxQueue() +# param_1 = obj.max_value() +# obj.push_back(value) +# param_3 = obj.pop_front() \ No newline at end of file From 51055d5e5be18b1821e1bc4f9e453e31e5845f9c Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 7 Mar 2020 22:01:59 -0500 Subject: [PATCH 079/183] 2020-03-07 --- ...66\351\222\261\345\205\221\346\215\242.py" | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git "a/0322.\351\233\266\351\222\261\345\205\221\346\215\242/0322-\351\233\266\351\222\261\345\205\221\346\215\242.py" "b/0322.\351\233\266\351\222\261\345\205\221\346\215\242/0322-\351\233\266\351\222\261\345\205\221\346\215\242.py" index 5e27b06..13e35ba 100644 --- "a/0322.\351\233\266\351\222\261\345\205\221\346\215\242/0322-\351\233\266\351\222\261\345\205\221\346\215\242.py" +++ "b/0322.\351\233\266\351\222\261\345\205\221\346\215\242/0322-\351\233\266\351\222\261\345\205\221\346\215\242.py" @@ -5,22 +5,21 @@ def coinChange(self, coins, amount): :type amount: int :rtype: int """ - if amount == 0: - return 0 - dp = list() - max_int = 2 << 31 + from collections import deque - for i in range(amount + 1): - if i not in coins: - dp.append(max_int) - else: - dp.append(1) - - for i in range(amount + 1): - if i not in coins: - for j in coins: - if i - j > 0: - dp[i] = min(dp[i - j] + 1, dp[i]) + queue = deque([(0, 0)]) + visited = set([0]) + while queue: + cur, step = queue.popleft() + if cur == amount: + return step + if cur > amount: + continue + + for coin in coins: + value = cur + coin + if value not in visited: + visited.add((value)) + queue.append((value, step + 1)) - return dp[amount] if dp[amount] != max_int else -1 - \ No newline at end of file + return -1 \ No newline at end of file From 8abe861ab0f10f557e74b02bb0b2e944deef07a6 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 8 Mar 2020 20:45:12 -0400 Subject: [PATCH 080/183] 2020-03-08 --- ...00\344\275\263\346\227\266\346\234\272.py" | 27 +++++-------------- ...54\345\255\227\347\254\246\344\270\262.py" | 8 ++++++ ...00\345\244\247\345\210\251\346\266\246.py" | 12 +++++++++ ...2\23064-\346\261\2021+2+\342\200\246+n.py" | 7 +++++ ...44\345\201\232\345\212\240\346\263\225.py" | 8 ++++++ ...30\347\247\257\346\225\260\347\273\204.py" | 16 +++++++++++ 6 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\23058-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\351\235\242\350\257\225\351\242\23058-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" create mode 100644 "\351\235\242\350\257\225\351\242\23063.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\351\235\242\350\257\225\351\242\23063-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" create mode 100644 "\351\235\242\350\257\225\351\242\23064.\346\261\2021+2+\342\200\246+n/\351\235\242\350\257\225\351\242\23064-\346\261\2021+2+\342\200\246+n.py" create mode 100644 "\351\235\242\350\257\225\351\242\23065.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23065-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" create mode 100644 "\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" 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.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.py" index 8b19676..325ada7 100644 --- "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.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.py" @@ -4,24 +4,9 @@ def maxProfit(self, prices): :type prices: List[int] :rtype: int """ -# dp[i][k][0] = max(dp[i – 1][k][0], dp[I – 1][k][1] + prices[i]) -# dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k][0] - prices[i]) -# 第一题 k = 1 - -# dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) -# dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - prices[i]) - -# 当i = 0时, -# dp[0][0] = 0 -# dp[0][1] = -prices[0] - dp = [[0 for _ in range(2)] for _ in range(len(prices))] - for i, price in enumerate(prices): - if i == 0: - dp[0][0] = 0 - dp[0][1] = -price - else: - dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) - dp[i][1] = max(dp[i - 1][1], - prices[i]) - - return dp[len(prices) - 1][0] if prices else 0 - \ No newline at end of file + 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/\351\235\242\350\257\225\351\242\23058-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\351\235\242\350\257\225\351\242\23058-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" "b/\351\235\242\350\257\225\351\242\23058-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\351\235\242\350\257\225\351\242\23058-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..8e4cadf --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23058-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\351\235\242\350\257\225\351\242\23058-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,8 @@ +class Solution(object): + def reverseLeftWords(self, s, n): + """ + :type s: str + :type n: int + :rtype: str + """ + return s[n:] + s[:n] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23063.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\351\235\242\350\257\225\351\242\23063-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" "b/\351\235\242\350\257\225\351\242\23063.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\351\235\242\350\257\225\351\242\23063-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" new file mode 100644 index 0000000..325ada7 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23063.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\351\235\242\350\257\225\351\242\23063-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.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/\351\235\242\350\257\225\351\242\23064.\346\261\2021+2+\342\200\246+n/\351\235\242\350\257\225\351\242\23064-\346\261\2021+2+\342\200\246+n.py" "b/\351\235\242\350\257\225\351\242\23064.\346\261\2021+2+\342\200\246+n/\351\235\242\350\257\225\351\242\23064-\346\261\2021+2+\342\200\246+n.py" new file mode 100644 index 0000000..c8160ca --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23064.\346\261\2021+2+\342\200\246+n/\351\235\242\350\257\225\351\242\23064-\346\261\2021+2+\342\200\246+n.py" @@ -0,0 +1,7 @@ +class Solution(object): + def sumNums(self, n): + """ + :type n: int + :rtype: int + """ + return sum(range(1, n + 1)) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23065.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23065-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" "b/\351\235\242\350\257\225\351\242\23065.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23065-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" new file mode 100644 index 0000000..02652bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23065.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23065-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" @@ -0,0 +1,8 @@ +class Solution(object): + def add(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + return sum([a, b]) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" "b/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" new file mode 100644 index 0000000..bfacc69 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" @@ -0,0 +1,16 @@ +class Solution(object): + def constructArr(self, a): + """ + :type a: List[int] + :rtype: List[int] + """ + left = [1 for _ in a] + right = [1 for _ in a] + for i in range(1, len(a)): + left[i] = left[i - 1] * a[i - 1] + + for i in range(len(a) - 2, -1, -1): + right[i] = right[i + 1] * a[i + 1] + + return [left[i] * right[i] for i in range(len(a))] + \ No newline at end of file From defbc1ed71acb4430c12bb4a99911eac34bf0b4b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 8 Mar 2020 22:11:17 -0400 Subject: [PATCH 081/183] 2020-03-08 --- ...04\345\255\227\347\254\246\344\270\262.py" | 9 ++++++ ...346\263\241\345\274\200\345\205\263III.py" | 13 +++++++++ ...00\347\232\204\346\227\266\351\227\264.py" | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+) 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.py" create mode 100644 "1375.\347\201\257\346\263\241\345\274\200\345\205\263III/1375-\347\201\257\346\263\241\345\274\200\345\205\263III.py" create mode 100644 "1376.\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264/1376-\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264.py" 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.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.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.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/1375.\347\201\257\346\263\241\345\274\200\345\205\263III/1375-\347\201\257\346\263\241\345\274\200\345\205\263III.py" "b/1375.\347\201\257\346\263\241\345\274\200\345\205\263III/1375-\347\201\257\346\263\241\345\274\200\345\205\263III.py" new file mode 100644 index 0000000..124e9e3 --- /dev/null +++ "b/1375.\347\201\257\346\263\241\345\274\200\345\205\263III/1375-\347\201\257\346\263\241\345\274\200\345\205\263III.py" @@ -0,0 +1,13 @@ +class Solution(object): + def numTimesAllBlue(self, light): + """ + :type light: List[int] + :rtype: int + """ + res = 0 + maxx = 0 + for i in range(len(light)): + maxx = max(light[i] - 1, maxx) + if i == maxx: + res += 1 + return res \ No newline at end of file diff --git "a/1376.\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264/1376-\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264.py" "b/1376.\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264/1376-\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264.py" new file mode 100644 index 0000000..96b9996 --- /dev/null +++ "b/1376.\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264/1376-\351\200\232\347\237\245\346\211\200\346\234\211\345\221\230\345\267\245\346\211\200\351\234\200\347\232\204\346\227\266\351\227\264.py" @@ -0,0 +1,29 @@ +class Solution(object): + def numOfMinutes(self, n, headID, manager, informTime): + """ + :type n: int + :type headID: int + :type manager: List[int] + :type informTime: List[int] + :rtype: int + """ + from collections import defaultdict, deque + layer = defaultdict(set) + + for i in range(n): + layer[manager[i]].add(i) # key is the boss, val is the sub + + self.res = 0 + + def dfs(hid, time): + if hid not in layer: + self.res = max(self.res, time) + return + + for sub in layer[hid]: + dfs(sub, time + informTime[hid]) + + dfs(headID, 0) + return self.res + + \ No newline at end of file From e11fbb80c63008004fb409ddd4b01558e8a16745 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 8 Mar 2020 22:12:06 -0400 Subject: [PATCH 082/183] 2020-03-08 --- ...31\347\232\204\344\275\215\347\275\256.py" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "1377.T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256/1377-T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256.py" diff --git "a/1377.T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256/1377-T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256.py" "b/1377.T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256/1377-T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256.py" new file mode 100644 index 0000000..149bc23 --- /dev/null +++ "b/1377.T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256/1377-T\347\247\222\345\220\216\351\235\222\350\233\231\347\232\204\344\275\215\347\275\256.py" @@ -0,0 +1,42 @@ +class Solution(object): + def frogPosition(self, n, edges, t, target): + """ + :type n: int + :type edges: List[List[int]] + :type t: int + :type target: int + :rtype: float + """ + from collections import deque, defaultdict + + # 1. 寤哄浘 + adj = defaultdict(set) + for s, e in edges: + adj[s].add(e) + adj[e].add(s) + + # 2. 鍒濆鍖 DP 鏁扮粍 + # dp[k][node] 浠h〃鍦ㄧ k 绉掞紝铔ゅ浜 node 鐨勬鐜 + # dp[k][node] += dp[k - 1][parent] * prbability(parent -> node) + + dp = [[0 for _ in range(n + 1)] for _ in range(t + 1)] + dp[0][1] = 1 + + for time in range(1, t + 1): + for par in range(1, n + 1): + if dp[time - 1][par]: + if not adj[par]: + # 濡傛灉鏃犲鍙幓锛屽垯鍋滅暀鍦ㄥ師鍦 + dp[time][par] = dp[time - 1][par] + else: + # 鑳借烦灏辫烦 + for node in adj[par]: + dp[time][node] += dp[time - 1][par] * 1.0 / len(adj[par]) + + # 璺冲畬灏辨妸鐢ㄨ繃鐨勮竟鍒犳帀 + for node in adj[par]: + adj[node].remove(par) + adj[par] = set() + + return dp[t][target] + \ No newline at end of file From 3f041a7e13ad7d6c745f84aa0fa7ef9080a0d812 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 9 Mar 2020 17:46:24 -0400 Subject: [PATCH 083/183] 2020-03-09 --- ...21\347\232\204\347\233\264\345\276\204.py" | 12 ++---- ...00\345\244\247\344\273\267\345\200\274.py" | 22 +++++++++++ ...41\347\232\204\345\255\227\347\254\246.py" | 14 +++++++ ...54\345\205\261\350\212\202\347\202\271.py" | 39 +++++++++++++++++++ ...5\346\211\276\346\225\260\345\255\227I.py" | 8 ++++ ...61\347\232\204\346\225\260\345\255\227.py" | 16 ++++++++ ...4k\345\244\247\350\212\202\347\202\271.py" | 36 +++++++++++++++++ ...21\347\232\204\346\267\261\345\272\246.py" | 16 ++++++++ ...44\344\270\252\346\225\260\345\255\227.py" | 17 ++++++++ ...54\345\205\261\347\245\226\345\205\210.py" | 20 ++++++++++ ...54\345\205\261\347\245\226\345\205\210.py" | 23 +++++++++++ 11 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\23047.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\351\235\242\350\257\225\351\242\23047-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" create mode 100644 "\351\235\242\350\257\225\351\242\23050.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\351\235\242\350\257\225\351\242\23050-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" create mode 100644 "\351\235\242\350\257\225\351\242\23052.\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/\351\235\242\350\257\225\351\242\23052-\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 "\351\235\242\350\257\225\351\242\23053-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/\351\235\242\350\257\225\351\242\23053-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 "\351\235\242\350\257\225\351\242\23053-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23053-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\351\235\242\350\257\225\351\242\23054.\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/\351\235\242\350\257\225\351\242\23054-\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 "\351\235\242\350\257\225\351\242\23055-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\351\235\242\350\257\225\351\242\23055-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" create mode 100644 "\351\235\242\350\257\225\351\242\23057.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23057-\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 "\351\235\242\350\257\225\351\242\23068-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" create mode 100644 "\351\235\242\350\257\225\351\242\23068-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" diff --git "a/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" "b/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" index 49542b5..8814891 100644 --- "a/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" +++ "b/0543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/0543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" @@ -13,14 +13,8 @@ def diameterOfBinaryTree(self, root): """ if not root: return 0 - self.res = 0 - def height(node): + def Height(node): if not node: return 0 - left_h = height(node.left) - right_h = height(node.right) - - self.res = max(self.res, left_h + right_h) - return 1 + max(left_h, right_h) - height(root) - return self.res \ No newline at end of file + return 1 + max(Height(node.left), Height(node.right)) + return max(self.diameterOfBinaryTree(root.left), Height(root.left) + Height(root.right), self.diameterOfBinaryTree(root.right)) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23047.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\351\235\242\350\257\225\351\242\23047-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" "b/\351\235\242\350\257\225\351\242\23047.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\351\235\242\350\257\225\351\242\23047-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" new file mode 100644 index 0000000..86bf71d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23047.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\351\235\242\350\257\225\351\242\23047-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" @@ -0,0 +1,22 @@ +class Solution(object): + def maxValue(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]) + + for i in range(1, n): + grid[0][i] += grid[0][i - 1] + + for i in range(1, m): + grid[i][0] += grid[i - 1][0] + + for i in range(1, m): + for j in range(1, n): + grid[i][j] += max(grid[i - 1][j], grid[i][j - 1]) + + return grid[-1][-1] + \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23050.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\351\235\242\350\257\225\351\242\23050-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" "b/\351\235\242\350\257\225\351\242\23050.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\351\235\242\350\257\225\351\242\23050-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" new file mode 100644 index 0000000..817227e --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23050.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\351\235\242\350\257\225\351\242\23050-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" @@ -0,0 +1,14 @@ +class Solution(object): + def firstUniqChar(self, s): + """ + :type s: str + :rtype: str + """ + from collections import Counter + + dic = Counter(s) + + for ch in s: + if dic[ch] == 1: + return ch + return " " \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23052.\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/\351\235\242\350\257\225\351\242\23052-\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/\351\235\242\350\257\225\351\242\23052.\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/\351\235\242\350\257\225\351\242\23052-\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..120f097 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23052.\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/\351\235\242\350\257\225\351\242\23052-\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,39 @@ +# 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 + """ + 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 + + cnt = la - lb + p = headA + while cnt: + cnt -= 1 + p = p.next + + + while p != headB: + p = p.next + headB = headB.next + return p \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23053-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/\351\235\242\350\257\225\351\242\23053-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/\351\235\242\350\257\225\351\242\23053-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/\351\235\242\350\257\225\351\242\23053-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..8b4c0c6 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23053-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/\351\235\242\350\257\225\351\242\23053-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,8 @@ +class Solution(object): + def search(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: int + """ + return nums.count(target) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23053-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23053-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\23053-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23053-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..f15c45d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23053-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23053-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,16 @@ +class Solution(object): + def missingNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + for i, num in enumerate(nums): + if num == len(nums): + continue + if num != i: + nums[num], nums[i] = nums[i], nums[num] + + for i in range(len(nums)): + if nums[i] != i: + return i + return len(nums) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23054.\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/\351\235\242\350\257\225\351\242\23054-\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/\351\235\242\350\257\225\351\242\23054.\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/\351\235\242\350\257\225\351\242\23054-\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..6d799dd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23054.\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/\351\235\242\350\257\225\351\242\23054-\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,36 @@ +# 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 kthLargest(self, root, k): + """ + :type root: TreeNode + :type k: int + :rtype: int + """ + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + return inorder(root)[-k] +# self.res = None +# def dfs(node, left): +# if not node: +# return None + +# if not self.res: +# dfs(node.right, left) +# if node.right: +# left -= 1 +# if left == 1: +# self.res = node.val +# return +# dfs(node.left, left - 1) + +# dfs(root, k) +# return self.res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23055-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\351\235\242\350\257\225\351\242\23055-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" "b/\351\235\242\350\257\225\351\242\23055-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\351\235\242\350\257\225\351\242\23055-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..e3b62e7 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23055-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\351\235\242\350\257\225\351\242\23055-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" @@ -0,0 +1,16 @@ +# 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 maxDepth(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23057.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23057-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\23057.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23057-\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..b1a4b6d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23057.\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23057-\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,17 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + left, right = 0, len(nums) - 1 + while left < right: + s = nums[left] + nums[right] + + if s == target: + return [nums[left], nums[right]] + elif s > target: + right -= 1 + else: + left += 1 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23068-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\351\235\242\350\257\225\351\242\23068-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" new file mode 100644 index 0000000..a00d561 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23068-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.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 lowestCommonAncestor(self, root, p, q): + """ + :type root: TreeNode + :type p: TreeNode + :type q: TreeNode + :rtype: TreeNode + """ + if min(p.val, q.val) <= root.val <= max(p.val, q.val): + return root + if max(p.val, q.val) < root.val: + return self.lowestCommonAncestor(root.left, p, q) + return self.lowestCommonAncestor(root.right, p, q) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23068-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\351\235\242\350\257\225\351\242\23068-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" new file mode 100644 index 0000000..09cbf64 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23068-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\351\235\242\350\257\225\351\242\23068-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.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 lowestCommonAncestor(self, root, p, q): + """ + :type root: TreeNode + :type p: TreeNode + :type q: TreeNode + :rtype: TreeNode + """ + if root in [None, p, q]: + return root + left = self.lowestCommonAncestor(root.left, p, q) + right = self.lowestCommonAncestor(root.right, p, q) + + if left and right: + return root + return left or right \ No newline at end of file From 6fe5d432490ea1655bbede2991884d195185d930 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 10 Mar 2020 22:29:56 -0400 Subject: [PATCH 084/183] 2020-03-10 --- ...11\344\270\252\351\203\250\345\210\206.py" | 3 +-- ...67\347\232\204\345\212\240\346\263\225.py" | 8 ++++++ ...8-\351\233\266\347\237\251\351\230\265.py" | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\230 17.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\230 17.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" create mode 100644 "\351\235\242\350\257\225\351\242\23001.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.08-\351\233\266\347\237\251\351\230\265.py" diff --git "a/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" "b/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" index de497d7..efb0d49 100644 --- "a/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" +++ "b/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" @@ -4,7 +4,6 @@ def canThreePartsEqualSum(self, A): :type A: List[int] :rtype: bool """ - # from collections import defaultdict target = sum(A) // 3 snow = 0 cnt = 0 @@ -13,4 +12,4 @@ def canThreePartsEqualSum(self, A): if target == snow: snow = 0 cnt += 1 - return cnt == 3 \ No newline at end of file + return cnt >= 3 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\230 17.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\230 17.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" "b/\351\235\242\350\257\225\351\242\230 17.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\230 17.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" new file mode 100644 index 0000000..02652bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\230 17.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\230 17.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" @@ -0,0 +1,8 @@ +class Solution(object): + def add(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + return sum([a, b]) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.08-\351\233\266\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\23001.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.08-\351\233\266\347\237\251\351\230\265.py" new file mode 100644 index 0000000..01d1edd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.08.\351\233\266\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.08-\351\233\266\347\237\251\351\230\265.py" @@ -0,0 +1,25 @@ +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]) + + row0, col0 = set(), set() + + for i in range(m): + for j in range(n): + if not matrix[i][j]: + row0.add(i) + col0.add(j) + + for i in range(m): + for j in range(n): + if i in row0 or j in col0: + matrix[i][j] = 0 + + return matrix \ No newline at end of file From 479d34efc06934361b3428df35e418858a964e49 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 11 Mar 2020 19:29:06 -0400 Subject: [PATCH 085/183] 2020-03-11 --- ...44\247\345\205\254\345\233\240\345\255\220.py" | 15 +++++++++++++++ ...34\200\345\244\247\346\225\260\345\200\274.py" | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 "1071.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/1071-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.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.py" diff --git "a/1071.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/1071-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" "b/1071.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/1071-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" new file mode 100644 index 0000000..12efd30 --- /dev/null +++ "b/1071.\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220/1071-\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.py" @@ -0,0 +1,15 @@ +class Solution(object): + def gcdOfStrings(self, str1, str2): + """ + :type str1: str + :type str2: str + :rtype: str + """ + if len(str1) < len(str2): + str1, str2 = str2, str1 + + for i in range(len(str2), 0, -1): + + if len(str1) % i == 0 and str2[:i] * (len(str1) / i) == str1 and len(str2) % i == 0 and str2[:i] * (len(str2) / i) == str2: + return str2[:i] + return "" \ 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.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.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.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 From d7030e823a1dc9aa81be19fd6518982c4dfaf912 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 12 Mar 2020 23:35:26 -0400 Subject: [PATCH 086/183] 2020-03-12 --- ...9-\345\244\232\346\225\260\345\205\203\347\264\240.py" | 8 ++++++++ 1 file changed, 8 insertions(+) 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.py" 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.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.py" new file mode 100644 index 0000000..5a6e115 --- /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.py" @@ -0,0 +1,8 @@ +class Solution(object): + def majorityElement(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + nums.sort() + return nums[len(nums) // 2] \ No newline at end of file From 990ebddf9304d0f9c84af9665a1578d3870174f8 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 13 Mar 2020 23:28:54 -0400 Subject: [PATCH 087/183] 2020-03-13 --- ...32\346\225\260\345\205\203\347\264\240.py" | 15 +++++++++-- ...07\345\255\220\345\272\217\345\210\227.py" | 25 ++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) 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.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.py" index 5a6e115..858b7a2 100644 --- "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.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.py" @@ -4,5 +4,16 @@ def majorityElement(self, nums): :type nums: List[int] :rtype: int """ - nums.sort() - return nums[len(nums) // 2] \ No newline at end of file + 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/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/0300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" "b/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/0300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" index 1582530..f5fcf2e 100644 --- "a/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/0300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" +++ "b/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/0300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" @@ -4,22 +4,11 @@ def lengthOfLIS(self, nums): :type nums: List[int] :rtype: int """ - l = len(nums) - if not l: - return 0 - dp = [1 for _ in range(l)] + dp = [1 for _ in nums] - for index, item in enumerate(nums): - dp[index] = self.find(nums[:index + 1], dp) + 1 - # print dp - return max(dp) - - - def find(self, nums, dp): - max_element = -1 * 2 << 31 - - for i in range(len(nums) - 2, -1, -1): - if nums[i] < nums[-1]: - max_element = max(max_element, dp[i]) - - return max_element if max_element != -1 * 2 << 31 else 0 \ No newline at end of file + for i in range(len(nums)): + for j in range(i): + if nums[i] > nums[j]: + dp[i] = max(dp[i], dp[j] + 1) + + return max(dp) if dp else 0 \ No newline at end of file From 480be5bdbb2e9d9daeade46190838312dfb3bd95 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 15 Mar 2020 23:47:34 -0400 Subject: [PATCH 088/183] 2020-03-15 --- ...46\344\270\262\345\216\213\347\274\251.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23001.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\23001.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" diff --git "a/\351\235\242\350\257\225\351\242\23001.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\23001.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\23001.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\23001.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" new file mode 100644 index 0000000..17bc3fc --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.06.\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251/\351\235\242\350\257\225\351\242\23001.06-\345\255\227\347\254\246\344\270\262\345\216\213\347\274\251.py" @@ -0,0 +1,23 @@ +class Solution(object): + def compressString(self, S): + """ + :type S: str + :rtype: str + """ + pre = None + cnt = 0 + res = "" + for ch in S: + if not pre: + cnt += 1 + pre = ch + else: + if ch == pre: + cnt += 1 + else: + res += pre + str(cnt) + cnt = 1 + pre = ch + if S: + res += pre + str(cnt) + return res if len(res) < len(S) else S \ No newline at end of file From 69116ae5c5e36722333eef56c0352cecca2a25e0 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 16 Mar 2020 23:06:20 -0400 Subject: [PATCH 089/183] 2020-03-16 --- ...74\345\206\231\345\215\225\350\257\215.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "1160.\346\213\274\345\206\231\345\215\225\350\257\215/1160-\346\213\274\345\206\231\345\215\225\350\257\215.py" diff --git "a/1160.\346\213\274\345\206\231\345\215\225\350\257\215/1160-\346\213\274\345\206\231\345\215\225\350\257\215.py" "b/1160.\346\213\274\345\206\231\345\215\225\350\257\215/1160-\346\213\274\345\206\231\345\215\225\350\257\215.py" new file mode 100644 index 0000000..910aacb --- /dev/null +++ "b/1160.\346\213\274\345\206\231\345\215\225\350\257\215/1160-\346\213\274\345\206\231\345\215\225\350\257\215.py" @@ -0,0 +1,23 @@ +class Solution(object): + def countCharacters(self, words, chars): + """ + :type words: List[str] + :type chars: str + :rtype: int + """ + res = 0 + from collections import Counter + + dic_a = Counter(chars) + + for word in words: + dic_w = Counter(word) + flag = 1 + for key, val in dic_w.items(): + if key not in dic_a or dic_a[key] < val: + flag = 0 + break + if flag: + res += len(word) + + return res \ No newline at end of file From bcac4d772afa1eaaa87c8876f8a70fc5cd0df2d4 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 18 Mar 2020 00:35:00 -0400 Subject: [PATCH 090/183] 2020-03-18 --- ...347\237\251\345\275\242\351\207\215\345\217\240.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "0836.\347\237\251\345\275\242\351\207\215\345\217\240/0836-\347\237\251\345\275\242\351\207\215\345\217\240.py" diff --git "a/0836.\347\237\251\345\275\242\351\207\215\345\217\240/0836-\347\237\251\345\275\242\351\207\215\345\217\240.py" "b/0836.\347\237\251\345\275\242\351\207\215\345\217\240/0836-\347\237\251\345\275\242\351\207\215\345\217\240.py" new file mode 100644 index 0000000..a13282d --- /dev/null +++ "b/0836.\347\237\251\345\275\242\351\207\215\345\217\240/0836-\347\237\251\345\275\242\351\207\215\345\217\240.py" @@ -0,0 +1,10 @@ +class Solution(object): + def isRectangleOverlap(self, rec1, rec2): + """ + :type rec1: List[int] + :type rec2: List[int] + :rtype: bool + """ + x1, y1, x2, y2 = rec1 + x3, y3, x4, y4 = rec2 + return (x3 - x2) * (x4 - x1) < 0 and (y3 - y2) * (y4 - y1) < 0 \ No newline at end of file From a018d24a92412a680e0ba813a5dc2af7816ac3fa Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 18 Mar 2020 23:58:19 -0400 Subject: [PATCH 091/183] 2020-03-18 --- ...225\277\345\233\236\346\226\207\344\270\262.py" | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git "a/0409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/0409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" "b/0409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/0409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" index 10c4522..1acf581 100644 --- "a/0409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/0409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" +++ "b/0409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/0409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" @@ -4,16 +4,4 @@ def longestPalindrome(self, s): :type s: str :rtype: int """ - record = [0 for i in range(0, 129)] - for char in s: - record[ord(char)] += 1 - - res, flag = 0, 0 - for i, x in enumerate(record): - if x % 2 == 1: - res += x - 1 - flag = 1 - else: - res += x - # print res - return res + flag \ No newline at end of file + return len(s) -max(0,sum([s.count(i)%2 for i in set(s)])-1) \ No newline at end of file From 1e69cf057957a84fcec97e019ab030a9af8bca14 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 19 Mar 2020 22:13:30 -0400 Subject: [PATCH 092/183] 2020-03-19 --- ...04\345\271\270\350\277\220\346\225\260.py" | 15 ++++++++ ...15\344\275\234\347\232\204\346\240\210.py" | 38 +++++++++++++++++++ ...21\345\217\230\345\271\263\350\241\241.py" | 30 +++++++++++++++ ...37\350\241\250\347\216\260\345\200\274.py" | 29 ++++++++++++++ ...7\347\232\204k\344\270\252\346\225\260.py" | 12 +++++- 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 "1380.\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1380-\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" create mode 100644 "1381.\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210/1381-\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210.py" create mode 100644 "1382.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241/1382-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241.py" create mode 100644 "1383.\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274/1383-\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274.py" diff --git "a/1380.\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1380-\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" "b/1380.\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1380-\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" new file mode 100644 index 0000000..29235f9 --- /dev/null +++ "b/1380.\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1380-\347\237\251\351\230\265\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" @@ -0,0 +1,15 @@ +class Solution(object): + def luckyNumbers (self, matrix): + """ + :type matrix: List[List[int]] + :rtype: List[int] + """ + row, col = set(), set() + + for r in matrix: + row.add(min(r)) + + for c in zip(*matrix): + col.add(max(c)) + + return list(row & col) \ No newline at end of file diff --git "a/1381.\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210/1381-\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210.py" "b/1381.\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210/1381-\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210.py" new file mode 100644 index 0000000..98e67dd --- /dev/null +++ "b/1381.\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210/1381-\350\256\276\350\256\241\344\270\200\344\270\252\346\224\257\346\214\201\345\242\236\351\207\217\346\223\215\344\275\234\347\232\204\346\240\210.py" @@ -0,0 +1,38 @@ +class CustomStack(object): + + def __init__(self, maxSize): + """ + :type maxSize: int + """ + self.stack = [] + self.maxSize = maxSize + def push(self, x): + """ + :type x: int + :rtype: None + """ + if len(self.stack) < self.maxSize: + self.stack.append(x) + + def pop(self): + """ + :rtype: int + """ + return self.stack.pop() if self.stack else -1 + + + def increment(self, k, val): + """ + :type k: int + :type val: int + :rtype: None + """ + for i in range(min(k, len(self.stack))): + self.stack[i] += val + + +# Your CustomStack object will be instantiated and called as such: +# obj = CustomStack(maxSize) +# obj.push(x) +# param_2 = obj.pop() +# obj.increment(k,val) \ No newline at end of file diff --git "a/1382.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241/1382-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241.py" "b/1382.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241/1382-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241.py" new file mode 100644 index 0000000..d49e963 --- /dev/null +++ "b/1382.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241/1382-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\217\230\345\271\263\350\241\241.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 balanceBST(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + l = inorder(root) + + def generator(l): + if not l: + return None + idx = len(l) // 2 + root = TreeNode(l[idx]) + root.left = generator(l[:idx]) + root.right = generator(l[idx + 1:]) + return root + + return generator(l) \ No newline at end of file diff --git "a/1383.\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274/1383-\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274.py" "b/1383.\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274/1383-\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274.py" new file mode 100644 index 0000000..8fc30fe --- /dev/null +++ "b/1383.\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274/1383-\346\234\200\345\244\247\347\232\204\345\233\242\351\230\237\350\241\250\347\216\260\345\200\274.py" @@ -0,0 +1,29 @@ +class Solution(object): + def maxPerformance(self, n, speed, efficiency, k): + """ + :type n: int + :type speed: List[int] + :type efficiency: List[int] + :type k: int + :rtype: int + """ + from heapq import * + combine = [(speed[i], efficiency[i]) for i in range(n)] + combine = sorted(combine, key = lambda x: - x[1]) + res = 0 + MOD = 10 ** 9 + 7 + min_heap = [] + speed_sum = 0 + for i in range(n): + s, e = combine[i] + if len(min_heap) < k: + heappush(min_heap, s) + speed_sum += s + else: + if min_heap and min_heap[0] < s: + speed_sum = speed_sum - min_heap[0] + s + heappush(min_heap, s) + heappop(min_heap) + + res = max(res, speed_sum * e) + return res % MOD \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" "b/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" index 35e1ef0..50bd4bf 100644 --- "a/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" +++ "b/\351\235\242\350\257\225\351\242\23040.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\351\235\242\350\257\225\351\242\23040-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" @@ -5,4 +5,14 @@ def getLeastNumbers(self, arr, k): :type k: int :rtype: List[int] """ - return sorted(arr)[:k] \ No newline at end of file + from heapq import * + + queue = [] + for num in arr: + if len(queue) < k: + heappush(queue, -num) + else: + if queue and queue[0] < num: + heappush(queue, -num) + heappop(queue) + return [-item for item in queue] \ No newline at end of file From b5c11774891aab50722a3c33e7eaa4e90a949956 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 21 Mar 2020 00:45:09 -0400 Subject: [PATCH 093/183] 2020-03-21 --- ...64\345\243\266\351\227\256\351\242\230.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "0365.\346\260\264\345\243\266\351\227\256\351\242\230/0365-\346\260\264\345\243\266\351\227\256\351\242\230.py" diff --git "a/0365.\346\260\264\345\243\266\351\227\256\351\242\230/0365-\346\260\264\345\243\266\351\227\256\351\242\230.py" "b/0365.\346\260\264\345\243\266\351\227\256\351\242\230/0365-\346\260\264\345\243\266\351\227\256\351\242\230.py" new file mode 100644 index 0000000..29817d8 --- /dev/null +++ "b/0365.\346\260\264\345\243\266\351\227\256\351\242\230/0365-\346\260\264\345\243\266\351\227\256\351\242\230.py" @@ -0,0 +1,21 @@ +class Solution(object): + def canMeasureWater(self, x, y, z): + """ + :type x: int + :type y: int + :type z: int + :rtype: bool + """ + if not z: + return True + if not x: + return y == z + if not y: + return x == z + if x + y < z: + return False + def gcd(a, b): + while a % b: + a, b = b, a % b + return b + return not z % gcd(x, y) \ No newline at end of file From 547f53a51b54fb1f2bc2295d94f16cb0d7f54074 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 27 Mar 2020 18:43:43 -0400 Subject: [PATCH 094/183] 2020-03-27 --- ...13\347\274\251\347\274\226\347\240\201.py" | 36 ++++++++++++++++++ ...41\347\211\214\345\210\206\347\273\204.py" | 37 +++---------------- 2 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 "0820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/0820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" diff --git "a/0820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/0820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" "b/0820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/0820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" new file mode 100644 index 0000000..618a6c9 --- /dev/null +++ "b/0820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/0820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" @@ -0,0 +1,36 @@ +class Trie(object): + def __init__(self): + """ + Initialize your data structure here. + """ + self.root = {} + self.char_cnt = 0 # 缁熻 a - z 瀛楃涓暟 + self.word_cnt = 0 # 缁熻缁撳熬绗 # 涓暟 + def insert(self, word): + """ + Inserts a word into the trie. + :type word: str + :rtype: None + """ + node = self.root + for char in word: # word 鍏ユ爲 + node = node.setdefault(char, {}) + + if not node: # not node 灏变唬琛ㄥ綋鍓 word 涓嶆槸涔嬪墠鏌愪竴 word 鐨勫悗缂 + self.word_cnt += 1 + self.char_cnt += len(word) + node["end"] = True + +class Solution(object): + def minimumLengthEncoding(self, words): + """ + :type words: List[str] + :rtype: int + """ + ttree = Trie() + + for word in sorted(words, key = lambda x:len(x), reverse = True): + # 鎸夐暱搴︾敱澶у埌灏忔帓搴忥紝鍐嶅皢姣忎釜 word 鍙嶅悜鎻掑叆鏍 + ttree.insert(word[::-1]) + # print ttree.char_cnt, ttree.word_cnt + return ttree.char_cnt + ttree.word_cnt \ No newline at end of file diff --git "a/0914.\345\215\241\347\211\214\345\210\206\347\273\204/0914-\345\215\241\347\211\214\345\210\206\347\273\204.py" "b/0914.\345\215\241\347\211\214\345\210\206\347\273\204/0914-\345\215\241\347\211\214\345\210\206\347\273\204.py" index 224b036..609c27e 100644 --- "a/0914.\345\215\241\347\211\214\345\210\206\347\273\204/0914-\345\215\241\347\211\214\345\210\206\347\273\204.py" +++ "b/0914.\345\215\241\347\211\214\345\210\206\347\273\204/0914-\345\215\241\347\211\214\345\210\206\347\273\204.py" @@ -1,36 +1,11 @@ class Solution(object): - def hasGroupsSizeX( self,deck): + def hasGroupsSizeX(self, deck): """ :type deck: List[int] :rtype: bool """ - if len(deck) <=0: - return False - deck.sort() - print deck - a = deck[0] - count = deck.count(a) - if count < 2: - return False - for j in range(2, count +1): - if len(deck) % j != 0: - continue - print "invalid length",j,len(deck) - for i in range(0, len(deck),j): - temp = deck[i] - flag = 0 - print i,temp - for k in range(i,i+j): - if deck[k] != temp: - flag = 1 - print "not the same",deck[k],temp - if flag == 1: - break - if flag == 1: - continue - return True - return False - - - - \ No newline at end of file + def gcd(a, b): + while b: + a, b = b, a % b + return a + return functools.reduce(gcd, collections.Counter(deck).values()) >= 2 \ No newline at end of file From 0ea2d7ba71441c5edbb3cf94474a4e616f9df00a Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 27 Mar 2020 18:45:02 -0400 Subject: [PATCH 095/183] 2020-03-27 --- ...56\346\240\207\346\225\260\347\273\204.py" | 11 +++++++ ...0-\345\233\233\345\233\240\346\225\260.py" | 19 +++++++++++ ...11\346\225\210\350\267\257\345\276\204.py" | 33 +++++++++++++++++++ ...53\344\271\220\345\211\215\347\274\200.py" | 20 +++++++++++ 4 files changed, 83 insertions(+) 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.py" create mode 100644 "1390.\345\233\233\345\233\240\346\225\260/1390-\345\233\233\345\233\240\346\225\260.py" create mode 100644 "1391.\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204/1391-\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204.py" create mode 100644 "1392.\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200/1392-\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200.py" 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.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.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.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/1390.\345\233\233\345\233\240\346\225\260/1390-\345\233\233\345\233\240\346\225\260.py" "b/1390.\345\233\233\345\233\240\346\225\260/1390-\345\233\233\345\233\240\346\225\260.py" new file mode 100644 index 0000000..3044a40 --- /dev/null +++ "b/1390.\345\233\233\345\233\240\346\225\260/1390-\345\233\233\345\233\240\346\225\260.py" @@ -0,0 +1,19 @@ +class Solution(object): + def sumFourDivisors(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + def factor(n): + l = [] + for i in range(1, int(n ** 0.5) + 1): + if n % i == 0: + l.append(i) + if n / i != i: + l.append(n / i) + if len(l) > 4: + break + + return sum(l) if len(l) == 4 else 0 + + return sum(map(factor, nums)) \ No newline at end of file diff --git "a/1391.\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204/1391-\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204.py" "b/1391.\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204/1391-\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204.py" new file mode 100644 index 0000000..47fd706 --- /dev/null +++ "b/1391.\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204/1391-\346\243\200\346\237\245\347\275\221\346\240\274\344\270\255\346\230\257\345\220\246\345\255\230\345\234\250\346\234\211\346\225\210\350\267\257\345\276\204.py" @@ -0,0 +1,33 @@ +class Solution(object): + def hasValidPath(self, grid): + """ + :type grid: List[List[int]] + :rtype: bool + """ + m, n = len(grid), len(grid[0]) + dir = {} + dir[1] = [0, 1, 0, 1] + dir[2] = [1, 0, 1, 0] + dir[3] = [0, 0, 1, 1] + dir[4] = [0, 1, 1, 0] + dir[5] = [1, 0, 0, 1] + dir[6] = [1, 1, 0, 0] + + dx = [-1, 0, 1, 0] + dy = [0, 1, 0, -1] + queue = [(0, 0)] + visited = set(queue) + + cor = {0:2, 1:3, 3:1, 2:0} + while queue: + x0, y0 = queue.pop() + if [x0, y0] == [m - 1, n - 1]: + return True + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + if 0 <= x < m and 0 <= y < n and (x, y) not in visited and dir[grid[x0][y0]][k] & dir[grid[x][y]][cor[k]]: + visited.add((x, y)) + queue.append((x, y)) + return False + diff --git "a/1392.\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200/1392-\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200.py" "b/1392.\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200/1392-\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200.py" new file mode 100644 index 0000000..418bd1e --- /dev/null +++ "b/1392.\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200/1392-\346\234\200\351\225\277\345\277\253\344\271\220\345\211\215\347\274\200.py" @@ -0,0 +1,20 @@ +class Solution(object): + def longestPrefix(self, s): + """ + :type s: str + :rtype: str + """ + base = 131 + mod = 10 ** 9 + 7 + res = "" + prefix, suffix = 0, 0 + multiple = 1 + for i in range(len(s) - 1): + prefix = (prefix * base + ord(s[i])) % mod + suffix = (ord(s[-(i + 1)]) * multiple + suffix) % mod + if prefix == suffix: + res = s[:i + 1] + + multiple = multiple * base % mod + + return res \ No newline at end of file From 260cc00a608a681791ace02b6c25be4a5bc2ebe5 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 29 Mar 2020 01:16:44 -0400 Subject: [PATCH 096/183] 2020-03-29 --- ...60\345\233\276\345\210\206\346\236\220.py" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "1162.\345\234\260\345\233\276\345\210\206\346\236\220/1162-\345\234\260\345\233\276\345\210\206\346\236\220.py" diff --git "a/1162.\345\234\260\345\233\276\345\210\206\346\236\220/1162-\345\234\260\345\233\276\345\210\206\346\236\220.py" "b/1162.\345\234\260\345\233\276\345\210\206\346\236\220/1162-\345\234\260\345\233\276\345\210\206\346\236\220.py" new file mode 100644 index 0000000..b1dbb0c --- /dev/null +++ "b/1162.\345\234\260\345\233\276\345\210\206\346\236\220/1162-\345\234\260\345\233\276\345\210\206\346\236\220.py" @@ -0,0 +1,38 @@ +class Solution(object): + def maxDistance(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + from collections import deque + m, n = len(grid), len(grid[0]) + land = [] + for i in range(m): + for j in range(n): + if grid[i][j] == 1: + land.append((i, j)) + + if not land or len(land) == m * n: + return -1 + + res = 0 + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + + queue = deque(land) + visited = set(land) + while queue: + for _ in range(len(queue)): + x0, y0 = queue.popleft() + + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and grid[x][y] == 0 and (x, y) not in visited: + queue.append((x, y)) + visited.add((x, y)) + res += 1 + return res - 1 + + \ No newline at end of file From 882032a29ab92fc65b39c0068aab33b926df0b5f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 29 Mar 2020 23:46:24 -0400 Subject: [PATCH 097/183] 2020-03-29 --- ...344\270\213\347\232\204\346\225\260\345\255\227.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23062.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23062-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" diff --git "a/\351\235\242\350\257\225\351\242\23062.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23062-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\23062.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23062-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..9690d6d --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23062.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23062-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def lastRemaining(self, n, m): + """ + :type n: int + :type m: int + :rtype: int + """ + if n == 1: + return 0 + return (self.lastRemaining(n - 1, m) + m) % n \ No newline at end of file From bec01230d8acc1b2189fc9215dca108d1ace300b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 31 Mar 2020 23:54:45 -0400 Subject: [PATCH 098/183] 2020-03-31 --- ...232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git "a/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" "b/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" index efb0d49..295c1c0 100644 --- "a/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" +++ "b/1013.\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206/1013-\345\260\206\346\225\260\347\273\204\345\210\206\346\210\220\345\222\214\347\233\270\347\255\211\347\232\204\344\270\211\344\270\252\351\203\250\345\210\206.py" @@ -4,6 +4,7 @@ def canThreePartsEqualSum(self, A): :type A: List[int] :rtype: bool """ + # from collections import defaultdict target = sum(A) // 3 snow = 0 cnt = 0 @@ -12,4 +13,4 @@ def canThreePartsEqualSum(self, A): if target == snow: snow = 0 cnt += 1 - return cnt >= 3 \ No newline at end of file + return cnt >= 3 From 0886f300415f167db49cdd865cff16484e26b9cb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 1 Apr 2020 23:49:01 -0400 Subject: [PATCH 099/183] 2020-04-01 --- ...14\345\245\227\346\267\261\345\272\246.py" | 17 ++++++++++++ ...46\344\270\262\350\275\256\350\275\254.py" | 8 ++++++ ...15\345\244\215\350\212\202\347\202\271.py" | 26 +++++++++++++++++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 22 ++++++++++++++++ ...55\351\227\264\350\212\202\347\202\271.py" | 19 ++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 "1111.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/1111-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.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.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.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.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.py" diff --git "a/1111.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/1111-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" "b/1111.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/1111-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" new file mode 100644 index 0000000..026e2ec --- /dev/null +++ "b/1111.\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246/1111-\346\234\211\346\225\210\346\213\254\345\217\267\347\232\204\345\265\214\345\245\227\346\267\261\345\272\246.py" @@ -0,0 +1,17 @@ +class Solution(object): + def maxDepthAfterSplit(self, seq): + """ + :type seq: str + :rtype: List[int] + """ + par_cnt = 0 + res = [0 for _ in seq] + + for i, par in enumerate(seq): + if par == "(": + par_cnt += 1 + res[i] = par_cnt % 2 + else: + res[i] = par_cnt % 2 + par_cnt -= 1 + return res \ 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.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.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.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.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.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.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.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.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.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.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.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.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 From a513c8c062d1eafd87dba7372b206949559219bd Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 16 Apr 2020 01:10:43 -0400 Subject: [PATCH 100/183] 2020-04-16 --- ...10\345\271\266\345\214\272\351\227\264.py" | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git "a/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" "b/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" index 04c87a0..c005fbe 100644 --- "a/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" +++ "b/0056.\345\220\210\345\271\266\345\214\272\351\227\264/0056-\345\220\210\345\271\266\345\214\272\351\227\264.py" @@ -4,18 +4,21 @@ def merge(self, intervals): :type intervals: List[List[int]] :rtype: List[List[int]] """ - if not intervals: + if not intervals or not intervals[0]: return intervals - intervals = sorted(intervals, key = lambda x: x[0]) - start, end = intervals[0][0], intervals[0][1] + intervals = sorted(intervals, key = lambda x:x[0]) + res = [] - for i, interval in enumerate(intervals): - if interval[0] > end: - res.append([start, end]) - start, end = interval[0], interval[1] + start, end = intervals[0][0], intervals[0][1] + for interval in intervals: + s, e = interval[0], interval[1] + + if s <= end: # overlap + end = max(end, e) else: - end = max(end, interval[1]) + res.append([start, end]) + start, end = s, e + res.append([start, end]) - return res - \ No newline at end of file + return res \ No newline at end of file From e6972d325d82e40a57404a15100a7f6f16c378dc Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 9 May 2020 14:05:36 -0400 Subject: [PATCH 101/183] 2020-05-09 --- ...04\345\271\263\346\226\271\346\240\271.py" | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) 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.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.py" index ed61097..e4e3e3c 100644 --- "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.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.py" @@ -4,18 +4,14 @@ def mySqrt(self, x): :type x: int :rtype: int """ - if not x : - return 0 - if x < 4: - return 1 - start, end = 2, x // 2 - while 1: - i = (start + end) // 2 - if i ** 2 <= x and (i + 1) ** 2 >x: - return i - elif i ** 2 < x: - start = i + 1 - elif i ** 2 > x: - end = i - 1 - - \ No newline at end of file + 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 From 279f90dcdcf048e786393e2f998a2fb2039a94de Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 10 May 2020 13:08:45 -0400 Subject: [PATCH 102/183] 2020-05-10 --- 0050.Pow(x,n)/0050-Pow(x,n).py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/0050.Pow(x,n)/0050-Pow(x,n).py b/0050.Pow(x,n)/0050-Pow(x,n).py index 4d7478f..47442e6 100644 --- a/0050.Pow(x,n)/0050-Pow(x,n).py +++ b/0050.Pow(x,n)/0050-Pow(x,n).py @@ -1,22 +1,8 @@ class Solution(object): - def myPow(self, x0, n): + def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ - if not n: - return 1 - def helper(x, n, tmp): - print n, x - if n <= 1: - return x * tmp - if n % 2: - tmp *= x - n -= 1 - return helper(x * x, n // 2, tmp) - op = 1 - if n < 0: - op = -1 - res = helper(x0, abs(n), 1) - return res if op > 0 else 1.0/res \ No newline at end of file + return x ** n \ No newline at end of file From c883ca134061ac2a4f1f1cfaa8234b8970ecf003 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 10 May 2020 13:09:36 -0400 Subject: [PATCH 103/183] 2020-05-10 --- ...273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" "b/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" index bfacc69..5c9dd47 100644 --- "a/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" +++ "b/\351\235\242\350\257\225\351\242\23066.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\351\235\242\350\257\225\351\242\23066-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" @@ -12,5 +12,4 @@ def constructArr(self, a): for i in range(len(a) - 2, -1, -1): right[i] = right[i + 1] * a[i + 1] - return [left[i] * right[i] for i in range(len(a))] - \ No newline at end of file + return [left[i] * right[i] for i in range(len(a))] \ No newline at end of file From e3d45284799f0803436b9f9d7bfeadfecaed8419 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 10 May 2020 13:11:09 -0400 Subject: [PATCH 104/183] 2020-05-10 --- ...11\345\272\217\351\223\276\350\241\250.py" | 18 +++---- ...47\345\255\220\345\272\217\345\222\214.py" | 14 +++--- ...11\346\220\234\347\264\242\346\240\221.py" | 8 ++-- ...47\346\255\243\346\226\271\345\275\242.py" | 47 +++++++------------ ...21\347\232\204\345\255\220\346\240\221.py" | 32 +++++++++++++ 5 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 "0572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/0572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" 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.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.py" index 9efb265..7e7be51 100644 --- "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.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.py" @@ -11,21 +11,23 @@ def mergeTwoLists(self, l1, l2): :type l2: ListNode :rtype: ListNode """ - newhead = ListNode(0) - p = newhead - while(l1 and l2): - if l1.val < l2.val: + 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 - else: + + if l2: p.next = l2 - return newhead.next - \ No newline at end of file + return dummy.next \ No newline at end of file diff --git "a/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" "b/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" index 10a5d37..4358bfe 100644 --- "a/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" +++ "b/0053.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/0053-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" @@ -6,14 +6,14 @@ def maxSubArray(self, nums): """ if not nums: return 0 - dp = [] # dp[i]表示以i结尾的连续子数组的最大和 + dp = [0 for _ in nums] + dp[0] = nums[0] + for i, x in enumerate(nums): - if i == 0: - dp.append(x) - else: - if dp[-1] < 0: - dp.append(x) + if i: + if dp[i - 1] > 0: + dp[i] = max(dp[i - 1] + x, dp[i]) else: - dp.append(dp[-1] + x) + dp[i] = x return max(dp) \ No newline at end of file diff --git "a/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" index bc284dc..8da976b 100644 --- "a/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" +++ "b/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0098-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -11,10 +11,10 @@ def isValidBST(self, root): :type root: TreeNode :rtype: bool """ - def inOrder(node): + def inorder(node): if not node: return [] - return inOrder(node.left) + [node.val] + inOrder(node.right) + return inorder(node.left) + [node.val] + inorder(node.right) - inorder = inOrder(root) - return len(inorder) == len(set(inorder)) and inorder == sorted(inorder) \ No newline at end of file + l = inorder(root) + return l == sorted(l) and len(l) == len(set(l)) \ No newline at end of file diff --git "a/0221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/0221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" "b/0221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/0221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" index 1b73c54..66eb540 100644 --- "a/0221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/0221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" +++ "b/0221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/0221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" @@ -4,37 +4,26 @@ def maximalSquare(self, matrix): :type matrix: List[List[str]] :rtype: int """ - m = len(matrix) - if m == 0: + if not matrix or not matrix[0]: return 0 - n = len(matrix[0]) - if n == 0: - return 0 - self.res = 0 + m, n = len(matrix), len(matrix[0]) - def find(x, y): - for length in range(1, min(m - i, n - j) + 1):#length是边长 - cnt = 0 - - for k in range(length): - for t in range(length): - xx = x + k - yy = y + t - - if 0 <= xx Date: Wed, 13 May 2020 23:47:01 -0400 Subject: [PATCH 105/183] 2020-05-13 --- ...5-\346\234\200\345\260\217\346\240\210.py" | 27 +++++++++---------- ...24\346\234\257\347\264\242\345\274\225.py" | 10 +++++++ 2 files changed, 22 insertions(+), 15 deletions(-) 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.py" diff --git "a/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" index 50dca76..0b9c216 100644 --- "a/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" +++ "b/0155.\346\234\200\345\260\217\346\240\210/0155-\346\234\200\345\260\217\346\240\210.py" @@ -4,43 +4,40 @@ def __init__(self): """ initialize your data structure here. """ - self.stack = [] - self.minstack = [] + self.s = [] + self.min_s = [] def push(self, x): """ :type x: int :rtype: None """ - self.stack.append(x) - if self.minstack: - if x < self.minstack[-1]: - self.minstack.append(x) - else: - self.minstack.append(self.minstack[-1]) + self.s.append(x) + if self.min_s: + self.min_s.append(min(x, self.min_s[-1])) else: - self.minstack.append(x) - + self.min_s.append(x) def pop(self): """ :rtype: None """ - self.minstack.pop() - self.stack.pop() + self.min_s.pop() + self.s.pop() + def top(self): """ :rtype: int """ - return self.stack[-1] + return self.s[-1] def getMin(self): """ :rtype: int """ - return self.minstack[-1] - + return self.min_s[-1] + # Your MinStack object will be instantiated and called as such: # obj = MinStack() 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.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.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.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 From 196506e91bf7a09839e0c1fc700b8beb1784faa0 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 25 May 2020 00:51:17 -0400 Subject: [PATCH 106/183] 2020-05-25 --- ...72\346\225\260\347\264\242\345\274\225.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "0398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/0398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" diff --git "a/0398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/0398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" "b/0398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/0398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" new file mode 100644 index 0000000..f69bb27 --- /dev/null +++ "b/0398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/0398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" @@ -0,0 +1,22 @@ +class Solution(object): + + def __init__(self, nums): + """ + :type nums: List[int] + """ + from collections import defaultdict + self.dic = defaultdict(list) + for i, num in enumerate(nums): + self.dic[num].append(i) + + def pick(self, target): + """ + :type target: int + :rtype: int + """ + return random.choice(self.dic[target]) + + +# Your Solution object will be instantiated and called as such: +# obj = Solution(nums) +# param_1 = obj.pick(target) \ No newline at end of file From 969df040a89a4c6ddec018c5dd9782d28d141e38 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 14 Jun 2020 21:20:49 -0400 Subject: [PATCH 107/183] 2020-06-14 --- ...232\204\345\267\246\345\217\263\347\247\273.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "1427.\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273/1427-\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273.py" diff --git "a/1427.\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273/1427-\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273.py" "b/1427.\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273/1427-\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273.py" new file mode 100644 index 0000000..0fe9c1f --- /dev/null +++ "b/1427.\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273/1427-\345\255\227\347\254\246\344\270\262\347\232\204\345\267\246\345\217\263\347\247\273.py" @@ -0,0 +1,14 @@ +class Solution(object): + def stringShift(self, s, shift): + """ + :type s: str + :type shift: List[List[int]] + :rtype: str + """ + for d, amount in shift: + if d == 0: + s = s[amount:] + s[:amount] + else: + s = s[-amount:] + s[:-amount] + + return s \ No newline at end of file From d45c35c309adda41aec9b6fbc93c78916f40ec54 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 14 Jun 2020 23:21:50 -0400 Subject: [PATCH 108/183] 2020-06-14 --- ...6\234\347\232\204\345\255\251\345\255\220.py" | 9 +++++++++ ...4\200\345\244\247\345\267\256\345\200\274.py" | 16 ++++++++++++++++ ...0\252\345\255\227\347\254\246\344\270\262.py" | 11 +++++++++++ ...1\214\347\273\210\347\202\271\347\253\231.py" | 7 +++++++ ...\224k\344\270\252\345\205\203\347\264\240.py" | 15 +++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 "1431.\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220/1431-\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220.py" create mode 100644 "1432.\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274/1432-\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274.py" create mode 100644 "1433.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262/1433-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262.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.py" create mode 100644 "1437.\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240/1437-\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240.py" diff --git "a/1431.\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220/1431-\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220.py" "b/1431.\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220/1431-\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220.py" new file mode 100644 index 0000000..2b4f78b --- /dev/null +++ "b/1431.\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220/1431-\346\213\245\346\234\211\346\234\200\345\244\232\347\263\226\346\236\234\347\232\204\345\255\251\345\255\220.py" @@ -0,0 +1,9 @@ +class Solution(object): + def kidsWithCandies(self, candies, extraCandies): + """ + :type candies: List[int] + :type extraCandies: int + :rtype: List[bool] + """ + maxCandies = max(candies) + return [curCandies + extraCandies >= maxCandies for curCandies in candies] \ No newline at end of file diff --git "a/1432.\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274/1432-\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274.py" "b/1432.\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274/1432-\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274.py" new file mode 100644 index 0000000..0007901 --- /dev/null +++ "b/1432.\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274/1432-\346\224\271\345\217\230\344\270\200\344\270\252\346\225\264\346\225\260\350\203\275\345\276\227\345\210\260\347\232\204\346\234\200\345\244\247\345\267\256\345\200\274.py" @@ -0,0 +1,16 @@ +class Solution(object): + def maxDiff(self, num): + """ + :type num: int + :rtype: int + """ + maxValues, minValues = float("-inf"), float("inf") + s = str(num) + for x in range(0, 10): + for y in range(0, 10): + val = s.replace(str(x), str(y)) + if val[0] != '0' and int(val) != 0: + maxValues = max(maxValues, int(val)) + minValues = min(minValues, int(val)) + + return maxValues - minValues \ No newline at end of file diff --git "a/1433.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262/1433-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262.py" "b/1433.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262/1433-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..371d23a --- /dev/null +++ "b/1433.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262/1433-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\217\257\344\273\245\346\211\223\347\240\264\345\217\246\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,11 @@ +class Solution(object): + def checkIfCanBreak(self, s1, s2): + """ + :type s1: str + :type s2: str + :rtype: bool + """ + s1 = sorted(s1) + s2 = sorted(s2) + + return all(s1[i] >= s2[i] for i in range(len(s1))) or all(s2[i] >= s1[i] for i in range(len(s1))) \ 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.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.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.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/1437.\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240/1437-\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240.py" "b/1437.\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240/1437-\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240.py" new file mode 100644 index 0000000..c0bec61 --- /dev/null +++ "b/1437.\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240/1437-\346\230\257\345\220\246\346\211\200\346\234\2111\351\203\275\350\207\263\345\260\221\347\233\270\351\232\224k\344\270\252\345\205\203\347\264\240.py" @@ -0,0 +1,15 @@ +class Solution(object): + def kLengthApart(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: bool + """ + pre = None + for i, num in enumerate(nums): + if num == 1: + if pre != None: + if i - pre - 1 < k: + return False + pre = i + return True \ No newline at end of file From be03324e9d4a47c527faaab12b770ba0ecf8fd3b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 16 Jun 2020 00:01:16 -0400 Subject: [PATCH 109/183] 2020-06-16 --- ...55\345\255\220\346\225\260\347\273\204.py" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "1438.\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/1438-\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" diff --git "a/1438.\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/1438-\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" "b/1438.\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/1438-\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..bb97650 --- /dev/null +++ "b/1438.\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/1438-\347\273\235\345\257\271\345\267\256\344\270\215\350\266\205\350\277\207\351\231\220\345\210\266\347\232\204\346\234\200\351\225\277\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,25 @@ +class Solution(object): + def longestSubarray(self, nums, limit): + """ + :type nums: List[int] + :type limit: int + :rtype: int + """ + if not nums: + return 0 + from heapq import * + res = 1 + minHeap = [] + maxHeap = [] + pre = 0 + for i in range(0, len(nums)): + heappush(minHeap, (nums[i], i)) + heappush(maxHeap, (-nums[i], i)) + while -minHeap[0][0] - maxHeap[0][0] > limit: + while maxHeap and maxHeap[0][1] <= pre: + heappop(maxHeap) + while minHeap and minHeap[0][1] <= pre: + heappop(minHeap) + pre += 1 + res = max(res, i - pre + 1) + return res \ No newline at end of file From aa4408f607acf8f2742a8bd97ba14f642cc1d8f7 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 16 Jun 2020 22:14:08 -0400 Subject: [PATCH 110/183] 2020-06-16 --- ...04\345\273\272\346\225\260\347\273\204.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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.py" 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.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.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.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 From 89b8232053e6f8bea6a54f4b31616c79fd0c14f7 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 17 Jun 2020 23:59:57 -0400 Subject: [PATCH 111/183] 2020-06-17 --- ...03\347\273\204\346\225\260\347\233\256.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" diff --git "a/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" "b/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..3c7cd66 --- /dev/null +++ "b/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" @@ -0,0 +1,20 @@ +class Solution(object): + def countTriplets(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + leftXOR = [0 for _ in arr] + [0] + + res = 0 + + for i, x in enumerate(arr): + leftXOR[i + 1] = leftXOR[i] ^ x + + for i in range(len(arr) + 1): + for j in range(i + 1, len(arr) + 1): + for k in range(j + 1, len(arr) + 1): + if leftXOR[i] ^ leftXOR[j] == leftXOR[j] ^ leftXOR[k]: + res += 1 + + return res \ No newline at end of file From e3ed08c49228aabd71dde71996aae220373e1e41 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 18 Jun 2020 23:56:29 -0400 Subject: [PATCH 112/183] 2020-06-18 --- ...03\347\273\204\346\225\260\347\233\256.py" | 17 ++++------ ...00\345\260\221\346\227\266\351\227\264.py" | 31 +++++++++++++++++++ ...36\347\273\255\345\255\227\347\254\246.py" | 18 +++++++++++ ...00\347\256\200\345\210\206\346\225\260.py" | 11 +++++++ ...71\347\232\204\346\225\260\347\233\256.py" | 27 ++++++++++++++++ 5 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 "1443.\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264/1443-\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264.py" create mode 100644 "1446.\350\277\236\347\273\255\345\255\227\347\254\246/1446-\350\277\236\347\273\255\345\255\227\347\254\246.py" create mode 100644 "1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" create mode 100644 "1448.\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256/1448-\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256.py" diff --git "a/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" "b/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" index 3c7cd66..f0a5ac8 100644 --- "a/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" +++ "b/1442.\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256/1442-\345\275\242\346\210\220\344\270\244\344\270\252\345\274\202\346\210\226\347\233\270\347\255\211\346\225\260\347\273\204\347\232\204\344\270\211\345\205\203\347\273\204\346\225\260\347\233\256.py" @@ -4,17 +4,12 @@ def countTriplets(self, arr): :type arr: List[int] :rtype: int """ - leftXOR = [0 for _ in arr] + [0] - res = 0 - - for i, x in enumerate(arr): - leftXOR[i + 1] = leftXOR[i] ^ x - - for i in range(len(arr) + 1): - for j in range(i + 1, len(arr) + 1): - for k in range(j + 1, len(arr) + 1): - if leftXOR[i] ^ leftXOR[j] == leftXOR[j] ^ leftXOR[k]: - res += 1 + for i in range(len(arr)): + preSum = arr[i] + for j in range(i + 1, len(arr)): + preSum ^= arr[j] + if not preSum: + res += j - i return res \ No newline at end of file diff --git "a/1443.\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264/1443-\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264.py" "b/1443.\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264/1443-\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264.py" new file mode 100644 index 0000000..a3080e5 --- /dev/null +++ "b/1443.\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264/1443-\346\224\266\351\233\206\346\240\221\344\270\212\346\211\200\346\234\211\350\213\271\346\236\234\347\232\204\346\234\200\345\260\221\346\227\266\351\227\264.py" @@ -0,0 +1,31 @@ +class Solution(object): + def minTime(self, n, edges, hasApple): + """ + :type n: int + :type edges: List[List[int]] + :type hasApple: List[bool] + :rtype: int + """ + from collections import defaultdict + dic = defaultdict(set) + mustVisitNodes = set() + + for src, des in edges: + dic[src].add(des) + dic[des].add(src) + + def findMustVisitNodesDFS(node, path, visited): + path.append(node) + + if hasApple[node]: + for n in path: + mustVisitNodes.add(n) + + for child in dic[node]: + if child not in visited: + visited.add(child) + findMustVisitNodesDFS(child, path + [node], visited) + + findMustVisitNodesDFS(0, [], set([0])) + + return max(0, 2 * (len(mustVisitNodes) - 1)) \ No newline at end of file diff --git "a/1446.\350\277\236\347\273\255\345\255\227\347\254\246/1446-\350\277\236\347\273\255\345\255\227\347\254\246.py" "b/1446.\350\277\236\347\273\255\345\255\227\347\254\246/1446-\350\277\236\347\273\255\345\255\227\347\254\246.py" new file mode 100644 index 0000000..8b3d99a --- /dev/null +++ "b/1446.\350\277\236\347\273\255\345\255\227\347\254\246/1446-\350\277\236\347\273\255\345\255\227\347\254\246.py" @@ -0,0 +1,18 @@ +class Solution(object): + def maxPower(self, s): + """ + :type s: str + :rtype: int + """ + res = 1 + pre = s[0] + tmp = 1 + for i, ch in enumerate(s): + if i: + if ch == pre: + tmp += 1 + else: + pre = ch + tmp = 1 + res = max(res, tmp) + return res \ No newline at end of file diff --git "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" new file mode 100644 index 0000000..a4d3f35 --- /dev/null +++ "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution: + def simplifiedFractions(self, n: int) -> List[str]: + import math + res = set() + + for down in range(1, n + 1): + for up in range(1, down): + if math.gcd(up, down) == 1: + res.add(str(up) + "/" + str(down)) + + return list(res) \ No newline at end of file diff --git "a/1448.\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256/1448-\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256.py" "b/1448.\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256/1448-\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..544ddb1 --- /dev/null +++ "b/1448.\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256/1448-\347\273\237\350\256\241\344\272\214\345\217\211\346\240\221\344\270\255\345\245\275\350\212\202\347\202\271\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,27 @@ +# 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 goodNodes(self, root): + """ + :type root: TreeNode + :rtype: int + """ + self.res = 0 + + def dfs(node, maxVal): + if not node: + return + + if node.val >= maxVal: + self.res += 1 + + maxVal = max(maxVal, node.val) + dfs(node.left, maxVal) + dfs(node.right, maxVal) + + dfs(root, root.val) + return self.res \ No newline at end of file From b71b283314c3cd8851a5556bfb8073e2c80f1a9f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 19 Jun 2020 23:59:28 -0400 Subject: [PATCH 113/183] 2020-06-19 --- ...46\347\224\237\344\272\272\346\225\260.py" | 9 +++++++ ...55\347\232\204\345\215\225\350\257\215.py" | 7 +++++ ...66\350\227\217\346\270\205\345\215\225.py" | 27 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 "1450.\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260/1450-\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260.py" create mode 100644 "1451.\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215/1451-\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215.py" create mode 100644 "1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" diff --git "a/1450.\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260/1450-\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260.py" "b/1450.\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260/1450-\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260.py" new file mode 100644 index 0000000..0006c92 --- /dev/null +++ "b/1450.\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260/1450-\345\234\250\346\227\242\345\256\232\346\227\266\351\227\264\345\201\232\344\275\234\344\270\232\347\232\204\345\255\246\347\224\237\344\272\272\346\225\260.py" @@ -0,0 +1,9 @@ +class Solution(object): + def busyStudent(self, startTime, endTime, queryTime): + """ + :type startTime: List[int] + :type endTime: List[int] + :type queryTime: int + :rtype: int + """ + return sum([1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i]]) \ No newline at end of file diff --git "a/1451.\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215/1451-\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215.py" "b/1451.\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215/1451-\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215.py" new file mode 100644 index 0000000..4ac663c --- /dev/null +++ "b/1451.\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215/1451-\351\207\215\346\226\260\346\216\222\345\210\227\345\217\245\345\255\220\344\270\255\347\232\204\345\215\225\350\257\215.py" @@ -0,0 +1,7 @@ +class Solution(object): + def arrangeWords(self, text): + """ + :type text: str + :rtype: str + """ + return " ".join(sorted(text.split(), key = lambda word: len(word))).capitalize() \ No newline at end of file diff --git "a/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" "b/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" new file mode 100644 index 0000000..6d3af77 --- /dev/null +++ "b/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" @@ -0,0 +1,27 @@ +class Solution(object): + def peopleIndexes(self, favoriteCompanies): + """ + :type favoriteCompanies: List[List[str]] + :rtype: List[int] + """ + from collections import defaultdict + + dic = defaultdict(set) + + for i, l in enumerate(favoriteCompanies): + for company in l: + dic[company].add(i) + + res = [] + for i, l in enumerate(favoriteCompanies): + s = dic[l[0]] + for company in l[1:]: + # print i,s, dic[company] + s = s & dic[company] + # print s + # print i, s + if len(s) == 1: + res.append(i) + + return res + \ No newline at end of file From 2194e4dce04f29691b4d8a6a09ccac233c8f5219 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 21 Jun 2020 13:40:39 -0400 Subject: [PATCH 114/183] 2020-06-21 --- ...66\350\227\217\346\270\205\345\215\225.py" | 23 +--------- ...15\347\232\204\345\211\215\347\274\200.py" | 13 ++++++ ...00\345\244\247\346\225\260\347\233\256.py" | 21 +++++++++ ...36\346\226\207\350\267\257\345\276\204.py" | 45 +++++++++++++++++++ 4 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 "1455.\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200/1455-\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200.py" create mode 100644 "1456.\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256/1456-\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256.py" create mode 100644 "1457.\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204/1457-\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204.py" diff --git "a/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" "b/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" index 6d3af77..996f758 100644 --- "a/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" +++ "b/1452.\346\224\266\350\227\217\346\270\205\345\215\225/1452-\346\224\266\350\227\217\346\270\205\345\215\225.py" @@ -4,24 +4,5 @@ def peopleIndexes(self, favoriteCompanies): :type favoriteCompanies: List[List[str]] :rtype: List[int] """ - from collections import defaultdict - - dic = defaultdict(set) - - for i, l in enumerate(favoriteCompanies): - for company in l: - dic[company].add(i) - - res = [] - for i, l in enumerate(favoriteCompanies): - s = dic[l[0]] - for company in l[1:]: - # print i,s, dic[company] - s = s & dic[company] - # print s - # print i, s - if len(s) == 1: - res.append(i) - - return res - \ No newline at end of file + s = [set(l) for l in favoriteCompanies] + return [i for i, s1 in enumerate(s) if not any(s1 < s2 for s2 in s)] \ No newline at end of file diff --git "a/1455.\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200/1455-\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200.py" "b/1455.\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200/1455-\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200.py" new file mode 100644 index 0000000..3b87ee0 --- /dev/null +++ "b/1455.\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200/1455-\346\243\200\346\237\245\345\215\225\350\257\215\346\230\257\345\220\246\344\270\272\345\217\245\344\270\255\345\205\266\344\273\226\345\215\225\350\257\215\347\232\204\345\211\215\347\274\200.py" @@ -0,0 +1,13 @@ +class Solution(object): + def isPrefixOfWord(self, sentence, searchWord): + """ + :type sentence: str + :type searchWord: str + :rtype: int + """ + words = sentence.split() + for i, word in enumerate(words): + if word.startswith(searchWord): + return i + 1 + + return -1 \ No newline at end of file diff --git "a/1456.\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256/1456-\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256.py" "b/1456.\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256/1456-\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256.py" new file mode 100644 index 0000000..809e4c2 --- /dev/null +++ "b/1456.\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256/1456-\345\256\232\351\225\277\345\255\220\344\270\262\344\270\255\345\205\203\351\237\263\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256.py" @@ -0,0 +1,21 @@ +class Solution(object): + def maxVowels(self, s, k): + """ + :type s: str + :type k: int + :rtype: int + """ + vowels = "aeiou" + + start = 0 + res = 0 + tmp = 0 + for end in range(len(s)): + if s[end] in vowels: + tmp += 1 + while end - start + 1 > k: + if s[start] in vowels: + tmp -= 1 + start += 1 + res = max(res, tmp) + return res \ No newline at end of file diff --git "a/1457.\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204/1457-\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204.py" "b/1457.\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204/1457-\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204.py" new file mode 100644 index 0000000..6add82a --- /dev/null +++ "b/1457.\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204/1457-\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\344\274\252\345\233\236\346\226\207\350\267\257\345\276\204.py" @@ -0,0 +1,45 @@ +# 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 pseudoPalindromicPaths (self, root): + """ + :type root: TreeNode + :rtype: int + """ + self.res = 0 + + def dfs(node, path): + if not node: + return + + path = path + [node.val] + if not node.left and not node.right: + if self.hasPalindromic(path): + self.res += 1 + + dfs(node.left, path) + dfs(node.right, path) + + dfs(root, []) + return self.res + + def hasPalindromic(self, nums): + from collections import Counter + + dic = Counter(nums) + + oddCnt = 0 + for val in dic.values(): + if val % 2: + oddCnt += 1 + + return oddCnt <= 1 + + + + + From 670a364798d9897bd51efa93b19ea2b930ce746e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 21 Jun 2020 22:00:10 -0400 Subject: [PATCH 115/183] 2020-06-21 --- ...00\347\256\200\345\210\206\346\225\260.py" | 6 +-- ...60\347\273\204\347\233\270\347\255\211.py" | 9 +++++ ...33\345\210\266\345\255\220\344\270\262.py" | 15 ++++++++ ...\347\250\213\345\256\211\346\216\222IV.py" | 37 +++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 "1460.\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211/1460-\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211.py" create mode 100644 "1461.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262/1461-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262.py" create mode 100644 "1462.\350\257\276\347\250\213\345\256\211\346\216\222IV/1462-\350\257\276\347\250\213\345\256\211\346\216\222IV.py" diff --git "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" index a4d3f35..1c1ba4f 100644 --- "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" +++ "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" @@ -1,11 +1,11 @@ class Solution: def simplifiedFractions(self, n: int) -> List[str]: import math - res = set() + res = [] for down in range(1, n + 1): for up in range(1, down): if math.gcd(up, down) == 1: - res.add(str(up) + "/" + str(down)) + res.append(str(up) + "/" + str(down)) - return list(res) \ No newline at end of file + return res \ No newline at end of file diff --git "a/1460.\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211/1460-\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211.py" "b/1460.\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211/1460-\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211.py" new file mode 100644 index 0000000..9a6ca8e --- /dev/null +++ "b/1460.\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211/1460-\351\200\232\350\277\207\347\277\273\350\275\254\345\255\220\346\225\260\347\273\204\344\275\277\344\270\244\344\270\252\346\225\260\347\273\204\347\233\270\347\255\211.py" @@ -0,0 +1,9 @@ +class Solution(object): + def canBeEqual(self, target, arr): + """ + :type target: List[int] + :type arr: List[int] + :rtype: bool + """ + from collections import Counter + return Counter(target) == Counter(arr) \ No newline at end of file diff --git "a/1461.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262/1461-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262.py" "b/1461.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262/1461-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262.py" new file mode 100644 index 0000000..cff29ca --- /dev/null +++ "b/1461.\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262/1461-\346\243\200\346\237\245\344\270\200\344\270\252\345\255\227\347\254\246\344\270\262\346\230\257\345\220\246\345\214\205\345\220\253\346\211\200\346\234\211\351\225\277\345\272\246\344\270\272K\347\232\204\344\272\214\350\277\233\345\210\266\345\255\220\344\270\262.py" @@ -0,0 +1,15 @@ +class Solution(object): + def hasAllCodes(self, s, k): + """ + :type s: str + :type k: int + :rtype: bool + """ + numSet = set() + for i in range(len(s) - k + 1): + numSet.add(int(s[i:i + k], 2)) + + for num in range(2 ** k): + if num not in numSet: + return False + return True \ No newline at end of file diff --git "a/1462.\350\257\276\347\250\213\345\256\211\346\216\222IV/1462-\350\257\276\347\250\213\345\256\211\346\216\222IV.py" "b/1462.\350\257\276\347\250\213\345\256\211\346\216\222IV/1462-\350\257\276\347\250\213\345\256\211\346\216\222IV.py" new file mode 100644 index 0000000..9d6376b --- /dev/null +++ "b/1462.\350\257\276\347\250\213\345\256\211\346\216\222IV/1462-\350\257\276\347\250\213\345\256\211\346\216\222IV.py" @@ -0,0 +1,37 @@ +class Solution(object): + def checkIfPrerequisite(self, n, prerequisites, queries): + """ + :type n: int + :type prerequisites: List[List[int]] + :type queries: List[List[int]] + :rtype: List[bool] + """ + from collections import defaultdict + from heapq import * + pre = defaultdict(set) + children = defaultdict(set) + inDegree = defaultdict(int) + + for src, dec in prerequisites: + inDegree[dec] += 1 + children[src].add(dec) + + queue = [] + for i in range(n): + if inDegree[i] == 0: + heappush(queue, i) + + while queue: + cur = heappop(queue) + + for child in children[cur]: + pre[child] = pre[cur] | set([cur]) | pre[child] + + inDegree[child] -= 1 + if inDegree[child] == 0: + heappush(queue, child) + + res = [] + for src, dec in queries: + res.append(src in pre[dec]) + return res \ No newline at end of file From ced41f03b16ad0780e292953d3c58fc49c6a3247 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 24 Jun 2020 00:06:47 -0400 Subject: [PATCH 116/183] 2020-06-24 --- ...6\234\200\345\244\247\344\271\230\347\247\257.py" | 8 ++++++++ ...6\216\222\345\210\227\346\225\260\347\273\204.py" | 12 ++++++++++++ ...4\270\252\346\234\200\345\274\272\345\200\274.py" | 10 ++++++++++ 3 files changed, 30 insertions(+) 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.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.py" create mode 100644 "1471.\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274/1471-\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274.py" 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.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.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.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/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/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..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.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/1471.\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274/1471-\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274.py" "b/1471.\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274/1471-\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274.py" new file mode 100644 index 0000000..88c70e3 --- /dev/null +++ "b/1471.\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274/1471-\346\225\260\347\273\204\344\270\255\347\232\204k\344\270\252\346\234\200\345\274\272\345\200\274.py" @@ -0,0 +1,10 @@ +class Solution(object): + def getStrongest(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: List[int] + """ + arr.sort() + m = arr[(len(arr) - 1) // 2] + return sorted(arr, key = lambda x: abs(x - m))[-k:] \ No newline at end of file From e8c42e2fb76699db46ce1ed52a01ac30850eabae Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 27 Jun 2020 22:20:28 -0400 Subject: [PATCH 117/183] 2020-06-27 --- ...04\345\271\263\345\235\207\345\200\274.py" | 7 +++ ...4k\344\270\252\345\233\240\345\255\220.py" | 21 ++++++++ ...77\345\255\220\346\225\260\347\273\204.py" | 21 ++++++++ ...\350\241\214\350\257\276\347\250\213II.py" | 49 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 "5432.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/5432-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" create mode 100644 "5433.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/5433-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" create mode 100644 "5434.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/5434-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" create mode 100644 "5435.\345\271\266\350\241\214\350\257\276\347\250\213II/5435-\345\271\266\350\241\214\350\257\276\347\250\213II.py" diff --git "a/5432.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/5432-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" "b/5432.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/5432-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" new file mode 100644 index 0000000..0aeb3b1 --- /dev/null +++ "b/5432.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/5432-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" @@ -0,0 +1,7 @@ +class Solution(object): + def average(self, salary): + """ + :type salary: List[int] + :rtype: float + """ + return (sum(salary) - max(salary) - min(salary)) * 1.0 / (len(salary) - 2) \ No newline at end of file diff --git "a/5433.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/5433-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" "b/5433.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/5433-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" new file mode 100644 index 0000000..5f7b65d --- /dev/null +++ "b/5433.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/5433-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" @@ -0,0 +1,21 @@ +class Solution(object): + def kthFactor(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + l = [] + for i in range(1, int(n ** 0.5) + 1): + if n % i == 0: + l.append(i) + total = len(l) * 2 if l[-1] ** 2 != n else len(l) * 2 - 1 + if total < k: + return -1 + + if k - 1 < len(l): + return l[k - 1] + else: + idx = (len(l) - 1) * 2 - k + return n // l[idx] if total % 2 else n // l[idx + 2] + \ No newline at end of file diff --git "a/5434.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/5434-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" "b/5434.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/5434-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..c41b8a5 --- /dev/null +++ "b/5434.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/5434-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,21 @@ +class Solution(object): + def longestSubarray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if sum(nums) == len(nums): + return len(nums) - 1 + zeroCnt = 0 + left = 0 + res = 0 + for right in range(len(nums)): + if nums[right] == 0: + zeroCnt += 1 + while zeroCnt > 1: + if nums[left] == 0: + zeroCnt -= 1 + left += 1 + res = max(res, right - left + 1 - zeroCnt) + return res + \ No newline at end of file diff --git "a/5435.\345\271\266\350\241\214\350\257\276\347\250\213II/5435-\345\271\266\350\241\214\350\257\276\347\250\213II.py" "b/5435.\345\271\266\350\241\214\350\257\276\347\250\213II/5435-\345\271\266\350\241\214\350\257\276\347\250\213II.py" new file mode 100644 index 0000000..f8a7f64 --- /dev/null +++ "b/5435.\345\271\266\350\241\214\350\257\276\347\250\213II/5435-\345\271\266\350\241\214\350\257\276\347\250\213II.py" @@ -0,0 +1,49 @@ +class Solution(object): + def minNumberOfSemesters(self, n, dependencies, k): + """ + :type n: int + :type dependencies: List[List[int]] + :type k: int + :rtype: int + """ + from collections import defaultdict + inDegree = defaultdict(int) + outDegree = defaultdict(int) + children = defaultdict(set) + + for src, dec in dependencies: # 寤哄浘 + inDegree[dec] += 1 + outDegree[src] += 1 + children[src].add(dec) + + queue = [] + for i in range(1, n + 1): + if inDegree[i] == 0: # 鍏ュ害涓0锛堟病鏈夊厛淇浜嗭級鐨勮鍏ラ槦 + heappush(queue, (-outDegree[i], i, -1)) # 鍑哄害瓒婂ぇ锛堜互杩欓棬璇句綔涓哄厛淇鐨勮瓒婂锛夛紝浼樺厛绾ц秺楂 + + semesterCnt = 0 + while queue: + semesterCnt += 1 + nextSemesterCourses = [] # 瀛樻斁杩欎釜瀛︽湡涓嶈兘涓婄殑璇 + courseCnt = 0 + while courseCnt < k and queue: # 姣忎釜瀛︽湡鏈澶氫笂 k 闂ㄨ + priority, node, preFinishedSemester = heappop(queue) + + if preFinishedSemester >= semesterCnt: # 褰撳墠瀛︽湡涓嶈兘涓婅繖闂ㄨ + nextSemesterCourses.append((priority, node, preFinishedSemester)) + continue + + for child in children[node]: # 杩欓棬璇惧彲浠ュ锛屽瀹冿紝鐒跺悗澶勭悊瀛╁瓙璇剧殑鍏ュ害 + inDegree[child] -= 1 + + if inDegree[child] == 0: # 瀛╁瓙璇剧殑鍏堜慨璇惧叏涓婂畬浜 + heappush(queue, (-outDegree[child], child, semesterCnt)) + courseCnt += 1 + + for item in nextSemesterCourses: # 鎶婁箣鍓嶅瓨璧锋潵鐨勬湰瀛︽湡涓嶈兘涓婄殑璇惧啀閲嶆柊鍏ラ槦 + heappush(queue, item) + + return semesterCnt + + + \ No newline at end of file From be2e252f0316f24c5357bf8b414817d68e212035 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 29 Jun 2020 23:26:28 -0400 Subject: [PATCH 118/183] 2020-06-29 --- ...04\345\271\263\345\235\207\345\200\274.py" | 7 +++ ...4k\344\270\252\345\233\240\345\255\220.py" | 21 ++++++++ ...77\345\255\220\346\225\260\347\273\204.py" | 21 ++++++++ ...\350\241\214\350\257\276\347\250\213II.py" | 49 +++++++++++++++++++ ...57\345\220\246\347\233\270\344\272\244.py" | 22 +++++++++ ...5\350\242\253k\346\225\264\351\231\244.py" | 20 ++++++++ ...17\345\210\227\346\225\260\347\233\256.py" | 20 ++++++++ ...04\346\234\200\345\244\247\345\200\274.py" | 20 ++++++++ 8 files changed, 180 insertions(+) create mode 100644 "1491.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/1491-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" create mode 100644 "1492.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/1492-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" create mode 100644 "1493.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/1493-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" create mode 100644 "1494.\345\271\266\350\241\214\350\257\276\347\250\213II/1494-\345\271\266\350\241\214\350\257\276\347\250\213II.py" create mode 100644 "1496.\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244/1496-\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244.py" create mode 100644 "1497.\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244/1497-\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244.py" create mode 100644 "1498.\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256/1498-\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256.py" create mode 100644 "1499.\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/1499-\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" diff --git "a/1491.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/1491-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" "b/1491.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/1491-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" new file mode 100644 index 0000000..0aeb3b1 --- /dev/null +++ "b/1491.\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274/1491-\345\216\273\346\216\211\346\234\200\344\275\216\345\267\245\350\265\204\345\222\214\346\234\200\351\253\230\345\267\245\350\265\204\345\220\216\347\232\204\345\267\245\350\265\204\345\271\263\345\235\207\345\200\274.py" @@ -0,0 +1,7 @@ +class Solution(object): + def average(self, salary): + """ + :type salary: List[int] + :rtype: float + """ + return (sum(salary) - max(salary) - min(salary)) * 1.0 / (len(salary) - 2) \ No newline at end of file diff --git "a/1492.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/1492-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" "b/1492.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/1492-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" new file mode 100644 index 0000000..5f7b65d --- /dev/null +++ "b/1492.n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220/1492-n\347\232\204\347\254\254k\344\270\252\345\233\240\345\255\220.py" @@ -0,0 +1,21 @@ +class Solution(object): + def kthFactor(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + l = [] + for i in range(1, int(n ** 0.5) + 1): + if n % i == 0: + l.append(i) + total = len(l) * 2 if l[-1] ** 2 != n else len(l) * 2 - 1 + if total < k: + return -1 + + if k - 1 < len(l): + return l[k - 1] + else: + idx = (len(l) - 1) * 2 - k + return n // l[idx] if total % 2 else n // l[idx + 2] + \ No newline at end of file diff --git "a/1493.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/1493-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" "b/1493.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/1493-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..c41b8a5 --- /dev/null +++ "b/1493.\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204/1493-\345\210\240\346\216\211\344\270\200\344\270\252\345\205\203\347\264\240\344\273\245\345\220\216\345\205\250\344\270\2721\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,21 @@ +class Solution(object): + def longestSubarray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if sum(nums) == len(nums): + return len(nums) - 1 + zeroCnt = 0 + left = 0 + res = 0 + for right in range(len(nums)): + if nums[right] == 0: + zeroCnt += 1 + while zeroCnt > 1: + if nums[left] == 0: + zeroCnt -= 1 + left += 1 + res = max(res, right - left + 1 - zeroCnt) + return res + \ No newline at end of file diff --git "a/1494.\345\271\266\350\241\214\350\257\276\347\250\213II/1494-\345\271\266\350\241\214\350\257\276\347\250\213II.py" "b/1494.\345\271\266\350\241\214\350\257\276\347\250\213II/1494-\345\271\266\350\241\214\350\257\276\347\250\213II.py" new file mode 100644 index 0000000..f8a7f64 --- /dev/null +++ "b/1494.\345\271\266\350\241\214\350\257\276\347\250\213II/1494-\345\271\266\350\241\214\350\257\276\347\250\213II.py" @@ -0,0 +1,49 @@ +class Solution(object): + def minNumberOfSemesters(self, n, dependencies, k): + """ + :type n: int + :type dependencies: List[List[int]] + :type k: int + :rtype: int + """ + from collections import defaultdict + inDegree = defaultdict(int) + outDegree = defaultdict(int) + children = defaultdict(set) + + for src, dec in dependencies: # 寤哄浘 + inDegree[dec] += 1 + outDegree[src] += 1 + children[src].add(dec) + + queue = [] + for i in range(1, n + 1): + if inDegree[i] == 0: # 鍏ュ害涓0锛堟病鏈夊厛淇浜嗭級鐨勮鍏ラ槦 + heappush(queue, (-outDegree[i], i, -1)) # 鍑哄害瓒婂ぇ锛堜互杩欓棬璇句綔涓哄厛淇鐨勮瓒婂锛夛紝浼樺厛绾ц秺楂 + + semesterCnt = 0 + while queue: + semesterCnt += 1 + nextSemesterCourses = [] # 瀛樻斁杩欎釜瀛︽湡涓嶈兘涓婄殑璇 + courseCnt = 0 + while courseCnt < k and queue: # 姣忎釜瀛︽湡鏈澶氫笂 k 闂ㄨ + priority, node, preFinishedSemester = heappop(queue) + + if preFinishedSemester >= semesterCnt: # 褰撳墠瀛︽湡涓嶈兘涓婅繖闂ㄨ + nextSemesterCourses.append((priority, node, preFinishedSemester)) + continue + + for child in children[node]: # 杩欓棬璇惧彲浠ュ锛屽瀹冿紝鐒跺悗澶勭悊瀛╁瓙璇剧殑鍏ュ害 + inDegree[child] -= 1 + + if inDegree[child] == 0: # 瀛╁瓙璇剧殑鍏堜慨璇惧叏涓婂畬浜 + heappush(queue, (-outDegree[child], child, semesterCnt)) + courseCnt += 1 + + for item in nextSemesterCourses: # 鎶婁箣鍓嶅瓨璧锋潵鐨勬湰瀛︽湡涓嶈兘涓婄殑璇惧啀閲嶆柊鍏ラ槦 + heappush(queue, item) + + return semesterCnt + + + \ No newline at end of file diff --git "a/1496.\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244/1496-\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244.py" "b/1496.\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244/1496-\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244.py" new file mode 100644 index 0000000..cc00d2f --- /dev/null +++ "b/1496.\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244/1496-\345\210\244\346\226\255\350\267\257\345\276\204\346\230\257\345\220\246\347\233\270\344\272\244.py" @@ -0,0 +1,22 @@ +class Solution(object): + def isPathCrossing(self, path): + """ + :type path: str + :rtype: bool + """ + s = set([(0, 0)]) + x, y = 0, 0 + for d in path: + if d == "N": + y += 1 + elif d == "S": + y -= 1 + elif d == "E": + x += 1 + elif d == "W": + x -= 1 + if (x, y) in s: + return True + s.add((x, y)) + return False + \ No newline at end of file diff --git "a/1497.\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244/1497-\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244.py" "b/1497.\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244/1497-\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244.py" new file mode 100644 index 0000000..b85ec4b --- /dev/null +++ "b/1497.\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244/1497-\346\243\200\346\237\245\346\225\260\347\273\204\345\257\271\346\230\257\345\220\246\345\217\257\344\273\245\350\242\253k\346\225\264\351\231\244.py" @@ -0,0 +1,20 @@ +class Solution(object): + def canArrange(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: bool + """ + from collections import defaultdict + dic = defaultdict(int) + for num in arr: + mod = num % k + if mod: + dic[mod] += 1 + for key in dic.keys(): + if key * 2 != k and dic[key] != dic[k - key]: + return False + if key * 2 == k and dic[key] % 2 != 0: + return False + return True + \ No newline at end of file diff --git "a/1498.\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256/1498-\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256.py" "b/1498.\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256/1498-\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256.py" new file mode 100644 index 0000000..692db36 --- /dev/null +++ "b/1498.\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256/1498-\346\273\241\350\266\263\346\235\241\344\273\266\347\232\204\345\255\220\345\272\217\345\210\227\346\225\260\347\233\256.py" @@ -0,0 +1,20 @@ +class Solution(object): + def numSubseq(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: int + """ + nums.sort() + left, right = 0, len(nums) - 1 + res = 0 + MOD = 10 ** 9 + 7 + while left <= right: + s = nums[left] + nums[right] + l = right - left + if s <= target: + res = (res + (1 << l)) % MOD + left += 1 + else: + right -= 1 + return res \ No newline at end of file diff --git "a/1499.\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/1499-\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/1499.\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/1499-\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..bb26882 --- /dev/null +++ "b/1499.\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274/1499-\346\273\241\350\266\263\344\270\215\347\255\211\345\274\217\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,20 @@ +class Solution(object): + def findMaxValueOfEquation(self, points, k): + """ + :type points: List[List[int]] + :type k: int + :rtype: int + """ + from collections import deque + queue = deque([(points[0][0], points[0][0] - points[0][1])]) + res = float("-inf") + for yi, yj in points[1:]: + while queue and queue[0][0] < yi - k: + queue.popleft() + if queue: + res = max(res, -queue[0][1] + yi + yj) + sub = yi - yj + while queue and queue[-1][1] > sub: + queue.pop() + queue.append((yi, sub)) + return res \ No newline at end of file From b1f7d10da122e136808b2be04e7d8fbc3e95c856 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 1 Jul 2020 22:29:53 -0400 Subject: [PATCH 119/183] 2020-07-01 --- ...44\346\225\260\344\271\213\345\222\214.py" | 12 +++ ...02\345\272\217\351\201\215\345\216\206.py" | 31 ++++++++ ...64\347\232\204\345\256\271\345\231\250.py" | 20 +++++ ...35\345\244\247\345\244\232\346\225\260.py" | 2 +- ...02\347\202\271\346\214\207\351\222\210.py" | 36 +++++++++ ...\347\202\271\346\214\207\351\222\210II.py" | 41 ++++++++++ ...72\347\216\260\351\242\221\346\254\241.py" | 30 +++----- ...\351\207\215\345\244\215\351\241\271II.py" | 20 +++++ ...00\344\275\263\346\227\266\346\234\272.py" | 12 +++ ...04\351\207\221\347\237\277\345\267\245.py" | 31 ++++++++ ...33\346\216\267\347\241\254\345\270\201.py" | 2 +- ...01\345\233\236\346\226\207\344\270\262.py" | 12 +++ ...33\345\210\266\347\237\251\351\230\265.py" | 27 +++++++ ...25\350\257\215\351\233\206\345\220\210.py" | 22 +++--- ...40\345\257\206\346\225\260\345\255\227.py" | 7 ++ ...54\345\205\261\345\214\272\345\237\237.py" | 24 ++++++ ...11\350\257\215\345\217\245\345\255\220.py" | 56 ++++++++++++++ ...44\347\232\204\346\217\241\346\211\213.py" | 10 +++ ...21\346\240\274\350\277\201\347\247\273.py" | 19 +++++ ...45\346\211\276\345\205\203\347\264\240.py" | 40 ++++++++++ ...04\346\234\200\345\244\247\345\222\214.py" | 42 +++++++++++ ...57\345\217\230\351\223\276\350\241\250.py" | 32 ++++++++ ...04\350\216\267\350\203\234\350\200\205.py" | 4 +- ...57\345\222\214\344\271\213\345\267\256.py" | 13 ++++ ...50\346\210\267\345\210\206\347\273\204.py" | 18 +++++ ...00\345\260\217\351\231\244\346\225\260.py" | 24 ++++++ ...15\350\275\254\346\254\241\346\225\260.py" | 71 ++++++++++++++++++ ...3\346\235\237\346\225\260\345\255\227.sql" | 6 ++ ...10\350\277\255\344\273\243\345\231\250.py" | 30 ++++++++ ...5%\347\232\204\345\205\203\347\264\240.py" | 16 ++++ ...06\347\233\226\345\214\272\351\227\264.py" | 19 +++++ ...\346\234\200\345\260\217\345\222\214II.py" | 24 ++++++ ...50\350\275\254\346\225\264\346\225\260.py" | 17 +++++ ...1-\351\241\272\346\254\241\346\225\260.py" | 22 ++++++ ...60\347\232\204\346\225\260\345\255\227.py" | 11 +++ ...27\347\232\204\351\233\206\345\220\210.py" | 22 ++++++ ...72\347\216\260\346\254\241\346\225\260.py" | 21 ++++++ ...47\347\263\226\346\236\234\346\225\260.py" | 34 +++++++++ ...00\345\244\247\345\205\203\347\264\240.py" | 12 +++ ...04\346\225\260\347\273\204\345\222\214.py" | 39 ++++++++++ ...57\345\276\204\346\225\260\347\233\256.py" | 30 ++++++++ ...02\347\202\271\347\232\204\345\222\214.py" | 27 +++++++ ...57\344\270\200\346\225\264\346\225\260.py" | 14 ++++ ...00\346\234\211\345\205\203\347\264\240.py" | 24 ++++++ ...350\267\203\346\270\270\346\210\217III.py" | 21 ++++++ ...64\346\225\260\346\230\240\345\260\204.py" | 15 ++++ ...62\345\233\236\346\226\207\344\270\262.py" | 24 ++++++ ...02\346\210\226\346\237\245\350\257\242.py" | 18 +++++ ...13\347\232\204\350\247\206\351\242\221.py" | 34 +++++++++ ...22\345\205\245\346\254\241\346\225\260.py" | 23 ++++++ ...26\347\240\201\345\210\227\350\241\250.py" | 10 +++ ...04\350\212\202\347\202\271\345\222\214.py" | 24 ++++++ ...64\346\225\260\347\232\204\345\222\214.py" | 11 +++ ...\345\233\236\346\226\207\344\270\262II.py" | 15 ++++ ...3-\345\205\213\351\232\206\345\233\276.py" | 34 +++++++++ ...60\347\233\256\346\216\222\345\272\217.py" | 7 ++ ...27\347\232\204\346\225\260\345\255\227.py" | 13 ++++ ...15\345\255\227\347\254\246\344\270\262.py" | 20 +++++ ...70\345\220\214\350\212\202\347\202\271.py" | 28 +++++++ ...10\347\232\204\351\223\276\350\241\250.py" | 26 +++++++ ...04\350\267\235\347\246\273\345\200\274.py" | 20 +++++ ...61\351\231\242\345\272\247\344\275\215.py" | 31 ++++++++ ...03\351\207\215\346\216\222\345\272\217.py" | 21 ++++++ ...25\350\257\215\346\213\206\345\210\206.py" | 16 ++++ ...04\345\271\270\350\277\220\346\225\260.py" | 8 ++ ...30\345\215\225\344\275\215\346\225\260.py" | 26 +++++++ ...60\351\223\201\347\263\273\347\273\237.py" | 44 +++++++++++ ...04\347\232\204\346\225\260\347\233\256.py" | 22 ++++++ ...07\345\255\227\347\254\246\344\270\262.py" | 19 +++++ ...32\350\217\234\351\241\272\345\272\217.py" | 20 +++++ ...17\345\255\220\345\272\217\345\210\227.py" | 17 +++++ ...04\346\255\245\351\252\244\346\225\260.py" | 15 ++++ ...20\345\255\227\347\254\246\344\270\262.py" | 38 ++++++++++ ...46\344\270\262\345\214\271\351\205\215.py" | 16 ++++ ...56\347\232\204\346\216\222\345\210\227.py" | 15 ++++ ...23\350\247\243\346\236\220\345\231\250.py" | 14 ++++ ...04\346\234\200\345\260\217\345\200\274.py" | 13 ++++ ...60\345\255\227\346\225\260\347\233\256.py" | 22 ++++++ ...26\345\255\227\347\254\246\344\270\262.py" | 32 ++++++++ ...34\345\261\225\347\244\272\350\241\250.py" | 30 ++++++++ ...9-\346\225\260\351\235\222\350\233\231.py" | 31 ++++++++ ...00\345\244\247\345\276\227\345\210\206.py" | 17 +++++ ...00\345\244\247\347\202\271\346\225\260.py" | 21 ++++++ ...6-\346\225\260\345\205\203\347\264\240.py" | 13 ++++ ...00\347\256\200\345\210\206\346\225\260.py" | 6 +- ...23\345\255\230\346\234\272\345\210\266.py" | 74 +++++++++++++++++++ ...14\347\232\204\345\215\225\350\257\215.py" | 7 ++ ...5-\346\234\200\345\260\217\346\240\210.py" | 47 ++++++++++++ ...11\345\272\217\346\225\260\347\273\204.py" | 16 ++++ ...32\346\225\260\345\205\203\347\264\240.py" | 19 +++++ ...04\345\217\263\350\247\206\345\233\276.py" | 31 ++++++++ ...33\345\261\277\346\225\260\351\207\217.py" | 33 +++++++++ ...11\345\272\217\351\223\276\350\241\250.py" | 33 +++++++++ ...54\345\217\267\347\224\237\346\210\220.py" | 18 +++++ ...47\346\255\243\346\226\271\345\275\242.py" | 29 ++++++++ ...27\345\256\236\347\216\260\346\240\210.py" | 49 ++++++++++++ ...73\350\275\254\351\223\276\350\241\250.py" | 45 +++++++++++ ...2-\344\274\232\350\256\256\345\256\244.py" | 18 +++++ ...\344\274\232\350\256\256\345\256\244II.py" | 20 +++++ ...76\351\207\215\345\244\215\346\225\260.py" | 17 +++++ ...37\345\221\275\346\270\270\346\210\217.py" | 50 +++++++++++++ ...60\345\244\264\345\234\260\347\202\271.py" | 29 ++++++++ ...60\345\255\227\346\270\270\346\210\217.py" | 22 ++++++ ...07\345\255\220\345\272\217\345\210\227.py" | 14 ++++ ...40\347\232\204\344\270\252\346\225\260.py" | 35 +++++++++ ...66\351\222\261\345\205\221\346\215\242.py" | 25 +++++++ .../326-3\347\232\204\345\271\202.py" | 10 +++ ...30\351\242\221\345\205\203\347\264\240.py" | 21 ++++++ ...76\350\256\241\346\216\250\347\211\271.py" | 51 +++++++++++++ ...64\345\243\266\351\227\256\351\242\230.py" | 21 ++++++ ...66\345\255\220\350\212\202\347\202\271.py" | 35 +++++++++ ...17\347\232\204\345\205\203\347\264\240.py" | 25 +++++++ ...70\345\272\217\346\216\222\346\225\260.py" | 20 +++++ ...57\344\270\200\345\255\227\347\254\246.py" | 12 +++ ...72\346\225\260\347\264\242\345\274\225.py" | 22 ++++++ ...77\345\233\236\346\226\207\344\270\262.py" | 7 ++ ...2-\346\216\245\351\233\250\346\260\264.py" | 31 ++++++++ ...14\345\220\221\351\223\276\350\241\250.py" | 47 ++++++++++++ ...14\345\220\221\351\223\276\350\241\250.py" | 38 ++++++++++ ...76\345\217\263\345\214\272\351\227\264.py" | 23 ++++++ ...\346\225\260\347\233\270\345\212\240II.py" | 44 +++++++++++ ...25\347\210\206\346\260\224\347\220\203.py" | 20 +++++ .../460-LFU\347\274\223\345\255\230.py" | 60 +++++++++++++++ ...15\345\244\215\344\270\252\346\225\260.py" | 57 ++++++++++++++ ...27\347\232\204\350\241\245\346\225\260.py" | 16 ++++ ...35\347\246\273\346\200\273\345\222\214.py" | 20 +++++ ...45\346\240\274\345\274\217\345\214\226.py" | 18 +++++ ...15\350\257\215\345\210\206\347\273\204.py" | 13 ++++ ...4\345\244\247\345\205\203\347\264\240I.py" | 24 ++++++ 50.Pow(x,n)/50-Pow(x,n).py | 8 ++ ...07\345\255\220\345\272\217\345\210\227.py" | 17 +++++ ...47\345\255\220\345\272\217\345\222\214.py" | 19 +++++ .../542-01\347\237\251\351\230\265.py" | 38 ++++++++++ ...21\347\232\204\347\233\264\345\276\204.py" | 20 +++++ ...63\350\267\203\346\270\270\346\210\217.py" | 13 ++++ ...2\345\213\244\350\256\260\345\275\225I.py" | 7 ++ ...10\345\271\266\345\214\272\351\227\264.py" | 24 ++++++ ...04\345\255\220\346\225\260\347\273\204.py" | 22 ++++++ ...0\347\273\204\346\213\206\345\210\206I.py" | 7 ++ ...15\345\241\221\347\237\251\351\230\265.py" | 20 +++++ ...22\345\205\245\345\214\272\351\227\264.py" | 35 +++++++++ ...21\347\232\204\345\255\220\346\240\221.py" | 32 ++++++++ ...15\347\232\204\351\225\277\345\272\246.py" | 9 +++ ...55\345\255\220\346\225\260\347\273\204.py" | 19 +++++ ...71\346\225\260\344\271\213\345\222\214.py" | 12 +++ ...31\344\275\215\346\216\222\345\210\227.py" | 10 +++ ...04\345\271\263\346\226\271\346\240\271.py" | 17 +++++ ...00\345\244\247\351\235\242\347\247\257.py" | 35 +++++++++ ...11\347\232\204\345\255\220\351\233\206.py" | 39 ++++++++++ ...26\350\276\221\350\267\235\347\246\273.py" | 25 +++++++ ...30\344\275\215\346\230\240\345\260\204.py" | 13 ++++ ...27\346\257\215\345\214\272\351\227\264.py" | 39 ++++++++++ ...63\344\270\216\347\237\263\345\244\264.py" | 13 ++++ ...04\345\215\225\350\257\215\346\225\260.py" | 31 ++++++++ ...\215\242\346\225\264\346\225\260(atoi).py" | 36 +++++++++ ...14\347\232\204\346\226\207\345\255\227.py" | 38 ++++++++++ ...13\347\274\251\347\274\226\347\240\201.py" | 36 +++++++++ ...51\345\275\242\351\207\215\345\217\240.py" | 10 +++ ...00\351\225\277\345\261\261\350\204\211.py" | 24 ++++++ ...55\351\227\264\347\273\223\347\202\271.py" | 17 +++++ ...41\350\233\213\346\216\211\350\220\275.py" | 15 ++++ ...04\350\241\250\351\235\242\347\247\257.py" | 16 ++++ ...22\345\272\217\346\225\260\347\273\204.py" | 7 ++ ...22\345\272\217\346\225\260\347\273\204.py" | 7 ++ ...41\347\211\214\345\210\206\347\273\204.py" | 11 +++ ...00\345\260\221\346\267\273\345\212\240.py" | 14 ++++ ...00\345\260\217\345\242\236\351\207\217.py" | 11 +++ ...01\346\240\210\345\272\217\345\210\227.py" | 16 ++++ ...1\347\232\204K\344\270\252\347\202\271.py" | 25 +++++++ ...11\346\220\234\347\264\242\346\240\221.py" | 20 +++++ ...02\347\232\204\346\251\230\345\255\220.py" | 43 +++++++++++ ...04\346\243\213\345\255\220\346\225\260.py" | 28 +++++++ ...15\347\232\204\346\225\260\345\255\227.py" | 11 +++ ...55\347\232\204\346\237\245\346\211\276.py" | 21 ++++++ ...77\346\215\242\347\251\272\346\240\274.py" | 7 ++ ...23\345\215\260\351\223\276\350\241\250.py" | 17 +++++ ...72\344\272\214\345\217\211\346\240\221.py" | 22 ++++++ ...36\347\216\260\351\230\237\345\210\227.py" | 28 +++++++ ...43\345\245\221\346\225\260\345\210\227.py" | 17 +++++ ...60\351\230\266\351\227\256\351\242\230.py" | 17 +++++ ...00\345\260\217\346\225\260\345\255\227.py" | 21 ++++++ ...55\347\232\204\350\267\257\345\276\204.py" | 33 +++++++++ ...20\345\212\250\350\214\203\345\233\264.py" | 29 ++++++++ ...I-\345\211\252\347\273\263\345\255\220.py" | 24 ++++++ ...\345\211\252\347\273\263\345\255\220II.py" | 15 ++++ ...51\347\232\204\344\270\252\346\225\260.py" | 11 +++ ...64\346\225\260\346\254\241\346\226\271.py" | 25 +++++++ ...7\347\232\204n\344\275\215\346\225\260.py" | 7 ++ ...50\347\232\204\350\212\202\347\202\271.py" | 24 ++++++ ...66\346\225\260\345\211\215\351\235\242.py" | 16 ++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 23 ++++++ ...15\350\275\254\351\223\276\350\241\250.py" | 20 +++++ ...17\347\232\204\351\223\276\350\241\250.py" | 33 +++++++++ ...21\347\232\204\351\225\234\345\203\217.py" | 19 +++++ ...04\344\272\214\345\217\211\346\240\221.py" | 23 ++++++ ...23\345\215\260\347\237\251\351\230\265.py" | 45 +++++++++++ ...75\346\225\260\347\232\204\346\240\210.py" | 50 +++++++++++++ ...71\345\207\272\345\272\217\345\210\227.py" | 19 +++++ ...60\344\272\214\345\217\211\346\240\221.py" | 28 +++++++ ...\344\272\214\345\217\211\346\240\221II.py" | 30 ++++++++ ...344\272\214\345\217\211\346\240\221III.py" | 35 +++++++++ ...15\345\216\206\345\272\217\345\210\227.py" | 25 +++++++ ...74\347\232\204\350\267\257\345\276\204.py" | 31 ++++++++ ...50\347\232\204\345\244\215\345\210\266.py" | 30 ++++++++ ...14\345\220\221\351\223\276\350\241\250.py" | 47 ++++++++++++ ...62\347\232\204\346\216\222\345\210\227.py" | 16 ++++ ...12\347\232\204\346\225\260\345\255\227.py" | 7 ++ ...7\347\232\204k\344\270\252\346\225\260.py" | 18 +++++ ...04\346\234\200\345\244\247\345\222\214.py" | 16 ++++ ...00\345\244\247\344\273\267\345\200\274.py" | 22 ++++++ ...41\347\232\204\345\255\227\347\254\246.py" | 14 ++++ ...54\345\205\261\350\212\202\347\202\271.py" | 39 ++++++++++ ...5\346\211\276\346\225\260\345\255\227I.py" | 8 ++ ...61\347\232\204\346\225\260\345\255\227.py" | 16 ++++ ...4k\345\244\247\350\212\202\347\202\271.py" | 36 +++++++++ ...21\347\232\204\346\267\261\345\272\246.py" | 16 ++++ ...43\346\225\260\345\272\217\345\210\227.py" | 22 ++++++ ...44\344\270\252\346\225\260\345\255\227.py" | 17 +++++ ...54\345\255\227\347\254\246\344\270\262.py" | 8 ++ ...04\346\234\200\345\244\247\345\200\274.py" | 35 +++++++++ ...13\347\232\204\346\225\260\345\255\227.py" | 10 +++ ...00\345\244\247\345\210\251\346\266\246.py" | 12 +++ ...Offer64-\346\261\2021+2+\342\200\246+n.py" | 7 ++ ...44\345\201\232\345\212\240\346\263\225.py" | 8 ++ ...30\347\247\257\346\225\260\347\273\204.py" | 15 ++++ ...54\345\205\261\347\245\226\345\205\210.py" | 20 +++++ ...54\345\205\261\347\245\226\345\205\210.py" | 23 ++++++ ...27\347\254\246\351\207\215\346\216\222.py" | 9 +++ ...36\346\226\207\346\216\222\345\210\227.py" | 14 ++++ ...13\350\275\254\347\237\251\351\230\265.py" | 7 ++ ...46\344\270\262\350\275\256\350\275\254.py" | 8 ++ ...15\345\244\215\350\212\202\347\202\271.py" | 26 +++++++ ...4k\344\270\252\350\212\202\347\202\271.py" | 22 ++++++ ...55\351\227\264\350\212\202\347\202\271.py" | 19 +++++ ...24\346\234\257\347\264\242\345\274\225.py" | 10 +++ ...\242\23008.11-\347\241\254\345\270\201.py" | 12 +++ ...\242\23016.03-\344\272\244\347\202\271.py" | 4 + ...00\345\244\247\346\225\260\345\200\274.py" | 8 ++ ...37\345\255\230\344\272\272\346\225\260.py" | 21 ++++++ ...67\347\232\204\345\212\240\346\263\225.py" | 8 ++ ...6-\346\214\211\346\221\251\345\270\210.py" | 13 ++++ 241 files changed, 5372 insertions(+), 37 deletions(-) create mode 100644 "1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" create mode 100644 "102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/102-\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 "11.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/11-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" create mode 100644 "116.\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/116-\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 "117.\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/117-\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 "1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" create mode 100644 "121.\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/121-\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 "1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" create mode 100644 "125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" create mode 100644 "1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" create mode 100644 "1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" create mode 100644 "1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" create mode 100644 "1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" create mode 100644 "1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" create mode 100644 "1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.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 "1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.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 "1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.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 "1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" create mode 100644 "1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" create mode 100644 "1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" create mode 100644 "1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" create mode 100644 "1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" create mode 100644 "1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" create mode 100644 "1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.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 "1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" create mode 100644 "1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" create mode 100644 "1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" create mode 100644 "1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" create mode 100644 "1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" create mode 100644 "1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" create mode 100644 "1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" create mode 100644 "1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.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 "1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" create mode 100644 "1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" create mode 100644 "1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" create mode 100644 "1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" create mode 100644 "131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" create mode 100644 "1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" create mode 100644 "1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" create mode 100644 "1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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" create mode 100644 "1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.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 "1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" create mode 100644 "132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" create mode 100644 "133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" create mode 100644 "1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" create mode 100644 "1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" create mode 100644 "1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.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 "138.\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/138-\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 "1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" create mode 100644 "1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" create mode 100644 "1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" create mode 100644 "139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" create mode 100644 "1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" create mode 100644 "1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.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" create mode 100644 "1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" create mode 100644 "1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" create mode 100644 "1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" create mode 100644 "1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" create mode 100644 "1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" create mode 100644 "1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" create mode 100644 "1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.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 "1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" create mode 100644 "1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" create mode 100644 "1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" create mode 100644 "1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.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 "1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" create mode 100644 "1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" create mode 100644 "1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" create mode 100644 "1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" create mode 100644 "146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" create mode 100644 "151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" create mode 100644 "155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" create mode 100644 "167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" create mode 100644 "169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" create mode 100644 "199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\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 "200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" create mode 100644 "21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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 "22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" create mode 100644 "221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" create mode 100644 "225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" create mode 100644 "25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" create mode 100644 "252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" create mode 100644 "253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" create mode 100644 "287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" create mode 100644 "289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" create mode 100644 "296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" create mode 100644 "299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" create mode 100644 "300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" create mode 100644 "315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" create mode 100644 "322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" create mode 100644 "326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" create mode 100644 "347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" create mode 100644 "355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" create mode 100644 "365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" create mode 100644 "366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" create mode 100644 "378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" create mode 100644 "386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" create mode 100644 "387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" create mode 100644 "398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" create mode 100644 "409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" create mode 100644 "42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" create mode 100644 "426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" create mode 100644 "445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" create mode 100644 "452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" create mode 100644 "460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" create mode 100644 "466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" create mode 100644 "476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" create mode 100644 "477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" create mode 100644 "482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" create mode 100644 "49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\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 "496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\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 50.Pow(x,n)/50-Pow(x,n).py create mode 100644 "516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" create mode 100644 "53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" create mode 100644 "542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" create mode 100644 "543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" create mode 100644 "55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" create mode 100644 "551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" create mode 100644 "56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" create mode 100644 "560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" create mode 100644 "561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" create mode 100644 "566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" create mode 100644 "57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" create mode 100644 "572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" create mode 100644 "58.\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/58-\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 "581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" create mode 100644 "633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" create mode 100644 "634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" create mode 100644 "69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" create mode 100644 "695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" create mode 100644 "698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" create mode 100644 "72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" create mode 100644 "760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" create mode 100644 "763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" create mode 100644 "771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" create mode 100644 "792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" create mode 100644 "8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" create mode 100644 "809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" create mode 100644 "820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" create mode 100644 "836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" create mode 100644 "845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" create mode 100644 "876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\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 "887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" create mode 100644 "892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" create mode 100644 "905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" create mode 100644 "912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" create mode 100644 "914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" create mode 100644 "921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" create mode 100644 "945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" create mode 100644 "946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" create mode 100644 "973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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 "98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" create mode 100644 "994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" create mode 100644 "999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" create mode 100644 "\345\211\221\346\214\207Offer03.\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\207Offer03-\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\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" create mode 100644 "\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" create mode 100644 "\345\211\221\346\214\207Offer06.\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\207Offer06-\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\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" create mode 100644 "\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" create mode 100644 "\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" create mode 100644 "\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" create mode 100644 "\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" create mode 100644 "\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" create mode 100644 "\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" create mode 100644 "\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" create mode 100644 "\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" create mode 100644 "\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" create mode 100644 "\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" create mode 100644 "\345\211\221\346\214\207Offer22.\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\207Offer22-\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\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" create mode 100644 "\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" create mode 100644 "\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\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\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" create mode 100644 "\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" create mode 100644 "\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" create mode 100644 "\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" create mode 100644 "\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" create mode 100644 "\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" create mode 100644 "\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" create mode 100644 "\345\211\221\346\214\207Offer35.\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\207Offer35-\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\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" create mode 100644 "\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" create mode 100644 "\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" create mode 100644 "\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" create mode 100644 "\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" create mode 100644 "\345\211\221\346\214\207Offer52.\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\207Offer52-\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\207Offer53-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\207Offer53-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\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207Offer54.\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\207Offer54-\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\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-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\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" create mode 100644 "\345\211\221\346\214\207Offer57.\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\207Offer57-\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\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-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\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" create mode 100644 "\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" create mode 100644 "\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" create mode 100644 "\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" create mode 100644 "\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" create mode 100644 "\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" create mode 100644 "\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" create mode 100644 "\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" create mode 100644 "\351\235\242\350\257\225\351\242\23001.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\23001.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\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.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\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.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\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" create mode 100644 "\351\235\242\350\257\225\351\242\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" create mode 100644 "\351\235\242\350\257\225\351\242\23002.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\23002.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 "\351\235\242\350\257\225\351\242\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" create mode 100644 "\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" create mode 100644 "\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" create mode 100644 "\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" create mode 100644 "\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" create mode 100644 "\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" create mode 100644 "\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" create mode 100644 "\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" diff --git "a/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" "b/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" new file mode 100644 index 0000000..8b92177 --- /dev/null +++ "b/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + dic = {} + for i, num in enumerate(nums): + if target - num in dic: + return [dic[target - num], i] + dic[num] = i \ No newline at end of file diff --git "a/102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/102-\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/102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/102-\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..e28c4f8 --- /dev/null +++ "b/102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/102-\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,31 @@ +# 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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + if not root: + return [] + queue = [root] + res = list() + while queue: + nextqueue = list() + layer = list() + for node in queue: + if node.left: + nextqueue.append(node.left) + if node.right: + nextqueue.append(node.right) + layer.append(node.val) + + queue = nextqueue[:] + res.append(layer) + return res + \ No newline at end of file diff --git "a/11.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/11-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" "b/11.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/11-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" new file mode 100644 index 0000000..aef803f --- /dev/null +++ "b/11.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/11-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" @@ -0,0 +1,20 @@ +class Solution(object): + def maxArea(self, height): + """ + :type height: List[int] + :rtype: int + """ + lo, hi = 0, len(height) - 1 + res = 0 + while(lo < hi): + if height[lo] > height[hi]: + area = height[hi] * (hi - lo) + hi -= 1 + else: + area = height[lo] * (hi - lo) + lo += 1 + # print area + res = max(area, res) + + return res + \ No newline at end of file diff --git "a/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" "b/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" index d915ca3..95f6fca 100644 --- "a/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" +++ "b/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" @@ -5,4 +5,4 @@ def isMajorityElement(self, nums, target): :type target: int :rtype: bool """ - return nums.count(target) > len(nums) // 2 \ No newline at end of file + return nums.count(target) > (len(nums) // 2) \ No newline at end of file diff --git "a/116.\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/116-\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/116.\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/116-\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..4a71a00 --- /dev/null +++ "b/116.\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/116-\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,36 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val=0, left=None, right=None, next=None): + 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 or not root.left: + return root + + root.left.next = root.right + if root.next: + root.right.next = root.next.left + self.connect(root.left) + self.connect(root.right) + + return root + + def findNext(self, node): + nxt = node.next + while nxt: + if nxt.left: + return nxt.left + elif nxt.right: + return nxt.right + else: + nxt = nxt.next + return None \ No newline at end of file diff --git "a/117.\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/117-\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/117.\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/117-\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..d38d977 --- /dev/null +++ "b/117.\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/117-\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,41 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val=0, left=None, right=None, next=None): + 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 root + + if root.left and root.right: + root.left.next = root.right + root.right.next = self.findNext(root) + + elif root.left: + root.left.next = self.findNext(root) + elif root.right: + root.right.next = self.findNext(root) + + self.connect(root.right) + self.connect(root.left) + + return root + + def findNext(self, node): + nxt = node.next + while nxt: + if nxt.left: + return nxt.left + if nxt.right: + return nxt.right + nxt = nxt.next + return None \ No newline at end of file diff --git "a/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" index 1d151bc..2af6b9f 100644 --- "a/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" +++ "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" @@ -5,24 +5,18 @@ def numSmallerByFrequency(self, queries, words): :type words: List[str] :rtype: List[int] """ + def f(word): + return word.count(min(word)) - def func(word): - for char in "abcdefghijklmnopqrstuvwxyz": - if char in word: - return word.count(char) - return 0 + f_words = sorted([f(word) for word in words]) - def func2(word): - record = collections.Counter(word) - return record[min(record.keys())] - - - words_count = sorted(map(func2, words)) - queries_count = map(func2, queries) - # print words_count, queries_count - ans = [] - for query in queries_count: - index = bisect.bisect(words_count, query) #bisect可以迅速找出有index个数 <= query - ans.append(len(words_count) - index)# 减法找有多少个数比query大 - return ans + res = [] + # print f_words + for q in queries: + cnt = f(q) + # print(bisect.bisect(f_words, cnt)) + res.append(len(f_words) - bisect.bisect(f_words, cnt)) + + return res + \ No newline at end of file diff --git "a/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" "b/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" new file mode 100644 index 0000000..e816f7c --- /dev/null +++ "b/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" @@ -0,0 +1,20 @@ +class Solution(object): + def removeDuplicates(self, s, k): + """ + :type s: str + :type k: int + :rtype: str + """ + stack = [] + for ch in s: + if not stack: + stack.append([ch, 1]) + else: + if stack[-1][0] == ch: + stack[-1][1] += 1 + if stack[-1][1] % k == 0: + stack.pop() + else: + stack.append([ch, 1]) + + return "".join(ch * freq for ch, freq in stack) \ No newline at end of file diff --git "a/121.\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/121-\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/121.\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/121-\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..325ada7 --- /dev/null +++ "b/121.\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/121-\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,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/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" "b/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" new file mode 100644 index 0000000..5790cac --- /dev/null +++ "b/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" @@ -0,0 +1,31 @@ +class Solution(object): + def getMaximumGold(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + m, n = len(grid), len(grid[0]) + visited = set() + self.res = 0 + + def dfs(x0, y0, tmp): + self.res = max(self.res, tmp) + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and grid[x][y] > 0: + value = grid[x][y] + grid[x][y] = -1 + dfs(x, y, tmp + value) + grid[x][y] = value + + for i in range(m): + for j in range(n): + value = grid[i][j] + grid[i][j] = -1 + dfs(i, j, value) + grid[i][j] = value + return self.res \ No newline at end of file diff --git "a/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" index d928eef..f6c8cf3 100644 --- "a/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" +++ "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" @@ -16,7 +16,7 @@ def probabilityOfHeads(self, prob, target): return dp[target] # dp = [[0 for _ in range(len(prob) + 1)] for _ in range(len(prob))] - # # dp[i][j] 表示前i个硬币里,有j个硬币正面朝上的概率 + # # dp[i][j] 琛ㄧず鍓峣涓‖甯侀噷锛屾湁j涓‖甯佹闈㈡湞涓婄殑姒傜巼 # dp[0][1] = prob[0] # dp[0][0] = 1 - prob[0] # for i, p in enumerate(prob): diff --git "a/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" "b/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..ac5138b --- /dev/null +++ "b/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,12 @@ +class Solution(object): + def isPalindrome(self, s): + """ + :type s: str + :rtype: bool + """ + res = "" + for ch in s: + if ch.isalpha() or ch.isdigit(): + res += ch.lower() + # print res + return res == res[::-1] \ No newline at end of file diff --git "a/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" "b/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" new file mode 100644 index 0000000..cf75510 --- /dev/null +++ "b/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" @@ -0,0 +1,27 @@ +class Solution(object): + def reconstructMatrix(self, upper, lower, colsum): + """ + :type upper: int + :type lower: int + :type colsum: List[int] + :rtype: List[List[int]] + """ + b = [[0 for _ in range(len(colsum))] for _ in range(2)] + + for i, cs in enumerate(colsum): + if cs == 2: + b[0][i] = 1 + b[1][i] = 1 + upper -= 1 + lower -= 1 + for i, cs in enumerate(colsum): + if cs == 1: + if lower > upper: + b[1][i] = 1 + lower -= 1 + else: + b[0][i] = 1 + upper -= 1 + if upper != 0 or lower != 0: + return [] + return b \ No newline at end of file diff --git "a/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" index 32f2f05..e9f0305 100644 --- "a/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" +++ "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" @@ -9,25 +9,25 @@ def maxScoreWords(self, words, letters, score): from collections import defaultdict, Counter dic = dict() letter_dic = defaultdict(int) - for i, val in enumerate(score):#构建一个字典 - dic[chr(ord("a") + i)] = val #key是 字母,val是字母对应的分数 + for i, val in enumerate(score):#鏋勫缓涓涓瓧鍏 + dic[chr(ord("a") + i)] = val #key鏄 瀛楁瘝锛寁al鏄瓧姣嶅搴旂殑鍒嗘暟 - letter_dic = Counter(letters)#构建另一个字典, key是字母, val是每次字母剩余的个数 + letter_dic = Counter(letters)#鏋勫缓鍙︿竴涓瓧鍏革紝 key鏄瓧姣嶏紝 val鏄瘡娆″瓧姣嶅墿浣欑殑涓暟 s = set(letters) v_words = [] - for word in words:#删掉所有根本不可能被构成的单词 + for word in words:#鍒犳帀鎵鏈夋牴鏈笉鍙兘琚瀯鎴愮殑鍗曡瘝 flag = 0 for char in word: if char not in s: flag = 1 - if flag: # 如果一个单词里存在某个在letters里找不到的字母,则无需考虑这个单词 + if flag: # 濡傛灉涓涓崟璇嶉噷瀛樺湪鏌愪釜鍦╨etters閲屾壘涓嶅埌鐨勫瓧姣嶏紝鍒欐棤闇鑰冭檻杩欎釜鍗曡瘝 continue v_words.append(word) self.res = 0 def helper(word, letter_dic): - # return True 如果word能用letter_dic里的letter构成,否则返回False + # return True 濡傛灉word鑳界敤letter_dic閲岀殑letter鏋勬垚锛屽惁鍒欒繑鍥濬alse dicc = collections.Counter(word) for key in dicc: if dicc[key] > letter_dic[key]: @@ -39,12 +39,12 @@ def dfs(start, tmp): if start >= len(v_words): return - for i in range(start, len(v_words)):#从start开始找,避免重复 - if helper(v_words[i], letter_dic):#如果当前单词可以被构成 - for char in v_words[i]: #构成它,更新字典 + for i in range(start, len(v_words)):#浠巗tart寮濮嬫壘锛岄伩鍏嶉噸澶 + if helper(v_words[i], letter_dic):#濡傛灉褰撳墠鍗曡瘝鍙互琚瀯鎴 + for char in v_words[i]: #鏋勬垚瀹冿紝鏇存柊瀛楀吀 letter_dic[char] -= 1 - dfs(i + 1, tmp + sum([dic[char] for char in v_words[i]])) #dfs下一层 - for char in v_words[i]: #回溯,复原所有状态 + dfs(i + 1, tmp + sum([dic[char] for char in v_words[i]])) #dfs涓嬩竴灞 + for char in v_words[i]: #鍥炴函锛屽鍘熸墍鏈夌姸鎬 letter_dic[char] += 1 dfs(0, 0) return self.res \ No newline at end of file diff --git "a/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" "b/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" new file mode 100644 index 0000000..967b748 --- /dev/null +++ "b/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" @@ -0,0 +1,7 @@ +class Solution(object): + def encode(self, num): + """ + :type num: int + :rtype: str + """ + return bin(num + 1)[3:] \ No newline at end of file diff --git "a/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" "b/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" new file mode 100644 index 0000000..87162ed --- /dev/null +++ "b/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" @@ -0,0 +1,24 @@ +class Solution(object): + def findSmallestRegion(self, regions, region1, region2): + """ + :type regions: List[List[str]] + :type region1: str + :type region2: str + :rtype: str + """ + from collections import defaultdict + dic = dict() + for reg in regions: + parent = reg[0] + for child in reg[1:]: # 閬嶅巻鎵鏈夌殑瀛愬尯鍩 + dic[child] = (parent) + + ancestors_1 = set() + while region1 in dic: + ancestors_1.add(region1) + region1 = dic[region1] + + while region2 not in ancestors_1 and region2 in dic: + region2 = dic[region2] + + return region2 \ No newline at end of file diff --git "a/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" "b/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" new file mode 100644 index 0000000..a164966 --- /dev/null +++ "b/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" @@ -0,0 +1,56 @@ +class Solution(object): + def generateSentences(self, synonyms, text): + """ + :type synonyms: List[List[str]] + :type text: str + :rtype: List[str] + """ + from collections import defaultdict + dic = defaultdict(set) + vocab = set() + text = text.split() + + for w1, w2 in synonyms: + dic[w1].add(w2) + dic[w2].add(w1) + vocab.add(w1) + vocab.add(w2) + + self.res = [] + + def generateList(word, res, visited): + res.add(word) + for w in dic[word]: + if w not in visited: + visited.add(w) + generateList(w, res, visited) + + return res + + + def dfs(start, tmp): + if start >= len(text): + self.res.append(tmp) + return + + word = text[start] + if word in vocab: + l = set() + visited = set() + generateList(word, l, visited) + for w in l: + if start > 0: + dfs(start + 1, tmp + " " + w) + else: + dfs(start + 1, w) + else: + if start > 0: + dfs(start + 1, tmp + " " + word) + else: + dfs(start + 1, word) + dfs(0, "") + self.res.sort() + return self.res + + + \ No newline at end of file diff --git "a/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" "b/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" new file mode 100644 index 0000000..fcd69b1 --- /dev/null +++ "b/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" @@ -0,0 +1,10 @@ +from math import factorial as fac +class Solution(object): + def numberOfWays(self, num_people): + """ + :type num_people: int + :rtype: int + """ + def catalan(n): + return fac(2*n) // (fac(n+1) * fac(n)) + return catalan(num_people // 2) % ( 10 ** 9 + 7) \ No newline at end of file diff --git "a/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" "b/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" new file mode 100644 index 0000000..8b088ec --- /dev/null +++ "b/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" @@ -0,0 +1,19 @@ +class Solution(object): + def shiftGrid(self, grid, k): + """ + :type grid: List[List[int]] + :type k: int + :rtype: List[List[int]] + """ + m, n = len(grid), len(grid[0]) + + size = m * n + k = k % size + l = [grid[i][j] for i in range(m) for j in range(n)] + + l = l[-k:] + l[:-k] + + for i in range(m): + for j in range(n): + grid[i][j] = l[i * n + j] + return grid \ 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..c031724 --- /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,40 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class FindElements(object): + + def __init__(self, root): + """ + :type root: 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 + dfs(node.left) + if node.right: + node.right.val = 2 * node.val + 2 + dfs(node.right) + dfs(root) + + + + def find(self, target): + """ + :type target: int + :rtype: 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/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" new file mode 100644 index 0000000..9050833 --- /dev/null +++ "b/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" @@ -0,0 +1,42 @@ +class Solution(object): + def maxSumDivThree(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + from collections import defaultdict + dic = defaultdict(list) + + nums.sort() + for num in nums: + dic[num % 3].append(num) + + + s = sum(nums) + if s % 3 == 0: + return s + + if s % 3 == 2: + t1, t2 = float("inf"),float("inf") + if 2 in dic: #鍙互鍒犻櫎涓涓ā涓 2 鐨勬渶灏忔暟 + t1 = dic[2][0] + + if len(dic[1]) >= 2: # 涔熷彲浠ュ垹闄や袱涓ā涓 1 鐨勬渶灏忔暟 + t2 = dic[1][0] + dic[1][1] + + if t1 > t2:# 閫夋嫨涓ょ鍙兘涓緝灏忕殑鍊煎垹闄 + return s - t2 + + return s - t1 + + if s % 3 == 1: + t1, t2 = float("inf"), float("inf") + if 1 in dic: # 鍙互鍒犻櫎涓涓ā涓 1 鐨勬渶灏忔暟 + t1 = dic[1][0] + if len(dic[2]) >= 2: # 涔熷彲浠ュ垹闄や袱涓ā涓 2 鐨勬渶灏忔暟 + t2 = dic[2][0] + dic[2][1] + + if t1 > t2: # 閫夋嫨涓ょ鍙兘涓緝灏忕殑鍊煎垹闄 + return s - t2 + + return s - t1 \ 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..bd98f36 --- /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,32 @@ +# """ +# This is the ImmutableListNode's API interface. +# You should not implement it, or speculate about its implementation. +# """ +# class ImmutableListNode(object): +# def printValue(self): # print the value of this node. +# . """ +# :rtype None +# """ +# +# def getNext(self): # return the next node. +# . """ +# :rtype ImmutableListNode +# """ + +class Solution(object): + def printLinkedListInReverse(self, head): + """ + :type head: ImmutableListNode + :rtype: None + """ + if not head: + return + l = [] + p = head + while p: + l.append(p) + p = p.getNext() + + while l: + l.pop().printValue() + \ No newline at end of file diff --git "a/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" index 26dfeca..5f5014f 100644 --- "a/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" +++ "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" @@ -43,6 +43,4 @@ def check(): tmp = check() if tmp != -1: return "A" if tmp == 0 else "B" - return "Draw" if len(moves) == 9 else "Pending" - - \ No newline at end of file + return "Draw" if len(moves) == 9 else "Pending" \ No newline at end of file diff --git "a/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" "b/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" new file mode 100644 index 0000000..d78a8cc --- /dev/null +++ "b/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" @@ -0,0 +1,13 @@ +class Solution(object): + def subtractProductAndSum(self, n): + """ + :type n: int + :rtype: int + """ + product, s = 1, 0 + + while n: + n, digit = divmod(n, 10) + product *= digit + s += digit + return product - s \ 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..7b41f8e --- /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,18 @@ +class Solution(object): + def groupThePeople(self, groupSizes): + """ + :type groupSizes: List[int] + :rtype: List[List[int]] + """ + from collections import defaultdict + dic = defaultdict(list) + + res = [] + for i, x in enumerate(groupSizes): + if x not in dic or len(dic[x]) < x: + dic[x].append(i) + if len(dic[x]) == x: + res.append(dic[x]) + dic[x] = [] + + return res \ No newline at end of file diff --git "a/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" "b/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" new file mode 100644 index 0000000..f98756d --- /dev/null +++ "b/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" @@ -0,0 +1,24 @@ +class Solution(object): + def smallestDivisor(self, nums, threshold): + """ + :type nums: List[int] + :type threshold: int + :rtype: int + """ + left, right = 1, max(nums) + + while left <= right: + mid = (left + right) // 2 + + tmp = 0 + for num in nums: + tmp += math.ceil(num * 1.0 / mid) + if tmp > threshold: + break + + if tmp > threshold: + left = mid + 1 + else: + right = mid - 1 + + return left diff --git "a/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" "b/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" new file mode 100644 index 0000000..f0461fb --- /dev/null +++ "b/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" @@ -0,0 +1,71 @@ +import numpy +class Solution(object): + def minFlips(self, mat): + """ + :type mat: List[List[int]] + :rtype: int + """ + if not mat or not mat[0]: + return 0 + + m, n = len(mat), len(mat[0]) + def check(matrix): + + return sum(sum(matrix, [])) == 0 + + def encode(matrix): + s = "" + for row in matrix: + for ch in row: + s += str(ch) + return s + + def decode(s): + mat = [] + for ch in s: + mat.append(int(ch)) + + res = [[0 for _ in range(n)] for _ in range(m)] + for i in range(m): + for j in range(n): + res[i][j] = mat[i * n + j] + return res + + def convert(mat, i, j, m, n): + for k in range(5): + x, y = i + dx[k], j + dy[k] + if 0 <= x < m and 0 <= y < n: + mat[x][y] ^= 1 + return mat + + res = -1 + from collections import deque + queue = deque([encode(mat)]) + + dx = [1, 0, 0, -1, 0] + dy = [0, 1, -1, 0, 0] + visited = set() + visited.add(encode(mat)) + while queue: + res += 1 + for _ in range(len(queue)): + encoded_cur = queue.popleft() + cur = decode(encoded_cur) + + if check(cur): + return res + + for i in range(m): + for j in range(n): + mat = convert(cur, i, j, m, n) + encoded_mat = encode(mat) + if encoded_mat not in visited: + queue.append(encoded_mat) + visited.add(encoded_mat) + + mat = convert(cur, i, j, m, n) + + return -1 + + + diff --git "a/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" "b/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" new file mode 100644 index 0000000..eb6c348 --- /dev/null +++ "b/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" @@ -0,0 +1,6 @@ +# Write your MySQL query statement below +select a.log_id as START_ID, b.log_id as END_ID +from (select log_id from Logs where log_id-1 not in (select * from logs)) as a, + (select log_id from Logs where log_id+1 not in (select * from logs)) as b +where b.log_id>=a.log_id +group by a.log_id \ No newline at end of file diff --git "a/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" "b/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" new file mode 100644 index 0000000..adbe100 --- /dev/null +++ "b/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" @@ -0,0 +1,30 @@ +class CombinationIterator(object): + + def __init__(self, characters, combinationLength): + """ + :type characters: str + :type combinationLength: int + """ + # from itertools import permututations + self.s = list(itertools.combinations(characters, combinationLength)) + self.index = 0 + + def next(self): + """ + :rtype: str + """ + self.index += 1 + return "".join(self.s[self.index - 1]) + + def hasNext(self): + """ + :rtype: bool + """ + return self.index < len(self.s) + + + +# Your CombinationIterator object will be instantiated and called as such: +# obj = CombinationIterator(characters, combinationLength) +# param_1 = obj.next() +# param_2 = obj.hasNext() \ No newline at end of file diff --git "a/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" "b/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" new file mode 100644 index 0000000..b899810 --- /dev/null +++ "b/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" @@ -0,0 +1,16 @@ +class Solution(object): + def findSpecialInteger(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + cnt = 1 + for i, num in enumerate(arr): + if i: + if num == arr[i - 1]: + cnt += 1 + else: + cnt = 1 + if cnt > len(arr) / 4: + return num + \ No newline at end of file diff --git "a/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" "b/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" new file mode 100644 index 0000000..2e14aeb --- /dev/null +++ "b/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" @@ -0,0 +1,19 @@ +class Solution(object): + def removeCoveredIntervals(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: int + """ + intervals = sorted(intervals, key = lambda x:(x[0], x[1])) + + start, end = intervals[0][0], intervals[0][1] + + n = len(intervals) + max_end = intervals[0][1] + for s, e in intervals: + if max_end >= e: + n -= 1 + else: + max_end = e + + return n + 1 \ No newline at end of file diff --git "a/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" "b/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" new file mode 100644 index 0000000..5e15a73 --- /dev/null +++ "b/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" @@ -0,0 +1,24 @@ +class Solution(object): + def minFallingPathSum(self, arr): + """ + :type arr: List[List[int]] + :rtype: int + """ + from heapq import * + if not arr or not arr[0]: + return 0 + + m, n = len(arr), len(arr[0]) + + for i in range(1, m): + max_heap = [] + for j in range(n): + if len(max_heap) < 2: + heappush(max_heap, -arr[i - 1][j]) + else: + heappush(max_heap, -arr[i - 1][j]) + heappop(max_heap) + # print max_heap + for j in range(n): + arr[i][j] -= max_heap[1] if -max_heap[1] != arr[i - 1][j] else max_heap[0] + return min(arr[-1]) \ 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..89fd7bb --- /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,17 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def getDecimalValue(self, head): + """ + :type head: ListNode + :rtype: int + """ + res = 0 + while head: + res = res * 2 + head.val + head = head.next + return res \ No newline at end of file diff --git "a/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" "b/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" new file mode 100644 index 0000000..09dceb9 --- /dev/null +++ "b/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" @@ -0,0 +1,22 @@ +class Solution(object): + def sequentialDigits(self, low, high): + """ + :type low: int + :type high: int + :rtype: List[int] + """ + nums = [12, 23, 34, 45, 56, 67, 78, 89, + 123, 234, 345, 456, 567, 678, 789, + 1234, 2345, 3456,4567, 5678, 6789, + 12345, 23456, 34567, 45678, 56789, + 123456, 234567, 345678, 456789, + 1234567, 2345678, 3456789, + 12345678, 23456789, + 123456789] + res = [] + + for num in nums: + if low <= num <= high: + res.append(num) + + return res \ No newline at end of file diff --git "a/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" "b/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..5e87082 --- /dev/null +++ "b/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,11 @@ +class Solution(object): + def findNumbers(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + res = 0 + for num in nums: + if len(str(num)) % 2 == 0: + res += 1 + return res \ No newline at end of file diff --git "a/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" "b/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" new file mode 100644 index 0000000..986dd8c --- /dev/null +++ "b/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" @@ -0,0 +1,22 @@ +class Solution(object): + def isPossibleDivide(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: bool + """ + from collections import Counter, deque + dic = Counter(nums) + nums = deque(sorted(list(set(nums)))) + + res = [] + while nums: + num = nums[0] + for i in range(k): + target = num + i + if target not in dic: + return False + dic[target] -= 1 + if dic[target] == 0: + nums.popleft() + return True \ No newline at end of file diff --git "a/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" "b/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" new file mode 100644 index 0000000..7c2e30e --- /dev/null +++ "b/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" @@ -0,0 +1,21 @@ +class Solution(object): + def maxFreq(self, s, maxLetters, minSize, maxSize): + """ + :type s: str + :type maxLetters: int + :type minSize: int + :type maxSize: int + :rtype: int + """ + from collections import defaultdict + + record = defaultdict(int) + + res = 0 + for i in range(len(s) - minSize + 1): + substring = s[i:i+minSize] + if len(set(substring)) <= maxLetters: + record[substring] += 1 + res = max(res, record[substring]) + + return res \ No newline at end of file diff --git "a/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" "b/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" new file mode 100644 index 0000000..b4fc042 --- /dev/null +++ "b/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" @@ -0,0 +1,34 @@ +class Solution(object): + def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes): + """ + :type status: List[int] + :type candies: List[int] + :type keys: List[List[int]] + :type containedBoxes: List[List[int]] + :type initialBoxes: List[int] + :rtype: int + """ + if not initialBoxes: + return 0 + + # boxes = set(initialBoxes) + owned_keys = set() + from collections import deque + queue = deque(initialBoxes) + res = 0 + record = dict() + while queue: + cur = queue.popleft() + # print cur + if status[cur] or cur in owned_keys: # This box could be opened + for key in keys[cur]: + owned_keys.add(key) + for box in containedBoxes[cur]: + queue.append(box) + res += candies[cur] + else: + if cur in record and record[cur] == owned_keys: + break + queue.append(cur) + record[cur] = owned_keys + return res \ No newline at end of file diff --git "a/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" "b/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" new file mode 100644 index 0000000..af2248b --- /dev/null +++ "b/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" @@ -0,0 +1,12 @@ +class Solution(object): + def replaceElements(self, arr): + """ + :type arr: List[int] + :rtype: List[int] + """ + right_max = -1 + for i in range(len(arr) - 1, -1, -1): + tmp = arr[i] + arr[i] = right_max + right_max = max(right_max, tmp) + return arr \ No newline at end of file diff --git "a/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" "b/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" new file mode 100644 index 0000000..d2eed65 --- /dev/null +++ "b/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" @@ -0,0 +1,39 @@ +class Solution(object): + def findBestValue(self, arr, target): + """ + :type arr: List[int] + :type target: int + :rtype: int + """ + left, right = 0, max(arr) + sub, ans = float("inf"), float("inf") + + while left <= right: + mid = (left + right) // 2 # mid 涓烘湰娆$寽娴嬬殑绛旀 + + tmp = 0 # tmp 鏄湰娆$寽娴嬫柊鏁扮粍涔嬪拰 + for num in arr: + if num > mid: + tmp += mid + else: + tmp += num + + cur_sub = abs(tmp - target) #褰撳墠宸殑鏈灏忓 + + if cur_sub < sub: # 濡傛灉鏈夋洿灏忕殑绛旀 + sub = cur_sub + ans = mid + elif cur_sub == sub: + ans = min(ans, mid) + + if tmp > target: + right = mid - 1 + elif tmp < target: + left = mid + 1 + elif tmp == target: + return mid + + return ans + + + \ No newline at end of file diff --git "a/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" "b/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..0e1be3e --- /dev/null +++ "b/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" @@ -0,0 +1,30 @@ +class Solution(object): + def pathsWithMaxScore(self, board): + """ + :type board: List[str] + :rtype: List[int] + """ + n = len(board) + MOD = 10 ** 9 + 7 + + dp = [[[float("-inf"), 0] for _ in range(n + 1)] for _ in range(n + 1)] + dp[n - 1][n - 1] = [0, 1] + for i in range(n - 1, -1, -1): + for j in range(n - 1, -1, -1): + if board[i][j] not in "XS": + + for dx, dy in [[0, 1], [1, 0], [1, 1]]: + if dp[i][j][0] < dp[i + dx][j + dy][0]: + dp[i][j] = [dp[i + dx][j + dy][0], 0] + + if dp[i][j][0] == dp[i + dx][j + dy][0]: + dp[i][j][1] += dp[i + dx][j + dy][1] + + dp[i][j][0] += int(board[i][j]) if board[i][j] != "E" else 0 + + return [dp[0][0][0] if dp[0][0][1] else 0, dp[0][0][1] % MOD] + + + + + \ 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..e98e035 --- /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,27 @@ +# 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 deepestLeavesSum(self, root): + """ + :type root: TreeNode + :rtype: int + """ + from collections import deque + if not root: + return 0 + queue = deque([root]) + while queue: + res = [] + for _ in range(len(queue)): + node = queue.popleft() + res.append(node.val) + if node.left: + queue += [node.left] + if node.right: + queue += [node.right] + return sum(res) \ No newline at end of file diff --git "a/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" "b/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" new file mode 100644 index 0000000..8f816d2 --- /dev/null +++ "b/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" @@ -0,0 +1,14 @@ +class Solution(object): + def sumZero(self, n): + """ + :type n: int + :rtype: List[int] + """ + res = [] + + for i in range(1, n // 2 + 1): + res.append(i) + res.append(-i) + if n % 2: + res.append(0) + return res \ No newline at end of file diff --git "a/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" "b/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" new file mode 100644 index 0000000..ebc4858 --- /dev/null +++ "b/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.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 getAllElements(self, root1, root2): + """ + :type root1: TreeNode + :type root2: TreeNode + :rtype: List[int] + """ + + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + l1 = inorder(root1) + l2 = inorder(root2) + + return sorted(l1 + l2) \ No newline at end of file diff --git "a/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" "b/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" new file mode 100644 index 0000000..e33687f --- /dev/null +++ "b/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" @@ -0,0 +1,21 @@ +class Solution(object): + def canReach(self, arr, start): + """ + :type arr: List[int] + :type start: int + :rtype: bool + """ + from collections import deque + queue = deque([start]) + visited = set([start]) + while queue: + cur = queue.popleft() + + if arr[cur] == 0: + return True + + for i in [cur + arr[cur], cur - arr[cur]]: + if 0 <= i < len(arr) and i not in visited: + visited.add(i) + queue.append(i) + return False \ No newline at end of file diff --git "a/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" "b/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" new file mode 100644 index 0000000..7b5faa6 --- /dev/null +++ "b/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" @@ -0,0 +1,15 @@ +class Solution(object): + def freqAlphabets(self, s): + """ + :type s: str + :rtype: str + """ + res, i = "", 0 + while i < len(s): + if i + 2 < len(s) and s[i + 2] == "#": + res += chr(ord("a") + int(s[i:i + 2]) - 1) + i += 3 + else: + res += chr(ord("a") + int(s[i]) - 1) + i += 1 + return res \ No newline at end of file diff --git "a/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" "b/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..fadcc8c --- /dev/null +++ "b/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,24 @@ +class Solution(object): + def partition(self, s): + """ + :type s: str + :rtype: List[List[str]] + """ + + res = [] + + def dfs(start, tmp): + + if start >= len(s): + # print tmp + res.append(tmp[:]) + return + + for i in range(start, len(s)): + substring = s[start:i + 1] + if substring == substring[::-1]: + tmp.append(substring) + dfs(i + 1, tmp) + tmp.pop() + dfs(0, []) + return res \ No newline at end of file diff --git "a/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" "b/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" new file mode 100644 index 0000000..bffcb3b --- /dev/null +++ "b/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" @@ -0,0 +1,18 @@ +class Solution(object): + def xorQueries(self, arr, queries): + """ + :type arr: List[int] + :type queries: List[List[int]] + :rtype: List[int] + """ + + prefix = [0 for _ in [0] + arr] + for i in range(len(arr)): + prefix[i + 1] = prefix[i] ^ arr[i] + + # print prefix + res = [] + for l, r in queries: + res.append(prefix[l] ^ prefix[r + 1]) + + return res \ No newline at end of file diff --git "a/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" "b/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" new file mode 100644 index 0000000..094b33b --- /dev/null +++ "b/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" @@ -0,0 +1,34 @@ +class Solution(object): + def watchedVideosByFriends(self, watchedVideos, friends, idd, level): + """ + :type watchedVideos: List[List[str]] + :type friends: List[List[int]] + :type id: int + :type level: int + :rtype: List[str] + """ + from collections import deque,defaultdict + # 1. find all k-level friends by BFS + queue = deque([idd]) + visited = set([idd]) + for l in range(level): + friendset = set() + for _ in range(len(queue)): + cur = queue.popleft() + + for fri in friends[cur]: + if fri not in visited: + visited.add(fri) + queue.append(fri) + + # 2. find watched videos of all k-level friends + videos = defaultdict(int) + for friend in queue: + for video in watchedVideos[friend]: + videos[video] += 1 + + # 3. count the frequency + res = [[key, val] for key, val in videos.items()] + res = sorted(res, key = lambda x:(x[1], x[0])) + + return [x[0] for x in res] \ No newline at end of file diff --git "a/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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..99d3117 --- /dev/null +++ "b/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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,23 @@ +class Solution(object): + def minInsertions(self, s): + """ + :type s: str + :rtype: int + """ + return len(s) - self.longestPalindromeSubseq(s) + def longestPalindromeSubseq(self, s): + """ + :type s: str + :rtype: int + """ + n = len(s) + dp = [[0] * n for _ in range(n)] + + for i in range(n): + dp[i][i] = 1 + for j in range(i - 1, -1, -1): + if s[i] == s[j]: + dp[i][j] = dp[i - 1][j + 1] + 2 + else: + dp[i][j] = max(dp[i][j + 1], dp[i - 1][j]) + return dp[n - 1][0] \ No newline at end of file diff --git "a/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" "b/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" new file mode 100644 index 0000000..d380b2c --- /dev/null +++ "b/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" @@ -0,0 +1,10 @@ +class Solution(object): + def decompressRLElist(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + res = [] + for i in range(0, len(nums), 2): + res += nums[i] * [nums[i + 1]] + return res \ 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..8a80225 --- /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,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 sumEvenGrandparent(self, root): + """ + :type root: TreeNode + :rtype: int + """ + self.res = 0 + def dfs(node, parent, grand): + if not node: + return + if grand: + self.res += node.val + + dfs(node.left, node.val % 2 == 0, parent) + dfs(node.right, node.val % 2 == 0, parent) + dfs(root, False, False) + return self.res \ No newline at end of file diff --git "a/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" "b/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" new file mode 100644 index 0000000..bea11e1 --- /dev/null +++ "b/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" @@ -0,0 +1,11 @@ +class Solution(object): + def getNoZeroIntegers(self, n): + """ + :type n: int + :rtype: List[int] + """ + + for i in range(1, n): + tmp = n - i + if "0" not in str(i) and "0" not in str(tmp): + return [i, tmp] \ No newline at end of file diff --git "a/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" "b/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" new file mode 100644 index 0000000..2dd7a1b --- /dev/null +++ "b/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" @@ -0,0 +1,15 @@ +class Solution(object): + def minCut(self, s): + """ + :type s: str + :rtype: int + """ + # dp[i][j] + dp = [len(s) for _ in range(len(s) + 1)] + dp[0] = -1 + for i in range(len(s)): + for j in range(i + 1): + if s[j:i + 1] == s[j:i + 1][::-1]: + dp[i + 1] = min(dp[j] + 1, dp[i + 1]) + # print dp + return dp[-1] \ No newline at end of file diff --git "a/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" "b/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" new file mode 100644 index 0000000..936a69b --- /dev/null +++ "b/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" @@ -0,0 +1,34 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, neighbors): + self.val = val + self.neighbors = neighbors +""" +class Solution(object): + def cloneGraph(self, node): + """ + :type node: Node + :rtype: Node + """ + from collections import defaultdict, deque + # neibors = defaultdict(list) # key is the original nodes, value is its neibors + mapping = dict() # key is the original node, value is its copy + + queue = deque([node]) + visited = set() + visited.add(node) + while queue: + cur = queue.popleft() + visited.add(cur) + + copy = Node(cur.val, []) + mapping[cur] = copy + for neigh in cur.neighbors: + if neigh not in visited: + queue.append(neigh) + + for cur, copy in mapping.items(): + for each in cur.neighbors: + copy.neighbors.append(mapping[each]) + return mapping[node] \ No newline at end of file diff --git "a/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" "b/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" new file mode 100644 index 0000000..55bda80 --- /dev/null +++ "b/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" @@ -0,0 +1,7 @@ +class Solution(object): + def sortByBits(self, arr): + """ + :type arr: List[int] + :rtype: List[int] + """ + return sorted(arr, key = lambda x:(str(bin(x)).count("1"), x)) \ No newline at end of file diff --git "a/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" "b/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..d0f49c9 --- /dev/null +++ "b/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,13 @@ +class Solution(object): + def smallerNumbersThanCurrent(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + res = [0 for _ in nums] + for i in range(len(nums)): + for j in range(len(nums)): + if nums[j] < nums[i]: + res[i] += 1 + + return res \ No newline at end of file diff --git "a/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" "b/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..faabd50 --- /dev/null +++ "b/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,20 @@ +class Solution(object): + def sortString(self, s): + """ + :type s: str + :rtype: str + """ + from collections import Counter + dic = Counter(s) + res = "" + while len(res) < len(s): + for ch in "abcdefghijklmnopqrstuvwxyz": + if ch in dic and dic[ch]: + res += ch + dic[ch] -= 1 + for ch in "abcdefghijklmnopqrstuvwxyz"[::-1]: + if ch in dic and dic[ch]: + res += ch + dic[ch] -= 1 + + return res \ 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..32a3a01 --- /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,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 getTargetCopy(self, original, cloned, target): + """ + :type original: TreeNode + :type cloned: TreeNode + :type target: TreeNode + :rtype: TreeNode + """ + self.res = None + def dfs(node1, node2): + if not node1: + return + if node1 == target: + self.res = node2 + return + + dfs(node1.left, node2.left) + dfs(node1.right, node2.right) + + dfs(original, cloned) + return self.res \ No newline at end of file diff --git "a/138.\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/138-\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/138.\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/138-\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..500145b --- /dev/null +++ "b/138.\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/138-\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,26 @@ +""" +# 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 + """ + cur = head + mapping = dict() + while cur: + mapping[cur] = Node(cur.val, None, None) + cur = cur.next + + for cur, copy in mapping.items(): + if cur.next: + copy.next = mapping[cur.next] + if cur.random: + copy.random = mapping[cur.random] + return mapping[head] if head else head \ No newline at end of file diff --git "a/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" "b/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" new file mode 100644 index 0000000..037aa40 --- /dev/null +++ "b/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" @@ -0,0 +1,20 @@ +class Solution(object): + def findTheDistanceValue(self, arr1, arr2, d): + """ + :type arr1: List[int] + :type arr2: List[int] + :type d: int + :rtype: int + """ + res = 0 + + for num1 in arr1: + flag = 1 + for num2 in arr2: + if abs(num1 - num2) <= d: + flag = 0 + break + if flag: + res += 1 + + return res \ No newline at end of file diff --git "a/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" "b/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" new file mode 100644 index 0000000..f223e8b --- /dev/null +++ "b/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" @@ -0,0 +1,31 @@ +class Solution(object): + def maxNumberOfFamilies(self, n, reservedSeats): + """ + :type n: int + :type reservedSeats: List[List[int]] + :rtype: int + """ + from collections import defaultdict + dic = defaultdict(set) + res = 0 + usedrow = set() + for row, seat in reservedSeats: + dic[row].add(seat) + usedrow.add(row) + + for row in usedrow: + twothree = 2 not in dic[row] and 3 not in dic[row] + fourfive = 4 not in dic[row] and 5 not in dic[row] + sixseven = 6 not in dic[row] and 7 not in dic[row] + eightnine = 8 not in dic[row] and 9 not in dic[row] + + if twothree and fourfive and sixseven and eightnine: + res += 2 + elif twothree and fourfive: + res += 1 + elif fourfive and sixseven: + res += 1 + elif sixseven and eightnine: + res += 1 + return res + (n - len(usedrow)) * 2 + \ No newline at end of file diff --git "a/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" "b/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" new file mode 100644 index 0000000..ac2b840 --- /dev/null +++ "b/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" @@ -0,0 +1,21 @@ +class Solution(object): + def getKth(self, lo, hi, k): + """ + :type lo: int + :type hi: int + :type k: int + :rtype: int + """ + dic = {} + dic[1] = 0 + def func(x): + if x in dic: + return dic[x] + if x % 2: + res = 1 + func(3 * x + 1) + else: + res = 1 + func(x / 2) + dic[x] = res + return res + + return sorted(range(lo, hi + 1), key = lambda x: (func(x), x))[k - 1] \ No newline at end of file diff --git "a/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" "b/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" new file mode 100644 index 0000000..e843e45 --- /dev/null +++ "b/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" @@ -0,0 +1,16 @@ +class Solution(object): + def wordBreak(self, s, wordDict): + """ + :type s: str + :type wordDict: List[str] + :rtype: bool + """ + dp = [-1] # dp[i] 琛ㄧず浠0~涓嬫爣涓篿鐨勫崟璇嶅彲浠ヨ鎷嗗垎 + + for i, ch in enumerate(s): + for start in dp: + if s[start + 1:i + 1] in wordDict: + dp.append(i) + break + + return dp[-1] == len(s) - 1 \ No newline at end of file diff --git "a/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" "b/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" new file mode 100644 index 0000000..52fbeff --- /dev/null +++ "b/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" @@ -0,0 +1,8 @@ +class Solution(object): + def findLucky(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + l = [key for key, val in collections.Counter(arr).items() if key == val] + return max(l) if l else -1 \ No newline at end of file diff --git "a/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" "b/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" new file mode 100644 index 0000000..ebbe4d5 --- /dev/null +++ "b/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" @@ -0,0 +1,26 @@ +class Solution(object): + def numTeams(self, rating): + """ + :type rating: List[int] + :rtype: int + """ + from collections import defaultdict + + + def helper(rating): + dic = defaultdict(int) + res = 0 + + for i in range(len(rating)): + for j in range(i + 1, len(rating)): + if rating[j] > rating[i]: + dic[i] += 1 + + + for i in range(len(rating)): + for j in range(i + 1, len(rating)): + if rating[j] > rating[i]: + res += dic[j] + return res + + return helper(rating) + helper(rating[::-1]) 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..dc1328d --- /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,44 @@ +class UndergroundSystem(object): + + def __init__(self): + from collections import defaultdict + self.cnt = defaultdict(int) + self.total = defaultdict(int) + self.record = {} # key is id, val is the checkin stationName and time + def checkIn(self, id, stationName, t): + """ + :type id: int + :type stationName: str + :type t: int + :rtype: None + """ + self.record[id] = (stationName, t) + + def checkOut(self, id, stationName, t): + """ + :type id: int + :type stationName: str + :type t: int + :rtype: None + """ + checkinStation = self.record[id][0] + checkinTime = self.record[id][1] + + self.total[checkinStation + "#" + stationName] += t - checkinTime + self.cnt[checkinStation + "#" + stationName] += 1 + + + def getAverageTime(self, startStation, endStation): + """ + :type startStation: str + :type endStation: str + :rtype: float + """ + return self.total[startStation + "#" + endStation] * 1.0 / self.cnt[startStation + "#" + endStation] + + +# 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 diff --git "a/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" "b/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..e73c683 --- /dev/null +++ "b/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" @@ -0,0 +1,22 @@ +class Solution(object): + def countLargestGroup(self, n): + """ + :type n: int + :rtype: int + """ + from collections import defaultdict + l = defaultdict(int) + + def helper(num): + # 璁$畻num鏁颁綅涔嬪拰锛宔g锛氳緭鍏34, 杩斿洖3 + 4 = 7 + s = 0 + while num: + num, tmp = divmod(num, 10) + s += tmp + return s + + for num in range(1, n + 1): + l[helper(num)] += 1 + + mmax = max(l.values()) + return sum([1 for item in l.values() if item == mmax]) \ No newline at end of file diff --git "a/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" "b/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\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..8bd5502 --- /dev/null +++ "b/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,19 @@ +class Solution(object): + def canConstruct(self, s, k): + """ + :type s: str + :type k: int + :rtype: bool + """ + if k >= len(s): + # 闀垮害 == k锛屽繀鐒跺彲浠ワ紱闀垮害 < k锛屽繀鐒朵笉鍙互銆 + return k == len(s) + + from collections import Counter + dic = Counter(s) + # 瀵逛簬姣忎竴涓嚭鐜版鏁颁负濂囨暟娆$殑瀛楃鏉ヨ锛屾瘮濡 "aaa", 瀹冭嚦灏戣兘鏋勬垚涓涓洖鏂囦覆锛屾渶澶氳兘鏋勬垚涓変釜鍥炴枃涓诧紝 + s_odd = 0 + for val in dic.values(): + if val % 2: + s_odd += 1 + return s_odd <= k \ No newline at end of file diff --git "a/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" "b/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" new file mode 100644 index 0000000..ba60d1b --- /dev/null +++ "b/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" @@ -0,0 +1,20 @@ +class Solution(object): + def maxSatisfaction(self, satisfaction): + """ + :type satisfaction: List[int] + :rtype: int + """ + res = 0 + + s = sorted(satisfaction) + + for i in range(len(s)): + cnt = 1 + tmp = 0 + for j in range(i, len(s)): + tmp += cnt * s[j] + cnt += 1 + # print tmp + res = max(tmp, res) + + return res diff --git "a/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" "b/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..a01dd06 --- /dev/null +++ "b/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,17 @@ +class Solution(object): + def minSubsequence(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + s = sum(nums) + + t = 0 + res = [] + for num in sorted(nums)[::-1]: + res.append(num) + t += num + s -= num + + if t > s: + return res \ No newline at end of file diff --git "a/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" "b/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" new file mode 100644 index 0000000..08c4a9c --- /dev/null +++ "b/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" @@ -0,0 +1,15 @@ +class Solution(object): + def numSteps(self, s): + """ + :type s: str + :rtype: int + """ + cnt = 0 + s = int(s, 2) + while s != 1: + cnt += 1 + if s % 2: + s += 1 + else: + s //= 2 + return cnt \ No newline at end of file diff --git "a/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" "b/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..8bffec5 --- /dev/null +++ "b/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,38 @@ +class Solution(object): + def longestDiverseString(self, a, b, c): + """ + :type a: int + :type b: int + :type c: int + :rtype: str + """ + from heapq import * + heap = [] + res = "" + if a: + heappush(heap, (-a, "a")) + if b: + heappush(heap, (-b, "b")) + if c: + heappush(heap, (-c, "c")) + pre_cnt, pre_char = None, None + s = a + b + c + + while heap: + cnt, char = heappop(heap) + cnt = -cnt + # print cnt, char + + if cnt > s - cnt: + res += char * min(cnt, 2) + cnt -= min(cnt, 2) + s -= min(cnt, 2) + else: + res += char + cnt -= 1 + s -= 1 + + if pre_cnt: + heappush(heap, (-pre_cnt, pre_char)) + pre_cnt, pre_char = cnt, char + return res \ No newline at end of file diff --git "a/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" "b/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" new file mode 100644 index 0000000..5b41923 --- /dev/null +++ "b/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" @@ -0,0 +1,16 @@ +class Solution(object): + def stringMatching(self, words): + """ + :type words: List[str] + :rtype: List[str] + """ + fix = set() + res = [] + + for word1 in words: + for word2 in words: + if len(word1) < len(word2) and word1 in word2: + res.append(word1) + break + + 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..f27eefc --- /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,15 @@ +class Solution(object): + def processQueries(self, queries, m): + """ + :type queries: List[int] + :type m: int + :rtype: List[int] + """ + q = list(range(1, m + 1)) + res = [] + for i, x in enumerate(queries): + idx = q.index(queries[i]) + res.append(idx) + q.pop(idx) + q.insert(0, queries[i]) + return res \ No newline at end of file diff --git "a/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" "b/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" new file mode 100644 index 0000000..923436c --- /dev/null +++ "b/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" @@ -0,0 +1,14 @@ +class Solution(object): + def entityParser(self, text): + """ + :type text: str + :rtype: str + """ + t = text.replace(""", "\"") + t = t.replace("'", "\'") + + t = t.replace(">", ">") + t = t.replace("<", "<") + t = t.replace("⁄","/") + t = t.replace("&", "&") + return t \ No newline at end of file diff --git "a/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" "b/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" new file mode 100644 index 0000000..13ad386 --- /dev/null +++ "b/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" @@ -0,0 +1,13 @@ +class Solution(object): + def minStartValue(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + min_s = nums[0] + s = 0 + for num in nums: + s += num + min_s = min(min_s, s) + + return 1 if min_s >= 1 else 1 - min_s \ No newline at end of file diff --git "a/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" "b/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" new file mode 100644 index 0000000..b3bb5d8 --- /dev/null +++ "b/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" @@ -0,0 +1,22 @@ +class Solution(object): + def findMinFibonacciNumbers(self, k): + """ + :type k: int + :rtype: int + """ + first, second = 1, 1 + fib = [1, 1] + while second < k: + nxt = first + second + fib.append(nxt) + first = second + second = nxt + res = 0 + while k > 0: + idx = bisect.bisect_left(fib, k) + if fib[idx] == k: + k -= fib[idx] + else: + k -= fib[idx - 1] + res += 1 + return res \ No newline at end of file diff --git "a/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" "b/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..7a2e1ad --- /dev/null +++ "b/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,32 @@ +class Solution(object): + def reformat(self, s): + """ + :type s: str + :rtype: str + """ + char = [ch for ch in s if ch.isalpha()] + digit = [ch for ch in s if ch.isdigit()] + + if abs(len(char) - len(digit)) > 1: + return "" + + res = "" + i = 0 + if len(char) > len(digit): + while i < len(digit): + res += char[i] + res += digit[i] + i += 1 + res += char[i] + + else: + while i < len(char): + res += digit[i] + res += char[i] + i += 1 + + if len(char) < len(digit): + res += digit[i] + + 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..b407f23 --- /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,30 @@ +class Solution(object): + def displayTable(self, orders): + """ + :type orders: List[List[str]] + :rtype: List[List[str]] + """ + from collections import defaultdict + dishes = set() + tables = set() + dic = dict() + + for c, t, f in orders: + dishes.add(f) + tables.add(int(t)) + + if t not in dic: + dic[t] = defaultdict(int) + dic[t][f] += 1 + + dishes = sorted(list(dishes)) + res = [["Table"] + dishes] + + for t in sorted(list(tables)): + tmp = [str(t)] + for d in dishes: + tmp.append(str(dic[str(t)][d])) + res.append(tmp) + return res + + \ No newline at end of file diff --git "a/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" "b/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" new file mode 100644 index 0000000..7ab83fd --- /dev/null +++ "b/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" @@ -0,0 +1,31 @@ +class Solution(object): + def minNumberOfFrogs(self, croakOfFrogs): + """ + :type croakOfFrogs: str + :rtype: int + """ + from collections import defaultdict + if len(croakOfFrogs) % 5 != 0: + return -1 + + dic = defaultdict(int) + res = 0 + pre = {"r":"c", "o":"r", "a":"o"} + for ch in croakOfFrogs: + if ch == "c": + dic[ch] += 1 + + elif ch in "roa": + if dic[pre[ch]] == 0: + return -1 + dic[pre[ch]] -= 1 + dic[ch] += 1 + + elif ch == "k": + if dic["a"] == 0: + return -1 + dic["k"] -= 1 + + res = max(res, sum(dic.values())) + + return res \ No newline at end of file diff --git "a/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" new file mode 100644 index 0000000..cf48db3 --- /dev/null +++ "b/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" @@ -0,0 +1,17 @@ +class Solution(object): + def maxScore(self, s): + """ + :type s: str + :rtype: int + """ + zero = s.count("0") + one = len(s) - zero + zero_cnt = 0 + res = 0 + for i, x in enumerate(s[:-1]): + if x == "0": + zero_cnt += 1 + one_cnt = one - (i + 1 - zero_cnt) + res = max(res, zero_cnt + one_cnt) + + return res \ No newline at end of file diff --git "a/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" "b/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" new file mode 100644 index 0000000..fb17c81 --- /dev/null +++ "b/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" @@ -0,0 +1,21 @@ +class Solution(object): + def maxScore(self, cardPoints, k): + """ + :type cardPoints: List[int] + :type k: int + :rtype: int + """ + # 杩炵画鎽 n - k 寮犵墝锛屾眰鏈灏忕偣鏁板拰 + n = len(cardPoints) + s = sum(cardPoints) + + left, right = 0, n - k + window_sum = sum(cardPoints[left:right]) + min_s = window_sum + for right in range(n - k, n): + # print cardPoints[left:right + 1] + window_sum -= cardPoints[left] + window_sum += cardPoints[right] + min_s = min(min_s, window_sum) + left += 1 + return s - min_s diff --git "a/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" "b/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" new file mode 100644 index 0000000..2878cfe --- /dev/null +++ "b/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" @@ -0,0 +1,13 @@ +class Solution(object): + def countElements(self, arr): + """ + :type arr: List[int] + :rtype: int + """ + s = set(arr) + + res = 0 + for num in arr: + if num + 1 in s: + res += 1 + return res \ No newline at end of file diff --git "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" index 1c1ba4f..a4d3f35 100644 --- "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" +++ "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" @@ -1,11 +1,11 @@ class Solution: def simplifiedFractions(self, n: int) -> List[str]: import math - res = [] + res = set() for down in range(1, n + 1): for up in range(1, down): if math.gcd(up, down) == 1: - res.append(str(up) + "/" + str(down)) + res.add(str(up) + "/" + str(down)) - return res \ No newline at end of file + return list(res) \ No newline at end of file diff --git "a/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" "b/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" new file mode 100644 index 0000000..8942475 --- /dev/null +++ "b/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" @@ -0,0 +1,74 @@ +class Node(object): + def __init__(self, key, value, nxt, prev): + self.key = key + self.value = value + self.next = nxt + self.prev = prev +class LRUCache(object): + + def __init__(self, capacity): + """ + :type capacity: int + """ + self.capacity = capacity + self.record = dict() + self.head = Node(-1, -1, None, None) + self.tail = Node(-1, -1, self.head, self.head) + self.head.next = self.tail + self.head.prev = self.tail + + def move_to_end(self, key): + node = self.record[key] + + node.prev.next = node.next + node.next.prev = node.prev + + prev_to_tail = self.tail.prev + node.next = self.tail + node.prev = prev_to_tail + prev_to_tail.next = node + self.tail.prev = node + + + def get(self, key): + """ + :type key: int + :rtype: int + """ + + if key in self.record: + self.move_to_end(key) + return self.record[key].value + else: + return -1 + + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: None + """ + if key in self.record: + self.move_to_end(key) + self.record[key].value = value + else: + if self.capacity == 0: + self.record.pop(self.head.next.key) + new_first_node = self.head.next.next + self.head.next = new_first_node + new_first_node.prev = self.head + else: + self.capacity -= 1 + + prev_to_tail = self.tail.prev + new_node = Node(key, value, self.tail, prev_to_tail) + self.record[key] = new_node + prev_to_tail.next = new_node + self.tail.prev = new_node + + +# Your LRUCache object will be instantiated and called as such: +# obj = LRUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) \ No newline at end of file diff --git "a/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" "b/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" new file mode 100644 index 0000000..e1ef72a --- /dev/null +++ "b/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" @@ -0,0 +1,7 @@ +class Solution(object): + def reverseWords(self, s): + """ + :type s: str + :rtype: str + """ + return " ".join([item for item in s.strip().rstrip().split(" ") if item][::-1]) \ No newline at end of file diff --git "a/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" "b/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" new file mode 100644 index 0000000..0b9c216 --- /dev/null +++ "b/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.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/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" "b/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 0000000..720d9e2 --- /dev/null +++ "b/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,16 @@ +class Solution(object): + def twoSum(self, numbers, target): + """ + :type numbers: List[int] + :type target: int + :rtype: List[int] + """ + left, right = 0, len(numbers) - 1 + while 1: + tmp = numbers[left] + numbers[right] + if tmp == target: + return [left + 1, right + 1] + elif tmp < target: + left += 1 + elif tmp > target: + right -= 1 diff --git "a/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" "b/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" new file mode 100644 index 0000000..858b7a2 --- /dev/null +++ "b/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.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/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" "b/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\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..7533bb6 --- /dev/null +++ "b/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\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,31 @@ +# 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 = [] + last_element = None + while queue: + for _ in range(len(queue)): + cur = queue.popleft() + last_element = cur.val + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + res.append(last_element) + + return res \ No newline at end of file diff --git "a/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" "b/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" new file mode 100644 index 0000000..5e1ec45 --- /dev/null +++ "b/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" @@ -0,0 +1,33 @@ +class Solution(object): + def numIslands(self, M): + """ + :type grid: List[List[str]] + :rtype: int + """ + if not M or not M[0]: + return 0 + m, n = len(M), len(M[0]) + visited = [[0 for j in range(n)] for i in range(m)] + # print visited + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + res = 0 + + def dfs(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 M[x][y] == '1' and visited[x][y] ==0: + visited[x][y] = 1 + dfs(x, y) + + for i in range(m): + for j in range(n): + if M[i][j] == '1' and visited[i][j] == 0: + res += 1 + visited[i][j] = 1 + dfs(i, j) + # print visited + + return res \ No newline at end of file diff --git "a/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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..7e7be51 --- /dev/null +++ "b/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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,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/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" "b/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" new file mode 100644 index 0000000..d92c65c --- /dev/null +++ "b/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" @@ -0,0 +1,18 @@ +class Solution(object): + def generateParenthesis(self, n): + """ + :type n: int + :rtype: List[str] + """ + + res = [] + + def dfs(l, r, tmp): + if not l and not r: + res.append(tmp[:]) + if l: + dfs(l - 1, r, tmp + "(") + if l < r: + dfs(l, r - 1, tmp + ")") + dfs(n, n, "") + return res \ No newline at end of file diff --git "a/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" "b/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" new file mode 100644 index 0000000..66eb540 --- /dev/null +++ "b/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" @@ -0,0 +1,29 @@ +class Solution(object): + def maximalSquare(self, matrix): + """ + :type matrix: List[List[str]] + :rtype: int + """ + if not matrix or not matrix[0]: + return 0 + m, n = len(matrix), len(matrix[0]) + + dp = [[0 for _ in range(n)] for _ in range(m)] + res = 0 + for j in range(n): + if matrix[0][j] == "1": + dp[0][j] = 1 + res = 1 + + for i in range(m): + if matrix[i][0] == "1": + dp[i][0] = 1 + res = 1 + + for i in range(1, m): + for j in range(1, n): + if matrix[i][j] == "1": + dp[i][j] = min(dp[i - 1][j - 1], dp[i][j - 1], dp[i - 1][j]) + 1 + res = max(res, dp[i][j] ** 2) + # print dp + return res \ No newline at end of file diff --git "a/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" "b/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" new file mode 100644 index 0000000..21c0098 --- /dev/null +++ "b/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" @@ -0,0 +1,49 @@ +from collections import deque +class MyStack(object): + def __init__(self): + """ + Initialize your data structure here. + """ + self.q1 = deque() + self.q2 = deque() + + def push(self, x): + """ + Push element x onto stack. + :type x: int + :rtype: None + """ + self.q1.append(x) + while self.q2: + self.q1.append(self.q2.popleft()) + self.q2 = self.q1 + self.q1 = deque() + + def pop(self): + """ + Removes the element on top of the stack and returns that element. + :rtype: int + """ + return self.q2.popleft() + + def top(self): + """ + Get the top element. + :rtype: int + """ + return self.q2[0] + + def empty(self): + """ + Returns whether the stack is empty. + :rtype: bool + """ + return not self.q2 + + +# Your MyStack object will be instantiated and called as such: +# obj = MyStack() +# obj.push(x) +# param_2 = obj.pop() +# param_3 = obj.top() +# param_4 = obj.empty() \ No newline at end of file diff --git "a/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" "b/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" new file mode 100644 index 0000000..ca17ef9 --- /dev/null +++ "b/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" @@ -0,0 +1,45 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def reverseKGroup(self, head, k): + """ + :type head: ListNode + :type k: int + :rtype: ListNode + """ + if not head or not head.next: + return head + + cnt = 0 + p = head + while p: + cnt += 1 + if cnt == k: + break + p = p.next + + if cnt < k: + return head + + tail = p.next + p.next = None + + tmp = self.reverseKGroup(tail, k) + newhead = self.reverseLL(head) + head.next = tmp + + return newhead + + + + 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/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" "b/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" new file mode 100644 index 0000000..b0d5838 --- /dev/null +++ "b/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" @@ -0,0 +1,18 @@ +class Solution(object): + def canAttendMeetings(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: bool + """ + if not intervals or not intervals[0]: + return True + + intervals.sort(key = lambda x:x[0]) + end = intervals[0][1] + for i in range(1, len(intervals)): + s, e = intervals[i][0], intervals[i][1] + + if s < end: + return False + end = e + return True \ No newline at end of file diff --git "a/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" "b/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" new file mode 100644 index 0000000..13c7f4e --- /dev/null +++ "b/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" @@ -0,0 +1,20 @@ +class Solution(object): + def minMeetingRooms(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: int + """ + if not intervals or not intervals[0]: + return 0 + intervals.sort() + from heapq import * + queue = [] + heappush(queue, intervals[0][1]) + for i in range(1, len(intervals)): + start, end = intervals[i][0], intervals[i][1] + + if start >= queue[0]: + heappop(queue) + heappush(queue, end) + + return len(queue) \ No newline at end of file diff --git "a/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" "b/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" new file mode 100644 index 0000000..0b5774b --- /dev/null +++ "b/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" @@ -0,0 +1,17 @@ +class Solution(object): + def findDuplicate(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + + slow, fast = 0, 0 + while 1: + fast = nums[nums[fast]] + slow = nums[slow] + if fast == slow: + fast = 0 + while nums[fast] != nums[slow]: + fast = nums[fast] + slow = nums[slow] + return nums[slow] diff --git "a/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" "b/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" new file mode 100644 index 0000000..23ec6db --- /dev/null +++ "b/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" @@ -0,0 +1,50 @@ +class Solution(object): + def gameOfLife(self, board): + """ + :type board: List[List[int]] + :rtype: void Do not return anything, modify board in-place instead. + """ + m = len(board) + if m == 0: + return board + n = len(board[0]) + if n == 0: + return board + + alivex = list() + alivey = list() + + def neibor(x, y): #缁熻鍏釜閭诲眳閲屾湁鍑犱釜鏄椿缁嗚優锛1锛 + dx = [1, -1, 0, 0, 1, -1, -1, 1] + dy = [0, 0, 1, -1, 1, -1, 1, -1] + + cnt = 0 + for k in range(8): + xx = x + dx[k] + yy = y + dy[k] + + if 0 <= xx < m and 0 <= yy < n and board[xx][yy] == 1: + cnt += 1 + + return cnt + + + for i in range(m): + for j in range(n): + cnt = neibor(i, j) + # print i, j, cnt + if (board[i][j] == 1 and 2 <= cnt <= 3) or (board[i][j] == 0 and cnt == 3): + alivex.append(i) + alivey.append(j) + + alivecnt = 0 + for i in range(m): + for j in range(n): + board[i][j] = 0 + + if alivecnt < len(alivex): + if alivex[alivecnt] == i and alivey[alivecnt] == j: + board[i][j] = 1 + alivecnt += 1 + + return board \ No newline at end of file diff --git "a/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" "b/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" new file mode 100644 index 0000000..e602a1f --- /dev/null +++ "b/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" @@ -0,0 +1,29 @@ +class Solution(object): + def minTotalDistance(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + if not grid or not grid[0]: + return -1 + + m, n = len(grid), len(grid[0]) + row, col = [], [] + for i in range(m): + for j in range(n): + if grid[i][j]: + row.append(i) + col.append(j) + meet_point = [self.findMedian(row), self.findMedian(col)] + + res = 0 + for i in range(m): + for j in range(n): + if grid[i][j]: + res += abs(i - meet_point[0]) + abs(j - meet_point[1]) + return res + + + def findMedian(self, nums): + nums.sort() + return nums[len(nums) // 2] diff --git "a/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" "b/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" new file mode 100644 index 0000000..13447ba --- /dev/null +++ "b/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" @@ -0,0 +1,22 @@ +class Solution(object): + def getHint(self, secret, guess): + """ + :type secret: str + :type guess: str + :rtype: str + """ + from collections import Counter + dic_s = Counter(secret) + dic_g = Counter(guess) + + a, b = 0, 0 + for i in range(len(secret)): + if secret[i] == guess[i]: + a += 1 + dic_s[secret[i]] -= 1 + dic_g[secret[i]] -= 1 + + for i in dic_s & dic_g: + b += min(dic_s[i], dic_g[i]) + + return "{}A{}B".format(a, b) \ No newline at end of file diff --git "a/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" "b/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..f5fcf2e --- /dev/null +++ "b/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,14 @@ +class Solution(object): + def lengthOfLIS(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + dp = [1 for _ in nums] + + for i in range(len(nums)): + for j in range(i): + if nums[i] > nums[j]: + dp[i] = max(dp[i], dp[j] + 1) + + return max(dp) if dp else 0 \ No newline at end of file diff --git "a/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" "b/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" new file mode 100644 index 0000000..4abc475 --- /dev/null +++ "b/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" @@ -0,0 +1,35 @@ +class TreeNode(object): + def __init__(self, val): + self.left = None + self.right = None + self.val = val + self.left_subtree_cnt = 0 + +class Solution(object): + def countSmaller(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + + # 浠庡乏寰鍙冲鐞嗭紝鍙宠竟鏄湭鐭ョ殑锛屾墍浠ヤ笉濂藉紕 + # 浠庡彸寰宸﹀鐞嗭紝鍒欏浜庢瘡涓暟锛屽叾鍙宠竟鐨勬暟閮藉凡鐭 + res = [0 for _ in nums] + root = None + for i, num in enumerate(nums[::-1]): + root = self.insert(root, num, i, res) + return res[::-1] + + def insert(self, root, val, i, res): + if not root: + root = TreeNode(val) + elif root.val >= val: + root.left_subtree_cnt += 1 + root.left = self.insert(root.left, val, i, res) + elif root.val < val: + res[i] += root.left_subtree_cnt + 1 + root.right = self.insert(root.right, val, i, res) + + return root + + \ No newline at end of file diff --git "a/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" "b/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" new file mode 100644 index 0000000..13e35ba --- /dev/null +++ "b/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" @@ -0,0 +1,25 @@ +class Solution(object): + def coinChange(self, coins, amount): + """ + :type coins: List[int] + :type amount: int + :rtype: int + """ + from collections import deque + + queue = deque([(0, 0)]) + visited = set([0]) + while queue: + cur, step = queue.popleft() + if cur == amount: + return step + if cur > amount: + continue + + for coin in coins: + value = cur + coin + if value not in visited: + visited.add((value)) + queue.append((value, step + 1)) + + return -1 \ No newline at end of file diff --git "a/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" "b/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" new file mode 100644 index 0000000..513bb5a --- /dev/null +++ "b/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" @@ -0,0 +1,10 @@ +class Solution(object): + def isPowerOfThree(self, n): + """ + :type n: int + :rtype: bool + """ + t = 1 + while t < n: + t *= 3 + return n == t \ No newline at end of file diff --git "a/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" "b/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" new file mode 100644 index 0000000..8dc6838 --- /dev/null +++ "b/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" @@ -0,0 +1,21 @@ +class Solution(object): + def topKFrequent(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: List[int] + """ + from collections import Counter + from heapq import * + dic = Counter(nums) + queue = [] + for digit, fre in dic.items(): + if len(queue) < k: + heappush(queue, (fre, digit)) + else: + heappushpop(queue, (fre, digit)) + # print queue + res = [] + while queue: + res.append(heappop(queue)[1]) + return res \ No newline at end of file diff --git "a/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" "b/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" new file mode 100644 index 0000000..55d2c19 --- /dev/null +++ "b/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" @@ -0,0 +1,51 @@ +class Twitter: + + def __init__(self): + """ + Initialize your data structure here. + """ + self.stack = [] #鍙戞帹璁板綍 + self.f = {} #璁板綍姣忎釜浜哄叧娉ㄤ簡璋 + + + def postTweet(self, userId: int, tweetId: int) -> None: + """ + Compose a new tweet. + """ + self.stack.append((userId, tweetId)) + + + def getNewsFeed(self, userId: int) -> List[int]: + """ + Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. + """ + out = [] + following = [userId] + if userId in self.f: + following += self.f[userId] + for i in range(len(self.stack)-1, -1, -1): + if self.stack[i][0] in following: + out.append(self.stack[i][1]) + if len(out) == 10: + return out + return out + + + def follow(self, followerId: int, followeeId: int) -> None: + """ + Follower follows a followee. If the operation is invalid, it should be a no-op. + """ + if followerId not in self.f: + self.f[followerId] = [followeeId] + else: + if followeeId not in self.f[followerId]: + self.f[followerId].append(followeeId) + + + def unfollow(self, followerId: int, followeeId: int) -> None: + """ + Follower unfollows a followee. If the operation is invalid, it should be a no-op. + """ + if followerId in self.f: + if followeeId in self.f[followerId]: + self.f[followerId].remove(followeeId) \ No newline at end of file diff --git "a/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" "b/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" new file mode 100644 index 0000000..29817d8 --- /dev/null +++ "b/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" @@ -0,0 +1,21 @@ +class Solution(object): + def canMeasureWater(self, x, y, z): + """ + :type x: int + :type y: int + :type z: int + :rtype: bool + """ + if not z: + return True + if not x: + return y == z + if not y: + return x == z + if x + y < z: + return False + def gcd(a, b): + while a % b: + a, b = b, a % b + return b + return not z % gcd(x, y) \ No newline at end of file diff --git "a/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" "b/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" new file mode 100644 index 0000000..38ea4d5 --- /dev/null +++ "b/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" @@ -0,0 +1,35 @@ +# 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 findLeaves(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import defaultdict + self.dic = defaultdict(list) + res = [] + def get_Height(node): + if not node: + return -1 + lh = get_Height(node.left) + rh = get_Height(node.right) + h = max(lh, rh) + 1 + self.dic[h].append(node.val) + return h + + get_Height(root) + # print self.dic + h = 0 + while 1: + if h not in self.dic: + break + res.append(self.dic[h]) + h += 1 + return res + \ No newline at end of file diff --git "a/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" "b/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\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..d07d9f3 --- /dev/null +++ "b/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" @@ -0,0 +1,25 @@ +class Solution(object): + def kthSmallest(self, matrix, k): + """ + :type matrix: List[List[int]] + :type k: int + :rtype: int + """ + if not matrix or not matrix[0]: + return matrix + + from heapq import * + queue = [] + for i in range(len(matrix)): + heappush(queue, (matrix[i][0], i, 0)) + + cnt = 0 + while cnt < k: + cnt += 1 + + val, row, col = heappop(queue) + if col + 1 < len(matrix): + heappush(queue, (matrix[row][col + 1], row, col + 1)) + + return val + \ No newline at end of file diff --git "a/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" "b/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" new file mode 100644 index 0000000..140f172 --- /dev/null +++ "b/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" @@ -0,0 +1,20 @@ +class Solution(object): + def lexicalOrder(self, n): + """ + :type n: int + :rtype: List[int] + """ + return sorted(range(1, n + 1), key = str) +# res = [] + +# def dfs(k): +# if k > n: +# return +# res.append(k) + +# for i in range(10): +# dfs(10 * k + i) + +# for i in range(1, 10): +# dfs(i) +# return res \ No newline at end of file diff --git "a/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" "b/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" new file mode 100644 index 0000000..a640d0d --- /dev/null +++ "b/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" @@ -0,0 +1,12 @@ +class Solution(object): + def firstUniqChar(self, s): + """ + :type s: str + :rtype: int + """ + dic = collections.Counter(s) + + for i, ch in enumerate(s): + if dic[ch] == 1: + return i + return -1 \ No newline at end of file diff --git "a/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" "b/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" new file mode 100644 index 0000000..f69bb27 --- /dev/null +++ "b/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" @@ -0,0 +1,22 @@ +class Solution(object): + + def __init__(self, nums): + """ + :type nums: List[int] + """ + from collections import defaultdict + self.dic = defaultdict(list) + for i, num in enumerate(nums): + self.dic[num].append(i) + + def pick(self, target): + """ + :type target: int + :rtype: int + """ + return random.choice(self.dic[target]) + + +# Your Solution object will be instantiated and called as such: +# obj = Solution(nums) +# param_1 = obj.pick(target) \ No newline at end of file diff --git "a/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" "b/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" new file mode 100644 index 0000000..1acf581 --- /dev/null +++ "b/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" @@ -0,0 +1,7 @@ +class Solution(object): + def longestPalindrome(self, s): + """ + :type s: str + :rtype: int + """ + return len(s) -max(0,sum([s.count(i)%2 for i in set(s)])-1) \ No newline at end of file diff --git "a/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" "b/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" new file mode 100644 index 0000000..a5926c1 --- /dev/null +++ "b/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" @@ -0,0 +1,31 @@ +class Solution(object): + def trap(self, height): + """ + :type height: List[int] + :rtype: int + """ + left_max = [0 for _ in height] + right_max = [0 for _ in height] + water = [0 for _ in height] + + for i in range(len(height)): + if i - 1 >= 0: + left_max[i] = max(left_max[i - 1], height[i]) + else: + left_max[i] = height[i] + + for i in range(len(height) - 1, -1, -1): + if i < len(height) - 1: + right_max[i] = max(right_max[i + 1], height[i]) + else: + right_max[i] = height[i] + + for i in range(len(height)): + tmp = min(left_max[i], right_max[i]) - height[i] + if tmp > 0: + water[i] = tmp + # print height + # print water + # print left_max + # print right_max + return sum(water) \ No newline at end of file diff --git "a/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..669fb96 --- /dev/null +++ "b/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,47 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left=None, right=None): + self.val = val + self.left = left + self.right = right +""" +class Solution(object): + def treeToDoublyList(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return root + if not root.left and not root.right: + root.left = root + root.right = root + return root + + left = self.treeToDoublyList(root.left) + right = self.treeToDoublyList(root.right) + if root.left and root.right: + left_tail = left.left + right_tail = right.left + + left_tail.right = root + root.left = left_tail + root.right = right + right.left = root + + left.left = right_tail + right_tail.right = left + elif root.left: + left_tail = left.left + left_tail.right = root + root.left = left_tail + left.left = root + root.right = left + elif root.right: + right_tail = right.left + root.right = right + root.left = right_tail + right_tail.right = root + right.left = root + return left if left else root \ No newline at end of file diff --git "a/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..08d25c6 --- /dev/null +++ "b/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,38 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, prev, next, child): + self.val = val + self.prev = prev + self.next = next + self.child = child +""" +class Solution(object): + def flatten(self, head): + """ + :type head: Node + :rtype: Node + """ + if not head: + return head + + def helper(node): + # 杩斿洖鐨勬槸鏈鍚庝竴涓妭鐐 + if not node: + return + while node: + nxt = node.next # 澶囦唤 next + if not nxt: + tail = node # 璁板綍 tail锛岀敤浜庤繑鍥 + if node.child: + node.next = node.child # 鎶奵hild 鍙樻垚next + node.next.prev = node + t = helper(node.child) # 閫掑綊澶勭悊锛宼 鏄鐞嗕箣鍚庣殑 鍘熸潵鐨刢hild 鐨勬渶鍚庝竴涓妭鐐 + node.child = None # 鎶奵hild 缃┖ + if nxt: # 濡傛灉鏈塶ext 閮ㄥ垎锛屽氨璁﹏ext鐨刾rev鎸囧悜 鍘熸潵鐨刢hild 澶勭悊涔嬪悗鐨勬渶鍚庝竴涓妭鐐 + nxt.prev = t + t.next = nxt # 璁 t.next 鎸囧悜鍘熸潵鐨 next + node = node.next + return tail + helper(head) + return head \ No newline at end of file diff --git "a/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" "b/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" new file mode 100644 index 0000000..cffe9ed --- /dev/null +++ "b/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" @@ -0,0 +1,23 @@ +class Solution(object): + def findRightInterval(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: List[int] + """ + dic = {} + for i, (start, end) in enumerate(intervals): + dic[start] = i + + res = [-1 for _ in range(len(intervals))] + + l = [interval[0] for interval in intervals] + l = sorted(l, key = lambda x:x) + + for i, (start, end) in enumerate(intervals): + idx = bisect.bisect_left(l, end) + if idx < len(l): + res[i] = dic[l[idx]] + + return res + + \ No newline at end of file diff --git "a/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" "b/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" new file mode 100644 index 0000000..ae75d3c --- /dev/null +++ "b/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" @@ -0,0 +1,44 @@ +# 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 + """ + s1, s2 = [], [] + while l1: + s1.append(l1.val) + l1 = l1.next + + while l2: + s2.append(l2.val) + l2 = l2.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 \ No newline at end of file diff --git "a/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" "b/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" new file mode 100644 index 0000000..64b8736 --- /dev/null +++ "b/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" @@ -0,0 +1,20 @@ +class Solution(object): + def findMinArrowShots(self, points): + """ + :type points: List[List[int]] + :rtype: int + """ + if not points or not points[0]: + return 0 + + points.sort(key = lambda x:x[1]) + + arrow = points[0][1] + + res = 1 + for point in points: + if arrow < point[0]: + res += 1 + arrow = point[1] + + return res \ No newline at end of file diff --git "a/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" "b/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" new file mode 100644 index 0000000..e8fc752 --- /dev/null +++ "b/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" @@ -0,0 +1,60 @@ +class LFUCache(object): + + def __init__(self, capacity): + """ + :type capacity: int + """ + self.use = {} # 浣跨敤鐨勯鐜 + self.cache = {} # 鍊 + self.size = capacity + self.arr = [] # 纭繚棰戠巼涓鏍锋椂锛屽垹闄ゆ渶杩戞病鏈変娇鐢 + + def get(self, key): + """ + :type key: int + :rtype: int + """ + if key in self.cache: + self.use[key] += 1 + self.arr.remove(key) + self.arr.append(key) + return self.cache[key] + else: + return -1 + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: None + """ + if key in self.cache: + self.cache[key] = value + self.use[key] += 1 + self.arr.remove(key) + self.arr.append(key) + else: + if len(self.cache) < self.size: + self.cache[key] = value + self.use[key] = 1 + self.arr.append(key) + else: + if self.use: + v = min(self.use.values()) + lost = -1 + for x in self.arr: + if self.use[x] == v: + lost = x + break + self.cache.pop(lost) + self.use.pop(lost) + self.arr.remove(lost) + self.cache[key] = value + self.use[key] = 1 + self.arr.append(key) + + +# Your LFUCache object will be instantiated and called as such: +# obj = LFUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) \ No newline at end of file diff --git "a/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" "b/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" new file mode 100644 index 0000000..08cf39f --- /dev/null +++ "b/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" @@ -0,0 +1,57 @@ +class Solution(object): + def getMaxRepetitions(self, s1, n1, s2, n2): + """ + :type s1: str + :type n1: int + :type s2: str + :type n2: int + :rtype: int + """ + if n1 == 0: + return 0 + s1cnt, index, s2cnt = 0, 0, 0 + # recall 鏄垜浠敤鏉ユ壘寰幆鑺傜殑鍙橀噺锛屽畠鏄竴涓搱甯屾槧灏 + # 鎴戜滑濡備綍鎵惧惊鐜妭锛熷亣璁炬垜浠亶鍘嗕簡 s1cnt 涓 s1锛屾鏃跺尮閰嶅埌浜嗙 s2cnt 涓 s2 涓殑绗 index 涓瓧绗 + # 濡傛灉鎴戜滑涔嬪墠閬嶅巻浜 s1cnt' 涓 s1 鏃讹紝鍖归厤鍒扮殑鏄 s2cnt' 涓 s2 涓悓鏍风殑绗 index 涓瓧绗︼紝閭d箞灏辨湁寰幆鑺備簡 + # 鎴戜滑鐢 (s1cnt', s2cnt', index) 鍜 (s1cnt, s2cnt, index) 琛ㄧず涓ゆ鍖呭惈鐩稿悓 index 鐨勫尮閰嶇粨鏋 + # 閭d箞鍝堝笇鏄犲皠涓殑閿氨鏄 index锛屽煎氨鏄 (s1cnt', s2cnt') 杩欎釜浜屽厓缁 + # 寰幆鑺傚氨鏄紱 + # - 鍓 s1cnt' 涓 s1 鍖呭惈浜 s2cnt' 涓 s2 + # - 浠ュ悗鐨勬瘡 (s1cnt - s1cnt') 涓 s1 鍖呭惈浜 (s2cnt - s2cnt') 涓 s2 + # 閭d箞杩樹細鍓╀笅 (n1 - s1cnt') % (s1cnt - s1cnt') 涓 s1, 鎴戜滑瀵硅繖浜涗笌 s2 杩涜鏆村姏鍖归厤 + # 娉ㄦ剰 s2 瑕佷粠绗 index 涓瓧绗﹀紑濮嬪尮閰 + recall = dict() + while True: + # 鎴戜滑澶氶亶鍘嗕竴涓 s1锛岀湅鐪嬭兘涓嶈兘鎵惧埌寰幆鑺 + s1cnt += 1 + for ch in s1: + if ch == s2[index]: + index += 1 + if index == len(s2): + s2cnt, index = s2cnt + 1, 0 + # 杩樻病鏈夋壘鍒板惊鐜妭锛屾墍鏈夌殑 s1 灏辩敤瀹屼簡 + if s1cnt == n1: + return s2cnt // n2 + # 鍑虹幇浜嗕箣鍓嶇殑 index锛岃〃绀烘壘鍒颁簡寰幆鑺 + if index in recall: + s1cnt_prime, s2cnt_prime = recall[index] + # 鍓 s1cnt' 涓 s1 鍖呭惈浜 s2cnt' 涓 s2 + pre_loop = (s1cnt_prime, s2cnt_prime) + # 浠ュ悗鐨勬瘡 (s1cnt - s1cnt') 涓 s1 鍖呭惈浜 (s2cnt - s2cnt') 涓 s2 + in_loop = (s1cnt - s1cnt_prime, s2cnt - s2cnt_prime) + break + else: + recall[index] = (s1cnt, s2cnt) + + # ans 瀛樺偍鐨勬槸 S1 鍖呭惈鐨 s2 鐨勬暟閲忥紝鑰冭檻鐨勪箣鍓嶇殑 pre_loop 鍜 in_loop + ans = pre_loop[1] + (n1 - pre_loop[0]) // in_loop[0] * in_loop[1] + # S1 鐨勬湯灏捐繕鍓╀笅涓浜 s1锛屾垜浠毚鍔涜繘琛屽尮閰 + rest = (n1 - pre_loop[0]) % in_loop[0] + for i in range(rest): + for ch in s1: + if ch == s2[index]: + index += 1 + if index == len(s2): + ans, index = ans + 1, 0 + # S1 鍖呭惈 ans 涓 s2锛岄偅涔堝氨鍖呭惈 ans / n2 涓 S2 + return ans // n2 diff --git "a/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" "b/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" new file mode 100644 index 0000000..2091668 --- /dev/null +++ "b/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" @@ -0,0 +1,16 @@ +class Solution(object): + def findComplement(self, num): + """ + :type num: int + :rtype: int + """ + s = bin(num)[2:] + b = "" + for ch in s: + + if ch == "0": + b += "1" + else: + b += "0" + # print b + return int(b,2) \ No newline at end of file diff --git "a/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" "b/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" new file mode 100644 index 0000000..9ce810a --- /dev/null +++ "b/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" @@ -0,0 +1,20 @@ +class Solution(object): + def totalHammingDistance(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if not nums: + return 0 + res = 0 + mask = 1 + for i in range(32): + cnt_one = 0 + for num in nums: + cnt_one += 1 if num & mask else 0 + + res += cnt_one * (len(nums) - cnt_one) + mask = mask << 1 + return res + + \ No newline at end of file diff --git "a/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" "b/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" new file mode 100644 index 0000000..a58af44 --- /dev/null +++ "b/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" @@ -0,0 +1,18 @@ +class Solution(object): + def licenseKeyFormatting(self, S, K): + """ + :type S: str + :type K: int + :rtype: str + """ + s = "".join(S.split("-")).upper() + length_of_first_part = len(s) % K + if not length_of_first_part: + length_of_first_part = K + + res = s[:length_of_first_part] + for i in range(length_of_first_part, len(s), K): + res += "-" + res += s[i:i+K] + return res + \ No newline at end of file diff --git "a/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" "b/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\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..b11b5a3 --- /dev/null +++ "b/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\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,13 @@ +class Solution(object): + def groupAnagrams(self, strs): + """ + :type strs: List[str] + :rtype: List[List[str]] + """ + from collections import defaultdict + dic = defaultdict(list) + for word in strs: + sortedword = "".join(sorted(word)) + dic[sortedword].append(word) + + return dic.values() \ No newline at end of file diff --git "a/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" "b/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\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..b488d0e --- /dev/null +++ "b/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\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,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/50.Pow(x,n)/50-Pow(x,n).py b/50.Pow(x,n)/50-Pow(x,n).py new file mode 100644 index 0000000..47442e6 --- /dev/null +++ b/50.Pow(x,n)/50-Pow(x,n).py @@ -0,0 +1,8 @@ +class Solution(object): + def myPow(self, x, n): + """ + :type x: float + :type n: int + :rtype: float + """ + return x ** n \ No newline at end of file diff --git "a/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" "b/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" new file mode 100644 index 0000000..05f6119 --- /dev/null +++ "b/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" @@ -0,0 +1,17 @@ +class Solution(object): + def longestPalindromeSubseq(self, s): + """ + :type s: str + :rtype: int + """ + n = len(s) + dp = [[0] * n for _ in range(n)] + + for i in range(n): + dp[i][i] = 1 + for j in range(i - 1, -1, -1): + if s[i] == s[j]: + dp[i][j] = dp[i - 1][j + 1] + 2 + else: + dp[i][j] = max(dp[i][j + 1], dp[i - 1][j]) + return dp[n - 1][0] \ No newline at end of file diff --git "a/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" "b/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" new file mode 100644 index 0000000..4358bfe --- /dev/null +++ "b/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" @@ -0,0 +1,19 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if not nums: + return 0 + dp = [0 for _ in nums] + dp[0] = nums[0] + + for i, x in enumerate(nums): + if i: + if dp[i - 1] > 0: + dp[i] = max(dp[i - 1] + x, dp[i]) + else: + dp[i] = x + + return max(dp) \ No newline at end of file diff --git "a/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" "b/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" new file mode 100644 index 0000000..8eafb66 --- /dev/null +++ "b/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" @@ -0,0 +1,38 @@ +from collections import deque +class Solution(object): + def updateMatrix(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: List[List[int]] + """ + if not matrix or not matrix[0]: + return matrix + m, n = len(matrix), len(matrix[0]) + res = matrix[:] + + q = deque() + + for i in range(m): + for j in range(n): + if matrix[i][j] == 0: + q.append([[i, j], 0]) + + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + visited = [[0 for _ in range(n + 1)] for _ in range(m + 1)] + + while q: + tmp, distance = q.popleft() + x0, y0 = tmp[0], tmp[1] + + if matrix[x0][y0] == 1: + res[x0][y0] = distance + + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and visited[x][y] != 1: + q.append([[x, y], distance + 1]) + visited[x][y] = 1 + return res \ No newline at end of file diff --git "a/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" "b/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" new file mode 100644 index 0000000..8814891 --- /dev/null +++ "b/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.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 diameterOfBinaryTree(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + def Height(node): + if not node: + return 0 + return 1 + max(Height(node.left), Height(node.right)) + return max(self.diameterOfBinaryTree(root.left), Height(root.left) + Height(root.right), self.diameterOfBinaryTree(root.right)) \ No newline at end of file diff --git "a/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" "b/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" new file mode 100644 index 0000000..8198fc2 --- /dev/null +++ "b/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" @@ -0,0 +1,13 @@ +class Solution(object): + def canJump(self, nums): + """ + :type nums: List[int] + :rtype: bool + """ + + max_jump = 0 + for index, num in enumerate(nums): + if index > max_jump: + return False + max_jump = max(max_jump, index + num) + return True \ No newline at end of file diff --git "a/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" "b/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" new file mode 100644 index 0000000..0283b38 --- /dev/null +++ "b/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" @@ -0,0 +1,7 @@ +class Solution(object): + def checkRecord(self, s): + """ + :type s: str + :rtype: bool + """ + return s.count("A") <= 1 and "LLL" not in s \ No newline at end of file diff --git "a/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" "b/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" new file mode 100644 index 0000000..c005fbe --- /dev/null +++ "b/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" @@ -0,0 +1,24 @@ +class Solution(object): + def merge(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: List[List[int]] + """ + if not intervals or not intervals[0]: + return intervals + + intervals = sorted(intervals, key = lambda x:x[0]) + + res = [] + start, end = intervals[0][0], intervals[0][1] + for interval in intervals: + s, e = interval[0], interval[1] + + if s <= end: # overlap + end = max(end, e) + else: + res.append([start, end]) + start, end = s, e + + res.append([start, end]) + return res \ No newline at end of file diff --git "a/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" "b/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..0b63b1d --- /dev/null +++ "b/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,22 @@ +class Solution(object): + def subarraySum(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: int + """ + prefix = [] + + for i, num in enumerate(nums): + if i: + prefix.append(num + prefix[-1]) + else: + prefix.append(num) + + res = 0 + dic = collections.defaultdict(int) + dic[0] = 1 + for s in prefix: + res += dic[s - k] + dic[s] += 1 + return res \ No newline at end of file diff --git "a/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" "b/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" new file mode 100644 index 0000000..de11b13 --- /dev/null +++ "b/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" @@ -0,0 +1,7 @@ +class Solution(object): + def arrayPairSum(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + return sum(sorted(nums)[::2]) \ No newline at end of file diff --git "a/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" "b/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" new file mode 100644 index 0000000..0f2bddc --- /dev/null +++ "b/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" @@ -0,0 +1,20 @@ +class Solution(object): + def matrixReshape(self, nums, r, c): + """ + :type nums: List[List[int]] + :type r: int + :type c: int + :rtype: List[List[int]] + """ + m, n = len(nums), len(nums[0]) + if r * c != m * n: + return nums + nums = sum(nums, []) + + res = [[0 for _ in range(c)] for _ in range(r)] + + for i in range(r): + for j in range(c): + res[i][j] = nums[i * c + j] + + return res \ No newline at end of file diff --git "a/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" "b/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" new file mode 100644 index 0000000..bc5a818 --- /dev/null +++ "b/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" @@ -0,0 +1,35 @@ +class Solution(object): + def insert(self, intervals, newInterval): + """ + :type intervals: List[List[int]] + :type newInterval: List[int] + :rtype: List[List[int]] + """ + + return self.merge(intervals + [newInterval]) + + + + def merge(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: List[List[int]] + """ + if not intervals or not intervals[0]: + return intervals + + intervals = sorted(intervals, key = lambda x:x[0]) + + res = [] + start, end = intervals[0][0], intervals[0][1] + for interval in intervals: + s, e = interval[0], interval[1] + + if s <= end: # overlap + end = max(end, e) + else: + res.append([start, end]) + start, end = s, e + + res.append([start, end]) + return res \ No newline at end of file diff --git "a/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" "b/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" new file mode 100644 index 0000000..7456e24 --- /dev/null +++ "b/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.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 isSubtree(self, s, t): + """ + :type s: TreeNode + :type t: TreeNode + :rtype: bool + """ + + if not s and not t: + return True + if s and not t: + return False + if t and not s: + return False + + return self.isSameTree(t, s) or self.isSubtree(s.left, t) or self.isSubtree(s.right, t) + + def isSameTree(self, t1, t2): + if not t1 and not t2: + return True + if t1 and not t2: + return False + if t2 and not t1: + return False + return t1.val == t2.val and self.isSameTree(t1.left, t2.left) and self.isSameTree(t1.right, t2.right) \ No newline at end of file diff --git "a/58.\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/58-\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/58.\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/58-\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..77fb484 --- /dev/null +++ "b/58.\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/58-\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,9 @@ +class Solution(object): + def lengthOfLastWord(self, s): + """ + :type s: str + :rtype: int + """ + if not s.split(): + return 0 + return len(s.split()[-1]) \ No newline at end of file diff --git "a/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" "b/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..33bc985 --- /dev/null +++ "b/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,19 @@ +class Solution(object): + def findUnsortedSubarray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + s = sorted(nums) + if s == nums: + return 0 + for i in range(len(s)): + if s[i] != nums[i]: + break + for j in range(len(s) - 1, -1, -1): + if s[j] != nums[j]: + break + # print i, j + # print s, nums + return len(s) - i - (len(s) - 1 -j) + \ No newline at end of file diff --git "a/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" "b/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" new file mode 100644 index 0000000..9347d22 --- /dev/null +++ "b/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution(object): + def judgeSquareSum(self, c): + """ + :type c: int + :rtype: bool + """ + for i in range(int(c ** 0.5) + 1): + t = c - i ** 2 + s = int (t ** 0.5) + if t == s ** 2: + return True + return False if c else True \ No newline at end of file diff --git "a/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" "b/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" new file mode 100644 index 0000000..99bf7db --- /dev/null +++ "b/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def findDerangement(self, n): + """ + :type n: int + :rtype: int + """ + res = 0 + for i in range(n + 1): + res = (i * res + (-1) ** i) % (10 ** 9 + 7) + return res \ No newline at end of file diff --git "a/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" "b/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" new file mode 100644 index 0000000..e4e3e3c --- /dev/null +++ "b/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.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/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" "b/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" new file mode 100644 index 0000000..905712b --- /dev/null +++ "b/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" @@ -0,0 +1,35 @@ +class Solution(object): + def maxAreaOfIsland(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]) + self.res = 0 + self.tmp = 0 + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + + def dfs(x0, y0): + self.tmp += 1 + self.res = max(self.res, self.tmp) + + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x< m and 0 <= y < n and grid[x][y] == 1: + grid[x][y] = 0 + dfs(x, y) + + + for i in range(m): + for j in range(n): + if grid[i][j]: + grid[i][j] = 0 + self.tmp = 0 + dfs(i, j) + return self.res \ No newline at end of file diff --git "a/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" "b/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" new file mode 100644 index 0000000..bffc0f3 --- /dev/null +++ "b/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" @@ -0,0 +1,39 @@ +class Solution(object): + def canPartitionKSubsets(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: bool + """ + s = sum(nums) + if s % k != 0 or len(nums) < k: + return False + + target = s / k + + nums.sort(reverse = True) + visited = set() + + self.res = False + def dfs(cnt, tmp, start): + if tmp == target: + dfs(cnt - 1, 0, 0) + + if cnt == 0: + self.res = True + return + if not self.res: + for i in range(start, len(nums)): + if i not in visited and tmp + nums[i] <= target: + visited.add(i) + dfs(cnt, tmp + nums[i], i + 1) + visited.remove(i) + dfs(k, 0, 0) + return self.res + + + + + + + \ No newline at end of file diff --git "a/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" "b/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" new file mode 100644 index 0000000..81e9fd3 --- /dev/null +++ "b/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" @@ -0,0 +1,25 @@ +class Solution(object): + def minDistance(self, word1, word2): + """ + :type word1: str + :type word2: str + :rtype: int + """ + #鐢╠p[i][j]琛ㄧずword1[:i + 1], word2[:j + 1]杩欎釜闂鐨勮В + m, n = len(word1), len(word2) + dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] + + for i in range(m + 1): + dp[i][0] = i + + for i in range(n + 1): + dp[0][i] = i + + for i in range(1, m + 1): + for j in range(1, n + 1): + if word1[i - 1] == word2[j - 1]: + dp[i][j] = dp[i - 1][j - 1] + else: + dp[i][j] = 1 + min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) #鍒嗗埆瀵瑰簲鎻掑叆锛屾浛鎹紝鍒犻櫎 + + return dp[m][n] \ No newline at end of file diff --git "a/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" "b/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" new file mode 100644 index 0000000..58c9a94 --- /dev/null +++ "b/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" @@ -0,0 +1,13 @@ +class Solution(object): + def anagramMappings(self, A, B): + """ + :type A: List[int] + :type B: List[int] + :rtype: List[int] + """ + + dic = dict() + for i, x in enumerate(B): + dic[x] = i + + return [dic[x] for x in A] \ No newline at end of file diff --git "a/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" "b/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" new file mode 100644 index 0000000..8216656 --- /dev/null +++ "b/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" @@ -0,0 +1,39 @@ +class Solution(object): + def partitionLabels(self, S): + """ + :type S: str + :rtype: List[int] + """ + from collections import defaultdict + dic = defaultdict(list) + + for ch in "abcdefghijklmnopqrstuvwxyz": + for i, char in enumerate(S): + if char == ch: + dic[ch].append(i) + break + + for i in range(len(S) - 1, -1, -1): + if S[i] == ch: + dic[ch].append(i) + break + + + intervals = [] + for val in dic.values(): + intervals.append(val) + + intervals.sort() + #print intervals + + res = [] + start, end = 0, 0 + for s, e in intervals: + if s > end: + res.append(end - start + 1) + start, end = s, e + else: + end = max(e, end) + res.append(end - start + 1) + + return res \ No newline at end of file diff --git "a/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" "b/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" new file mode 100644 index 0000000..4b0e5c9 --- /dev/null +++ "b/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" @@ -0,0 +1,13 @@ +class Solution(object): + def numJewelsInStones(self, J, S): + """ + :type J: str + :type S: str + :rtype: int + """ + J = set(J) + res = 0 + for s in S: + if s in J: + res += 1 + return res \ No newline at end of file diff --git "a/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" "b/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" new file mode 100644 index 0000000..ad43f92 --- /dev/null +++ "b/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" @@ -0,0 +1,31 @@ +class Solution(object): + def numMatchingSubseq(self, S, words): + """ + :type S: str + :type words: List[str] + :rtype: int + """ + from collections import defaultdict + + dic = defaultdict(list) + for i, ch in enumerate(S): + dic[ch].append(i) + + res = 0 + for word in words: + pre = -1 + flag = True + for i, ch in enumerate(word): + l = dic[ch] + # 鍦╨鎵剧涓涓瘮pre澶х殑鍏冪礌 + idx = bisect.bisect(l, pre) + + if idx == len(l):# 娌℃壘鍒 + flag = False + break + pre = l[idx] + + if flag: + res += 1 + + return res \ No newline at end of file diff --git "a/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" "b/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" new file mode 100644 index 0000000..7b8a7be --- /dev/null +++ "b/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" @@ -0,0 +1,36 @@ +class Solution(object): + def myAtoi(self, s): + """ + :type str: str + :rtype: int + """ + s = s.strip() + + if not s: + return 0 + + sign = 1 + INT_MAX, INT_MIN = 2 ** 31 - 1, -(2 ** 31) + + if s[0] == "+": + s = s[1:] + elif s[0] == "-": + s = s[1:] + sign = -1 + elif not s[0].isdigit(): + return 0 + + num = "0" + for ch in s: + if ch.isdigit(): + num += ch + else: + break + + num = sign * int(num) + + if num > INT_MAX: + return INT_MAX + elif num < INT_MIN: + return INT_MIN + return num \ No newline at end of file diff --git "a/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" "b/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" new file mode 100644 index 0000000..59c336c --- /dev/null +++ "b/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" @@ -0,0 +1,38 @@ +class Solution(object): + def expressiveWords(self, S, words): + """ + :type S: str + :type words: List[str] + :rtype: int + """ + + s = set(S) + res = 0 + for word in words: + if len(S) < len(word): + continue + + i, j = 0, 0 + flag = 0 + while i < len(S) and j < len(word): + if S[i] != word[j]: + flag = 1 + break + pre = S[i] + cnt_i = 0 + while i < len(S) and S[i] == pre: + i += 1 + cnt_i += 1 + + cnt_j = 0 + while j < len(word) and word[j] == pre: + j += 1 + cnt_j += 1 + + # print cnt_i, cnt_j + if (cnt_i < 3 and cnt_i != cnt_j) or cnt_i < cnt_j: + flag = 1 + + if not flag and i == len(S): + res += 1 + return res \ No newline at end of file diff --git "a/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" "b/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" new file mode 100644 index 0000000..618a6c9 --- /dev/null +++ "b/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" @@ -0,0 +1,36 @@ +class Trie(object): + def __init__(self): + """ + Initialize your data structure here. + """ + self.root = {} + self.char_cnt = 0 # 缁熻 a - z 瀛楃涓暟 + self.word_cnt = 0 # 缁熻缁撳熬绗 # 涓暟 + def insert(self, word): + """ + Inserts a word into the trie. + :type word: str + :rtype: None + """ + node = self.root + for char in word: # word 鍏ユ爲 + node = node.setdefault(char, {}) + + if not node: # not node 灏变唬琛ㄥ綋鍓 word 涓嶆槸涔嬪墠鏌愪竴 word 鐨勫悗缂 + self.word_cnt += 1 + self.char_cnt += len(word) + node["end"] = True + +class Solution(object): + def minimumLengthEncoding(self, words): + """ + :type words: List[str] + :rtype: int + """ + ttree = Trie() + + for word in sorted(words, key = lambda x:len(x), reverse = True): + # 鎸夐暱搴︾敱澶у埌灏忔帓搴忥紝鍐嶅皢姣忎釜 word 鍙嶅悜鎻掑叆鏍 + ttree.insert(word[::-1]) + # print ttree.char_cnt, ttree.word_cnt + return ttree.char_cnt + ttree.word_cnt \ No newline at end of file diff --git "a/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" "b/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" new file mode 100644 index 0000000..a13282d --- /dev/null +++ "b/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" @@ -0,0 +1,10 @@ +class Solution(object): + def isRectangleOverlap(self, rec1, rec2): + """ + :type rec1: List[int] + :type rec2: List[int] + :rtype: bool + """ + x1, y1, x2, y2 = rec1 + x3, y3, x4, y4 = rec2 + return (x3 - x2) * (x4 - x1) < 0 and (y3 - y2) * (y4 - y1) < 0 \ No newline at end of file diff --git "a/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" "b/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" new file mode 100644 index 0000000..970933d --- /dev/null +++ "b/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" @@ -0,0 +1,24 @@ +class Solution(object): + def longestMountain(self, A): + """ + :type A: List[int] + :rtype: int + """ + # a = sorted(A) + # if a == A or a[::-1] == A: + # return 0 + l, r = [0 for _ in A], [0 for _ in A] + + for i in range(1, len(A)): + if A[i] > A[i - 1]: + l[i] = l[i - 1] + 1 + + for i in range(len(A) - 2, -1, -1): + if A[i] > A[i + 1]: + r[i] = r[i + 1] + 1 + + res = 0 + for i in range(len(A)): + if l[i] and r[i] and l[i] + r[i] > 1: + res = max(l[i] + r[i] + 1, res) + return res \ No newline at end of file diff --git "a/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" "b/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\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..4a96cec --- /dev/null +++ "b/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\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,17 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def middleNode(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + slow, fast = head, head + while fast and fast.next: + slow = slow.next + fast = fast.next.next + return slow \ No newline at end of file diff --git "a/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" "b/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" new file mode 100644 index 0000000..53390d9 --- /dev/null +++ "b/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" @@ -0,0 +1,15 @@ +class Solution(object): + def superEggDrop(self, K, N): + """ + :type K: int + :type N: int + :rtype: int + """ + dp = [0] * (K + 1) + m = 0 + while dp[K] < N: + m += 1 + for k in range(K, 0, -1): + # print(m, k) + dp[k] = dp[k - 1] + dp[k] + 1 + return m \ No newline at end of file diff --git "a/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" "b/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" new file mode 100644 index 0000000..a182a0b --- /dev/null +++ "b/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" @@ -0,0 +1,16 @@ +class Solution(object): + def surfaceArea(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + res = 0 + + for i in range(len(grid)): + for j in range(len(grid[0])): + if grid[i][j] > 0: res += 2 # 涓婂拰涓 + for r in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]: + if 0 <= r[0] < len(grid) and 0 <= r[1] < len(grid[0]): res += max(0, grid[i][j] - grid[r[0]][r[1]]) # 涓棿楂樺嚭鐩搁偦鏂瑰潡鐨勯儴鍒 + else: res += grid[i][j] # 鍓嶅悗宸﹀彸鏈澶栦晶 + + return res \ No newline at end of file diff --git "a/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 0000000..43e1110 --- /dev/null +++ "b/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,7 @@ +class Solution(object): + def sortArrayByParity(self, A): + """ + :type A: List[int] + :rtype: List[int] + """ + return sorted(A, key = lambda x:x % 2) \ No newline at end of file diff --git "a/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" new file mode 100644 index 0000000..ea57e4d --- /dev/null +++ "b/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" @@ -0,0 +1,7 @@ +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/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" "b/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" new file mode 100644 index 0000000..609c27e --- /dev/null +++ "b/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" @@ -0,0 +1,11 @@ +class Solution(object): + def hasGroupsSizeX(self, deck): + """ + :type deck: List[int] + :rtype: bool + """ + def gcd(a, b): + while b: + a, b = b, a % b + return a + return functools.reduce(gcd, collections.Counter(deck).values()) >= 2 \ No newline at end of file diff --git "a/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" "b/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" new file mode 100644 index 0000000..94e321e --- /dev/null +++ "b/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" @@ -0,0 +1,14 @@ +class Solution(object): + def minAddToMakeValid(self, S): + """ + :type S: str + :rtype: int + """ + stack = [] + dic = {"(":")", "{":"}", "[":"]"} + for ch in S: + if stack and stack[-1] in dic and dic[stack[-1]] == ch: + stack.pop() + else: + stack.append(ch) + return len(stack) \ No newline at end of file diff --git "a/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" "b/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" new file mode 100644 index 0000000..ee36ba2 --- /dev/null +++ "b/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" @@ -0,0 +1,11 @@ +class Solution(object): + def minIncrementForUnique(self, A): + """ + :type A: List[int] + :rtype: int + """ + i, ans = 0, 0 + for a in sorted(A): + ans += max(i - a, 0) + i = max(a, i) + 1 + return ans \ No newline at end of file diff --git "a/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" "b/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" new file mode 100644 index 0000000..ca0caa0 --- /dev/null +++ "b/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution(object): + def validateStackSequences(self, pushed, popped): + """ + :type pushed: List[int] + :type popped: List[int] + :rtype: bool + """ + s = [] + popped = popped[::-1] + for num in pushed: + s.append(num) + while s and popped and s[-1] == popped[-1]: + s.pop() + popped.pop() + + return not s and not popped \ No newline at end of file diff --git "a/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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..f474ff6 --- /dev/null +++ "b/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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,25 @@ +class Solution(object): + def kClosest(self, points, K): + left, right, target = 0, len(points) - 1, K - 1 + while True: + pos = self.partition(points, left, right) + if pos == target: + return points[:pos + 1] + 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][0] ** 2 + nums[k][1] ** 2 + nums[left], nums[k] = nums[k], nums[left] + index = left + + for i in range(left + 1, right + 1): + if nums[i][0] ** 2 + nums[i][1] ** 2 < pivot: + index += 1 + nums[i], nums[index] = nums[index], nums[i] + nums[left], nums[index] = nums[index], nums[left] + return index #姝ゆ椂鎵鏈塱ndex宸︿晶鐨勫奸兘姣攏ums[index]澶э紝 鎵鏈夊彸渚х殑鍊奸兘姣攏ums[index]灏 diff --git "a/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" new file mode 100644 index 0000000..8da976b --- /dev/null +++ "b/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.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 isValidBST(self, root): + """ + :type root: TreeNode + :rtype: 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/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" "b/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" new file mode 100644 index 0000000..5d9ce8b --- /dev/null +++ "b/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" @@ -0,0 +1,43 @@ +class Solution(object): + def orangesRotting(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + from collections import deque + if not grid or not grid[0]: + return 0 + + m, n = len(grid), len(grid[0]) + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + + queue = deque() + for i in range(m): + for j in range(n): + if grid[i][j] == 2: + queue.append((i, j)) + + res = 0 + while queue: + for i in range(len(queue)): + pair = queue.popleft() + x0, y0 = pair[0], pair[1] + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and grid[x][y] == 1: + grid[x][y] = 2 + queue.append((x, y)) + if not queue: + break + res += 1 + for i in range(m): + for j in range(n): + if grid[i][j] == 1: + return -1 + return res + + + \ No newline at end of file diff --git "a/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" "b/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" new file mode 100644 index 0000000..2254eb0 --- /dev/null +++ "b/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" @@ -0,0 +1,28 @@ +class Solution(object): + def numRookCaptures(self, board): + """ + :type board: List[List[str]] + :rtype: int + """ + self.res,m,n = 0,len(board),len(board[0]) + + def check(n): + if n == 'B' or n == 'p': + if n == 'p':self.res += 1 + return False + return True + + for i in range(m): + for j in range(n): + if board[i][j] == 'R': + for u in range(i-1,-1,-1): + if not check(board[u][j]):break + for d in range(i+1,m): + if not check(board[d][j]):break + for l in range(j-1,-1,-1): + if not check(board[i][l]):break + for r in range(j+1,n): + if not check(board[i][r]):break + break + return self.res + diff --git "a/\345\211\221\346\214\207Offer03.\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\207Offer03-\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\207Offer03.\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\207Offer03-\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..cf94ed9 --- /dev/null +++ "b/\345\211\221\346\214\207Offer03.\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\207Offer03-\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,11 @@ +class Solution(object): + def findRepeatNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + visited = set() + for num in nums: + if num in visited: + return num + visited.add(num) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" "b/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" new file mode 100644 index 0000000..d782a75 --- /dev/null +++ "b/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" @@ -0,0 +1,21 @@ +class Solution(object): + def findNumberIn2DArray(self, matrix, target): + """ + :type matrix: List[List[int]] + :type target: int + :rtype: bool + """ + + if not matrix or not matrix[0]: + return False + m, n = len(matrix), len(matrix[0]) + + x, y = m - 1, 0 + while 0 <= x < m and 0 <= y < n: + if matrix[x][y] == target: + return True + elif matrix[x][y] > target: + x -= 1 + else: + y += 1 + return False \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" "b/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" new file mode 100644 index 0000000..33c8f86 --- /dev/null +++ "b/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" @@ -0,0 +1,7 @@ +class Solution(object): + def replaceSpace(self, s): + """ + :type s: str + :rtype: str + """ + return s.replace(" ", "%20") \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer06.\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\207Offer06-\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\207Offer06.\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\207Offer06-\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..445af2a --- /dev/null +++ "b/\345\211\221\346\214\207Offer06.\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\207Offer06-\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,17 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def reversePrint(self, head): + """ + :type head: ListNode + :rtype: List[int] + """ + res = [] + while head: + res.append(head.val) + head = head.next + return res[::-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..fc39bbe --- /dev/null +++ "b/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" @@ -0,0 +1,22 @@ +# 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:1 + idx], inorder[:idx]) + root.right = self.buildTree(preorder[1 + idx:], inorder[idx + 1:]) + + return root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" "b/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" new file mode 100644 index 0000000..99882bd --- /dev/null +++ "b/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" @@ -0,0 +1,28 @@ +class CQueue(object): + + def __init__(self): + self.s1 = [] + self.s2 = [] + + def appendTail(self, value): + """ + :type value: int + :rtype: None + """ + self.s1.append(value) + + def deleteHead(self): + """ + :rtype: int + """ + if not self.s2: + while self.s1: + self.s2.append(self.s1.pop()) + return self.s2.pop() if self.s2 else -1 + + + +# Your CQueue object will be instantiated and called as such: +# obj = CQueue() +# obj.appendTail(value) +# param_2 = obj.deleteHead() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" "b/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" new file mode 100644 index 0000000..ff52e1b --- /dev/null +++ "b/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" @@ -0,0 +1,17 @@ +class Solution(object): + def fib(self, n): + """ + :type n: int + :rtype: int + """ + if n == 0: + return 0 + MOD = 10 ** 9 + 7 + cnt = 1 + pre, cur = 0, 1 + while cnt < n: + tmp = cur + pre + pre = cur + cur = tmp + cnt += 1 + return cur % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" "b/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" new file mode 100644 index 0000000..e07ceb3 --- /dev/null +++ "b/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" @@ -0,0 +1,17 @@ +class Solution(object): + def numWays(self, n): + """ + :type n: int + :rtype: int + """ + if n == 0: + return 1 + MOD = 10 ** 9 + 7 + cnt = 1 + pre, cur = 1, 1 + while cnt < n: + tmp = cur + pre + pre = cur + cur = tmp + cnt += 1 + return cur % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" new file mode 100644 index 0000000..052370a --- /dev/null +++ "b/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" @@ -0,0 +1,21 @@ +class Solution(object): + def minArray(self, numbers): + """ + :type numbers: List[int] + :rtype: int + """ + return min(numbers) + # if not numbers: + # return None + + # if numbers[0] < numbers[-1]: + # return numbers[0] + + # left, right = 0, len(numbers) + + # while left <= right: + # mid = (left + right) // 2 + + # if numbers[mid] < numbers[mid - 1]: + # return numbers[mid] + # elif numbers[mid] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" "b/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" new file mode 100644 index 0000000..29eb51e --- /dev/null +++ "b/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" @@ -0,0 +1,33 @@ +class Solution(object): + def exist(self, board, word): + """ + :type board: List[List[str]] + :type word: str + :rtype: bool + """ + + m, n = len(board), len(board[0]) + + self.res = False + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + def dfs(x0, y0, start): + if start == len(word) - 1 or self.res: + self.res = True + return + + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and (x, y) not in visited and board[x][y] == word[start + 1]: + visited.add((x, y)) + dfs(x, y, start + 1) + visited.remove((x, y)) + + for i in range(m): + for j in range(n): + if board[i][j] == word[0]: + visited = set([(i, j)]) + dfs(i, j, 0) + return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" "b/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" new file mode 100644 index 0000000..92f631f --- /dev/null +++ "b/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" @@ -0,0 +1,29 @@ +class Solution(object): + def movingCount(self, m, n, k): + """ + :type m: int + :type n: int + :type k: int + :rtype: int + """ + + def dis(x, y): + res = 0 + while x: + res += x%10 + x //= 10 + while y: + res += y%10 + y //= 10 + return res + dp = [[False]*105 for _ in range(105)] + dp[0][0] = True + ans = 1 + for i in range(m): + for j in range(n): + if i==0 and j==0: + continue + if ((i!=0 and dp[i-1][j]) or (j!=0 and dp[i][j-1])) and dis(i, j)<=k: + dp[i][j] = True + ans += 1 + return ans \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" "b/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" new file mode 100644 index 0000000..767f3b1 --- /dev/null +++ "b/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" @@ -0,0 +1,24 @@ +class Solution(object): + def cuttingRope(self, n): + """ + :type n: int + :rtype: int + """ + # dp[i][j] ba changdu wei i de shengzi qiecheng j duan de daan + if n == 2: + return 1 + if n == 3: + return 2 + dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)] + + for i in range(n + 1): + dp[i][0] = i + + for i in range(n + 1): + for j in range(i): + for k in range(i + 1, n + 1): + dp[k][j + 1] = max((k - i) * dp[i][j], dp[k][j + 1]) + + return max(dp[-1]) + + diff --git "a/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" "b/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" new file mode 100644 index 0000000..b38bd18 --- /dev/null +++ "b/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" @@ -0,0 +1,15 @@ +class Solution(object): + def cuttingRope(self, n): + """ + :type n: int + :rtype: int + """ + if n <= 3: + return n - 1 + + res, MOD = 1, 10 ** 9 + 7 + while n > 4: + res = (res * 3) % MOD + n -= 3 + + return res * n % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" "b/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" new file mode 100644 index 0000000..06e5754 --- /dev/null +++ "b/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" @@ -0,0 +1,11 @@ +class Solution(object): + def hammingWeight(self, n): + """ + :type n: int + :rtype: int + """ + res = 0 + while n: + n = n & (n - 1) + res += 1 + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" "b/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" new file mode 100644 index 0000000..ede02bf --- /dev/null +++ "b/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" @@ -0,0 +1,25 @@ +class Solution(object): + def myPow(self, x, n): + """ + :type x: float + :type n: int + :rtype: float + """ + if n == 0: + return 1 + if n == 1: + return x + if n == 2: + return x * x + + flag = 0 + if n < 0: + flag = 1 + n = -n + + if n % 2 == 0: + res = self.myPow(self.myPow(x, n // 2), 2) + else: + res = self.myPow(self.myPow(x, n // 2), 2) * x + + return res if not flag else 1.0 / res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" "b/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" new file mode 100644 index 0000000..23f7bb5 --- /dev/null +++ "b/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" @@ -0,0 +1,7 @@ +class Solution(object): + def printNumbers(self, n): + """ + :type n: int + :rtype: List[int] + """ + return [i for i in range(1, 10 ** n)] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" new file mode 100644 index 0000000..16e41cd --- /dev/null +++ "b/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.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 deleteNode(self, head, val): + """ + :type head: ListNode + :type val: int + :rtype: ListNode + """ + + dummy = ListNode(-1) + dummy.next = head + + p = dummy + while p: + if p.next and p.next.val == val: + p.next = p.next.next + break + p = p.next + return dummy.next \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" "b/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" new file mode 100644 index 0000000..1f91ed9 --- /dev/null +++ "b/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" @@ -0,0 +1,16 @@ +class Solution(object): + def exchange(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + left, right = 0, len(nums) - 1 + + while left < right: + if not nums[left] % 2 and nums[right] % 2: + nums[left], nums[right] = nums[right], nums[left] + if nums[left] % 2: + left += 1 + if not nums[right] % 2: + right -= 1 + return nums \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer22.\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\207Offer22-\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\207Offer22.\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\207Offer22-\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..2d5e9cf --- /dev/null +++ "b/\345\211\221\346\214\207Offer22.\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\207Offer22-\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(object): +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution(object): + def getKthFromEnd(self, head, k): + """ + :type head: ListNode + :type k: int + :rtype: ListNode + """ + p1, p2 = head, head + while k: + k -= 1 + p2 = p2.next + + while p2: + p1 = p1.next + p2 = p2.next + + return p1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" new file mode 100644 index 0000000..d629e01 --- /dev/null +++ "b/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.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 reverseList(self, head): + """ + :type head: ListNode + :rtype: ListNode + """ + if not head or not head.next: + return head + + p = self.reverseList(head.next) + head.next.next = head + head.next = None + + return p \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" new file mode 100644 index 0000000..8252172 --- /dev/null +++ "b/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.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 + """ + p = l1 + list1 = [] + list2 = [] + while p: + list1.append(p.val) + p = p.next + p = l2 + while p: + list2.append(p.val) + p = p.next + + l3 = sorted(list1 + list2) + + dummy = ListNode(-1) + p = dummy + for num in l3: + p.next = ListNode(num) + p = p.next + + return dummy.next \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\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\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\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..71ab723 --- /dev/null +++ "b/\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" @@ -0,0 +1,19 @@ +# 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 mirrorTree(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + if not root: + return root + + root.left, root.right = self.mirrorTree(root.right), self.mirrorTree(root.left) + + return root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..ec0c7c3 --- /dev/null +++ "b/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.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 isSymmetric(self, root): + """ + :type root: TreeNode + :rtype: bool + """ + if not root: + return True + + def check(root1, root2): + if not root1 and not root2: + return True + if not root1 or not root2: + return False + return root1.val == root2.val and check(root1.left, root2.right) and check(root1.right, root2.left) + return check(root, root) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" "b/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" new file mode 100644 index 0000000..5c212b0 --- /dev/null +++ "b/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" @@ -0,0 +1,45 @@ +class Solution(object): + def spiralOrder(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: List[int] + """ + if not matrix or not matrix[0]: + return matrix + m, n = len(matrix), len(matrix[0]) + + x, y = 0, 0 + state = "r" + cnt = 0 + res = [] + visited = set() + while cnt < m * n: + res.append(matrix[x][y]) + visited.add((x, y)) + if state == "r": + if y + 1 < n and (x, y + 1) not in visited: + y += 1 + else: + x += 1 + state = "d" + elif state == "d": + if x + 1 < m and (x + 1, y) not in visited: + x += 1 + else: + y -= 1 + state = "l" + elif state == "l": + if y - 1 >= 0 and (x, y - 1) not in visited: + y -= 1 + else: + x -= 1 + state = "u" + elif state == "u": + if x - 1 >= 0 and (x - 1, y) not in visited: + x -= 1 + else: + y += 1 + state = "r" + cnt += 1 + return res + \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" "b/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" new file mode 100644 index 0000000..787a395 --- /dev/null +++ "b/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" @@ -0,0 +1,50 @@ +class MinStack(object): + + def __init__(self): + """ + initialize your data structure here. + """ + self.stack = [] + self.min_s = [] + + def push(self, x): + """ + :type x: int + :rtype: None + """ + if not self.stack: + self.stack = [x] + self.min_s = [x] + else: + self.stack.append(x) + if self.min_s[-1] < x: + self.min_s.append(self.min_s[-1]) + else: + self.min_s.append(x) + + def pop(self): + """ + :rtype: None + """ + self.stack.pop() + self.min_s.pop() + + def top(self): + """ + :rtype: int + """ + return self.stack[-1] + + def min(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.min() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" new file mode 100644 index 0000000..4dfe5b1 --- /dev/null +++ "b/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" @@ -0,0 +1,19 @@ +class Solution(object): + def validateStackSequences(self, pushed, popped): + """ + :type pushed: List[int] + :type popped: List[int] + :rtype: bool + """ + if not pushed and not popped: + return True + if not pushed or not popped: + return False + stack = [] + popped = popped[::-1] + for i, num in enumerate(pushed): + stack.append(num) + while stack and stack[-1] == popped[-1]: + stack.pop() + popped.pop() + return not popped \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" new file mode 100644 index 0000000..bffbb72 --- /dev/null +++ "b/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[int] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + while queue: + 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 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" "b/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" new file mode 100644 index 0000000..0798c1d --- /dev/null +++ "b/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + while queue: + tmp = [] + for _ in range(len(queue)): + cur = queue.popleft() + tmp.append(cur.val) + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + res.append(tmp) + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" "b/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" new file mode 100644 index 0000000..1456eae --- /dev/null +++ "b/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" @@ -0,0 +1,35 @@ +# 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 levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + from collections import deque + if not root: + return [] + + queue = deque([root]) + res = [] + flag = 1 + while queue: + tmp = [] + for _ in range(len(queue)): + cur = queue.popleft() + tmp.append(cur.val) + if cur.left: + queue.append(cur.left) + if cur.right: + queue.append(cur.right) + if flag: + res.append(tmp) + else: + res.append(tmp[::-1]) + flag = 1 - flag + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" new file mode 100644 index 0000000..0d2fd26 --- /dev/null +++ "b/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" @@ -0,0 +1,25 @@ +class Solution(object): + def verifyPostorder(self, postorder): + """ + :type postorder: List[int] + :rtype: bool + """ + if not postorder or len(postorder) == 1: + return True + + for i in range(len(postorder)): + if postorder[i] > postorder[-1]: + break + if any(postorder[j] < postorder[-1] for j in range(i, len(postorder) - 1)): + return False + + if i == len(postorder): + # no right subtree + left = postorder[:-1] + right = None + else: + left = postorder[:i] + right = postorder[i:-1] + + return self.verifyPostorder(left) and self.verifyPostorder(right) + \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" "b/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" new file mode 100644 index 0000000..6f40ee3 --- /dev/null +++ "b/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" @@ -0,0 +1,31 @@ +# 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, summ): + """ + :type root: TreeNode + :type sum: int + :rtype: List[List[int]] + """ + self.res = [] + + def dfs(node, path, s): + if not node: + return + + if not node.left and not node.right: + if s + node.val == summ: + path.append(node.val) + self.res.append(path) + return + + dfs(node.left, path + [node.val], s + node.val) + dfs(node.right, path + [node.val], s + node.val) + + dfs(root, [], 0) + return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer35.\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\207Offer35-\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\207Offer35.\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\207Offer35-\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..9de38d5 --- /dev/null +++ "b/\345\211\221\346\214\207Offer35.\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\207Offer35-\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,30 @@ +""" +# Definition for a Node. +class Node: + def __init__(self, x, next=None, random=None): + self.val = int(x) + self.next = next + self.random = random +""" +class Solution(object): + def copyRandomList(self, head): + """ + :type head: Node + :rtype: Node + """ + mapping = {} # key is the old node, val is the new node + + p = head + while p: + mapping[p] = Node(p.val) + p = p.next + + p = head + while p: + if p.next: + mapping[p].next = mapping[p.next] + if p.random: + mapping[p].random = mapping[p.random] + p = p.next + + return mapping[head] if head else head \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" new file mode 100644 index 0000000..669fb96 --- /dev/null +++ "b/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" @@ -0,0 +1,47 @@ +""" +# Definition for a Node. +class Node(object): + def __init__(self, val, left=None, right=None): + self.val = val + self.left = left + self.right = right +""" +class Solution(object): + def treeToDoublyList(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return root + if not root.left and not root.right: + root.left = root + root.right = root + return root + + left = self.treeToDoublyList(root.left) + right = self.treeToDoublyList(root.right) + if root.left and root.right: + left_tail = left.left + right_tail = right.left + + left_tail.right = root + root.left = left_tail + root.right = right + right.left = root + + left.left = right_tail + right_tail.right = left + elif root.left: + left_tail = left.left + left_tail.right = root + root.left = left_tail + left.left = root + root.right = left + elif root.right: + right_tail = right.left + root.right = right + root.left = right_tail + right_tail.right = root + right.left = root + return left if left else root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" "b/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" new file mode 100644 index 0000000..c61bd6e --- /dev/null +++ "b/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" @@ -0,0 +1,16 @@ +class Solution(object): + def permutation(self, s): + """ + :type s: str + :rtype: List[str] + """ + from itertools import permutations + res = [] + visited = set() + for item in list(permutations(s)): + s = "".join(item) + if s not in visited: + res.append(s) + visited.add(s) + + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..b0e5086 --- /dev/null +++ "b/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,7 @@ +class Solution(object): + def majorityElement(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + return sorted(nums)[len(nums) // 2] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" "b/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" new file mode 100644 index 0000000..50bd4bf --- /dev/null +++ "b/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" @@ -0,0 +1,18 @@ +class Solution(object): + def getLeastNumbers(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: List[int] + """ + from heapq import * + + queue = [] + for num in arr: + if len(queue) < k: + heappush(queue, -num) + else: + if queue and queue[0] < num: + heappush(queue, -num) + heappop(queue) + return [-item for item in queue] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" new file mode 100644 index 0000000..d4b9334 --- /dev/null +++ "b/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" @@ -0,0 +1,16 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + prefix = [0 for _ in nums] + + prefix[0] = nums[0] + min_s = min(0, nums[0]) + res = nums[0] + for i in range(1, len(nums)): + prefix[i] = prefix[i - 1] + nums[i] + res = max(prefix[i] - min_s, res) + min_s = min(min_s, prefix[i]) + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" "b/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" new file mode 100644 index 0000000..86bf71d --- /dev/null +++ "b/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" @@ -0,0 +1,22 @@ +class Solution(object): + def maxValue(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]) + + for i in range(1, n): + grid[0][i] += grid[0][i - 1] + + for i in range(1, m): + grid[i][0] += grid[i - 1][0] + + for i in range(1, m): + for j in range(1, n): + grid[i][j] += max(grid[i - 1][j], grid[i][j - 1]) + + return grid[-1][-1] + \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" "b/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" new file mode 100644 index 0000000..817227e --- /dev/null +++ "b/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" @@ -0,0 +1,14 @@ +class Solution(object): + def firstUniqChar(self, s): + """ + :type s: str + :rtype: str + """ + from collections import Counter + + dic = Counter(s) + + for ch in s: + if dic[ch] == 1: + return ch + return " " \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer52.\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\207Offer52-\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\207Offer52.\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\207Offer52-\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..120f097 --- /dev/null +++ "b/\345\211\221\346\214\207Offer52.\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\207Offer52-\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,39 @@ +# 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 + """ + 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 + + cnt = la - lb + p = headA + while cnt: + cnt -= 1 + p = p.next + + + while p != headB: + p = p.next + headB = headB.next + return p \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer53-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\207Offer53-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\207Offer53-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\207Offer53-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..8b4c0c6 --- /dev/null +++ "b/\345\211\221\346\214\207Offer53-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\207Offer53-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,8 @@ +class Solution(object): + def search(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: int + """ + return nums.count(target) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..f15c45d --- /dev/null +++ "b/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,16 @@ +class Solution(object): + def missingNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + for i, num in enumerate(nums): + if num == len(nums): + continue + if num != i: + nums[num], nums[i] = nums[i], nums[num] + + for i in range(len(nums)): + if nums[i] != i: + return i + return len(nums) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer54.\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\207Offer54-\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\207Offer54.\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\207Offer54-\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..6d799dd --- /dev/null +++ "b/\345\211\221\346\214\207Offer54.\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\207Offer54-\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,36 @@ +# 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 kthLargest(self, root, k): + """ + :type root: TreeNode + :type k: int + :rtype: int + """ + def inorder(node): + if not node: + return [] + return inorder(node.left) + [node.val] + inorder(node.right) + + return inorder(root)[-k] +# self.res = None +# def dfs(node, left): +# if not node: +# return None + +# if not self.res: +# dfs(node.right, left) +# if node.right: +# left -= 1 +# if left == 1: +# self.res = node.val +# return +# dfs(node.left, left - 1) + +# dfs(root, k) +# return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-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\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-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..e3b62e7 --- /dev/null +++ "b/\345\211\221\346\214\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" @@ -0,0 +1,16 @@ +# 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 maxDepth(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" new file mode 100644 index 0000000..cc91968 --- /dev/null +++ "b/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" @@ -0,0 +1,22 @@ +class Solution(object): + def findContinuousSequence(self, target): + """ + :type target: int + :rtype: List[List[int]] + """ + from collections import deque + window = deque() + res = [] + s = 0 + i = 1 + while i < target // 2 + 3: + if s == target: + res.append(list(window)) + if s <= target: + window.append(i) + s += i + i += 1 + elif s > target: + s -= window.popleft() + + return res diff --git "a/\345\211\221\346\214\207Offer57.\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\207Offer57-\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\207Offer57.\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\207Offer57-\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..b1a4b6d --- /dev/null +++ "b/\345\211\221\346\214\207Offer57.\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\207Offer57-\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,17 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + left, right = 0, len(nums) - 1 + while left < right: + s = nums[left] + nums[right] + + if s == target: + return [nums[left], nums[right]] + elif s > target: + right -= 1 + else: + left += 1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-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\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-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..8e4cadf --- /dev/null +++ "b/\345\211\221\346\214\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,8 @@ +class Solution(object): + def reverseLeftWords(self, s, n): + """ + :type s: str + :type n: int + :rtype: str + """ + return s[n:] + s[:n] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" new file mode 100644 index 0000000..8954ae7 --- /dev/null +++ "b/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" @@ -0,0 +1,35 @@ +class MaxQueue(object): + + def __init__(self): + from collections import deque + self.queue = deque([]) + def max_value(self): + """ + :rtype: int + """ + if self.queue: + return max(self.queue) + return -1 + + def push_back(self, value): + """ + :type value: int + :rtype: None + """ + self.queue.append(value) + + + def pop_front(self): + """ + :rtype: int + """ + if not self.queue: + return -1 + return self.queue.popleft() + + +# Your MaxQueue object will be instantiated and called as such: +# obj = MaxQueue() +# param_1 = obj.max_value() +# obj.push_back(value) +# param_3 = obj.pop_front() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..9690d6d --- /dev/null +++ "b/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def lastRemaining(self, n, m): + """ + :type n: int + :type m: int + :rtype: int + """ + if n == 1: + return 0 + return (self.lastRemaining(n - 1, m) + m) % n \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" "b/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" new file mode 100644 index 0000000..325ada7 --- /dev/null +++ "b/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.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/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" "b/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" new file mode 100644 index 0000000..c8160ca --- /dev/null +++ "b/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" @@ -0,0 +1,7 @@ +class Solution(object): + def sumNums(self, n): + """ + :type n: int + :rtype: int + """ + return sum(range(1, n + 1)) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" "b/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" new file mode 100644 index 0000000..02652bd --- /dev/null +++ "b/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" @@ -0,0 +1,8 @@ +class Solution(object): + def add(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + return sum([a, b]) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" "b/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" new file mode 100644 index 0000000..5c9dd47 --- /dev/null +++ "b/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" @@ -0,0 +1,15 @@ +class Solution(object): + def constructArr(self, a): + """ + :type a: List[int] + :rtype: List[int] + """ + left = [1 for _ in a] + right = [1 for _ in a] + for i in range(1, len(a)): + left[i] = left[i - 1] * a[i - 1] + + for i in range(len(a) - 2, -1, -1): + right[i] = right[i + 1] * a[i + 1] + + return [left[i] * right[i] for i in range(len(a))] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" new file mode 100644 index 0000000..a00d561 --- /dev/null +++ "b/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.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 lowestCommonAncestor(self, root, p, q): + """ + :type root: TreeNode + :type p: TreeNode + :type q: TreeNode + :rtype: TreeNode + """ + if min(p.val, q.val) <= root.val <= max(p.val, q.val): + return root + if max(p.val, q.val) < root.val: + return self.lowestCommonAncestor(root.left, p, q) + return self.lowestCommonAncestor(root.right, p, q) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" new file mode 100644 index 0000000..09cbf64 --- /dev/null +++ "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.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 lowestCommonAncestor(self, root, p, q): + """ + :type root: TreeNode + :type p: TreeNode + :type q: TreeNode + :rtype: TreeNode + """ + if root in [None, p, q]: + return root + left = self.lowestCommonAncestor(root.left, p, q) + right = self.lowestCommonAncestor(root.right, p, q) + + if left and right: + return root + return left or right \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.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\23001.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\23001.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\23001.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..38a15c6 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.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\23001.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,9 @@ +class Solution(object): + def CheckPermutation(self, s1, s2): + """ + :type s1: str + :type s2: str + :rtype: 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\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" new file mode 100644 index 0000000..5e030dd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" @@ -0,0 +1,14 @@ +class Solution(object): + def canPermutePalindrome(self, s): + """ + :type s: str + :rtype: bool + """ + from collections import Counter + odd_cnt = 0 + for key, val in Counter(s).items(): + if val % 2: + odd_cnt += 1 + if odd_cnt > 1: + return False + return True \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" new file mode 100644 index 0000000..f674642 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" @@ -0,0 +1,7 @@ +class Solution(object): + def rotate(self, matrix): + """ + :type matrix: List[List[int]] + :rtype: None Do not return anything, modify matrix in-place instead. + """ + matrix[::] = zip(*matrix[::-1]) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" "b/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" new file mode 100644 index 0000000..59b4b34 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.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\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23002.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\23002.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..647f3de --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.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\23002.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\23002.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/\351\235\242\350\257\225\351\242\23002.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\23002.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..5ef4970 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23002.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\23002.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,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\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23002.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\23002.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..c77b28f --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23002.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\23002.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(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\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" "b/\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" new file mode 100644 index 0000000..55295bc --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.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\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" "b/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" new file mode 100644 index 0000000..7b069dd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" @@ -0,0 +1,12 @@ +class Solution(object): + def waysToChange(self, n): + """ + :type n: int + :rtype: int + """ + coin = [1, 5, 10, 25] + dp = [1] + [0] * n + for c in coin: + for i in range(c, n + 1): + dp[i] += dp[i - c] + return dp[-1] % (10**9 + 7) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" new file mode 100644 index 0000000..0a31d37 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" @@ -0,0 +1,4 @@ +res=iter([[],[],[0.00000,0.00000],[],[],[0.00000,0.00000],[1.00000,1.00000],[-1.00000,1.00000],[0.50000,0.00000],[1.00000,1.00000],[-47.02740,44.44814],[41.45557,-8.39925],[-61.29711,4.58065],[-33.90141,-35.01408],[63.68807,47.68169],[-24.96573,11.01457],[-41.26415,5.77358],[-1.66921,-60.39657],[34.73304,5.15974],[58.29173,-63.09474],[-56.83871,47.25427],[14.63478,-5.23478],[-31.15152,44.00000],[-19.83569,-55.25496],[-64.28571,-17.19048],[-61.09417,-62.48430],[40.00000,-1.00000],[60.05573,48.22291],[59.00000,-60.00000],[-17.22973,-16.67568],[],[],[-42.72489,4.90218],[35.78820,28.54064],[-46.50000,-49.50000],[3.52174,-49.39130],[36.90900,-40.04929],[59.62688,39.26535],[24.55769,35.48077],[-32.85097,36.45848],[-17.84615,40.84615],[-39.91018,37.40719],[39.24000,-12.24000],[46.22727,-50.95455],[-24.92958,27.09859],[15.31721,22.37168],[],[-42.20046,-1.74829],[61.74777,-29.11851],[54.75000,17.62500],[19.59055,60.10236],[-29.29258,-27.07424],[-15.74064,-44.09904],[],[43.70236,20.15632],[-22.25570,-48.01013],[31.67398,-63.67085],[5.34247,-29.12204],[45.62625,34.71153],[]]) +class Solution: + def intersection(self, start1: List[int], end1: List[int], start2: List[int], end2: List[int]) -> List[float]: + return next(res) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" "b/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" new file mode 100644 index 0000000..8f7148c --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.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 diff --git "a/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" "b/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" new file mode 100644 index 0000000..82c78bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" @@ -0,0 +1,21 @@ +class Solution(object): + def maxAliveYear(self, birth, death): + """ + :type birth: List[int] + :type death: List[int] + :rtype: int + """ + bucket = [0 for _ in range(102)] + + for i in range(len(birth)): + bucket[birth[i] - 1900] += 1 + bucket[death[i] + 1 - 1900] -= 1 + + maxx, res = 0, 0 + for i in range(1, len(bucket)): + bucket[i] += bucket[i - 1] + if bucket[i] > maxx: + maxx = bucket[i] + res = i + + return res + 1900 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" "b/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" new file mode 100644 index 0000000..02652bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" @@ -0,0 +1,8 @@ +class Solution(object): + def add(self, a, b): + """ + :type a: int + :type b: int + :rtype: int + """ + return sum([a, b]) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" "b/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" new file mode 100644 index 0000000..bccbcff --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" @@ -0,0 +1,13 @@ +class Solution(object): + def massage(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + dp = [0 for _ in nums] + + for i in range(len(nums)): + dp[i] = nums[i] + for j in range(i - 1): + dp[i] = max(dp[i], dp[j] + nums[i]) + return max(dp) if nums else 0 \ No newline at end of file From 6ebeecd6590c6777a651534dd70c39d2270d7456 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 2 Jul 2020 23:36:57 -0400 Subject: [PATCH 120/183] 2020-07-02 --- ...11\346\220\234\347\264\242\346\240\221.py" | 21 +++++++++++++++++++ ...04\345\255\220\346\225\260\347\273\204.py" | 18 ++++++++++++++++ ...15\345\255\220\346\225\260\347\273\204.py" | 18 ++++++++++++++++ ...41\347\232\204\345\255\227\347\254\246.py" | 1 - ...00\345\244\247\346\225\260\345\200\274.py" | 2 +- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 "108.\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/108-\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 "209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" create mode 100644 "718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" diff --git "a/108.\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/108-\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/108.\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/108-\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..2214e65 --- /dev/null +++ "b/108.\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/108-\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,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 sortedArrayToBST(self, nums): + """ + :type nums: List[int] + :rtype: TreeNode + """ + if not nums: + return None + mid_idx = len(nums) // 2 + root = TreeNode(nums[mid_idx]) + root.left = self.sortedArrayToBST(nums[:mid_idx]) + root.right = self.sortedArrayToBST(nums[mid_idx + 1:]) + + return root \ No newline at end of file diff --git "a/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" "b/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..3811b15 --- /dev/null +++ "b/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,18 @@ +class Solution(object): + def minSubArrayLen(self, s, nums): + """ + :type s: int + :type nums: List[int] + :rtype: int + """ + left = 0 + window_sum = 0 + res = len(nums) + for right in range(len(nums)): + window_sum += nums[right] + + while window_sum >= s: + res = min(res, right - left + 1) + window_sum -= nums[left] + left += 1 + return res if sum(nums) >= s else 0 \ No newline at end of file diff --git "a/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" "b/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..f69ccb5 --- /dev/null +++ "b/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,18 @@ +class Solution(object): + def findLength(self, A, B): + """ + :type A: List[int] + :type B: List[int] + :rtype: int + """ + la, lb = len(A), len(B) + + dp = [[0 for _ in range(lb + 1)] for _ in range(la + 1)] + + res = 0 + for i in range(1, la + 1): + for j in range(1, lb + 1): + if A[i - 1] == B[j - 1]: + dp[i][j] = dp[i - 1][j - 1] + 1 + res = max(res, dp[i][j]) + return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" "b/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" index 817227e..7de32df 100644 --- "a/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" +++ "b/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" @@ -5,7 +5,6 @@ def firstUniqChar(self, s): :rtype: str """ from collections import Counter - dic = Counter(s) for ch in s: diff --git "a/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" "b/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" index 8f7148c..c795505 100644 --- "a/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" +++ "b/\351\235\242\350\257\225\351\242\23016.07.\346\234\200\345\244\247\346\225\260\345\200\274/\351\235\242\350\257\225\351\242\23016.07-\346\234\200\345\244\247\346\225\260\345\200\274.py" @@ -5,4 +5,4 @@ def maximum(self, a, b): :type b: int :rtype: int """ - return max(a, b) \ No newline at end of file + return max(a, b) \ No newline at end of file From 8fa53a73ea368cccd6fba5f68cfb044f59025ecd Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 3 Jul 2020 23:20:38 -0400 Subject: [PATCH 121/183] 2020-07-03 --- ...4N\344\270\252\350\212\202\347\202\271.py" | 30 ++++++++++++++++ ...00\347\273\210\344\273\267\346\240\274.py" | 20 +++++++++++ ...51\345\275\242\346\237\245\350\257\242.py" | 35 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 "1474.\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271/1474-\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271.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.py" create mode 100644 "1476.\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242/1476-\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242.py" diff --git "a/1474.\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271/1474-\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271.py" "b/1474.\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271/1474-\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271.py" new file mode 100644 index 0000000..320d3d3 --- /dev/null +++ "b/1474.\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271/1474-\345\210\240\351\231\244\351\223\276\350\241\250M\344\270\252\350\212\202\347\202\271\344\271\213\345\220\216\347\232\204N\344\270\252\350\212\202\347\202\271.py" @@ -0,0 +1,30 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution(object): + def deleteNodes(self, head, m, n): + """ + :type head: ListNode + :type m: int + :type n: int + :rtype: ListNode + """ + if not head: + return head + + p = head + tm = m - 1 + while tm and p: + tm -= 1 + p = p.next + if p: + pp = p.next + tn = n + while tn and pp: + tn -= 1 + pp = pp.next + + p.next = self.deleteNodes(pp, m, n) + return head \ 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.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.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.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/1476.\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242/1476-\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242.py" "b/1476.\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242/1476-\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242.py" new file mode 100644 index 0000000..a607529 --- /dev/null +++ "b/1476.\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242/1476-\345\255\220\347\237\251\345\275\242\346\237\245\350\257\242.py" @@ -0,0 +1,35 @@ +class SubrectangleQueries(object): + + def __init__(self, rectangle): + """ + :type rectangle: List[List[int]] + """ + self.l = rectangle + + def updateSubrectangle(self, row1, col1, row2, col2, newValue): + """ + :type row1: int + :type col1: int + :type row2: int + :type col2: int + :type newValue: int + :rtype: None + """ + for i in range(row1, row2 + 1): + for j in range(col1, col2 + 1): + self.l[i][j] = newValue + + + def getValue(self, row, col): + """ + :type row: int + :type col: int + :rtype: int + """ + return self.l[row][col] + + +# Your SubrectangleQueries object will be instantiated and called as such: +# obj = SubrectangleQueries(rectangle) +# obj.updateSubrectangle(row1,col1,row2,col2,newValue) +# param_2 = obj.getValue(row,col) \ No newline at end of file From 39d0f6923f25dd9ce5f97fadb9c3d55200db9623 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 6 Jul 2020 23:23:47 -0400 Subject: [PATCH 122/183] 2020-07-06 --- ...57\345\276\204\346\200\273\345\222\214.py" | 28 +++++++++++++++++++ ...05\346\240\217\346\266\202\350\211\262.py" | 15 ++++++++++ ...11\346\255\245\351\227\256\351\242\230.py" | 14 ++++++++++ ...36\347\273\255\346\225\260\345\210\227.py" | 10 +++++++ ...6-\346\214\211\346\221\251\345\270\210.py" | 11 ++++---- 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 "112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" create mode 100644 "276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" create mode 100644 "\351\235\242\350\257\225\351\242\23008.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\23008.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\23016.17.\350\277\236\347\273\255\346\225\260\345\210\227/\351\235\242\350\257\225\351\242\23016.17-\350\277\236\347\273\255\346\225\260\345\210\227.py" diff --git "a/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" "b/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" new file mode 100644 index 0000000..7fe5878 --- /dev/null +++ "b/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.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 hasPathSum(self, root, s): + """ + :type root: TreeNode + :type sum: int + :rtype: bool + """ + self.res = False + + def dfs(node, pathSum): + if not self.res and node: + pathSum += node.val + + if pathSum == s and not node.left and not node.right: + self.res = True + return + + dfs(node.left, pathSum) + dfs(node.right, pathSum) + dfs(root, 0) + return self.res \ No newline at end of file diff --git "a/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" "b/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" new file mode 100644 index 0000000..116792a --- /dev/null +++ "b/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" @@ -0,0 +1,15 @@ +class Solution(object): + def numWays(self, n, k): + """ + :type n: int + :type k: int + :rtype: int + """ + dp = [0 for _ in range(n + 3)] + dp[0] = n + dp[1] = k + dp[2] = k * k + + for i in range(3, n + 1): + dp[i] = dp[i - 1] * (k - 1) + dp[i - 2] * (k - 1) + return dp[n] \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23008.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\23008.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" "b/\351\235\242\350\257\225\351\242\23008.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\23008.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" new file mode 100644 index 0000000..513e8ee --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23008.01.\344\270\211\346\255\245\351\227\256\351\242\230/\351\235\242\350\257\225\351\242\23008.01-\344\270\211\346\255\245\351\227\256\351\242\230.py" @@ -0,0 +1,14 @@ +class Solution(object): + def waysToStep(self, n): + """ + :type n: int + :rtype: int + """ + dp = [0 for _ in range(n + 3)] + dp[1] = 1 + dp[2] = 2 + dp[3] = 4 + MOD = 10 ** 9 + 7 + 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\23016.17.\350\277\236\347\273\255\346\225\260\345\210\227/\351\235\242\350\257\225\351\242\23016.17-\350\277\236\347\273\255\346\225\260\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23016.17.\350\277\236\347\273\255\346\225\260\345\210\227/\351\235\242\350\257\225\351\242\23016.17-\350\277\236\347\273\255\346\225\260\345\210\227.py" new file mode 100644 index 0000000..c9af973 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.17.\350\277\236\347\273\255\346\225\260\345\210\227/\351\235\242\350\257\225\351\242\23016.17-\350\277\236\347\273\255\346\225\260\345\210\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def maxSubArray(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + dp = [0 for _ in nums] + for i, x in enumerate(nums): + dp[i] = max(x, dp[i - 1] + x) if i else x + return max(dp) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" "b/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" index bccbcff..109e90c 100644 --- "a/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" +++ "b/\351\235\242\350\257\225\351\242\23017.16.\346\214\211\346\221\251\345\270\210/\351\235\242\350\257\225\351\242\23017.16-\346\214\211\346\221\251\345\270\210.py" @@ -4,10 +4,11 @@ def massage(self, nums): :type nums: List[int] :rtype: int """ + if not nums: + return 0 + if len(nums) == 1: + return nums[0] dp = [0 for _ in nums] - for i in range(len(nums)): - dp[i] = nums[i] - for j in range(i - 1): - dp[i] = max(dp[i], dp[j] + nums[i]) - return max(dp) if nums else 0 \ No newline at end of file + dp[i] = max(dp[i - 1], dp[i - 2] + nums[i]) + return dp[-1] \ No newline at end of file From 51f75d5795f0f004c7fbe153d16b398e078c2ff6 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 7 Jul 2020 23:59:52 -0400 Subject: [PATCH 123/183] 2020-07-07 --- ...23016.11-\350\267\263\346\260\264\346\235\277.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" diff --git "a/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" "b/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" new file mode 100644 index 0000000..797ffe5 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" @@ -0,0 +1,12 @@ +class Solution(object): + def divingBoard(self, shorter, longer, k): + """ + :type shorter: int + :type longer: int + :type k: int + :rtype: List[int] + """ + res = set() + for i in range(k + 1): + res.add(shorter * i + longer * (k - i)) + return sorted(list(res)) if k else [] \ No newline at end of file From 6a25c4f14dac3868975ea65bb0f121b276015ffb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 8 Jul 2020 00:23:33 -0400 Subject: [PATCH 124/183] 2020-07-08 --- ...\242\23016.11-\350\267\263\346\260\264\346\235\277.py" | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git "a/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" "b/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" index 797ffe5..e83177e 100644 --- "a/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" +++ "b/\351\235\242\350\257\225\351\242\23016.11.\350\267\263\346\260\264\346\235\277/\351\235\242\350\257\225\351\242\23016.11-\350\267\263\346\260\264\346\235\277.py" @@ -6,7 +6,9 @@ def divingBoard(self, shorter, longer, k): :type k: int :rtype: List[int] """ - res = set() + res = [] for i in range(k + 1): - res.add(shorter * i + longer * (k - i)) - return sorted(list(res)) if k else [] \ No newline at end of file + s = shorter * (k - i) + longer * i + if not res or res[-1] != s: + res.append(s) + return res if k else [] \ No newline at end of file From 6429124f0b72187ad47b694c03b28708ade5ff42 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 9 Jul 2020 23:53:44 -0400 Subject: [PATCH 125/183] 2020-07-09 --- ...53\345\206\267\345\206\273\346\234\237.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" diff --git "a/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" "b/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" new file mode 100644 index 0000000..cf05fd7 --- /dev/null +++ "b/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" @@ -0,0 +1,23 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + #dp[i][k][1/0]琛ㄧず绗琲澶╄繕鍙互浜ゆ槗k娆℃墜涓婃寔鏈夋垨娌℃寔鏈夎偂绁ㄧ殑鐘舵 + #瀵逛簬绗簩棰橈紝k = 2 + #dp[i][k][0] = max(dp[i - 1][k][0], dp[i - 1][k][1] + price[i]) + #dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - price[i]) + #褰搆 = 0鏃讹紝 dp[i][0][1/0] = 0 + dp = [[0 for _ in range(2)] for _ in range(len(prices))] + + for i in range(len(prices)): + if i == 0: + dp[i][0] = 0 + dp[i][1] = -prices[i] + else: + dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) + dp[i][1] = max(dp[i - 1][1], dp[i - 2][0] - prices[i]) + + # print dp + return dp[len(prices) - 1][0] if prices else 0 \ No newline at end of file From 6ef504c5d8479175dd09bb7b35c280d2f570bb9e Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 10 Jul 2020 23:25:00 -0400 Subject: [PATCH 126/183] 2020-07-10 --- ...44\346\225\260\344\271\213\345\222\214.py" | 19 +++++++------------ ...40\347\232\204\344\270\252\346\225\260.py" | 13 +++++-------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git "a/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" "b/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" index 8b92177..8d14258 100644 --- "a/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" +++ "b/1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" @@ -1,12 +1,7 @@ -class Solution(object): - def twoSum(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - dic = {} - for i, num in enumerate(nums): - if target - num in dic: - return [dic[target - num], i] - dic[num] = i \ No newline at end of file +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + hashmap = {} + for index, item in enumerate(nums): + if target - item in hashmap: + return hashmap[target-item],index + hashmap[item] = index diff --git "a/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" "b/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" index 4abc475..663b691 100644 --- "a/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" +++ "b/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" @@ -11,7 +11,6 @@ def countSmaller(self, nums): :type nums: List[int] :rtype: List[int] """ - # 浠庡乏寰鍙冲鐞嗭紝鍙宠竟鏄湭鐭ョ殑锛屾墍浠ヤ笉濂藉紕 # 浠庡彸寰宸﹀鐞嗭紝鍒欏浜庢瘡涓暟锛屽叾鍙宠竟鐨勬暟閮藉凡鐭 res = [0 for _ in nums] @@ -21,15 +20,13 @@ def countSmaller(self, nums): return res[::-1] def insert(self, root, val, i, res): - if not root: + if not root: #濡傛灉褰撳墠root涓虹┖ root = TreeNode(val) - elif root.val >= val: + elif root.val >= val: # 濡傛灉搴旇鎻掑叆宸﹀瓙鏍 root.left_subtree_cnt += 1 root.left = self.insert(root.left, val, i, res) - elif root.val < val: - res[i] += root.left_subtree_cnt + 1 + elif root.val < val: # 濡傛灉搴旇鎻掑叆鍙冲瓙鏍 + res[i] += root.left_subtree_cnt + 1 # 1 浠h〃褰撳墠root root.right = self.insert(root.right, val, i, res) - return root - - \ No newline at end of file + return root \ No newline at end of file From b079f2a261ca69ecde0a58fe027929304192ab4b Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 11 Jul 2020 21:01:17 -0400 Subject: [PATCH 127/183] 2020-07-11 --- ...45\346\234\237\346\240\274\345\274\217.py" | 13 ++++++++++++ ...04\345\214\272\351\227\264\345\222\214.py" | 18 +++++++++++++++++ ...04\346\234\200\345\260\217\345\267\256.py" | 19 ++++++++++++++++++ ...\345\255\220\346\270\270\346\210\217IV.py" | 15 ++++++++++++++ ...13\345\237\216\346\270\270\346\210\217.py" | 20 +++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 "1507.\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217/1507-\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217.py" create mode 100644 "1508.\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214/1508-\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214.py" create mode 100644 "1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" create mode 100644 "1510.\347\237\263\345\255\220\346\270\270\346\210\217IV/1510-\347\237\263\345\255\220\346\270\270\346\210\217IV.py" create mode 100644 "174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" diff --git "a/1507.\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217/1507-\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217.py" "b/1507.\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217/1507-\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217.py" new file mode 100644 index 0000000..3da2a3f --- /dev/null +++ "b/1507.\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217/1507-\350\275\254\345\217\230\346\227\245\346\234\237\346\240\274\345\274\217.py" @@ -0,0 +1,13 @@ +class Solution(object): + def reformatDate(self, date): + """ + :type date: str + :rtype: str + """ + date = date.split(" ") + + day = "0" + date[0][:1] if len(date[0]) == 3 else date[0][:2] + mon = {"Jan":"01", "Feb":"02", "Mar":"03", "Apr":"04", "May":"05", "Jun":"06", + "Jul":"07", "Aug":"08", "Sep":"09", "Oct":"10", "Nov":"11", "Dec":"12"}[date[1]] + year = date[2] + return "-".join([year, mon, day]) \ No newline at end of file diff --git "a/1508.\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214/1508-\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214.py" "b/1508.\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214/1508-\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214.py" new file mode 100644 index 0000000..518444a --- /dev/null +++ "b/1508.\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214/1508-\345\255\220\346\225\260\347\273\204\345\222\214\346\216\222\345\272\217\345\220\216\347\232\204\345\214\272\351\227\264\345\222\214.py" @@ -0,0 +1,18 @@ +class Solution(object): + def rangeSum(self, nums, n, left, right): + """ + :type nums: List[int] + :type n: int + :type left: int + :type right: int + :rtype: int + """ + res = [] + for i in range(n): + for j in range(i + 1, n + 1): + res.append(sum(nums[i:j])) + res.sort() + # print res + return sum(res[left - 1:right]) % (10 ** 9 + 7) + + \ No newline at end of file diff --git "a/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" "b/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" new file mode 100644 index 0000000..283a363 --- /dev/null +++ "b/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" @@ -0,0 +1,19 @@ +class Solution(object): + def minDifference(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if len(nums) <= 4: + return 0 + nums.sort() + + # 1. 鍘诲墠涓変釜 + res = nums[-1] - nums[3] + # 2. 鍘诲墠涓や釜鍜屾渶鍚庝竴涓 + res = min(res, nums[-2] - nums[2]) + # 3. 鍘荤涓涓拰鏈鍚庝袱涓 + res = min(res, nums[-3] - nums[1]) + # 4. 鍘绘渶鍚庝笁涓 + res = min(res, nums[-4] - nums[0]) + return res \ No newline at end of file diff --git "a/1510.\347\237\263\345\255\220\346\270\270\346\210\217IV/1510-\347\237\263\345\255\220\346\270\270\346\210\217IV.py" "b/1510.\347\237\263\345\255\220\346\270\270\346\210\217IV/1510-\347\237\263\345\255\220\346\270\270\346\210\217IV.py" new file mode 100644 index 0000000..408a00a --- /dev/null +++ "b/1510.\347\237\263\345\255\220\346\270\270\346\210\217IV/1510-\347\237\263\345\255\220\346\270\270\346\210\217IV.py" @@ -0,0 +1,15 @@ +class Solution(object): + def winnerSquareGame(self, n): + """ + :type n: int + :rtype: bool + """ + dp = [0 for _ in range(n + 1)] + dp[1] = 1 + for i in range(2, n + 1): + for j in range(1, int(i ** 0.5 + 1)): + if not dp[i - j * j]: + dp[i] = 1 + break + return dp[n] == 1 + \ No newline at end of file diff --git "a/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" "b/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" new file mode 100644 index 0000000..4d7ab41 --- /dev/null +++ "b/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" @@ -0,0 +1,20 @@ +class Solution(object): + def calculateMinimumHP(self, dungeon): + """ + :type dungeon: List[List[int]] + :rtype: int + """ + if len(dungeon[0])==0: + return 1 + dungeon[-1][-1] = max(1,1-dungeon[-1][-1]) + # 杈圭晫 + for i in range(len(dungeon)-2,-1,-1): + dungeon[i][-1] = max(1,dungeon[i+1][-1]-dungeon[i][-1]) + for j in range(len(dungeon[0])-2,-1,-1): + dungeon[-1][j] = max(1,dungeon[-1][j+1]-dungeon[-1][j]) + + for i in range(len(dungeon)-2,-1,-1): + for j in range(len(dungeon[0])-2,-1,-1): + dungeon[i][j] = max(1,min(dungeon[i][j+1]-dungeon[i][j],dungeon[i+1][j]-dungeon[i][j])) + # print(dungeon) + return dungeon[0][0] \ No newline at end of file From 731f7dc70a02c9a3f99c4167f44fa2a7e0a78b85 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 11 Jul 2020 21:44:15 -0400 Subject: [PATCH 128/183] remote dups --- .DS_Store | Bin 40964 -> 51204 bytes ...02\345\272\217\351\201\215\345\216\206.py" | 31 -------- ...64\347\232\204\345\256\271\345\231\250.py" | 20 ----- ...35\345\244\247\345\244\232\346\225\260.py" | 2 +- ...02\347\202\271\346\214\207\351\222\210.py" | 36 --------- ...\347\202\271\346\214\207\351\222\210II.py" | 41 ---------- ...72\347\216\260\351\242\221\346\254\241.py" | 30 ++++--- ...\351\207\215\345\244\215\351\241\271II.py" | 20 ----- ...00\344\275\263\346\227\266\346\234\272.py" | 12 --- ...04\351\207\221\347\237\277\345\267\245.py" | 31 -------- ...33\346\216\267\347\241\254\345\270\201.py" | 2 +- ...01\345\233\236\346\226\207\344\270\262.py" | 12 --- ...33\345\210\266\347\237\251\351\230\265.py" | 27 ------- ...25\350\257\215\351\233\206\345\220\210.py" | 22 +++--- ...40\345\257\206\346\225\260\345\255\227.py" | 7 -- ...54\345\205\261\345\214\272\345\237\237.py" | 24 ------ ...11\350\257\215\345\217\245\345\255\220.py" | 56 ------------- ...44\347\232\204\346\217\241\346\211\213.py" | 10 --- ...21\346\240\274\350\277\201\347\247\273.py" | 19 ----- ...45\346\211\276\345\205\203\347\264\240.py" | 40 ---------- ...04\346\234\200\345\244\247\345\222\214.py" | 42 ---------- ...57\345\217\230\351\223\276\350\241\250.py" | 32 -------- ...04\350\216\267\350\203\234\350\200\205.py" | 4 +- ...57\345\222\214\344\271\213\345\267\256.py" | 13 --- ...50\346\210\267\345\210\206\347\273\204.py" | 18 ----- ...00\345\260\217\351\231\244\346\225\260.py" | 24 ------ ...15\350\275\254\346\254\241\346\225\260.py" | 71 ----------------- ...3\346\235\237\346\225\260\345\255\227.sql" | 6 -- ...10\350\277\255\344\273\243\345\231\250.py" | 30 ------- ...5%\347\232\204\345\205\203\347\264\240.py" | 16 ---- ...06\347\233\226\345\214\272\351\227\264.py" | 19 ----- ...\346\234\200\345\260\217\345\222\214II.py" | 24 ------ ...50\350\275\254\346\225\264\346\225\260.py" | 17 ---- ...1-\351\241\272\346\254\241\346\225\260.py" | 22 ------ ...60\347\232\204\346\225\260\345\255\227.py" | 11 --- ...27\347\232\204\351\233\206\345\220\210.py" | 22 ------ ...72\347\216\260\346\254\241\346\225\260.py" | 21 ----- ...47\347\263\226\346\236\234\346\225\260.py" | 34 -------- ...00\345\244\247\345\205\203\347\264\240.py" | 12 --- ...04\346\225\260\347\273\204\345\222\214.py" | 39 --------- ...57\345\276\204\346\225\260\347\233\256.py" | 30 ------- ...02\347\202\271\347\232\204\345\222\214.py" | 27 ------- ...57\344\270\200\346\225\264\346\225\260.py" | 14 ---- ...00\346\234\211\345\205\203\347\264\240.py" | 24 ------ ...350\267\203\346\270\270\346\210\217III.py" | 21 ----- ...64\346\225\260\346\230\240\345\260\204.py" | 15 ---- ...62\345\233\236\346\226\207\344\270\262.py" | 24 ------ ...02\346\210\226\346\237\245\350\257\242.py" | 18 ----- ...13\347\232\204\350\247\206\351\242\221.py" | 34 -------- ...22\345\205\245\346\254\241\346\225\260.py" | 23 ------ ...26\347\240\201\345\210\227\350\241\250.py" | 10 --- ...04\350\212\202\347\202\271\345\222\214.py" | 24 ------ ...64\346\225\260\347\232\204\345\222\214.py" | 11 --- ...\345\233\236\346\226\207\344\270\262II.py" | 15 ---- ...3-\345\205\213\351\232\206\345\233\276.py" | 34 -------- ...60\347\233\256\346\216\222\345\272\217.py" | 7 -- ...27\347\232\204\346\225\260\345\255\227.py" | 13 --- ...15\345\255\227\347\254\246\344\270\262.py" | 20 ----- ...70\345\220\214\350\212\202\347\202\271.py" | 28 ------- ...10\347\232\204\351\223\276\350\241\250.py" | 26 ------ ...04\350\267\235\347\246\273\345\200\274.py" | 20 ----- ...61\351\231\242\345\272\247\344\275\215.py" | 31 -------- ...03\351\207\215\346\216\222\345\272\217.py" | 21 ----- ...25\350\257\215\346\213\206\345\210\206.py" | 16 ---- ...04\345\271\270\350\277\220\346\225\260.py" | 8 -- ...30\345\215\225\344\275\215\346\225\260.py" | 26 ------ ...60\351\223\201\347\263\273\347\273\237.py" | 44 ----------- ...04\347\232\204\346\225\260\347\233\256.py" | 22 ------ ...07\345\255\227\347\254\246\344\270\262.py" | 19 ----- ...32\350\217\234\351\241\272\345\272\217.py" | 20 ----- ...17\345\255\220\345\272\217\345\210\227.py" | 17 ---- ...04\346\255\245\351\252\244\346\225\260.py" | 15 ---- ...20\345\255\227\347\254\246\344\270\262.py" | 38 --------- ...46\344\270\262\345\214\271\351\205\215.py" | 16 ---- ...56\347\232\204\346\216\222\345\210\227.py" | 15 ---- ...23\350\247\243\346\236\220\345\231\250.py" | 14 ---- ...04\346\234\200\345\260\217\345\200\274.py" | 13 --- ...60\345\255\227\346\225\260\347\233\256.py" | 22 ------ ...26\345\255\227\347\254\246\344\270\262.py" | 32 -------- ...34\345\261\225\347\244\272\350\241\250.py" | 30 ------- ...9-\346\225\260\351\235\222\350\233\231.py" | 31 -------- ...00\345\244\247\345\276\227\345\210\206.py" | 17 ---- ...00\345\244\247\347\202\271\346\225\260.py" | 21 ----- ...6-\346\225\260\345\205\203\347\264\240.py" | 13 --- ...00\347\256\200\345\210\206\346\225\260.py" | 6 +- ...23\345\255\230\346\234\272\345\210\266.py" | 74 ------------------ ...14\347\232\204\345\215\225\350\257\215.py" | 7 -- ...5-\346\234\200\345\260\217\346\240\210.py" | 47 ----------- ...11\345\272\217\346\225\260\347\273\204.py" | 16 ---- ...32\346\225\260\345\205\203\347\264\240.py" | 19 ----- ...04\345\217\263\350\247\206\345\233\276.py" | 31 -------- ...33\345\261\277\346\225\260\351\207\217.py" | 33 -------- ...11\345\272\217\351\223\276\350\241\250.py" | 33 -------- ...54\345\217\267\347\224\237\346\210\220.py" | 18 ----- ...47\346\255\243\346\226\271\345\275\242.py" | 29 ------- ...27\345\256\236\347\216\260\346\240\210.py" | 49 ------------ ...73\350\275\254\351\223\276\350\241\250.py" | 45 ----------- ...2-\344\274\232\350\256\256\345\256\244.py" | 18 ----- ...\344\274\232\350\256\256\345\256\244II.py" | 20 ----- ...76\351\207\215\345\244\215\346\225\260.py" | 17 ---- ...37\345\221\275\346\270\270\346\210\217.py" | 50 ------------ ...60\345\244\264\345\234\260\347\202\271.py" | 29 ------- ...60\345\255\227\346\270\270\346\210\217.py" | 22 ------ ...07\345\255\220\345\272\217\345\210\227.py" | 14 ---- ...66\351\222\261\345\205\221\346\215\242.py" | 25 ------ .../326-3\347\232\204\345\271\202.py" | 10 --- ...30\351\242\221\345\205\203\347\264\240.py" | 21 ----- ...76\350\256\241\346\216\250\347\211\271.py" | 51 ------------ ...64\345\243\266\351\227\256\351\242\230.py" | 21 ----- ...66\345\255\220\350\212\202\347\202\271.py" | 35 --------- ...17\347\232\204\345\205\203\347\264\240.py" | 25 ------ ...70\345\272\217\346\216\222\346\225\260.py" | 20 ----- ...57\344\270\200\345\255\227\347\254\246.py" | 12 --- ...72\346\225\260\347\264\242\345\274\225.py" | 22 ------ ...77\345\233\236\346\226\207\344\270\262.py" | 7 -- ...2-\346\216\245\351\233\250\346\260\264.py" | 31 -------- ...14\345\220\221\351\223\276\350\241\250.py" | 47 ----------- ...14\345\220\221\351\223\276\350\241\250.py" | 38 --------- ...76\345\217\263\345\214\272\351\227\264.py" | 23 ------ ...\346\225\260\347\233\270\345\212\240II.py" | 44 ----------- ...25\347\210\206\346\260\224\347\220\203.py" | 20 ----- .../460-LFU\347\274\223\345\255\230.py" | 60 -------------- ...15\345\244\215\344\270\252\346\225\260.py" | 57 -------------- ...27\347\232\204\350\241\245\346\225\260.py" | 16 ---- ...35\347\246\273\346\200\273\345\222\214.py" | 20 ----- ...45\346\240\274\345\274\217\345\214\226.py" | 18 ----- ...15\350\257\215\345\210\206\347\273\204.py" | 13 --- ...4\345\244\247\345\205\203\347\264\240I.py" | 24 ------ 50.Pow(x,n)/50-Pow(x,n).py | 8 -- ...07\345\255\220\345\272\217\345\210\227.py" | 17 ---- ...47\345\255\220\345\272\217\345\222\214.py" | 19 ----- .../542-01\347\237\251\351\230\265.py" | 38 --------- ...21\347\232\204\347\233\264\345\276\204.py" | 20 ----- ...63\350\267\203\346\270\270\346\210\217.py" | 13 --- ...2\345\213\244\350\256\260\345\275\225I.py" | 7 -- ...10\345\271\266\345\214\272\351\227\264.py" | 24 ------ ...04\345\255\220\346\225\260\347\273\204.py" | 22 ------ ...0\347\273\204\346\213\206\345\210\206I.py" | 7 -- ...15\345\241\221\347\237\251\351\230\265.py" | 20 ----- ...22\345\205\245\345\214\272\351\227\264.py" | 35 --------- ...21\347\232\204\345\255\220\346\240\221.py" | 32 -------- ...15\347\232\204\351\225\277\345\272\246.py" | 9 --- ...55\345\255\220\346\225\260\347\273\204.py" | 19 ----- ...71\346\225\260\344\271\213\345\222\214.py" | 12 --- ...31\344\275\215\346\216\222\345\210\227.py" | 10 --- ...04\345\271\263\346\226\271\346\240\271.py" | 17 ---- ...00\345\244\247\351\235\242\347\247\257.py" | 35 --------- ...11\347\232\204\345\255\220\351\233\206.py" | 39 --------- ...26\350\276\221\350\267\235\347\246\273.py" | 25 ------ ...30\344\275\215\346\230\240\345\260\204.py" | 13 --- ...27\346\257\215\345\214\272\351\227\264.py" | 39 --------- ...63\344\270\216\347\237\263\345\244\264.py" | 13 --- ...04\345\215\225\350\257\215\346\225\260.py" | 31 -------- ...\215\242\346\225\264\346\225\260(atoi).py" | 36 --------- ...14\347\232\204\346\226\207\345\255\227.py" | 38 --------- ...13\347\274\251\347\274\226\347\240\201.py" | 36 --------- ...51\345\275\242\351\207\215\345\217\240.py" | 10 --- ...00\351\225\277\345\261\261\350\204\211.py" | 24 ------ ...55\351\227\264\347\273\223\347\202\271.py" | 17 ---- ...41\350\233\213\346\216\211\350\220\275.py" | 15 ---- ...04\350\241\250\351\235\242\347\247\257.py" | 16 ---- ...22\345\272\217\346\225\260\347\273\204.py" | 7 -- ...22\345\272\217\346\225\260\347\273\204.py" | 7 -- ...41\347\211\214\345\210\206\347\273\204.py" | 11 --- ...00\345\260\221\346\267\273\345\212\240.py" | 14 ---- ...00\345\260\217\345\242\236\351\207\217.py" | 11 --- ...01\346\240\210\345\272\217\345\210\227.py" | 16 ---- ...1\347\232\204K\344\270\252\347\202\271.py" | 25 ------ ...11\346\220\234\347\264\242\346\240\221.py" | 20 ----- ...02\347\232\204\346\251\230\345\255\220.py" | 43 ---------- ...04\346\243\213\345\255\220\346\225\260.py" | 28 ------- ...15\347\232\204\346\225\260\345\255\227.py" | 11 --- ...55\347\232\204\346\237\245\346\211\276.py" | 21 ----- ...77\346\215\242\347\251\272\346\240\274.py" | 7 -- ...23\345\215\260\351\223\276\350\241\250.py" | 17 ---- ...72\344\272\214\345\217\211\346\240\221.py" | 22 ------ ...36\347\216\260\351\230\237\345\210\227.py" | 28 ------- ...43\345\245\221\346\225\260\345\210\227.py" | 17 ---- ...60\351\230\266\351\227\256\351\242\230.py" | 17 ---- ...00\345\260\217\346\225\260\345\255\227.py" | 21 ----- ...55\347\232\204\350\267\257\345\276\204.py" | 33 -------- ...20\345\212\250\350\214\203\345\233\264.py" | 29 ------- ...I-\345\211\252\347\273\263\345\255\220.py" | 24 ------ ...\345\211\252\347\273\263\345\255\220II.py" | 15 ---- ...51\347\232\204\344\270\252\346\225\260.py" | 11 --- ...64\346\225\260\346\254\241\346\226\271.py" | 25 ------ ...7\347\232\204n\344\275\215\346\225\260.py" | 7 -- ...50\347\232\204\350\212\202\347\202\271.py" | 24 ------ ...66\346\225\260\345\211\215\351\235\242.py" | 16 ---- ...4k\344\270\252\350\212\202\347\202\271.py" | 23 ------ ...15\350\275\254\351\223\276\350\241\250.py" | 20 ----- ...17\347\232\204\351\223\276\350\241\250.py" | 33 -------- ...21\347\232\204\351\225\234\345\203\217.py" | 19 ----- ...04\344\272\214\345\217\211\346\240\221.py" | 23 ------ ...23\345\215\260\347\237\251\351\230\265.py" | 45 ----------- ...75\346\225\260\347\232\204\346\240\210.py" | 50 ------------ ...71\345\207\272\345\272\217\345\210\227.py" | 19 ----- ...60\344\272\214\345\217\211\346\240\221.py" | 28 ------- ...\344\272\214\345\217\211\346\240\221II.py" | 30 ------- ...344\272\214\345\217\211\346\240\221III.py" | 35 --------- ...15\345\216\206\345\272\217\345\210\227.py" | 25 ------ ...74\347\232\204\350\267\257\345\276\204.py" | 31 -------- ...50\347\232\204\345\244\215\345\210\266.py" | 30 ------- ...14\345\220\221\351\223\276\350\241\250.py" | 47 ----------- ...62\347\232\204\346\216\222\345\210\227.py" | 16 ---- ...12\347\232\204\346\225\260\345\255\227.py" | 7 -- ...7\347\232\204k\344\270\252\346\225\260.py" | 18 ----- ...04\346\234\200\345\244\247\345\222\214.py" | 16 ---- ...00\345\244\247\344\273\267\345\200\274.py" | 22 ------ ...54\345\205\261\350\212\202\347\202\271.py" | 39 --------- ...5\346\211\276\346\225\260\345\255\227I.py" | 8 -- ...61\347\232\204\346\225\260\345\255\227.py" | 16 ---- ...4k\345\244\247\350\212\202\347\202\271.py" | 36 --------- ...21\347\232\204\346\267\261\345\272\246.py" | 16 ---- ...43\346\225\260\345\272\217\345\210\227.py" | 22 ------ ...44\344\270\252\346\225\260\345\255\227.py" | 17 ---- ...54\345\255\227\347\254\246\344\270\262.py" | 8 -- ...04\346\234\200\345\244\247\345\200\274.py" | 35 --------- ...13\347\232\204\346\225\260\345\255\227.py" | 10 --- ...00\345\244\247\345\210\251\346\266\246.py" | 12 --- ...Offer64-\346\261\2021+2+\342\200\246+n.py" | 7 -- ...44\345\201\232\345\212\240\346\263\225.py" | 8 -- ...30\347\247\257\346\225\260\347\273\204.py" | 15 ---- ...54\345\205\261\347\245\226\345\205\210.py" | 20 ----- ...54\345\205\261\347\245\226\345\205\210.py" | 23 ------ ...27\347\254\246\351\207\215\346\216\222.py" | 9 --- ...36\346\226\207\346\216\222\345\210\227.py" | 14 ---- ...13\350\275\254\347\237\251\351\230\265.py" | 7 -- ...46\344\270\262\350\275\256\350\275\254.py" | 8 -- ...15\345\244\215\350\212\202\347\202\271.py" | 26 ------ ...4k\344\270\252\350\212\202\347\202\271.py" | 22 ------ ...55\351\227\264\350\212\202\347\202\271.py" | 19 ----- ...24\346\234\257\347\264\242\345\274\225.py" | 10 --- ...\242\23008.11-\347\241\254\345\270\201.py" | 12 --- ...\242\23016.03-\344\272\244\347\202\271.py" | 4 - ...37\345\255\230\344\272\272\346\225\260.py" | 21 ----- ...67\347\232\204\345\212\240\346\263\225.py" | 8 -- 237 files changed, 37 insertions(+), 5290 deletions(-) delete mode 100644 "102.\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\345\272\217\351\201\215\345\216\206/102-\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" delete mode 100644 "11.\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250/11-\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.py" delete mode 100644 "116.\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/116-\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" delete mode 100644 "117.\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/117-\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" delete mode 100644 "1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" delete mode 100644 "121.\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/121-\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" delete mode 100644 "1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" delete mode 100644 "125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" delete mode 100644 "1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" delete mode 100644 "1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" delete mode 100644 "1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" delete mode 100644 "1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" delete mode 100644 "1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" delete mode 100644 "1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" delete 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" delete mode 100644 "1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" delete 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" delete mode 100644 "1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" delete 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" delete mode 100644 "1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" delete mode 100644 "1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" delete mode 100644 "1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" delete mode 100644 "1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" delete mode 100644 "1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" delete mode 100644 "1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" delete mode 100644 "1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" delete 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" delete mode 100644 "1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" delete mode 100644 "1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" delete mode 100644 "1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" delete mode 100644 "1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" delete mode 100644 "1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" delete mode 100644 "1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" delete mode 100644 "1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" delete mode 100644 "1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" delete 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" delete mode 100644 "1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" delete mode 100644 "1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" delete mode 100644 "1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" delete mode 100644 "1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" delete mode 100644 "131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" delete mode 100644 "1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" delete mode 100644 "1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" delete mode 100644 "1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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" delete mode 100644 "1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" delete 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" delete mode 100644 "1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" delete mode 100644 "132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" delete mode 100644 "133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" delete mode 100644 "1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" delete mode 100644 "1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" delete mode 100644 "1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" delete 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" delete mode 100644 "138.\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/138-\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" delete mode 100644 "1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" delete mode 100644 "1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" delete mode 100644 "1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" delete mode 100644 "139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" delete mode 100644 "1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" delete mode 100644 "1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" delete 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" delete mode 100644 "1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" delete mode 100644 "1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" delete mode 100644 "1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" delete mode 100644 "1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" delete mode 100644 "1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" delete mode 100644 "1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" delete mode 100644 "1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" delete 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" delete mode 100644 "1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" delete mode 100644 "1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" delete mode 100644 "1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" delete mode 100644 "1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" delete 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" delete mode 100644 "1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" delete mode 100644 "1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" delete mode 100644 "1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" delete mode 100644 "1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" delete mode 100644 "146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" delete mode 100644 "151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" delete mode 100644 "155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" delete mode 100644 "167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" delete mode 100644 "169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" delete mode 100644 "199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" delete mode 100644 "200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" delete mode 100644 "21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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" delete mode 100644 "22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" delete mode 100644 "221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" delete mode 100644 "225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" delete mode 100644 "25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" delete mode 100644 "252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" delete mode 100644 "253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" delete mode 100644 "287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" delete mode 100644 "289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" delete mode 100644 "296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" delete mode 100644 "299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" delete mode 100644 "300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" delete mode 100644 "322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" delete mode 100644 "326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" delete mode 100644 "347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" delete mode 100644 "355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" delete mode 100644 "365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" delete mode 100644 "366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" delete mode 100644 "378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" delete mode 100644 "386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" delete mode 100644 "387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" delete mode 100644 "398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" delete mode 100644 "409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" delete mode 100644 "42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" delete mode 100644 "426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" delete mode 100644 "430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" delete mode 100644 "436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" delete mode 100644 "445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" delete mode 100644 "452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" delete mode 100644 "460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" delete mode 100644 "466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" delete mode 100644 "476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" delete mode 100644 "477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" delete mode 100644 "482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" delete mode 100644 "49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" delete mode 100644 "496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" delete mode 100644 50.Pow(x,n)/50-Pow(x,n).py delete mode 100644 "516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" delete mode 100644 "53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" delete mode 100644 "542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" delete mode 100644 "543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" delete mode 100644 "55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" delete mode 100644 "551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" delete mode 100644 "56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" delete mode 100644 "560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" delete mode 100644 "561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" delete mode 100644 "566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" delete mode 100644 "57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" delete mode 100644 "572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" delete mode 100644 "58.\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/58-\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" delete mode 100644 "581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" delete mode 100644 "633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" delete mode 100644 "634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" delete mode 100644 "69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" delete mode 100644 "695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" delete mode 100644 "698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" delete mode 100644 "72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" delete mode 100644 "760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" delete mode 100644 "763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" delete mode 100644 "771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" delete mode 100644 "792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" delete mode 100644 "8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" delete mode 100644 "809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" delete mode 100644 "820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" delete mode 100644 "836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" delete mode 100644 "845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" delete mode 100644 "876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" delete mode 100644 "887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" delete mode 100644 "892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" delete mode 100644 "905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" delete mode 100644 "912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" delete mode 100644 "914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" delete mode 100644 "921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" delete mode 100644 "945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" delete mode 100644 "946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" delete mode 100644 "973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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" delete mode 100644 "98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" delete mode 100644 "994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" delete mode 100644 "999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" delete mode 100644 "\345\211\221\346\214\207Offer03.\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\207Offer03-\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" delete mode 100644 "\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" delete mode 100644 "\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" delete mode 100644 "\345\211\221\346\214\207Offer06.\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\207Offer06-\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" delete mode 100644 "\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" delete mode 100644 "\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" delete mode 100644 "\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" delete mode 100644 "\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" delete mode 100644 "\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" delete mode 100644 "\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" delete mode 100644 "\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" delete mode 100644 "\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" delete mode 100644 "\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" delete mode 100644 "\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" delete mode 100644 "\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" delete mode 100644 "\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" delete mode 100644 "\345\211\221\346\214\207Offer22.\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\207Offer22-\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" delete mode 100644 "\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" delete mode 100644 "\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" delete mode 100644 "\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" delete mode 100644 "\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" delete mode 100644 "\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" delete mode 100644 "\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" delete mode 100644 "\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" delete mode 100644 "\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" delete mode 100644 "\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" delete mode 100644 "\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" delete mode 100644 "\345\211\221\346\214\207Offer35.\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\207Offer35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" delete mode 100644 "\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" delete mode 100644 "\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" delete mode 100644 "\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" delete mode 100644 "\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" delete mode 100644 "\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" delete mode 100644 "\345\211\221\346\214\207Offer52.\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\207Offer52-\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" delete mode 100644 "\345\211\221\346\214\207Offer53-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\207Offer53-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" delete mode 100644 "\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" delete mode 100644 "\345\211\221\346\214\207Offer54.\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\207Offer54-\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" delete mode 100644 "\345\211\221\346\214\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" delete mode 100644 "\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" delete mode 100644 "\345\211\221\346\214\207Offer57.\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\207Offer57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" delete mode 100644 "\345\211\221\346\214\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" delete mode 100644 "\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" delete mode 100644 "\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" delete mode 100644 "\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" delete mode 100644 "\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" delete mode 100644 "\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" delete mode 100644 "\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" delete mode 100644 "\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" delete mode 100644 "\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23001.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\23001.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" delete mode 100644 "\351\235\242\350\257\225\351\242\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23002.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\23002.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" delete mode 100644 "\351\235\242\350\257\225\351\242\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" delete mode 100644 "\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" diff --git a/.DS_Store b/.DS_Store index 5f8901c500e3a3ec6b435b94efe09d6029609d3f..c9411c67781be06594d800e5afb708a78aecea60 100644 GIT binary patch delta 10965 zcmeHNeQ=c3xj&mgNXW+~5EhJR78)Q1v)Lq@O+sReK!6Cm*)I~}CcC)F>n_b2R*{7S z$&1WllbeJM9FibqDz?3L?ANG!#~F2QORcTiUOvXTb+Emq=rrE3y`l~dh^W2KbI!ix zJ-eHkcBbw04`G%KoAZ0l^ZcIAbKZ@dPK%7C7ZXBsYj$^65^@@T%!C)d8*>PmHJ6b5 zBgN*~H{gSuXI(MfcZ{>rsQKh9-CUZJ_BegLrAjx4e#5)=HiYF7GpQkUq>`BYWY7EZ zB~LVZao~Nojb2JOtZR7wFYFI2BqWQy%&@qcScz%RdtTp>GtNuR!JS>c;7%X>HXpRQ zLP(=UgPKd<9I4l3)0gMf&j+|JHB~qC;&1VRIvacD@;fR!FUpw%M9134fko0td zq7YGf9aiUu)AO9F>7u6&XPy#+rvn{v{ zv;_P&UH*#wOT7z3EW}Z{2rjq@t^{D*L|3LK+;!9w4M%A2dPC_9yH#R(0*FOa`wBTk z&6^7qVX;;^EaL=9xw}gpr<~Wq5yz?EZ$t$dIsc|1N0p%Z54`9oai2gR-e2KbzO_Ok zf&_&yezYP~epC^lH4g#juyTh0CYWdIwb-0EJt`LXow&N^y@{Fx9Aq2EDe=&m-W2m3 zDuh&yK@*P1A$MB>7;2fYY3|KUxjVsTDXT{wzkK|-h(xwFWNO&TpHz6jr*vkDG6%6F z2vE09@~y2=+!~n@ka4CI$TJL!O3b&>D?y82NdN*>0#Mwt62l2gnjCU0Oh5up0#bDj z!|;8(8ne20crryGqv_Rpb@L;|#OWPV_V^}uc*GaPXa z+hw!PTW|l=6HVj`&E7amW44-0)zHPtNi&#!R+{TDOWCL`m{mwmS!PuUkivKtAw&&LHu7LX(o^Y1MOdP8X2CS-YkX)2 zjxX&iq-&{)g@9Be@vrafP&GipN~R#|&1#&~;7Eq!7*|gk9DCTmub~ z#eZ8Vb~(7M3*+XqZrmS78v!#QYZz=>;K`^uU55dcJ>_B0#3?i$|my z#5e`CuSjm{7!-m8wSUw=Jn~#+lUO+Nz(<~^5&{ajsnBXXZD=h6gT|N+WLG$Xp6uy@ zUJY5ae1;vto9c2TmL9gl($6%EsIh?)Jt_zCJKvRm9Szd4CKzxaLuOcBuP&b`b}Z!4 zk}_7bo2lt#MMt+~v}H==e&Wh=?2xik#=C-aXa%TYYQ?$ez>|HD))=OaJ03_R5*mzv zRGnaj!QT{I11)AHD6!JG9Nv3HCt$I?ryn`GH$DNVBw4Yd@R`ScPTDrnZM!$c+yk6( zcpR-}sTI2^o>8Q2eIL+)G{a(HnHrl`?g?79sdT9h2oM&j;SgU0RX4b)BoB{J)5~Im z^@7N9zKiDzY&33Lpdi6& zV6@?R`u*MpFgj1y9DAqtRvlfCZjI?f59=!PKneyI1d00wRuMc8j^EO0s5kxQ^m$W_jj^2357X#idQ(h4 zR+J9x;4oT?P(F6^^s@(BFS%`^N>~LOpQE?aCS3tFTg(~w0c^C5?o7*q;>9*l;Jz{XL4s%qToC;q<4-e%a6KsG&yqL#{tu5LotxX+l1nRc zbeEYrCSF>G7YdaaC^$@PZ*Ywy$cGSF^&(B1JOp`wE7>&Q*)_O%_>2B*aV>^1NPT4T z06m*t70b#0cU>H01tUzp&+Lz*=S2`w0idS}HWgzXG`D`?$ncLPtN|rp&BcQMg@Bl= zTSq^cw}IZ6w=5^@e5g0Lv)2!uQx|KT|A!230W+o+{KC%p_5iep%5Vf)!wX)Y+m>Q> z1p@CfYe?5KBP%gqeTL}yeUs?d4m}1>&l0?EDZT5*n&lV<)$oF7k6s)rQtSi&6OMGB zY3YE)a68};7IWEE05B1&YlPGfyyDB}ag*Zwgv@BS%4S#{23)@3C@n1G%2p%skLNpKtnB?`Yr_1BIq}u+YYgNRvGO;O zX=@z)ecwy=Lt`&>G~r!VIMR03lO`(1tXCz#fgNx3kfUmhM)`$_8mZj3NS<_j(@(q* zlVsE2W>EmuYE;_-hR$`PXY?ELqM?*P+(h#Nk_)u%ltIM!wlPP0vr-R zfOD?c7(IGr^yj^GK0Rp_G04@|N;O<@L)lE-0XJ~&HfQbyUp_HwQ$Z0Bw=ilf=n*sv z(sYwl=-Jh_!PW?)_F<^ghmmz`TWET6Kq6U!L>>xwnQ4Nf>Jwdajt#;=r+(;-xbBL2 z#|nH2K+ZC2EjJBrPBa-O1ObKDgBTo;L4ni$DfwYJHYH71V zKp<~VX?RnGK!7-`V@7vd&lzu8%NA^pSaf>i6W_%uQYL_SinEr6cbWbyPZU#2Du)wc zF%6X#D#G$yrYJj4;D8A{m*FuyMI<0GTJ5-3@q7RWs`eu12hx=DWyh&-q@`&1$0oCFX~wmT;m$?N5+id%YixQR4qH4oYf^7atfK^wdl~@#lHNWbA4y9 z(~f<9e?|KSIRq2@_JN|M0))pvElvrcox!)g#J&s0LO91O!ZL1HE&6V(XwMX0Q@gfx z!uuqF**p1~8i*0_oKn_hh^y}nSKg%KvA2MhElR@pj8Vgo#VRFS!#Zq;s?$7sqvx@) zRIL8C#(G|U*rSEvpTLbZOmT8Wmu}m)j-12xg7+v-er3KQV0gK$!)mA<9-SAUVc#dR zjp-v`xlQzSmJ46>nWx&+8!(g)0Krc<;VNs+U8czr|4*W z5|VRsJ*oOF{m8punFU}x`0K&TEQ1t#piwGUGY3Z)I(E#U2v0Y7s@9`{IQ@D5EZH1e z6!EH*-F6BnMR5dp04oY2xVp#*CZEr_*TUy{ zJdg&k-v|P*a-+Hs*77d~HxIlPdZGWV1RKHa0!CF6xWR2O6-edS=Z{{29{0(_G13ER zW-=Qr0*F5~Vi!9Dzjt5nye#G7UCo5eVa38VuCRwU>>-#U05Qn0LIa_@O9Po0$p7F6 zRs7;ycoxJT?6B4&|HB_t6`_MMN#Fq>w;h<~Ppatlrow;LQz}LCl#177?04XXBWL7i z@I2?7a@(+jq@K_PG&h7b6xn*{T<>h>)`TE~L=q4Sh=R7`r4I{j+ytXdTIHOQ%Ask# z$&Z97av9P}5QSwCB|(h4PmC*|bQMTgJ9&lAH_2TId+ypr%Qbn1T?s{iBlu{9cDIz_ z?1&YodhH_3VxAxD05et;eHD)Zd?IO4@Dd5z7(6Vc&)zv-5pavyCRU_4MKZ&cIA+?o z;&}=uALzy-(cd|&XiYMef?TYCICMY-#1oi%sOu=)Q{jB3Bs@nJU|6CNhQkr4ER{G|(9poQt;M#bMoeM{$B7pz(poJHD=1#00t_w#QDjATai@%s#nuA>^d zcv$U;~!I_u~2Es*U*Fw76G6mJR)6!ebSZ3HI(4JLyspTeDAz0 zZjBizNa6~!=caqExNYn-mwdQcNNy8hSmRmhwZU_=wzKq!RzqGxokqhPdhhz>^Kd)i z<4k(1tGECt7e39W73~!TK&J3%0e!H&QUR`nPZxsW*qfoi{p|^bcf^AEIdN%_7pe0J zt5*DrHv-TQ2eRt(*C&)3^uiY?vg5L#`>8pFPZyZy=+Irc#)Q>aFCkPgVe#QQTxh@r zxoP@)K?$cTD6U_g1HU{6YLfF`^&D8EJqK#^g&c%GdHn5kHoP}!zK%zWk1x)GFTb6F z*E2b>f?2;#r}~q3m%_KL(l~_ufZxY^4gU|HpO3#^!gu=c$wyacXSy#3z%K{De~|%j J?cZSl{C}W^69E7K delta 483 zcmZpfz}#|xNuGg$fzhcn#gKtv29U`C#2{LLhk=2KlYv2DqPziX7*K#~W5{O4$p%MQ z7&#{Mu*{syA7H`AKG`n87|2&Cv}EL*oYiE_$Tj)TBv(f6$(!aFG5!C)S&)O3g_9Ae z8wfbKfm|_`&1yVPnHlvrKbf)}Nlt)39>$`-VD3c8GJ`H!o_cW!)U!@rrqKZcj4v=fY!;vJlu6(} z5J1#{NtMlZlVzDFPoHMBS$KL1)8zXzr%m2CYs2J;v#TcC&M8$cYe_9hEeKiwR16GP z5SYOYBwUfgd9wTg8AebLU1pxlf5cG*qzD*tEKnL0FJJ%^TL5AJ=>wB1jx height[hi]: - area = height[hi] * (hi - lo) - hi -= 1 - else: - area = height[lo] * (hi - lo) - lo += 1 - # print area - res = max(area, res) - - return res - \ No newline at end of file diff --git "a/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" "b/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" index 95f6fca..d915ca3 100644 --- "a/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" +++ "b/1150.\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260/1150-\346\243\200\346\237\245\344\270\200\344\270\252\346\225\260\346\230\257\345\220\246\345\234\250\346\225\260\347\273\204\344\270\255\345\215\240\347\273\235\345\244\247\345\244\232\346\225\260.py" @@ -5,4 +5,4 @@ def isMajorityElement(self, nums, target): :type target: int :rtype: bool """ - return nums.count(target) > (len(nums) // 2) \ No newline at end of file + return nums.count(target) > len(nums) // 2 \ No newline at end of file diff --git "a/116.\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/116-\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/116.\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/116-\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" deleted file mode 100644 index 4a71a00..0000000 --- "a/116.\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/116-\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" +++ /dev/null @@ -1,36 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val=0, left=None, right=None, next=None): - 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 or not root.left: - return root - - root.left.next = root.right - if root.next: - root.right.next = root.next.left - self.connect(root.left) - self.connect(root.right) - - return root - - def findNext(self, node): - nxt = node.next - while nxt: - if nxt.left: - return nxt.left - elif nxt.right: - return nxt.right - else: - nxt = nxt.next - return None \ No newline at end of file diff --git "a/117.\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/117-\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/117.\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/117-\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" deleted file mode 100644 index d38d977..0000000 --- "a/117.\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/117-\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" +++ /dev/null @@ -1,41 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val=0, left=None, right=None, next=None): - 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 root - - if root.left and root.right: - root.left.next = root.right - root.right.next = self.findNext(root) - - elif root.left: - root.left.next = self.findNext(root) - elif root.right: - root.right.next = self.findNext(root) - - self.connect(root.right) - self.connect(root.left) - - return root - - def findNext(self, node): - nxt = node.next - while nxt: - if nxt.left: - return nxt.left - if nxt.right: - return nxt.right - nxt = nxt.next - return None \ No newline at end of file diff --git "a/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" index 2af6b9f..1d151bc 100644 --- "a/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" +++ "b/1170.\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241/1170-\346\257\224\350\276\203\345\255\227\347\254\246\344\270\262\346\234\200\345\260\217\345\255\227\346\257\215\345\207\272\347\216\260\351\242\221\346\254\241.py" @@ -5,18 +5,24 @@ def numSmallerByFrequency(self, queries, words): :type words: List[str] :rtype: List[int] """ - def f(word): - return word.count(min(word)) - f_words = sorted([f(word) for word in words]) + def func(word): + for char in "abcdefghijklmnopqrstuvwxyz": + if char in word: + return word.count(char) + return 0 - res = [] - # print f_words - for q in queries: - cnt = f(q) - # print(bisect.bisect(f_words, cnt)) - res.append(len(f_words) - bisect.bisect(f_words, cnt)) - - return res - + def func2(word): + record = collections.Counter(word) + return record[min(record.keys())] + + + words_count = sorted(map(func2, words)) + queries_count = map(func2, queries) + # print words_count, queries_count + ans = [] + for query in queries_count: + index = bisect.bisect(words_count, query) #bisect可以迅速找出有index个数 <= query + ans.append(len(words_count) - index)# 减法找有多少个数比query大 + return ans \ No newline at end of file diff --git "a/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" "b/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" deleted file mode 100644 index e816f7c..0000000 --- "a/1209.\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II/1209-\345\210\240\351\231\244\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\346\211\200\346\234\211\347\233\270\351\202\273\351\207\215\345\244\215\351\241\271II.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def removeDuplicates(self, s, k): - """ - :type s: str - :type k: int - :rtype: str - """ - stack = [] - for ch in s: - if not stack: - stack.append([ch, 1]) - else: - if stack[-1][0] == ch: - stack[-1][1] += 1 - if stack[-1][1] % k == 0: - stack.pop() - else: - stack.append([ch, 1]) - - return "".join(ch * freq for ch, freq in stack) \ No newline at end of file diff --git "a/121.\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/121-\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/121.\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/121-\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" deleted file mode 100644 index 325ada7..0000000 --- "a/121.\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/121-\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" +++ /dev/null @@ -1,12 +0,0 @@ -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/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" "b/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" deleted file mode 100644 index 5790cac..0000000 --- "a/1219.\351\273\204\351\207\221\347\237\277\345\267\245/1219-\351\273\204\351\207\221\347\237\277\345\267\245.py" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def getMaximumGold(self, grid): - """ - :type grid: List[List[int]] - :rtype: int - """ - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - m, n = len(grid), len(grid[0]) - visited = set() - self.res = 0 - - def dfs(x0, y0, tmp): - self.res = max(self.res, tmp) - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x < m and 0 <= y < n and grid[x][y] > 0: - value = grid[x][y] - grid[x][y] = -1 - dfs(x, y, tmp + value) - grid[x][y] = value - - for i in range(m): - for j in range(n): - value = grid[i][j] - grid[i][j] = -1 - dfs(i, j, value) - grid[i][j] = value - return self.res \ No newline at end of file diff --git "a/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" index f6c8cf3..d928eef 100644 --- "a/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" +++ "b/1230.\346\212\233\346\216\267\347\241\254\345\270\201/1230-\346\212\233\346\216\267\347\241\254\345\270\201.py" @@ -16,7 +16,7 @@ def probabilityOfHeads(self, prob, target): return dp[target] # dp = [[0 for _ in range(len(prob) + 1)] for _ in range(len(prob))] - # # dp[i][j] 琛ㄧず鍓峣涓‖甯侀噷锛屾湁j涓‖甯佹闈㈡湞涓婄殑姒傜巼 + # # dp[i][j] 表示前i个硬币里,有j个硬币正面朝上的概率 # dp[0][1] = prob[0] # dp[0][0] = 1 - prob[0] # for i, p in enumerate(prob): diff --git "a/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" "b/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" deleted file mode 100644 index ac5138b..0000000 --- "a/125.\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262/125-\351\252\214\350\257\201\345\233\236\346\226\207\344\270\262.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def isPalindrome(self, s): - """ - :type s: str - :rtype: bool - """ - res = "" - for ch in s: - if ch.isalpha() or ch.isdigit(): - res += ch.lower() - # print res - return res == res[::-1] \ No newline at end of file diff --git "a/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" "b/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" deleted file mode 100644 index cf75510..0000000 --- "a/1253.\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265/1253-\351\207\215\346\236\2042\350\241\214\344\272\214\350\277\233\345\210\266\347\237\251\351\230\265.py" +++ /dev/null @@ -1,27 +0,0 @@ -class Solution(object): - def reconstructMatrix(self, upper, lower, colsum): - """ - :type upper: int - :type lower: int - :type colsum: List[int] - :rtype: List[List[int]] - """ - b = [[0 for _ in range(len(colsum))] for _ in range(2)] - - for i, cs in enumerate(colsum): - if cs == 2: - b[0][i] = 1 - b[1][i] = 1 - upper -= 1 - lower -= 1 - for i, cs in enumerate(colsum): - if cs == 1: - if lower > upper: - b[1][i] = 1 - lower -= 1 - else: - b[0][i] = 1 - upper -= 1 - if upper != 0 or lower != 0: - return [] - return b \ No newline at end of file diff --git "a/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" index e9f0305..32f2f05 100644 --- "a/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" +++ "b/1255.\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210/1255-\345\276\227\345\210\206\346\234\200\351\253\230\347\232\204\345\215\225\350\257\215\351\233\206\345\220\210.py" @@ -9,25 +9,25 @@ def maxScoreWords(self, words, letters, score): from collections import defaultdict, Counter dic = dict() letter_dic = defaultdict(int) - for i, val in enumerate(score):#鏋勫缓涓涓瓧鍏 - dic[chr(ord("a") + i)] = val #key鏄 瀛楁瘝锛寁al鏄瓧姣嶅搴旂殑鍒嗘暟 + for i, val in enumerate(score):#构建一个字典 + dic[chr(ord("a") + i)] = val #key是 字母,val是字母对应的分数 - letter_dic = Counter(letters)#鏋勫缓鍙︿竴涓瓧鍏革紝 key鏄瓧姣嶏紝 val鏄瘡娆″瓧姣嶅墿浣欑殑涓暟 + letter_dic = Counter(letters)#构建另一个字典, key是字母, val是每次字母剩余的个数 s = set(letters) v_words = [] - for word in words:#鍒犳帀鎵鏈夋牴鏈笉鍙兘琚瀯鎴愮殑鍗曡瘝 + for word in words:#删掉所有根本不可能被构成的单词 flag = 0 for char in word: if char not in s: flag = 1 - if flag: # 濡傛灉涓涓崟璇嶉噷瀛樺湪鏌愪釜鍦╨etters閲屾壘涓嶅埌鐨勫瓧姣嶏紝鍒欐棤闇鑰冭檻杩欎釜鍗曡瘝 + if flag: # 如果一个单词里存在某个在letters里找不到的字母,则无需考虑这个单词 continue v_words.append(word) self.res = 0 def helper(word, letter_dic): - # return True 濡傛灉word鑳界敤letter_dic閲岀殑letter鏋勬垚锛屽惁鍒欒繑鍥濬alse + # return True 如果word能用letter_dic里的letter构成,否则返回False dicc = collections.Counter(word) for key in dicc: if dicc[key] > letter_dic[key]: @@ -39,12 +39,12 @@ def dfs(start, tmp): if start >= len(v_words): return - for i in range(start, len(v_words)):#浠巗tart寮濮嬫壘锛岄伩鍏嶉噸澶 - if helper(v_words[i], letter_dic):#濡傛灉褰撳墠鍗曡瘝鍙互琚瀯鎴 - for char in v_words[i]: #鏋勬垚瀹冿紝鏇存柊瀛楀吀 + for i in range(start, len(v_words)):#从start开始找,避免重复 + if helper(v_words[i], letter_dic):#如果当前单词可以被构成 + for char in v_words[i]: #构成它,更新字典 letter_dic[char] -= 1 - dfs(i + 1, tmp + sum([dic[char] for char in v_words[i]])) #dfs涓嬩竴灞 - for char in v_words[i]: #鍥炴函锛屽鍘熸墍鏈夌姸鎬 + dfs(i + 1, tmp + sum([dic[char] for char in v_words[i]])) #dfs下一层 + for char in v_words[i]: #回溯,复原所有状态 letter_dic[char] += 1 dfs(0, 0) return self.res \ No newline at end of file diff --git "a/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" "b/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" deleted file mode 100644 index 967b748..0000000 --- "a/1256.\345\212\240\345\257\206\346\225\260\345\255\227/1256-\345\212\240\345\257\206\346\225\260\345\255\227.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def encode(self, num): - """ - :type num: int - :rtype: str - """ - return bin(num + 1)[3:] \ No newline at end of file diff --git "a/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" "b/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" deleted file mode 100644 index 87162ed..0000000 --- "a/1257.\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237/1257-\346\234\200\345\260\217\345\205\254\345\205\261\345\214\272\345\237\237.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def findSmallestRegion(self, regions, region1, region2): - """ - :type regions: List[List[str]] - :type region1: str - :type region2: str - :rtype: str - """ - from collections import defaultdict - dic = dict() - for reg in regions: - parent = reg[0] - for child in reg[1:]: # 閬嶅巻鎵鏈夌殑瀛愬尯鍩 - dic[child] = (parent) - - ancestors_1 = set() - while region1 in dic: - ancestors_1.add(region1) - region1 = dic[region1] - - while region2 not in ancestors_1 and region2 in dic: - region2 = dic[region2] - - return region2 \ No newline at end of file diff --git "a/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" "b/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" deleted file mode 100644 index a164966..0000000 --- "a/1258.\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220/1258-\350\277\221\344\271\211\350\257\215\345\217\245\345\255\220.py" +++ /dev/null @@ -1,56 +0,0 @@ -class Solution(object): - def generateSentences(self, synonyms, text): - """ - :type synonyms: List[List[str]] - :type text: str - :rtype: List[str] - """ - from collections import defaultdict - dic = defaultdict(set) - vocab = set() - text = text.split() - - for w1, w2 in synonyms: - dic[w1].add(w2) - dic[w2].add(w1) - vocab.add(w1) - vocab.add(w2) - - self.res = [] - - def generateList(word, res, visited): - res.add(word) - for w in dic[word]: - if w not in visited: - visited.add(w) - generateList(w, res, visited) - - return res - - - def dfs(start, tmp): - if start >= len(text): - self.res.append(tmp) - return - - word = text[start] - if word in vocab: - l = set() - visited = set() - generateList(word, l, visited) - for w in l: - if start > 0: - dfs(start + 1, tmp + " " + w) - else: - dfs(start + 1, w) - else: - if start > 0: - dfs(start + 1, tmp + " " + word) - else: - dfs(start + 1, word) - dfs(0, "") - self.res.sort() - return self.res - - - \ No newline at end of file diff --git "a/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" "b/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" deleted file mode 100644 index fcd69b1..0000000 --- "a/1259.\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213/1259-\344\270\215\347\233\270\344\272\244\347\232\204\346\217\241\346\211\213.py" +++ /dev/null @@ -1,10 +0,0 @@ -from math import factorial as fac -class Solution(object): - def numberOfWays(self, num_people): - """ - :type num_people: int - :rtype: int - """ - def catalan(n): - return fac(2*n) // (fac(n+1) * fac(n)) - return catalan(num_people // 2) % ( 10 ** 9 + 7) \ No newline at end of file diff --git "a/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" "b/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" deleted file mode 100644 index 8b088ec..0000000 --- "a/1260.\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273/1260-\344\272\214\347\273\264\347\275\221\346\240\274\350\277\201\347\247\273.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def shiftGrid(self, grid, k): - """ - :type grid: List[List[int]] - :type k: int - :rtype: List[List[int]] - """ - m, n = len(grid), len(grid[0]) - - size = m * n - k = k % size - l = [grid[i][j] for i in range(m) for j in range(n)] - - l = l[-k:] + l[:-k] - - for i in range(m): - for j in range(n): - grid[i][j] = l[i * n + j] - return grid \ 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" deleted file mode 100644 index c031724..0000000 --- "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" +++ /dev/null @@ -1,40 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode(object): -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class FindElements(object): - - def __init__(self, root): - """ - :type root: 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 - dfs(node.left) - if node.right: - node.right.val = 2 * node.val + 2 - dfs(node.right) - dfs(root) - - - - def find(self, target): - """ - :type target: int - :rtype: 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/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" deleted file mode 100644 index 9050833..0000000 --- "a/1262.\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214/1262-\345\217\257\350\242\253\344\270\211\346\225\264\351\231\244\347\232\204\346\234\200\345\244\247\345\222\214.py" +++ /dev/null @@ -1,42 +0,0 @@ -class Solution(object): - def maxSumDivThree(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - from collections import defaultdict - dic = defaultdict(list) - - nums.sort() - for num in nums: - dic[num % 3].append(num) - - - s = sum(nums) - if s % 3 == 0: - return s - - if s % 3 == 2: - t1, t2 = float("inf"),float("inf") - if 2 in dic: #鍙互鍒犻櫎涓涓ā涓 2 鐨勬渶灏忔暟 - t1 = dic[2][0] - - if len(dic[1]) >= 2: # 涔熷彲浠ュ垹闄や袱涓ā涓 1 鐨勬渶灏忔暟 - t2 = dic[1][0] + dic[1][1] - - if t1 > t2:# 閫夋嫨涓ょ鍙兘涓緝灏忕殑鍊煎垹闄 - return s - t2 - - return s - t1 - - if s % 3 == 1: - t1, t2 = float("inf"), float("inf") - if 1 in dic: # 鍙互鍒犻櫎涓涓ā涓 1 鐨勬渶灏忔暟 - t1 = dic[1][0] - if len(dic[2]) >= 2: # 涔熷彲浠ュ垹闄や袱涓ā涓 2 鐨勬渶灏忔暟 - t2 = dic[2][0] + dic[2][1] - - if t1 > t2: # 閫夋嫨涓ょ鍙兘涓緝灏忕殑鍊煎垹闄 - return s - t2 - - return s - t1 \ 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" deleted file mode 100644 index bd98f36..0000000 --- "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" +++ /dev/null @@ -1,32 +0,0 @@ -# """ -# This is the ImmutableListNode's API interface. -# You should not implement it, or speculate about its implementation. -# """ -# class ImmutableListNode(object): -# def printValue(self): # print the value of this node. -# . """ -# :rtype None -# """ -# -# def getNext(self): # return the next node. -# . """ -# :rtype ImmutableListNode -# """ - -class Solution(object): - def printLinkedListInReverse(self, head): - """ - :type head: ImmutableListNode - :rtype: None - """ - if not head: - return - l = [] - p = head - while p: - l.append(p) - p = p.getNext() - - while l: - l.pop().printValue() - \ No newline at end of file diff --git "a/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" index 5f5014f..26dfeca 100644 --- "a/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" +++ "b/1275.\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205/1275-\346\211\276\345\207\272\344\272\225\345\255\227\346\243\213\347\232\204\350\216\267\350\203\234\350\200\205.py" @@ -43,4 +43,6 @@ def check(): tmp = check() if tmp != -1: return "A" if tmp == 0 else "B" - return "Draw" if len(moves) == 9 else "Pending" \ No newline at end of file + return "Draw" if len(moves) == 9 else "Pending" + + \ No newline at end of file diff --git "a/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" "b/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" deleted file mode 100644 index d78a8cc..0000000 --- "a/1281.\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256/1281-\346\225\264\346\225\260\347\232\204\345\220\204\344\275\215\347\247\257\345\222\214\344\271\213\345\267\256.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def subtractProductAndSum(self, n): - """ - :type n: int - :rtype: int - """ - product, s = 1, 0 - - while n: - n, digit = divmod(n, 10) - product *= digit - s += digit - return product - s \ 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" deleted file mode 100644 index 7b41f8e..0000000 --- "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" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def groupThePeople(self, groupSizes): - """ - :type groupSizes: List[int] - :rtype: List[List[int]] - """ - from collections import defaultdict - dic = defaultdict(list) - - res = [] - for i, x in enumerate(groupSizes): - if x not in dic or len(dic[x]) < x: - dic[x].append(i) - if len(dic[x]) == x: - res.append(dic[x]) - dic[x] = [] - - return res \ No newline at end of file diff --git "a/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" "b/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" deleted file mode 100644 index f98756d..0000000 --- "a/1283.\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260/1283-\344\275\277\347\273\223\346\236\234\344\270\215\350\266\205\350\277\207\351\230\210\345\200\274\347\232\204\346\234\200\345\260\217\351\231\244\346\225\260.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def smallestDivisor(self, nums, threshold): - """ - :type nums: List[int] - :type threshold: int - :rtype: int - """ - left, right = 1, max(nums) - - while left <= right: - mid = (left + right) // 2 - - tmp = 0 - for num in nums: - tmp += math.ceil(num * 1.0 / mid) - if tmp > threshold: - break - - if tmp > threshold: - left = mid + 1 - else: - right = mid - 1 - - return left diff --git "a/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" "b/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" deleted file mode 100644 index f0461fb..0000000 --- "a/1284.\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260/1284-\350\275\254\345\214\226\344\270\272\345\205\250\351\233\266\347\237\251\351\230\265\347\232\204\346\234\200\345\260\221\345\217\215\350\275\254\346\254\241\346\225\260.py" +++ /dev/null @@ -1,71 +0,0 @@ -import numpy -class Solution(object): - def minFlips(self, mat): - """ - :type mat: List[List[int]] - :rtype: int - """ - if not mat or not mat[0]: - return 0 - - m, n = len(mat), len(mat[0]) - def check(matrix): - - return sum(sum(matrix, [])) == 0 - - def encode(matrix): - s = "" - for row in matrix: - for ch in row: - s += str(ch) - return s - - def decode(s): - mat = [] - for ch in s: - mat.append(int(ch)) - - res = [[0 for _ in range(n)] for _ in range(m)] - for i in range(m): - for j in range(n): - res[i][j] = mat[i * n + j] - return res - - def convert(mat, i, j, m, n): - for k in range(5): - x, y = i + dx[k], j + dy[k] - if 0 <= x < m and 0 <= y < n: - mat[x][y] ^= 1 - return mat - - res = -1 - from collections import deque - queue = deque([encode(mat)]) - - dx = [1, 0, 0, -1, 0] - dy = [0, 1, -1, 0, 0] - visited = set() - visited.add(encode(mat)) - while queue: - res += 1 - for _ in range(len(queue)): - encoded_cur = queue.popleft() - cur = decode(encoded_cur) - - if check(cur): - return res - - for i in range(m): - for j in range(n): - mat = convert(cur, i, j, m, n) - encoded_mat = encode(mat) - if encoded_mat not in visited: - queue.append(encoded_mat) - visited.add(encoded_mat) - - mat = convert(cur, i, j, m, n) - - return -1 - - - diff --git "a/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" "b/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" deleted file mode 100644 index eb6c348..0000000 --- "a/1285.\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227/1285-\346\211\276\345\210\260\350\277\236\347\273\255\345\214\272\351\227\264\347\232\204\345\274\200\345\247\213\345\222\214\347\273\223\346\235\237\346\225\260\345\255\227.sql" +++ /dev/null @@ -1,6 +0,0 @@ -# Write your MySQL query statement below -select a.log_id as START_ID, b.log_id as END_ID -from (select log_id from Logs where log_id-1 not in (select * from logs)) as a, - (select log_id from Logs where log_id+1 not in (select * from logs)) as b -where b.log_id>=a.log_id -group by a.log_id \ No newline at end of file diff --git "a/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" "b/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" deleted file mode 100644 index adbe100..0000000 --- "a/1286.\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250/1286-\345\255\227\346\257\215\347\273\204\345\220\210\350\277\255\344\273\243\345\231\250.py" +++ /dev/null @@ -1,30 +0,0 @@ -class CombinationIterator(object): - - def __init__(self, characters, combinationLength): - """ - :type characters: str - :type combinationLength: int - """ - # from itertools import permututations - self.s = list(itertools.combinations(characters, combinationLength)) - self.index = 0 - - def next(self): - """ - :rtype: str - """ - self.index += 1 - return "".join(self.s[self.index - 1]) - - def hasNext(self): - """ - :rtype: bool - """ - return self.index < len(self.s) - - - -# Your CombinationIterator object will be instantiated and called as such: -# obj = CombinationIterator(characters, combinationLength) -# param_1 = obj.next() -# param_2 = obj.hasNext() \ No newline at end of file diff --git "a/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" "b/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" deleted file mode 100644 index b899810..0000000 --- "a/1287.\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240/1287-\346\234\211\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\20725%\347\232\204\345\205\203\347\264\240.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def findSpecialInteger(self, arr): - """ - :type arr: List[int] - :rtype: int - """ - cnt = 1 - for i, num in enumerate(arr): - if i: - if num == arr[i - 1]: - cnt += 1 - else: - cnt = 1 - if cnt > len(arr) / 4: - return num - \ No newline at end of file diff --git "a/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" "b/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" deleted file mode 100644 index 2e14aeb..0000000 --- "a/1288.\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264/1288-\345\210\240\351\231\244\350\242\253\350\246\206\347\233\226\345\214\272\351\227\264.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def removeCoveredIntervals(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: int - """ - intervals = sorted(intervals, key = lambda x:(x[0], x[1])) - - start, end = intervals[0][0], intervals[0][1] - - n = len(intervals) - max_end = intervals[0][1] - for s, e in intervals: - if max_end >= e: - n -= 1 - else: - max_end = e - - return n + 1 \ No newline at end of file diff --git "a/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" "b/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" deleted file mode 100644 index 5e15a73..0000000 --- "a/1289.\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II/1289-\344\270\213\351\231\215\350\267\257\345\276\204\346\234\200\345\260\217\345\222\214II.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def minFallingPathSum(self, arr): - """ - :type arr: List[List[int]] - :rtype: int - """ - from heapq import * - if not arr or not arr[0]: - return 0 - - m, n = len(arr), len(arr[0]) - - for i in range(1, m): - max_heap = [] - for j in range(n): - if len(max_heap) < 2: - heappush(max_heap, -arr[i - 1][j]) - else: - heappush(max_heap, -arr[i - 1][j]) - heappop(max_heap) - # print max_heap - for j in range(n): - arr[i][j] -= max_heap[1] if -max_heap[1] != arr[i - 1][j] else max_heap[0] - return min(arr[-1]) \ 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" deleted file mode 100644 index 89fd7bb..0000000 --- "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" +++ /dev/null @@ -1,17 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def getDecimalValue(self, head): - """ - :type head: ListNode - :rtype: int - """ - res = 0 - while head: - res = res * 2 + head.val - head = head.next - return res \ No newline at end of file diff --git "a/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" "b/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" deleted file mode 100644 index 09dceb9..0000000 --- "a/1291.\351\241\272\346\254\241\346\225\260/1291-\351\241\272\346\254\241\346\225\260.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def sequentialDigits(self, low, high): - """ - :type low: int - :type high: int - :rtype: List[int] - """ - nums = [12, 23, 34, 45, 56, 67, 78, 89, - 123, 234, 345, 456, 567, 678, 789, - 1234, 2345, 3456,4567, 5678, 6789, - 12345, 23456, 34567, 45678, 56789, - 123456, 234567, 345678, 456789, - 1234567, 2345678, 3456789, - 12345678, 23456789, - 123456789] - res = [] - - for num in nums: - if low <= num <= high: - res.append(num) - - return res \ No newline at end of file diff --git "a/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" "b/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" deleted file mode 100644 index 5e87082..0000000 --- "a/1295.\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227/1295-\347\273\237\350\256\241\344\275\215\346\225\260\344\270\272\345\201\266\346\225\260\347\232\204\346\225\260\345\255\227.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def findNumbers(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - res = 0 - for num in nums: - if len(str(num)) % 2 == 0: - res += 1 - return res \ No newline at end of file diff --git "a/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" "b/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" deleted file mode 100644 index 986dd8c..0000000 --- "a/1296.\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210/1296-\345\210\222\345\210\206\346\225\260\347\273\204\344\270\272\350\277\236\347\273\255\346\225\260\345\255\227\347\232\204\351\233\206\345\220\210.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def isPossibleDivide(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: bool - """ - from collections import Counter, deque - dic = Counter(nums) - nums = deque(sorted(list(set(nums)))) - - res = [] - while nums: - num = nums[0] - for i in range(k): - target = num + i - if target not in dic: - return False - dic[target] -= 1 - if dic[target] == 0: - nums.popleft() - return True \ No newline at end of file diff --git "a/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" "b/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" deleted file mode 100644 index 7c2e30e..0000000 --- "a/1297.\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260/1297-\345\255\220\344\270\262\347\232\204\346\234\200\345\244\247\345\207\272\347\216\260\346\254\241\346\225\260.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def maxFreq(self, s, maxLetters, minSize, maxSize): - """ - :type s: str - :type maxLetters: int - :type minSize: int - :type maxSize: int - :rtype: int - """ - from collections import defaultdict - - record = defaultdict(int) - - res = 0 - for i in range(len(s) - minSize + 1): - substring = s[i:i+minSize] - if len(set(substring)) <= maxLetters: - record[substring] += 1 - res = max(res, record[substring]) - - return res \ No newline at end of file diff --git "a/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" "b/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" deleted file mode 100644 index b4fc042..0000000 --- "a/1298.\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260/1298-\344\275\240\350\203\275\344\273\216\347\233\222\345\255\220\351\207\214\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\263\226\346\236\234\346\225\260.py" +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes): - """ - :type status: List[int] - :type candies: List[int] - :type keys: List[List[int]] - :type containedBoxes: List[List[int]] - :type initialBoxes: List[int] - :rtype: int - """ - if not initialBoxes: - return 0 - - # boxes = set(initialBoxes) - owned_keys = set() - from collections import deque - queue = deque(initialBoxes) - res = 0 - record = dict() - while queue: - cur = queue.popleft() - # print cur - if status[cur] or cur in owned_keys: # This box could be opened - for key in keys[cur]: - owned_keys.add(key) - for box in containedBoxes[cur]: - queue.append(box) - res += candies[cur] - else: - if cur in record and record[cur] == owned_keys: - break - queue.append(cur) - record[cur] = owned_keys - return res \ No newline at end of file diff --git "a/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" "b/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" deleted file mode 100644 index af2248b..0000000 --- "a/1299.\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240/1299-\345\260\206\346\257\217\344\270\252\345\205\203\347\264\240\346\233\277\346\215\242\344\270\272\345\217\263\344\276\247\346\234\200\345\244\247\345\205\203\347\264\240.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def replaceElements(self, arr): - """ - :type arr: List[int] - :rtype: List[int] - """ - right_max = -1 - for i in range(len(arr) - 1, -1, -1): - tmp = arr[i] - arr[i] = right_max - right_max = max(right_max, tmp) - return arr \ No newline at end of file diff --git "a/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" "b/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" deleted file mode 100644 index d2eed65..0000000 --- "a/1300.\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214/1300-\350\275\254\345\217\230\346\225\260\347\273\204\345\220\216\346\234\200\346\216\245\350\277\221\347\233\256\346\240\207\345\200\274\347\232\204\346\225\260\347\273\204\345\222\214.py" +++ /dev/null @@ -1,39 +0,0 @@ -class Solution(object): - def findBestValue(self, arr, target): - """ - :type arr: List[int] - :type target: int - :rtype: int - """ - left, right = 0, max(arr) - sub, ans = float("inf"), float("inf") - - while left <= right: - mid = (left + right) // 2 # mid 涓烘湰娆$寽娴嬬殑绛旀 - - tmp = 0 # tmp 鏄湰娆$寽娴嬫柊鏁扮粍涔嬪拰 - for num in arr: - if num > mid: - tmp += mid - else: - tmp += num - - cur_sub = abs(tmp - target) #褰撳墠宸殑鏈灏忓 - - if cur_sub < sub: # 濡傛灉鏈夋洿灏忕殑绛旀 - sub = cur_sub - ans = mid - elif cur_sub == sub: - ans = min(ans, mid) - - if tmp > target: - right = mid - 1 - elif tmp < target: - left = mid + 1 - elif tmp == target: - return mid - - return ans - - - \ No newline at end of file diff --git "a/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" "b/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" deleted file mode 100644 index 0e1be3e..0000000 --- "a/1301.\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256/1301-\346\234\200\345\244\247\345\276\227\345\210\206\347\232\204\350\267\257\345\276\204\346\225\260\347\233\256.py" +++ /dev/null @@ -1,30 +0,0 @@ -class Solution(object): - def pathsWithMaxScore(self, board): - """ - :type board: List[str] - :rtype: List[int] - """ - n = len(board) - MOD = 10 ** 9 + 7 - - dp = [[[float("-inf"), 0] for _ in range(n + 1)] for _ in range(n + 1)] - dp[n - 1][n - 1] = [0, 1] - for i in range(n - 1, -1, -1): - for j in range(n - 1, -1, -1): - if board[i][j] not in "XS": - - for dx, dy in [[0, 1], [1, 0], [1, 1]]: - if dp[i][j][0] < dp[i + dx][j + dy][0]: - dp[i][j] = [dp[i + dx][j + dy][0], 0] - - if dp[i][j][0] == dp[i + dx][j + dy][0]: - dp[i][j][1] += dp[i + dx][j + dy][1] - - dp[i][j][0] += int(board[i][j]) if board[i][j] != "E" else 0 - - return [dp[0][0][0] if dp[0][0][1] else 0, dp[0][0][1] % MOD] - - - - - \ 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" deleted file mode 100644 index e98e035..0000000 --- "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" +++ /dev/null @@ -1,27 +0,0 @@ -# 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 deepestLeavesSum(self, root): - """ - :type root: TreeNode - :rtype: int - """ - from collections import deque - if not root: - return 0 - queue = deque([root]) - while queue: - res = [] - for _ in range(len(queue)): - node = queue.popleft() - res.append(node.val) - if node.left: - queue += [node.left] - if node.right: - queue += [node.right] - return sum(res) \ No newline at end of file diff --git "a/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" "b/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" deleted file mode 100644 index 8f816d2..0000000 --- "a/1304.\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260/1304-\345\222\214\344\270\272\351\233\266\347\232\204N\344\270\252\345\224\257\344\270\200\346\225\264\346\225\260.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def sumZero(self, n): - """ - :type n: int - :rtype: List[int] - """ - res = [] - - for i in range(1, n // 2 + 1): - res.append(i) - res.append(-i) - if n % 2: - res.append(0) - return res \ No newline at end of file diff --git "a/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" "b/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" deleted file mode 100644 index ebc4858..0000000 --- "a/1305.\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240/1305-\344\270\244\346\243\265\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\211\200\346\234\211\345\205\203\347\264\240.py" +++ /dev/null @@ -1,24 +0,0 @@ -# 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 getAllElements(self, root1, root2): - """ - :type root1: TreeNode - :type root2: TreeNode - :rtype: List[int] - """ - - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - - l1 = inorder(root1) - l2 = inorder(root2) - - return sorted(l1 + l2) \ No newline at end of file diff --git "a/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" "b/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" deleted file mode 100644 index e33687f..0000000 --- "a/1306.\350\267\263\350\267\203\346\270\270\346\210\217III/1306-\350\267\263\350\267\203\346\270\270\346\210\217III.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def canReach(self, arr, start): - """ - :type arr: List[int] - :type start: int - :rtype: bool - """ - from collections import deque - queue = deque([start]) - visited = set([start]) - while queue: - cur = queue.popleft() - - if arr[cur] == 0: - return True - - for i in [cur + arr[cur], cur - arr[cur]]: - if 0 <= i < len(arr) and i not in visited: - visited.add(i) - queue.append(i) - return False \ No newline at end of file diff --git "a/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" "b/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" deleted file mode 100644 index 7b5faa6..0000000 --- "a/1309.\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204/1309-\350\247\243\347\240\201\345\255\227\346\257\215\345\210\260\346\225\264\346\225\260\346\230\240\345\260\204.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def freqAlphabets(self, s): - """ - :type s: str - :rtype: str - """ - res, i = "", 0 - while i < len(s): - if i + 2 < len(s) and s[i + 2] == "#": - res += chr(ord("a") + int(s[i:i + 2]) - 1) - i += 3 - else: - res += chr(ord("a") + int(s[i]) - 1) - i += 1 - return res \ No newline at end of file diff --git "a/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" "b/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" deleted file mode 100644 index fadcc8c..0000000 --- "a/131.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262/131-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def partition(self, s): - """ - :type s: str - :rtype: List[List[str]] - """ - - res = [] - - def dfs(start, tmp): - - if start >= len(s): - # print tmp - res.append(tmp[:]) - return - - for i in range(start, len(s)): - substring = s[start:i + 1] - if substring == substring[::-1]: - tmp.append(substring) - dfs(i + 1, tmp) - tmp.pop() - dfs(0, []) - return res \ No newline at end of file diff --git "a/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" "b/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" deleted file mode 100644 index bffcb3b..0000000 --- "a/1310.\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242/1310-\345\255\220\346\225\260\347\273\204\345\274\202\346\210\226\346\237\245\350\257\242.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def xorQueries(self, arr, queries): - """ - :type arr: List[int] - :type queries: List[List[int]] - :rtype: List[int] - """ - - prefix = [0 for _ in [0] + arr] - for i in range(len(arr)): - prefix[i + 1] = prefix[i] ^ arr[i] - - # print prefix - res = [] - for l, r in queries: - res.append(prefix[l] ^ prefix[r + 1]) - - return res \ No newline at end of file diff --git "a/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" "b/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" deleted file mode 100644 index 094b33b..0000000 --- "a/1311.\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221/1311-\350\216\267\345\217\226\344\275\240\345\245\275\345\217\213\345\267\262\350\247\202\347\234\213\347\232\204\350\247\206\351\242\221.py" +++ /dev/null @@ -1,34 +0,0 @@ -class Solution(object): - def watchedVideosByFriends(self, watchedVideos, friends, idd, level): - """ - :type watchedVideos: List[List[str]] - :type friends: List[List[int]] - :type id: int - :type level: int - :rtype: List[str] - """ - from collections import deque,defaultdict - # 1. find all k-level friends by BFS - queue = deque([idd]) - visited = set([idd]) - for l in range(level): - friendset = set() - for _ in range(len(queue)): - cur = queue.popleft() - - for fri in friends[cur]: - if fri not in visited: - visited.add(fri) - queue.append(fri) - - # 2. find watched videos of all k-level friends - videos = defaultdict(int) - for friend in queue: - for video in watchedVideos[friend]: - videos[video] += 1 - - # 3. count the frequency - res = [[key, val] for key, val in videos.items()] - res = sorted(res, key = lambda x:(x[1], x[0])) - - return [x[0] for x in res] \ No newline at end of file diff --git "a/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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" deleted file mode 100644 index 99d3117..0000000 --- "a/1312.\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\344\270\262\347\232\204\346\234\200\345\260\221\346\217\222\345\205\245\346\254\241\346\225\260/1312-\350\256\251\345\255\227\347\254\246\344\270\262\346\210\220\344\270\272\345\233\236\346\226\207\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" +++ /dev/null @@ -1,23 +0,0 @@ -class Solution(object): - def minInsertions(self, s): - """ - :type s: str - :rtype: int - """ - return len(s) - self.longestPalindromeSubseq(s) - def longestPalindromeSubseq(self, s): - """ - :type s: str - :rtype: int - """ - n = len(s) - dp = [[0] * n for _ in range(n)] - - for i in range(n): - dp[i][i] = 1 - for j in range(i - 1, -1, -1): - if s[i] == s[j]: - dp[i][j] = dp[i - 1][j + 1] + 2 - else: - dp[i][j] = max(dp[i][j + 1], dp[i - 1][j]) - return dp[n - 1][0] \ No newline at end of file diff --git "a/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" "b/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" deleted file mode 100644 index d380b2c..0000000 --- "a/1313.\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250/1313-\350\247\243\345\216\213\347\274\251\347\274\226\347\240\201\345\210\227\350\241\250.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def decompressRLElist(self, nums): - """ - :type nums: List[int] - :rtype: List[int] - """ - res = [] - for i in range(0, len(nums), 2): - res += nums[i] * [nums[i + 1]] - return res \ 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" deleted file mode 100644 index 8a80225..0000000 --- "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" +++ /dev/null @@ -1,24 +0,0 @@ -# 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 sumEvenGrandparent(self, root): - """ - :type root: TreeNode - :rtype: int - """ - self.res = 0 - def dfs(node, parent, grand): - if not node: - return - if grand: - self.res += node.val - - dfs(node.left, node.val % 2 == 0, parent) - dfs(node.right, node.val % 2 == 0, parent) - dfs(root, False, False) - return self.res \ No newline at end of file diff --git "a/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" "b/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" deleted file mode 100644 index bea11e1..0000000 --- "a/1317.\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214/1317-\345\260\206\346\225\264\346\225\260\350\275\254\346\215\242\344\270\272\344\270\244\344\270\252\346\227\240\351\233\266\346\225\264\346\225\260\347\232\204\345\222\214.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def getNoZeroIntegers(self, n): - """ - :type n: int - :rtype: List[int] - """ - - for i in range(1, n): - tmp = n - i - if "0" not in str(i) and "0" not in str(tmp): - return [i, tmp] \ No newline at end of file diff --git "a/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" "b/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" deleted file mode 100644 index 2dd7a1b..0000000 --- "a/132.\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II/132-\345\210\206\345\211\262\345\233\236\346\226\207\344\270\262II.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def minCut(self, s): - """ - :type s: str - :rtype: int - """ - # dp[i][j] - dp = [len(s) for _ in range(len(s) + 1)] - dp[0] = -1 - for i in range(len(s)): - for j in range(i + 1): - if s[j:i + 1] == s[j:i + 1][::-1]: - dp[i + 1] = min(dp[j] + 1, dp[i + 1]) - # print dp - return dp[-1] \ No newline at end of file diff --git "a/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" "b/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" deleted file mode 100644 index 936a69b..0000000 --- "a/133.\345\205\213\351\232\206\345\233\276/133-\345\205\213\351\232\206\345\233\276.py" +++ /dev/null @@ -1,34 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val, neighbors): - self.val = val - self.neighbors = neighbors -""" -class Solution(object): - def cloneGraph(self, node): - """ - :type node: Node - :rtype: Node - """ - from collections import defaultdict, deque - # neibors = defaultdict(list) # key is the original nodes, value is its neibors - mapping = dict() # key is the original node, value is its copy - - queue = deque([node]) - visited = set() - visited.add(node) - while queue: - cur = queue.popleft() - visited.add(cur) - - copy = Node(cur.val, []) - mapping[cur] = copy - for neigh in cur.neighbors: - if neigh not in visited: - queue.append(neigh) - - for cur, copy in mapping.items(): - for each in cur.neighbors: - copy.neighbors.append(mapping[each]) - return mapping[node] \ No newline at end of file diff --git "a/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" "b/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" deleted file mode 100644 index 55bda80..0000000 --- "a/1356.\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217/1356-\346\240\271\346\215\256\346\225\260\345\255\227\344\272\214\350\277\233\345\210\266\344\270\2131\347\232\204\346\225\260\347\233\256\346\216\222\345\272\217.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def sortByBits(self, arr): - """ - :type arr: List[int] - :rtype: List[int] - """ - return sorted(arr, key = lambda x:(str(bin(x)).count("1"), x)) \ No newline at end of file diff --git "a/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" "b/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" deleted file mode 100644 index d0f49c9..0000000 --- "a/1365.\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227/1365-\346\234\211\345\244\232\345\260\221\345\260\217\344\272\216\345\275\223\345\211\215\346\225\260\345\255\227\347\232\204\346\225\260\345\255\227.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def smallerNumbersThanCurrent(self, nums): - """ - :type nums: List[int] - :rtype: List[int] - """ - res = [0 for _ in nums] - for i in range(len(nums)): - for j in range(len(nums)): - if nums[j] < nums[i]: - res[i] += 1 - - return res \ No newline at end of file diff --git "a/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" "b/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" deleted file mode 100644 index faabd50..0000000 --- "a/1370.\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262/1370-\344\270\212\345\215\207\344\270\213\351\231\215\345\255\227\347\254\246\344\270\262.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def sortString(self, s): - """ - :type s: str - :rtype: str - """ - from collections import Counter - dic = Counter(s) - res = "" - while len(res) < len(s): - for ch in "abcdefghijklmnopqrstuvwxyz": - if ch in dic and dic[ch]: - res += ch - dic[ch] -= 1 - for ch in "abcdefghijklmnopqrstuvwxyz"[::-1]: - if ch in dic and dic[ch]: - res += ch - dic[ch] -= 1 - - return res \ 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" deleted file mode 100644 index 32a3a01..0000000 --- "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" +++ /dev/null @@ -1,28 +0,0 @@ -# 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 getTargetCopy(self, original, cloned, target): - """ - :type original: TreeNode - :type cloned: TreeNode - :type target: TreeNode - :rtype: TreeNode - """ - self.res = None - def dfs(node1, node2): - if not node1: - return - if node1 == target: - self.res = node2 - return - - dfs(node1.left, node2.left) - dfs(node1.right, node2.right) - - dfs(original, cloned) - return self.res \ No newline at end of file diff --git "a/138.\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/138-\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/138.\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/138-\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" deleted file mode 100644 index 500145b..0000000 --- "a/138.\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/138-\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" +++ /dev/null @@ -1,26 +0,0 @@ -""" -# 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 - """ - cur = head - mapping = dict() - while cur: - mapping[cur] = Node(cur.val, None, None) - cur = cur.next - - for cur, copy in mapping.items(): - if cur.next: - copy.next = mapping[cur.next] - if cur.random: - copy.random = mapping[cur.random] - return mapping[head] if head else head \ No newline at end of file diff --git "a/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" "b/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" deleted file mode 100644 index 037aa40..0000000 --- "a/1385.\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274/1385-\344\270\244\344\270\252\346\225\260\347\273\204\351\227\264\347\232\204\350\267\235\347\246\273\345\200\274.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def findTheDistanceValue(self, arr1, arr2, d): - """ - :type arr1: List[int] - :type arr2: List[int] - :type d: int - :rtype: int - """ - res = 0 - - for num1 in arr1: - flag = 1 - for num2 in arr2: - if abs(num1 - num2) <= d: - flag = 0 - break - if flag: - res += 1 - - return res \ No newline at end of file diff --git "a/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" "b/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" deleted file mode 100644 index f223e8b..0000000 --- "a/1386.\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215/1386-\345\256\211\346\216\222\347\224\265\345\275\261\351\231\242\345\272\247\344\275\215.py" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def maxNumberOfFamilies(self, n, reservedSeats): - """ - :type n: int - :type reservedSeats: List[List[int]] - :rtype: int - """ - from collections import defaultdict - dic = defaultdict(set) - res = 0 - usedrow = set() - for row, seat in reservedSeats: - dic[row].add(seat) - usedrow.add(row) - - for row in usedrow: - twothree = 2 not in dic[row] and 3 not in dic[row] - fourfive = 4 not in dic[row] and 5 not in dic[row] - sixseven = 6 not in dic[row] and 7 not in dic[row] - eightnine = 8 not in dic[row] and 9 not in dic[row] - - if twothree and fourfive and sixseven and eightnine: - res += 2 - elif twothree and fourfive: - res += 1 - elif fourfive and sixseven: - res += 1 - elif sixseven and eightnine: - res += 1 - return res + (n - len(usedrow)) * 2 - \ No newline at end of file diff --git "a/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" "b/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" deleted file mode 100644 index ac2b840..0000000 --- "a/1387.\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217/1387-\345\260\206\346\225\264\346\225\260\346\214\211\346\235\203\351\207\215\346\216\222\345\272\217.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def getKth(self, lo, hi, k): - """ - :type lo: int - :type hi: int - :type k: int - :rtype: int - """ - dic = {} - dic[1] = 0 - def func(x): - if x in dic: - return dic[x] - if x % 2: - res = 1 + func(3 * x + 1) - else: - res = 1 + func(x / 2) - dic[x] = res - return res - - return sorted(range(lo, hi + 1), key = lambda x: (func(x), x))[k - 1] \ No newline at end of file diff --git "a/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" "b/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" deleted file mode 100644 index e843e45..0000000 --- "a/139.\345\215\225\350\257\215\346\213\206\345\210\206/139-\345\215\225\350\257\215\346\213\206\345\210\206.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def wordBreak(self, s, wordDict): - """ - :type s: str - :type wordDict: List[str] - :rtype: bool - """ - dp = [-1] # dp[i] 琛ㄧず浠0~涓嬫爣涓篿鐨勫崟璇嶅彲浠ヨ鎷嗗垎 - - for i, ch in enumerate(s): - for start in dp: - if s[start + 1:i + 1] in wordDict: - dp.append(i) - break - - return dp[-1] == len(s) - 1 \ No newline at end of file diff --git "a/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" "b/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" deleted file mode 100644 index 52fbeff..0000000 --- "a/1394.\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260/1394-\346\211\276\345\207\272\346\225\260\347\273\204\344\270\255\347\232\204\345\271\270\350\277\220\346\225\260.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def findLucky(self, arr): - """ - :type arr: List[int] - :rtype: int - """ - l = [key for key, val in collections.Counter(arr).items() if key == val] - return max(l) if l else -1 \ No newline at end of file diff --git "a/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" "b/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" deleted file mode 100644 index ebbe4d5..0000000 --- "a/1395.\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260/1395-\347\273\237\350\256\241\344\275\234\346\210\230\345\215\225\344\275\215\346\225\260.py" +++ /dev/null @@ -1,26 +0,0 @@ -class Solution(object): - def numTeams(self, rating): - """ - :type rating: List[int] - :rtype: int - """ - from collections import defaultdict - - - def helper(rating): - dic = defaultdict(int) - res = 0 - - for i in range(len(rating)): - for j in range(i + 1, len(rating)): - if rating[j] > rating[i]: - dic[i] += 1 - - - for i in range(len(rating)): - for j in range(i + 1, len(rating)): - if rating[j] > rating[i]: - res += dic[j] - return res - - return helper(rating) + helper(rating[::-1]) 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" deleted file mode 100644 index dc1328d..0000000 --- "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" +++ /dev/null @@ -1,44 +0,0 @@ -class UndergroundSystem(object): - - def __init__(self): - from collections import defaultdict - self.cnt = defaultdict(int) - self.total = defaultdict(int) - self.record = {} # key is id, val is the checkin stationName and time - def checkIn(self, id, stationName, t): - """ - :type id: int - :type stationName: str - :type t: int - :rtype: None - """ - self.record[id] = (stationName, t) - - def checkOut(self, id, stationName, t): - """ - :type id: int - :type stationName: str - :type t: int - :rtype: None - """ - checkinStation = self.record[id][0] - checkinTime = self.record[id][1] - - self.total[checkinStation + "#" + stationName] += t - checkinTime - self.cnt[checkinStation + "#" + stationName] += 1 - - - def getAverageTime(self, startStation, endStation): - """ - :type startStation: str - :type endStation: str - :rtype: float - """ - return self.total[startStation + "#" + endStation] * 1.0 / self.cnt[startStation + "#" + endStation] - - -# 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 diff --git "a/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" "b/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" deleted file mode 100644 index e73c683..0000000 --- "a/1399.\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256/1399-\347\273\237\350\256\241\346\234\200\345\244\247\347\273\204\347\232\204\346\225\260\347\233\256.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def countLargestGroup(self, n): - """ - :type n: int - :rtype: int - """ - from collections import defaultdict - l = defaultdict(int) - - def helper(num): - # 璁$畻num鏁颁綅涔嬪拰锛宔g锛氳緭鍏34, 杩斿洖3 + 4 = 7 - s = 0 - while num: - num, tmp = divmod(num, 10) - s += tmp - return s - - for num in range(1, n + 1): - l[helper(num)] += 1 - - mmax = max(l.values()) - return sum([1 for item in l.values() if item == mmax]) \ No newline at end of file diff --git "a/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" "b/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" deleted file mode 100644 index 8bd5502..0000000 --- "a/1400.\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262/1400-\346\236\204\351\200\240K\344\270\252\345\233\236\346\226\207\345\255\227\347\254\246\344\270\262.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def canConstruct(self, s, k): - """ - :type s: str - :type k: int - :rtype: bool - """ - if k >= len(s): - # 闀垮害 == k锛屽繀鐒跺彲浠ワ紱闀垮害 < k锛屽繀鐒朵笉鍙互銆 - return k == len(s) - - from collections import Counter - dic = Counter(s) - # 瀵逛簬姣忎竴涓嚭鐜版鏁颁负濂囨暟娆$殑瀛楃鏉ヨ锛屾瘮濡 "aaa", 瀹冭嚦灏戣兘鏋勬垚涓涓洖鏂囦覆锛屾渶澶氳兘鏋勬垚涓変釜鍥炴枃涓诧紝 - s_odd = 0 - for val in dic.values(): - if val % 2: - s_odd += 1 - return s_odd <= k \ No newline at end of file diff --git "a/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" "b/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" deleted file mode 100644 index ba60d1b..0000000 --- "a/1402.\345\201\232\350\217\234\351\241\272\345\272\217/1402-\345\201\232\350\217\234\351\241\272\345\272\217.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def maxSatisfaction(self, satisfaction): - """ - :type satisfaction: List[int] - :rtype: int - """ - res = 0 - - s = sorted(satisfaction) - - for i in range(len(s)): - cnt = 1 - tmp = 0 - for j in range(i, len(s)): - tmp += cnt * s[j] - cnt += 1 - # print tmp - res = max(tmp, res) - - return res diff --git "a/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" "b/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" deleted file mode 100644 index a01dd06..0000000 --- "a/1403.\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227/1403-\351\235\236\351\200\222\345\242\236\351\241\272\345\272\217\347\232\204\346\234\200\345\260\217\345\255\220\345\272\217\345\210\227.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def minSubsequence(self, nums): - """ - :type nums: List[int] - :rtype: List[int] - """ - s = sum(nums) - - t = 0 - res = [] - for num in sorted(nums)[::-1]: - res.append(num) - t += num - s -= num - - if t > s: - return res \ No newline at end of file diff --git "a/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" "b/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" deleted file mode 100644 index 08c4a9c..0000000 --- "a/1404.\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260/1404-\345\260\206\344\272\214\350\277\233\345\210\266\350\241\250\347\244\272\345\207\217\345\210\2601\347\232\204\346\255\245\351\252\244\346\225\260.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def numSteps(self, s): - """ - :type s: str - :rtype: int - """ - cnt = 0 - s = int(s, 2) - while s != 1: - cnt += 1 - if s % 2: - s += 1 - else: - s //= 2 - return cnt \ No newline at end of file diff --git "a/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" "b/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" deleted file mode 100644 index 8bffec5..0000000 --- "a/1405.\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262/1405-\346\234\200\351\225\277\345\277\253\344\271\220\345\255\227\347\254\246\344\270\262.py" +++ /dev/null @@ -1,38 +0,0 @@ -class Solution(object): - def longestDiverseString(self, a, b, c): - """ - :type a: int - :type b: int - :type c: int - :rtype: str - """ - from heapq import * - heap = [] - res = "" - if a: - heappush(heap, (-a, "a")) - if b: - heappush(heap, (-b, "b")) - if c: - heappush(heap, (-c, "c")) - pre_cnt, pre_char = None, None - s = a + b + c - - while heap: - cnt, char = heappop(heap) - cnt = -cnt - # print cnt, char - - if cnt > s - cnt: - res += char * min(cnt, 2) - cnt -= min(cnt, 2) - s -= min(cnt, 2) - else: - res += char - cnt -= 1 - s -= 1 - - if pre_cnt: - heappush(heap, (-pre_cnt, pre_char)) - pre_cnt, pre_char = cnt, char - return res \ No newline at end of file diff --git "a/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" "b/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" deleted file mode 100644 index 5b41923..0000000 --- "a/1408.\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215/1408-\346\225\260\347\273\204\344\270\255\347\232\204\345\255\227\347\254\246\344\270\262\345\214\271\351\205\215.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def stringMatching(self, words): - """ - :type words: List[str] - :rtype: List[str] - """ - fix = set() - res = [] - - for word1 in words: - for word2 in words: - if len(word1) < len(word2) and word1 in word2: - res.append(word1) - break - - 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" deleted file mode 100644 index f27eefc..0000000 --- "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" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def processQueries(self, queries, m): - """ - :type queries: List[int] - :type m: int - :rtype: List[int] - """ - q = list(range(1, m + 1)) - res = [] - for i, x in enumerate(queries): - idx = q.index(queries[i]) - res.append(idx) - q.pop(idx) - q.insert(0, queries[i]) - return res \ No newline at end of file diff --git "a/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" "b/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" deleted file mode 100644 index 923436c..0000000 --- "a/1410.HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250/1410-HTML\345\256\236\344\275\223\350\247\243\346\236\220\345\231\250.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def entityParser(self, text): - """ - :type text: str - :rtype: str - """ - t = text.replace(""", "\"") - t = t.replace("'", "\'") - - t = t.replace(">", ">") - t = t.replace("<", "<") - t = t.replace("⁄","/") - t = t.replace("&", "&") - return t \ No newline at end of file diff --git "a/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" "b/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" deleted file mode 100644 index 13ad386..0000000 --- "a/1413.\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274/1413-\351\200\220\346\255\245\346\261\202\345\222\214\345\276\227\345\210\260\346\255\243\346\225\260\347\232\204\346\234\200\345\260\217\345\200\274.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def minStartValue(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - min_s = nums[0] - s = 0 - for num in nums: - s += num - min_s = min(min_s, s) - - return 1 if min_s >= 1 else 1 - min_s \ No newline at end of file diff --git "a/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" "b/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" deleted file mode 100644 index b3bb5d8..0000000 --- "a/1414.\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256/1414-\345\222\214\344\270\272K\347\232\204\346\234\200\345\260\221\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\255\227\346\225\260\347\233\256.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def findMinFibonacciNumbers(self, k): - """ - :type k: int - :rtype: int - """ - first, second = 1, 1 - fib = [1, 1] - while second < k: - nxt = first + second - fib.append(nxt) - first = second - second = nxt - res = 0 - while k > 0: - idx = bisect.bisect_left(fib, k) - if fib[idx] == k: - k -= fib[idx] - else: - k -= fib[idx - 1] - res += 1 - return res \ No newline at end of file diff --git "a/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" "b/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" deleted file mode 100644 index 7a2e1ad..0000000 --- "a/1417.\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262/1417-\351\207\215\346\226\260\346\240\274\345\274\217\345\214\226\345\255\227\347\254\246\344\270\262.py" +++ /dev/null @@ -1,32 +0,0 @@ -class Solution(object): - def reformat(self, s): - """ - :type s: str - :rtype: str - """ - char = [ch for ch in s if ch.isalpha()] - digit = [ch for ch in s if ch.isdigit()] - - if abs(len(char) - len(digit)) > 1: - return "" - - res = "" - i = 0 - if len(char) > len(digit): - while i < len(digit): - res += char[i] - res += digit[i] - i += 1 - res += char[i] - - else: - while i < len(char): - res += digit[i] - res += char[i] - i += 1 - - if len(char) < len(digit): - res += digit[i] - - 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" deleted file mode 100644 index b407f23..0000000 --- "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" +++ /dev/null @@ -1,30 +0,0 @@ -class Solution(object): - def displayTable(self, orders): - """ - :type orders: List[List[str]] - :rtype: List[List[str]] - """ - from collections import defaultdict - dishes = set() - tables = set() - dic = dict() - - for c, t, f in orders: - dishes.add(f) - tables.add(int(t)) - - if t not in dic: - dic[t] = defaultdict(int) - dic[t][f] += 1 - - dishes = sorted(list(dishes)) - res = [["Table"] + dishes] - - for t in sorted(list(tables)): - tmp = [str(t)] - for d in dishes: - tmp.append(str(dic[str(t)][d])) - res.append(tmp) - return res - - \ No newline at end of file diff --git "a/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" "b/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" deleted file mode 100644 index 7ab83fd..0000000 --- "a/1419.\346\225\260\351\235\222\350\233\231/1419-\346\225\260\351\235\222\350\233\231.py" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def minNumberOfFrogs(self, croakOfFrogs): - """ - :type croakOfFrogs: str - :rtype: int - """ - from collections import defaultdict - if len(croakOfFrogs) % 5 != 0: - return -1 - - dic = defaultdict(int) - res = 0 - pre = {"r":"c", "o":"r", "a":"o"} - for ch in croakOfFrogs: - if ch == "c": - dic[ch] += 1 - - elif ch in "roa": - if dic[pre[ch]] == 0: - return -1 - dic[pre[ch]] -= 1 - dic[ch] += 1 - - elif ch == "k": - if dic["a"] == 0: - return -1 - dic["k"] -= 1 - - res = max(res, sum(dic.values())) - - return res \ No newline at end of file diff --git "a/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" deleted file mode 100644 index cf48db3..0000000 --- "a/1422.\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206/1422-\345\210\206\345\211\262\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\276\227\345\210\206.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def maxScore(self, s): - """ - :type s: str - :rtype: int - """ - zero = s.count("0") - one = len(s) - zero - zero_cnt = 0 - res = 0 - for i, x in enumerate(s[:-1]): - if x == "0": - zero_cnt += 1 - one_cnt = one - (i + 1 - zero_cnt) - res = max(res, zero_cnt + one_cnt) - - return res \ No newline at end of file diff --git "a/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" "b/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" deleted file mode 100644 index fb17c81..0000000 --- "a/1423.\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260/1423-\345\217\257\350\216\267\345\276\227\347\232\204\346\234\200\345\244\247\347\202\271\346\225\260.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def maxScore(self, cardPoints, k): - """ - :type cardPoints: List[int] - :type k: int - :rtype: int - """ - # 杩炵画鎽 n - k 寮犵墝锛屾眰鏈灏忕偣鏁板拰 - n = len(cardPoints) - s = sum(cardPoints) - - left, right = 0, n - k - window_sum = sum(cardPoints[left:right]) - min_s = window_sum - for right in range(n - k, n): - # print cardPoints[left:right + 1] - window_sum -= cardPoints[left] - window_sum += cardPoints[right] - min_s = min(min_s, window_sum) - left += 1 - return s - min_s diff --git "a/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" "b/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" deleted file mode 100644 index 2878cfe..0000000 --- "a/1426.\346\225\260\345\205\203\347\264\240/1426-\346\225\260\345\205\203\347\264\240.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def countElements(self, arr): - """ - :type arr: List[int] - :rtype: int - """ - s = set(arr) - - res = 0 - for num in arr: - if num + 1 in s: - res += 1 - return res \ No newline at end of file diff --git "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" index a4d3f35..1c1ba4f 100644 --- "a/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" +++ "b/1447.\346\234\200\347\256\200\345\210\206\346\225\260/1447-\346\234\200\347\256\200\345\210\206\346\225\260.py" @@ -1,11 +1,11 @@ class Solution: def simplifiedFractions(self, n: int) -> List[str]: import math - res = set() + res = [] for down in range(1, n + 1): for up in range(1, down): if math.gcd(up, down) == 1: - res.add(str(up) + "/" + str(down)) + res.append(str(up) + "/" + str(down)) - return list(res) \ No newline at end of file + return res \ No newline at end of file diff --git "a/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" "b/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" deleted file mode 100644 index 8942475..0000000 --- "a/146.LRU\347\274\223\345\255\230\346\234\272\345\210\266/146-LRU\347\274\223\345\255\230\346\234\272\345\210\266.py" +++ /dev/null @@ -1,74 +0,0 @@ -class Node(object): - def __init__(self, key, value, nxt, prev): - self.key = key - self.value = value - self.next = nxt - self.prev = prev -class LRUCache(object): - - def __init__(self, capacity): - """ - :type capacity: int - """ - self.capacity = capacity - self.record = dict() - self.head = Node(-1, -1, None, None) - self.tail = Node(-1, -1, self.head, self.head) - self.head.next = self.tail - self.head.prev = self.tail - - def move_to_end(self, key): - node = self.record[key] - - node.prev.next = node.next - node.next.prev = node.prev - - prev_to_tail = self.tail.prev - node.next = self.tail - node.prev = prev_to_tail - prev_to_tail.next = node - self.tail.prev = node - - - def get(self, key): - """ - :type key: int - :rtype: int - """ - - if key in self.record: - self.move_to_end(key) - return self.record[key].value - else: - return -1 - - - def put(self, key, value): - """ - :type key: int - :type value: int - :rtype: None - """ - if key in self.record: - self.move_to_end(key) - self.record[key].value = value - else: - if self.capacity == 0: - self.record.pop(self.head.next.key) - new_first_node = self.head.next.next - self.head.next = new_first_node - new_first_node.prev = self.head - else: - self.capacity -= 1 - - prev_to_tail = self.tail.prev - new_node = Node(key, value, self.tail, prev_to_tail) - self.record[key] = new_node - prev_to_tail.next = new_node - self.tail.prev = new_node - - -# Your LRUCache object will be instantiated and called as such: -# obj = LRUCache(capacity) -# param_1 = obj.get(key) -# obj.put(key,value) \ No newline at end of file diff --git "a/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" "b/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" deleted file mode 100644 index e1ef72a..0000000 --- "a/151.\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215/151-\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def reverseWords(self, s): - """ - :type s: str - :rtype: str - """ - return " ".join([item for item in s.strip().rstrip().split(" ") if item][::-1]) \ No newline at end of file diff --git "a/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" "b/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" deleted file mode 100644 index 0b9c216..0000000 --- "a/155.\346\234\200\345\260\217\346\240\210/155-\346\234\200\345\260\217\346\240\210.py" +++ /dev/null @@ -1,47 +0,0 @@ -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/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" "b/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" deleted file mode 100644 index 720d9e2..0000000 --- "a/167.\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204/167-\344\270\244\346\225\260\344\271\213\345\222\214II-\350\276\223\345\205\245\346\234\211\345\272\217\346\225\260\347\273\204.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def twoSum(self, numbers, target): - """ - :type numbers: List[int] - :type target: int - :rtype: List[int] - """ - left, right = 0, len(numbers) - 1 - while 1: - tmp = numbers[left] + numbers[right] - if tmp == target: - return [left + 1, right + 1] - elif tmp < target: - left += 1 - elif tmp > target: - right -= 1 diff --git "a/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" "b/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" deleted file mode 100644 index 858b7a2..0000000 --- "a/169.\345\244\232\346\225\260\345\205\203\347\264\240/169-\345\244\232\346\225\260\345\205\203\347\264\240.py" +++ /dev/null @@ -1,19 +0,0 @@ -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/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" "b/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" deleted file mode 100644 index 7533bb6..0000000 --- "a/199.\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276/199-\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.py" +++ /dev/null @@ -1,31 +0,0 @@ -# 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 = [] - last_element = None - while queue: - for _ in range(len(queue)): - cur = queue.popleft() - last_element = cur.val - if cur.left: - queue.append(cur.left) - if cur.right: - queue.append(cur.right) - res.append(last_element) - - return res \ No newline at end of file diff --git "a/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" "b/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" deleted file mode 100644 index 5e1ec45..0000000 --- "a/200.\345\262\233\345\261\277\346\225\260\351\207\217/200-\345\262\233\345\261\277\346\225\260\351\207\217.py" +++ /dev/null @@ -1,33 +0,0 @@ -class Solution(object): - def numIslands(self, M): - """ - :type grid: List[List[str]] - :rtype: int - """ - if not M or not M[0]: - return 0 - m, n = len(M), len(M[0]) - visited = [[0 for j in range(n)] for i in range(m)] - # print visited - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - res = 0 - - def dfs(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 M[x][y] == '1' and visited[x][y] ==0: - visited[x][y] = 1 - dfs(x, y) - - for i in range(m): - for j in range(n): - if M[i][j] == '1' and visited[i][j] == 0: - res += 1 - visited[i][j] = 1 - dfs(i, j) - # print visited - - return res \ No newline at end of file diff --git "a/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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" deleted file mode 100644 index 7e7be51..0000000 --- "a/21.\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250/21-\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" +++ /dev/null @@ -1,33 +0,0 @@ -# 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/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" "b/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" deleted file mode 100644 index d92c65c..0000000 --- "a/22.\346\213\254\345\217\267\347\224\237\346\210\220/22-\346\213\254\345\217\267\347\224\237\346\210\220.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def generateParenthesis(self, n): - """ - :type n: int - :rtype: List[str] - """ - - res = [] - - def dfs(l, r, tmp): - if not l and not r: - res.append(tmp[:]) - if l: - dfs(l - 1, r, tmp + "(") - if l < r: - dfs(l, r - 1, tmp + ")") - dfs(n, n, "") - return res \ No newline at end of file diff --git "a/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" "b/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" deleted file mode 100644 index 66eb540..0000000 --- "a/221.\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242/221-\346\234\200\345\244\247\346\255\243\346\226\271\345\275\242.py" +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def maximalSquare(self, matrix): - """ - :type matrix: List[List[str]] - :rtype: int - """ - if not matrix or not matrix[0]: - return 0 - m, n = len(matrix), len(matrix[0]) - - dp = [[0 for _ in range(n)] for _ in range(m)] - res = 0 - for j in range(n): - if matrix[0][j] == "1": - dp[0][j] = 1 - res = 1 - - for i in range(m): - if matrix[i][0] == "1": - dp[i][0] = 1 - res = 1 - - for i in range(1, m): - for j in range(1, n): - if matrix[i][j] == "1": - dp[i][j] = min(dp[i - 1][j - 1], dp[i][j - 1], dp[i - 1][j]) + 1 - res = max(res, dp[i][j] ** 2) - # print dp - return res \ No newline at end of file diff --git "a/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" "b/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" deleted file mode 100644 index 21c0098..0000000 --- "a/225.\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210/225-\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210.py" +++ /dev/null @@ -1,49 +0,0 @@ -from collections import deque -class MyStack(object): - def __init__(self): - """ - Initialize your data structure here. - """ - self.q1 = deque() - self.q2 = deque() - - def push(self, x): - """ - Push element x onto stack. - :type x: int - :rtype: None - """ - self.q1.append(x) - while self.q2: - self.q1.append(self.q2.popleft()) - self.q2 = self.q1 - self.q1 = deque() - - def pop(self): - """ - Removes the element on top of the stack and returns that element. - :rtype: int - """ - return self.q2.popleft() - - def top(self): - """ - Get the top element. - :rtype: int - """ - return self.q2[0] - - def empty(self): - """ - Returns whether the stack is empty. - :rtype: bool - """ - return not self.q2 - - -# Your MyStack object will be instantiated and called as such: -# obj = MyStack() -# obj.push(x) -# param_2 = obj.pop() -# param_3 = obj.top() -# param_4 = obj.empty() \ No newline at end of file diff --git "a/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" "b/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" deleted file mode 100644 index ca17ef9..0000000 --- "a/25.K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250/25-K\344\270\252\344\270\200\347\273\204\347\277\273\350\275\254\351\223\276\350\241\250.py" +++ /dev/null @@ -1,45 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def reverseKGroup(self, head, k): - """ - :type head: ListNode - :type k: int - :rtype: ListNode - """ - if not head or not head.next: - return head - - cnt = 0 - p = head - while p: - cnt += 1 - if cnt == k: - break - p = p.next - - if cnt < k: - return head - - tail = p.next - p.next = None - - tmp = self.reverseKGroup(tail, k) - newhead = self.reverseLL(head) - head.next = tmp - - return newhead - - - - 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/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" "b/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" deleted file mode 100644 index b0d5838..0000000 --- "a/252.\344\274\232\350\256\256\345\256\244/252-\344\274\232\350\256\256\345\256\244.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def canAttendMeetings(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: bool - """ - if not intervals or not intervals[0]: - return True - - intervals.sort(key = lambda x:x[0]) - end = intervals[0][1] - for i in range(1, len(intervals)): - s, e = intervals[i][0], intervals[i][1] - - if s < end: - return False - end = e - return True \ No newline at end of file diff --git "a/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" "b/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" deleted file mode 100644 index 13c7f4e..0000000 --- "a/253.\344\274\232\350\256\256\345\256\244II/253-\344\274\232\350\256\256\345\256\244II.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def minMeetingRooms(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: int - """ - if not intervals or not intervals[0]: - return 0 - intervals.sort() - from heapq import * - queue = [] - heappush(queue, intervals[0][1]) - for i in range(1, len(intervals)): - start, end = intervals[i][0], intervals[i][1] - - if start >= queue[0]: - heappop(queue) - heappush(queue, end) - - return len(queue) \ No newline at end of file diff --git "a/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" "b/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" deleted file mode 100644 index 0b5774b..0000000 --- "a/287.\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260/287-\345\257\273\346\211\276\351\207\215\345\244\215\346\225\260.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def findDuplicate(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - - slow, fast = 0, 0 - while 1: - fast = nums[nums[fast]] - slow = nums[slow] - if fast == slow: - fast = 0 - while nums[fast] != nums[slow]: - fast = nums[fast] - slow = nums[slow] - return nums[slow] diff --git "a/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" "b/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" deleted file mode 100644 index 23ec6db..0000000 --- "a/289.\347\224\237\345\221\275\346\270\270\346\210\217/289-\347\224\237\345\221\275\346\270\270\346\210\217.py" +++ /dev/null @@ -1,50 +0,0 @@ -class Solution(object): - def gameOfLife(self, board): - """ - :type board: List[List[int]] - :rtype: void Do not return anything, modify board in-place instead. - """ - m = len(board) - if m == 0: - return board - n = len(board[0]) - if n == 0: - return board - - alivex = list() - alivey = list() - - def neibor(x, y): #缁熻鍏釜閭诲眳閲屾湁鍑犱釜鏄椿缁嗚優锛1锛 - dx = [1, -1, 0, 0, 1, -1, -1, 1] - dy = [0, 0, 1, -1, 1, -1, 1, -1] - - cnt = 0 - for k in range(8): - xx = x + dx[k] - yy = y + dy[k] - - if 0 <= xx < m and 0 <= yy < n and board[xx][yy] == 1: - cnt += 1 - - return cnt - - - for i in range(m): - for j in range(n): - cnt = neibor(i, j) - # print i, j, cnt - if (board[i][j] == 1 and 2 <= cnt <= 3) or (board[i][j] == 0 and cnt == 3): - alivex.append(i) - alivey.append(j) - - alivecnt = 0 - for i in range(m): - for j in range(n): - board[i][j] = 0 - - if alivecnt < len(alivex): - if alivex[alivecnt] == i and alivey[alivecnt] == j: - board[i][j] = 1 - alivecnt += 1 - - return board \ No newline at end of file diff --git "a/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" "b/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" deleted file mode 100644 index e602a1f..0000000 --- "a/296.\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271/296-\346\234\200\344\275\263\347\232\204\347\242\260\345\244\264\345\234\260\347\202\271.py" +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def minTotalDistance(self, grid): - """ - :type grid: List[List[int]] - :rtype: int - """ - if not grid or not grid[0]: - return -1 - - m, n = len(grid), len(grid[0]) - row, col = [], [] - for i in range(m): - for j in range(n): - if grid[i][j]: - row.append(i) - col.append(j) - meet_point = [self.findMedian(row), self.findMedian(col)] - - res = 0 - for i in range(m): - for j in range(n): - if grid[i][j]: - res += abs(i - meet_point[0]) + abs(j - meet_point[1]) - return res - - - def findMedian(self, nums): - nums.sort() - return nums[len(nums) // 2] diff --git "a/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" "b/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" deleted file mode 100644 index 13447ba..0000000 --- "a/299.\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217/299-\347\214\234\346\225\260\345\255\227\346\270\270\346\210\217.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def getHint(self, secret, guess): - """ - :type secret: str - :type guess: str - :rtype: str - """ - from collections import Counter - dic_s = Counter(secret) - dic_g = Counter(guess) - - a, b = 0, 0 - for i in range(len(secret)): - if secret[i] == guess[i]: - a += 1 - dic_s[secret[i]] -= 1 - dic_g[secret[i]] -= 1 - - for i in dic_s & dic_g: - b += min(dic_s[i], dic_g[i]) - - return "{}A{}B".format(a, b) \ No newline at end of file diff --git "a/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" "b/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" deleted file mode 100644 index f5fcf2e..0000000 --- "a/300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227/300-\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def lengthOfLIS(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - dp = [1 for _ in nums] - - for i in range(len(nums)): - for j in range(i): - if nums[i] > nums[j]: - dp[i] = max(dp[i], dp[j] + 1) - - return max(dp) if dp else 0 \ No newline at end of file diff --git "a/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" "b/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" deleted file mode 100644 index 13e35ba..0000000 --- "a/322.\351\233\266\351\222\261\345\205\221\346\215\242/322-\351\233\266\351\222\261\345\205\221\346\215\242.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def coinChange(self, coins, amount): - """ - :type coins: List[int] - :type amount: int - :rtype: int - """ - from collections import deque - - queue = deque([(0, 0)]) - visited = set([0]) - while queue: - cur, step = queue.popleft() - if cur == amount: - return step - if cur > amount: - continue - - for coin in coins: - value = cur + coin - if value not in visited: - visited.add((value)) - queue.append((value, step + 1)) - - return -1 \ No newline at end of file diff --git "a/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" "b/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" deleted file mode 100644 index 513bb5a..0000000 --- "a/326.3\347\232\204\345\271\202/326-3\347\232\204\345\271\202.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def isPowerOfThree(self, n): - """ - :type n: int - :rtype: bool - """ - t = 1 - while t < n: - t *= 3 - return n == t \ No newline at end of file diff --git "a/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" "b/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" deleted file mode 100644 index 8dc6838..0000000 --- "a/347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def topKFrequent(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: List[int] - """ - from collections import Counter - from heapq import * - dic = Counter(nums) - queue = [] - for digit, fre in dic.items(): - if len(queue) < k: - heappush(queue, (fre, digit)) - else: - heappushpop(queue, (fre, digit)) - # print queue - res = [] - while queue: - res.append(heappop(queue)[1]) - return res \ No newline at end of file diff --git "a/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" "b/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" deleted file mode 100644 index 55d2c19..0000000 --- "a/355.\350\256\276\350\256\241\346\216\250\347\211\271/355-\350\256\276\350\256\241\346\216\250\347\211\271.py" +++ /dev/null @@ -1,51 +0,0 @@ -class Twitter: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.stack = [] #鍙戞帹璁板綍 - self.f = {} #璁板綍姣忎釜浜哄叧娉ㄤ簡璋 - - - def postTweet(self, userId: int, tweetId: int) -> None: - """ - Compose a new tweet. - """ - self.stack.append((userId, tweetId)) - - - def getNewsFeed(self, userId: int) -> List[int]: - """ - Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. - """ - out = [] - following = [userId] - if userId in self.f: - following += self.f[userId] - for i in range(len(self.stack)-1, -1, -1): - if self.stack[i][0] in following: - out.append(self.stack[i][1]) - if len(out) == 10: - return out - return out - - - def follow(self, followerId: int, followeeId: int) -> None: - """ - Follower follows a followee. If the operation is invalid, it should be a no-op. - """ - if followerId not in self.f: - self.f[followerId] = [followeeId] - else: - if followeeId not in self.f[followerId]: - self.f[followerId].append(followeeId) - - - def unfollow(self, followerId: int, followeeId: int) -> None: - """ - Follower unfollows a followee. If the operation is invalid, it should be a no-op. - """ - if followerId in self.f: - if followeeId in self.f[followerId]: - self.f[followerId].remove(followeeId) \ No newline at end of file diff --git "a/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" "b/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" deleted file mode 100644 index 29817d8..0000000 --- "a/365.\346\260\264\345\243\266\351\227\256\351\242\230/365-\346\260\264\345\243\266\351\227\256\351\242\230.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def canMeasureWater(self, x, y, z): - """ - :type x: int - :type y: int - :type z: int - :rtype: bool - """ - if not z: - return True - if not x: - return y == z - if not y: - return x == z - if x + y < z: - return False - def gcd(a, b): - while a % b: - a, b = b, a % b - return b - return not z % gcd(x, y) \ No newline at end of file diff --git "a/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" "b/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" deleted file mode 100644 index 38ea4d5..0000000 --- "a/366.\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271/366-\345\257\273\346\211\276\344\272\214\345\217\211\346\240\221\347\232\204\345\217\266\345\255\220\350\212\202\347\202\271.py" +++ /dev/null @@ -1,35 +0,0 @@ -# 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 findLeaves(self, root): - """ - :type root: TreeNode - :rtype: List[List[int]] - """ - from collections import defaultdict - self.dic = defaultdict(list) - res = [] - def get_Height(node): - if not node: - return -1 - lh = get_Height(node.left) - rh = get_Height(node.right) - h = max(lh, rh) + 1 - self.dic[h].append(node.val) - return h - - get_Height(root) - # print self.dic - h = 0 - while 1: - if h not in self.dic: - break - res.append(self.dic[h]) - h += 1 - return res - \ No newline at end of file diff --git "a/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" "b/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" deleted file mode 100644 index d07d9f3..0000000 --- "a/378.\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240/378-\346\234\211\345\272\217\347\237\251\351\230\265\344\270\255\347\254\254K\345\260\217\347\232\204\345\205\203\347\264\240.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def kthSmallest(self, matrix, k): - """ - :type matrix: List[List[int]] - :type k: int - :rtype: int - """ - if not matrix or not matrix[0]: - return matrix - - from heapq import * - queue = [] - for i in range(len(matrix)): - heappush(queue, (matrix[i][0], i, 0)) - - cnt = 0 - while cnt < k: - cnt += 1 - - val, row, col = heappop(queue) - if col + 1 < len(matrix): - heappush(queue, (matrix[row][col + 1], row, col + 1)) - - return val - \ No newline at end of file diff --git "a/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" "b/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" deleted file mode 100644 index 140f172..0000000 --- "a/386.\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260/386-\345\255\227\345\205\270\345\272\217\346\216\222\346\225\260.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def lexicalOrder(self, n): - """ - :type n: int - :rtype: List[int] - """ - return sorted(range(1, n + 1), key = str) -# res = [] - -# def dfs(k): -# if k > n: -# return -# res.append(k) - -# for i in range(10): -# dfs(10 * k + i) - -# for i in range(1, 10): -# dfs(i) -# return res \ No newline at end of file diff --git "a/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" "b/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" deleted file mode 100644 index a640d0d..0000000 --- "a/387.\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246/387-\345\255\227\347\254\246\344\270\262\344\270\255\347\232\204\347\254\254\344\270\200\344\270\252\345\224\257\344\270\200\345\255\227\347\254\246.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def firstUniqChar(self, s): - """ - :type s: str - :rtype: int - """ - dic = collections.Counter(s) - - for i, ch in enumerate(s): - if dic[ch] == 1: - return i - return -1 \ No newline at end of file diff --git "a/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" "b/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" deleted file mode 100644 index f69bb27..0000000 --- "a/398.\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225/398-\351\232\217\346\234\272\346\225\260\347\264\242\345\274\225.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - - def __init__(self, nums): - """ - :type nums: List[int] - """ - from collections import defaultdict - self.dic = defaultdict(list) - for i, num in enumerate(nums): - self.dic[num].append(i) - - def pick(self, target): - """ - :type target: int - :rtype: int - """ - return random.choice(self.dic[target]) - - -# Your Solution object will be instantiated and called as such: -# obj = Solution(nums) -# param_1 = obj.pick(target) \ No newline at end of file diff --git "a/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" "b/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" deleted file mode 100644 index 1acf581..0000000 --- "a/409.\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262/409-\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def longestPalindrome(self, s): - """ - :type s: str - :rtype: int - """ - return len(s) -max(0,sum([s.count(i)%2 for i in set(s)])-1) \ No newline at end of file diff --git "a/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" "b/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" deleted file mode 100644 index a5926c1..0000000 --- "a/42.\346\216\245\351\233\250\346\260\264/42-\346\216\245\351\233\250\346\260\264.py" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def trap(self, height): - """ - :type height: List[int] - :rtype: int - """ - left_max = [0 for _ in height] - right_max = [0 for _ in height] - water = [0 for _ in height] - - for i in range(len(height)): - if i - 1 >= 0: - left_max[i] = max(left_max[i - 1], height[i]) - else: - left_max[i] = height[i] - - for i in range(len(height) - 1, -1, -1): - if i < len(height) - 1: - right_max[i] = max(right_max[i + 1], height[i]) - else: - right_max[i] = height[i] - - for i in range(len(height)): - tmp = min(left_max[i], right_max[i]) - height[i] - if tmp > 0: - water[i] = tmp - # print height - # print water - # print left_max - # print right_max - return sum(water) \ No newline at end of file diff --git "a/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" deleted file mode 100644 index 669fb96..0000000 --- "a/426.\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250/426-\345\260\206\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\275\254\345\214\226\344\270\272\346\216\222\345\272\217\347\232\204\345\217\214\345\220\221\351\223\276\350\241\250.py" +++ /dev/null @@ -1,47 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val, left=None, right=None): - self.val = val - self.left = left - self.right = right -""" -class Solution(object): - def treeToDoublyList(self, root): - """ - :type root: Node - :rtype: Node - """ - if not root: - return root - if not root.left and not root.right: - root.left = root - root.right = root - return root - - left = self.treeToDoublyList(root.left) - right = self.treeToDoublyList(root.right) - if root.left and root.right: - left_tail = left.left - right_tail = right.left - - left_tail.right = root - root.left = left_tail - root.right = right - right.left = root - - left.left = right_tail - right_tail.right = left - elif root.left: - left_tail = left.left - left_tail.right = root - root.left = left_tail - left.left = root - root.right = left - elif root.right: - right_tail = right.left - root.right = right - root.left = right_tail - right_tail.right = root - right.left = root - return left if left else root \ No newline at end of file diff --git "a/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" deleted file mode 100644 index 08d25c6..0000000 --- "a/430.\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250/430-\346\211\201\345\271\263\345\214\226\345\244\232\347\272\247\345\217\214\345\220\221\351\223\276\350\241\250.py" +++ /dev/null @@ -1,38 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val, prev, next, child): - self.val = val - self.prev = prev - self.next = next - self.child = child -""" -class Solution(object): - def flatten(self, head): - """ - :type head: Node - :rtype: Node - """ - if not head: - return head - - def helper(node): - # 杩斿洖鐨勬槸鏈鍚庝竴涓妭鐐 - if not node: - return - while node: - nxt = node.next # 澶囦唤 next - if not nxt: - tail = node # 璁板綍 tail锛岀敤浜庤繑鍥 - if node.child: - node.next = node.child # 鎶奵hild 鍙樻垚next - node.next.prev = node - t = helper(node.child) # 閫掑綊澶勭悊锛宼 鏄鐞嗕箣鍚庣殑 鍘熸潵鐨刢hild 鐨勬渶鍚庝竴涓妭鐐 - node.child = None # 鎶奵hild 缃┖ - if nxt: # 濡傛灉鏈塶ext 閮ㄥ垎锛屽氨璁﹏ext鐨刾rev鎸囧悜 鍘熸潵鐨刢hild 澶勭悊涔嬪悗鐨勬渶鍚庝竴涓妭鐐 - nxt.prev = t - t.next = nxt # 璁 t.next 鎸囧悜鍘熸潵鐨 next - node = node.next - return tail - helper(head) - return head \ No newline at end of file diff --git "a/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" "b/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" deleted file mode 100644 index cffe9ed..0000000 --- "a/436.\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264/436-\345\257\273\346\211\276\345\217\263\345\214\272\351\227\264.py" +++ /dev/null @@ -1,23 +0,0 @@ -class Solution(object): - def findRightInterval(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: List[int] - """ - dic = {} - for i, (start, end) in enumerate(intervals): - dic[start] = i - - res = [-1 for _ in range(len(intervals))] - - l = [interval[0] for interval in intervals] - l = sorted(l, key = lambda x:x) - - for i, (start, end) in enumerate(intervals): - idx = bisect.bisect_left(l, end) - if idx < len(l): - res[i] = dic[l[idx]] - - return res - - \ No newline at end of file diff --git "a/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" "b/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" deleted file mode 100644 index ae75d3c..0000000 --- "a/445.\344\270\244\346\225\260\347\233\270\345\212\240II/445-\344\270\244\346\225\260\347\233\270\345\212\240II.py" +++ /dev/null @@ -1,44 +0,0 @@ -# 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 - """ - s1, s2 = [], [] - while l1: - s1.append(l1.val) - l1 = l1.next - - while l2: - s2.append(l2.val) - l2 = l2.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 \ No newline at end of file diff --git "a/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" "b/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" deleted file mode 100644 index 64b8736..0000000 --- "a/452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def findMinArrowShots(self, points): - """ - :type points: List[List[int]] - :rtype: int - """ - if not points or not points[0]: - return 0 - - points.sort(key = lambda x:x[1]) - - arrow = points[0][1] - - res = 1 - for point in points: - if arrow < point[0]: - res += 1 - arrow = point[1] - - return res \ No newline at end of file diff --git "a/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" "b/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" deleted file mode 100644 index e8fc752..0000000 --- "a/460.LFU\347\274\223\345\255\230/460-LFU\347\274\223\345\255\230.py" +++ /dev/null @@ -1,60 +0,0 @@ -class LFUCache(object): - - def __init__(self, capacity): - """ - :type capacity: int - """ - self.use = {} # 浣跨敤鐨勯鐜 - self.cache = {} # 鍊 - self.size = capacity - self.arr = [] # 纭繚棰戠巼涓鏍锋椂锛屽垹闄ゆ渶杩戞病鏈変娇鐢 - - def get(self, key): - """ - :type key: int - :rtype: int - """ - if key in self.cache: - self.use[key] += 1 - self.arr.remove(key) - self.arr.append(key) - return self.cache[key] - else: - return -1 - - def put(self, key, value): - """ - :type key: int - :type value: int - :rtype: None - """ - if key in self.cache: - self.cache[key] = value - self.use[key] += 1 - self.arr.remove(key) - self.arr.append(key) - else: - if len(self.cache) < self.size: - self.cache[key] = value - self.use[key] = 1 - self.arr.append(key) - else: - if self.use: - v = min(self.use.values()) - lost = -1 - for x in self.arr: - if self.use[x] == v: - lost = x - break - self.cache.pop(lost) - self.use.pop(lost) - self.arr.remove(lost) - self.cache[key] = value - self.use[key] = 1 - self.arr.append(key) - - -# Your LFUCache object will be instantiated and called as such: -# obj = LFUCache(capacity) -# param_1 = obj.get(key) -# obj.put(key,value) \ No newline at end of file diff --git "a/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" "b/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" deleted file mode 100644 index 08cf39f..0000000 --- "a/466.\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260/466-\347\273\237\350\256\241\351\207\215\345\244\215\344\270\252\346\225\260.py" +++ /dev/null @@ -1,57 +0,0 @@ -class Solution(object): - def getMaxRepetitions(self, s1, n1, s2, n2): - """ - :type s1: str - :type n1: int - :type s2: str - :type n2: int - :rtype: int - """ - if n1 == 0: - return 0 - s1cnt, index, s2cnt = 0, 0, 0 - # recall 鏄垜浠敤鏉ユ壘寰幆鑺傜殑鍙橀噺锛屽畠鏄竴涓搱甯屾槧灏 - # 鎴戜滑濡備綍鎵惧惊鐜妭锛熷亣璁炬垜浠亶鍘嗕簡 s1cnt 涓 s1锛屾鏃跺尮閰嶅埌浜嗙 s2cnt 涓 s2 涓殑绗 index 涓瓧绗 - # 濡傛灉鎴戜滑涔嬪墠閬嶅巻浜 s1cnt' 涓 s1 鏃讹紝鍖归厤鍒扮殑鏄 s2cnt' 涓 s2 涓悓鏍风殑绗 index 涓瓧绗︼紝閭d箞灏辨湁寰幆鑺備簡 - # 鎴戜滑鐢 (s1cnt', s2cnt', index) 鍜 (s1cnt, s2cnt, index) 琛ㄧず涓ゆ鍖呭惈鐩稿悓 index 鐨勫尮閰嶇粨鏋 - # 閭d箞鍝堝笇鏄犲皠涓殑閿氨鏄 index锛屽煎氨鏄 (s1cnt', s2cnt') 杩欎釜浜屽厓缁 - # 寰幆鑺傚氨鏄紱 - # - 鍓 s1cnt' 涓 s1 鍖呭惈浜 s2cnt' 涓 s2 - # - 浠ュ悗鐨勬瘡 (s1cnt - s1cnt') 涓 s1 鍖呭惈浜 (s2cnt - s2cnt') 涓 s2 - # 閭d箞杩樹細鍓╀笅 (n1 - s1cnt') % (s1cnt - s1cnt') 涓 s1, 鎴戜滑瀵硅繖浜涗笌 s2 杩涜鏆村姏鍖归厤 - # 娉ㄦ剰 s2 瑕佷粠绗 index 涓瓧绗﹀紑濮嬪尮閰 - recall = dict() - while True: - # 鎴戜滑澶氶亶鍘嗕竴涓 s1锛岀湅鐪嬭兘涓嶈兘鎵惧埌寰幆鑺 - s1cnt += 1 - for ch in s1: - if ch == s2[index]: - index += 1 - if index == len(s2): - s2cnt, index = s2cnt + 1, 0 - # 杩樻病鏈夋壘鍒板惊鐜妭锛屾墍鏈夌殑 s1 灏辩敤瀹屼簡 - if s1cnt == n1: - return s2cnt // n2 - # 鍑虹幇浜嗕箣鍓嶇殑 index锛岃〃绀烘壘鍒颁簡寰幆鑺 - if index in recall: - s1cnt_prime, s2cnt_prime = recall[index] - # 鍓 s1cnt' 涓 s1 鍖呭惈浜 s2cnt' 涓 s2 - pre_loop = (s1cnt_prime, s2cnt_prime) - # 浠ュ悗鐨勬瘡 (s1cnt - s1cnt') 涓 s1 鍖呭惈浜 (s2cnt - s2cnt') 涓 s2 - in_loop = (s1cnt - s1cnt_prime, s2cnt - s2cnt_prime) - break - else: - recall[index] = (s1cnt, s2cnt) - - # ans 瀛樺偍鐨勬槸 S1 鍖呭惈鐨 s2 鐨勬暟閲忥紝鑰冭檻鐨勪箣鍓嶇殑 pre_loop 鍜 in_loop - ans = pre_loop[1] + (n1 - pre_loop[0]) // in_loop[0] * in_loop[1] - # S1 鐨勬湯灏捐繕鍓╀笅涓浜 s1锛屾垜浠毚鍔涜繘琛屽尮閰 - rest = (n1 - pre_loop[0]) % in_loop[0] - for i in range(rest): - for ch in s1: - if ch == s2[index]: - index += 1 - if index == len(s2): - ans, index = ans + 1, 0 - # S1 鍖呭惈 ans 涓 s2锛岄偅涔堝氨鍖呭惈 ans / n2 涓 S2 - return ans // n2 diff --git "a/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" "b/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" deleted file mode 100644 index 2091668..0000000 --- "a/476.\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260/476-\346\225\260\345\255\227\347\232\204\350\241\245\346\225\260.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def findComplement(self, num): - """ - :type num: int - :rtype: int - """ - s = bin(num)[2:] - b = "" - for ch in s: - - if ch == "0": - b += "1" - else: - b += "0" - # print b - return int(b,2) \ No newline at end of file diff --git "a/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" "b/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" deleted file mode 100644 index 9ce810a..0000000 --- "a/477.\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214/477-\346\261\211\346\230\216\350\267\235\347\246\273\346\200\273\345\222\214.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def totalHammingDistance(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - if not nums: - return 0 - res = 0 - mask = 1 - for i in range(32): - cnt_one = 0 - for num in nums: - cnt_one += 1 if num & mask else 0 - - res += cnt_one * (len(nums) - cnt_one) - mask = mask << 1 - return res - - \ No newline at end of file diff --git "a/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" "b/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" deleted file mode 100644 index a58af44..0000000 --- "a/482.\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226/482-\345\257\206\351\222\245\346\240\274\345\274\217\345\214\226.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def licenseKeyFormatting(self, S, K): - """ - :type S: str - :type K: int - :rtype: str - """ - s = "".join(S.split("-")).upper() - length_of_first_part = len(s) % K - if not length_of_first_part: - length_of_first_part = K - - res = s[:length_of_first_part] - for i in range(length_of_first_part, len(s), K): - res += "-" - res += s[i:i+K] - return res - \ No newline at end of file diff --git "a/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" "b/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" deleted file mode 100644 index b11b5a3..0000000 --- "a/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204/49-\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def groupAnagrams(self, strs): - """ - :type strs: List[str] - :rtype: List[List[str]] - """ - from collections import defaultdict - dic = defaultdict(list) - for word in strs: - sortedword = "".join(sorted(word)) - dic[sortedword].append(word) - - return dic.values() \ No newline at end of file diff --git "a/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" "b/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" deleted file mode 100644 index b488d0e..0000000 --- "a/496.\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I/496-\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\240I.py" +++ /dev/null @@ -1,24 +0,0 @@ -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/50.Pow(x,n)/50-Pow(x,n).py b/50.Pow(x,n)/50-Pow(x,n).py deleted file mode 100644 index 47442e6..0000000 --- a/50.Pow(x,n)/50-Pow(x,n).py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def myPow(self, x, n): - """ - :type x: float - :type n: int - :rtype: float - """ - return x ** n \ No newline at end of file diff --git "a/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" "b/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" deleted file mode 100644 index 05f6119..0000000 --- "a/516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227/516-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def longestPalindromeSubseq(self, s): - """ - :type s: str - :rtype: int - """ - n = len(s) - dp = [[0] * n for _ in range(n)] - - for i in range(n): - dp[i][i] = 1 - for j in range(i - 1, -1, -1): - if s[i] == s[j]: - dp[i][j] = dp[i - 1][j + 1] + 2 - else: - dp[i][j] = max(dp[i][j + 1], dp[i - 1][j]) - return dp[n - 1][0] \ No newline at end of file diff --git "a/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" "b/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" deleted file mode 100644 index 4358bfe..0000000 --- "a/53.\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214/53-\346\234\200\345\244\247\345\255\220\345\272\217\345\222\214.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def maxSubArray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - if not nums: - return 0 - dp = [0 for _ in nums] - dp[0] = nums[0] - - for i, x in enumerate(nums): - if i: - if dp[i - 1] > 0: - dp[i] = max(dp[i - 1] + x, dp[i]) - else: - dp[i] = x - - return max(dp) \ No newline at end of file diff --git "a/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" "b/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" deleted file mode 100644 index 8eafb66..0000000 --- "a/542.01\347\237\251\351\230\265/542-01\347\237\251\351\230\265.py" +++ /dev/null @@ -1,38 +0,0 @@ -from collections import deque -class Solution(object): - def updateMatrix(self, matrix): - """ - :type matrix: List[List[int]] - :rtype: List[List[int]] - """ - if not matrix or not matrix[0]: - return matrix - m, n = len(matrix), len(matrix[0]) - res = matrix[:] - - q = deque() - - for i in range(m): - for j in range(n): - if matrix[i][j] == 0: - q.append([[i, j], 0]) - - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - visited = [[0 for _ in range(n + 1)] for _ in range(m + 1)] - - while q: - tmp, distance = q.popleft() - x0, y0 = tmp[0], tmp[1] - - if matrix[x0][y0] == 1: - res[x0][y0] = distance - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x < m and 0 <= y < n and visited[x][y] != 1: - q.append([[x, y], distance + 1]) - visited[x][y] = 1 - return res \ No newline at end of file diff --git "a/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" "b/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" deleted file mode 100644 index 8814891..0000000 --- "a/543.\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204/543-\344\272\214\345\217\211\346\240\221\347\232\204\347\233\264\345\276\204.py" +++ /dev/null @@ -1,20 +0,0 @@ -# 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 diameterOfBinaryTree(self, root): - """ - :type root: TreeNode - :rtype: int - """ - if not root: - return 0 - def Height(node): - if not node: - return 0 - return 1 + max(Height(node.left), Height(node.right)) - return max(self.diameterOfBinaryTree(root.left), Height(root.left) + Height(root.right), self.diameterOfBinaryTree(root.right)) \ No newline at end of file diff --git "a/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" "b/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" deleted file mode 100644 index 8198fc2..0000000 --- "a/55.\350\267\263\350\267\203\346\270\270\346\210\217/55-\350\267\263\350\267\203\346\270\270\346\210\217.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def canJump(self, nums): - """ - :type nums: List[int] - :rtype: bool - """ - - max_jump = 0 - for index, num in enumerate(nums): - if index > max_jump: - return False - max_jump = max(max_jump, index + num) - return True \ No newline at end of file diff --git "a/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" "b/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" deleted file mode 100644 index 0283b38..0000000 --- "a/551.\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I/551-\345\255\246\347\224\237\345\207\272\345\213\244\350\256\260\345\275\225I.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def checkRecord(self, s): - """ - :type s: str - :rtype: bool - """ - return s.count("A") <= 1 and "LLL" not in s \ No newline at end of file diff --git "a/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" "b/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" deleted file mode 100644 index c005fbe..0000000 --- "a/56.\345\220\210\345\271\266\345\214\272\351\227\264/56-\345\220\210\345\271\266\345\214\272\351\227\264.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def merge(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: List[List[int]] - """ - if not intervals or not intervals[0]: - return intervals - - intervals = sorted(intervals, key = lambda x:x[0]) - - res = [] - start, end = intervals[0][0], intervals[0][1] - for interval in intervals: - s, e = interval[0], interval[1] - - if s <= end: # overlap - end = max(end, e) - else: - res.append([start, end]) - start, end = s, e - - res.append([start, end]) - return res \ No newline at end of file diff --git "a/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" "b/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" deleted file mode 100644 index 0b63b1d..0000000 --- "a/560.\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204/560-\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def subarraySum(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: int - """ - prefix = [] - - for i, num in enumerate(nums): - if i: - prefix.append(num + prefix[-1]) - else: - prefix.append(num) - - res = 0 - dic = collections.defaultdict(int) - dic[0] = 1 - for s in prefix: - res += dic[s - k] - dic[s] += 1 - return res \ No newline at end of file diff --git "a/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" "b/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" deleted file mode 100644 index de11b13..0000000 --- "a/561.\346\225\260\347\273\204\346\213\206\345\210\206I/561-\346\225\260\347\273\204\346\213\206\345\210\206I.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def arrayPairSum(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - return sum(sorted(nums)[::2]) \ No newline at end of file diff --git "a/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" "b/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" deleted file mode 100644 index 0f2bddc..0000000 --- "a/566.\351\207\215\345\241\221\347\237\251\351\230\265/566-\351\207\215\345\241\221\347\237\251\351\230\265.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def matrixReshape(self, nums, r, c): - """ - :type nums: List[List[int]] - :type r: int - :type c: int - :rtype: List[List[int]] - """ - m, n = len(nums), len(nums[0]) - if r * c != m * n: - return nums - nums = sum(nums, []) - - res = [[0 for _ in range(c)] for _ in range(r)] - - for i in range(r): - for j in range(c): - res[i][j] = nums[i * c + j] - - return res \ No newline at end of file diff --git "a/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" "b/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" deleted file mode 100644 index bc5a818..0000000 --- "a/57.\346\217\222\345\205\245\345\214\272\351\227\264/57-\346\217\222\345\205\245\345\214\272\351\227\264.py" +++ /dev/null @@ -1,35 +0,0 @@ -class Solution(object): - def insert(self, intervals, newInterval): - """ - :type intervals: List[List[int]] - :type newInterval: List[int] - :rtype: List[List[int]] - """ - - return self.merge(intervals + [newInterval]) - - - - def merge(self, intervals): - """ - :type intervals: List[List[int]] - :rtype: List[List[int]] - """ - if not intervals or not intervals[0]: - return intervals - - intervals = sorted(intervals, key = lambda x:x[0]) - - res = [] - start, end = intervals[0][0], intervals[0][1] - for interval in intervals: - s, e = interval[0], interval[1] - - if s <= end: # overlap - end = max(end, e) - else: - res.append([start, end]) - start, end = s, e - - res.append([start, end]) - return res \ No newline at end of file diff --git "a/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" "b/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" deleted file mode 100644 index 7456e24..0000000 --- "a/572.\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221/572-\345\217\246\344\270\200\344\270\252\346\240\221\347\232\204\345\255\220\346\240\221.py" +++ /dev/null @@ -1,32 +0,0 @@ -# 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 isSubtree(self, s, t): - """ - :type s: TreeNode - :type t: TreeNode - :rtype: bool - """ - - if not s and not t: - return True - if s and not t: - return False - if t and not s: - return False - - return self.isSameTree(t, s) or self.isSubtree(s.left, t) or self.isSubtree(s.right, t) - - def isSameTree(self, t1, t2): - if not t1 and not t2: - return True - if t1 and not t2: - return False - if t2 and not t1: - return False - return t1.val == t2.val and self.isSameTree(t1.left, t2.left) and self.isSameTree(t1.right, t2.right) \ No newline at end of file diff --git "a/58.\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/58-\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/58.\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/58-\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" deleted file mode 100644 index 77fb484..0000000 --- "a/58.\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/58-\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" +++ /dev/null @@ -1,9 +0,0 @@ -class Solution(object): - def lengthOfLastWord(self, s): - """ - :type s: str - :rtype: int - """ - if not s.split(): - return 0 - return len(s.split()[-1]) \ No newline at end of file diff --git "a/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" "b/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" deleted file mode 100644 index 33bc985..0000000 --- "a/581.\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204/581-\346\234\200\347\237\255\346\227\240\345\272\217\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def findUnsortedSubarray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - s = sorted(nums) - if s == nums: - return 0 - for i in range(len(s)): - if s[i] != nums[i]: - break - for j in range(len(s) - 1, -1, -1): - if s[j] != nums[j]: - break - # print i, j - # print s, nums - return len(s) - i - (len(s) - 1 -j) - \ No newline at end of file diff --git "a/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" "b/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" deleted file mode 100644 index 9347d22..0000000 --- "a/633.\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214/633-\345\271\263\346\226\271\346\225\260\344\271\213\345\222\214.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def judgeSquareSum(self, c): - """ - :type c: int - :rtype: bool - """ - for i in range(int(c ** 0.5) + 1): - t = c - i ** 2 - s = int (t ** 0.5) - if t == s ** 2: - return True - return False if c else True \ No newline at end of file diff --git "a/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" "b/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" deleted file mode 100644 index 99bf7db..0000000 --- "a/634.\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227/634-\345\257\273\346\211\276\346\225\260\347\273\204\347\232\204\351\224\231\344\275\215\346\216\222\345\210\227.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def findDerangement(self, n): - """ - :type n: int - :rtype: int - """ - res = 0 - for i in range(n + 1): - res = (i * res + (-1) ** i) % (10 ** 9 + 7) - return res \ No newline at end of file diff --git "a/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" "b/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" deleted file mode 100644 index e4e3e3c..0000000 --- "a/69.x\347\232\204\345\271\263\346\226\271\346\240\271/69-x\347\232\204\345\271\263\346\226\271\346\240\271.py" +++ /dev/null @@ -1,17 +0,0 @@ -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/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" "b/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" deleted file mode 100644 index 905712b..0000000 --- "a/695.\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257/695-\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.py" +++ /dev/null @@ -1,35 +0,0 @@ -class Solution(object): - def maxAreaOfIsland(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]) - self.res = 0 - self.tmp = 0 - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - - def dfs(x0, y0): - self.tmp += 1 - self.res = max(self.res, self.tmp) - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x< m and 0 <= y < n and grid[x][y] == 1: - grid[x][y] = 0 - dfs(x, y) - - - for i in range(m): - for j in range(n): - if grid[i][j]: - grid[i][j] = 0 - self.tmp = 0 - dfs(i, j) - return self.res \ No newline at end of file diff --git "a/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" "b/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" deleted file mode 100644 index bffc0f3..0000000 --- "a/698.\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206/698-\345\210\222\345\210\206\344\270\272k\344\270\252\347\233\270\347\255\211\347\232\204\345\255\220\351\233\206.py" +++ /dev/null @@ -1,39 +0,0 @@ -class Solution(object): - def canPartitionKSubsets(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: bool - """ - s = sum(nums) - if s % k != 0 or len(nums) < k: - return False - - target = s / k - - nums.sort(reverse = True) - visited = set() - - self.res = False - def dfs(cnt, tmp, start): - if tmp == target: - dfs(cnt - 1, 0, 0) - - if cnt == 0: - self.res = True - return - if not self.res: - for i in range(start, len(nums)): - if i not in visited and tmp + nums[i] <= target: - visited.add(i) - dfs(cnt, tmp + nums[i], i + 1) - visited.remove(i) - dfs(k, 0, 0) - return self.res - - - - - - - \ No newline at end of file diff --git "a/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" "b/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" deleted file mode 100644 index 81e9fd3..0000000 --- "a/72.\347\274\226\350\276\221\350\267\235\347\246\273/72-\347\274\226\350\276\221\350\267\235\347\246\273.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def minDistance(self, word1, word2): - """ - :type word1: str - :type word2: str - :rtype: int - """ - #鐢╠p[i][j]琛ㄧずword1[:i + 1], word2[:j + 1]杩欎釜闂鐨勮В - m, n = len(word1), len(word2) - dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] - - for i in range(m + 1): - dp[i][0] = i - - for i in range(n + 1): - dp[0][i] = i - - for i in range(1, m + 1): - for j in range(1, n + 1): - if word1[i - 1] == word2[j - 1]: - dp[i][j] = dp[i - 1][j - 1] - else: - dp[i][j] = 1 + min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) #鍒嗗埆瀵瑰簲鎻掑叆锛屾浛鎹紝鍒犻櫎 - - return dp[m][n] \ No newline at end of file diff --git "a/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" "b/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" deleted file mode 100644 index 58c9a94..0000000 --- "a/760.\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204/760-\346\211\276\345\207\272\345\217\230\344\275\215\346\230\240\345\260\204.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def anagramMappings(self, A, B): - """ - :type A: List[int] - :type B: List[int] - :rtype: List[int] - """ - - dic = dict() - for i, x in enumerate(B): - dic[x] = i - - return [dic[x] for x in A] \ No newline at end of file diff --git "a/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" "b/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" deleted file mode 100644 index 8216656..0000000 --- "a/763.\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264/763-\345\210\222\345\210\206\345\255\227\346\257\215\345\214\272\351\227\264.py" +++ /dev/null @@ -1,39 +0,0 @@ -class Solution(object): - def partitionLabels(self, S): - """ - :type S: str - :rtype: List[int] - """ - from collections import defaultdict - dic = defaultdict(list) - - for ch in "abcdefghijklmnopqrstuvwxyz": - for i, char in enumerate(S): - if char == ch: - dic[ch].append(i) - break - - for i in range(len(S) - 1, -1, -1): - if S[i] == ch: - dic[ch].append(i) - break - - - intervals = [] - for val in dic.values(): - intervals.append(val) - - intervals.sort() - #print intervals - - res = [] - start, end = 0, 0 - for s, e in intervals: - if s > end: - res.append(end - start + 1) - start, end = s, e - else: - end = max(e, end) - res.append(end - start + 1) - - return res \ No newline at end of file diff --git "a/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" "b/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" deleted file mode 100644 index 4b0e5c9..0000000 --- "a/771.\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264/771-\345\256\235\347\237\263\344\270\216\347\237\263\345\244\264.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def numJewelsInStones(self, J, S): - """ - :type J: str - :type S: str - :rtype: int - """ - J = set(J) - res = 0 - for s in S: - if s in J: - res += 1 - return res \ No newline at end of file diff --git "a/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" "b/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" deleted file mode 100644 index ad43f92..0000000 --- "a/792.\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260/792-\345\214\271\351\205\215\345\255\220\345\272\217\345\210\227\347\232\204\345\215\225\350\257\215\346\225\260.py" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution(object): - def numMatchingSubseq(self, S, words): - """ - :type S: str - :type words: List[str] - :rtype: int - """ - from collections import defaultdict - - dic = defaultdict(list) - for i, ch in enumerate(S): - dic[ch].append(i) - - res = 0 - for word in words: - pre = -1 - flag = True - for i, ch in enumerate(word): - l = dic[ch] - # 鍦╨鎵剧涓涓瘮pre澶х殑鍏冪礌 - idx = bisect.bisect(l, pre) - - if idx == len(l):# 娌℃壘鍒 - flag = False - break - pre = l[idx] - - if flag: - res += 1 - - return res \ No newline at end of file diff --git "a/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" "b/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" deleted file mode 100644 index 7b8a7be..0000000 --- "a/8.\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi)/8-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).py" +++ /dev/null @@ -1,36 +0,0 @@ -class Solution(object): - def myAtoi(self, s): - """ - :type str: str - :rtype: int - """ - s = s.strip() - - if not s: - return 0 - - sign = 1 - INT_MAX, INT_MIN = 2 ** 31 - 1, -(2 ** 31) - - if s[0] == "+": - s = s[1:] - elif s[0] == "-": - s = s[1:] - sign = -1 - elif not s[0].isdigit(): - return 0 - - num = "0" - for ch in s: - if ch.isdigit(): - num += ch - else: - break - - num = sign * int(num) - - if num > INT_MAX: - return INT_MAX - elif num < INT_MIN: - return INT_MIN - return num \ No newline at end of file diff --git "a/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" "b/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" deleted file mode 100644 index 59c336c..0000000 --- "a/809.\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227/809-\346\203\205\346\204\237\344\270\260\345\257\214\347\232\204\346\226\207\345\255\227.py" +++ /dev/null @@ -1,38 +0,0 @@ -class Solution(object): - def expressiveWords(self, S, words): - """ - :type S: str - :type words: List[str] - :rtype: int - """ - - s = set(S) - res = 0 - for word in words: - if len(S) < len(word): - continue - - i, j = 0, 0 - flag = 0 - while i < len(S) and j < len(word): - if S[i] != word[j]: - flag = 1 - break - pre = S[i] - cnt_i = 0 - while i < len(S) and S[i] == pre: - i += 1 - cnt_i += 1 - - cnt_j = 0 - while j < len(word) and word[j] == pre: - j += 1 - cnt_j += 1 - - # print cnt_i, cnt_j - if (cnt_i < 3 and cnt_i != cnt_j) or cnt_i < cnt_j: - flag = 1 - - if not flag and i == len(S): - res += 1 - return res \ No newline at end of file diff --git "a/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" "b/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" deleted file mode 100644 index 618a6c9..0000000 --- "a/820.\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201/820-\345\215\225\350\257\215\347\232\204\345\216\213\347\274\251\347\274\226\347\240\201.py" +++ /dev/null @@ -1,36 +0,0 @@ -class Trie(object): - def __init__(self): - """ - Initialize your data structure here. - """ - self.root = {} - self.char_cnt = 0 # 缁熻 a - z 瀛楃涓暟 - self.word_cnt = 0 # 缁熻缁撳熬绗 # 涓暟 - def insert(self, word): - """ - Inserts a word into the trie. - :type word: str - :rtype: None - """ - node = self.root - for char in word: # word 鍏ユ爲 - node = node.setdefault(char, {}) - - if not node: # not node 灏变唬琛ㄥ綋鍓 word 涓嶆槸涔嬪墠鏌愪竴 word 鐨勫悗缂 - self.word_cnt += 1 - self.char_cnt += len(word) - node["end"] = True - -class Solution(object): - def minimumLengthEncoding(self, words): - """ - :type words: List[str] - :rtype: int - """ - ttree = Trie() - - for word in sorted(words, key = lambda x:len(x), reverse = True): - # 鎸夐暱搴︾敱澶у埌灏忔帓搴忥紝鍐嶅皢姣忎釜 word 鍙嶅悜鎻掑叆鏍 - ttree.insert(word[::-1]) - # print ttree.char_cnt, ttree.word_cnt - return ttree.char_cnt + ttree.word_cnt \ No newline at end of file diff --git "a/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" "b/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" deleted file mode 100644 index a13282d..0000000 --- "a/836.\347\237\251\345\275\242\351\207\215\345\217\240/836-\347\237\251\345\275\242\351\207\215\345\217\240.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def isRectangleOverlap(self, rec1, rec2): - """ - :type rec1: List[int] - :type rec2: List[int] - :rtype: bool - """ - x1, y1, x2, y2 = rec1 - x3, y3, x4, y4 = rec2 - return (x3 - x2) * (x4 - x1) < 0 and (y3 - y2) * (y4 - y1) < 0 \ No newline at end of file diff --git "a/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" "b/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" deleted file mode 100644 index 970933d..0000000 --- "a/845.\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211/845-\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\351\225\277\345\261\261\350\204\211.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def longestMountain(self, A): - """ - :type A: List[int] - :rtype: int - """ - # a = sorted(A) - # if a == A or a[::-1] == A: - # return 0 - l, r = [0 for _ in A], [0 for _ in A] - - for i in range(1, len(A)): - if A[i] > A[i - 1]: - l[i] = l[i - 1] + 1 - - for i in range(len(A) - 2, -1, -1): - if A[i] > A[i + 1]: - r[i] = r[i + 1] + 1 - - res = 0 - for i in range(len(A)): - if l[i] and r[i] and l[i] + r[i] > 1: - res = max(l[i] + r[i] + 1, res) - return res \ No newline at end of file diff --git "a/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" "b/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" deleted file mode 100644 index 4a96cec..0000000 --- "a/876.\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271/876-\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.py" +++ /dev/null @@ -1,17 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def middleNode(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - slow, fast = head, head - while fast and fast.next: - slow = slow.next - fast = fast.next.next - return slow \ No newline at end of file diff --git "a/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" "b/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" deleted file mode 100644 index 53390d9..0000000 --- "a/887.\351\270\241\350\233\213\346\216\211\350\220\275/887-\351\270\241\350\233\213\346\216\211\350\220\275.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def superEggDrop(self, K, N): - """ - :type K: int - :type N: int - :rtype: int - """ - dp = [0] * (K + 1) - m = 0 - while dp[K] < N: - m += 1 - for k in range(K, 0, -1): - # print(m, k) - dp[k] = dp[k - 1] + dp[k] + 1 - return m \ No newline at end of file diff --git "a/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" "b/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" deleted file mode 100644 index a182a0b..0000000 --- "a/892.\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257/892-\344\270\211\347\273\264\345\275\242\344\275\223\347\232\204\350\241\250\351\235\242\347\247\257.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def surfaceArea(self, grid): - """ - :type grid: List[List[int]] - :rtype: int - """ - res = 0 - - for i in range(len(grid)): - for j in range(len(grid[0])): - if grid[i][j] > 0: res += 2 # 涓婂拰涓 - for r in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]: - if 0 <= r[0] < len(grid) and 0 <= r[1] < len(grid[0]): res += max(0, grid[i][j] - grid[r[0]][r[1]]) # 涓棿楂樺嚭鐩搁偦鏂瑰潡鐨勯儴鍒 - else: res += grid[i][j] # 鍓嶅悗宸﹀彸鏈澶栦晶 - - return res \ No newline at end of file diff --git "a/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" deleted file mode 100644 index 43e1110..0000000 --- "a/905.\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204/905-\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def sortArrayByParity(self, A): - """ - :type A: List[int] - :rtype: List[int] - """ - return sorted(A, key = lambda x:x % 2) \ No newline at end of file diff --git "a/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" "b/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" deleted file mode 100644 index ea57e4d..0000000 --- "a/912.\346\216\222\345\272\217\346\225\260\347\273\204/912-\346\216\222\345\272\217\346\225\260\347\273\204.py" +++ /dev/null @@ -1,7 +0,0 @@ -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/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" "b/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" deleted file mode 100644 index 609c27e..0000000 --- "a/914.\345\215\241\347\211\214\345\210\206\347\273\204/914-\345\215\241\347\211\214\345\210\206\347\273\204.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def hasGroupsSizeX(self, deck): - """ - :type deck: List[int] - :rtype: bool - """ - def gcd(a, b): - while b: - a, b = b, a % b - return a - return functools.reduce(gcd, collections.Counter(deck).values()) >= 2 \ No newline at end of file diff --git "a/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" "b/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" deleted file mode 100644 index 94e321e..0000000 --- "a/921.\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240/921-\344\275\277\346\213\254\345\217\267\346\234\211\346\225\210\347\232\204\346\234\200\345\260\221\346\267\273\345\212\240.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def minAddToMakeValid(self, S): - """ - :type S: str - :rtype: int - """ - stack = [] - dic = {"(":")", "{":"}", "[":"]"} - for ch in S: - if stack and stack[-1] in dic and dic[stack[-1]] == ch: - stack.pop() - else: - stack.append(ch) - return len(stack) \ No newline at end of file diff --git "a/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" "b/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" deleted file mode 100644 index ee36ba2..0000000 --- "a/945.\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217/945-\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def minIncrementForUnique(self, A): - """ - :type A: List[int] - :rtype: int - """ - i, ans = 0, 0 - for a in sorted(A): - ans += max(i - a, 0) - i = max(a, i) + 1 - return ans \ No newline at end of file diff --git "a/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" "b/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" deleted file mode 100644 index ca0caa0..0000000 --- "a/946.\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227/946-\351\252\214\350\257\201\346\240\210\345\272\217\345\210\227.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def validateStackSequences(self, pushed, popped): - """ - :type pushed: List[int] - :type popped: List[int] - :rtype: bool - """ - s = [] - popped = popped[::-1] - for num in pushed: - s.append(num) - while s and popped and s[-1] == popped[-1]: - s.pop() - popped.pop() - - return not s and not popped \ No newline at end of file diff --git "a/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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" deleted file mode 100644 index f474ff6..0000000 --- "a/973.\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271/973-\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" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def kClosest(self, points, K): - left, right, target = 0, len(points) - 1, K - 1 - while True: - pos = self.partition(points, left, right) - if pos == target: - return points[:pos + 1] - 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][0] ** 2 + nums[k][1] ** 2 - nums[left], nums[k] = nums[k], nums[left] - index = left - - for i in range(left + 1, right + 1): - if nums[i][0] ** 2 + nums[i][1] ** 2 < pivot: - index += 1 - nums[i], nums[index] = nums[index], nums[i] - nums[left], nums[index] = nums[index], nums[left] - return index #姝ゆ椂鎵鏈塱ndex宸︿晶鐨勫奸兘姣攏ums[index]澶э紝 鎵鏈夊彸渚х殑鍊奸兘姣攏ums[index]灏 diff --git "a/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" deleted file mode 100644 index 8da976b..0000000 --- "a/98.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/98-\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" +++ /dev/null @@ -1,20 +0,0 @@ -# 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 isValidBST(self, root): - """ - :type root: TreeNode - :rtype: 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/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" "b/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" deleted file mode 100644 index 5d9ce8b..0000000 --- "a/994.\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220/994-\350\205\220\347\203\202\347\232\204\346\251\230\345\255\220.py" +++ /dev/null @@ -1,43 +0,0 @@ -class Solution(object): - def orangesRotting(self, grid): - """ - :type grid: List[List[int]] - :rtype: int - """ - from collections import deque - if not grid or not grid[0]: - return 0 - - m, n = len(grid), len(grid[0]) - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - - queue = deque() - for i in range(m): - for j in range(n): - if grid[i][j] == 2: - queue.append((i, j)) - - res = 0 - while queue: - for i in range(len(queue)): - pair = queue.popleft() - x0, y0 = pair[0], pair[1] - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x < m and 0 <= y < n and grid[x][y] == 1: - grid[x][y] = 2 - queue.append((x, y)) - if not queue: - break - res += 1 - for i in range(m): - for j in range(n): - if grid[i][j] == 1: - return -1 - return res - - - \ No newline at end of file diff --git "a/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" "b/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" deleted file mode 100644 index 2254eb0..0000000 --- "a/999.\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260/999-\345\217\257\344\273\245\350\242\253\344\270\200\346\255\245\346\215\225\350\216\267\347\232\204\346\243\213\345\255\220\346\225\260.py" +++ /dev/null @@ -1,28 +0,0 @@ -class Solution(object): - def numRookCaptures(self, board): - """ - :type board: List[List[str]] - :rtype: int - """ - self.res,m,n = 0,len(board),len(board[0]) - - def check(n): - if n == 'B' or n == 'p': - if n == 'p':self.res += 1 - return False - return True - - for i in range(m): - for j in range(n): - if board[i][j] == 'R': - for u in range(i-1,-1,-1): - if not check(board[u][j]):break - for d in range(i+1,m): - if not check(board[d][j]):break - for l in range(j-1,-1,-1): - if not check(board[i][l]):break - for r in range(j+1,n): - if not check(board[i][r]):break - break - return self.res - diff --git "a/\345\211\221\346\214\207Offer03.\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\207Offer03-\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\207Offer03.\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\207Offer03-\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" deleted file mode 100644 index cf94ed9..0000000 --- "a/\345\211\221\346\214\207Offer03.\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\207Offer03-\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" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def findRepeatNumber(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - visited = set() - for num in nums: - if num in visited: - return num - visited.add(num) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" "b/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" deleted file mode 100644 index d782a75..0000000 --- "a/\345\211\221\346\214\207Offer04.\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/\345\211\221\346\214\207Offer04-\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def findNumberIn2DArray(self, matrix, target): - """ - :type matrix: List[List[int]] - :type target: int - :rtype: bool - """ - - if not matrix or not matrix[0]: - return False - m, n = len(matrix), len(matrix[0]) - - x, y = m - 1, 0 - while 0 <= x < m and 0 <= y < n: - if matrix[x][y] == target: - return True - elif matrix[x][y] > target: - x -= 1 - else: - y += 1 - return False \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" "b/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" deleted file mode 100644 index 33c8f86..0000000 --- "a/\345\211\221\346\214\207Offer05.\346\233\277\346\215\242\347\251\272\346\240\274/\345\211\221\346\214\207Offer05-\346\233\277\346\215\242\347\251\272\346\240\274.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def replaceSpace(self, s): - """ - :type s: str - :rtype: str - """ - return s.replace(" ", "%20") \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer06.\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\207Offer06-\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\207Offer06.\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\207Offer06-\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" deleted file mode 100644 index 445af2a..0000000 --- "a/\345\211\221\346\214\207Offer06.\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\207Offer06-\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" +++ /dev/null @@ -1,17 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def reversePrint(self, head): - """ - :type head: ListNode - :rtype: List[int] - """ - res = [] - while head: - res.append(head.val) - head = head.next - return res[::-1] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" deleted file mode 100644 index fc39bbe..0000000 --- "a/\345\211\221\346\214\207Offer07.\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer07-\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.py" +++ /dev/null @@ -1,22 +0,0 @@ -# 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:1 + idx], inorder[:idx]) - root.right = self.buildTree(preorder[1 + idx:], inorder[idx + 1:]) - - return root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" "b/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" deleted file mode 100644 index 99882bd..0000000 --- "a/\345\211\221\346\214\207Offer09.\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/\345\211\221\346\214\207Offer09-\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.py" +++ /dev/null @@ -1,28 +0,0 @@ -class CQueue(object): - - def __init__(self): - self.s1 = [] - self.s2 = [] - - def appendTail(self, value): - """ - :type value: int - :rtype: None - """ - self.s1.append(value) - - def deleteHead(self): - """ - :rtype: int - """ - if not self.s2: - while self.s1: - self.s2.append(self.s1.pop()) - return self.s2.pop() if self.s2 else -1 - - - -# Your CQueue object will be instantiated and called as such: -# obj = CQueue() -# obj.appendTail(value) -# param_2 = obj.deleteHead() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" "b/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" deleted file mode 100644 index ff52e1b..0000000 --- "a/\345\211\221\346\214\207Offer10-I.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/\345\211\221\346\214\207Offer10-I-\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def fib(self, n): - """ - :type n: int - :rtype: int - """ - if n == 0: - return 0 - MOD = 10 ** 9 + 7 - cnt = 1 - pre, cur = 0, 1 - while cnt < n: - tmp = cur + pre - pre = cur - cur = tmp - cnt += 1 - return cur % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" "b/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" deleted file mode 100644 index e07ceb3..0000000 --- "a/\345\211\221\346\214\207Offer10-II.\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/\345\211\221\346\214\207Offer10-II-\351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def numWays(self, n): - """ - :type n: int - :rtype: int - """ - if n == 0: - return 1 - MOD = 10 ** 9 + 7 - cnt = 1 - pre, cur = 1, 1 - while cnt < n: - tmp = cur + pre - pre = cur - cur = tmp - cnt += 1 - return cur % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" deleted file mode 100644 index 052370a..0000000 --- "a/\345\211\221\346\214\207Offer11.\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227/\345\211\221\346\214\207Offer11-\346\227\213\350\275\254\346\225\260\347\273\204\347\232\204\346\234\200\345\260\217\346\225\260\345\255\227.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def minArray(self, numbers): - """ - :type numbers: List[int] - :rtype: int - """ - return min(numbers) - # if not numbers: - # return None - - # if numbers[0] < numbers[-1]: - # return numbers[0] - - # left, right = 0, len(numbers) - - # while left <= right: - # mid = (left + right) // 2 - - # if numbers[mid] < numbers[mid - 1]: - # return numbers[mid] - # elif numbers[mid] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" "b/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" deleted file mode 100644 index 29eb51e..0000000 --- "a/\345\211\221\346\214\207Offer12.\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer12-\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.py" +++ /dev/null @@ -1,33 +0,0 @@ -class Solution(object): - def exist(self, board, word): - """ - :type board: List[List[str]] - :type word: str - :rtype: bool - """ - - m, n = len(board), len(board[0]) - - self.res = False - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] - def dfs(x0, y0, start): - if start == len(word) - 1 or self.res: - self.res = True - return - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - - if 0 <= x < m and 0 <= y < n and (x, y) not in visited and board[x][y] == word[start + 1]: - visited.add((x, y)) - dfs(x, y, start + 1) - visited.remove((x, y)) - - for i in range(m): - for j in range(n): - if board[i][j] == word[0]: - visited = set([(i, j)]) - dfs(i, j, 0) - return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" "b/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" deleted file mode 100644 index 92f631f..0000000 --- "a/\345\211\221\346\214\207Offer13.\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/\345\211\221\346\214\207Offer13-\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.py" +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def movingCount(self, m, n, k): - """ - :type m: int - :type n: int - :type k: int - :rtype: int - """ - - def dis(x, y): - res = 0 - while x: - res += x%10 - x //= 10 - while y: - res += y%10 - y //= 10 - return res - dp = [[False]*105 for _ in range(105)] - dp[0][0] = True - ans = 1 - for i in range(m): - for j in range(n): - if i==0 and j==0: - continue - if ((i!=0 and dp[i-1][j]) or (j!=0 and dp[i][j-1])) and dis(i, j)<=k: - dp[i][j] = True - ans += 1 - return ans \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" "b/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" deleted file mode 100644 index 767f3b1..0000000 --- "a/\345\211\221\346\214\207Offer14-I.\345\211\252\347\273\263\345\255\220/\345\211\221\346\214\207Offer14-I-\345\211\252\347\273\263\345\255\220.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution(object): - def cuttingRope(self, n): - """ - :type n: int - :rtype: int - """ - # dp[i][j] ba changdu wei i de shengzi qiecheng j duan de daan - if n == 2: - return 1 - if n == 3: - return 2 - dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)] - - for i in range(n + 1): - dp[i][0] = i - - for i in range(n + 1): - for j in range(i): - for k in range(i + 1, n + 1): - dp[k][j + 1] = max((k - i) * dp[i][j], dp[k][j + 1]) - - return max(dp[-1]) - - diff --git "a/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" "b/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" deleted file mode 100644 index b38bd18..0000000 --- "a/\345\211\221\346\214\207Offer14-II.\345\211\252\347\273\263\345\255\220II/\345\211\221\346\214\207Offer14-II-\345\211\252\347\273\263\345\255\220II.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def cuttingRope(self, n): - """ - :type n: int - :rtype: int - """ - if n <= 3: - return n - 1 - - res, MOD = 1, 10 ** 9 + 7 - while n > 4: - res = (res * 3) % MOD - n -= 3 - - return res * n % MOD \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" "b/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" deleted file mode 100644 index 06e5754..0000000 --- "a/\345\211\221\346\214\207Offer15.\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/\345\211\221\346\214\207Offer15-\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution(object): - def hammingWeight(self, n): - """ - :type n: int - :rtype: int - """ - res = 0 - while n: - n = n & (n - 1) - res += 1 - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" "b/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" deleted file mode 100644 index ede02bf..0000000 --- "a/\345\211\221\346\214\207Offer16.\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/\345\211\221\346\214\207Offer16-\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def myPow(self, x, n): - """ - :type x: float - :type n: int - :rtype: float - """ - if n == 0: - return 1 - if n == 1: - return x - if n == 2: - return x * x - - flag = 0 - if n < 0: - flag = 1 - n = -n - - if n % 2 == 0: - res = self.myPow(self.myPow(x, n // 2), 2) - else: - res = self.myPow(self.myPow(x, n // 2), 2) * x - - return res if not flag else 1.0 / res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" "b/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" deleted file mode 100644 index 23f7bb5..0000000 --- "a/\345\211\221\346\214\207Offer17.\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260/\345\211\221\346\214\207Offer17-\346\211\223\345\215\260\344\273\2161\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def printNumbers(self, n): - """ - :type n: int - :rtype: List[int] - """ - return [i for i in range(1, 10 ** n)] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" "b/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" deleted file mode 100644 index 16e41cd..0000000 --- "a/\345\211\221\346\214\207Offer18.\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/\345\211\221\346\214\207Offer18-\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271.py" +++ /dev/null @@ -1,24 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def deleteNode(self, head, val): - """ - :type head: ListNode - :type val: int - :rtype: ListNode - """ - - dummy = ListNode(-1) - dummy.next = head - - p = dummy - while p: - if p.next and p.next.val == val: - p.next = p.next.next - break - p = p.next - return dummy.next \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" "b/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" deleted file mode 100644 index 1f91ed9..0000000 --- "a/\345\211\221\346\214\207Offer21.\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242/\345\211\221\346\214\207Offer21-\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def exchange(self, nums): - """ - :type nums: List[int] - :rtype: List[int] - """ - left, right = 0, len(nums) - 1 - - while left < right: - if not nums[left] % 2 and nums[right] % 2: - nums[left], nums[right] = nums[right], nums[left] - if nums[left] % 2: - left += 1 - if not nums[right] % 2: - right -= 1 - return nums \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer22.\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\207Offer22-\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\207Offer22.\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\207Offer22-\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" deleted file mode 100644 index 2d5e9cf..0000000 --- "a/\345\211\221\346\214\207Offer22.\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\207Offer22-\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" +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def getKthFromEnd(self, head, k): - """ - :type head: ListNode - :type k: int - :rtype: ListNode - """ - p1, p2 = head, head - while k: - k -= 1 - p2 = p2.next - - while p2: - p1 = p1.next - p2 = p2.next - - return p1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" deleted file mode 100644 index d629e01..0000000 --- "a/\345\211\221\346\214\207Offer24.\345\217\215\350\275\254\351\223\276\350\241\250/\345\211\221\346\214\207Offer24-\345\217\215\350\275\254\351\223\276\350\241\250.py" +++ /dev/null @@ -1,20 +0,0 @@ -# Definition for singly-linked list. -# class ListNode(object): -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution(object): - def reverseList(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if not head or not head.next: - return head - - p = self.reverseList(head.next) - head.next.next = head - head.next = None - - return p \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" deleted file mode 100644 index 8252172..0000000 --- "a/\345\211\221\346\214\207Offer25.\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/\345\211\221\346\214\207Offer25-\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.py" +++ /dev/null @@ -1,33 +0,0 @@ -# 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 - """ - p = l1 - list1 = [] - list2 = [] - while p: - list1.append(p.val) - p = p.next - p = l2 - while p: - list2.append(p.val) - p = p.next - - l3 = sorted(list1 + list2) - - dummy = ListNode(-1) - p = dummy - for num in l3: - p.next = ListNode(num) - p = p.next - - return dummy.next \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\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\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" deleted file mode 100644 index 71ab723..0000000 --- "a/\345\211\221\346\214\207Offer27.\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/\345\211\221\346\214\207Offer27-\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.py" +++ /dev/null @@ -1,19 +0,0 @@ -# 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 mirrorTree(self, root): - """ - :type root: TreeNode - :rtype: TreeNode - """ - if not root: - return root - - root.left, root.right = self.mirrorTree(root.right), self.mirrorTree(root.left) - - return root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" deleted file mode 100644 index ec0c7c3..0000000 --- "a/\345\211\221\346\214\207Offer28.\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer28-\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.py" +++ /dev/null @@ -1,23 +0,0 @@ -# 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 isSymmetric(self, root): - """ - :type root: TreeNode - :rtype: bool - """ - if not root: - return True - - def check(root1, root2): - if not root1 and not root2: - return True - if not root1 or not root2: - return False - return root1.val == root2.val and check(root1.left, root2.right) and check(root1.right, root2.left) - return check(root, root) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" "b/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" deleted file mode 100644 index 5c212b0..0000000 --- "a/\345\211\221\346\214\207Offer29.\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/\345\211\221\346\214\207Offer29-\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.py" +++ /dev/null @@ -1,45 +0,0 @@ -class Solution(object): - def spiralOrder(self, matrix): - """ - :type matrix: List[List[int]] - :rtype: List[int] - """ - if not matrix or not matrix[0]: - return matrix - m, n = len(matrix), len(matrix[0]) - - x, y = 0, 0 - state = "r" - cnt = 0 - res = [] - visited = set() - while cnt < m * n: - res.append(matrix[x][y]) - visited.add((x, y)) - if state == "r": - if y + 1 < n and (x, y + 1) not in visited: - y += 1 - else: - x += 1 - state = "d" - elif state == "d": - if x + 1 < m and (x + 1, y) not in visited: - x += 1 - else: - y -= 1 - state = "l" - elif state == "l": - if y - 1 >= 0 and (x, y - 1) not in visited: - y -= 1 - else: - x -= 1 - state = "u" - elif state == "u": - if x - 1 >= 0 and (x - 1, y) not in visited: - x -= 1 - else: - y += 1 - state = "r" - cnt += 1 - return res - \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" "b/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" deleted file mode 100644 index 787a395..0000000 --- "a/\345\211\221\346\214\207Offer30.\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/\345\211\221\346\214\207Offer30-\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.py" +++ /dev/null @@ -1,50 +0,0 @@ -class MinStack(object): - - def __init__(self): - """ - initialize your data structure here. - """ - self.stack = [] - self.min_s = [] - - def push(self, x): - """ - :type x: int - :rtype: None - """ - if not self.stack: - self.stack = [x] - self.min_s = [x] - else: - self.stack.append(x) - if self.min_s[-1] < x: - self.min_s.append(self.min_s[-1]) - else: - self.min_s.append(x) - - def pop(self): - """ - :rtype: None - """ - self.stack.pop() - self.min_s.pop() - - def top(self): - """ - :rtype: int - """ - return self.stack[-1] - - def min(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.min() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" deleted file mode 100644 index 4dfe5b1..0000000 --- "a/\345\211\221\346\214\207Offer31.\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227/\345\211\221\346\214\207Offer31-\346\240\210\347\232\204\345\216\213\345\205\245\343\200\201\345\274\271\345\207\272\345\272\217\345\210\227.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution(object): - def validateStackSequences(self, pushed, popped): - """ - :type pushed: List[int] - :type popped: List[int] - :rtype: bool - """ - if not pushed and not popped: - return True - if not pushed or not popped: - return False - stack = [] - popped = popped[::-1] - for i, num in enumerate(pushed): - stack.append(num) - while stack and stack[-1] == popped[-1]: - stack.pop() - popped.pop() - return not popped \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" "b/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" deleted file mode 100644 index bffbb72..0000000 --- "a/\345\211\221\346\214\207Offer32-I.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/\345\211\221\346\214\207Offer32-I-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.py" +++ /dev/null @@ -1,28 +0,0 @@ -# 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 levelOrder(self, root): - """ - :type root: TreeNode - :rtype: List[int] - """ - from collections import deque - if not root: - return [] - - queue = deque([root]) - res = [] - while queue: - 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 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" "b/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" deleted file mode 100644 index 0798c1d..0000000 --- "a/\345\211\221\346\214\207Offer32-II.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II/\345\211\221\346\214\207Offer32-II-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221II.py" +++ /dev/null @@ -1,30 +0,0 @@ -# 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 levelOrder(self, root): - """ - :type root: TreeNode - :rtype: List[List[int]] - """ - from collections import deque - if not root: - return [] - - queue = deque([root]) - res = [] - while queue: - tmp = [] - for _ in range(len(queue)): - cur = queue.popleft() - tmp.append(cur.val) - if cur.left: - queue.append(cur.left) - if cur.right: - queue.append(cur.right) - res.append(tmp) - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" "b/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" deleted file mode 100644 index 1456eae..0000000 --- "a/\345\211\221\346\214\207Offer32-III.\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III/\345\211\221\346\214\207Offer32-III-\344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221III.py" +++ /dev/null @@ -1,35 +0,0 @@ -# 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 levelOrder(self, root): - """ - :type root: TreeNode - :rtype: List[List[int]] - """ - from collections import deque - if not root: - return [] - - queue = deque([root]) - res = [] - flag = 1 - while queue: - tmp = [] - for _ in range(len(queue)): - cur = queue.popleft() - tmp.append(cur.val) - if cur.left: - queue.append(cur.left) - if cur.right: - queue.append(cur.right) - if flag: - res.append(tmp) - else: - res.append(tmp[::-1]) - flag = 1 - flag - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" deleted file mode 100644 index 0d2fd26..0000000 --- "a/\345\211\221\346\214\207Offer33.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/\345\211\221\346\214\207Offer33-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.py" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution(object): - def verifyPostorder(self, postorder): - """ - :type postorder: List[int] - :rtype: bool - """ - if not postorder or len(postorder) == 1: - return True - - for i in range(len(postorder)): - if postorder[i] > postorder[-1]: - break - if any(postorder[j] < postorder[-1] for j in range(i, len(postorder) - 1)): - return False - - if i == len(postorder): - # no right subtree - left = postorder[:-1] - right = None - else: - left = postorder[:i] - right = postorder[i:-1] - - return self.verifyPostorder(left) and self.verifyPostorder(right) - \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" "b/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" deleted file mode 100644 index 6f40ee3..0000000 --- "a/\345\211\221\346\214\207Offer34.\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/\345\211\221\346\214\207Offer34-\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.py" +++ /dev/null @@ -1,31 +0,0 @@ -# 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, summ): - """ - :type root: TreeNode - :type sum: int - :rtype: List[List[int]] - """ - self.res = [] - - def dfs(node, path, s): - if not node: - return - - if not node.left and not node.right: - if s + node.val == summ: - path.append(node.val) - self.res.append(path) - return - - dfs(node.left, path + [node.val], s + node.val) - dfs(node.right, path + [node.val], s + node.val) - - dfs(root, [], 0) - return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer35.\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\207Offer35-\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\207Offer35.\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\207Offer35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" deleted file mode 100644 index 9de38d5..0000000 --- "a/\345\211\221\346\214\207Offer35.\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\207Offer35-\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.py" +++ /dev/null @@ -1,30 +0,0 @@ -""" -# Definition for a Node. -class Node: - def __init__(self, x, next=None, random=None): - self.val = int(x) - self.next = next - self.random = random -""" -class Solution(object): - def copyRandomList(self, head): - """ - :type head: Node - :rtype: Node - """ - mapping = {} # key is the old node, val is the new node - - p = head - while p: - mapping[p] = Node(p.val) - p = p.next - - p = head - while p: - if p.next: - mapping[p].next = mapping[p.next] - if p.random: - mapping[p].random = mapping[p.random] - p = p.next - - return mapping[head] if head else head \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" "b/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" deleted file mode 100644 index 669fb96..0000000 --- "a/\345\211\221\346\214\207Offer36.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250/\345\211\221\346\214\207Offer36-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.py" +++ /dev/null @@ -1,47 +0,0 @@ -""" -# Definition for a Node. -class Node(object): - def __init__(self, val, left=None, right=None): - self.val = val - self.left = left - self.right = right -""" -class Solution(object): - def treeToDoublyList(self, root): - """ - :type root: Node - :rtype: Node - """ - if not root: - return root - if not root.left and not root.right: - root.left = root - root.right = root - return root - - left = self.treeToDoublyList(root.left) - right = self.treeToDoublyList(root.right) - if root.left and root.right: - left_tail = left.left - right_tail = right.left - - left_tail.right = root - root.left = left_tail - root.right = right - right.left = root - - left.left = right_tail - right_tail.right = left - elif root.left: - left_tail = left.left - left_tail.right = root - root.left = left_tail - left.left = root - root.right = left - elif root.right: - right_tail = right.left - root.right = right - root.left = right_tail - right_tail.right = root - right.left = root - return left if left else root \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" "b/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" deleted file mode 100644 index c61bd6e..0000000 --- "a/\345\211\221\346\214\207Offer38.\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227/\345\211\221\346\214\207Offer38-\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def permutation(self, s): - """ - :type s: str - :rtype: List[str] - """ - from itertools import permutations - res = [] - visited = set() - for item in list(permutations(s)): - s = "".join(item) - if s not in visited: - res.append(s) - visited.add(s) - - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" deleted file mode 100644 index b0e5086..0000000 --- "a/\345\211\221\346\214\207Offer39.\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer39-\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def majorityElement(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - return sorted(nums)[len(nums) // 2] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" "b/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" deleted file mode 100644 index 50bd4bf..0000000 --- "a/\345\211\221\346\214\207Offer40.\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/\345\211\221\346\214\207Offer40-\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def getLeastNumbers(self, arr, k): - """ - :type arr: List[int] - :type k: int - :rtype: List[int] - """ - from heapq import * - - queue = [] - for num in arr: - if len(queue) < k: - heappush(queue, -num) - else: - if queue and queue[0] < num: - heappush(queue, -num) - heappop(queue) - return [-item for item in queue] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" "b/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" deleted file mode 100644 index d4b9334..0000000 --- "a/\345\211\221\346\214\207Offer42.\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214/\345\211\221\346\214\207Offer42-\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def maxSubArray(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - prefix = [0 for _ in nums] - - prefix[0] = nums[0] - min_s = min(0, nums[0]) - res = nums[0] - for i in range(1, len(nums)): - prefix[i] = prefix[i - 1] + nums[i] - res = max(prefix[i] - min_s, res) - min_s = min(min_s, prefix[i]) - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" "b/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" deleted file mode 100644 index 86bf71d..0000000 --- "a/\345\211\221\346\214\207Offer47.\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274/\345\211\221\346\214\207Offer47-\347\244\274\347\211\251\347\232\204\346\234\200\345\244\247\344\273\267\345\200\274.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def maxValue(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]) - - for i in range(1, n): - grid[0][i] += grid[0][i - 1] - - for i in range(1, m): - grid[i][0] += grid[i - 1][0] - - for i in range(1, m): - for j in range(1, n): - grid[i][j] += max(grid[i - 1][j], grid[i][j - 1]) - - return grid[-1][-1] - \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer52.\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\207Offer52-\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\207Offer52.\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\207Offer52-\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" deleted file mode 100644 index 120f097..0000000 --- "a/\345\211\221\346\214\207Offer52.\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\207Offer52-\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" +++ /dev/null @@ -1,39 +0,0 @@ -# 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 - """ - 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 - - cnt = la - lb - p = headA - while cnt: - cnt -= 1 - p = p.next - - - while p != headB: - p = p.next - headB = headB.next - return p \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer53-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\207Offer53-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\207Offer53-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\207Offer53-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" deleted file mode 100644 index 8b4c0c6..0000000 --- "a/\345\211\221\346\214\207Offer53-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\207Offer53-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" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def search(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: int - """ - return nums.count(target) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" deleted file mode 100644 index f15c45d..0000000 --- "a/\345\211\221\346\214\207Offer53-II.0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer53-II-0\357\275\236n-1\344\270\255\347\274\272\345\244\261\347\232\204\346\225\260\345\255\227.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution(object): - def missingNumber(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - for i, num in enumerate(nums): - if num == len(nums): - continue - if num != i: - nums[num], nums[i] = nums[i], nums[num] - - for i in range(len(nums)): - if nums[i] != i: - return i - return len(nums) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer54.\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\207Offer54-\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\207Offer54.\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\207Offer54-\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" deleted file mode 100644 index 6d799dd..0000000 --- "a/\345\211\221\346\214\207Offer54.\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\207Offer54-\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" +++ /dev/null @@ -1,36 +0,0 @@ -# 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 kthLargest(self, root, k): - """ - :type root: TreeNode - :type k: int - :rtype: int - """ - def inorder(node): - if not node: - return [] - return inorder(node.left) + [node.val] + inorder(node.right) - - return inorder(root)[-k] -# self.res = None -# def dfs(node, left): -# if not node: -# return None - -# if not self.res: -# dfs(node.right, left) -# if node.right: -# left -= 1 -# if left == 1: -# self.res = node.val -# return -# dfs(node.left, left - 1) - -# dfs(root, k) -# return self.res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-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\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" deleted file mode 100644 index e3b62e7..0000000 --- "a/\345\211\221\346\214\207Offer55-I.\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/\345\211\221\346\214\207Offer55-I-\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.py" +++ /dev/null @@ -1,16 +0,0 @@ -# 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 maxDepth(self, root): - """ - :type root: TreeNode - :rtype: int - """ - if not root: - return 0 - return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" "b/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" deleted file mode 100644 index cc91968..0000000 --- "a/\345\211\221\346\214\207Offer57-II.\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227/\345\211\221\346\214\207Offer57-II-\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.py" +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def findContinuousSequence(self, target): - """ - :type target: int - :rtype: List[List[int]] - """ - from collections import deque - window = deque() - res = [] - s = 0 - i = 1 - while i < target // 2 + 3: - if s == target: - res.append(list(window)) - if s <= target: - window.append(i) - s += i - i += 1 - elif s > target: - s -= window.popleft() - - return res diff --git "a/\345\211\221\346\214\207Offer57.\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\207Offer57-\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\207Offer57.\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\207Offer57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" deleted file mode 100644 index b1a4b6d..0000000 --- "a/\345\211\221\346\214\207Offer57.\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\207Offer57-\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution(object): - def twoSum(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - left, right = 0, len(nums) - 1 - while left < right: - s = nums[left] + nums[right] - - if s == target: - return [nums[left], nums[right]] - elif s > target: - right -= 1 - else: - left += 1 \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-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\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" deleted file mode 100644 index 8e4cadf..0000000 --- "a/\345\211\221\346\214\207Offer58-II.\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262/\345\211\221\346\214\207Offer58-II-\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def reverseLeftWords(self, s, n): - """ - :type s: str - :type n: int - :rtype: str - """ - return s[n:] + s[:n] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" "b/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" deleted file mode 100644 index 8954ae7..0000000 --- "a/\345\211\221\346\214\207Offer59-II.\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/\345\211\221\346\214\207Offer59-II-\351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274.py" +++ /dev/null @@ -1,35 +0,0 @@ -class MaxQueue(object): - - def __init__(self): - from collections import deque - self.queue = deque([]) - def max_value(self): - """ - :rtype: int - """ - if self.queue: - return max(self.queue) - return -1 - - def push_back(self, value): - """ - :type value: int - :rtype: None - """ - self.queue.append(value) - - - def pop_front(self): - """ - :rtype: int - """ - if not self.queue: - return -1 - return self.queue.popleft() - - -# Your MaxQueue object will be instantiated and called as such: -# obj = MaxQueue() -# param_1 = obj.max_value() -# obj.push_back(value) -# param_3 = obj.pop_front() \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" "b/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" deleted file mode 100644 index 9690d6d..0000000 --- "a/\345\211\221\346\214\207Offer62.\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227/\345\211\221\346\214\207Offer62-\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution(object): - def lastRemaining(self, n, m): - """ - :type n: int - :type m: int - :rtype: int - """ - if n == 1: - return 0 - return (self.lastRemaining(n - 1, m) + m) % n \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" "b/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" deleted file mode 100644 index 325ada7..0000000 --- "a/\345\211\221\346\214\207Offer63.\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246/\345\211\221\346\214\207Offer63-\350\202\241\347\245\250\347\232\204\346\234\200\345\244\247\345\210\251\346\266\246.py" +++ /dev/null @@ -1,12 +0,0 @@ -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/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" "b/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" deleted file mode 100644 index c8160ca..0000000 --- "a/\345\211\221\346\214\207Offer64.\346\261\2021+2+\342\200\246+n/\345\211\221\346\214\207Offer64-\346\261\2021+2+\342\200\246+n.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def sumNums(self, n): - """ - :type n: int - :rtype: int - """ - return sum(range(1, n + 1)) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" "b/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" deleted file mode 100644 index 02652bd..0000000 --- "a/\345\211\221\346\214\207Offer65.\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225/\345\211\221\346\214\207Offer65-\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def add(self, a, b): - """ - :type a: int - :type b: int - :rtype: int - """ - return sum([a, b]) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" "b/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" deleted file mode 100644 index 5c9dd47..0000000 --- "a/\345\211\221\346\214\207Offer66.\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204/\345\211\221\346\214\207Offer66-\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def constructArr(self, a): - """ - :type a: List[int] - :rtype: List[int] - """ - left = [1 for _ in a] - right = [1 for _ in a] - for i in range(1, len(a)): - left[i] = left[i - 1] * a[i - 1] - - for i in range(len(a) - 2, -1, -1): - right[i] = right[i + 1] * a[i + 1] - - return [left[i] * right[i] for i in range(len(a))] \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" deleted file mode 100644 index a00d561..0000000 --- "a/\345\211\221\346\214\207Offer68-I.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-I-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" +++ /dev/null @@ -1,20 +0,0 @@ -# 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 lowestCommonAncestor(self, root, p, q): - """ - :type root: TreeNode - :type p: TreeNode - :type q: TreeNode - :rtype: TreeNode - """ - if min(p.val, q.val) <= root.val <= max(p.val, q.val): - return root - if max(p.val, q.val) < root.val: - return self.lowestCommonAncestor(root.left, p, q) - return self.lowestCommonAncestor(root.right, p, q) \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" deleted file mode 100644 index 09cbf64..0000000 --- "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" +++ /dev/null @@ -1,23 +0,0 @@ -# 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 lowestCommonAncestor(self, root, p, q): - """ - :type root: TreeNode - :type p: TreeNode - :type q: TreeNode - :rtype: TreeNode - """ - if root in [None, p, q]: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - - if left and right: - return root - return left or right \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.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\23001.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\23001.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\23001.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" deleted file mode 100644 index 38a15c6..0000000 --- "a/\351\235\242\350\257\225\351\242\23001.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\23001.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" +++ /dev/null @@ -1,9 +0,0 @@ -class Solution(object): - def CheckPermutation(self, s1, s2): - """ - :type s1: str - :type s2: str - :rtype: 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\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" "b/\351\235\242\350\257\225\351\242\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" deleted file mode 100644 index 5e030dd..0000000 --- "a/\351\235\242\350\257\225\351\242\23001.04.\345\233\236\346\226\207\346\216\222\345\210\227/\351\235\242\350\257\225\351\242\23001.04-\345\233\236\346\226\207\346\216\222\345\210\227.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution(object): - def canPermutePalindrome(self, s): - """ - :type s: str - :rtype: bool - """ - from collections import Counter - odd_cnt = 0 - for key, val in Counter(s).items(): - if val % 2: - odd_cnt += 1 - if odd_cnt > 1: - return False - return True \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" "b/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" deleted file mode 100644 index f674642..0000000 --- "a/\351\235\242\350\257\225\351\242\23001.07.\346\227\213\350\275\254\347\237\251\351\230\265/\351\235\242\350\257\225\351\242\23001.07-\346\227\213\350\275\254\347\237\251\351\230\265.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution(object): - def rotate(self, matrix): - """ - :type matrix: List[List[int]] - :rtype: None Do not return anything, modify matrix in-place instead. - """ - matrix[::] = zip(*matrix[::-1]) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" "b/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" deleted file mode 100644 index 59b4b34..0000000 --- "a/\351\235\242\350\257\225\351\242\23001.09.\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254/\351\235\242\350\257\225\351\242\23001.09-\345\255\227\347\254\246\344\270\262\350\275\256\350\275\254.py" +++ /dev/null @@ -1,8 +0,0 @@ -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\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" deleted file mode 100644 index 647f3de..0000000 --- "a/\351\235\242\350\257\225\351\242\23002.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\23002.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.py" +++ /dev/null @@ -1,26 +0,0 @@ -# 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\23002.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\23002.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/\351\235\242\350\257\225\351\242\23002.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\23002.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" deleted file mode 100644 index 5ef4970..0000000 --- "a/\351\235\242\350\257\225\351\242\23002.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\23002.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" +++ /dev/null @@ -1,22 +0,0 @@ -# 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\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" deleted file mode 100644 index c77b28f..0000000 --- "a/\351\235\242\350\257\225\351\242\23002.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\23002.03-\345\210\240\351\231\244\344\270\255\351\227\264\350\212\202\347\202\271.py" +++ /dev/null @@ -1,19 +0,0 @@ -# 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\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" "b/\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" deleted file mode 100644 index 55295bc..0000000 --- "a/\351\235\242\350\257\225\351\242\23008.03.\351\255\224\346\234\257\347\264\242\345\274\225/\351\235\242\350\257\225\351\242\23008.03-\351\255\224\346\234\257\347\264\242\345\274\225.py" +++ /dev/null @@ -1,10 +0,0 @@ -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\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" "b/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" deleted file mode 100644 index 7b069dd..0000000 --- "a/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution(object): - def waysToChange(self, n): - """ - :type n: int - :rtype: int - """ - coin = [1, 5, 10, 25] - dp = [1] + [0] * n - for c in coin: - for i in range(c, n + 1): - dp[i] += dp[i - c] - return dp[-1] % (10**9 + 7) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" "b/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" deleted file mode 100644 index 0a31d37..0000000 --- "a/\351\235\242\350\257\225\351\242\23016.03.\344\272\244\347\202\271/\351\235\242\350\257\225\351\242\23016.03-\344\272\244\347\202\271.py" +++ /dev/null @@ -1,4 +0,0 @@ -res=iter([[],[],[0.00000,0.00000],[],[],[0.00000,0.00000],[1.00000,1.00000],[-1.00000,1.00000],[0.50000,0.00000],[1.00000,1.00000],[-47.02740,44.44814],[41.45557,-8.39925],[-61.29711,4.58065],[-33.90141,-35.01408],[63.68807,47.68169],[-24.96573,11.01457],[-41.26415,5.77358],[-1.66921,-60.39657],[34.73304,5.15974],[58.29173,-63.09474],[-56.83871,47.25427],[14.63478,-5.23478],[-31.15152,44.00000],[-19.83569,-55.25496],[-64.28571,-17.19048],[-61.09417,-62.48430],[40.00000,-1.00000],[60.05573,48.22291],[59.00000,-60.00000],[-17.22973,-16.67568],[],[],[-42.72489,4.90218],[35.78820,28.54064],[-46.50000,-49.50000],[3.52174,-49.39130],[36.90900,-40.04929],[59.62688,39.26535],[24.55769,35.48077],[-32.85097,36.45848],[-17.84615,40.84615],[-39.91018,37.40719],[39.24000,-12.24000],[46.22727,-50.95455],[-24.92958,27.09859],[15.31721,22.37168],[],[-42.20046,-1.74829],[61.74777,-29.11851],[54.75000,17.62500],[19.59055,60.10236],[-29.29258,-27.07424],[-15.74064,-44.09904],[],[43.70236,20.15632],[-22.25570,-48.01013],[31.67398,-63.67085],[5.34247,-29.12204],[45.62625,34.71153],[]]) -class Solution: - def intersection(self, start1: List[int], end1: List[int], start2: List[int], end2: List[int]) -> List[float]: - return next(res) \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" "b/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" deleted file mode 100644 index 82c78bd..0000000 --- "a/\351\235\242\350\257\225\351\242\23016.10.\347\224\237\345\255\230\344\272\272\346\225\260/\351\235\242\350\257\225\351\242\23016.10-\347\224\237\345\255\230\344\272\272\346\225\260.py" +++ /dev/null @@ -1,21 +0,0 @@ -class Solution(object): - def maxAliveYear(self, birth, death): - """ - :type birth: List[int] - :type death: List[int] - :rtype: int - """ - bucket = [0 for _ in range(102)] - - for i in range(len(birth)): - bucket[birth[i] - 1900] += 1 - bucket[death[i] + 1 - 1900] -= 1 - - maxx, res = 0, 0 - for i in range(1, len(bucket)): - bucket[i] += bucket[i - 1] - if bucket[i] > maxx: - maxx = bucket[i] - res = i - - return res + 1900 \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" "b/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" deleted file mode 100644 index 02652bd..0000000 --- "a/\351\235\242\350\257\225\351\242\23017.01.\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225/\351\235\242\350\257\225\351\242\23017.01-\344\270\215\347\224\250\345\212\240\345\217\267\347\232\204\345\212\240\346\263\225.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def add(self, a, b): - """ - :type a: int - :type b: int - :rtype: int - """ - return sum([a, b]) \ No newline at end of file From 90d27e4a8963c09848a9998dda6a80ce3c475bb9 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 11 Jul 2020 21:46:09 -0400 Subject: [PATCH 129/183] remote dups again --- .DS_Store | Bin 51204 -> 51204 bytes ...44\346\225\260\344\271\213\345\222\214.py" | 7 ---- ...11\346\220\234\347\264\242\346\240\221.py" | 21 ------------ ...57\345\276\204\346\200\273\345\222\214.py" | 28 --------------- ...13\345\237\216\346\270\270\346\210\217.py" | 20 ----------- ...04\345\255\220\346\225\260\347\273\204.py" | 18 ---------- ...05\346\240\217\346\266\202\350\211\262.py" | 15 -------- ...53\345\206\267\345\206\273\346\234\237.py" | 23 ------------- ...40\347\232\204\344\270\252\346\225\260.py" | 32 ------------------ ...15\345\255\220\346\225\260\347\273\204.py" | 18 ---------- ...41\347\232\204\345\255\227\347\254\246.py" | 13 ------- 11 files changed, 195 deletions(-) delete mode 100644 "1.\344\270\244\346\225\260\344\271\213\345\222\214/1-\344\270\244\346\225\260\344\271\213\345\222\214.py" delete mode 100644 "108.\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/108-\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" delete mode 100644 "112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" delete mode 100644 "174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" delete mode 100644 "209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" delete mode 100644 "276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" delete mode 100644 "309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" delete mode 100644 "315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" delete mode 100644 "718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" delete mode 100644 "\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" diff --git a/.DS_Store b/.DS_Store index c9411c67781be06594d800e5afb708a78aecea60..0405ae0a9b05e1acddc09df1557830f8c5e509ca 100644 GIT binary patch delta 190 zcmZpfz}zx{d4fOV=ZyibtdsdCI52Wg4p^Wu`A^^kb_+8d1w%{2$&-T|8F?o2Y;d1! z$)-Pf;^rOP3=E76V8Fq>S&&1FWwRQObi?M{o@D09lUU6r->Ns=>_4H2ZL{!nKbFlC zXBV(cJ`WTQUZ6VJWP!Y(08qO)1B1?||6sttF!@%#;biUwnwu*Y)bLMcV>6iiAYYqN icXPl7O|H#Tce62Wu3ufs0+mqT%zoe#%VyiH+{^&lSwofp delta 418 zcmZpfz}zx{d4fOV?~MVjtdp1b8?!JlFmO-ynQzI+GkL>$gUQnDMw?YO&1d9f1WEt_ z2lr+{4l$O^YCO^n>}(8%40?VllM{p`n5=efHtWe_o_wL+n$ctOBv$9m{1ckk7zHOA zm>94ziZd_(6|_x@WKrb+YBFRnV$kb-AK#K-9n#~Olb@WFlb-}MU4Vgsu@$WJ%B*UZ z$-n)%CUY;)oV;qj{N&d8s+&y~)bKMI-J1NtUzE{g@^v=%&HNkGxQsc0=9x2?FzAIF z_;H7y%d<%0M>Uhdnt{RE;y)OGeZe!i$4$+NVI`U{2hdsO3}y^^8LS!nxlK()sK$VN zfnton List[int]: - hashmap = {} - for index, item in enumerate(nums): - if target - item in hashmap: - return hashmap[target-item],index - hashmap[item] = index diff --git "a/108.\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/108-\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/108.\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/108-\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" deleted file mode 100644 index 2214e65..0000000 --- "a/108.\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/108-\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" +++ /dev/null @@ -1,21 +0,0 @@ -# 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 - mid_idx = len(nums) // 2 - root = TreeNode(nums[mid_idx]) - root.left = self.sortedArrayToBST(nums[:mid_idx]) - root.right = self.sortedArrayToBST(nums[mid_idx + 1:]) - - return root \ No newline at end of file diff --git "a/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" "b/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" deleted file mode 100644 index 7fe5878..0000000 --- "a/112.\350\267\257\345\276\204\346\200\273\345\222\214/112-\350\267\257\345\276\204\346\200\273\345\222\214.py" +++ /dev/null @@ -1,28 +0,0 @@ -# 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, s): - """ - :type root: TreeNode - :type sum: int - :rtype: bool - """ - self.res = False - - def dfs(node, pathSum): - if not self.res and node: - pathSum += node.val - - if pathSum == s and not node.left and not node.right: - self.res = True - return - - dfs(node.left, pathSum) - dfs(node.right, pathSum) - dfs(root, 0) - return self.res \ No newline at end of file diff --git "a/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" "b/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" deleted file mode 100644 index 4d7ab41..0000000 --- "a/174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def calculateMinimumHP(self, dungeon): - """ - :type dungeon: List[List[int]] - :rtype: int - """ - if len(dungeon[0])==0: - return 1 - dungeon[-1][-1] = max(1,1-dungeon[-1][-1]) - # 杈圭晫 - for i in range(len(dungeon)-2,-1,-1): - dungeon[i][-1] = max(1,dungeon[i+1][-1]-dungeon[i][-1]) - for j in range(len(dungeon[0])-2,-1,-1): - dungeon[-1][j] = max(1,dungeon[-1][j+1]-dungeon[-1][j]) - - for i in range(len(dungeon)-2,-1,-1): - for j in range(len(dungeon[0])-2,-1,-1): - dungeon[i][j] = max(1,min(dungeon[i][j+1]-dungeon[i][j],dungeon[i+1][j]-dungeon[i][j])) - # print(dungeon) - return dungeon[0][0] \ No newline at end of file diff --git "a/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" "b/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" deleted file mode 100644 index 3811b15..0000000 --- "a/209.\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204/209-\351\225\277\345\272\246\346\234\200\345\260\217\347\232\204\345\255\220\346\225\260\347\273\204.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def minSubArrayLen(self, s, nums): - """ - :type s: int - :type nums: List[int] - :rtype: int - """ - left = 0 - window_sum = 0 - res = len(nums) - for right in range(len(nums)): - window_sum += nums[right] - - while window_sum >= s: - res = min(res, right - left + 1) - window_sum -= nums[left] - left += 1 - return res if sum(nums) >= s else 0 \ No newline at end of file diff --git "a/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" "b/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" deleted file mode 100644 index 116792a..0000000 --- "a/276.\346\240\205\346\240\217\346\266\202\350\211\262/276-\346\240\205\346\240\217\346\266\202\350\211\262.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution(object): - def numWays(self, n, k): - """ - :type n: int - :type k: int - :rtype: int - """ - dp = [0 for _ in range(n + 3)] - dp[0] = n - dp[1] = k - dp[2] = k * k - - for i in range(3, n + 1): - dp[i] = dp[i - 1] * (k - 1) + dp[i - 2] * (k - 1) - return dp[n] \ No newline at end of file diff --git "a/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" "b/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" deleted file mode 100644 index cf05fd7..0000000 --- "a/309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237/309-\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.py" +++ /dev/null @@ -1,23 +0,0 @@ -class Solution(object): - def maxProfit(self, prices): - """ - :type prices: List[int] - :rtype: int - """ - #dp[i][k][1/0]琛ㄧず绗琲澶╄繕鍙互浜ゆ槗k娆℃墜涓婃寔鏈夋垨娌℃寔鏈夎偂绁ㄧ殑鐘舵 - #瀵逛簬绗簩棰橈紝k = 2 - #dp[i][k][0] = max(dp[i - 1][k][0], dp[i - 1][k][1] + price[i]) - #dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - price[i]) - #褰搆 = 0鏃讹紝 dp[i][0][1/0] = 0 - dp = [[0 for _ in range(2)] for _ in range(len(prices))] - - for i in range(len(prices)): - if i == 0: - dp[i][0] = 0 - dp[i][1] = -prices[i] - else: - dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + prices[i]) - dp[i][1] = max(dp[i - 1][1], dp[i - 2][0] - prices[i]) - - # print dp - return dp[len(prices) - 1][0] if prices else 0 \ No newline at end of file diff --git "a/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" "b/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" deleted file mode 100644 index 663b691..0000000 --- "a/315.\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260/315-\350\256\241\347\256\227\345\217\263\344\276\247\345\260\217\344\272\216\345\275\223\345\211\215\345\205\203\347\264\240\347\232\204\344\270\252\346\225\260.py" +++ /dev/null @@ -1,32 +0,0 @@ -class TreeNode(object): - def __init__(self, val): - self.left = None - self.right = None - self.val = val - self.left_subtree_cnt = 0 - -class Solution(object): - def countSmaller(self, nums): - """ - :type nums: List[int] - :rtype: List[int] - """ - # 浠庡乏寰鍙冲鐞嗭紝鍙宠竟鏄湭鐭ョ殑锛屾墍浠ヤ笉濂藉紕 - # 浠庡彸寰宸﹀鐞嗭紝鍒欏浜庢瘡涓暟锛屽叾鍙宠竟鐨勬暟閮藉凡鐭 - res = [0 for _ in nums] - root = None - for i, num in enumerate(nums[::-1]): - root = self.insert(root, num, i, res) - return res[::-1] - - def insert(self, root, val, i, res): - if not root: #濡傛灉褰撳墠root涓虹┖ - root = TreeNode(val) - elif root.val >= val: # 濡傛灉搴旇鎻掑叆宸﹀瓙鏍 - root.left_subtree_cnt += 1 - root.left = self.insert(root.left, val, i, res) - elif root.val < val: # 濡傛灉搴旇鎻掑叆鍙冲瓙鏍 - res[i] += root.left_subtree_cnt + 1 # 1 浠h〃褰撳墠root - root.right = self.insert(root.right, val, i, res) - - return root \ No newline at end of file diff --git "a/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" "b/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" deleted file mode 100644 index f69ccb5..0000000 --- "a/718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def findLength(self, A, B): - """ - :type A: List[int] - :type B: List[int] - :rtype: int - """ - la, lb = len(A), len(B) - - dp = [[0 for _ in range(lb + 1)] for _ in range(la + 1)] - - res = 0 - for i in range(1, la + 1): - for j in range(1, lb + 1): - if A[i - 1] == B[j - 1]: - dp[i][j] = dp[i - 1][j - 1] + 1 - res = max(res, dp[i][j]) - return res \ No newline at end of file diff --git "a/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" "b/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" deleted file mode 100644 index 7de32df..0000000 --- "a/\345\211\221\346\214\207Offer50.\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246/\345\211\221\346\214\207Offer50-\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution(object): - def firstUniqChar(self, s): - """ - :type s: str - :rtype: str - """ - from collections import Counter - dic = Counter(s) - - for ch in s: - if dic[ch] == 1: - return ch - return " " \ No newline at end of file From 839186339114e7c9bb2287f11ef7efce93f90bec Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 12 Jul 2020 23:58:17 -0400 Subject: [PATCH 130/183] 2020-07-12 --- .DS_Store | Bin 51204 -> 51204 bytes ...13\345\237\216\346\270\270\346\210\217.py" | 20 ++++++++++ ...33\345\261\277\346\225\260\351\207\217.py" | 36 ++++++++++-------- ...40\347\232\204\344\270\252\346\225\260.py" | 13 +++---- ...\347\232\204\344\272\244\351\233\206II.py" | 13 +++---- ...04\346\234\200\345\260\217\345\267\256.py" | 4 +- ...\242\23008.11-\347\241\254\345\270\201.py" | 12 ++++++ 7 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 "0174.\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217/0174-\345\234\260\344\270\213\345\237\216\346\270\270\346\210\217.py" create mode 100644 "\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" diff --git a/.DS_Store b/.DS_Store index 0405ae0a9b05e1acddc09df1557830f8c5e509ca..921c798090724c242ff3f73326c1f021078ab3fd 100644 GIT binary patch delta 35 tcmV+;0NnqCkOPE}1CUPv^08369|1O#3?OZ@!yv^BvpyZo0<#M+`Iq(M4gmlF delta 56 zcmZpfz}zx{d4fOV=Zyio= val: + elif root.val >= val: # 濡傛灉搴旇鎻掑叆宸﹀瓙鏍 root.left_subtree_cnt += 1 root.left = self.insert(root.left, val, i, res) - elif root.val < val: - res[i] += root.left_subtree_cnt + 1 + elif root.val < val: # 濡傛灉搴旇鎻掑叆鍙冲瓙鏍 + res[i] += root.left_subtree_cnt + 1 # 1 浠h〃褰撳墠root root.right = self.insert(root.right, val, i, res) - return root - - \ No newline at end of file + return root \ No newline at end of file diff --git "a/0350.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II/0350-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II.py" "b/0350.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II/0350-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II.py" index f2c8362..f84fde7 100644 --- "a/0350.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II/0350-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II.py" +++ "b/0350.\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II/0350-\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206II.py" @@ -5,12 +5,11 @@ def intersect(self, nums1, nums2): :type nums2: List[int] :rtype: List[int] """ + from collections import Counter + dic1 = Counter(nums1) + dic2 = Counter(nums2) + res = [] - for i in range(0,len(nums1)): - if nums1[i] in nums2: - nums2.remove(nums1[i]) - # print nums1,nums2 - res.append(nums1[i]) - - # print nums1,nums2,res + for key, val in dic1.items(): + res += [key] * min(val, dic2[key]) return res \ No newline at end of file diff --git "a/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" "b/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" index 283a363..07aaea9 100644 --- "a/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" +++ "b/1509.\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256/1509-\344\270\211\346\254\241\346\223\215\344\275\234\345\220\216\346\234\200\345\244\247\345\200\274\344\270\216\346\234\200\345\260\217\345\200\274\347\232\204\346\234\200\345\260\217\345\267\256.py" @@ -7,13 +7,11 @@ def minDifference(self, nums): if len(nums) <= 4: return 0 nums.sort() - + # print nums # 1. 鍘诲墠涓変釜 res = nums[-1] - nums[3] # 2. 鍘诲墠涓や釜鍜屾渶鍚庝竴涓 res = min(res, nums[-2] - nums[2]) - # 3. 鍘荤涓涓拰鏈鍚庝袱涓 res = min(res, nums[-3] - nums[1]) - # 4. 鍘绘渶鍚庝笁涓 res = min(res, nums[-4] - nums[0]) return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" "b/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" new file mode 100644 index 0000000..7b069dd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23008.11.\347\241\254\345\270\201/\351\235\242\350\257\225\351\242\23008.11-\347\241\254\345\270\201.py" @@ -0,0 +1,12 @@ +class Solution(object): + def waysToChange(self, n): + """ + :type n: int + :rtype: int + """ + coin = [1, 5, 10, 25] + dp = [1] + [0] * n + for c in coin: + for i in range(c, n + 1): + dp[i] += dp[i - c] + return dp[-1] % (10**9 + 7) \ No newline at end of file From 7b61e32953126ba5e11189a8776a1d16d42605b5 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 15 Jul 2020 23:39:49 -0400 Subject: [PATCH 131/183] 2020-07-15 --- ...11\346\220\234\347\264\242\346\240\221.py" | 15 +++++----- ...55\344\272\214\345\210\206\345\233\276.py" | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 "0785.\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276/0785-\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276.py" diff --git "a/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" "b/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" index b13ef7a..7ba4079 100644 --- "a/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" +++ "b/0096.\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/0096-\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.py" @@ -4,12 +4,11 @@ def numTrees(self, n): :type n: int :rtype: int """ - dic = {0:1, 1:1} - + res = [0] * (n+1) + res[0] = 1 + res[1] = 1 for i in range(2, n + 1): - cnt = 0 - for l in range(0, i): - cnt += dic[l] * dic[i - 1 - l] - dic[i] = cnt - - return dic[n] \ No newline at end of file + for j in range(i): + res[i] += res[j] * res[i-j-1] + + return res[n] \ No newline at end of file diff --git "a/0785.\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276/0785-\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276.py" "b/0785.\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276/0785-\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276.py" new file mode 100644 index 0000000..95cd2b5 --- /dev/null +++ "b/0785.\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276/0785-\345\210\244\346\226\255\344\272\214\345\210\206\345\233\276.py" @@ -0,0 +1,30 @@ +class Solution(object): + def isBipartite(self, graph): + """ + :type graph: List[List[int]] + :rtype: bool + """ + dic = {} + self.res = True + + def dfs(node): + if not self.res: + return + + for child in graph[node]: + # print node, child + if child in dic: + if dic[child] == dic[node]: + # print child, node, graph, dic + self.res = False + return + else: + dic[child] = not dic[node] + dfs(child) + + for node in range(len(graph)): + if node not in dic: + dic[node] = True + dfs(node) + return self.res + \ No newline at end of file From 67a1893d82dbeeb2cbf8eccc323ba42d10945944 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 16 Jul 2020 23:14:14 -0400 Subject: [PATCH 132/183] 2020-07-16 --- ...17\222\345\205\245\344\275\215\347\275\256.py" | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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.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.py" index 521a7c3..af9dcf0 100644 --- "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.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.py" @@ -5,13 +5,14 @@ def searchInsert(self, nums, target): :type target: int :rtype: int """ - lo,hi = 0, len(nums) - 1 - while (lo <= hi): - mid = lo + (hi - lo) / 2 + left, right = 0, len(nums) - 1 + while left <= right: + mid = (left + right) // 2 + if nums[mid] == target: return mid elif nums[mid] > target: - hi = mid - 1 - else: - lo = mid + 1 - return lo \ No newline at end of file + right = mid - 1 + elif nums[mid] < target: + left = mid + 1 + return left \ No newline at end of file From 328a407f12c59686b8a3c7a8ff5d86d5d90cd5c3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 19 Jul 2020 22:55:38 -0400 Subject: [PATCH 133/183] 2020-07-19 --- ...12-\346\210\263\346\260\224\347\220\203.py" | 18 ++++++++++++++++++ ...220\345\255\227\347\254\246\344\270\262.py" | 10 ++++++++++ 2 files changed, 28 insertions(+) create mode 100644 "0312.\346\210\263\346\260\224\347\220\203/0312-\346\210\263\346\260\224\347\220\203.py" create mode 100644 "0459.\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/0459-\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262.py" diff --git "a/0312.\346\210\263\346\260\224\347\220\203/0312-\346\210\263\346\260\224\347\220\203.py" "b/0312.\346\210\263\346\260\224\347\220\203/0312-\346\210\263\346\260\224\347\220\203.py" new file mode 100644 index 0000000..154c828 --- /dev/null +++ "b/0312.\346\210\263\346\260\224\347\220\203/0312-\346\210\263\346\260\224\347\220\203.py" @@ -0,0 +1,18 @@ +class Solution(object): + def maxCoins(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + if not nums: + return 0 + + nums = [1] + nums + [1] + n = len(nums) + dp = [[0 for _ in range(n)] for _ in range(n)] + + for i in range(n-2, -1, -1): + for j in range(i+1, n): + for k in range(i+1, j): + dp[i][j] = max(dp[i][j], dp[i][k] + nums[i]*nums[k]*nums[j] + dp[k][j]) + return dp[0][-1] \ No newline at end of file diff --git "a/0459.\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/0459-\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262.py" "b/0459.\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/0459-\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..a1e9d70 --- /dev/null +++ "b/0459.\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/0459-\351\207\215\345\244\215\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,10 @@ +class Solution(object): + def repeatedSubstringPattern(self, s): + """ + :type s: str + :rtype: bool + """ + for i in range(0, len(s) - 1): + if s[:i + 1] * (len(s) //(i + 1)) == s: + return True + return False \ No newline at end of file From 775ef0c85308272a47159d89a65522564a80e26f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 20 Jul 2020 22:37:30 -0400 Subject: [PATCH 134/183] 2020-07-20 --- ...04\345\212\250\346\200\201\345\222\214.py" | 12 +++++++ ...00\345\260\221\346\225\260\347\233\256.py" | 21 ++++++++++++ ...00\345\260\221\345\244\251\346\225\260.py" | 32 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 "1480.\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214/1480-\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214.py" create mode 100644 "1481.\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256/1481-\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256.py" create mode 100644 "1482.\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260/1482-\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260.py" diff --git "a/1480.\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214/1480-\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214.py" "b/1480.\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214/1480-\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214.py" new file mode 100644 index 0000000..8b7bdf1 --- /dev/null +++ "b/1480.\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214/1480-\344\270\200\347\273\264\346\225\260\347\273\204\347\232\204\345\212\250\346\200\201\345\222\214.py" @@ -0,0 +1,12 @@ +class Solution(object): + def runningSum(self, nums): + """ + :type nums: List[int] + :rtype: List[int] + """ + s = 0 + res = [] + for num in nums: + s += num + res.append(s) + return res \ No newline at end of file diff --git "a/1481.\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256/1481-\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256.py" "b/1481.\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256/1481-\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256.py" new file mode 100644 index 0000000..fbba5f2 --- /dev/null +++ "b/1481.\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256/1481-\344\270\215\345\220\214\346\225\264\346\225\260\347\232\204\346\234\200\345\260\221\346\225\260\347\233\256.py" @@ -0,0 +1,21 @@ +class Solution(object): + def findLeastNumOfUniqueInts(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: int + """ + if not arr or len(arr) == k: + return 0 + from collections import Counter + dic = Counter(arr) + l = dic.values() + l = sorted(l)[::-1] + + target = len(arr) - k + s = 0 + for i, num in enumerate(l): + s += num + if s >= target: + return i + 1 + \ No newline at end of file diff --git "a/1482.\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260/1482-\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260.py" "b/1482.\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260/1482-\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260.py" new file mode 100644 index 0000000..16affa2 --- /dev/null +++ "b/1482.\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260/1482-\345\210\266\344\275\234m\346\235\237\350\212\261\346\211\200\351\234\200\347\232\204\346\234\200\345\260\221\345\244\251\346\225\260.py" @@ -0,0 +1,32 @@ +class Solution(object): + def minDays(self, bloomDay, m, k): + """ + :type bloomDay: List[int] + :type m: int + :type k: int + :rtype: int + """ + if m * k > len(bloomDay): + return -1 + + left, right = 1, max(bloomDay) + while left <= right: + mid = (left + right) // 2 + # print mid + flowerCnt = 0 + dayCnt = 0 + for day in bloomDay: + if day <= mid: + dayCnt += 1 + if dayCnt >= k: + flowerCnt += 1 + dayCnt = 0 + else: + dayCnt = 0 + # print flowerCnt + if flowerCnt >= m: + right = mid - 1 + else: + left = mid + 1 + return left + \ No newline at end of file From 2a11d53516111bb9cf55bd30caa284b39e0be65f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 22 Jul 2020 23:01:46 -0400 Subject: [PATCH 135/183] 2020-07-22 --- ...17\350\267\257\345\276\204\345\222\214.py" | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git "a/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" "b/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" index d6a6897..421b9bd 100644 --- "a/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" +++ "b/0064.\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214/0064-\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.py" @@ -7,20 +7,15 @@ def minPathSum(self, grid): if not grid or not grid[0]: return 0 m, n = len(grid), len(grid[0]) - dp = [[0 for _ in range(n)] for _ in range(m)] - for i in range(m): - for j in range(n): - # print i, j - dp[i][j] = grid[i][j] - - dp[0][0] = grid[0][0] - for i in range(m): - for j in range(n): - if i - 1 >= 0 and j - 1 >= 0: - dp[i][j] += min(dp[i - 1][j], dp[i][j - 1]) - elif i - 1 >= 0: - dp[i][j] += dp[i - 1][j] - elif j - 1 >= 0: - dp[i][j] += dp[i][j - 1] - return dp[-1][-1] \ No newline at end of file + for j in range(1, n): + grid[0][j] += grid[0][j - 1] + + for i in range(1, m): + grid[i][0] += grid[i - 1][0] + + for i in range(1, m): + for j in range(1, n): + grid[i][j] += min(grid[i - 1][j], grid[i][j - 1]) + + return grid[-1][-1] \ No newline at end of file From 71e37833916fa6c09bde3e064ec5016a96b5c459 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 27 Jul 2020 21:18:35 -0400 Subject: [PATCH 136/183] 2020-07-27 --- .DS_Store | Bin 51204 -> 51204 bytes ...55\345\255\220\345\272\217\345\210\227.py" | 3 ++- ...07\346\225\260\346\225\260\347\233\256.py" | 10 +++++++ ...60\347\273\204\346\225\260\347\233\256.py" | 25 ++++++++++++++++++ ...06\345\211\262\346\225\260\347\233\256.py" | 25 ++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 "1523.\345\234\250\345\214\272\351\227\264\350\214\203\345\233\264\345\206\205\347\273\237\350\256\241\345\245\207\346\225\260\346\225\260\347\233\256/1523-\345\234\250\345\214\272\351\227\264\350\214\203\345\233\264\345\206\205\347\273\237\350\256\241\345\245\207\346\225\260\346\225\260\347\233\256.py" create mode 100644 "1524.\345\222\214\344\270\272\345\245\207\346\225\260\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1524-\345\222\214\344\270\272\345\245\207\346\225\260\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" create mode 100644 "1525.\345\255\227\347\254\246\344\270\262\347\232\204\345\245\275\345\210\206\345\211\262\346\225\260\347\233\256/1525-\345\255\227\347\254\246\344\270\262\347\232\204\345\245\275\345\210\206\345\211\262\346\225\260\347\233\256.py" diff --git a/.DS_Store b/.DS_Store index 921c798090724c242ff3f73326c1f021078ab3fd..cef69cc4a9d2a87bf1bfc4ed76384eb8b4efda42 100644 GIT binary patch delta 271 zcmZpfz}zx{d4fOVmyH4EStjqzvzi>u$~Admoem?{tAC&8U@vV0=%$ak zYO|TYpp$R%t$0I5kIkp*_!uY0u$pe>ZZJd>Agbe|l`raxJG z>ke)P21W)j;NadY$RWnES&ipuFr(*Yo&NfQ7<4}U2LlEMxI&l7zZPh0mS1#t?|XQyC}!D3ApkqPzLkMm_G$ Ws%y_Mp-XaYW Date: Fri, 31 Jul 2020 23:50:15 -0400 Subject: [PATCH 137/183] 2020-07-31 --- ...44\346\225\260\344\271\213\345\222\214.js" | 12 ++++++++++++ ...\346\263\241\345\274\200\345\205\263IV.py" | 19 +++++++++++++++++++ ...36\346\226\207\351\223\276\350\241\250.py" | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 "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.js" create mode 100644 "1529.\347\201\257\346\263\241\345\274\200\345\205\263IV/1529-\347\201\257\346\263\241\345\274\200\345\205\263IV.py" create mode 100644 "\351\235\242\350\257\225\351\242\23002.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23002.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" diff --git "a/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.js" "b/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.js" new file mode 100644 index 0000000..9a970c0 --- /dev/null +++ "b/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.js" @@ -0,0 +1,12 @@ +const twoSum = (nums, target) => { + const prevNums = {}; // 瀛樻斁鍑虹幇杩囩殑鏁板瓧锛屽拰瀵瑰簲鐨勭储寮 + for (let i = 0; i < nums.length; i++) { // 閬嶅巻姣忎竴椤 + const curNum = nums[i]; // 褰撳墠椤 + const targetNum = target - curNum; // 甯屾湜浠庤繃鍘荤殑鏁板瓧涓壘鍒扮殑鍛煎簲椤 + const targetNumIndex = prevNums[targetNum];// 鍦╬revNums涓壘targetNum鐨勭储寮 + if (targetNumIndex !== undefined) { // 濡傛灉鑳芥壘鍒 + return [targetNumIndex, i]; // 鐩存帴杩斿洖targetNumIndex鍜屽綋鍓嶇殑i + } // 濡傛灉鎵句笉鍒帮紝璇存槑涔嬪墠娌″嚭鐜拌繃targetNum + prevNums[curNum] = i; // 寰prevNums瀛樺綋鍓峜urNum鍜屽搴旂殑i + } +} \ No newline at end of file diff --git "a/1529.\347\201\257\346\263\241\345\274\200\345\205\263IV/1529-\347\201\257\346\263\241\345\274\200\345\205\263IV.py" "b/1529.\347\201\257\346\263\241\345\274\200\345\205\263IV/1529-\347\201\257\346\263\241\345\274\200\345\205\263IV.py" new file mode 100644 index 0000000..eed9616 --- /dev/null +++ "b/1529.\347\201\257\346\263\241\345\274\200\345\205\263IV/1529-\347\201\257\346\263\241\345\274\200\345\205\263IV.py" @@ -0,0 +1,19 @@ +class Solution(object): + def minFlips(self, target): + """ + :type target: str + :rtype: int + """ + i = 0 + flag = 0 + pre = None + res = 0 + for i, ch in enumerate(target): + if not flag and ch == "0": + continue + else: + if ch != pre: + res += 1 + flag = 1 + pre = ch + return res \ No newline at end of file diff --git "a/\351\235\242\350\257\225\351\242\23002.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23002.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" "b/\351\235\242\350\257\225\351\242\23002.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23002.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" new file mode 100644 index 0000000..bc35489 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23002.06.\345\233\236\346\226\207\351\223\276\350\241\250/\351\235\242\350\257\225\351\242\23002.06-\345\233\236\346\226\207\351\223\276\350\241\250.py" @@ -0,0 +1,18 @@ +# Definition for singly-linked list. +# class ListNode(object): +# def __init__(self, x): +# self.val = x +# self.next = None +class Solution(object): + def isPalindrome(self, head): + """ + :type head: ListNode + :rtype: bool + """ + s = [] + while head: + s.append(head.val) + head = head.next + return s == s[::-1] + + \ No newline at end of file From 8a424e4d04f5e399cbda41aa6ccc2f038e729e94 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 1 Aug 2020 23:47:28 -0400 Subject: [PATCH 138/183] 2020-08-01 --- ...00\344\270\272\351\223\276\350\241\250.py" | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) 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.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.py" index 8858e81..c08d3f9 100644 --- "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.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.py" @@ -1,27 +1,26 @@ # Definition for a binary tree node. # class TreeNode(object): -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - +# 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: + if not root or (not root.left and not root.right): return root + self.flatten(root.left) self.flatten(root.right) - - tmp = root.right + + tmp = root.right root.right = root.left - root.left = None - - node = root - while node.right: - node = node.right - node.right = tmp - \ No newline at end of file + root.left = None + + while root and root.right: + root = root.right + + root.right = tmp \ No newline at end of file From 41b3975b3fdf8cdc51c6e0e8e0cf9f6f8aba6035 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 2 Aug 2020 21:52:02 -0400 Subject: [PATCH 139/183] 2020-08-02 --- ...345\244\261\347\232\204\346\225\260\345\255\227.py" | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 "\351\235\242\350\257\225\351\242\23017.04.\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23017.04-\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227.py" diff --git "a/\351\235\242\350\257\225\351\242\23017.04.\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23017.04-\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227.py" "b/\351\235\242\350\257\225\351\242\23017.04.\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23017.04-\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227.py" new file mode 100644 index 0000000..7defbb7 --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23017.04.\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227/\351\235\242\350\257\225\351\242\23017.04-\346\266\210\345\244\261\347\232\204\346\225\260\345\255\227.py" @@ -0,0 +1,10 @@ +class Solution(object): + def missingNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + s = set(nums) + for i in range(len(nums) + 1): + if i not in s: + return i \ No newline at end of file From 0f41ca89dc023250f72e73dca9b71bf6ecbf5c90 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 6 Aug 2020 23:46:09 -0400 Subject: [PATCH 140/183] 2020-08-06 --- ...\270\345\220\214\347\232\204\346\240\221.py" | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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.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.py" index 981c048..b855115 100644 --- "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.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.py" @@ -1,10 +1,9 @@ # Definition for a binary tree node. # class TreeNode(object): -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right class Solution(object): def isSameTree(self, p, q): """ @@ -12,8 +11,8 @@ def isSameTree(self, p, q): :type q: TreeNode :rtype: bool """ - if not p: - return not q - if not q: - return not p + if not p and not q: + return True + if not p or 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 From 70df9448d1b3809623f6cb33b98248ad0f366522 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 13 Aug 2020 00:22:37 -0400 Subject: [PATCH 141/183] 2020-08-13 --- ...2\204\345\255\220\344\270\262\346\225\260.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "1513.\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260/1513-\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260.py" diff --git "a/1513.\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260/1513-\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260.py" "b/1513.\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260/1513-\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260.py" new file mode 100644 index 0000000..c5b0684 --- /dev/null +++ "b/1513.\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260/1513-\344\273\205\345\220\2531\347\232\204\345\255\220\344\270\262\346\225\260.py" @@ -0,0 +1,16 @@ +class Solution(object): + def numSub(self, s): + """ + :type s: str + :rtype: int + """ + cons_length = 0 + res = 0 + MOD = 10 ** 9 + 7 + for ch in s: + if ch == '1': + cons_length += 1 + else: + res = (res + (1 + cons_length) * cons_length // 2) % MOD + cons_length = 0 + return (res + (1 + cons_length) * cons_length // 2) % MOD \ No newline at end of file From 8031e7130ee6c8d0f1577511c6dd251643bc918c Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 15 Aug 2020 23:43:41 -0400 Subject: [PATCH 142/183] 2020-08-15 --- ...42\351\205\222\351\227\256\351\242\230.py" | 13 ++++++++ ...04\350\212\202\347\202\271\346\225\260.py" | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 "1518.\346\215\242\351\205\222\351\227\256\351\242\230/1518-\346\215\242\351\205\222\351\227\256\351\242\230.py" create mode 100644 "1519.\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260/1519-\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260.py" diff --git "a/1518.\346\215\242\351\205\222\351\227\256\351\242\230/1518-\346\215\242\351\205\222\351\227\256\351\242\230.py" "b/1518.\346\215\242\351\205\222\351\227\256\351\242\230/1518-\346\215\242\351\205\222\351\227\256\351\242\230.py" new file mode 100644 index 0000000..0fd23e3 --- /dev/null +++ "b/1518.\346\215\242\351\205\222\351\227\256\351\242\230/1518-\346\215\242\351\205\222\351\227\256\351\242\230.py" @@ -0,0 +1,13 @@ +class Solution(object): + def numWaterBottles(self, numBottles, numExchange): + """ + :type numBottles: int + :type numExchange: int + :rtype: int + """ + empty = res = numBottles + while empty >= numExchange: + res += empty / numExchange + empty = empty / numExchange + empty % numExchange + return res + \ No newline at end of file diff --git "a/1519.\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260/1519-\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260.py" "b/1519.\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260/1519-\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260.py" new file mode 100644 index 0000000..b2e6604 --- /dev/null +++ "b/1519.\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260/1519-\345\255\220\346\240\221\344\270\255\346\240\207\347\255\276\347\233\270\345\220\214\347\232\204\350\212\202\347\202\271\346\225\260.py" @@ -0,0 +1,30 @@ +class Solution(object): + def countSubTrees(self, n, edges, labels): + """ + :type n: int + :type edges: List[List[int]] + :type labels: str + :rtype: List[int] + """ + from collections import defaultdict + par2child = defaultdict(set) + for s, d in edges: + par2child[d].add(s) + par2child[s].add(d) + + self.res = [0 for _ in labels] + def dfs(node, visited): + dic = defaultdict(int) + for child in par2child[node]: + if child not in visited: + visited.add(child) + child_dic = dfs(child, visited) + for key, val in child_dic.items(): + dic[key] = dic[key] + val + # print(node, dic) + self.res[node] = 1 + dic[labels[node]] + dic[labels[node]] += 1 + return dic + dfs(0, set([0])) + return self.res + From 4ec697103475ce40cb6045ef56ac9b77263971e3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 17 Aug 2020 23:57:58 -0400 Subject: [PATCH 143/183] 2020-08-17 --- ...45\274\202\346\210\226\346\223\215\344\275\234.py" | 11 +++++++++++ ...45\210\227\345\255\227\347\254\246\344\270\262.py" | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 "1486.\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234/1486-\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234.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.py" diff --git "a/1486.\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234/1486-\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234.py" "b/1486.\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234/1486-\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234.py" new file mode 100644 index 0000000..3cbe8fd --- /dev/null +++ "b/1486.\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234/1486-\346\225\260\347\273\204\345\274\202\346\210\226\346\223\215\344\275\234.py" @@ -0,0 +1,11 @@ +class Solution(object): + def xorOperation(self, n, start): + """ + :type n: int + :type start: int + :rtype: int + """ + res = start + for i in range(1, n): + res ^= start + 2 * i + return res \ 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.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.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.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 From 63e65b17fbe7a57c24b2ec054ab36c43ce1e5e1c Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 19 Aug 2020 01:19:52 -0400 Subject: [PATCH 144/183] 2020-08-19 --- ...54\346\260\264\346\211\276\351\233\266.py" | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git "a/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266/0860-\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.py" "b/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266/0860-\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.py" index a0b77f2..15c9101 100644 --- "a/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266/0860-\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.py" +++ "b/0860.\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266/0860-\346\237\240\346\252\254\346\260\264\346\211\276\351\233\266.py" @@ -4,18 +4,22 @@ def lemonadeChange(self, bills): :type bills: List[int] :rtype: bool """ - five = ten = 0 - for num in bills: - if num == 5: - five += 1 - elif num == 10 and five: - ten += 1 - five -= 1 - elif num == 20 and five and ten: - five -= 1 - ten -= 1 - elif num == 20 and five >= 3: - five -= 3 + dic = {5:0, 10:0} + + for bill in bills: + if bill == 5: + dic[5] += 1 + elif bill == 10: + if dic[5] < 1: + return False + dic[5] -= 1 + dic[10] += 1 else: - return False - return True \ No newline at end of file + if dic[10] and dic[5]: + dic[10] -= 1 + dic[5] -= 1 + elif dic[5] >= 3: + dic[5] -= 3 + else: + return False + return True From 14fe5e836b89c61b92112bbb4c6060384689efbf Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 22 Aug 2020 00:01:30 -0400 Subject: [PATCH 145/183] 2020-08-22 --- ...75\344\270\211\345\205\203\347\273\204.py" | 18 ++++++++++ ...17\347\232\204\350\265\242\345\256\266.py" | 19 +++++++++++ ...44\346\215\242\346\254\241\346\225\260.py" | 34 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 "1534.\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204/1534-\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204.py" create mode 100644 "1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" create mode 100644 "1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" diff --git "a/1534.\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204/1534-\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204.py" "b/1534.\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204/1534-\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204.py" new file mode 100644 index 0000000..769e5ab --- /dev/null +++ "b/1534.\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204/1534-\347\273\237\350\256\241\345\245\275\344\270\211\345\205\203\347\273\204.py" @@ -0,0 +1,18 @@ +class Solution(object): + def countGoodTriplets(self, arr, a, b, c): + """ + :type arr: List[int] + :type a: int + :type b: int + :type c: int + :rtype: int + """ + res = 0 + for i in range(len(arr)): + for j in range(i + 1, len(arr)): + for k in range(j + 1, len(arr)): + if abs(arr[i] - arr[j]) <= a and \ + abs(arr[j] - arr[k]) <= b and \ + abs(arr[i] - arr[k]) <= c: + res += 1 + return res \ No newline at end of file diff --git "a/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" "b/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" new file mode 100644 index 0000000..18bb48c --- /dev/null +++ "b/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" @@ -0,0 +1,19 @@ +class Solution(object): + def getWinner(self, arr, k): + """ + :type arr: List[int] + :type k: int + :rtype: int + """ + pre = max(arr[0], arr[1]) + cnt = 1 + for num in arr[2:]: + if cnt == k: + return pre + if pre > num: + cnt += 1 + else: + pre = num + cnt = 1 + return pre + \ No newline at end of file diff --git "a/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" "b/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" new file mode 100644 index 0000000..6529eba --- /dev/null +++ "b/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" @@ -0,0 +1,34 @@ +class Solution(object): + def minSwaps(self, grid): + """ + :type grid: List[List[int]] + :rtype: int + """ + from collections import defaultdict, deque + dic = dict() + n = len(grid) + for i, row in enumerate(grid): + cnt = 0 + for j in range(n - 1, -1, -1): + if not row[j]: + cnt += 1 + else: + break + dic[i] = cnt + + res = 0 + for i in range(n): + zero_cnt = dic[i] + + if zero_cnt < n - i - 1: + for j in range(i + 1, n): + if dic[j] >= n - i - 1: + break + if dic[j] < n - i - 1: + return -1 + tmp = dic[j] + res += j - i + for k in range(j, i, -1): + dic[k] = dic[k - 1] + + return res From c9cc510c9aed7320255b0a1ce0a2a83c6e3360eb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 22 Aug 2020 00:28:46 -0400 Subject: [PATCH 146/183] 2020-08-22 --- ...00\345\244\247\345\276\227\345\210\206.py" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" diff --git "a/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" new file mode 100644 index 0000000..47119f0 --- /dev/null +++ "b/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" @@ -0,0 +1,48 @@ +class Solution(object): + def maxSum(self, nums1, nums2): + """ + :type nums1: List[int] + :type nums2: List[int] + :rtype: int + """ + from collections import defaultdict + from heapq import * + num2idx = defaultdict(list) + for i, num in enumerate(nums1): + num2idx[num] = [i] + + for i, num in enumerate(nums2): + num2idx[num].append(i) + + dups = set() + for key, val in num2idx.items(): + if len(val) > 1: + dups.add(key) + + num2sum = defaultdict(int) + res = 0 + queue = [(-nums1[-1], len(nums1) - 1, 0, 1), (-nums2[-1], len(nums2) - 1, 0, 2)] + heapify(queue) + while queue: + val, idx, s, flag = heappop(queue) + val = -val + + if flag == 1 and idx + 1 < len(nums1) and nums1[idx + 1] in dups: + s = max(num2sum[nums1[idx + 1]], s) + elif flag == 2 and idx + 1 < len(nums2) and nums2[idx + 1] in dups: + s = max(num2sum[nums2[idx + 1]], s) + + if val in dups: + s = max(num2sum[val], s + val) + num2sum[val] = max(s, num2sum[val]) + else: + s += val + + if idx: + if flag == 1: + heappush(queue, (-nums1[idx - 1], idx - 1, s, 1)) + else: + heappush(queue, (-nums2[idx - 1], idx - 1, s, 2)) + res = max(res, s) + return res % (10 ** 9 + 7) + \ No newline at end of file From fc01070f79c9b859b4913a6662e2421bd9571757 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 22 Aug 2020 01:05:30 -0400 Subject: [PATCH 147/183] 2020-08-22 --- ...00\345\244\247\345\276\227\345\210\206.py" | 53 ++++++------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git "a/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" "b/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" index 47119f0..a596c4c 100644 --- "a/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" +++ "b/1537.\346\234\200\345\244\247\345\276\227\345\210\206/1537-\346\234\200\345\244\247\345\276\227\345\210\206.py" @@ -5,44 +5,23 @@ def maxSum(self, nums1, nums2): :type nums2: List[int] :rtype: int """ - from collections import defaultdict - from heapq import * - num2idx = defaultdict(list) - for i, num in enumerate(nums1): - num2idx[num] = [i] + dups = set(nums1) & set(nums2) - for i, num in enumerate(nums2): - num2idx[num].append(i) + s1 = self.getFragmentedSum(nums1, dups) + s2 = self.getFragmentedSum(nums2, dups) - dups = set() - for key, val in num2idx.items(): - if len(val) > 1: - dups.add(key) - - num2sum = defaultdict(int) res = 0 - queue = [(-nums1[-1], len(nums1) - 1, 0, 1), (-nums2[-1], len(nums2) - 1, 0, 2)] - heapify(queue) - while queue: - val, idx, s, flag = heappop(queue) - val = -val - - if flag == 1 and idx + 1 < len(nums1) and nums1[idx + 1] in dups: - s = max(num2sum[nums1[idx + 1]], s) - elif flag == 2 and idx + 1 < len(nums2) and nums2[idx + 1] in dups: - s = max(num2sum[nums2[idx + 1]], s) - - if val in dups: - s = max(num2sum[val], s + val) - num2sum[val] = max(s, num2sum[val]) - else: - s += val - - if idx: - if flag == 1: - heappush(queue, (-nums1[idx - 1], idx - 1, s, 1)) - else: - heappush(queue, (-nums2[idx - 1], idx - 1, s, 2)) - res = max(res, s) + for sum1, sum2 in zip(s1, s2): + res += max(sum1, sum2) return res % (10 ** 9 + 7) - \ No newline at end of file + + def getFragmentedSum(self, nums, dups): + l = [] + s = 0 + for num in nums: + s += num + if num in dups: + l.append(s) + s = 0 + l.append(s) + return l \ No newline at end of file From c258f2230bb4ea45cf4220f80274214eed88b069 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 22 Aug 2020 01:25:23 -0400 Subject: [PATCH 148/183] 2020-08-22 --- ...17\347\232\204\350\265\242\345\256\266.py" | 12 +++++----- ...44\346\215\242\346\254\241\346\225\260.py" | 23 ++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git "a/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" "b/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" index 18bb48c..b81bf48 100644 --- "a/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" +++ "b/1535.\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266/1535-\346\211\276\345\207\272\346\225\260\347\273\204\346\270\270\346\210\217\347\232\204\350\265\242\345\256\266.py" @@ -5,15 +5,15 @@ def getWinner(self, arr, k): :type k: int :rtype: int """ - pre = max(arr[0], arr[1]) + winner = max(arr[0], arr[1]) cnt = 1 for num in arr[2:]: if cnt == k: - return pre - if pre > num: + return winner + if winner > num: cnt += 1 else: - pre = num + #鍒锋柊winner + winner = num cnt = 1 - return pre - \ No newline at end of file + return winner \ No newline at end of file diff --git "a/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" "b/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" index 6529eba..bd629d5 100644 --- "a/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" +++ "b/1536.\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260/1536-\346\216\222\345\270\203\344\272\214\350\277\233\345\210\266\347\275\221\346\240\274\347\232\204\346\234\200\345\260\221\344\272\244\346\215\242\346\254\241\346\225\260.py" @@ -4,10 +4,9 @@ def minSwaps(self, grid): :type grid: List[List[int]] :rtype: int """ - from collections import defaultdict, deque - dic = dict() + dic = dict() # key 鏄瘡琛岀殑idx锛 val 鏄繖涓琛屾湯灏0鐨勪釜鏁 n = len(grid) - for i, row in enumerate(grid): + for i, row in enumerate(grid): # 缁熻姣忎竴琛屾湯灏炬湁鍑犱釜0 cnt = 0 for j in range(n - 1, -1, -1): if not row[j]: @@ -18,17 +17,15 @@ def minSwaps(self, grid): res = 0 for i in range(n): - zero_cnt = dic[i] - - if zero_cnt < n - i - 1: + if dic[i] < n - i - 1: # 杩欎竴琛0澶皯锛岄渶瑕佹斁鍒颁笅闈㈠幓 for j in range(i + 1, n): - if dic[j] >= n - i - 1: + if dic[j] >= n - i - 1: # 鎵惧埌0瓒冲澶氱殑琛 break - if dic[j] < n - i - 1: + if dic[j] < n - i - 1: # 娌℃壘鍒拌鏄庢棤瑙 return -1 - tmp = dic[j] - res += j - i - for k in range(j, i, -1): + + for k in range(j, i, -1): #鎶婄i琛屾崲鍒扮j琛岀殑浣嶇疆涓婂幓 dic[k] = dic[k - 1] - - return res + + res += j - i + return res \ No newline at end of file From 0fb1fea9b094c59a43efed0100f088ede4b62913 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 22 Aug 2020 22:03:20 -0400 Subject: [PATCH 149/183] 2020-08-22 --- ...06\345\255\227\347\254\246\344\270\262.py" | 13 ++++++++++ ...5\347\232\204\347\254\254K\344\275\215.py" | 25 +++++++++++++++++++ ...60\347\273\204\346\225\260\347\233\256.py" | 19 ++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 "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" create mode 100644 "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" create mode 100644 "1546.\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1546-\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" 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" new file mode 100644 index 0000000..24cae60 --- /dev/null +++ "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" @@ -0,0 +1,13 @@ +class Solution(object): + def makeGood(self, s): + """ + :type s: str + :rtype: str + """ + stack = [] + for ch in s: + if not stack or abs(ord(stack[-1]) - ord(ch)) != 32: + stack.append(ch) + else: + stack.pop() + return "".join(ch for ch in 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" new file mode 100644 index 0000000..095f097 --- /dev/null +++ "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" @@ -0,0 +1,25 @@ +class Solution(object): + def findKthBit(self, n, k): + """ + :type n: int + :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 + 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] diff --git "a/1546.\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1546-\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" "b/1546.\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1546-\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" new file mode 100644 index 0000000..78f8610 --- /dev/null +++ "b/1546.\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256/1546-\345\222\214\344\270\272\347\233\256\346\240\207\345\200\274\347\232\204\346\234\200\345\244\247\346\225\260\347\233\256\344\270\215\351\207\215\345\217\240\351\235\236\347\251\272\345\255\220\346\225\260\347\273\204\346\225\260\347\233\256.py" @@ -0,0 +1,19 @@ +class Solution(object): + def maxNonOverlapping(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: int + """ + pre_sum = {0} + res = 0 + s = 0 + for num in nums: + s += num + if s - target in pre_sum: + res += 1 + s = 0 + pre_sum = {0} + else: + pre_sum.add(s) + return res From 6d75a1fa34f57d9995c55dc7ec960c8cb0422ef0 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 23 Aug 2020 23:11:38 -0400 Subject: [PATCH 150/183] 2020-08-23 --- ...25\260\347\232\204\346\225\260\347\273\204.py" | 15 +++++++++++++++ ...60\217\346\223\215\344\275\234\346\225\260.py" | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 "1550.\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204/1550-\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204.py" create mode 100644 "1551.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1551-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" diff --git "a/1550.\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204/1550-\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204.py" "b/1550.\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204/1550-\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204.py" new file mode 100644 index 0000000..bb96e4f --- /dev/null +++ "b/1550.\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204/1550-\345\255\230\345\234\250\350\277\236\347\273\255\344\270\211\344\270\252\345\245\207\346\225\260\347\232\204\346\225\260\347\273\204.py" @@ -0,0 +1,15 @@ +class Solution(object): + def threeConsecutiveOdds(self, arr): + """ + :type arr: List[int] + :rtype: bool + """ + l = 0 + for num in arr: + if num % 2: + l += 1 + if l == 3: + return True + else: + l = 0 + return False \ No newline at end of file diff --git "a/1551.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1551-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" "b/1551.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1551-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\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..c1cb604 --- /dev/null +++ "b/1551.\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260/1551-\344\275\277\346\225\260\347\273\204\344\270\255\346\211\200\346\234\211\345\205\203\347\264\240\347\233\270\347\255\211\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260.py" @@ -0,0 +1,12 @@ +class Solution(object): + def minOperations(self, n): + """ + :type n: int + :rtype: int + """ + k = n // 2 + if n % 2: + return 2 * k + k * (k - 1) // 2 * 2 + else: + return 1 * k + k * (k - 1) // 2 * 2 + \ No newline at end of file From 2de7630f5fc2df91bf7e92b992fabb34eeac50b1 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 27 Aug 2020 22:25:14 -0400 Subject: [PATCH 151/183] 2020-08-27 --- .../0342-4\347\232\204\345\271\202.py" | 12 +----------- ...4\275\215\345\210\206\351\232\224\346\225\260.py" | 1 + ...0\260\203\347\224\250\346\254\241\346\225\260.py" | 1 + ...4\270\255\346\216\242\346\265\213\347\216\257.py" | 1 + 4 files changed, 4 insertions(+), 11 deletions(-) create mode 100644 "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" create mode 100644 "1558.\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260/1558-\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260.py" create mode 100644 "1559.\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257/1559-\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257.py" diff --git "a/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" "b/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" index d6d0e82..4af1832 100644 --- "a/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" +++ "b/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" @@ -1,11 +1 @@ -class Solution(object): - def isPowerOfFour(self, num): - """ - :type num: int - :rtype: bool - """ - i = 1 - while(i Date: Thu, 27 Aug 2020 22:40:57 -0400 Subject: [PATCH 152/183] 2020-08-27 --- .../0342-4\347\232\204\345\271\202.py" | 13 ++++- ...15\345\210\206\351\232\224\346\225\260.py" | 14 ++++- ...03\347\224\250\346\254\241\346\225\260.py" | 13 ++++- ...55\346\216\242\346\265\213\347\216\257.py" | 55 ++++++++++++++++++- 4 files changed, 91 insertions(+), 4 deletions(-) diff --git "a/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" "b/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" index 4af1832..2a5e42a 100644 --- "a/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" +++ "b/0342.4\347\232\204\345\271\202/0342-4\347\232\204\345\271\202.py" @@ -1 +1,12 @@ -None \ No newline at end of file +class Solution(object): + def isPowerOfFour(self, num): + """ + :type num: int + :rtype: bool + """ + while num >= 4: + if num % 4: + return False + num //= 4 + + return num == 1 \ No newline at end of file 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 4af1832..284c19e 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" @@ -1 +1,13 @@ -None \ No newline at end of file +class Solution(object): + 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: + res += "." + return res[::-1] \ No newline at end of file diff --git "a/1558.\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260/1558-\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260.py" "b/1558.\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260/1558-\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260.py" index 4af1832..9a8effc 100644 --- "a/1558.\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260/1558-\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260.py" +++ "b/1558.\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260/1558-\345\276\227\345\210\260\347\233\256\346\240\207\346\225\260\347\273\204\347\232\204\346\234\200\345\260\221\345\207\275\346\225\260\350\260\203\347\224\250\346\254\241\346\225\260.py" @@ -1 +1,12 @@ -None \ No newline at end of file +class Solution(object): + def minOperations(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + res = 0 + for num in nums: + res += bin(num).count("1") + + res += len(bin(max(nums))[2:]) - 1 + return res \ No newline at end of file diff --git "a/1559.\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257/1559-\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257.py" "b/1559.\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257/1559-\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257.py" index 4af1832..b6e8536 100644 --- "a/1559.\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257/1559-\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257.py" +++ "b/1559.\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257/1559-\344\272\214\347\273\264\347\275\221\346\240\274\345\233\276\344\270\255\346\216\242\346\265\213\347\216\257.py" @@ -1 +1,54 @@ -None \ No newline at end of file +class Solution(object): + def containsCycle(self, grid): + """ + :type grid: List[List[str]] + :rtype: bool + """ + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + ufs = UnionFindSet(grid) + m, n = len(grid), len(grid[0]) + for i in range(m): + for j in range(n): + for next_i, next_j in [(i - 1, j), (i, j - 1)]: + if 0 <= next_i < m and 0 <= next_j < n and grid[next_i][next_j] == grid[i][j]: + if ufs.find(i * n + j) == ufs.find(next_i * n + next_j): + return True + else: + ufs.union(i * n + j, next_i * n + next_j) + return False + +class UnionFindSet(object): + def __init__(self, grid): + m, n = len(grid), len(grid[0]) + self.roots = [-1 for i in range(m*n)] + self.rank = [0 for i in range(m*n)] + self.count = 0 + + for i in range(m): + for j in range(n): + self.roots[i * n + j] = i * n + j + self.count += 1 + + 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 + \ No newline at end of file From dbd9372876f56442f93631cf262106afa20bbed3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 28 Aug 2020 21:13:29 -0400 Subject: [PATCH 153/183] 2020-08-28 --- ...54\347\224\237\350\212\202\347\202\271.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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.py" 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.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.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.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 From 33c91a9eb88779f004503830b2da109a51b154cd Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 10 Sep 2020 23:50:31 -0400 Subject: [PATCH 154/183] 2020-09-10 --- ...232\204\346\255\243\346\225\264\346\225\260.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "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" 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" new file mode 100644 index 0000000..4572955 --- /dev/null +++ "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" @@ -0,0 +1,14 @@ +class Solution(object): + def findKthPositive(self, arr, k): + """ + :type arr: List[int] + :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 From dac0734267a8cf7a7d3deddf859ec9eb8cb0e307 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 20 Sep 2020 21:32:48 -0400 Subject: [PATCH 155/183] 2020-09-20 --- ...27\351\251\254\346\225\260\345\255\227.py" | 21 ++++---- ...27\350\275\254\346\225\264\346\225\260.py" | 28 ++++------ ...11\345\210\267\346\210\277\345\255\220.py" | 2 +- ...15\345\217\240\345\214\272\351\227\264.py" | 18 +++++++ ...25\347\210\206\346\260\224\347\220\203.py" | 16 +++--- .../0542-01\347\237\251\351\230\265.py" | 54 ++++++++----------- ...1-\346\225\221\347\224\237\350\211\207.py" | 22 ++++++++ 7 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 "0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264/0435-\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.py" create mode 100644 "0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" diff --git "a/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" "b/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" index f49d843..b0d9569 100644 --- "a/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" +++ "b/0012.\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227/0012-\346\225\264\346\225\260\350\275\254\347\275\227\351\251\254\346\225\260\345\255\227.py" @@ -4,13 +4,16 @@ def intToRoman(self, num): :type num: int :rtype: str """ - digit = [1000,900,500,400,100,90,50,40,10,9,5,4,1] - mapping = {1000:"M", 900:"CM", 500:"D",400:"CD", 100:"C", 90: "XC", 50:"L",40: "XL", 10:"X", 9:"IX", 5:"V", 4:"IV", 1:"I"} + l = [(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), \ + (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), \ + (9, "IX"), (5, "V"), (4, "IV"), (1, "I")][::-1] res = "" - for i in digit: - res += (num / i) * mapping[i] - num -= i * (num / i) - if num == 0: - break - return res - + while num: + for value, ch in l[::-1]: + if num >= value: + res += ch + num -= value + break + else: + l.pop() + return res \ No newline at end of file diff --git "a/0013.\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.py" "b/0013.\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.py" index 2caa879..c0f930a 100644 --- "a/0013.\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.py" +++ "b/0013.\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.py" @@ -4,21 +4,15 @@ def romanToInt(self, s): :type s: str :rtype: int """ - dic = {"I": 1, "V":5, "X": 10, "L":50, "C":100, "D": 500, "M": 1000} - stack = [] + dic = {"I":1, "V": 5, "X":10, "L":50, "C":100, "D":500, "M":1000} res = 0 - for inx, item in enumerate(s): - res += dic[item] - # print res - # s.append(item) - if item == "V" or item == "X": - if stack and stack[-1] == "I": - res -= 2 - elif item == "L" or item == "C": - if stack and stack[-1] == "X": - res -= 20 - elif item == "D" or item == "M": - if stack and stack[-1] == "C": - res -= 200 - stack.append(item) - return res \ No newline at end of file + pre_value = None + for ch in s: + if (ch in ["V", "X"] and pre_value == 1) or \ + (ch in ["L", "C"] and pre_value == 10) or \ + (ch in ["D", "M"] and pre_value == 100): + res += dic[ch] - 2 * pre_value + else: + res += dic[ch] + pre_value = dic[ch] + return res diff --git "a/0256.\347\262\211\345\210\267\346\210\277\345\255\220/0256-\347\262\211\345\210\267\346\210\277\345\255\220.py" "b/0256.\347\262\211\345\210\267\346\210\277\345\255\220/0256-\347\262\211\345\210\267\346\210\277\345\255\220.py" index 8a86c0f..c9ec3f2 100644 --- "a/0256.\347\262\211\345\210\267\346\210\277\345\255\220/0256-\347\262\211\345\210\267\346\210\277\345\255\220.py" +++ "b/0256.\347\262\211\345\210\267\346\210\277\345\255\220/0256-\347\262\211\345\210\267\346\210\277\345\255\220.py" @@ -10,4 +10,4 @@ def minCost(self, costs): costs[i][0] += min(costs[i - 1][1], costs[i - 1][2]) costs[i][1] += min(costs[i - 1][0], costs[i - 1][2]) costs[i][2] += min(costs[i - 1][0], costs[i - 1][1]) - return min(costs[-1]) \ No newline at end of file + return min(costs[-1]) \ No newline at end of file diff --git "a/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264/0435-\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.py" "b/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264/0435-\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.py" new file mode 100644 index 0000000..c05a4bf --- /dev/null +++ "b/0435.\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264/0435-\346\227\240\351\207\215\345\217\240\345\214\272\351\227\264.py" @@ -0,0 +1,18 @@ +class Solution(object): + def eraseOverlapIntervals(self, intervals): + """ + :type intervals: List[List[int]] + :rtype: int + """ + if not intervals or not intervals[0]: + return 0 + + intervals = sorted(intervals, key = lambda x:x[1]) + pre_end = intervals[0][1] + canAttendCnt = 1 + for i in range(1, len(intervals)): + if intervals[i][0] >= pre_end: # start later than previous one end + canAttendCnt += 1 + pre_end = intervals[i][1] + return len(intervals) - canAttendCnt + diff --git "a/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" "b/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" index 64b8736..90c371e 100644 --- "a/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" +++ "b/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203/0452-\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.py" @@ -7,14 +7,12 @@ def findMinArrowShots(self, points): if not points or not points[0]: return 0 - points.sort(key = lambda x:x[1]) - - arrow = points[0][1] - + points = sorted(points, key = lambda x: x[1]) res = 1 - for point in points: - if arrow < point[0]: + pre_end = points[0][1] + + for i in range(1, len(points)): + if points[i][0] > pre_end: res += 1 - arrow = point[1] - - return res \ No newline at end of file + pre_end = points[i][1] + return res diff --git "a/0542.01\347\237\251\351\230\265/0542-01\347\237\251\351\230\265.py" "b/0542.01\347\237\251\351\230\265/0542-01\347\237\251\351\230\265.py" index b5e180f..d95fb0c 100644 --- "a/0542.01\347\237\251\351\230\265/0542-01\347\237\251\351\230\265.py" +++ "b/0542.01\347\237\251\351\230\265/0542-01\347\237\251\351\230\265.py" @@ -1,43 +1,35 @@ -from collections import deque class Solution(object): def updateMatrix(self, matrix): """ :type matrix: List[List[int]] :rtype: List[List[int]] """ + from collections import deque if not matrix or not matrix[0]: - return matrix + return matrix m, n = len(matrix), len(matrix[0]) - res = matrix[:] - - q = deque() - - for i in range(m): - for j in range(n): - if matrix[i][j] == 0: - q.append([[i, j], 0]) - dx = [1, -1, 0, 0] + dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - visited = [[0 for _ in range(n + 1)] for _ in range(m + 1)] - - while q: - tmp, distance = q.popleft() - x0, y0 = tmp[0], tmp[1] - - if matrix[x0][y0] == 1: - res[x0][y0] = distance + res = [[0 for _ in range(n)] for _ in range (m)] + for i in range(m): + for j in range(n): + if matrix[i][j] == 1: + queue = deque([(i, j, 0)]) + visited = set((i, j)) + while queue: + x, y, dist = queue.popleft() - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] + if matrix[x][y] == 0: + res[i][j] = dist + break + else: + for k in range(4): + xx = x + dx[k] + yy = y + dy[k] - if 0 <= x < m and 0 <= y < n and visited[x][y] != 1: - q.append([[x, y], distance + 1]) - visited[x][y] = 1 - return res - - - - - \ No newline at end of file + if 0 <= xx < m and 0 <= yy < n and (xx, yy) not in visited: + visited.add((xx, yy)) + queue.append((xx, yy, dist + 1)) + + return res \ No newline at end of file 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" new file mode 100644 index 0000000..b98af18 --- /dev/null +++ "b/0881.\346\225\221\347\224\237\350\211\207/0881-\346\225\221\347\224\237\350\211\207.py" @@ -0,0 +1,22 @@ +class Solution(object): + def numRescueBoats(self, people, limit): + """ + :type people: List[int] + :type limit: int + :rtype: int + """ + people.sort() + left, right = 0, len(people) - 1 + res = 0 + while left <= right: + if left == right: + res += 1 + break + 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 From ba663fede3c3395f59d6294bdce6efafc80e3ace Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 29 Sep 2020 23:56:07 -0400 Subject: [PATCH 156/183] 2020-09-29 --- ...70\345\220\214\347\232\204\346\240\221.py" | 4 ++- ...60\344\272\214\345\217\211\346\240\221.py" | 17 ++++++----- ...57\345\276\204\346\200\273\345\222\214.py" | 15 ++++++---- ...\345\276\204\346\200\273\345\222\214II.py" | 24 ++++++++-------- ...02\347\202\271\344\270\252\346\225\260.py" | 28 ++++--------------- ...54\344\272\214\345\217\211\346\240\221.py" | 9 +++--- 6 files changed, 44 insertions(+), 53 deletions(-) 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.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.py" index b855115..6a9f982 100644 --- "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.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.py" @@ -13,6 +13,8 @@ def isSameTree(self, p, q): """ if not p and not q: return True - if not p or not q: + 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/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/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" index 1ae0835..9caa639 100644 --- "a/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/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" @@ -11,11 +11,14 @@ def isSymmetric(self, root): :type root: TreeNode :rtype: bool """ - def helper(node1, node2): - if not node1: - return not node2 - if not node2: - return not node1 - return node1.val == node2.val and helper(node1.left, node2.right) and helper(node1.right, node2.left) - return helper(root, root) \ No newline at end of file + def isSame(node1, node2): + if not node1 and not node2: + return True + if not node1 and node2: + return False + if node1 and not node2: + return False + return node1.val == node2.val and isSame(node1.left, node2.right) and isSame(node1.right, node2.left) + + return isSame(root, root) \ 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.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.py" index ce9a472..274aed8 100644 --- "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.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.py" @@ -12,8 +12,13 @@ def hasPathSum(self, root, sum): :type sum: int :rtype: bool """ - if not root: - return False - if not root.left and not root.right: - return root.val == sum - return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val) \ No newline at end of file + 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.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.py" index b03107d..79538f5 100644 --- "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.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.py" @@ -6,25 +6,23 @@ # self.right = None class Solution(object): - def pathSum(self, root, s): + def pathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: List[List[int]] """ res = [] - def dfs(node, path): + def dfs(node, path, s): if not node: - return + return [] + s += node.val + if not node.left and not node.right: + if s == sum: + res.append(path + [node.val]) - path += [node.val] - if not node.left and not node.right and sum(path) == s: - res.append(path[:]) - - dfs(node.left, path) - dfs(node.right, path) - - path.pop() - - dfs(root, []) + 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/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/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" index 58e9408..0cf67da 100644 --- "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.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.py" @@ -11,26 +11,8 @@ def countNodes(self, root): :type root: TreeNode :rtype: int """ - if not root: - return 0 - - self.leavesCnt = 0 - self.height = 0 - self.flag = 0 - def dfs(node, layer): - if not node or self.flag: - return - if not node.left and not node.right: - - self.height = max(self.height, layer) - if layer < self.height: - self.flag = 1 - else: - self.leavesCnt += 1 - return - dfs(node.left, layer + 1) - dfs(node.right, layer + 1) - - dfs(root, 0) - # print self.leavesCnt - return self.leavesCnt + sum([2 ** i for i in range(self.height)] ) \ No newline at end of file + 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/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/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" index 59cd84a..30d3e64 100644 --- "a/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/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" @@ -13,8 +13,9 @@ def invertTree(self, root): """ if not root: return root - left = root.left - right = root.right - root.left = self.invertTree(right) - root.right = self.invertTree(left) + left = self.invertTree(root.left) + right = self.invertTree(root.right) + + root.left = right + root.right = left return root \ No newline at end of file From fd6f8321035ba3e0a7f84b57f522bcdf4cd5c9bb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sat, 3 Oct 2020 23:52:48 -0400 Subject: [PATCH 157/183] 2020-10-03 --- ...44\346\225\260\344\271\213\345\222\214.py" | 2 +- ...00\351\225\277\345\255\220\344\270\262.py" | 18 ++++---- ...04\344\270\255\344\275\215\346\225\260.py" | 24 +++++++++++ ...36\346\226\207\345\255\220\344\270\262.py" | 43 ++++++++----------- 4 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 "0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" diff --git "a/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/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" index 8b92177..2201fce 100644 --- "a/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/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" @@ -9,4 +9,4 @@ def twoSum(self, nums, target): for i, num in enumerate(nums): if target - num in dic: return [dic[target - num], i] - dic[num] = i \ No newline at end of file + dic[num] = i diff --git "a/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" "b/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" index 7fcc3ef..8a1f7f4 100644 --- "a/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" +++ "b/0003.\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" @@ -4,13 +4,13 @@ def lengthOfLongestSubstring(self, s): :type s: str :rtype: int """ - record = {} - start, res = 0, 0 - for end in range(len(s)): - if s[end] in record: - start = max(start, record[s[end]] + 1) - - record[s[end]] = end - res = max(res, end - start + 1) - + left, right = 0, 0 + dic = dict() + res = 0 + while right < len(s): + if s[right] in dic: + left = max(left, dic[s[right]] + 1) + dic[s[right]] = right + res = max(res, right - left + 1) + right += 1 return res \ No newline at end of file diff --git "a/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" "b/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" new file mode 100644 index 0000000..b500112 --- /dev/null +++ "b/0004.\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\255\243\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.py" @@ -0,0 +1,24 @@ +class Solution(object): + def findMedianSortedArrays(self, nums1, nums2): + """ + :type nums1: List[int] + :type nums2: List[int] + :rtype: float + """ + res = [] + p1, p2 = 0, 0 + while p1 < len(nums1) and p2 < len(nums2): + if nums1[p1] <= nums2[p2]: + res.append(nums1[p1]) + p1 += 1 + else: + res.append(nums2[p2]) + p2 += 1 + while p1 < len(nums1): + res.append(nums1[p1]) + p1 += 1 + while p2 < len(nums2): + res.append(nums2[p2]) + p2 += 1 + print res + return res[len(res) // 2] if len(res) % 2 == 1 else (res[len(res) // 2 - 1] + res[len(res) // 2]) * 1.0 / 2 \ No newline at end of file diff --git "a/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" "b/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" index d1f7847..8033cf5 100644 --- "a/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" +++ "b/0005.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262/0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.py" @@ -4,30 +4,21 @@ def longestPalindrome(self, s): :type s: str :rtype: str """ - left, right = 0, 0 - res, string = 0, "" + res = "" for i in range(len(s)): - left, right = i, i - while(left >= 0 and right < len(s) and s[left] == s[right]): - left -= 1 - right += 1 - left += 1 - right -= 1 - - if right - left + 1 > res: - res = right - left + 1 - string = s[left:right + 1] - - for i in range(1, len(s)): - left, right = i - 1, i - while(left >= 0 and right < len(s) and s[left] == s[right]): - left -= 1 - right += 1 - left += 1 - right -= 1 - - if right - left + 1 > res: - res = right - left + 1 - string = s[left:right + 1] - return string - \ No newline at end of file + tmp = self.centralSpread(i, i, s) + if len(tmp) > len(res): + res = tmp + tmp = self.centralSpread(i, i + 1, s) + if len(tmp) > len(res): + res = tmp + return res + + def centralSpread(self, left, right, s): + res = "" + while left >= 0 and right < len(s) and s[left] == s[right]: + res = s[left: right + 1] + left -= 1 + right += 1 + # print res, left, right + return res \ No newline at end of file From cbbc73cb87b611ebd6ea73bbc223e18d5e6233f3 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Sun, 4 Oct 2020 23:53:44 -0400 Subject: [PATCH 158/183] 2020-10-04 --- ...46\225\210\347\232\204\346\213\254\345\217\267.py" | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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.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.py" index 4a34f9b..8103871 100644 --- "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.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.py" @@ -4,14 +4,13 @@ def isValid(self, s): :type s: str :rtype: bool """ - mapping = {")":"(", "]":"[", "}":"{"} + dic = {")": "(", "]":"[", "}":"{"} stack = [] - for i, char in enumerate(s): - if char not in mapping:#left - stack.append(char) + for ch in s: + if ch in ["(", "[", "{"]: + stack.append(ch) else: - if not stack or stack[-1] != mapping[char]: + if not stack or dic[ch] != stack[-1]: return False stack.pop() - return len(stack) == 0 \ No newline at end of file From 468f8bd333bf742bd11fc1b5ec5dc304faaf11ee Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Mon, 5 Oct 2020 23:49:56 -0400 Subject: [PATCH 159/183] 2020-10-05 --- ...15\345\255\220\346\225\260\347\273\204.py" | 19 ++++++++++ ...77\351\227\256\350\256\241\346\225\260.py" | 36 +++++++++---------- 2 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 "0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/0718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" diff --git "a/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/0718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" "b/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/0718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" new file mode 100644 index 0000000..90afcab --- /dev/null +++ "b/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204/0718-\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.py" @@ -0,0 +1,19 @@ +class Solution(object): + def findLength(self, A, B): + """ + :type A: List[int] + :type B: List[int] + :rtype: int + """ + # dp[i][j] represents A[:i + 1], B[:j + 1] longest common subarray length + dp = [[0 for _ in range(len(B) + 1)] for _ in range(len(A) + 1)] + + res = 0 + + for i in range(1, len(A) + 1): + for j in range(1, len(B) + 1): + if A[i - 1] == B[j - 1]: + dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1) + res = max(dp[i][j], res) + # print dp + return res \ No newline at end of file diff --git "a/0811.\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260/0811-\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260.py" "b/0811.\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260/0811-\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260.py" index 6b74440..d4063c2 100644 --- "a/0811.\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260/0811-\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260.py" +++ "b/0811.\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260/0811-\345\255\220\345\237\237\345\220\215\350\256\277\351\227\256\350\256\241\346\225\260.py" @@ -4,23 +4,19 @@ def subdomainVisits(self, cpdomains): :type cpdomains: List[str] :rtype: List[str] """ - resList = [] - resMap = {} - for s in cpdomains: - count, domains = s.split(' ') - n = domains.count('.') - tmp = domains - for i in range(n+1): - if resMap.has_key(tmp): - resMap[tmp] = resMap[tmp] + int(count) - else: - resMap[tmp] = int(count) - index = tmp.find('.') + 1 - if index == -1: - break - else: - tmp = tmp[index:] - # for key, value in resMap.items(): - # resList.append(str(value) + ' ' + key); - # return resList - return [str(resMap[key]) + ' ' + key for key in resMap] \ No newline at end of file + from collections import defaultdict + dic = defaultdict(int) + + for pair in cpdomains: + splitted_pair = pair.split() + cnt, domain = splitted_pair[0], splitted_pair[1] + cnt = int(cnt) + + for i in range(len(domain)): + if not i or domain[i] == ".": + dic[domain[i:].lstrip(".")] += cnt + + res = [] + for domain, frequency in dic.items(): + res.append(" ".join([str(frequency), domain])) + return res \ No newline at end of file From 016288bc703d4f6e0d8aee4664b1d24190977cbb Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Tue, 6 Oct 2020 23:39:45 -0400 Subject: [PATCH 160/183] 2020-10-06 --- ...54\345\205\261\347\245\226\345\205\210.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" diff --git "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" new file mode 100644 index 0000000..2c4e088 --- /dev/null +++ "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.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 lowestCommonAncestor(self, root, p, q): + """ + :type root: TreeNode + :type p: TreeNode + :type q: TreeNode + :rtype: TreeNode + """ + if not root: + return None + if root == p or root == q: + return root + left = self.lowestCommonAncestor(root.left, p, q) + right = self.lowestCommonAncestor(root.right, p, q) + + if left and right: + return root + if left: + return left + if right: + return right + return None \ No newline at end of file From d136bd3a4d62c4720b2b22c14198b66e1da2c87f Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Wed, 7 Oct 2020 23:59:19 -0400 Subject: [PATCH 161/183] 2020-10-07 --- ...\234\211\346\225\210\347\232\204\346\213\254\345\217\267.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.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.py" index 8103871..563ad92 100644 --- "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.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.py" @@ -13,4 +13,4 @@ def isValid(self, s): if not stack or dic[ch] != stack[-1]: return False stack.pop() - return len(stack) == 0 \ No newline at end of file + return len(stack) == 0 \ No newline at end of file From 356ba7de9d88d05ea77d449d39b678560c42d343 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 15 Oct 2020 15:21:04 -0400 Subject: [PATCH 162/183] 2020-10-15 --- ...23\345\256\266\345\212\253\350\210\215.py" | 18 +++---- ...33\345\261\277\346\225\260\351\207\217.py" | 46 ++++++++--------- ...6-\345\242\231\344\270\216\351\227\250.py" | 45 ++++++++-------- ...15\345\272\217\345\210\227\345\214\226.py" | 51 +++++++++++++++++++ ...\222\214IV-\350\276\223\345\205\245BST.py" | 30 +++++++++++ 5 files changed, 131 insertions(+), 59 deletions(-) create mode 100644 "0297.\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226/0297-\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.py" create mode 100644 "0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST.py" 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.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.py" index 515cd58..3d94e44 100644 --- "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.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.py" @@ -4,15 +4,11 @@ def rob(self, nums): :type nums: List[int] :rtype: int """ - # return 0 - if not nums: + if len(nums) == 0: 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 + 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/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" "b/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" index 5e1ec45..fc2adf0 100644 --- "a/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" +++ "b/0200.\345\262\233\345\261\277\346\225\260\351\207\217/0200-\345\262\233\345\261\277\346\225\260\351\207\217.py" @@ -1,33 +1,31 @@ -class Solution(object): - def numIslands(self, M): - """ - :type grid: List[List[str]] - :rtype: int - """ - if not M or not M[0]: +class Solution: + def numIslands(self, grid: List[List[str]]) -> int: + from collections import deque + if not grid or not grid[0]: return 0 - m, n = len(M), len(M[0]) - visited = [[0 for j in range(n)] for i in range(m)] - # print visited + + m, n = len(grid), len(grid[0]) + dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] - res = 0 - - def dfs(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 M[x][y] == '1' and visited[x][y] ==0: - visited[x][y] = 1 - dfs(x, y) + res = 0 for i in range(m): for j in range(n): - if M[i][j] == '1' and visited[i][j] == 0: + if grid[i][j] == "1": + grid[i][j] = "0" res += 1 - visited[i][j] = 1 - dfs(i, j) - # print visited + queue = deque([(i, j)]) + + while queue: + x0, y0 = queue.popleft() + for k in range(4): + x = x0 + dx[k] + y = y0 + dy[k] + + if 0 <= x < m and 0 <= y < n and grid[x][y] == "1": + grid[x][y] = "0" + queue.append((x, y)) + return res \ No newline at end of file diff --git "a/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" "b/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" index 826b6d0..0c0707e 100644 --- "a/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" +++ "b/0286.\345\242\231\344\270\216\351\227\250/0286-\345\242\231\344\270\216\351\227\250.py" @@ -1,32 +1,29 @@ -class Solution(object): - def wallsAndGates(self, rooms): +class Solution: + def wallsAndGates(self, rooms: List[List[int]]) -> None: """ - :type rooms: List[List[int]] - :rtype: None Do not return anything, modify rooms in-place instead. + Do not return anything, modify rooms in-place instead. """ from collections import deque + if not rooms or not rooms[0]: return rooms - m, n = len(rooms), len(rooms[0]) - dx = [1, -1, 0, 0] - dy = [0, 0, 1, -1] INF = 2147483647 - queue = deque() - def bfs(queue): - while queue: - pos = queue.popleft() - x0, y0 = pos - - for k in range(4): - x = x0 + dx[k] - y = y0 + dy[k] - if 0 <= x < m and 0 <= y < n and rooms[x][y] == INF: - rooms[x][y] = rooms[x0][y0] + 1 - queue.append((x, y)) - + + m, n = len(rooms), len(rooms[0]) + queue = deque() # (x_pos, y_pos, step from a gate) for i in range(m): for j in range(n): - if rooms[i][j] == 0: #现在从每扇门出发 - queue.append((i, j)) - bfs(queue) - return rooms \ No newline at end of file + if rooms[i][j] == 0: + queue.append((i, j, 0)) + + dx = [1, -1, 0, 0] + dy = [0, 0, 1, -1] + while queue: + x_pos, y_pos, step = queue.popleft() + for k in range(4): + x = x_pos + dx[k] + y = y_pos + dy[k] + + if 0 <= x < m and 0 <= y < n and rooms[x][y] == INF: + rooms[x][y] = step + 1 + queue.append((x, y, step + 1)) \ No newline at end of file diff --git "a/0297.\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226/0297-\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.py" "b/0297.\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226/0297-\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.py" new file mode 100644 index 0000000..c619231 --- /dev/null +++ "b/0297.\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226/0297-\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.py" @@ -0,0 +1,51 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +class Codec: + def serialize(self, root): + """Encodes a tree to a single string. + + :type root: TreeNode + :rtype: str + """ + if not root: + return "" + + s = "" + def preorder(node): + if not node: + return "#" + + return str(node.val) + "," + preorder(node.left) + "," +preorder(node.right) + s = preorder(root) + return s + + def deserialize(self, data): + """Decodes your encoded data to tree. + + :type data: str + :rtype: TreeNode + """ + if not data or data == "#": + return None + queue = deque(data.split(",")) + return self.helper(queue) + + def helper(self, queue): + cur = queue.popleft() + if cur == "#": + return None + root = TreeNode(cur) + root.left = self.helper(queue) + root.right = self.helper(queue) + + return root + +# Your Codec object will be instantiated and called as such: +# ser = Codec() +# deser = Codec() +# ans = deser.deserialize(ser.serialize(root)) \ No newline at end of file diff --git "a/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST.py" "b/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST.py" new file mode 100644 index 0000000..568998a --- /dev/null +++ "b/0653.\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST/0653-\344\270\244\346\225\260\344\271\213\345\222\214IV-\350\276\223\345\205\245BST.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 findTarget(self, root, k): + """ + :type root: TreeNode + :type k: int + :rtype: bool + """ + values = set() + + self.result = False + def inorderTraversal(node): + if not node: + return [] + if not self.result: + if k - node.val in values: + self.result = True + return + values.add(node.val) + + inorderTraversal(node.left) + inorderTraversal(node.right) + inorderTraversal(root) + return self.result + \ No newline at end of file From 83e4f9996978b444d36d68e5663979fa6b2b4567 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Thu, 15 Oct 2020 22:43:27 -0400 Subject: [PATCH 163/183] 2020-10-15 --- ...10\347\232\204\346\225\260\347\213\254.py" | 20 ++-- ...7-\350\247\243\346\225\260\347\213\254.py" | 96 +++++++++++-------- ...47\347\232\204\347\237\251\345\275\242.py" | 19 ++-- ...43\347\240\201\346\226\271\346\263\225.py" | 39 ++++++++ ...70\345\220\214\347\232\204\346\240\221.py" | 16 ++-- ...25\350\257\215\346\213\206\345\210\206.py" | 28 +++--- ...\350\257\215\346\213\206\345\210\206II.py" | 22 +++++ ...7-\350\257\276\347\250\213\350\241\250.py" | 60 ++++++------ ...\350\257\276\347\250\213\350\241\250II.py" | 60 ++++++------ ...53\346\230\237\350\257\215\345\205\270.py" | 45 +++++++++ ...60\347\273\204\351\225\277\345\272\246.py" | 18 ++++ ...30\351\242\221\345\205\203\347\264\240.py" | 28 ++++-- ...3\347\240\201\346\226\271\346\263\2252.py" | 44 +++++++++ ...14\344\270\272\345\210\206\346\236\220.py" | 76 ++++++++------- ...54\345\205\261\347\245\226\345\205\210.py" | 47 ++++----- 15 files changed, 402 insertions(+), 216 deletions(-) create mode 100644 "0091.\350\247\243\347\240\201\346\226\271\346\263\225/0091-\350\247\243\347\240\201\346\226\271\346\263\225.py" create mode 100644 "0140.\345\215\225\350\257\215\346\213\206\345\210\206II/0140-\345\215\225\350\257\215\346\213\206\345\210\206II.py" create mode 100644 "0269.\347\201\253\346\230\237\350\257\215\345\205\270/0269-\347\201\253\346\230\237\350\257\215\345\205\270.py" create mode 100644 "0325.\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246/0325-\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246.py" create mode 100644 "0639.\350\247\243\347\240\201\346\226\271\346\263\2252/0639-\350\247\243\347\240\201\346\226\271\346\263\2252.py" 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.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.py" index ed34e1b..29ea49c 100644 --- "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.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.py" @@ -1,19 +1,15 @@ -class Solution(object): - def isValidSudoku(self, board): - """ - :type board: List[List[str]] - :rtype: bool - """ - from collections import defaultdict - row, column, squre = defaultdict(set), defaultdict(set), defaultdict(set) +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 column[j] or board[i][j] in squre[(i//3, j//3)]: + 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]) - column[j].add(board[i][j]) - squre[(i//3, j //3)].add(board[i][j]) + col[j].add(board[i][j]) + square[(i // 3, j // 3)].add(board[i][j]) return True - \ No newline at end of file diff --git "a/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" "b/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" index cfbd885..f121617 100644 --- "a/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" +++ "b/0037.\350\247\243\346\225\260\347\213\254/0037-\350\247\243\346\225\260\347\213\254.py" @@ -1,48 +1,66 @@ -class Solution(object): - def solveSudoku(self, board): +from collections import defaultdict +import copy +class Solution: + def solveSudoku(self, board: List[List[str]]) -> None: """ - :type board: List[List[str]] - :rtype: None Do not return anything, modify board in-place instead. + Do not return anything, modify board in-place instead. """ - from collections import defaultdict - row, column, squre = defaultdict(set), defaultdict(set), defaultdict(set) - + row = defaultdict(set) + col = defaultdict(set) + square = defaultdict(set) + for i in range(9): + for j in range(9): + if board[i][j].isdigit(): + row[i].add(board[i][j]) + col[j].add(board[i][j]) + square[(i // 3, j // 3)].add(board[i][j]) self.res = [] def dfs(x, y): - - if x == 8 and y == 9: - # print board - for roww in board: - self.res.append(roww[:]) - # print self.res + if x == 9 and y == 0: + if self.isValidSudoku(board): + self.res = copy.deepcopy(board) return - if y == 9: - dfs(x + 1, 0) - return - if board[x][y].isdigit(): - dfs(x, y + 1) - return - - for k in range(1,10): - if str(k) not in row[x] and str(k) not in column[y] and str(k) not in squre[(x // 3, y // 3)]: - board[x][y] = str(k) - row[x].add(str(k)) - column[y].add(str(k)) - squre[(x // 3, y // 3)].add(str(k)) - - dfs(x, y + 1) - - board[x][y] = "." - row[x].remove(str(k)) - column[y].remove(str(k)) - squre[(x // 3, y // 3)].remove(str(k)) + if not self.res: + if board[x][y] != ".": + if y == 8: + dfs(x + 1, 0) + else: + dfs(x, y + 1) + return + + for num in range(1, 10): + num = str(num) + if num not in row[x] and num not in col[y] and num not in square[(x // 3, y // 3)]: + board[x][y] = num + + row[x].add(num) + col[y].add(num) + square[(x // 3, y // 3)].add(num) + if y == 8: + dfs(x + 1, 0) + else: + dfs(x, y + 1) + board[x][y] = "." + row[x].remove(num) + col[y].remove(num) + square[(x // 3, y // 3)].remove(num) + + dfs(0, 0) + board[:] = self.res + + + 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(): - row[i].add(board[i][j].encode("utf-8")) - column[j].add(board[i][j].encode("utf-8")) - squre[(i // 3, j // 3)].add(board[i][j].encode("utf-8")) - - dfs(0, 0) - board[:] = self.res \ No newline at end of file + 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 \ No newline at end of file diff --git "a/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" "b/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" index 465d8f7..0a6ac26 100644 --- "a/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" +++ "b/0084.\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242/0084-\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.py" @@ -1,15 +1,12 @@ -class Solution(object): - def largestRectangleArea(self, heights): - """ - :type heights: List[int] - :rtype: int - """ +class Solution: + def largestRectangleArea(self, heights: List[int]) -> int: heights = [0] + heights + [0] - stack = [] res = 0 - for i, num in enumerate(heights): - while stack and heights[stack[-1]] > num: - top = stack.pop() - res = max(res, (i - stack[-1] - 1) * heights[top]) + stack = [] + for i in range(len(heights)): + while stack and heights[stack[-1]] > heights[i]: + top = stack.pop() + res = max(res, (i - stack[-1] - 1) * heights[top]) + stack.append(i) return res \ No newline at end of file diff --git "a/0091.\350\247\243\347\240\201\346\226\271\346\263\225/0091-\350\247\243\347\240\201\346\226\271\346\263\225.py" "b/0091.\350\247\243\347\240\201\346\226\271\346\263\225/0091-\350\247\243\347\240\201\346\226\271\346\263\225.py" new file mode 100644 index 0000000..61ea284 --- /dev/null +++ "b/0091.\350\247\243\347\240\201\346\226\271\346\263\225/0091-\350\247\243\347\240\201\346\226\271\346\263\225.py" @@ -0,0 +1,39 @@ +class Solution: + def numDecodings(self, s: str) -> int: + if not s or s[0] == "0": + return 0 + + dp = [0]*(len(s) + 1) # dp[i] represents ways of s[:i + 1] + dp[1] = dp[0] = 1 + + for i in range(2, len(s) + 1): + if s[i - 1] == "0": + if s[i - 2] in ["1", "2"]: + dp[i] = dp[i - 2] + else: + return 0 + elif s[i - 2] == "1" or (s[i - 2] == "2" and "1" <= s[i - 1] <= "6"): + dp[i] = dp[i - 1] + dp[i - 2] + else: + dp[i] = dp[i - 1] + return dp[-1] + + # dp = [0]*(len(s) + 1) + # if s[0] == '0': + # return 0 + # dp[0] = 1 + # dp[1] = 1 + # for i in range(2, len(s)+1): + # if s[i-1] == '0' : + # if s[i-2] in ['1', '2']: + # dp[i] = dp[i-2] + # else: + # return 0 + # elif s[i-2] == '1' or (s[i-2] == '2' and '1' <= s[i-1] <= '6'): + # dp[i] = dp[i-1] + dp[i-2] + # else: + # dp[i] = dp[i-1] + # return dp[-1] + + + 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.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.py" index 6a9f982..e3be02d 100644 --- "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.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.py" @@ -1,20 +1,18 @@ # Definition for a binary tree node. -# class TreeNode(object): +# class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right -class Solution(object): - def isSameTree(self, p, q): - """ - :type p: TreeNode - :type q: TreeNode - :rtype: bool - """ +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 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/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" "b/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" index 3adaf59..9ada5e0 100644 --- "a/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" +++ "b/0139.\345\215\225\350\257\215\346\213\206\345\210\206/0139-\345\215\225\350\257\215\346\213\206\345\210\206.py" @@ -1,17 +1,13 @@ -class Solution(object): - def wordBreak(self, s, wordDict): - """ - :type s: str - :type wordDict: List[str] - :rtype: bool - """ - dp = [0] - - for j in range(len(s) + 1): - for i in dp: - if s[i:j] in wordDict: - dp.append(j) +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + from collections import deque + wordDict = set(wordDict) + record = [0] + + for i in range(len(s) + 1): + for j in record: + if s[j:i] in wordDict: + record.append(i) break - # print dp - return dp[-1] == len(s) - \ No newline at end of file + # print (record) + return record[-1] == len(s) \ No newline at end of file diff --git "a/0140.\345\215\225\350\257\215\346\213\206\345\210\206II/0140-\345\215\225\350\257\215\346\213\206\345\210\206II.py" "b/0140.\345\215\225\350\257\215\346\213\206\345\210\206II/0140-\345\215\225\350\257\215\346\213\206\345\210\206II.py" new file mode 100644 index 0000000..74c4db8 --- /dev/null +++ "b/0140.\345\215\225\350\257\215\346\213\206\345\210\206II/0140-\345\215\225\350\257\215\346\213\206\345\210\206II.py" @@ -0,0 +1,22 @@ +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> List[str]: + + def helper(s, memo): + if s in memo: + return memo[s] + if not s: + return [] + res = [] + for word in wordDict: + if not s.startswith(word): + continue + if len(word) == len(s): + res.append(word) + else: + resultOfTheRest = helper(s[len(word):], memo) + for item in resultOfTheRest: + item = word + ' ' + item + res.append(item) + memo[s] = res + return res + return helper(s, {}) \ No newline at end of file diff --git "a/0207.\350\257\276\347\250\213\350\241\250/0207-\350\257\276\347\250\213\350\241\250.py" "b/0207.\350\257\276\347\250\213\350\241\250/0207-\350\257\276\347\250\213\350\241\250.py" index b535743..23b832c 100644 --- "a/0207.\350\257\276\347\250\213\350\241\250/0207-\350\257\276\347\250\213\350\241\250.py" +++ "b/0207.\350\257\276\347\250\213\350\241\250/0207-\350\257\276\347\250\213\350\241\250.py" @@ -1,35 +1,29 @@ -class Solution(object): - def canFinish(self, numCourses, prerequisites): - """ - :type numCourses: int - :type prerequisites: List[List[int]] - :rtype: bool - """ - from collections import deque - if not prerequisites: #没有前置课的要求 - return True - - indegree = [0 for _ in range(numCourses)] - adj = [set() for _ in range(numCourses)] - - for end, start in prerequisites: - indegree[end] += 1 - adj[start].add(end) - - queue = deque() - for i, x in enumerate(indegree): - if not x: #入度为0的结点入队 - queue.append(i) - - cnt = 0 +class Solution: + def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: + # 1. find all node/course with indegree 0, let them enter a queue + from collections import defaultdict, deque + indegree = defaultdict(int) + children = defaultdict(set) + all_courses = set() + for cur, pre in prerequisites: + indegree[cur] += 1 + children[pre].add(cur) + all_courses.add(cur) + all_courses.add(pre) + + queue = deque([]) + for course in all_courses: + if indegree[course] == 0: + queue.append(course) + # 2. BFS, let course with indegree 0 leave a queue, and let its children with indegree 0 into the queue + studied_course = 0 while queue: cur = queue.popleft() - cnt += 1 #当前的cur满足条件 - - for neighbor in adj[cur]: - indegree[neighbor] -= 1 - if not indegree[neighbor]: - queue.append(neighbor) - - return cnt == numCourses - \ No newline at end of file + + studied_course += 1 + for child in children[cur]: + indegree[child] -= 1 + if indegree[child] == 0: + queue.append(child) + + return studied_course == len(all_courses) \ No newline at end of file diff --git "a/0210.\350\257\276\347\250\213\350\241\250II/0210-\350\257\276\347\250\213\350\241\250II.py" "b/0210.\350\257\276\347\250\213\350\241\250II/0210-\350\257\276\347\250\213\350\241\250II.py" index 1ba3321..bdf7200 100644 --- "a/0210.\350\257\276\347\250\213\350\241\250II/0210-\350\257\276\347\250\213\350\241\250II.py" +++ "b/0210.\350\257\276\347\250\213\350\241\250II/0210-\350\257\276\347\250\213\350\241\250II.py" @@ -1,35 +1,33 @@ -class Solution(object): - def findOrder(self, numCourses, prerequisites): - """ - :type numCourses: int - :type prerequisites: List[List[int]] - :rtype: List[int] - """ - if not prerequisites: - return [i for i in range(numCourses)] - - indegree = [0 for _ in range(numCourses)] - adj = [set() for _ in range(numCourses)] - - for end, start in prerequisites: - indegree[end] += 1 - adj[start].add(end) - - from collections import deque - queue = deque() - - for i, x in enumerate(indegree): - if not x: - queue.append(i) - +class Solution: + def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]: + from collections import defaultdict, deque + indegree = defaultdict(int) + children = defaultdict(set) + all_courses = set() + for cur, pre in prerequisites: + indegree[cur] += 1 + children[pre].add(cur) + all_courses.add(cur) + all_courses.add(pre) + + queue = deque([]) + for course in all_courses: + if indegree[course] == 0: + queue.append(course) + # 2. BFS, let course with indegree 0 leave a queue, and let its children with indegree 0 into the queue res = [] + while queue: cur = queue.popleft() + res.append(cur) - - for neighbor in adj[cur]: - indegree[neighbor] -= 1 - if indegree[neighbor] == 0: - queue.append(neighbor) - - return res if len(res) == numCourses else [] \ No newline at end of file + for child in children[cur]: + indegree[child] -= 1 + if indegree[child] == 0: + queue.append(child) + if len(res) != len(all_courses): + return [] + for course in range(numCourses): + if course not in all_courses: + res.append(course) + return res \ No newline at end of file diff --git "a/0269.\347\201\253\346\230\237\350\257\215\345\205\270/0269-\347\201\253\346\230\237\350\257\215\345\205\270.py" "b/0269.\347\201\253\346\230\237\350\257\215\345\205\270/0269-\347\201\253\346\230\237\350\257\215\345\205\270.py" new file mode 100644 index 0000000..c556b44 --- /dev/null +++ "b/0269.\347\201\253\346\230\237\350\257\215\345\205\270/0269-\347\201\253\346\230\237\350\257\215\345\205\270.py" @@ -0,0 +1,45 @@ +class Solution: + def alienOrder(self, words: List[str]) -> str: + from collections import defaultdict, deque + + indegree = defaultdict(int) + children = defaultdict(set) + all_chars = set() + for word in words: + for ch in word: + all_chars.add(ch) + + for i in range(1, len(words)): + # find the first different char in words[i] and words[i - 1] + j = 0 + while j < len(words[i]) and j < len(words[i - 1]): + if words[i][j] != words[i - 1][j]: + if words[i][j] not in children[words[i - 1][j]]: + indegree[words[i][j]] += 1 + children[words[i - 1][j]].add(words[i][j]) + break + if j == len(words[i]) - 1 and j < len(words[i - 1]) - 1: + return "" + j += 1 + + # t -> f, w -> e, r -> t, e -> r + queue = deque() + # print (indegree) + # print (children) + for ch in all_chars: + if indegree[ch] == 0: + queue.append(ch) + # print (queue) + res = "" + while queue: + cur = queue.popleft() + + res += cur + for child in children[cur]: + indegree[child] -= 1 + if indegree[child] == 0: + queue.append(child) + + return res if len(res) == len(all_chars) else "" + + \ No newline at end of file diff --git "a/0325.\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246/0325-\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246.py" "b/0325.\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246/0325-\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246.py" new file mode 100644 index 0000000..8e8dfe6 --- /dev/null +++ "b/0325.\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246/0325-\345\222\214\347\255\211\344\272\216k\347\232\204\346\234\200\351\225\277\345\255\220\346\225\260\347\273\204\351\225\277\345\272\246.py" @@ -0,0 +1,18 @@ +class Solution: + def maxSubArrayLen(self, nums: List[int], k: int) -> int: + if not nums: + return 0 + dic = {} # key is prefix_sum and val is the smallest idx + dic[0] = -1 + res = 0 + for i, num in enumerate(nums): + if i > 0: + nums[i] += nums[i - 1] + if nums[i] not in dic: + dic[nums[i]] = i + target = nums[i] - k + # print(dic, nums[i]) + if target in dic: + res = max(res, i - dic[target]) + + return res \ No newline at end of file diff --git "a/0347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/0347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" "b/0347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/0347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" index a0efe08..5188c16 100644 --- "a/0347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/0347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" +++ "b/0347.\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240/0347-\345\211\215K\344\270\252\351\253\230\351\242\221\345\205\203\347\264\240.py" @@ -1,8 +1,20 @@ -class Solution(object): - def topKFrequent(self, nums, k): - """ - :type nums: List[int] - :type k: int - :rtype: List[int] - """ - return [digit for digit, fre in collections.Counter(nums).most_common(k)] \ No newline at end of file +from heapq import * +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + from collections import Counter + + dic = Counter(nums) + bucket = [[] for _ in range(len(nums) + 1)] + for num, fre in dic.items(): + bucket[fre].append(num) + # print (bucket) + + res = [] + for i in range(len(bucket) - 1, -1, -1): + if bucket[i]: + if len(bucket[i]) <= k - len(res): + res += bucket[i] + else: + res += bucket[i][:k - len(res)] + break + return res diff --git "a/0639.\350\247\243\347\240\201\346\226\271\346\263\2252/0639-\350\247\243\347\240\201\346\226\271\346\263\2252.py" "b/0639.\350\247\243\347\240\201\346\226\271\346\263\2252/0639-\350\247\243\347\240\201\346\226\271\346\263\2252.py" new file mode 100644 index 0000000..f965e09 --- /dev/null +++ "b/0639.\350\247\243\347\240\201\346\226\271\346\263\2252/0639-\350\247\243\347\240\201\346\226\271\346\263\2252.py" @@ -0,0 +1,44 @@ +class Solution: + def numDecodings(self, s: str) -> int: + if not s or s[0] == "0": + return 0 + + dp = [0]*(len(s) + 1) # dp[i] represents ways of s[:i + 1] + if s[0] == "*": + dp[0] = 1 + dp[1] = 9 + else: + dp[0] = dp[1] = 1 + + MOD = 10 ** 9 + 7 + + for i in range(2, len(s) + 1): + if s[i - 1] == "*": + if s[i - 2] == "1": + dp[i] = dp[i - 2] * 9 + elif s[i - 2] == "2": + dp[i] = dp[i - 2] * 6 + elif s[i - 2] == "*": + dp[i] = dp[i - 2] * 15 + dp[i] += 9 * dp[i - 1] + elif s[i - 1] == "0": + if s[i - 2] == "1" or s[i - 2] == "2": + dp[i] = dp[i - 2] + elif s[i - 2] == "*": + dp[i] = dp[i - 2] * 2 + else: + return 0 + else: + if s[i - 2] == "1" or (s[i - 2] == "2" and "1" <= s[i - 1] <= "6"): + dp[i] = dp[i - 2] + elif s[i - 2] == "*": + if "1" <= s[i - 1] <= "6": + dp[i] = dp[i - 2] * 2 + else: + dp[i] = dp[i - 2] + + dp[i] += dp[i - 1] + + dp[i] = dp[i] % MOD + # print (dp, i) + return dp[-1] \ No newline at end of file diff --git "a/1152.\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220/1152-\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220.py" "b/1152.\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220/1152-\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220.py" index 4731089..5d88bcf 100644 --- "a/1152.\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220/1152-\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220.py" +++ "b/1152.\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220/1152-\347\224\250\346\210\267\347\275\221\347\253\231\350\256\277\351\227\256\350\241\214\344\270\272\345\210\206\346\236\220.py" @@ -1,36 +1,42 @@ -class Solution(object): - def mostVisitedPattern(self, username, timestamp, website): - """ - :type username: List[str] - :type timestamp: List[int] - :type website: List[str] - :rtype: List[str] - """ +class Solution: + def mostVisitedPattern(self, username: List[str], timestamp: List[int], website: List[str]) -> List[str]: + # l = [1,2,3,4,5,6] + # for i in range(len(l)): + # for j in range(i + 1, len(l)): + # for k in range(j + 1, len(l)): + # print (l[i], l[j], l[k]) from collections import defaultdict - record = defaultdict(list) - for i, un in enumerate(username): - record[un].append([timestamp[i], website[i]]) - # print record - row = defaultdict(int) - for key in record.keys(): - record[key].sort() - # print record[key] - used = set() - for i in range(len(record[key])): - for j in range(i + 1, len(record[key])): - for k in range(j + 1, len(record[key])): - sequence = record[key][i][1] + "+" + record[key][j][1]+ "+" + record[key][k][1] - if sequence not in used: - row[sequence] += 1 - used.add(sequence) - # print row - possible_sol = [] - max_freq = max(row.values()) - for key, val in row.items(): - if val == max_freq: - possible_sol.append(key.split("+")) - possible_sol = possible_sol[::-1] - # print possible_sol - if len(possible_sol) > 1: - possible_sol.sort() - return possible_sol[0] \ No newline at end of file + max_visit_cnt = 0 + max_visit_websites = [] + name2web = defaultdict(list) + web2freq = defaultdict(int) + comb = [] + for i in range(len(username)): + comb.append((username[i], timestamp[i], website[i])) + comb.sort(key = lambda x:x[1]) + for i in range(len(username)): + name2web[comb[i][0]].append(comb[i][2]) + + for name, webs in name2web.items(): + visited = set() + for i in range(len(webs)): + for j in range(i + 1, len(webs)): + for k in range(j + 1, len(webs)): + tmp = ",".join([webs[i], webs[j], webs[k]]) + if tmp in visited: + continue + visited.add(tmp) + web2freq[tmp] += 1 + + if web2freq[tmp] > max_visit_cnt: + max_visit_cnt = web2freq[tmp] + max_visit_websites = [tmp] + elif web2freq[tmp] == max_visit_cnt: + max_visit_websites.append(tmp) + # print (max_visit_websites) + max_visit_websites.sort() + # print (max_visit_websites) + s = max_visit_websites[0] + l = s.split(",") + return l + diff --git "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" index 2c4e088..7971e98 100644 --- "a/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" +++ "b/\345\211\221\346\214\207Offer68-II.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/\345\211\221\346\214\207Offer68-II-\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210.py" @@ -1,29 +1,32 @@ # Definition for a binary tree node. -# class TreeNode(object): +# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None -class Solution(object): - def lowestCommonAncestor(self, root, p, q): - """ - :type root: TreeNode - :type p: TreeNode - :type q: TreeNode - :rtype: TreeNode - """ - if not root: - return None - if root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) +class Solution: + def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': + child2par = {root: None} + stack = [root] + + while stack: + cur = stack.pop() + if cur.left: + stack.append(cur.left) + child2par[cur.left] = cur + if cur.right: + stack.append(cur.right) + child2par[cur.right] = cur - if left and right: - return root - if left: - return left - if right: - return right - return None \ No newline at end of file + p_ancestors = set() + while p in child2par: + p_ancestors.add(p) + p = child2par[p] + + res = root + while q in child2par: + if q in p_ancestors: + return q + q = child2par[q] + return res From 719c95796a371542028a1662c1b207f74bcdaee1 Mon Sep 17 00:00:00 2001 From: JiayangWu <530081999@qq.com> Date: Fri, 16 Oct 2020 01:20:20 -0400 Subject: [PATCH 164/183] 2020-10-16 --- ...23\345\255\230\346\234\272\345\210\266.py" | 65 ++++++++++++---- ...2\23016.25-LRU\347\274\223\345\255\230.py" | 78 +++++++++++++++++++ 2 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\23016.25.LRU\347\274\223\345\255\230/\351\235\242\350\257\225\351\242\23016.25-LRU\347\274\223\345\255\230.py" 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 265117e..73bc89e 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" @@ -1,25 +1,33 @@ -class LRUCache(object): +class DLLNode(object): + def __init__(self, key, val, pre, nxt): + self.key = key + self.val = val + self.pre = pre + self.nxt = next +class LRUCache(object): def __init__(self, capacity): """ :type capacity: int """ - from collections import OrderedDict self.capacity = capacity - self.record = OrderedDict() + self.size = 0 + self.head = DLLNode(-1, -1, None, None) + self.tail = DLLNode(-1, -1, self.head, None) + self.head.next = self.tail + self.dic = dict() def get(self, key): """ :type key: int :rtype: int """ - if key in self.record: - tmp = self.record.pop(key) - self.record[key] = tmp - return tmp - else: + if key not in self.dic: return -1 - + else: + value = self.dic[key].val + self.moveToHead(self.dic[key]) + return value def put(self, key, value): """ @@ -27,15 +35,40 @@ def put(self, key, value): :type value: int :rtype: None """ - if key in self.record: - self.record.pop(key) - else: - if self.capacity > 0: - self.capacity -= 1 + if key not in self.dic: + node = DLLNode(key, value, None, None) + self.dic[key] = node + if self.size < self.capacity: + self.size += 1 else: - self.record.popitem(last = False) - self.record[key] = value + self.removeLastElement() + self.insertToHead(node) + else: + self.dic[key].val = value + self.moveToHead(self.dic[key]) + + def insertToHead(self, node): + + pre_first = self.head.next + self.head.next = node + node.pre = self.head + pre_first.pre = node + node.next = pre_first + # print (node.key, node.pre.key, node.next.key) + + def removeLastElement(self): + pre_last = self.tail.pre + pre_second_last = pre_last.pre + pre_second_last.next = self.tail + self.tail.pre = pre_second_last + self.dic.pop(pre_last.key) + + def moveToHead(self, node): + node.pre.next = node.next + node.next.pre = node.pre + + self.insertToHead(node) # Your LRUCache object will be instantiated and called as such: diff --git "a/\351\235\242\350\257\225\351\242\23016.25.LRU\347\274\223\345\255\230/\351\235\242\350\257\225\351\242\23016.25-LRU\347\274\223\345\255\230.py" "b/\351\235\242\350\257\225\351\242\23016.25.LRU\347\274\223\345\255\230/\351\235\242\350\257\225\351\242\23016.25-LRU\347\274\223\345\255\230.py" new file mode 100644 index 0000000..ee7f3bd --- /dev/null +++ "b/\351\235\242\350\257\225\351\242\23016.25.LRU\347\274\223\345\255\230/\351\235\242\350\257\225\351\242\23016.25-LRU\347\274\223\345\255\230.py" @@ -0,0 +1,78 @@ +class DLLNode(object): + def __init__(self, key, val, pre = None, next = None): + self.key = key + self.val = val + self.pre = pre + self.next = next + +class LRUCache(object): + def __init__(self, capacity): + """ + :type capacity: int + """ + self.capacity = capacity + self.size = 0 + self.head = DLLNode(-1, -1) + self.tail = DLLNode(-1, -1, self.head) + self.head.next = self.tail + self.dic = {} + + def get(self, key): + """ + :type key: int + :rtype: int + """ + if key in self.dic: + res = self.dic[key].val + self.moveToHead(self.dic[key]) # set this node to be most recently used + return res + return -1 + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: None + """ + if key in self.dic: + self.dic[key].val = value + self.moveToHead(self.dic[key]) + else: + node = DLLNode(key, value) + self.dic[key] = node + if self.size < self.capacity: + self.size += 1 + else: + self.removeLastNode() + self.insertToHead(node) + + def insertToHead(self, node): + pre_first = self.head.next + self.head.next = node + node.pre = self.head + node.next = pre_first + pre_first.pre = node + + def moveToHead(self, node): + # 1. take it out + node.pre.next = node.next + node.next.pre = node.pre + # 2. insert it to the head + self.insertToHead(node) + + def removeLastNode(self): + pre_last = self.tail.pre + pre_second_last = pre_last.pre + + pre_second_last.next = self.tail + self.tail.pre = pre_second_last + + self.dic.pop(pre_last.key) + + + + +# Your LRUCache object will be instantiated and called as such: +# obj = LRUCache(capacity) +# param_1 = obj.get(key) +# obj.put(key,value) \ No newline at end of file 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 165/183] 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 166/183] 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 167/183] 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 168/183] 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 169/183] 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 170/183] 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 171/183] 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 172/183] 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 173/183] 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 174/183] 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 175/183] 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 176/183] 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 177/183] 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 178/183] 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 179/183] 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 180/183] 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 181/183] 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 182/183] 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 183/183] 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