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 001/143] 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 002/143] 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 003/143] 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 004/143] 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 005/143] 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 006/143] 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 007/143] 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 008/143] 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 009/143] 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 010/143] 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 011/143] 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 012/143] 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 013/143] 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 014/143] 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 015/143] 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 016/143] 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 017/143] 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 018/143] 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 019/143] 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 020/143] 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 021/143] 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 022/143] 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 023/143] 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 024/143] 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 025/143] 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 026/143] 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 027/143] 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 028/143] 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 029/143] 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) #下个学期可以学neighbor这门课了 + queue = next_queue + return semester_cnt if finished_course == N else -1 #如果所有的课都学完了,那么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 030/143] 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 + # 排序并反转,反转是为了可以快速pop + events = sorted(events, key = lambda x:(x[0], x[1]))[::-1] + + queue = [] + res = 0 + for day in range(1, 10 ** 5 + 1): + # 把所有结束日期在当前日期之前的event都pop掉 + while queue and queue[0] < day: + heappop(queue) + + # 把所有开始日期大于等于当前日期的event都push进队列 + while events and events[-1][0] <= day: + last = events.pop() + heappush(queue, last[1]) + + if queue: + # 如果当前日期有可以去的event,就去这一个 + heappop(queue) + res += 1 + if not queue and not events: + # 如果所有event都参加完了 + 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 031/143] 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 032/143] 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 033/143] 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 034/143] 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 035/143] 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 036/143] 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 037/143] 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 038/143] 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 039/143] 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 040/143] 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 C 1][k][0], dp[I C 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 041/143] 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 042/143] 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] 代表在第 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 043/143] 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 044/143] 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 045/143] 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 046/143] 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 047/143] 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 048/143] 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 049/143] 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 050/143] 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 051/143] 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 052/143] 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 053/143] 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 054/143] 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 055/143] 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 056/143] 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 057/143] 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 058/143] 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 059/143] 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 060/143] 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 061/143] 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 062/143] 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 063/143] 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 064/143] 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):#lengthDZ߳ - 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 065/143] 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 066/143] 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 067/143] 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 068/143] 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 069/143] 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 070/143] 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 071/143] 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 072/143] 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 073/143] 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 074/143] 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 075/143] 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 076/143] 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 077/143] 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 078/143] 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 079/143] 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] 表示前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" 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是 字母,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: # һijlettersҲĸ迼 + if flag: # 如果一个单词里存在某个在letters里找不到的字母,则无需考虑这个单词 continue v_words.append(word) self.res = 0 def helper(word, letter_dic): - # return True wordletter_dicletterɣ򷵻False + # 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)):#startʼңظ - 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" 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~下标为i的单词可以被拆分 + + 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数位之和,eg:输入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 # 把child 变成next + node.next.prev = node + t = helper(node.child) # 递归处理,t 是处理之后的 原来的child 的最后一个节点 + node.child = None # 把child 置空 + if nxt: # 如果有next 部分,就让next的prev指向 原来的child 处理之后的最后一个节点 + 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 个字符,那么就有循环节了 + # 我们用 (s1cnt', s2cnt', index) 和 (s1cnt, s2cnt, index) 表示两次包含相同 index 的匹配结果 + # 那么哈希映射中的键就是 index,值就是 (s1cnt', s2cnt') 这个二元组 + # 循环节就是; + # - 前 s1cnt' 个 s1 包含了 s2cnt' 个 s2 + # - 以后的每 (s1cnt - s1cnt') 个 s1 包含了 (s2cnt - s2cnt') 个 s2 + # 那么还会剩下 (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 + """ + #用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)] + + 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] + # 在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/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 #此时所有index左侧的值都比nums[index]大, 所有右侧的值都比nums[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 080/143] 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 081/143] 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 082/143] 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 083/143] 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 084/143] 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 085/143] 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]表示第i天还可以交易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]) + #当k = 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 086/143] 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 代表当前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 087/143] 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 088/143] 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] 表示前i个硬币里,有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是 字母,val是字母对应的分数 + 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: # 如果一个单词里存在某个在letters里找不到的字母,则无需考虑这个单词 + if flag: # һijlettersҲĸ迼 continue v_words.append(word) self.res = 0 def helper(word, letter_dic): - # return True 如果word能用letter_dic里的letter构成,否则返回False + # return True wordletter_dicletterɣ򷵻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)):#从start开始找,避免重复 - 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~下标为i的单词可以被拆分 - - 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数位之和,eg:输入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 # 把child 变成next - node.next.prev = node - t = helper(node.child) # 递归处理,t 是处理之后的 原来的child 的最后一个节点 - node.child = None # 把child 置空 - if nxt: # 如果有next 部分,就让next的prev指向 原来的child 处理之后的最后一个节点 - 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 个字符,那么就有循环节了 - # 我们用 (s1cnt', s2cnt', index) 和 (s1cnt, s2cnt, index) 表示两次包含相同 index 的匹配结果 - # 那么哈希映射中的键就是 index,值就是 (s1cnt', s2cnt') 这个二元组 - # 循环节就是; - # - 前 s1cnt' 个 s1 包含了 s2cnt' 个 s2 - # - 以后的每 (s1cnt - s1cnt') 个 s1 包含了 (s2cnt - s2cnt') 个 s2 - # 那么还会剩下 (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 - """ - #用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)] - - 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] - # 在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/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 #此时所有index左侧的值都比nums[index]大, 所有右侧的值都比nums[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 089/143] 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]表示第i天还可以交易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]) - #当k = 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 代表当前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 090/143] 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 代表当前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 091/143] 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 092/143] 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 093/143] 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 094/143] 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 095/143] 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 096/143] 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 097/143] 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];// 在prevNums中找targetNum的索引 + if (targetNumIndex !== undefined) { // 如果能找到 + return [targetNumIndex, i]; // 直接返回targetNumIndex和当前的i + } // 如果找不到,说明之前没出现过targetNum + prevNums[curNum] = i; // 往prevNums存当前curNum和对应的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 098/143] 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 099/143] 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 100/143] 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 101/143] 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 102/143] 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 103/143] 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 104/143] 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 105/143] 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 106/143] 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 107/143] 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 108/143] 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 109/143] 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 110/143] 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 111/143] 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 112/143] 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 113/143] 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 114/143] 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 115/143] 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 116/143] 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 117/143] 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 118/143] 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 119/143] 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 120/143] 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 121/143] 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 122/143] 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 123/143] 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 124/143] 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 125/143] 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 126/143] 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 127/143] 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 128/143] 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 129/143] 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 130/143] 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 131/143] 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 + + # 建立配对字典,给定x, 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 132/143] 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 133/143] 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 134/143] 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 135/143] 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 136/143] 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 137/143] 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 138/143] 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 139/143] 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 140/143] 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 141/143] 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 142/143] 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 143/143] 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ÿϽ㣬valneighbors + 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:#IJ÷ŽջֱĬ-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