From 10f78164a1022d8fb2e9dbc982995f7e177a3fea Mon Sep 17 00:00:00 2001 From: hjh <544789628@qq.com> Date: Wed, 16 Jul 2025 00:12:21 +0800 Subject: [PATCH 1/3] init --- notes/target/classes/TianJi.class | Bin 2413 -> 0 bytes .../README.md" | 70 ------------------ 2 files changed, 70 deletions(-) delete mode 100644 notes/target/classes/TianJi.class delete mode 100644 "notes/target/classes/\347\224\260\345\277\214\350\265\233\351\251\254/README.md" diff --git a/notes/target/classes/TianJi.class b/notes/target/classes/TianJi.class deleted file mode 100644 index 5271c3c141018b659201313705222df55447ad8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2413 zcmbVO>vI!T6#v~M&2Bc^cegYY1w?E^QUXPywg>`>7Q;hZih!WobSYcYO~|9PD1s8u z85niOGH7uetYSrRiZG-tt@SbEI6C8uU-XmXV{F>;iT{9lZW2sd>KEI&k3ILC-#O=Z z&b^Z#Z(Sb)uo5RE+>H$aHcBw@^-&uh!zKw9JkEDdh-i?o8BcPFPsA1pTd_?-8MgE3 zDLbA zL)8t2^6EXlcC}OW1XQEV(-;lwMq53{XQWC_$>>HnJ+6 z1Cc@Q($!#;yz{|Ol!lH)^?=8xN1_yw$Tbe?2MOO4@e@vtN~2#j3@uDrOieioucR%p zLO#Q_v?a*A7M~iSFxYNNYbFWZq1!|(%>m_p*W{$wU_`YxabA zYs)!NG8SSH1(zZ%75@5gSncLm48>V#CSn188LiN`*?t*qIKZ%eYG80`?Cs=<3*$q_ z#)qydBtV$*)dN_Qr2qyyUz& z+ABbp(T*2n1kgblFA`wL2qGloAi^>thzf|w=)|G_h zU7xu0!NfZQl%0%Yc!f`|$~cY=8F9|IHC+U1ovedxE$y10c+U|vc1NNbabn`#t)#1~ z2R#i&C>Evm*3=HFZbkK+2fXji!59H%4Y$*c$Qq{0PIx(D1|h_i0^DH+c=l})4XrE6 zuPQ@XwKJ#ZGB<8!3aML24IK#ubPA?wF3>qInHW;T5sm8cACb_t6*|>GOxw1fU;T#M zNHSFLz#d({Sig-pm84vU>5Vy@dXzBqq6w(ZerDiTl?w~c(d6d$EnYpG}&mN1>U|K|^ z`vaO9#$wz>Z$AGsf$=L(^J4n)(8_4dTQ&&xMe6t-nyo3J6-#I@rxkE7meQ9E_o0d; zWNa>m8HE6QZ3L!WgE0Ft>y{B%c3nZt5_CVY*u1QfTDpY!z*3ghy0JbyY~K!N_?Qly+iw_?xv;;Ish+gVEW{n@Iy zsD0B%xoZA&|8ytiK7w-McV0{Ln_PUNE&1@KYX_Ry-L7&=Pmr7fi=v5a0P1!rhIhk5uA75Eqqe1`eBObA!0 ze+H>@MyPjwrt<$nh`&)&{6P(I3ssDvnpxmv5|%M1T+9tO^Pq;U#&XsK58H_qY%f-^ zL%5$E!D@CKUUm`>q+09}#ld5$rU-5HC@-S;T@?KozDw;Se1mV{CYc@IV-z*ClkpQ0 zSWdfqisveIvWqgJX2c5mi9^}5qm=6^YSkj{lXfOlvH(`YODs9rKJx9PA2_va2OcDg zJOo(<9wM0)U91pwBol~*anuvCNL>7dHF%ifTTAHWgqHTO?q3h xiaotiantian = new ArrayList(); - List xiaoqiqi = new ArrayList(); - Scanner sc = new Scanner(System.in); - System.out.println("请输入一串数字数组,并用空格分隔(田忌的马):"); - String a = sc.nextLine(); - String[] arr1 = a.split(" "); - for (String s : arr1) { - xiaotiantian.add(Integer.parseInt(s)); - } - System.out.println("请输入一串数字数组,并用空格分隔(齐王的马):"); - String b = sc.nextLine(); - String[] arr2 = b.split(" "); - for (int i = 0; i < arr1.length; i++) { - xiaoqiqi.add(Integer.parseInt(arr2[i])); - } - int n = xiaotiantian.size(); - boolean bLast = true; - while (bLast) { - if (n == 0) { - break; - } - //处理数据 - Collections.sort(xiaotiantian); - Collections.sort(xiaoqiqi); - int i = 0, j = 0, x = n - 1, y = n - 1, cnt = 0; - while (bLast) { - //是否是最后一匹马 - if (x == i) { - bLast = false; - } - if (xiaotiantian.get(x) > xiaoqiqi.get(y)) {//如果田忌当前最好的马可以胜齐王最好的马,那么比一场 - x--; - y--; - cnt++; - } else if (xiaotiantian.get(i) > xiaoqiqi.get(j)) {//如果田忌当前最差的马可以胜齐王最差的马,那么比一场 - i++; - j++; - cnt++; - } else if (xiaotiantian.get(i) < xiaoqiqi.get(y)) {//否则,让田忌最差的马和齐王最好的好比一场 - i++; - y--; - } - } - System.out.println("田忌可以赢得的比赛场次是:" + cnt); - xiaotiantian.clear(); - xiaoqiqi.clear(); - } - } -} -``` From e7c3d2be810bf1a3778653135c2b2d0718fb3fa0 Mon Sep 17 00:00:00 2001 From: hjh <544789628@qq.com> Date: Wed, 16 Jul 2025 00:45:08 +0800 Subject: [PATCH 2/3] init --- .gitignore | 1 + leetcode/README_EN.md | 190 -- leetcode/basic/README_EN.md | 14 - leetcode/lcci/01.01.Is Unique/README_EN.md | 73 - leetcode/lcci/01.01.Is Unique/Solution.py | 4 - .../lcci/01.02.Check Permutation/README_EN.md | 70 - .../lcci/01.02.Check Permutation/Solution.py | 3 - .../lcci/01.03.String to URL/README_EN.md | 81 - leetcode/lcci/01.03.String to URL/Solution.py | 4 - .../01.04.Palindrome Permutation/README_EN.md | 77 - leetcode/lcci/01.05.One Away/README_EN.md | 92 - leetcode/lcci/01.05.One Away/Solution.py | 14 - .../lcci/01.06.Compress String/README_EN.md | 90 - .../lcci/01.06.Compress String/Solution.py | 13 - .../lcci/01.07.Rotate Matrix/README_EN.md | 127 -- leetcode/lcci/01.07.Rotate Matrix/Solution.py | 13 - leetcode/lcci/01.08.Zero Matrix/README_EN.md | 141 -- leetcode/lcci/01.08.Zero Matrix/Solution.py | 22 - .../lcci/01.09.String Rotation/README_EN.md | 65 - .../lcci/01.09.String Rotation/Solution.py | 3 - .../02.01.Remove Duplicate Node/README_EN.md | 112 -- .../02.01.Remove Duplicate Node/Solution.py | 21 - .../README_EN.md | 78 - .../Solution.py | 14 - .../02.03.Delete Middle Node/README_EN.md | 69 - .../lcci/02.03.Delete Middle Node/Solution.py | 14 - .../lcci/02.04.Partition List/README_EN.md | 95 - .../lcci/02.04.Partition List/Solution.py | 25 - leetcode/lcci/02.05.Sum Lists/README_EN.md | 99 - leetcode/lcci/02.05.Sum Lists/Solution.py | 21 - .../02.06.Palindrome Linked List/README_EN.md | 117 -- .../02.06.Palindrome Linked List/Solution.py | 22 - .../lcci/02.08.Linked List Cycle/README_EN.md | 107 -- .../lcci/02.08.Linked List Cycle/Solution.py | 20 - leetcode/lcci/03.01.Three in One/README_EN.md | 134 -- leetcode/lcci/03.01.Three in One/Solution.py | 26 - leetcode/lcci/03.02.Min Stack/README_EN.md | 117 -- leetcode/lcci/03.02.Min Stack/Solution.py | 31 - .../README_EN.md | 160 -- .../Solution.py | 45 - .../lcci/03.05.Sort of Stacks/README_EN.md | 129 -- .../lcci/03.05.Sort of Stacks/Solution.py | 22 - .../lcci/03.06.Animal Shelter/README_EN.md | 138 -- .../lcci/03.06.Animal Shelter/Solution.py | 32 - .../lcci/04.04.Check Balance/README_EN.md | 116 -- leetcode/lcci/04.04.Check Balance/Solution.py | 19 - .../README_EN.md | 121 -- .../Solution.py | 23 - .../04.08.First Common Ancestor/README_EN.md | 109 -- .../04.08.First Common Ancestor/Solution.py | 14 - .../lcci/04.10.Check SubTree/README_EN.md | 95 - leetcode/lcci/04.10.Check SubTree/Solution.py | 17 - .../lcci/04.12.Paths with Sum/README_EN.md | 125 -- .../lcci/04.12.Paths with Sum/Solution.py | 19 - .../lcci/05.01.Insert Into Bits/README_EN.md | 58 - .../lcci/05.06.Convert Integer/README_EN.md | 61 - leetcode/lcci/05.07.Exchange/README_EN.md | 64 - .../08.01.Three Steps Problem/README_EN.md | 91 - .../lcci/08.01.Three Steps Problem/Solution.c | 16 - .../08.01.Three Steps Problem/Solution.cpp | 16 - .../08.01.Three Steps Problem/Solution.py | 8 - leetcode/lcci/08.09.Bracket/README_EN.md | 91 - leetcode/lcci/08.09.Bracket/Solution.py | 15 - leetcode/lcci/08.10.Color Fill/README_EN.md | 83 - .../10.09.Sorted Matrix Search/README_EN.md | 90 - .../10.09.Sorted Matrix Search/Solution.py | 14 - leetcode/lcci/16.01.Swap Numbers/README_EN.md | 57 - leetcode/lcci/16.01.Swap Numbers/Solution.py | 4 - .../16.06.Smallest Difference/README_EN.md | 76 - .../16.06.Smallest Difference/Solution.py | 13 - .../lcci/16.10.Living People/README_EN.md | 89 - leetcode/lcci/16.10.Living People/Solution.py | 15 - leetcode/lcci/16.11.Diving Board/README_EN.md | 56 - leetcode/lcci/16.21.Sum Swap/README_EN.md | 88 - leetcode/lcci/16.21.Sum Swap/Solution.py | 9 - .../lcci/17.01.Add Without Plus/README_EN.md | 59 - .../lcci/17.04.Missing Number/README_EN.md | 70 - .../lcci/17.04.Missing Number/Solution.py | 8 - leetcode/lcci/17.12.BiNode/README_EN.md | 104 -- leetcode/lcci/17.12.BiNode/Solution.py | 23 - leetcode/lcci/17.13.Re-Space/README_EN.md | 59 - leetcode/lcci/17.16.The Masseuse/README_EN.md | 101 -- leetcode/lcci/17.16.The Masseuse/Solution.py | 13 - leetcode/lcci/17.19.Missing Two/README_EN.md | 117 -- leetcode/lcci/17.19.Missing Two/Solution.py | 28 - .../lcci/17.20.Continuous Median/README_EN.md | 115 -- .../lcci/17.20.Continuous Median/Solution.py | 24 - leetcode/lcci/README_EN.md | 125 -- leetcode/lcof/README_EN.md | 19 - .../Solution.cpp" | 19 - .../Solution.go" | 11 - .../Solution.js" | 11 - .../Solution.py" | 9 - .../Solution.go" | 18 - .../Solution.js" | 21 - .../Solution.py" | 14 - .../Solution.go" | 3 - .../Solution.js" | 7 - .../Solution.py" | 3 - .../Solution.cpp" | 27 - .../Solution.go" | 16 - .../Solution.js" | 20 - .../Solution.py" | 13 - .../Solution.go" | 25 - .../Solution.js" | 33 - .../Solution.py" | 23 - .../Solution.go" | 33 - .../Solution.js" | 28 - .../Solution.py" | 26 - .../Solution.go" | 12 - .../Solution.js" | 15 - .../Solution.py" | 6 - .../Solution.go" | 15 - .../Solution.js" | 15 - .../Solution.py" | 6 - .../Solution.go" | 14 - .../Solution.js" | 20 - .../Solution.py" | 12 - .../Solution.cpp" | 47 - .../Solution.go" | 36 - .../Solution.js" | 45 - .../Solution.py" | 20 - .../Solution.cpp" | 37 - .../Solution.go" | 16 - .../Solution.js" | 52 - .../Solution.py" | 19 - .../Solution.go" | 11 - .../Solution.js" | 24 - .../Solution.py" | 11 - .../Solution.go" | 12 - .../Solution.js" | 22 - .../Solution.py" | 11 - .../Solution.go" | 9 - .../Solution.js" | 12 - .../Solution.py" | 7 - .../Solution.go" | 23 - .../Solution.js" | 22 - .../Solution.py" | 10 - .../Solution.go" | 11 - .../Solution.js" | 11 - .../Solution.py" | 3 - .../Solution.cpp" | 34 - .../Solution.go" | 17 - .../Solution.js" | 22 - .../Solution.py" | 14 - .../Solution.cpp" | 31 - .../Solution.js" | 23 - .../Solution.py" | 22 - .../Solution.js" | 7 - .../Solution.py" | 24 - .../Solution.js" | 20 - .../Solution.py" | 12 - .../Solution.go" | 14 - .../Solution.js" | 30 - .../Solution.py" | 15 - .../Solution.go" | 14 - .../Solution.js" | 22 - .../Solution.py" | 15 - .../Solution.cpp" | 32 - .../Solution.go" | 14 - .../Solution.js" | 47 - .../Solution.py" | 20 - .../Solution.cpp" | 49 - .../Solution.go" | 25 - .../Solution.js" | 23 - .../Solution.py" | 20 - .../Solution.cpp" | 26 - .../Solution.go" | 17 - .../Solution.js" | 18 - .../Solution.py" | 15 - .../Solution.go" | 24 - .../Solution.js" | 20 - .../Solution.py" | 18 - .../Solution.cpp" | 35 - .../Solution.js" | 45 - .../Solution.py" | 17 - .../Solution.js" | 50 - .../Solution.py" | 30 - .../Solution.js" | 17 - .../Solution.py" | 10 - .../Solution.cpp" | 37 - .../Solution.go" | 21 - .../Solution.js" | 23 - .../Solution.py" | 24 - .../Solution.go" | 27 - .../Solution.js" | 29 - .../Solution.py" | 26 - .../Solution.go" | 34 - .../Solution.js" | 35 - .../Solution.py" | 26 - .../Solution.go" | 28 - .../Solution.js" | 19 - .../Solution.py" | 17 - .../Solution.go" | 25 - .../Solution.js" | 28 - .../Solution.py" | 24 - .../Solution.go" | 44 - .../Solution.js" | 25 - .../Solution.py" | 26 - .../Solution.js" | 29 - .../Solution.py" | 28 - .../Solution.js" | 62 - .../Solution.py" | 60 - .../Solution.cpp" | 25 - .../Solution.js" | 22 - .../Solution.py" | 17 - .../Solution.js" | 19 - .../Solution.py" | 10 - .../Solution.cpp" | 43 - .../Solution.js" | 38 - .../Solution.py" | 10 - .../Solution.js" | 34 - .../Solution.py" | 24 - .../Solution.js" | 14 - .../Solution.py" | 8 - .../Solution.js" | 25 - .../Solution.py" | 12 - .../Solution.js" | 21 - .../Solution.py" | 17 - .../Solution.js" | 14 - .../Solution.py" | 16 - .../Solution.js" | 21 - .../Solution.py" | 8 - .../Solution.js" | 15 - .../Solution.py" | 13 - .../Solution.cpp" | 32 - .../Solution.js" | 25 - .../Solution.py" | 19 - .../Solution.js" | 20 - .../Solution.py" | 16 - .../Solution.js" | 15 - .../Solution.py" | 13 - .../Solution.js" | 32 - .../Solution.py" | 36 - .../Solution.cpp" | 22 - .../Solution.js" | 22 - .../Solution.py" | 29 - .../Solution.js" | 31 - .../Solution.py" | 29 - .../Solution.js" | 18 - .../Solution.py" | 14 - .../Solution.js" | 24 - .../Solution.py" | 24 - .../Solution.cpp" | 22 - .../Solution.js" | 24 - .../Solution.py" | 12 - .../Solution.cpp" | 45 - .../Solution.js" | 22 - .../Solution.py" | 17 - .../Solution.js" | 24 - .../Solution.py" | 18 - .../Solution.js" | 13 - .../Solution.py" | 12 - .../Solution.cpp" | 44 - .../Solution.js" | 28 - .../Solution.py" | 14 - .../Solution.js" | 19 - .../Solution.py" | 11 - .../Solution.js" | 11 - .../Solution.py" | 5 - .../Solution.js" | 8 - .../Solution.py" | 3 - .../Solution.js" | 29 - .../Solution.py" | 13 - .../Solution.js" | 47 - .../Solution.py" | 32 - .../Solution.js" | 20 - .../Solution.py" | 15 - .../Solution.cpp" | 26 - .../Solution.js" | 23 - .../Solution.py" | 14 - .../Solution.js" | 13 - .../Solution.py" | 6 - .../Solution.cpp" | 24 - .../Solution.js" | 13 - .../Solution.py" | 10 - .../Solution.cpp" | 9 - .../Solution.js" | 7 - .../Solution.py" | 3 - .../Solution.go" | 6 - .../Solution.js" | 9 - .../Solution.py" | 9 - .../Solution.js" | 17 - .../Solution.py" | 12 - .../Solution.js" | 24 - .../Solution.py" | 28 - .../Solution.js" | 23 - .../Solution.py" | 19 - .../Solution.js" | 21 - .../Solution.py" | 18 - .../0000-0099/0001.Two Sum/README_EN.md | 66 - .../0000-0099/0001.Two Sum/Solution.cpp | 24 - .../0000-0099/0001.Two Sum/Solution.cs | 20 - .../0000-0099/0001.Two Sum/Solution.go | 12 - .../0000-0099/0001.Two Sum/Solution.js | 43 - .../0000-0099/0001.Two Sum/Solution.py | 8 - .../0000-0099/0001.Two Sum/Solution.rb | 11 - .../0002.Add Two Numbers/README_EN.md | 120 -- .../0002.Add Two Numbers/Solution.cpp | 37 - .../0002.Add Two Numbers/Solution.cs | 28 - .../0002.Add Two Numbers/Solution.go | 53 - .../0002.Add Two Numbers/Solution.js | 45 - .../0002.Add Two Numbers/Solution.py | 18 - .../0002.Add Two Numbers/Solution.rb | 37 - .../README_EN.md | 81 - .../Solution.cs | 22 - .../Solution.go | 22 - .../Solution.js | 25 - .../Solution.py | 12 - .../README_EN.md | 63 - .../Solution.cpp | 36 - .../Solution.cs | 121 -- .../Solution.go | 68 - .../Solution.js | 77 - .../Solution.py | 12 - .../README_EN.md | 53 - .../Solution.cs | 31 - .../Solution.go | 28 - .../Solution.js | 38 - .../Solution.py | 24 - .../0006.ZigZag Conversion/README_EN.md | 79 - .../0006.ZigZag Conversion/Solution.cpp | 36 - .../0006.ZigZag Conversion/Solution.cs | 29 - .../0006.ZigZag Conversion/Solution.go | 20 - .../0006.ZigZag Conversion/Solution.js | 34 - .../0006.ZigZag Conversion/Solution.py | 29 - .../0007.Reverse Integer/README_EN.md | 65 - .../0007.Reverse Integer/Solution.cs | 15 - .../0007.Reverse Integer/Solution.go | 23 - .../0007.Reverse Integer/Solution.js | 52 - .../0007.Reverse Integer/Solution.py | 20 - .../0007.Reverse Integer/Solution.rb | 21 - .../README_EN.md | 156 -- .../0008.String to Integer (atoi)/Solution.cs | 46 - .../0008.String to Integer (atoi)/Solution.go | 37 - .../0008.String to Integer (atoi)/Solution.js | 24 - .../0008.String to Integer (atoi)/Solution.py | 28 - .../0009.Palindrome Number/README_EN.md | 87 - .../0009.Palindrome Number/Solution.go | 12 - .../0009.Palindrome Number/Solution.js | 15 - .../0009.Palindrome Number/Solution.py | 9 - .../README_EN.md | 94 - .../Solution.cs | 47 - .../Solution.go | 15 - .../README_EN.md | 49 - .../Solution.cpp | 20 - .../Solution.go | 30 - .../Solution.js | 20 - .../0012.Integer to Roman/README_EN.md | 107 -- .../0012.Integer to Roman/Solution.go | 49 - .../0013.Roman to Integer/README_EN.md | 107 -- .../0013.Roman to Integer/Solution.go | 41 - .../0013.Roman to Integer/Solution.js | 20 - .../0013.Roman to Integer/Solution.py | 21 - .../0013.Roman to Integer/Solution.rb | 32 - .../0014.Longest Common Prefix/README_EN.md | 59 - .../0014.Longest Common Prefix/Solution.cpp | 37 - .../0014.Longest Common Prefix/Solution.cs | 22 - .../0014.Longest Common Prefix/Solution.go | 14 - .../0014.Longest Common Prefix/Solution.js | 11 - .../0014.Longest Common Prefix/Solution.py | 25 - .../0014.Longest Common Prefix/Solution.rb | 25 - .../solution/0000-0099/0015.3Sum/README_EN.md | 116 -- .../solution/0000-0099/0015.3Sum/Solution.cpp | 40 - .../solution/0000-0099/0015.3Sum/Solution.cs | 91 - .../solution/0000-0099/0015.3Sum/Solution.go | 57 - .../solution/0000-0099/0015.3Sum/Solution.py | 27 - .../solution/0000-0099/0015.3Sum/Solution.rb | 28 - .../0000-0099/0016.3Sum Closest/README_EN.md | 43 - .../0000-0099/0016.3Sum Closest/Solution.go | 54 - .../README_EN.md | 49 - .../Solution.cs | 37 - .../Solution.go | 28 - .../solution/0000-0099/0018.4Sum/README_EN.md | 128 -- .../solution/0000-0099/0018.4Sum/Solution.cpp | 40 - .../solution/0000-0099/0018.4Sum/Solution.cs | 64 - .../solution/0000-0099/0018.4Sum/Solution.go | 78 - .../solution/0000-0099/0018.4Sum/Solution.py | 31 - .../README_EN.md | 90 - .../Solution.cpp | 25 - .../Solution.go | 23 - .../Solution.js | 15 - .../Solution.py | 16 - .../Solution.rb | 27 - .../0020.Valid Parentheses/README_EN.md | 135 -- .../0020.Valid Parentheses/Solution.cpp | 16 - .../0020.Valid Parentheses/Solution.go | 54 - .../0020.Valid Parentheses/Solution.js | 14 - .../0020.Valid Parentheses/Solution.py | 10 - .../0020.Valid Parentheses/Solution.rb | 22 - .../0021.Merge Two Sorted Lists/README_EN.md | 88 - .../0021.Merge Two Sorted Lists/Solution.cpp | 37 - .../0021.Merge Two Sorted Lists/Solution.go | 49 - .../0021.Merge Two Sorted Lists/Solution.js | 58 - .../0021.Merge Two Sorted Lists/Solution.py | 19 - .../0021.Merge Two Sorted Lists/Solution.rb | 25 - .../0022.Generate Parentheses/README_EN.md | 59 - .../0022.Generate Parentheses/Solution.go | 19 - .../0023.Merge k Sorted Lists/README_EN.md | 116 -- .../0023.Merge k Sorted Lists/Solution.cpp | 105 -- .../0023.Merge k Sorted Lists/Solution.cs | 45 - .../0023.Merge k Sorted Lists/Solution.go | 53 - .../0023.Merge k Sorted Lists/Solution.py | 28 - .../0023.Merge k Sorted Lists/Solution.rb | 39 - .../0024.Swap Nodes in Pairs/README_EN.md | 116 -- .../0024.Swap Nodes in Pairs/Solution.cpp | 27 - .../0024.Swap Nodes in Pairs/Solution.go | 32 - .../0024.Swap Nodes in Pairs/Solution.py | 17 - .../0024.Swap Nodes in Pairs/Solution.rb | 23 - .../README_EN.md | 52 - .../0025.Reverse Nodes in k-Group/Solution.cs | 52 - .../0025.Reverse Nodes in k-Group/Solution.go | 59 - .../README_EN.md | 124 -- .../Solution.cs | 16 - .../Solution.go | 21 - .../Solution.js | 13 - .../Solution.py | 9 - .../0027.Remove Element/README_EN.md | 134 -- .../0027.Remove Element/Solution.cpp | 14 - .../0000-0099/0027.Remove Element/Solution.go | 13 - .../0000-0099/0027.Remove Element/Solution.js | 39 - .../0000-0099/0027.Remove Element/Solution.py | 9 - .../0028.Implement strStr()/README_EN.md | 59 - .../0028.Implement strStr()/Solution.cpp | 54 - .../0028.Implement strStr()/Solution.cs | 14 - .../0028.Implement strStr()/Solution.go | 26 - .../0028.Implement strStr()/Solution.js | 22 - .../0028.Implement strStr()/Solution.py | 18 - .../0029.Divide Two Integers/README_EN.md | 59 - .../0029.Divide Two Integers/Solution.cs | 49 - .../0029.Divide Two Integers/Solution.py | 29 - .../README_EN.md | 53 - .../Solution.cs | 57 - .../0031.Next Permutation/README_EN.md | 43 - .../0031.Next Permutation/Solution.cpp | 20 - .../0031.Next Permutation/Solution.cs | 26 - .../README_EN.md | 55 - .../Solution.cs | 40 - .../Solution.py | 24 - .../README_EN.md | 57 - .../Solution.cpp | 36 - .../Solution.js | 13 - .../README_EN.md | 51 - .../Solution.cpp | 46 - .../Solution.go | 48 - .../Solution.py | 41 - .../0035.Search Insert Position/README_EN.md | 154 -- .../0035.Search Insert Position/Solution.cpp | 13 - .../0035.Search Insert Position/Solution.go | 15 - .../0035.Search Insert Position/Solution.js | 16 - .../0035.Search Insert Position/Solution.py | 12 - .../0000-0099/0036.Valid Sudoku/README_EN.md | 120 -- .../0000-0099/0036.Valid Sudoku/Solution.js | 94 - .../0000-0099/0037.Sudoku Solver/README_EN.md | 57 - .../0000-0099/0037.Sudoku Solver/Solution.cs | 131 -- .../0000-0099/0038.Count and Say/README_EN.md | 65 - .../0000-0099/0038.Count and Say/Solution.cs | 37 - .../0000-0099/0038.Count and Say/Solution.go | 22 - .../0000-0099/0038.Count and Say/Solution.js | 20 - .../0000-0099/0038.Count and Say/Solution.py | 18 - .../0039.Combination Sum/README_EN.md | 78 - .../0039.Combination Sum/Solution.cpp | 23 - .../0039.Combination Sum/Solution.cs | 55 - .../0040.Combination Sum II/README_EN.md | 80 - .../0040.Combination Sum II/Solution.cpp | 27 - .../0040.Combination Sum II/Solution.cs | 71 - .../0040.Combination Sum II/Solution.go | 26 - .../0041.First Missing Positive/README_EN.md | 65 - .../0041.First Missing Positive/Solution.c | 22 - .../0041.First Missing Positive/Solution.cpp | 20 - .../0041.First Missing Positive/Solution.cs | 35 - .../0041.First Missing Positive/Solution.py | 11 - .../0042.Trapping Rain Water/README_EN.md | 43 - .../0042.Trapping Rain Water/Solution.cpp | 38 - .../0042.Trapping Rain Water/Solution.py | 30 - .../0043.Multiply Strings/README_EN.md | 58 - .../0043.Multiply Strings/Solution.cs | 36 - .../0043.Multiply Strings/Solution.py | 20 - .../0044.Wildcard Matching/README_EN.md | 126 -- .../0044.Wildcard Matching/Solution.cs | 43 - .../0000-0099/0045.Jump Game II/README_EN.md | 51 - .../0000-0099/0045.Jump Game II/Solution.cs | 29 - .../0000-0099/0046.Permutations/README_EN.md | 57 - .../0000-0099/0046.Permutations/Solution.cpp | 35 - .../0000-0099/0046.Permutations/Solution.cs | 31 - .../0000-0099/0046.Permutations/Solution.go | 32 - .../0000-0099/0046.Permutations/Solution.py | 15 - .../0047.Permutations II/README_EN.md | 51 - .../0047.Permutations II/Solution.cpp | 41 - .../0047.Permutations II/Solution.cs | 38 - .../0047.Permutations II/Solution.py | 40 - .../0000-0099/0048.Rotate Image/README_EN.md | 134 -- .../0000-0099/0048.Rotate Image/Solution.cpp | 22 - .../0000-0099/0048.Rotate Image/Solution.js | 39 - .../0000-0099/0048.Rotate Image/Solution.py | 15 - .../0049.Group Anagrams/README_EN.md | 56 - .../0000-0099/0049.Group Anagrams/Solution.cs | 55 - .../0000-0099/0050.Pow(x, n)/README_EN.md | 70 - .../0000-0099/0050.Pow(x, n)/Solution.js | 15 - .../0000-0099/0050.Pow(x, n)/Solution.py | 21 - .../0000-0099/0051.N-Queens/README_EN.md | 69 - .../0000-0099/0051.N-Queens/Solution.cs | 49 - .../0000-0099/0052.N-Queens II/README_EN.md | 69 - .../0053.Maximum Subarray/README_EN.md | 63 - .../0053.Maximum Subarray/Solution.cpp | 74 - .../0053.Maximum Subarray/Solution.go | 15 - .../0053.Maximum Subarray/Solution.js | 10 - .../0053.Maximum Subarray/Solution.py | 8 - .../0000-0099/0054.Spiral Matrix/README_EN.md | 133 -- .../0000-0099/0054.Spiral Matrix/Solution.cpp | 51 - .../0000-0099/0054.Spiral Matrix/Solution.cs | 48 - .../0000-0099/0054.Spiral Matrix/Solution.py | 16 - .../0000-0099/0055.Jump Game/README_EN.md | 61 - .../0000-0099/0055.Jump Game/Solution.cs | 19 - .../0056.Merge Intervals/README_EN.md | 55 - .../0056.Merge Intervals/Solution.cpp | 36 - .../0056.Merge Intervals/Solution.cs | 28 - .../0057.Insert Interval/README_EN.md | 55 - .../0057.Insert Interval/Solution.cpp | 32 - .../0057.Insert Interval/Solution.cs | 29 - .../0058.Length of Last Word/README_EN.md | 71 - .../0058.Length of Last Word/Solution.go | 18 - .../0058.Length of Last Word/Solution.js | 16 - .../0058.Length of Last Word/Solution.py | 12 - .../0059.Spiral Matrix II/README_EN.md | 133 -- .../0059.Spiral Matrix II/Solution.cpp | 28 - .../0059.Spiral Matrix II/Solution.py | 23 - .../0060.Permutation Sequence/README_EN.md | 71 - .../0060.Permutation Sequence/Solution.cs | 22 - .../0000-0099/0061.Rotate List/README_EN.md | 128 -- .../0000-0099/0061.Rotate List/Solution.cs | 29 - .../0000-0099/0061.Rotate List/Solution.py | 26 - .../0000-0099/0062.Unique Paths/README_EN.md | 67 - .../0000-0099/0062.Unique Paths/Solution.cpp | 21 - .../0000-0099/0062.Unique Paths/Solution.go | 25 - .../0000-0099/0062.Unique Paths/Solution.py | 15 - .../0063.Unique Paths II/README_EN.md | 99 - .../0063.Unique Paths II/Solution.go | 23 - .../0063.Unique Paths II/Solution.py | 22 - .../0064.Minimum Path Sum/README_EN.md | 55 - .../0064.Minimum Path Sum/Solution.cpp | 21 - .../0064.Minimum Path Sum/Solution.go | 36 - .../0000-0099/0065.Valid Number/README_EN.md | 76 - .../0000-0099/0065.Valid Number/Solution.cs | 12 - .../0000-0099/0065.Valid Number/Solution.py | 17 - .../0000-0099/0066.Plus One/README_EN.md | 59 - .../0000-0099/0066.Plus One/Solution.cpp | 19 - .../0000-0099/0066.Plus One/Solution.go | 11 - .../0000-0099/0066.Plus One/Solution.js | 12 - .../0000-0099/0066.Plus One/Solution.py | 20 - .../0000-0099/0067.Add Binary/README_EN.md | 49 - .../0000-0099/0067.Add Binary/Solution.cs | 29 - .../0000-0099/0067.Add Binary/Solution.go | 24 - .../0068.Text Justification/README_EN.md | 131 -- .../0068.Text Justification/Solution.cs | 66 - .../0000-0099/0069.Sqrt(x)/README_EN.md | 59 - .../0000-0099/0069.Sqrt(x)/Solution.cs | 30 - .../0000-0099/0069.Sqrt(x)/Solution.go | 28 - .../0000-0099/0069.Sqrt(x)/Solution.js | 18 - .../0000-0099/0069.Sqrt(x)/Solution.py | 18 - .../0070.Climbing Stairs/README_EN.md | 69 - .../0070.Climbing Stairs/Solution.cpp | 17 - .../0070.Climbing Stairs/Solution.go | 10 - .../0070.Climbing Stairs/Solution.js | 9 - .../0070.Climbing Stairs/Solution.py | 14 - .../0000-0099/0071.Simplify Path/README_EN.md | 103 -- .../0000-0099/0071.Simplify Path/Solution.cs | 50 - .../0000-0099/0072.Edit Distance/README_EN.md | 79 - .../0073.Set Matrix Zeroes/README_EN.md | 99 - .../0073.Set Matrix Zeroes/Solution.cpp | 113 -- .../0073.Set Matrix Zeroes/Solution.py | 17 - .../0074.Search a 2D Matrix/README_EN.md | 78 - .../0074.Search a 2D Matrix/Solution.cpp | 22 - .../0074.Search a 2D Matrix/Solution.py | 27 - .../0000-0099/0075.Sort Colors/README_EN.md | 51 - .../0000-0099/0075.Sort Colors/Solution.cpp | 20 - .../0000-0099/0075.Sort Colors/Solution.go | 20 - .../0000-0099/0075.Sort Colors/Solution.py | 19 - .../README_EN.md | 48 - .../0076.Minimum Window Substring/Solution.cs | 71 - .../0000-0099/0077.Combinations/README_EN.md | 57 - .../0000-0099/0078.Subsets/README_EN.md | 61 - .../0000-0099/0078.Subsets/Solution.cpp | 22 - .../0000-0099/0078.Subsets/Solution.go | 21 - .../0000-0099/0079.Word Search/README_EN.md | 117 -- .../0000-0099/0079.Word Search/Solution.cs | 37 - .../0000-0099/0079.Word Search/Solution.py | 20 - .../README_EN.md | 91 - .../Solution.cpp | 27 - .../Solution.cs | 16 - .../README_EN.md | 60 - .../README_EN.md | 47 - .../Solution.cs | 43 - .../Solution.py | 35 - .../README_EN.md | 51 - .../Solution.cs | 21 - .../Solution.go | 11 - .../Solution.js | 22 - .../Solution.py | 29 - .../README_EN.md | 55 - .../Solution.cpp | 42 - .../Solution.cs | 27 - .../0085.Maximal Rectangle/README_EN.md | 53 - .../0085.Maximal Rectangle/Solution.cs | 50 - .../0086.Partition List/README_EN.md | 43 - .../0086.Partition List/Solution.cpp | 34 - .../0000-0099/0086.Partition List/Solution.py | 30 - .../0087.Scramble String/README_EN.md | 117 -- .../0087.Scramble String/Solution.cs | 35 - .../0088.Merge Sorted Array/README_EN.md | 80 - .../0088.Merge Sorted Array/Solution.go | 20 - .../0088.Merge Sorted Array/Solution.js | 40 - .../0088.Merge Sorted Array/Solution.py | 15 - .../0000-0099/0089.Gray Code/README_EN.md | 85 - .../0000-0099/0089.Gray Code/Solution.cpp | 10 - .../0000-0099/0090.Subsets II/README_EN.md | 59 - .../0000-0099/0090.Subsets II/Solution.cpp | 22 - .../0000-0099/0091.Decode Ways/README_EN.md | 67 - .../0000-0099/0091.Decode Ways/Solution.cs | 25 - .../0092.Reverse Linked List II/README_EN.md | 98 - .../0092.Reverse Linked List II/Solution.cpp | 40 - .../0092.Reverse Linked List II/Solution.cs | 35 - .../0092.Reverse Linked List II/Solution.py | 25 - .../0093.Restore IP Addresses/README_EN.md | 41 - .../0093.Restore IP Addresses/Solution.cpp | 54 - .../0093.Restore IP Addresses/Solution.cs | 44 - .../README_EN.md | 53 - .../Solution.py | 44 - .../README_EN.md | 71 - .../Solution.go | 68 - .../README_EN.md | 57 - .../Solution.py | 12 - .../0097.Interleaving String/README_EN.md | 51 - .../0097.Interleaving String/Solution.cs | 33 - .../0097.Interleaving String/Solution.go | 23 - .../README_EN.md | 83 - .../Solution.cpp | 38 - .../Solution.cs | 13 - .../Solution.js | 28 - .../README_EN.md | 112 -- .../Solution.cs | 62 - .../0100-0199/0100.Same Tree/README_EN.md | 172 -- .../0100-0199/0100.Same Tree/Solution.cpp | 19 - .../0100-0199/0100.Same Tree/Solution.go | 17 - .../0100-0199/0100.Same Tree/Solution.py | 13 - .../0101.Symmetric Tree/README_EN.md | 128 -- .../0101.Symmetric Tree/Solution.cpp | 14 - .../0100-0199/0101.Symmetric Tree/Solution.js | 25 - .../0100-0199/0101.Symmetric Tree/Solution.py | 19 - .../README_EN.md | 160 -- .../Solution.cpp | 29 - .../Solution.js | 34 - .../Solution.py | 26 - .../README_EN.md | 73 - .../Solution.cpp | 33 - .../Solution.py | 41 - .../README_EN.md | 101 -- .../Solution.cpp | 9 - .../Solution.js | 36 - .../Solution.py | 13 - .../README_EN.md | 108 -- .../Solution.cpp | 30 - .../Solution.py | 23 - .../README_EN.md | 133 -- .../Solution.cpp | 18 - .../Solution.py | 23 - .../README_EN.md | 125 -- .../Solution.cpp | 20 - .../Solution.py | 25 - .../README_EN.md | 57 - .../Solution.cpp | 25 - .../Solution.js | 23 - .../README_EN.md | 57 - .../Solution.cpp | 19 - .../0110.Balanced Binary Tree/README_EN.md | 68 - .../0110.Balanced Binary Tree/Solution.cpp | 14 - .../README_EN.md | 95 - .../Solution.cpp | 9 - .../Solution.py | 19 - .../0100-0199/0112.Path Sum/README_EN.md | 91 - .../0100-0199/0112.Path Sum/Solution.cpp | 13 - .../0100-0199/0112.Path Sum/Solution.py | 16 - .../0100-0199/0113.Path Sum II/README_EN.md | 123 -- .../0100-0199/0113.Path Sum II/Solution.cpp | 21 - .../0100-0199/0113.Path Sum II/Solution.py | 24 - .../README_EN.md | 75 - .../Solution.cpp | 16 - .../0115.Distinct Subsequences/README_EN.md | 105 -- .../0115.Distinct Subsequences/Solution.cpp | 14 - .../README_EN.md | 72 - .../Solution.cpp | 21 - .../README_EN.md | 72 - .../Solution.cpp | 22 - .../Solution.go | 41 - .../0118.Pascal's Triangle/README_EN.md | 89 - .../0118.Pascal's Triangle/Solution.cpp | 21 - .../0118.Pascal's Triangle/Solution.js | 36 - .../0118.Pascal's Triangle/Solution.py | 11 - .../0119.Pascal's Triangle II/README_EN.md | 51 - .../0119.Pascal's Triangle II/Solution.cpp | 15 - .../0100-0199/0120.Triangle/README_EN.md | 55 - .../0100-0199/0120.Triangle/Solution.cpp | 30 - .../README_EN.md | 81 - .../Solution.cpp | 17 - .../Solution.cs | 18 - .../Solution.js | 13 - .../Solution.py | 10 - .../README_EN.md | 112 -- .../Solution.cpp | 13 - .../Solution.cs | 20 - .../Solution.js | 9 - .../Solution.py | 9 - .../README_EN.md | 73 - .../Solution.cpp | 44 - .../Solution.cs | 37 - .../Solution.py | 12 - .../README_EN.md | 77 - .../Solution.cpp | 27 - .../Solution.cs | 21 - .../Solution.go | 37 - .../0125.Valid Palindrome/README_EN.md | 53 - .../0125.Valid Palindrome/Solution.cpp | 24 - .../0125.Valid Palindrome/Solution.cs | 14 - .../0125.Valid Palindrome/Solution.js | 50 - .../0126.Word Ladder II/README_EN.md | 98 - .../0100-0199/0127.Word Ladder/README_EN.md | 96 - .../0100-0199/0127.Word Ladder/Solution.cpp | 26 - .../0100-0199/0127.Word Ladder/Solution.cs | 68 - .../README_EN.md | 45 - .../Solution.cpp | 16 - .../README_EN.md | 87 - .../Solution.cpp | 34 - .../0129.Sum Root to Leaf Numbers/Solution.go | 16 - .../0130.Surrounded Regions/README_EN.md | 65 - .../0130.Surrounded Regions/Solution.cpp | 50 - .../0130.Surrounded Regions/Solution.cs | 60 - .../0131.Palindrome Partitioning/README_EN.md | 51 - .../0131.Palindrome Partitioning/Solution.cs | 85 - .../README_EN.md | 45 - .../Solution.cs | 67 - .../0100-0199/0133.Clone Graph/README_EN.md | 105 -- .../0100-0199/0133.Clone Graph/Solution.cs | 34 - .../0100-0199/0134.Gas Station/README_EN.md | 109 -- .../0100-0199/0134.Gas Station/Solution.cs | 30 - .../0100-0199/0135.Candy/README_EN.md | 66 - .../solution/0100-0199/0135.Candy/Solution.cs | 40 - .../0100-0199/0136.Single Number/README_EN.md | 96 - .../0100-0199/0136.Single Number/Solution.go | 7 - .../0100-0199/0136.Single Number/Solution.js | 11 - .../0100-0199/0136.Single Number/Solution.py | 6 - .../0137.Single Number II/README_EN.md | 82 - .../0137.Single Number II/Solution.py | 12 - .../README_EN.md | 85 - .../Solution.cs | 31 - .../0100-0199/0139.Word Break/README_EN.md | 74 - .../0100-0199/0139.Word Break/Solution.cs | 29 - .../0100-0199/0140.Word Break II/README_EN.md | 100 - .../0100-0199/0140.Word Break II/Solution.cs | 77 - .../0141.Linked List Cycle/README_EN.md | 132 -- .../0141.Linked List Cycle/Solution.go | 20 - .../0141.Linked List Cycle/Solution.js | 35 - .../0141.Linked List Cycle/Solution.py | 14 - .../0142.Linked List Cycle II/README_EN.md | 125 -- .../0142.Linked List Cycle II/Solution.cpp | 22 - .../0142.Linked List Cycle II/Solution.py | 21 - .../0100-0199/0143.Reorder List/README_EN.md | 119 -- .../0100-0199/0143.Reorder List/Solution.cs | 55 - .../0100-0199/0143.Reorder List/Solution.go | 28 - .../0100-0199/0143.Reorder List/Solution.py | 31 - .../README_EN.md | 55 - .../README_EN.md | 55 - .../0100-0199/0146.Lru Cache/README_EN.md | 71 - .../0100-0199/0146.Lru Cache/Solution.cpp | 57 - .../0100-0199/0146.Lru Cache/Solution.cs | 111 -- .../0100-0199/0146.Lru Cache/Solution.go | 105 -- .../0147.Insertion Sort List/README_EN.md | 136 -- .../0147.Insertion Sort List/Solution.py | 26 - .../0100-0199/0148.Sort List/README_EN.md | 114 -- .../0100-0199/0148.Sort List/Solution.cs | 50 - .../0100-0199/0148.Sort List/Solution.py | 27 - .../0149.Max Points on a Line/README_EN.md | 87 - .../0149.Max Points on a Line/Solution.cs | 101 -- .../README_EN.md | 138 -- .../Solution.cs | 30 - .../Solution.py | 17 - .../README_EN.md | 83 - .../Solution.cs | 41 - .../README_EN.md | 74 - .../0152.Maximum Product Subarray/Solution.cs | 18 - .../0152.Maximum Product Subarray/Solution.py | 10 - .../README_EN.md | 79 - .../Solution.cpp | 20 - .../Solution.go | 23 - .../Solution.py | 10 - .../README_EN.md | 86 - .../Solution.py | 12 - .../0100-0199/0155.Min Stack/README_EN.md | 133 -- .../0100-0199/0155.Min Stack/Solution.cpp | 40 - .../0100-0199/0155.Min Stack/Solution.cs | 25 - .../0100-0199/0155.Min Stack/Solution.js | 62 - .../0100-0199/0155.Min Stack/Solution.py | 32 - .../README_EN.md | 133 -- .../Solution.js | 46 - .../Solution.py | 15 - .../0162.Find Peak Element/README_EN.md | 65 - .../0100-0199/0164.Maximum Gap/README_EN.md | 62 - .../0100-0199/0164.Maximum Gap/Solution.cs | 39 - .../0165.Compare Version Numbers/README_EN.md | 98 - .../0165.Compare Version Numbers/Solution.cs | 31 - .../README_EN.md | 61 - .../Solution.cs | 57 - .../README_EN.md | 50 - .../Solution.cpp | 39 - .../README_EN.md | 83 - .../0168.Excel Sheet Column Title/Solution.cs | 22 - .../0169.Majority Element/README_EN.md | 51 - .../0169.Majority Element/Solution.cs | 30 - .../README_EN.md | 83 - .../README_EN.md | 53 - .../Solution.cpp | 9 - .../README_EN.md | 76 - .../0100-0199/0174.Dungeon Game/README_EN.md | 110 -- .../0100-0199/0174.Dungeon Game/Solution.cs | 22 - .../0179.Largest Number/README_EN.md | 51 - .../0100-0199/0179.Largest Number/Solution.cs | 54 - .../0187.Repeated DNA Sequences/README_EN.md | 45 - .../0187.Repeated DNA Sequences/Solution.cs | 63 - .../README_EN.md | 53 - .../Solution.cs | 121 -- .../Solution.py | 28 - .../0100-0199/0189.Rotate Array/README_EN.md | 108 -- .../0100-0199/0189.Rotate Array/Solution.cs | 52 - .../0100-0199/0189.Rotate Array/Solution.py | 12 - .../0100-0199/0190.Reverse Bits/README_EN.md | 63 - .../0100-0199/0190.Reverse Bits/Solution.cpp | 16 - .../0100-0199/0190.Reverse Bits/Solution.js | 6 - .../0100-0199/0190.Reverse Bits/Solution.py | 7 - .../0191.Number of 1 Bits/README_EN.md | 82 - .../0191.Number of 1 Bits/Solution.js | 8 - .../0191.Number of 1 Bits/Solution.py | 8 - .../0100-0199/0198.House Robber/README_EN.md | 88 - .../0100-0199/0198.House Robber/Solution.cpp | 20 - .../0100-0199/0198.House Robber/Solution.go | 15 - .../0100-0199/0198.House Robber/Solution.py | 12 - .../README_EN.md | 73 - .../0200.Number of Islands/README_EN.md | 71 - .../0200.Number of Islands/Solution.cs | 40 - .../0200.Number of Islands/Solution.py | 20 - .../README_EN.md | 49 - .../Solution.cs | 13 - .../0200-0299/0202.Happy Number/README_EN.md | 85 - .../0200-0299/0202.Happy Number/Solution.py | 14 - .../README_EN.md | 75 - .../Solution.cs | 25 - .../Solution.py | 15 - .../0200-0299/0204.Count Primes/README_EN.md | 72 - .../0200-0299/0204.Count Primes/Solution.cpp | 29 - .../0200-0299/0204.Count Primes/Solution.cs | 18 - .../0200-0299/0204.Count Primes/Solution.js | 31 - .../0200-0299/0204.Count Primes/Solution.py | 12 - .../0205.Isomorphic Strings/README_EN.md | 88 - .../0205.Isomorphic Strings/Solution.cs | 27 - .../0205.Isomorphic Strings/Solution.py | 11 - .../0206.Reverse Linked List/README_EN.md | 150 -- .../0206.Reverse Linked List/Solution.cs | 13 - .../0206.Reverse Linked List/Solution.go | 14 - .../0206.Reverse Linked List/Solution.js | 22 - .../0206.Reverse Linked List/Solution.py | 15 - .../0207.Course Schedule/README_EN.md | 64 - .../0207.Course Schedule/Solution.cs | 44 - .../README_EN.md | 60 - .../Solution.cs | 63 - .../README_EN.md | 45 - .../Solution.cs | 26 - .../0210.Course Schedule II/README_EN.md | 70 - .../0210.Course Schedule II/Solution.cs | 45 - .../README_EN.md | 70 - .../Solution.cs | 67 - .../0213.House Robber II/README_EN.md | 104 -- .../0213.House Robber II/Solution.go | 26 - .../0213.House Robber II/Solution.py | 18 - .../README_EN.md | 53 - .../Solution.cpp | 44 - .../Solution.go | 35 - .../0216.Combination Sum III/README_EN.md | 62 - .../0216.Combination Sum III/Solution.cs | 59 - .../0217.Contains Duplicate/README_EN.md | 68 - .../0217.Contains Duplicate/Solution.cs | 11 - .../0217.Contains Duplicate/Solution.js | 23 - .../0217.Contains Duplicate/Solution.py | 3 - .../0219.Contains Duplicate II/README_EN.md | 94 - .../0219.Contains Duplicate II/Solution.cs | 37 - .../0219.Contains Duplicate II/Solution.py | 8 - .../0220.Contains Duplicate III/README_EN.md | 73 - .../0220.Contains Duplicate III/Solution.cs | 35 - .../0221.Maximal Square/README_EN.md | 53 - .../0200-0299/0221.Maximal Square/Solution.cs | 40 - .../README_EN.md | 57 - .../Solution.cs | 38 - .../0223.Rectangle Area/README_EN.md | 47 - .../0200-0299/0223.Rectangle Area/Solution.cs | 20 - .../0224.Basic Calculator/README_EN.md | 66 - .../0224.Basic Calculator/Solution.cs | 62 - .../README_EN.md | 151 -- .../Solution.py | 47 - .../0226.Invert Binary Tree/README_EN.md | 145 -- .../0226.Invert Binary Tree/Solution.go | 17 - .../0226.Invert Binary Tree/Solution.js | 18 - .../0226.Invert Binary Tree/Solution.py | 15 - .../0227.Basic Calculator II/README_EN.md | 68 - .../0227.Basic Calculator II/Solution.cs | 84 - .../0228.Summary Ranges/README_EN.md | 55 - .../0228.Summary Ranges/Solution.cpp | 37 - .../0200-0299/0228.Summary Ranges/Solution.cs | 18 - .../0200-0299/0228.Summary Ranges/Solution.py | 32 - .../0229.Majority Element II/README_EN.md | 49 - .../0229.Majority Element II/Solution.cs | 44 - .../README_EN.md | 81 - .../0200-0299/0231.Power of Two/README_EN.md | 61 - .../0200-0299/0231.Power of Two/Solution.py | 13 - .../README_EN.md | 167 -- .../Solution.py | 54 - .../0233.Number of Digit One/README_EN.md | 43 - .../0233.Number of Digit One/Solution.cs | 17 - .../0234.Palindrome Linked List/README_EN.md | 109 -- .../0234.Palindrome Linked List/Solution.cs | 48 - .../0234.Palindrome Linked List/Solution.js | 58 - .../0234.Palindrome Linked List/Solution.py | 22 - .../README_EN.md | 206 --- .../Solution.go | 24 - .../Solution.py | 16 - .../README_EN.md | 131 -- .../Solution.js | 21 - .../Solution.py | 18 - .../README_EN.md | 112 -- .../Solution.js | 15 - .../Solution.py | 14 - .../README_EN.md | 92 - .../Solution.cpp | 23 - .../Solution.js | 17 - .../Solution.py | 12 - .../0239.Sliding Window Maximum/README_EN.md | 69 - .../0239.Sliding Window Maximum/Solution.cs | 26 - .../0240.Search a 2D Matrix II/README_EN.md | 62 - .../README_EN.md | 67 - .../Solution.cs | 61 - .../Solution.go | 36 - .../0200-0299/0242.Valid Anagram/README_EN.md | 59 - .../0200-0299/0242.Valid Anagram/Solution.js | 27 - .../0243.Shortest Word Distance/README_EN.md | 47 - .../README_EN.md | 46 - .../README_EN.md | 49 - .../0246.Strobogrammatic Number/README_EN.md | 88 - .../0246.Strobogrammatic Number/Solution.py | 18 - .../README_EN.md | 39 - .../0200-0299/0252.Meeting Rooms/README_EN.md | 61 - .../0200-0299/0252.Meeting Rooms/Solution.py | 7 - .../0257.Binary Tree Paths/README_EN.md | 113 -- .../0257.Binary Tree Paths/Solution.py | 22 - .../0200-0299/0258.Add Digits/README_EN.md | 66 - .../0200-0299/0258.Add Digits/Solution.cpp | 6 - .../0200-0299/0258.Add Digits/Solution.py | 3 - .../0260.Single Number III/README_EN.md | 73 - .../0260.Single Number III/Solution.py | 13 - .../0200-0299/0263.Ugly Number/README_EN.md | 74 - .../0264.Ugly Number II/README_EN.md | 50 - .../0266.Palindrome Permutation/README_EN.md | 73 - .../0266.Palindrome Permutation/Solution.py | 10 - .../0268.Missing Number/README_EN.md | 84 - .../0200-0299/0268.Missing Number/Solution.js | 6 - .../README_EN.md | 69 - .../0273.Integer to English Words/Solution.cs | 88 - .../0200-0299/0274.H-Index/README_EN.md | 51 - .../0200-0299/0275.H-Index II/README_EN.md | 60 - .../0278.First Bad Version/README_EN.md | 124 -- .../0278.First Bad Version/Solution.js | 33 - .../0278.First Bad Version/Solution.py | 19 - .../0279.Perfect Squares/README_EN.md | 51 - .../0279.Perfect Squares/Solution.go | 24 - .../0200-0299/0283.Move Zeroes/README_EN.md | 80 - .../0200-0299/0283.Move Zeroes/Solution.cpp | 48 - .../0200-0299/0283.Move Zeroes/Solution.js | 14 - .../0200-0299/0283.Move Zeroes/Solution.py | 17 - .../0284.Peeking Iterator/README_EN.md | 51 - .../README_EN.md | 58 - .../0200-0299/0289.Game of Life/README_EN.md | 86 - .../0200-0299/0290.Word Pattern/README_EN.md | 105 -- .../0200-0299/0290.Word Pattern/Solution.py | 15 - .../0200-0299/0292.Nim Game/README_EN.md | 47 - .../0200-0299/0293.Flip Game/README_EN.md | 70 - .../0200-0299/0293.Flip Game/Solution.py | 10 - .../README_EN.md | 71 - .../Solution.cs | 60 - .../README_EN.md | 61 - .../0299.Bulls and Cows/README_EN.md | 65 - .../README_EN.md | 78 - .../Solution.cpp | 17 - .../Solution.py | 13 - .../README_EN.md | 63 - .../README_EN.md | 61 - .../README_EN.md | 83 - .../0306.Additive Number/README_EN.md | 67 - .../README_EN.md | 56 - .../Solution.cs | 75 - .../README_EN.md | 50 - .../0312.Burst Balloons/README_EN.md | 54 - .../0300-0399/0319.Bulb Switcher/README_EN.md | 55 - .../0300-0399/0322.Coin Change/README_EN.md | 74 - .../0300-0399/0322.Coin Change/Solution.js | 18 - .../0328.Odd Even Linked List/README_EN.md | 103 -- .../0328.Odd Even Linked List/Solution.py | 18 - .../README_EN.md | 77 - .../Solution.cpp | 54 - .../README_EN.md | 83 - .../0337.House Robber III/README_EN.md | 83 - .../0300-0399/0342.Power of Four/README_EN.md | 55 - .../0300-0399/0342.Power of Four/Solution.js | 3 - .../0300-0399/0343.Integer Break/README_EN.md | 61 - .../0344.Reverse String/README_EN.md | 83 - .../0300-0399/0344.Reverse String/Solution.js | 3 - .../0300-0399/0344.Reverse String/Solution.py | 10 - .../README_EN.md | 119 -- .../Solution.py | 17 - .../0347.Top K Frequent Elements/README_EN.md | 60 - .../README_EN.md | 85 - .../Solution.py | 4 - .../README_EN.md | 68 - .../Solution.js | 12 - .../0354.Russian Doll Envelopes/README_EN.md | 87 - .../0354.Russian Doll Envelopes/Solution.py | 15 - .../0355.Design Twitter/README_EN.md | 103 -- .../0367.Valid Perfect Square/README_EN.md | 61 - .../0371.Sum of Two Integers/README_EN.md | 59 - .../README_EN.md | 61 - .../0376.Wiggle Subsequence/README_EN.md | 75 - .../0377.Combination Sum IV/README_EN.md | 81 - .../README_EN.md | 65 - .../README_EN.md | 99 - .../README_EN.md | 95 - .../0300-0399/0383.Ransom Note/README_EN.md | 82 - .../0300-0399/0383.Ransom Note/Solution.py | 10 - .../0384.Shuffle an Array/README_EN.md | 65 - .../0384.Shuffle an Array/Solution.js | 36 - .../README_EN.md | 83 - .../Solution.cpp | 23 - .../Solution.js | 48 - .../Solution.py | 11 - .../0392.Is Subsequence/README_EN.md | 97 - .../0300-0399/0392.Is Subsequence/Solution.py | 9 - .../0300-0399/0394.Decode String/README_EN.md | 47 - .../0300-0399/0394.Decode String/Solution.py | 42 - .../0397.Integer Replacement/README_EN.md | 107 -- .../0400-0499/0400.Nth Digit/README_EN.md | 79 - .../0400-0499/0401.Binary Watch/README_EN.md | 59 - .../0402.Remove K Digits/README_EN.md | 89 - .../0404.Sum of Left Leaves/README_EN.md | 53 - .../README_EN.md | 87 - .../README_EN.md | 55 - .../0409.Longest Palindrome/README_EN.md | 84 - .../0409.Longest Palindrome/Solution.py | 9 - .../0410.Split Array Largest Sum/README_EN.md | 77 - .../0414.Third Maximum Number/README_EN.md | 87 - .../0400-0499/0415.Add Strings/README_EN.md | 47 - .../README_EN.md | 53 - .../Solution.py | 19 - .../README_EN.md | 89 - .../README_EN.md | 190 -- .../Solution.js | 29 - .../Solution.py | 28 - .../README_EN.md | 60 - .../README_EN.md | 113 -- .../0400-0499/0437.Path Sum III/README_EN.md | 77 - .../0441.Arranging Coins/README_EN.md | 91 - .../0441.Arranging Coins/Solution.py | 3 - .../README_EN.md | 53 - .../0445.Add Two Numbers II/README_EN.md | 53 - .../README_EN.md | 80 - .../Solution.cpp | 24 - .../Solution.py | 11 - .../README_EN.md | 37 - .../0450.Delete Node in a BST/README_EN.md | 105 -- .../README_EN.md | 57 - .../README_EN.md | 59 - .../0400-0499/0454.4Sum II/README_EN.md | 67 - .../0400-0499/0456.132 Pattern/README_EN.md | 91 - .../0400-0499/0458.Poor Pigs/README_EN.md | 49 - .../README_EN.md | 67 - .../0461.Hamming Distance/README_EN.md | 67 - .../0461.Hamming Distance/Solution.js | 9 - .../README_EN.md | 61 - .../0473.Matchsticks to Square/README_EN.md | 77 - .../0400-0499/0475.Heaters/README_EN.md | 74 - .../0477.Total Hamming Distance/README_EN.md | 67 - .../0483.Smallest Good Base/README_EN.md | 84 - .../0485.Max Consecutive Ones/README_EN.md | 103 -- .../0485.Max Consecutive Ones/Solution.js | 17 - .../0485.Max Consecutive Ones/Solution.py | 10 - .../0486.Predict the Winner/README_EN.md | 75 - .../0487.Max Consecutive Ones II/README_EN.md | 132 -- .../0487.Max Consecutive Ones II/Solution.py | 28 - .../0400-0499/0490.The Maze/README_EN.md | 150 -- .../0400-0499/0490.The Maze/Solution.py | 29 - .../0492.Construct the Rectangle/README_EN.md | 97 - .../0492.Construct the Rectangle/Solution.py | 13 - .../0400-0499/0494.Target Sum/README_EN.md | 83 - .../0496.Next Greater Element I/README_EN.md | 91 - .../0500-0599/0500.Keyboard Row/README_EN.md | 56 - .../0500-0599/0500.Keyboard Row/Solution.py | 16 - .../README_EN.md | 67 - .../solution/0500-0599/0502.IPO/README_EN.md | 87 - .../0503.Next Greater Element II/README_EN.md | 55 - .../0500-0599/0504.Base 7/README_EN.md | 61 - .../0506.Relative Ranks/README_EN.md | 59 - .../0507.Perfect Number/README_EN.md | 57 - .../README_EN.md | 77 - .../0509.Fibonacci Number/README_EN.md | 85 - .../0509.Fibonacci Number/Solution.cpp | 9 - .../0509.Fibonacci Number/Solution.js | 20 - .../README_EN.md | 97 - .../README_EN.md | 57 - .../0500-0599/0518.Coin Change 2/README_EN.md | 92 - .../0520.Detect Capital/README_EN.md | 69 - .../README_EN.md | 75 - .../Solution.py | 8 - .../README_EN.md | 71 - .../0523.Continuous Subarray Sum/README_EN.md | 66 - .../0525.Contiguous Array/README_EN.md | 65 - .../0526.Beautiful Arrangement/README_EN.md | 86 - .../README_EN.md | 58 - .../Solution.go | 27 - .../README_EN.md | 47 - .../0541.Reverse String II/README_EN.md | 57 - .../0500-0599/0542.01 Matrix/README_EN.md | 93 - .../0543.Diameter of Binary Tree/README_EN.md | 69 - .../0500-0599/0554.Brick Wall/README_EN.md | 76 - .../0500-0599/0554.Brick Wall/Solution.py | 22 - .../README_EN.md | 55 - .../README_EN.md | 49 - .../0560.Subarray Sum Equals K/README_EN.md | 55 - .../0561.Array Partition I/README_EN.md | 91 - .../0561.Array Partition I/Solution.js | 12 - .../0561.Array Partition I/Solution.py | 3 - .../0563.Binary Tree Tilt/README_EN.md | 75 - .../0566.Reshape the Matrix/README_EN.md | 127 -- .../0566.Reshape the Matrix/Solution.py | 9 - .../0572.Subtree of Another Tree/README_EN.md | 107 -- .../0572.Subtree of Another Tree/Solution.cpp | 37 - .../0576.Out of Boundary Paths/README_EN.md | 71 - .../README_EN.md | 59 - .../Solution.cpp | 40 - .../README_EN.md | 66 - .../README_EN.md | 66 - .../0605.Can Place Flowers/README_EN.md | 71 - .../0605.Can Place Flowers/Solution.cpp | 33 - .../0605.Can Place Flowers/Solution.py | 22 - .../README_EN.md | 85 - .../0611.Valid Triangle Number/README_EN.md | 65 - .../0617.Merge Two Binary Trees/README_EN.md | 71 - .../0617.Merge Two Binary Trees/Solution.go | 20 - .../0622.Design Circular Queue/README_EN.md | 83 - .../0633.Sum of Square Numbers/README_EN.md | 57 - .../README_EN.md | 67 - .../0600-0699/0645.Set Mismatch/README_EN.md | 126 -- .../0600-0699/0645.Set Mismatch/Solution.py | 26 - .../0650.2 Keys Keyboard/README_EN.md | 70 - .../0652.Find Duplicate Subtrees/README_EN.md | 75 - .../0664.Strange Printer/README_EN.md | 79 - .../README_EN.md | 111 -- .../README_EN.md | 83 - .../README_EN.md | 69 - .../README_EN.md | 91 - .../Solution.py | 10 - .../0600-0699/0679.24 Game/README_EN.md | 77 - .../0600-0699/0682.Baseball Game/README_EN.md | 162 -- .../0600-0699/0682.Baseball Game/Solution.py | 13 - .../0684.Redundant Connection/README_EN.md | 103 -- .../0687.Longest Univalue Path/README_EN.md | 81 - .../0690.Employee Importance/README_EN.md | 60 - .../0695.Max Area of Island/README_EN.md | 67 - .../0695.Max Area of Island/Solution.cpp | 51 - .../0696.Count Binary Substrings/README_EN.md | 75 - .../0697.Degree of an Array/README_EN.md | 119 -- .../0697.Degree of an Array/Solution.py | 19 - .../README_EN.md | 69 - .../Solution.cpp | 30 - .../Solution.py | 27 - .../README_EN.md | 89 - .../Solution.py | 51 - .../README_EN.md | 59 - .../0700-0799/0704.Binary Search/README_EN.md | 69 - .../0700-0799/0704.Binary Search/Solution.py | 23 - .../0707.Design Linked List/README_EN.md | 231 --- .../0707.Design Linked List/Solution.py | 79 - .../README_EN.md | 60 - .../0724.Find Pivot Index/README_EN.md | 82 - .../README_EN.md | 111 -- .../0739.Daily Temperatures/README_EN.md | 71 - .../0739.Daily Temperatures/Solution.py | 11 - .../0740.Delete and Earn/README_EN.md | 122 -- .../README_EN.md | 96 - .../0746.Min Cost Climbing Stairs/Solution.py | 8 - .../0700-0799/0752.Open the Lock/README_EN.md | 125 -- .../0760.Find Anagram Mappings/README_EN.md | 58 - .../0760.Find Anagram Mappings/Solution.py | 9 - .../0766.Toeplitz Matrix/README_EN.md | 123 -- .../0766.Toeplitz Matrix/Solution.py | 8 - .../0771.Jewels and Stones/README_EN.md | 60 - .../0771.Jewels and Stones/Solution.cpp | 13 - .../0771.Jewels and Stones/Solution.py | 7 - .../README_EN.md | 62 - .../README_EN.md | 58 - .../Solution.go | 36 - .../0784.Letter Case Permutation/README_EN.md | 60 - .../0814.Binary Tree Pruning/README_EN.md | 86 - .../0817.Linked List Components/README_EN.md | 80 - .../0817.Linked List Components/Solution.py | 29 - .../0829.Consecutive Numbers Sum/README_EN.md | 63 - .../0832.Flipping an Image/README_EN.md | 126 -- .../0832.Flipping an Image/Solution.cpp | 20 - .../0832.Flipping an Image/Solution.js | 34 - .../0832.Flipping an Image/Solution.py | 14 - .../README_EN.md | 68 - .../0856.Score of Parentheses/README_EN.md | 104 -- .../README_EN.md | 89 - .../0860.Lemonade Change/README_EN.md | 126 -- .../README_EN.md | 91 - .../0872.Leaf-Similar Trees/README_EN.md | 99 - .../0872.Leaf-Similar Trees/Solution.py | 20 - .../0875.Koko Eating Bananas/README_EN.md | 95 - .../README_EN.md | 79 - .../Solution.py | 23 - .../0878.Nth Magical Number/README_EN.md | 105 -- .../README_EN.md | 216 --- .../0887.Super Egg Drop/README_EN.md | 108 -- .../0800-0899/0887.Super Egg Drop/Solution.py | 8 - .../README_EN.md | 70 - .../README_EN.md | 132 -- .../README_EN.md | 124 -- .../Solution.py | 22 - .../README_EN.md | 104 -- .../0900-0999/0912.Sort an Array/README_EN.md | 47 - .../README_EN.md | 122 -- .../0922.Sort Array By Parity II/README_EN.md | 65 - .../0922.Sort Array By Parity II/Solution.js | 27 - .../0929.Unique Email Addresses/README_EN.md | 73 - .../0929.Unique Email Addresses/Solution.js | 40 - .../0929.Unique Email Addresses/Solution.py | 13 - .../README_EN.md | 65 - .../Solution.js | 26 - .../README_EN.md | 66 - .../0933.Number of Recent Calls/README_EN.md | 101 -- .../0933.Number of Recent Calls/Solution.py | 16 - .../0938.Range Sum of BST/README_EN.md | 72 - .../0938.Range Sum of BST/Solution.cpp | 47 - .../0938.Range Sum of BST/Solution.py | 30 - .../README_EN.md | 80 - .../README_EN.md | 99 - .../README_EN.md | 132 -- .../README_EN.md | 77 - .../README_EN.md | 91 - .../Solution.cpp | 12 - .../Solution.js | 10 - .../Solution.py | 17 - .../README_EN.md | 87 - .../README_EN.md | 71 - .../Solution.cpp | 17 - .../Solution.js | 46 - .../README_EN.md | 95 - .../README_EN.md | 106 -- .../README_EN.md | 114 -- .../README_EN.md | 136 -- .../Solution.py | 20 - .../README_EN.md | 84 - .../README_EN.md | 57 - .../Solution.py | 29 - .../README_EN.md | 80 - .../README_EN.md | 79 - .../Solution.py | 13 - .../1017.Convert to Base -2/README_EN.md | 91 - .../README_EN.md | 90 - .../README_EN.md | 115 -- .../README_EN.md | 61 - .../1000-1099/1025.Divisor Game/README_EN.md | 88 - .../1000-1099/1025.Divisor Game/Solution.cpp | 20 - .../README_EN.md | 60 - .../Solution.cpp | 41 - .../1029.Two City Scheduling/README_EN.md | 69 - .../README_EN.md | 100 - .../README_EN.md | 106 -- .../1034.Coloring A Border/README_EN.md | 88 - .../1036.Escape a Large Maze/README_EN.md | 78 - .../1037.Valid Boomerang/README_EN.md | 73 - .../README_EN.md | 68 - .../1041.Robot Bounded In Circle/README_EN.md | 80 - .../README_EN.md | 54 - .../1046.Last Stone Weight/README_EN.md | 69 - .../README_EN.md | 60 - .../1048.Longest String Chain/README_EN.md | 67 - .../1051.Height Checker/README_EN.md | 71 - .../1052.Grumpy Bookstore Owner/README_EN.md | 91 - .../1052.Grumpy Bookstore Owner/Solution.py | 13 - .../README_EN.md | 90 - .../1054.Distant Barcodes/README_EN.md | 72 - .../README_EN.md | 66 - .../README_EN.md | 98 - .../README_EN.md | 57 - .../README_EN.md | 76 - .../README_EN.md | 68 - .../README_EN.md | 107 -- .../README_EN.md | 76 - .../1089.Duplicate Zeros/README_EN.md | 70 - .../README_EN.md | 116 -- .../README_EN.md | 79 - .../README_EN.md | 58 - .../1000-1099/1094.Car Pooling/README_EN.md | 90 - .../1095.Find in Mountain Array/README_EN.md | 82 - .../README_EN.md | 72 - .../README_EN.md | 59 - .../1108.Defanging an IP Address/README_EN.md | 57 - .../README_EN.md | 57 - .../README_EN.md | 60 - .../Solution.py | 55 - .../README_EN.md | 77 - .../1114.Print in Order/README_EN.md | 64 - .../1114.Print in Order/Solution.cpp | 34 - .../README_EN.md | 67 - .../Solution.cpp | 30 - .../1116.Print Zero Even Odd/README_EN.md | 67 - .../1116.Print Zero Even Odd/Solution.cpp | 43 - .../1100-1199/1117.Building H2O/README_EN.md | 75 - .../1100-1199/1117.Building H2O/Solution.cpp | 25 - .../1122.Relative Sort Array/README_EN.md | 48 - .../README_EN.md | 73 - .../README_EN.md | 54 - .../README_EN.md | 52 - .../1137.N-th Tribonacci Number/README_EN.md | 72 - .../1138.Alphabet Board Path/README_EN.md | 76 - .../README_EN.md | 63 - .../1100-1199/1140.Stone Game II/README_EN.md | 62 - .../README_EN.md | 64 - .../README_EN.md | 96 - .../README_EN.md | 116 -- .../README_EN.md | 66 - .../README_EN.md | 92 - .../1185.Day of the Week/README_EN.md | 75 - .../1195.Fizz Buzz Multithreaded/README_EN.md | 59 - .../1195.Fizz Buzz Multithreaded/Solution.cpp | 56 - .../README_EN.md | 52 - .../Solution.js | 16 - .../Solution.py | 7 - .../README_EN.md | 99 - .../README_EN.md | 76 - .../Solution.py | 6 - .../README_EN.md | 72 - .../README_EN.md | 83 - .../README_EN.md | 110 -- .../Solution.py | 5 - .../1476.Subrectangle Queries/README_EN.md | 157 -- .../README_EN.md | 107 -- .../1537.Get the Maximum Score/README_EN.md | 93 - .../README_EN.md | 93 - .../1544.Make The String Great/README_EN.md | 93 - .../README_EN.md | 104 -- .../README_EN.md | 73 - .../1550.Three Consecutive Odds/README_EN.md | 56 - .../README_EN.md | 71 - .../README_EN.md | 65 - .../README_EN.md | 113 -- .../README_EN.md | 72 - .../README_EN.md | 78 - .../README_EN.md | 88 - .../README_EN.md | 86 - .../README_EN.md | 82 - .../README_EN.md | 99 - .../1572.Matrix Diagonal Sum/README_EN.md | 73 - .../README_EN.md | 81 - .../README_EN.md | 75 - .../README_EN.md | 119 -- .../Solution.go | 14 - .../Solution.py | 12 - .../README_EN.md | 70 - .../README_EN.md | 85 - .../README_EN.md | 85 - .../1583.Count Unhappy Friends/README_EN.md | 93 - .../README_EN.md | 88 - .../README_EN.md | 75 - leetcode/solution/README_EN.md | 1611 ----------------- notes/src/main/java/org/example/Main.java | 17 + 1388 files changed, 18 insertions(+), 70180 deletions(-) delete mode 100644 leetcode/README_EN.md delete mode 100644 leetcode/basic/README_EN.md delete mode 100644 leetcode/lcci/01.01.Is Unique/README_EN.md delete mode 100644 leetcode/lcci/01.01.Is Unique/Solution.py delete mode 100644 leetcode/lcci/01.02.Check Permutation/README_EN.md delete mode 100644 leetcode/lcci/01.02.Check Permutation/Solution.py delete mode 100644 leetcode/lcci/01.03.String to URL/README_EN.md delete mode 100644 leetcode/lcci/01.03.String to URL/Solution.py delete mode 100644 leetcode/lcci/01.04.Palindrome Permutation/README_EN.md delete mode 100644 leetcode/lcci/01.05.One Away/README_EN.md delete mode 100644 leetcode/lcci/01.05.One Away/Solution.py delete mode 100644 leetcode/lcci/01.06.Compress String/README_EN.md delete mode 100644 leetcode/lcci/01.06.Compress String/Solution.py delete mode 100644 leetcode/lcci/01.07.Rotate Matrix/README_EN.md delete mode 100644 leetcode/lcci/01.07.Rotate Matrix/Solution.py delete mode 100644 leetcode/lcci/01.08.Zero Matrix/README_EN.md delete mode 100644 leetcode/lcci/01.08.Zero Matrix/Solution.py delete mode 100644 leetcode/lcci/01.09.String Rotation/README_EN.md delete mode 100644 leetcode/lcci/01.09.String Rotation/Solution.py delete mode 100644 leetcode/lcci/02.01.Remove Duplicate Node/README_EN.md delete mode 100644 leetcode/lcci/02.01.Remove Duplicate Node/Solution.py delete mode 100644 leetcode/lcci/02.02.Kth Node From End of List/README_EN.md delete mode 100644 leetcode/lcci/02.02.Kth Node From End of List/Solution.py delete mode 100644 leetcode/lcci/02.03.Delete Middle Node/README_EN.md delete mode 100644 leetcode/lcci/02.03.Delete Middle Node/Solution.py delete mode 100644 leetcode/lcci/02.04.Partition List/README_EN.md delete mode 100644 leetcode/lcci/02.04.Partition List/Solution.py delete mode 100644 leetcode/lcci/02.05.Sum Lists/README_EN.md delete mode 100644 leetcode/lcci/02.05.Sum Lists/Solution.py delete mode 100644 leetcode/lcci/02.06.Palindrome Linked List/README_EN.md delete mode 100644 leetcode/lcci/02.06.Palindrome Linked List/Solution.py delete mode 100644 leetcode/lcci/02.08.Linked List Cycle/README_EN.md delete mode 100644 leetcode/lcci/02.08.Linked List Cycle/Solution.py delete mode 100644 leetcode/lcci/03.01.Three in One/README_EN.md delete mode 100644 leetcode/lcci/03.01.Three in One/Solution.py delete mode 100644 leetcode/lcci/03.02.Min Stack/README_EN.md delete mode 100644 leetcode/lcci/03.02.Min Stack/Solution.py delete mode 100644 leetcode/lcci/03.04.Implement Queue using Stacks/README_EN.md delete mode 100644 leetcode/lcci/03.04.Implement Queue using Stacks/Solution.py delete mode 100644 leetcode/lcci/03.05.Sort of Stacks/README_EN.md delete mode 100644 leetcode/lcci/03.05.Sort of Stacks/Solution.py delete mode 100644 leetcode/lcci/03.06.Animal Shelter/README_EN.md delete mode 100644 leetcode/lcci/03.06.Animal Shelter/Solution.py delete mode 100644 leetcode/lcci/04.04.Check Balance/README_EN.md delete mode 100644 leetcode/lcci/04.04.Check Balance/Solution.py delete mode 100644 leetcode/lcci/04.05.Legal Binary Search Tree/README_EN.md delete mode 100644 leetcode/lcci/04.05.Legal Binary Search Tree/Solution.py delete mode 100644 leetcode/lcci/04.08.First Common Ancestor/README_EN.md delete mode 100644 leetcode/lcci/04.08.First Common Ancestor/Solution.py delete mode 100644 leetcode/lcci/04.10.Check SubTree/README_EN.md delete mode 100644 leetcode/lcci/04.10.Check SubTree/Solution.py delete mode 100644 leetcode/lcci/04.12.Paths with Sum/README_EN.md delete mode 100644 leetcode/lcci/04.12.Paths with Sum/Solution.py delete mode 100644 leetcode/lcci/05.01.Insert Into Bits/README_EN.md delete mode 100644 leetcode/lcci/05.06.Convert Integer/README_EN.md delete mode 100644 leetcode/lcci/05.07.Exchange/README_EN.md delete mode 100644 leetcode/lcci/08.01.Three Steps Problem/README_EN.md delete mode 100644 leetcode/lcci/08.01.Three Steps Problem/Solution.c delete mode 100644 leetcode/lcci/08.01.Three Steps Problem/Solution.cpp delete mode 100644 leetcode/lcci/08.01.Three Steps Problem/Solution.py delete mode 100644 leetcode/lcci/08.09.Bracket/README_EN.md delete mode 100644 leetcode/lcci/08.09.Bracket/Solution.py delete mode 100644 leetcode/lcci/08.10.Color Fill/README_EN.md delete mode 100644 leetcode/lcci/10.09.Sorted Matrix Search/README_EN.md delete mode 100644 leetcode/lcci/10.09.Sorted Matrix Search/Solution.py delete mode 100644 leetcode/lcci/16.01.Swap Numbers/README_EN.md delete mode 100644 leetcode/lcci/16.01.Swap Numbers/Solution.py delete mode 100644 leetcode/lcci/16.06.Smallest Difference/README_EN.md delete mode 100644 leetcode/lcci/16.06.Smallest Difference/Solution.py delete mode 100644 leetcode/lcci/16.10.Living People/README_EN.md delete mode 100644 leetcode/lcci/16.10.Living People/Solution.py delete mode 100644 leetcode/lcci/16.11.Diving Board/README_EN.md delete mode 100644 leetcode/lcci/16.21.Sum Swap/README_EN.md delete mode 100644 leetcode/lcci/16.21.Sum Swap/Solution.py delete mode 100644 leetcode/lcci/17.01.Add Without Plus/README_EN.md delete mode 100644 leetcode/lcci/17.04.Missing Number/README_EN.md delete mode 100644 leetcode/lcci/17.04.Missing Number/Solution.py delete mode 100644 leetcode/lcci/17.12.BiNode/README_EN.md delete mode 100644 leetcode/lcci/17.12.BiNode/Solution.py delete mode 100644 leetcode/lcci/17.13.Re-Space/README_EN.md delete mode 100644 leetcode/lcci/17.16.The Masseuse/README_EN.md delete mode 100644 leetcode/lcci/17.16.The Masseuse/Solution.py delete mode 100644 leetcode/lcci/17.19.Missing Two/README_EN.md delete mode 100644 leetcode/lcci/17.19.Missing Two/Solution.py delete mode 100644 leetcode/lcci/17.20.Continuous Median/README_EN.md delete mode 100644 leetcode/lcci/17.20.Continuous Median/Solution.py delete mode 100644 leetcode/lcci/README_EN.md delete mode 100644 leetcode/lcof/README_EN.md delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.go" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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\221 II/Solution.go" delete mode 100644 "leetcode/lcof/\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\221 II/Solution.js" delete mode 100644 "leetcode/lcof/\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\221 II/Solution.py" delete mode 100644 "leetcode/lcof/\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\221 III/Solution.go" delete mode 100644 "leetcode/lcof/\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\221 III/Solution.js" delete mode 100644 "leetcode/lcof/\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\221 III/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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\227 I/Solution.js" delete mode 100644 "leetcode/lcof/\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\227 I/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.cpp" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.go" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" delete mode 100644 "leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 "leetcode/lcof/\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/Solution.js" delete mode 100644 "leetcode/lcof/\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/Solution.py" delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.go delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.js delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.py delete mode 100644 leetcode/solution/0000-0099/0001.Two Sum/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.go delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.js delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.py delete mode 100644 leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.go delete mode 100644 leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js delete mode 100644 leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.py delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.go delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js delete mode 100644 leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.py delete mode 100644 leetcode/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.go delete mode 100644 leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js delete mode 100644 leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.py delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.go delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.js delete mode 100644 leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.py delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/Solution.go delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/Solution.js delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/Solution.py delete mode 100644 leetcode/solution/0000-0099/0007.Reverse Integer/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.go delete mode 100644 leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.js delete mode 100644 leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.py delete mode 100644 leetcode/solution/0000-0099/0009.Palindrome Number/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0009.Palindrome Number/Solution.go delete mode 100644 leetcode/solution/0000-0099/0009.Palindrome Number/Solution.js delete mode 100644 leetcode/solution/0000-0099/0009.Palindrome Number/Solution.py delete mode 100644 leetcode/solution/0000-0099/0010.Regular Expression Matching/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.go delete mode 100644 leetcode/solution/0000-0099/0011.Container With Most Water/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0011.Container With Most Water/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0011.Container With Most Water/Solution.go delete mode 100644 leetcode/solution/0000-0099/0011.Container With Most Water/Solution.js delete mode 100644 leetcode/solution/0000-0099/0012.Integer to Roman/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0012.Integer to Roman/Solution.go delete mode 100644 leetcode/solution/0000-0099/0013.Roman to Integer/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0013.Roman to Integer/Solution.go delete mode 100644 leetcode/solution/0000-0099/0013.Roman to Integer/Solution.js delete mode 100644 leetcode/solution/0000-0099/0013.Roman to Integer/Solution.py delete mode 100644 leetcode/solution/0000-0099/0013.Roman to Integer/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.go delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.js delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.py delete mode 100644 leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/Solution.go delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/Solution.py delete mode 100644 leetcode/solution/0000-0099/0015.3Sum/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0016.3Sum Closest/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0016.3Sum Closest/Solution.go delete mode 100644 leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.go delete mode 100644 leetcode/solution/0000-0099/0018.4Sum/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0018.4Sum/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0018.4Sum/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0018.4Sum/Solution.go delete mode 100644 leetcode/solution/0000-0099/0018.4Sum/Solution.py delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.go delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.py delete mode 100644 leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.go delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.js delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.py delete mode 100644 leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.go delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.py delete mode 100644 leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0022.Generate Parentheses/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0022.Generate Parentheses/Solution.go delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.go delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.py delete mode 100644 leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.go delete mode 100644 leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.py delete mode 100644 leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.rb delete mode 100644 leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.go delete mode 100644 leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.go delete mode 100644 leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js delete mode 100644 leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.py delete mode 100644 leetcode/solution/0000-0099/0027.Remove Element/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0027.Remove Element/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0027.Remove Element/Solution.go delete mode 100644 leetcode/solution/0000-0099/0027.Remove Element/Solution.js delete mode 100644 leetcode/solution/0000-0099/0027.Remove Element/Solution.py delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/Solution.go delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/Solution.js delete mode 100644 leetcode/solution/0000-0099/0028.Implement strStr()/Solution.py delete mode 100644 leetcode/solution/0000-0099/0029.Divide Two Integers/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.py delete mode 100644 leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0031.Next Permutation/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0031.Next Permutation/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0031.Next Permutation/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.py delete mode 100644 leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.js delete mode 100644 leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.go delete mode 100644 leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.py delete mode 100644 leetcode/solution/0000-0099/0035.Search Insert Position/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0035.Search Insert Position/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0035.Search Insert Position/Solution.go delete mode 100644 leetcode/solution/0000-0099/0035.Search Insert Position/Solution.js delete mode 100644 leetcode/solution/0000-0099/0035.Search Insert Position/Solution.py delete mode 100644 leetcode/solution/0000-0099/0036.Valid Sudoku/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0036.Valid Sudoku/Solution.js delete mode 100644 leetcode/solution/0000-0099/0037.Sudoku Solver/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0037.Sudoku Solver/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0038.Count and Say/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0038.Count and Say/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0038.Count and Say/Solution.go delete mode 100644 leetcode/solution/0000-0099/0038.Count and Say/Solution.js delete mode 100644 leetcode/solution/0000-0099/0038.Count and Say/Solution.py delete mode 100644 leetcode/solution/0000-0099/0039.Combination Sum/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0039.Combination Sum/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0039.Combination Sum/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0040.Combination Sum II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0040.Combination Sum II/Solution.go delete mode 100644 leetcode/solution/0000-0099/0041.First Missing Positive/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0041.First Missing Positive/Solution.c delete mode 100644 leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0041.First Missing Positive/Solution.py delete mode 100644 leetcode/solution/0000-0099/0042.Trapping Rain Water/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0042.Trapping Rain Water/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0042.Trapping Rain Water/Solution.py delete mode 100644 leetcode/solution/0000-0099/0043.Multiply Strings/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0043.Multiply Strings/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0043.Multiply Strings/Solution.py delete mode 100644 leetcode/solution/0000-0099/0044.Wildcard Matching/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0044.Wildcard Matching/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0045.Jump Game II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0045.Jump Game II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0046.Permutations/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0046.Permutations/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0046.Permutations/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0046.Permutations/Solution.go delete mode 100644 leetcode/solution/0000-0099/0046.Permutations/Solution.py delete mode 100644 leetcode/solution/0000-0099/0047.Permutations II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0047.Permutations II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0047.Permutations II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0047.Permutations II/Solution.py delete mode 100644 leetcode/solution/0000-0099/0048.Rotate Image/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0048.Rotate Image/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0048.Rotate Image/Solution.js delete mode 100644 leetcode/solution/0000-0099/0048.Rotate Image/Solution.py delete mode 100644 leetcode/solution/0000-0099/0049.Group Anagrams/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0049.Group Anagrams/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0050.Pow(x, n)/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.js delete mode 100644 leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.py delete mode 100644 leetcode/solution/0000-0099/0051.N-Queens/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0051.N-Queens/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0052.N-Queens II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0053.Maximum Subarray/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.go delete mode 100644 leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.js delete mode 100644 leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.py delete mode 100644 leetcode/solution/0000-0099/0054.Spiral Matrix/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.py delete mode 100644 leetcode/solution/0000-0099/0055.Jump Game/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0055.Jump Game/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0056.Merge Intervals/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0057.Insert Interval/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0057.Insert Interval/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0057.Insert Interval/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0058.Length of Last Word/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0058.Length of Last Word/Solution.go delete mode 100644 leetcode/solution/0000-0099/0058.Length of Last Word/Solution.js delete mode 100644 leetcode/solution/0000-0099/0058.Length of Last Word/Solution.py delete mode 100644 leetcode/solution/0000-0099/0059.Spiral Matrix II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.py delete mode 100644 leetcode/solution/0000-0099/0060.Permutation Sequence/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0060.Permutation Sequence/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0061.Rotate List/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0061.Rotate List/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0061.Rotate List/Solution.py delete mode 100644 leetcode/solution/0000-0099/0062.Unique Paths/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0062.Unique Paths/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0062.Unique Paths/Solution.go delete mode 100644 leetcode/solution/0000-0099/0062.Unique Paths/Solution.py delete mode 100644 leetcode/solution/0000-0099/0063.Unique Paths II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0063.Unique Paths II/Solution.go delete mode 100644 leetcode/solution/0000-0099/0063.Unique Paths II/Solution.py delete mode 100644 leetcode/solution/0000-0099/0064.Minimum Path Sum/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0064.Minimum Path Sum/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0064.Minimum Path Sum/Solution.go delete mode 100644 leetcode/solution/0000-0099/0065.Valid Number/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0065.Valid Number/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0065.Valid Number/Solution.py delete mode 100644 leetcode/solution/0000-0099/0066.Plus One/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0066.Plus One/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0066.Plus One/Solution.go delete mode 100644 leetcode/solution/0000-0099/0066.Plus One/Solution.js delete mode 100644 leetcode/solution/0000-0099/0066.Plus One/Solution.py delete mode 100644 leetcode/solution/0000-0099/0067.Add Binary/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0067.Add Binary/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0067.Add Binary/Solution.go delete mode 100644 leetcode/solution/0000-0099/0068.Text Justification/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0068.Text Justification/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0069.Sqrt(x)/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.go delete mode 100644 leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.js delete mode 100644 leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.py delete mode 100644 leetcode/solution/0000-0099/0070.Climbing Stairs/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.go delete mode 100644 leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.js delete mode 100644 leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.py delete mode 100644 leetcode/solution/0000-0099/0071.Simplify Path/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0071.Simplify Path/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0072.Edit Distance/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.py delete mode 100644 leetcode/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0074.Search a 2D Matrix/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0074.Search a 2D Matrix/Solution.py delete mode 100644 leetcode/solution/0000-0099/0075.Sort Colors/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0075.Sort Colors/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0075.Sort Colors/Solution.go delete mode 100644 leetcode/solution/0000-0099/0075.Sort Colors/Solution.py delete mode 100644 leetcode/solution/0000-0099/0076.Minimum Window Substring/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0076.Minimum Window Substring/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0077.Combinations/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0078.Subsets/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0078.Subsets/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0078.Subsets/Solution.go delete mode 100644 leetcode/solution/0000-0099/0079.Word Search/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0079.Word Search/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0079.Word Search/Solution.py delete mode 100644 leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.py delete mode 100644 leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.go delete mode 100644 leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js delete mode 100644 leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.py delete mode 100644 leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0085.Maximal Rectangle/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0085.Maximal Rectangle/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0086.Partition List/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0086.Partition List/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0086.Partition List/Solution.py delete mode 100644 leetcode/solution/0000-0099/0087.Scramble String/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0087.Scramble String/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0088.Merge Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.go delete mode 100644 leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.js delete mode 100644 leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.py delete mode 100644 leetcode/solution/0000-0099/0089.Gray Code/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0089.Gray Code/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0090.Subsets II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0090.Subsets II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0091.Decode Ways/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0091.Decode Ways/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0092.Reverse Linked List II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.py delete mode 100644 leetcode/solution/0000-0099/0093.Restore IP Addresses/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.py delete mode 100644 leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.go delete mode 100644 leetcode/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0096.Unique Binary Search Trees/Solution.py delete mode 100644 leetcode/solution/0000-0099/0097.Interleaving String/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0097.Interleaving String/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0097.Interleaving String/Solution.go delete mode 100644 leetcode/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cpp delete mode 100644 leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cs delete mode 100644 leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js delete mode 100644 leetcode/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0000-0099/0099.Recover Binary Search Tree/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0100.Same Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0100.Same Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0100.Same Tree/Solution.go delete mode 100644 leetcode/solution/0100-0199/0100.Same Tree/Solution.py delete mode 100644 leetcode/solution/0100-0199/0101.Symmetric Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.js delete mode 100644 leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.py delete mode 100644 leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js delete mode 100644 leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.py delete mode 100644 leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.py delete mode 100644 leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js delete mode 100644 leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.py delete mode 100644 leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.py delete mode 100644 leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.py delete mode 100644 leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js delete mode 100644 leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.py delete mode 100644 leetcode/solution/0100-0199/0112.Path Sum/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0112.Path Sum/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0112.Path Sum/Solution.py delete mode 100644 leetcode/solution/0100-0199/0113.Path Sum II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0113.Path Sum II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0113.Path Sum II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0115.Distinct Subsequences/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0115.Distinct Subsequences/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.go delete mode 100644 leetcode/solution/0100-0199/0118.Pascal's Triangle/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.js delete mode 100644 leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.py delete mode 100644 leetcode/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0119.Pascal's Triangle II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0120.Triangle/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0120.Triangle/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js delete mode 100644 leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.py delete mode 100644 leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js delete mode 100644 leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.py delete mode 100644 leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.go delete mode 100644 leetcode/solution/0100-0199/0125.Valid Palindrome/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.js delete mode 100644 leetcode/solution/0100-0199/0126.Word Ladder II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0127.Word Ladder/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0127.Word Ladder/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0127.Word Ladder/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.go delete mode 100644 leetcode/solution/0100-0199/0130.Surrounded Regions/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0131.Palindrome Partitioning/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0132.Palindrome Partitioning II/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0133.Clone Graph/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0133.Clone Graph/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0134.Gas Station/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0134.Gas Station/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0135.Candy/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0135.Candy/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0136.Single Number/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0136.Single Number/Solution.go delete mode 100644 leetcode/solution/0100-0199/0136.Single Number/Solution.js delete mode 100644 leetcode/solution/0100-0199/0136.Single Number/Solution.py delete mode 100644 leetcode/solution/0100-0199/0137.Single Number II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0137.Single Number II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0138.Copy List with Random Pointer/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0139.Word Break/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0139.Word Break/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0140.Word Break II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0140.Word Break II/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0141.Linked List Cycle/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.go delete mode 100644 leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.js delete mode 100644 leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.py delete mode 100644 leetcode/solution/0100-0199/0142.Linked List Cycle II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0143.Reorder List/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0143.Reorder List/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0143.Reorder List/Solution.go delete mode 100644 leetcode/solution/0100-0199/0143.Reorder List/Solution.py delete mode 100644 leetcode/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0146.Lru Cache/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0146.Lru Cache/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0146.Lru Cache/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0146.Lru Cache/Solution.go delete mode 100644 leetcode/solution/0100-0199/0147.Insertion Sort List/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0147.Insertion Sort List/Solution.py delete mode 100644 leetcode/solution/0100-0199/0148.Sort List/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0148.Sort List/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0148.Sort List/Solution.py delete mode 100644 leetcode/solution/0100-0199/0149.Max Points on a Line/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0149.Max Points on a Line/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.py delete mode 100644 leetcode/solution/0100-0199/0151.Reverse Words in a String/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0151.Reverse Words in a String/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.py delete mode 100644 leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.go delete mode 100644 leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.py delete mode 100644 leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/Solution.py delete mode 100644 leetcode/solution/0100-0199/0155.Min Stack/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0155.Min Stack/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0155.Min Stack/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0155.Min Stack/Solution.js delete mode 100644 leetcode/solution/0100-0199/0155.Min Stack/Solution.py delete mode 100644 leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js delete mode 100644 leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.py delete mode 100644 leetcode/solution/0100-0199/0162.Find Peak Element/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0164.Maximum Gap/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0164.Maximum Gap/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0165.Compare Version Numbers/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0165.Compare Version Numbers/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0168.Excel Sheet Column Title/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0169.Majority Element/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0169.Majority Element/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0174.Dungeon Game/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0174.Dungeon Game/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0179.Largest Number/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0179.Largest Number/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0187.Repeated DNA Sequences/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.py delete mode 100644 leetcode/solution/0100-0199/0189.Rotate Array/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0189.Rotate Array/Solution.cs delete mode 100644 leetcode/solution/0100-0199/0189.Rotate Array/Solution.py delete mode 100644 leetcode/solution/0100-0199/0190.Reverse Bits/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0190.Reverse Bits/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0190.Reverse Bits/Solution.js delete mode 100644 leetcode/solution/0100-0199/0190.Reverse Bits/Solution.py delete mode 100644 leetcode/solution/0100-0199/0191.Number of 1 Bits/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.js delete mode 100644 leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.py delete mode 100644 leetcode/solution/0100-0199/0198.House Robber/README_EN.md delete mode 100644 leetcode/solution/0100-0199/0198.House Robber/Solution.cpp delete mode 100644 leetcode/solution/0100-0199/0198.House Robber/Solution.go delete mode 100644 leetcode/solution/0100-0199/0198.House Robber/Solution.py delete mode 100644 leetcode/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0200.Number of Islands/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0200.Number of Islands/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0200.Number of Islands/Solution.py delete mode 100644 leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0202.Happy Number/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0202.Happy Number/Solution.py delete mode 100644 leetcode/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.py delete mode 100644 leetcode/solution/0200-0299/0204.Count Primes/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0204.Count Primes/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0204.Count Primes/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0204.Count Primes/Solution.js delete mode 100644 leetcode/solution/0200-0299/0204.Count Primes/Solution.py delete mode 100644 leetcode/solution/0200-0299/0205.Isomorphic Strings/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.py delete mode 100644 leetcode/solution/0200-0299/0206.Reverse Linked List/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.go delete mode 100644 leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.js delete mode 100644 leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.py delete mode 100644 leetcode/solution/0200-0299/0207.Course Schedule/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0207.Course Schedule/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0210.Course Schedule II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0210.Course Schedule II/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0213.House Robber II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0213.House Robber II/Solution.go delete mode 100644 leetcode/solution/0200-0299/0213.House Robber II/Solution.py delete mode 100644 leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.go delete mode 100644 leetcode/solution/0200-0299/0216.Combination Sum III/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0216.Combination Sum III/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0217.Contains Duplicate/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.js delete mode 100644 leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.py delete mode 100644 leetcode/solution/0200-0299/0219.Contains Duplicate II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.py delete mode 100644 leetcode/solution/0200-0299/0220.Contains Duplicate III/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0220.Contains Duplicate III/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0221.Maximal Square/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0221.Maximal Square/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0223.Rectangle Area/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0223.Rectangle Area/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0224.Basic Calculator/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0224.Basic Calculator/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0225.Implement Stack using Queues/Solution.py delete mode 100644 leetcode/solution/0200-0299/0226.Invert Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.go delete mode 100644 leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.js delete mode 100644 leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.py delete mode 100644 leetcode/solution/0200-0299/0227.Basic Calculator II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0227.Basic Calculator II/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0228.Summary Ranges/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0228.Summary Ranges/Solution.py delete mode 100644 leetcode/solution/0200-0299/0229.Majority Element II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0229.Majority Element II/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0231.Power of Two/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0231.Power of Two/Solution.py delete mode 100644 leetcode/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0232.Implement Queue using Stacks/Solution.py delete mode 100644 leetcode/solution/0200-0299/0233.Number of Digit One/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0233.Number of Digit One/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0234.Palindrome Linked List/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.js delete mode 100644 leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.py delete mode 100644 leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.go delete mode 100644 leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.py delete mode 100644 leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.js delete mode 100644 leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.py delete mode 100644 leetcode/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.js delete mode 100644 leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.py delete mode 100644 leetcode/solution/0200-0299/0238.Product of Array Except Self/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.js delete mode 100644 leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.py delete mode 100644 leetcode/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0239.Sliding Window Maximum/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.go delete mode 100644 leetcode/solution/0200-0299/0242.Valid Anagram/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0242.Valid Anagram/Solution.js delete mode 100644 leetcode/solution/0200-0299/0243.Shortest Word Distance/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0246.Strobogrammatic Number/Solution.py delete mode 100644 leetcode/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0252.Meeting Rooms/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0252.Meeting Rooms/Solution.py delete mode 100644 leetcode/solution/0200-0299/0257.Binary Tree Paths/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0257.Binary Tree Paths/Solution.py delete mode 100644 leetcode/solution/0200-0299/0258.Add Digits/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0258.Add Digits/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0258.Add Digits/Solution.py delete mode 100644 leetcode/solution/0200-0299/0260.Single Number III/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0260.Single Number III/Solution.py delete mode 100644 leetcode/solution/0200-0299/0263.Ugly Number/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0264.Ugly Number II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0266.Palindrome Permutation/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0266.Palindrome Permutation/Solution.py delete mode 100644 leetcode/solution/0200-0299/0268.Missing Number/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0268.Missing Number/Solution.js delete mode 100644 leetcode/solution/0200-0299/0273.Integer to English Words/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0273.Integer to English Words/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0274.H-Index/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0275.H-Index II/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0278.First Bad Version/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0278.First Bad Version/Solution.js delete mode 100644 leetcode/solution/0200-0299/0278.First Bad Version/Solution.py delete mode 100644 leetcode/solution/0200-0299/0279.Perfect Squares/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0279.Perfect Squares/Solution.go delete mode 100644 leetcode/solution/0200-0299/0283.Move Zeroes/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0283.Move Zeroes/Solution.cpp delete mode 100644 leetcode/solution/0200-0299/0283.Move Zeroes/Solution.js delete mode 100644 leetcode/solution/0200-0299/0283.Move Zeroes/Solution.py delete mode 100644 leetcode/solution/0200-0299/0284.Peeking Iterator/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0289.Game of Life/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0290.Word Pattern/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0290.Word Pattern/Solution.py delete mode 100644 leetcode/solution/0200-0299/0292.Nim Game/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0293.Flip Game/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0293.Flip Game/Solution.py delete mode 100644 leetcode/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0295.Find Median from Data Stream/Solution.cs delete mode 100644 leetcode/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0200-0299/0299.Bulls and Cows/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.cpp delete mode 100644 leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.py delete mode 100644 leetcode/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0306.Additive Number/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/Solution.cs delete mode 100644 leetcode/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0312.Burst Balloons/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0319.Bulb Switcher/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0322.Coin Change/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0322.Coin Change/Solution.js delete mode 100644 leetcode/solution/0300-0399/0328.Odd Even Linked List/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0328.Odd Even Linked List/Solution.py delete mode 100644 leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/Solution.cpp delete mode 100644 leetcode/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0337.House Robber III/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0342.Power of Four/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0342.Power of Four/Solution.js delete mode 100644 leetcode/solution/0300-0399/0343.Integer Break/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0344.Reverse String/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0344.Reverse String/Solution.js delete mode 100644 leetcode/solution/0300-0399/0344.Reverse String/Solution.py delete mode 100644 leetcode/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0345.Reverse Vowels of a String/Solution.py delete mode 100644 leetcode/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0349.Intersection of Two Arrays/Solution.py delete mode 100644 leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/Solution.js delete mode 100644 leetcode/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0354.Russian Doll Envelopes/Solution.py delete mode 100644 leetcode/solution/0300-0399/0355.Design Twitter/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0367.Valid Perfect Square/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0371.Sum of Two Integers/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0377.Combination Sum IV/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0383.Ransom Note/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0383.Ransom Note/Solution.py delete mode 100644 leetcode/solution/0300-0399/0384.Shuffle an Array/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0384.Shuffle an Array/Solution.js delete mode 100644 leetcode/solution/0300-0399/0387.First Unique Character in a String/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.cpp delete mode 100644 leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.js delete mode 100644 leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.py delete mode 100644 leetcode/solution/0300-0399/0392.Is Subsequence/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0392.Is Subsequence/Solution.py delete mode 100644 leetcode/solution/0300-0399/0394.Decode String/README_EN.md delete mode 100644 leetcode/solution/0300-0399/0394.Decode String/Solution.py delete mode 100644 leetcode/solution/0300-0399/0397.Integer Replacement/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0400.Nth Digit/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0401.Binary Watch/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0402.Remove K Digits/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0409.Longest Palindrome/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0409.Longest Palindrome/Solution.py delete mode 100644 leetcode/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0414.Third Maximum Number/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0415.Add Strings/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/Solution.py delete mode 100644 leetcode/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.js delete mode 100644 leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.py delete mode 100644 leetcode/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0437.Path Sum III/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0441.Arranging Coins/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0441.Arranging Coins/Solution.py delete mode 100644 leetcode/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0445.Add Two Numbers II/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.cpp delete mode 100644 leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.py delete mode 100644 leetcode/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0450.Delete Node in a BST/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0454.4Sum II/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0456.132 Pattern/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0458.Poor Pigs/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0461.Hamming Distance/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0461.Hamming Distance/Solution.js delete mode 100644 leetcode/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0473.Matchsticks to Square/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0475.Heaters/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0477.Total Hamming Distance/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0483.Smallest Good Base/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.js delete mode 100644 leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.py delete mode 100644 leetcode/solution/0400-0499/0486.Predict the Winner/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0487.Max Consecutive Ones II/Solution.py delete mode 100644 leetcode/solution/0400-0499/0490.The Maze/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0490.The Maze/Solution.py delete mode 100644 leetcode/solution/0400-0499/0492.Construct the Rectangle/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0492.Construct the Rectangle/Solution.py delete mode 100644 leetcode/solution/0400-0499/0494.Target Sum/README_EN.md delete mode 100644 leetcode/solution/0400-0499/0496.Next Greater Element I/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0500.Keyboard Row/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0500.Keyboard Row/Solution.py delete mode 100644 leetcode/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0502.IPO/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0503.Next Greater Element II/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0504.Base 7/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0506.Relative Ranks/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0507.Perfect Number/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0509.Fibonacci Number/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.cpp delete mode 100644 leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.js delete mode 100644 leetcode/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0518.Coin Change 2/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0520.Detect Capital/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/Solution.py delete mode 100644 leetcode/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0525.Contiguous Array/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.go delete mode 100644 leetcode/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0541.Reverse String II/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0542.01 Matrix/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0554.Brick Wall/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0554.Brick Wall/Solution.py delete mode 100644 leetcode/solution/0500-0599/0556.Next Greater Element III/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0561.Array Partition I/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0561.Array Partition I/Solution.js delete mode 100644 leetcode/solution/0500-0599/0561.Array Partition I/Solution.py delete mode 100644 leetcode/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0566.Reshape the Matrix/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0566.Reshape the Matrix/Solution.py delete mode 100644 leetcode/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0572.Subtree of Another Tree/Solution.cpp delete mode 100644 leetcode/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/Solution.cpp delete mode 100644 leetcode/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0605.Can Place Flowers/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.cpp delete mode 100644 leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.py delete mode 100644 leetcode/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0611.Valid Triangle Number/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0617.Merge Two Binary Trees/Solution.go delete mode 100644 leetcode/solution/0600-0699/0622.Design Circular Queue/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0645.Set Mismatch/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0645.Set Mismatch/Solution.py delete mode 100644 leetcode/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0664.Strange Printer/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.py delete mode 100644 leetcode/solution/0600-0699/0679.24 Game/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0682.Baseball Game/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0682.Baseball Game/Solution.py delete mode 100644 leetcode/solution/0600-0699/0684.Redundant Connection/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0687.Longest Univalue Path/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0690.Employee Importance/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0695.Max Area of Island/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0695.Max Area of Island/Solution.cpp delete mode 100644 leetcode/solution/0600-0699/0696.Count Binary Substrings/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0697.Degree of an Array/README_EN.md delete mode 100644 leetcode/solution/0600-0699/0697.Degree of an Array/Solution.py delete mode 100644 leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.cpp delete mode 100644 leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.py delete mode 100644 leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/Solution.py delete mode 100644 leetcode/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0704.Binary Search/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0704.Binary Search/Solution.py delete mode 100644 leetcode/solution/0700-0799/0707.Design Linked List/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0707.Design Linked List/Solution.py delete mode 100644 leetcode/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0724.Find Pivot Index/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0739.Daily Temperatures/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0739.Daily Temperatures/Solution.py delete mode 100644 leetcode/solution/0700-0799/0740.Delete and Earn/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.py delete mode 100644 leetcode/solution/0700-0799/0752.Open the Lock/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0760.Find Anagram Mappings/Solution.py delete mode 100644 leetcode/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0766.Toeplitz Matrix/Solution.py delete mode 100644 leetcode/solution/0700-0799/0771.Jewels and Stones/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.cpp delete mode 100644 leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.py delete mode 100644 leetcode/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md delete mode 100644 leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.go delete mode 100644 leetcode/solution/0700-0799/0784.Letter Case Permutation/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0817.Linked List Components/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0817.Linked List Components/Solution.py delete mode 100644 leetcode/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0832.Flipping an Image/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0832.Flipping an Image/Solution.cpp delete mode 100644 leetcode/solution/0800-0899/0832.Flipping an Image/Solution.js delete mode 100644 leetcode/solution/0800-0899/0832.Flipping an Image/Solution.py delete mode 100644 leetcode/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0856.Score of Parentheses/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0860.Lemonade Change/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0872.Leaf-Similar Trees/Solution.py delete mode 100644 leetcode/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0876.Middle of the Linked List/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0876.Middle of the Linked List/Solution.py delete mode 100644 leetcode/solution/0800-0899/0878.Nth Magical Number/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0887.Super Egg Drop/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0887.Super Egg Drop/Solution.py delete mode 100644 leetcode/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md delete mode 100644 leetcode/solution/0800-0899/0897.Increasing Order Search Tree/Solution.py delete mode 100644 leetcode/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0912.Sort an Array/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0922.Sort Array By Parity II/Solution.js delete mode 100644 leetcode/solution/0900-0999/0929.Unique Email Addresses/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.js delete mode 100644 leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.py delete mode 100644 leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/Solution.js delete mode 100644 leetcode/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0933.Number of Recent Calls/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0933.Number of Recent Calls/Solution.py delete mode 100644 leetcode/solution/0900-0999/0938.Range Sum of BST/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.cpp delete mode 100644 leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.py delete mode 100644 leetcode/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.cpp delete mode 100644 leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.js delete mode 100644 leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.py delete mode 100644 leetcode/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.cpp delete mode 100644 leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.js delete mode 100644 leetcode/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0999.Available Captures for Rook/README_EN.md delete mode 100644 leetcode/solution/0900-0999/0999.Available Captures for Rook/Solution.py delete mode 100644 leetcode/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.py delete mode 100644 leetcode/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1012.Complement of Base 10 Integer/Solution.py delete mode 100644 leetcode/solution/1000-1099/1017.Convert to Base -2/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1025.Divisor Game/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1025.Divisor Game/Solution.cpp delete mode 100644 leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/Solution.cpp delete mode 100644 leetcode/solution/1000-1099/1029.Two City Scheduling/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1034.Coloring A Border/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1036.Escape a Large Maze/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1037.Valid Boomerang/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1046.Last Stone Weight/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1048.Longest String Chain/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1051.Height Checker/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/Solution.py delete mode 100644 leetcode/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1054.Distant Barcodes/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1089.Duplicate Zeros/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1090.Largest Values From Labels/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1094.Car Pooling/README_EN.md delete mode 100644 leetcode/solution/1000-1099/1095.Find in Mountain Array/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1103.Distribute Candies to People/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1108.Defanging an IP Address/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/Solution.py delete mode 100644 leetcode/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1114.Print in Order/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1114.Print in Order/Solution.cpp delete mode 100644 leetcode/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1115.Print FooBar Alternately/Solution.cpp delete mode 100644 leetcode/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1116.Print Zero Even Odd/Solution.cpp delete mode 100644 leetcode/solution/1100-1199/1117.Building H2O/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1117.Building H2O/Solution.cpp delete mode 100644 leetcode/solution/1100-1199/1122.Relative Sort Array/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1138.Alphabet Board Path/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1140.Stone Game II/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1185.Day of the Week/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md delete mode 100644 leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/Solution.cpp delete mode 100644 leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md delete mode 100644 leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.js delete mode 100644 leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.py delete mode 100644 leetcode/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md delete mode 100644 leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md delete mode 100644 leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/Solution.py delete mode 100644 leetcode/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md delete mode 100644 leetcode/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md delete mode 100644 leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md delete mode 100644 leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/Solution.py delete mode 100644 leetcode/solution/1400-1499/1476.Subrectangle Queries/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1537.Get the Maximum Score/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1544.Make The String Great/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.go delete mode 100644 leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.py delete mode 100644 leetcode/solution/1500-1599/1578.Minimum Deletion Cost to Avoid Repeating Letters/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md delete mode 100644 leetcode/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md delete mode 100644 leetcode/solution/README_EN.md create mode 100644 notes/src/main/java/org/example/Main.java diff --git a/.gitignore b/.gitignore index 8d7dcfba..aaa1466d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ out/ # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # should NOT be excluded as they contain compiler settings and other important # information for Eclipse / Flash Builder. +/notes/target/ diff --git a/leetcode/README_EN.md b/leetcode/README_EN.md deleted file mode 100644 index c2aac0cc..00000000 --- a/leetcode/README_EN.md +++ /dev/null @@ -1,190 +0,0 @@ -

- LeetCode-GitHub-Doocs -

- -

- languages - - - LICENSE
- stars - forks - github - github - PRs Welcome - open-source-organization -

- -## Introduction - -Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF](https://leetcode-cn.com/problemset/lcof/) and [LCCI](https://leetcode-cn.com/problemset/lcci/) problems, updated daily. - -[中文文档](/README.md) - -## Sites - -- Netlify: https://lc.netlify.app -- Gitee Pages: https://doocs.gitee.io/leetcode -- GitHub Pages: https://doocs.github.io/leetcode - -## Solutions - -- [LeetCode](/solution/README_EN.md) -- [LCOF: _Coding Interviews, 2nd Edition_](/lcof/README_EN.md) -- [LCCI: _Cracking the Coding Interview, 6th Edition_](/lcci/README_EN.md) - -## Basic Algorithms - -### Sorting - -- [Bubble Sort](/basic/sorting/BubbleSort/README.md) -- [Insertion Sort](/basic/sorting/InsertionSort/README.md) -- [Selection Sort](/basic/sorting/SelectionSort/README.md) -- [Merge Sort](/basic/sorting/MergeSort/README.md) -- [Quick Sort](/basic/sorting/QuickSort/README.md) - -### Searching - -- [Binary Search](/basic/searching/BinarySearch/README.md) -- [Binary Search II](/basic/searching/BinarySearch-II/README.md) - -## High Frequency Interview Questions - -### Arrays - -- [Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md) -- [Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md) -- [Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md) -- [Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md) -- [Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md) -- [Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md) -- [3Sum](/solution/0000-0099/0015.3Sum/README_EN.md) -- [4Sum](/solution/0000-0099/0018.4Sum/README_EN.md) -- [Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md) -- [Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) -- [Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) -- [Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md) - -### Strings - -- [Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md) -- [String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md) -- [Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md) - -### Linked List - -- [Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) -- [Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md) -- [Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md) -- [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) -- [Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) -- [Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) -- [Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) -- [Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) -- [Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md) -- [Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md) -- [Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) -- [Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md) -- [Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md) -- [Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md) -- [Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) -- [Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md) -- [Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) -- [Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) -- [Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md) - -### Binary Tree - -- [Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) -- [Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md) -- [Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md) -- [Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) -- [Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md) -- [Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) -- [Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md) -- [Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md) -- [Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md) -- [Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) -- [Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) -- [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md) -- [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md) -- [BiNode](/lcci/17.12.BiNode/README_EN.md) -- [Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md) - -### Math - -- [Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md) -- [Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) -- [Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md) -- [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md) -- [Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md) -- [Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md) - -### Stack & Queue - -- [Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) -- [Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md) -- [Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md) -- [Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md) -- [Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) -- [Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md) -- [Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md) - -### Dynamic Programming - -- [Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md) -- [Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) -- [House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md) -- [House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md) -- [Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md) -- [Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md) - -### Misc - -- [Combine Two Tables](/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md) -- [Second Highest Salary](/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md) -- [Nth Highest Salary](/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md) -- [Rank Scores](/solution/0100-0199/0178.Rank%20Scores/README_EN.md) - -## Maintainer - -[Yang Libin](https://github.com/yanglbme): Creator of [@Doocs](https://github.com/doocs) technical community; member of [@TheAlgorithms](https://github.com/TheAlgorithms) organization. - -## Contributions - -I'm looking for long-term contributors/partners to this repo! Send me [PRs](https://github.com/doocs/leetcode/pulls) if you're interested! See the following: - -1. Fork [this repository](https://github.com/doocs/leetcode) to your own GitHub account and then clone it to your local machine. -1. Make some changes to your leetcode repository, then add, commit and push the changes to your remote GitHub repository. -1. Submit a pull request with your changes! -1. See [CONTRIBUTING](https://github.com/doocs/.github/blob/main/CONTRIBUTING.md) or [GitHub Help](https://help.github.com/en) for more details. - -

- how-to-contribute -

- -You can also contribute to [doocs/leetcode](https://github.com/doocs/leetcode) using [Gitpod.io](https://www.gitpod.io), a free online dev environment with a single click. - -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/doocs/leetcode) - -## Contributors - -This project exists thanks to all the people who contribute. - - - -## Backers & Sponsors - -Thank you to all our backers and sponsors! - - - - - -> "_You help the developer community practice for interviews, and there is nothing better we could ask for._" -- [Alan Yessenbayev](https://opencollective.com/alan-yessenbayev) - -## License - -This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. - -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdoocs%2Fleetcode.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdoocs%2Fleetcode?ref=badge_large) diff --git a/leetcode/basic/README_EN.md b/leetcode/basic/README_EN.md deleted file mode 100644 index 8889d6a5..00000000 --- a/leetcode/basic/README_EN.md +++ /dev/null @@ -1,14 +0,0 @@ -# Basic Algorithms - -## Sorting - -- [Bubble Sort](./sorting/BubbleSort/README.md) -- [Insertion Sort](./sorting/InsertionSort/README.md) -- [Selection Sort](./sorting/SelectionSort/README.md) -- [Merge Sort](./sorting/MergeSort/README.md) -- [Quick Sort](./sorting/QuickSort/README.md) - -## Searching - -- [Binary Search](./searching/BinarySearch/README.md) -- [Binary Search II](./searching/BinarySearch-II/README.md) diff --git a/leetcode/lcci/01.01.Is Unique/README_EN.md b/leetcode/lcci/01.01.Is Unique/README_EN.md deleted file mode 100644 index 23ad69d0..00000000 --- a/leetcode/lcci/01.01.Is Unique/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [01.01. Is Unique](https://leetcode-cn.com/problems/is-unique-lcci) - -[中文文档](/lcci/01.01.Is%20Unique/README.md) - -## Description - -

Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

- -

Example 1:

- -
-
-Input: s = "leetcode"
-
-Output: false
-
-
- -

Example 2:

- -
-
-Input: s = "abc"
-
-Output: true
-
-
- -

Note:

- -
    -
  • 0 <= len(s) <= 100
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isUnique(self, astr: str) -> bool: - sets = set(astr) - return len(sets) == len(astr) -``` - -### **Java** - -```java -class Solution { - public boolean isUnique(String astr) { - char[] chars = astr.toCharArray(); - int len = chars.length; - for (int i = 0; i < len - 1; ++i) { - for (int j = i + 1; j < len; ++j) { - if (chars[i] == chars[j]) { - return false; - } - } - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.01.Is Unique/Solution.py b/leetcode/lcci/01.01.Is Unique/Solution.py deleted file mode 100644 index 9277e91b..00000000 --- a/leetcode/lcci/01.01.Is Unique/Solution.py +++ /dev/null @@ -1,4 +0,0 @@ -class Solution: - def isUnique(self, astr: str) -> bool: - sets = set(astr) - return len(sets) == len(astr) \ No newline at end of file diff --git a/leetcode/lcci/01.02.Check Permutation/README_EN.md b/leetcode/lcci/01.02.Check Permutation/README_EN.md deleted file mode 100644 index b02a0a73..00000000 --- a/leetcode/lcci/01.02.Check Permutation/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [01.02. Check Permutation](https://leetcode-cn.com/problems/check-permutation-lcci) - -[中文文档](/lcci/01.02.Check%20Permutation/README.md) - -## Description - -

Given two strings,write a method to decide if one is a permutation of the other.

- -

Example 1:

- -
-
-Input: s1 = "abc", s2 = "bca"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: s1 = "abc", s2 = "bad"
-
-Output: false
-
-
- -

Note:

-
    -
  1. 0 <= len(s1) <= 100
  2. -
  3. 0 <= len(s2) <= 100
  4. -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def CheckPermutation(self, s1: str, s2: str) -> bool: - return sorted(s1) == sorted(s2) -``` - -### **Java** - -```java -class Solution { - public boolean CheckPermutation(String s1, String s2) { - if (s1 == null || s2 == null || s1.length() != s2.length()) { - return false; - } - char[] c1 = s1.toCharArray(); - char[] c2 = s2.toCharArray(); - Arrays.sort(c1); - Arrays.sort(c2); - return Arrays.equals(c1, c2); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.02.Check Permutation/Solution.py b/leetcode/lcci/01.02.Check Permutation/Solution.py deleted file mode 100644 index 7696c7a1..00000000 --- a/leetcode/lcci/01.02.Check Permutation/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def CheckPermutation(self, s1: str, s2: str) -> bool: - return sorted(s1) == sorted(s2) \ No newline at end of file diff --git a/leetcode/lcci/01.03.String to URL/README_EN.md b/leetcode/lcci/01.03.String to URL/README_EN.md deleted file mode 100644 index b5fb2000..00000000 --- a/leetcode/lcci/01.03.String to URL/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [01.03. String to URL](https://leetcode-cn.com/problems/string-to-url-lcci) - -[中文文档](/lcci/01.03.String%20to%20URL/README.md) - -## Description - -

Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)

- -

Example 1:

- -
-
-Input: "Mr John Smith ", 13
-
-Output: "Mr%20John%20Smith"
-
-Explanation: 
-
-The missing numbers are [5,6,8,...], hence the third missing number is 8.
-
-
- -

Example 2:

- -
-
-Input: "               ", 5
-
-Output: "%20%20%20%20%20"
-
-
- -

 

- -

Note:

- -
    -
  1. 0 <= S.length <= 500000
  2. -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def replaceSpaces(self, S: str, length: int) -> str: - S = S[:length] if length < len(S) else S - return S.replace(' ', '%20') -``` - -### **Java** - -```java -class Solution { - public String replaceSpaces(String S, int length) { - char[] c = S.toCharArray(); - int j = c.length; - for (int i = length - 1; i >= 0; i--) { - if (c[i] == ' ') { - c[--j] = '0'; - c[--j] = '2'; - c[--j] = '%'; - } else { - c[--j] = c[i]; - } - } - return new String(c, j, c.length - j); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.03.String to URL/Solution.py b/leetcode/lcci/01.03.String to URL/Solution.py deleted file mode 100644 index 849b77e6..00000000 --- a/leetcode/lcci/01.03.String to URL/Solution.py +++ /dev/null @@ -1,4 +0,0 @@ -class Solution: - def replaceSpaces(self, S: str, length: int) -> str: - S = S[:length] if length < len(S) else S - return S.replace(' ', '%20') \ No newline at end of file diff --git a/leetcode/lcci/01.04.Palindrome Permutation/README_EN.md b/leetcode/lcci/01.04.Palindrome Permutation/README_EN.md deleted file mode 100644 index f1d8489c..00000000 --- a/leetcode/lcci/01.04.Palindrome Permutation/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [01.04. Palindrome Permutation](https://leetcode-cn.com/problems/palindrome-permutation-lcci) - -[中文文档](/lcci/01.04.Palindrome%20Permutation/README.md) - -## Description - -

Given a string, write a function to check if it is a permutation of a palin­ drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.

- -

 

- -

Example1:

- -
-
-Input: "tactcoa"
-
-Output: true(permutations: "tacocat"、"atcocta", etc.)
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def canPermutePalindrome(self, s: str) -> bool: - if s is None or len(s) < 2: - return True - cache = {} - for ch in s: - cache[ch] = 1 if cache.get(ch) is None else cache[ch] + 1 - cnt = 0 - for k, v in cache.items(): - if (v & 1) == 1: - cnt += 1 - if cnt > 1: - return False - return cnt <= 1 -``` - -### **Java** - -```java -class Solution { - public boolean canPermutePalindrome(String s) { - if (s == null || s.length() < 2) { - return true; - } - char[] chars = s.toCharArray(); - Map counter = new HashMap<>(); - for (char ch : chars) { - counter.put(ch, counter.get(ch) == null ? 1 : counter.get(ch) + 1); - } - int cnt = 0; - for (Map.Entry entry : counter.entrySet()) { - if ((entry.getValue() & 1) == 1) { - ++cnt; - } - if (cnt > 1) { - return false; - } - } - return cnt <= 1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.05.One Away/README_EN.md b/leetcode/lcci/01.05.One Away/README_EN.md deleted file mode 100644 index 719353de..00000000 --- a/leetcode/lcci/01.05.One Away/README_EN.md +++ /dev/null @@ -1,92 +0,0 @@ -# [01.05. One Away](https://leetcode-cn.com/problems/one-away-lcci) - -[中文文档](/lcci/01.05.One%20Away/README.md) - -## Description - -

There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edit (or zero edits) away.

- -

Example 1:

- -
-
-Input: 
-
-first = "pale"
-
-second = "ple"
-
-Output: True
-
-
- -

Example 2:

- -
-
-Input: 
-
-first = "pales"
-
-second = "pal"
-
-Output: False
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def oneEditAway(self, first: str, second: str) -> bool: - n1, n2 = len(first), len(second) - if abs(n1 - n2) > 1: - return False - if n1 + n2 <= 2: - return True - if first[0] != second[0]: - if n1 == n2: - return first[1:] == second[1:] - else: - return first[1:] == second or second[1:] == first - else: - return self.oneEditAway(first[1:], second[1:]) -``` - -### **Java** - -```java -class Solution { - public boolean oneEditAway(String first, String second) { - int n1 = first.length(), n2 = second.length(); - int differ = Math.abs(n1 - n2); - if (differ > 1) { - return false; - } - if (n1 + n2 <= 2) { - return true; - } - if (first.charAt(0) != second.charAt(0)) { - if (n1 == n2) { - return first.substring(1).equals(second.substring(1)); - } else { - return first.substring(1).equals(second) || second.substring(1).equals(first); - } - } else { - return oneEditAway(first.substring(1), second.substring(1)); - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.05.One Away/Solution.py b/leetcode/lcci/01.05.One Away/Solution.py deleted file mode 100644 index b801678b..00000000 --- a/leetcode/lcci/01.05.One Away/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def oneEditAway(self, first: str, second: str) -> bool: - n1, n2 = len(first), len(second) - if abs(n1 - n2) > 1: - return False - if n1 + n2 <= 2: - return True - if first[0] != second[0]: - if n1 == n2: - return first[1:] == second[1:] - else: - return first[1:] == second or second[1:] == first - else: - return self.oneEditAway(first[1:], second[1:]) \ No newline at end of file diff --git a/leetcode/lcci/01.06.Compress String/README_EN.md b/leetcode/lcci/01.06.Compress String/README_EN.md deleted file mode 100644 index 50212609..00000000 --- a/leetcode/lcci/01.06.Compress String/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [01.06. Compress String](https://leetcode-cn.com/problems/compress-string-lcci) - -[中文文档](/lcci/01.06.Compress%20String/README.md) - -## Description - -

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a - z).

- -

Example 1:

- -
-
-Input: "aabcccccaaa"
-
-Output: "a2b1c5a3"
-
-
- -

Example 2:

- -
-
-Input: "abbccd"
-
-Output: "abbccd"
-
-Explanation: 
-
-The compressed string is "a1b2c2d1", which is longer than the original string.
-
-
- -

Note:

- -- `0 <= S.length <= 50000` - -## Solutions - - - -### **Python3** - -```python -class Solution: - def compressString(self, S: str) -> str: - if len(S) < 2: - return S - p, q = 0, 1 - res = '' - while q < len(S): - if S[p] != S[q]: - res += (S[p] + str(q - p)) - p = q - q += 1 - res += (S[p] + str(q - p)) - return res if len(res) < len(S) else S -``` - -### **Java** - -```java -class Solution { - public String compressString(String S) { - if (S == null || S.length() < 2) { - return S; - } - char[] chars = S.toCharArray(); - int p = 0, q = 1, n = chars.length; - StringBuilder sb = new StringBuilder(); - while (q < n) { - if (chars[p] != chars[q]) { - sb.append(chars[p]).append(q - p); - p = q; - } - q += 1; - } - sb.append(chars[p]).append(q - p); - String res = sb.toString(); - return res.length() < n ? res : S; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.06.Compress String/Solution.py b/leetcode/lcci/01.06.Compress String/Solution.py deleted file mode 100644 index 5fbae1cd..00000000 --- a/leetcode/lcci/01.06.Compress String/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def compressString(self, S: str) -> str: - if len(S) < 2: - return S - p, q = 0, 1 - res = '' - while q < len(S): - if S[p] != S[q]: - res += (S[p] + str(q - p)) - p = q - q += 1 - res += (S[p] + str(q - p)) - return res if len(res) < len(S) else S \ No newline at end of file diff --git a/leetcode/lcci/01.07.Rotate Matrix/README_EN.md b/leetcode/lcci/01.07.Rotate Matrix/README_EN.md deleted file mode 100644 index 82932f7f..00000000 --- a/leetcode/lcci/01.07.Rotate Matrix/README_EN.md +++ /dev/null @@ -1,127 +0,0 @@ -# [01.07. Rotate Matrix](https://leetcode-cn.com/problems/rotate-matrix-lcci) - -[中文文档](/lcci/01.07.Rotate%20Matrix/README.md) - -## Description - -

Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?

- -

 

- -

Example 1:

- -
-
-Given matrix = 
-
-[
-
-  [1,2,3],
-
-  [4,5,6],
-
-  [7,8,9]
-
-],
-
-
-
-Rotate the matrix in place. It becomes:
-
-[
-
-  [7,4,1],
-
-  [8,5,2],
-
-  [9,6,3]
-
-]
-
-
- -

Example 2:

- -
-
-Given matrix =
-
-[
-
-  [ 5, 1, 9,11],
-
-  [ 2, 4, 8,10],
-
-  [13, 3, 6, 7],
-
-  [15,14,12,16]
-
-], 
-
-
-
-Rotate the matrix in place. It becomes:
-
-[
-
-  [15,13, 2, 5],
-
-  [14, 3, 4, 1],
-
-  [12, 6, 8, 9],
-
-  [16, 7,10,11]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -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 // 2): - for j in range(i, n - 1 - i): - t = matrix[i][j] - matrix[i][j] = matrix[n - j - 1][i] - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] - matrix[j][n - i - 1] = t - -``` - -### **Java** - -```java -class Solution { - public void rotate(int[][] matrix) { - int n = matrix.length; - for (int i = 0; i < n / 2; ++i) { - for (int j = i; j < n - 1 - i; ++j) { - int t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; - } - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.07.Rotate Matrix/Solution.py b/leetcode/lcci/01.07.Rotate Matrix/Solution.py deleted file mode 100644 index 950a8e3a..00000000 --- a/leetcode/lcci/01.07.Rotate Matrix/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -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 // 2): - for j in range(i, n - 1 - i): - t = matrix[i][j] - matrix[i][j] = matrix[n - j - 1][i] - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] - matrix[j][n - i - 1] = t diff --git a/leetcode/lcci/01.08.Zero Matrix/README_EN.md b/leetcode/lcci/01.08.Zero Matrix/README_EN.md deleted file mode 100644 index a1585a7f..00000000 --- a/leetcode/lcci/01.08.Zero Matrix/README_EN.md +++ /dev/null @@ -1,141 +0,0 @@ -# [01.08. Zero Matrix](https://leetcode-cn.com/problems/zero-matrix-lcci) - -[中文文档](/lcci/01.08.Zero%20Matrix/README.md) - -## Description - -

Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.

- -

 

- -

Example 1:

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

Example 2:

- -
-
-Input: 
-
-[
-
-  [0,1,2,0],
-
-  [3,4,5,2],
-
-  [1,3,1,5]
-
-]
-
-Output: 
-
-[
-
-  [0,0,0,0],
-
-  [0,4,5,0],
-
-  [0,3,1,0]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def setZeroes(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ - rows, cols = len(matrix), len(matrix[0]) - zero_rows, zero_cols = set(), set() - for i in range(rows): - for j in range(cols): - if matrix[i][j] == 0: - zero_rows.add(i) - zero_cols.add(j) - - for i in zero_rows: - for j in range(cols): - matrix[i][j] = 0 - - for j in zero_cols: - for i in range(rows): - matrix[i][j] = 0 - - return matrix - -``` - -### **Java** - -```java -class Solution { - public void setZeroes(int[][] matrix) { - int rows = matrix.length, cols = matrix[0].length; - Set zeroRows = new HashSet<>(); - Set zeroCols = new HashSet<>(); - for (int i = 0; i < rows; ++i) { - for (int j = 0; j < cols; ++j) { - if (matrix[i][j] == 0) { - zeroRows.add(i); - zeroCols.add(j); - } - } - } - - for (int row : zeroRows) { - for (int j = 0; j < cols; ++j) { - matrix[row][j] = 0; - } - } - - for (int col : zeroCols) { - for (int i = 0; i < rows; ++i) { - matrix[i][col] = 0; - } - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.08.Zero Matrix/Solution.py b/leetcode/lcci/01.08.Zero Matrix/Solution.py deleted file mode 100644 index 7a54e54b..00000000 --- a/leetcode/lcci/01.08.Zero Matrix/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -class Solution: - def setZeroes(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ - rows, cols = len(matrix), len(matrix[0]) - zero_rows, zero_cols = set(), set() - for i in range(rows): - for j in range(cols): - if matrix[i][j] == 0: - zero_rows.add(i) - zero_cols.add(j) - - for i in zero_rows: - for j in range(cols): - matrix[i][j] = 0 - - for j in zero_cols: - for i in range(rows): - matrix[i][j] = 0 - - return matrix diff --git a/leetcode/lcci/01.09.String Rotation/README_EN.md b/leetcode/lcci/01.09.String Rotation/README_EN.md deleted file mode 100644 index 331cac42..00000000 --- a/leetcode/lcci/01.09.String Rotation/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [01.09. String Rotation](https://leetcode-cn.com/problems/string-rotation-lcci) - -[中文文档](/lcci/01.09.String%20Rotation/README.md) - -## Description - -

Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?

- -

Example 1:

- -
-
-Input: s1 = "waterbottle", s2 = "erbottlewat"
-
-Output: True
-
-
- -

Example 2:

- -
-
-Input: s1 = "aa", "aba"
-
-Output: False
-
-
- -

 

- -

Note:

- -
    -
  1. 0 <= s1.length, s1.length <= 100000
  2. -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isFlipedString(self, s1: str, s2: str) -> bool: - return len(s1) == len(s2) and s1 in (s2 * 2) -``` - -### **Java** - -```java -class Solution { - public boolean isFlipedString(String s1, String s2) { - return s1.length() == s2.length() && (s2 + s2).indexOf(s1) != -1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/01.09.String Rotation/Solution.py b/leetcode/lcci/01.09.String Rotation/Solution.py deleted file mode 100644 index c197a3bf..00000000 --- a/leetcode/lcci/01.09.String Rotation/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def isFlipedString(self, s1: str, s2: str) -> bool: - return len(s1) == len(s2) and s1 in (s2 * 2) diff --git a/leetcode/lcci/02.01.Remove Duplicate Node/README_EN.md b/leetcode/lcci/02.01.Remove Duplicate Node/README_EN.md deleted file mode 100644 index 1e86e25a..00000000 --- a/leetcode/lcci/02.01.Remove Duplicate Node/README_EN.md +++ /dev/null @@ -1,112 +0,0 @@ -# [02.01. Remove Duplicate Node](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) - -[中文文档](/lcci/02.01.Remove%20Duplicate%20Node/README.md) - -## Description - -

Write code to remove duplicates from an unsorted linked list.

- -

Example1:

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

Example2:

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

Note:

- -
    -
  1. The length of the list is within the range[0, 20000].
  2. - -
  3. The values of the list elements are within the range [0, 20000].
  4. - -
- -

Follow Up:

- -

How would you solve this problem if a temporary buffer is not allowed?

- -## Solutions - - - -### **Python3** - -```python -# 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 head is None or head.next is None: - return head - cache = set() - cache.add(head.val) - cur, p = head, head.next - while p: - if p.val not in cache: - cur.next = p - cur = cur.next - cache.add(p.val) - p = p.next - cur.next = None - return head -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode removeDuplicateNodes(ListNode head) { - if (head == null || head.next == null) { - return head; - } - Set s = new HashSet<>(); - s.add(head.val); - ListNode p = head.next, cur = head; - while (p != null) { - if (!s.contains(p.val)) { - cur.next = p; - cur = cur.next; - s.add(p.val); - } - p = p.next; - } - cur.next = null; - return head; - - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.01.Remove Duplicate Node/Solution.py b/leetcode/lcci/02.01.Remove Duplicate Node/Solution.py deleted file mode 100644 index 601b7cdc..00000000 --- a/leetcode/lcci/02.01.Remove Duplicate Node/Solution.py +++ /dev/null @@ -1,21 +0,0 @@ -# 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 head is None or head.next is None: - return head - cache = set() - cache.add(head.val) - cur, p = head, head.next - while p: - if p.val not in cache: - cur.next = p - cur = cur.next - cache.add(p.val) - p = p.next - cur.next = None - return head \ No newline at end of file diff --git a/leetcode/lcci/02.02.Kth Node From End of List/README_EN.md b/leetcode/lcci/02.02.Kth Node From End of List/README_EN.md deleted file mode 100644 index 464e1674..00000000 --- a/leetcode/lcci/02.02.Kth Node From End of List/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [02.02. Kth Node From End of List](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) - -[中文文档](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README.md) - -## Description - -

Implement an algorithm to find the kth to last element of a singly linked list. Return the value of the element.

- -

Note: This problem is slightly different from the original one in the book.

- -

Example:

- -
-
-Input:  1->2->3->4->5 和 k = 2
-
-Output:  4
- -

Note:

- -

k is always valid.

- -## Solutions - - - -### **Python3** - -```python -# 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: - p = q = head - for _ in range(k): - q = q.next - while q: - p, q = p.next, q.next - return p.val -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public int kthToLast(ListNode head, int k) { - ListNode p = head, q = head; - while (k-- > 0) { - q = q.next; - } - while (q != null) { - q = q.next; - p = p.next; - } - return p.val; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.02.Kth Node From End of List/Solution.py b/leetcode/lcci/02.02.Kth Node From End of List/Solution.py deleted file mode 100644 index 903ef471..00000000 --- a/leetcode/lcci/02.02.Kth Node From End of List/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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: - p = q = head - for _ in range(k): - q = q.next - while q: - p, q = p.next, q.next - return p.val \ No newline at end of file diff --git a/leetcode/lcci/02.03.Delete Middle Node/README_EN.md b/leetcode/lcci/02.03.Delete Middle Node/README_EN.md deleted file mode 100644 index 5b34c7d6..00000000 --- a/leetcode/lcci/02.03.Delete Middle Node/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [02.03. Delete Middle Node](https://leetcode-cn.com/problems/delete-middle-node-lcci) - -[中文文档](/lcci/02.03.Delete%20Middle%20Node/README.md) - -## Description - -

Implement an algorithm to delete a node in the middle (i.e., any node but the first and last node, not necessarily the exact middle) of a singly linked list, given only access to that node.

- -

 

- -

Example:

- -
-
-Input: the node c from the linked list a->b->c->d->e->f
-
-Output: nothing is returned, but the new linked list looks like a->b->d->e->f
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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. - """ - node.val = node.next.val - node.next = node.next.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public void deleteNode(ListNode node) { - node.val = node.next.val; - node.next = node.next.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.03.Delete Middle Node/Solution.py b/leetcode/lcci/02.03.Delete Middle Node/Solution.py deleted file mode 100644 index 201e675b..00000000 --- a/leetcode/lcci/02.03.Delete Middle Node/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - """ - node.val = node.next.val - node.next = node.next.next \ No newline at end of file diff --git a/leetcode/lcci/02.04.Partition List/README_EN.md b/leetcode/lcci/02.04.Partition List/README_EN.md deleted file mode 100644 index b31db0fe..00000000 --- a/leetcode/lcci/02.04.Partition List/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [02.04. Partition List](https://leetcode-cn.com/problems/partition-list-lcci) - -[中文文档](/lcci/02.04.Partition%20List/README.md) - -## Description - -

Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x (see below). The partition element x can appear anywhere in the "right partition"; it does not need to appear between the left and right partitions.

- -

Example:

- -
-
-Input: head = 3->5->8->5->10->2->1, x = 5
-
-Output: 3->1->2->10->5->5->8
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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: - if head is None or head.next is None: - return head - left, right = ListNode(-1), ListNode(-1) - p, q = left, right - while head: - t = head.next - head.next = None - if head.val < x: - p.next = head - p = p.next - else: - q.next = head - q = q.next - head = t - p.next = right.next - return left.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode partition(ListNode head, int x) { - if (head == null || head.next == null) { - return head; - } - ListNode left = new ListNode(-1); - ListNode right = new ListNode(-1); - ListNode p = left, q = right; - while (head != null) { - ListNode t = head.next; - head.next = null; - if (head.val < x) { - p.next = head; - p = p.next; - } else { - q.next = head; - q = q.next; - } - head = t; - } - p.next = right.next; - return left.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.04.Partition List/Solution.py b/leetcode/lcci/02.04.Partition List/Solution.py deleted file mode 100644 index 3d941f03..00000000 --- a/leetcode/lcci/02.04.Partition List/Solution.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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: - if head is None or head.next is None: - return head - left, right = ListNode(-1), ListNode(-1) - p, q = left, right - while head: - t = head.next - head.next = None - if head.val < x: - p.next = head - p = p.next - else: - q.next = head - q = q.next - head = t - p.next = right.next - return left.next diff --git a/leetcode/lcci/02.05.Sum Lists/README_EN.md b/leetcode/lcci/02.05.Sum Lists/README_EN.md deleted file mode 100644 index 61b5c845..00000000 --- a/leetcode/lcci/02.05.Sum Lists/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [02.05. Sum Lists](https://leetcode-cn.com/problems/sum-lists-lcci) - -[中文文档](/lcci/02.05.Sum%20Lists/README.md) - -## Description - -

You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.

- -

 

- -

Example:

- -
-
-Input: (7 -> 1 -> 6) + (5 -> 9 -> 2). That is, 617 + 295.
-
-Output: 2 -> 1 -> 9. That is, 912.
-
-
- -

Follow Up: Suppose the digits are stored in forward order. Repeat the above problem.

- -

Example:

- -
-
-Input: (6 -> 1 -> 7) + (2 -> 9 -> 5). That is, 617 + 295.
-
-Output: 9 -> 1 -> 2. That is, 912.
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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: - p = ListNode(-1) - carry, t = 0, p - while l1 or l2: - s = (0 if l1 is None else l1.val) + (0 if l2 is None else l2.val) + carry - carry = 1 if s > 9 else 0 - t.next = ListNode(s % 10) - t = t.next - l1 = l1.next if l1 else l1 - l2 = l2.next if l2 else l2 - t.next = None if carry == 0 else ListNode(carry) - return p.next - - -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode addTwoNumbers(ListNode l1, ListNode l2) { - ListNode p = new ListNode(-1); - int carry = 0; - ListNode t = p; - while (l1 != null || l2 != null) { - int s = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry; - t.next = new ListNode(s % 10); - carry = s > 9 ? 1 : 0; - t = t.next; - l1 = l1 == null ? l1 : l1.next; - l2 = l2 == null ? l2 : l2.next; - } - t.next = carry == 0 ? null : new ListNode(carry); - return p.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.05.Sum Lists/Solution.py b/leetcode/lcci/02.05.Sum Lists/Solution.py deleted file mode 100644 index 8165bb4c..00000000 --- a/leetcode/lcci/02.05.Sum Lists/Solution.py +++ /dev/null @@ -1,21 +0,0 @@ -# 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: - p = ListNode(-1) - carry, t = 0, p - while l1 or l2: - s = (0 if l1 is None else l1.val) + \ - (0 if l2 is None else l2.val) + carry - carry = 1 if s > 9 else 0 - t.next = ListNode(s % 10) - t = t.next - l1 = l1.next if l1 else l1 - l2 = l2.next if l2 else l2 - t.next = None if carry == 0 else ListNode(carry) - return p.next diff --git a/leetcode/lcci/02.06.Palindrome Linked List/README_EN.md b/leetcode/lcci/02.06.Palindrome Linked List/README_EN.md deleted file mode 100644 index ff60a696..00000000 --- a/leetcode/lcci/02.06.Palindrome Linked List/README_EN.md +++ /dev/null @@ -1,117 +0,0 @@ -# [02.06. Palindrome Linked List](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) - -[中文文档](/lcci/02.06.Palindrome%20Linked%20List/README.md) - -## Description - -

Implement a function to check if a linked list is a palindrome.

- -

 

- -

Example 1:

- -
-
-Input:  1->2
-
-Output:  false 
-
-
- -

Example 2:

- -
-
-Input:  1->2->2->1
-
-Output:  true 
-
-
- -

 

- -

Follow up:
- -Could you do it in O(n) time and O(1) space?

- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None -class Solution: - def isPalindrome(self, head: ListNode) -> bool: - if head is None or head.next is None: - return True - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - pre, cur = None, slow.next - while cur: - t = cur.next - cur.next = pre - pre, cur = cur, t - while pre: - if pre.val != head.val: - return False - pre, head = pre.next, head.next - return True -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public boolean isPalindrome(ListNode head) { - if (head == null || head.next == null) { - return true; - } - ListNode slow = head; - ListNode fast = head.next; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - } - ListNode cur = slow.next; - slow.next = null; - ListNode pre = null; - while (cur != null) { - ListNode t = cur.next; - cur.next = pre; - pre = cur; - cur = t; - } - while (pre != null) { - if (pre.val != head.val) { - return false; - } - pre = pre.next; - head = head.next; - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.06.Palindrome Linked List/Solution.py b/leetcode/lcci/02.06.Palindrome Linked List/Solution.py deleted file mode 100644 index f71cd69a..00000000 --- a/leetcode/lcci/02.06.Palindrome Linked List/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None -class Solution: - def isPalindrome(self, head: ListNode) -> bool: - if head is None or head.next is None: - return True - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - pre, cur = None, slow.next - while cur: - t = cur.next - cur.next = pre - pre, cur = cur, t - while pre: - if pre.val != head.val: - return False - pre, head = pre.next, head.next - return True \ No newline at end of file diff --git a/leetcode/lcci/02.08.Linked List Cycle/README_EN.md b/leetcode/lcci/02.08.Linked List Cycle/README_EN.md deleted file mode 100644 index d47d506a..00000000 --- a/leetcode/lcci/02.08.Linked List Cycle/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [02.08. Linked List Cycle](https://leetcode-cn.com/problems/linked-list-cycle-lcci) - -[中文文档](/lcci/02.08.Linked%20List%20Cycle/README.md) - -## Description - -

Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop.

- -

Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node, so as to make a loop in the linked list.

- -

Example 1:

- -
-
-Input: head = [3,2,0,-4], pos = 1
-
-Output: tail connects to node index 1
- -

Example 2:

- -
-
-Input: head = [1,2], pos = 0
-
-Output: tail connects to node index 0
- -

Example 3:

- -
-
-Input: head = [1], pos = -1
-
-Output: no cycle
- -

Follow Up:
- -Can you solve it without using additional space?

- -## Solutions - - - -### **Python3** - -```python -# 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: - fast = slow = p = head - while fast and fast.next: - fast = fast.next.next - slow = slow.next - if fast == slow: - break - if fast is None or fast.next is None: - return None - while slow != p: - p = p.next - slow = slow.next - return p -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { - * val = x; - * next = null; - * } - * } - */ -public class Solution { - public ListNode detectCycle(ListNode head) { - ListNode fast = head, slow = head; - while (fast != null && fast.next != null) { - fast = fast.next.next; - slow = slow.next; - if (fast == slow) break; - } - if (fast == null || fast.next == null) return null; - ListNode p = head; - while (p != slow) { - p = p.next; - slow = slow.next; - } - return p; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/02.08.Linked List Cycle/Solution.py b/leetcode/lcci/02.08.Linked List Cycle/Solution.py deleted file mode 100644 index fec1db65..00000000 --- a/leetcode/lcci/02.08.Linked List Cycle/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -# 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: - fast = slow = p = head - while fast and fast.next: - fast = fast.next.next - slow = slow.next - if fast == slow: - break - if fast is None or fast.next is None: - return None - while slow != p: - p = p.next - slow = slow.next - return p \ No newline at end of file diff --git a/leetcode/lcci/03.01.Three in One/README_EN.md b/leetcode/lcci/03.01.Three in One/README_EN.md deleted file mode 100644 index 40ded4af..00000000 --- a/leetcode/lcci/03.01.Three in One/README_EN.md +++ /dev/null @@ -1,134 +0,0 @@ -# [03.01. Three in One](https://leetcode-cn.com/problems/three-in-one-lcci) - -[中文文档](/lcci/03.01.Three%20in%20One/README.md) - -## Description - -

Describe how you could use a single array to implement three stacks.

- -

Yout should implement push(stackNum, value)pop(stackNum)isEmpty(stackNum)peek(stackNum) methods. stackNum is the index of the stack. value is the value that pushed to the stack.

- -

The constructor requires a stackSize parameter, which represents the size of each stack.

- -

Example1:

- -
-
- Input: 
-
-["TripleInOne", "push", "push", "pop", "pop", "pop", "isEmpty"]
-
-[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
-
- Output: 
-
-[null, null, null, 1, -1, -1, true]
-
-Explanation: When the stack is empty, `pop, peek` return -1. When the stack is full, `push` does nothing.
-
-
- -

Example2:

- -
-
- Input: 
-
-["TripleInOne", "push", "push", "push", "pop", "pop", "pop", "peek"]
-
-[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
-
- Output: 
-
-[null, null, null, null, 2, 1, -1, -1]
-
-
- -## Solutions - - - -### **Python3** - -```python -class TripleInOne: - - def __init__(self, stackSize: int): - self._capacity = stackSize - self._s = [[], [], []] - - def push(self, stackNum: int, value: int) -> None: - if len(self._s[stackNum]) < self._capacity: - self._s[stackNum].append(value) - - def pop(self, stackNum: int) -> int: - return -1 if self.isEmpty(stackNum) else self._s[stackNum].pop() - - def peek(self, stackNum: int) -> int: - return -1 if self.isEmpty(stackNum) else self._s[stackNum][-1] - - def isEmpty(self, stackNum: int) -> bool: - return len(self._s[stackNum]) == 0 - - -# Your TripleInOne object will be instantiated and called as such: -# obj = TripleInOne(stackSize) -# obj.push(stackNum,value) -# param_2 = obj.pop(stackNum) -# param_3 = obj.peek(stackNum) -# param_4 = obj.isEmpty(stackNum) -``` - -### **Java** - -```java -class TripleInOne { - private int[] s; - private int capacity; - - public TripleInOne(int stackSize) { - s = new int[stackSize * 3 + 3]; - capacity = stackSize; - } - - public void push(int stackNum, int value) { - if (s[stackNum + 3 * capacity] < capacity) { - s[s[stackNum + 3 * capacity] * 3 + stackNum] = value; - ++s[stackNum + 3 * capacity]; - } - } - - public int pop(int stackNum) { - if (isEmpty(stackNum)) { - return -1; - } - --s[stackNum + 3 * capacity]; - return s[s[stackNum + 3 * capacity] * 3 + stackNum]; - } - - public int peek(int stackNum) { - return isEmpty(stackNum) ? -1 : s[(s[stackNum + 3 * capacity] - 1) * 3 + stackNum]; - } - - public boolean isEmpty(int stackNum) { - return s[stackNum + 3 * capacity] == 0; - } -} - -/** - * Your TripleInOne object will be instantiated and called as such: - * TripleInOne obj = new TripleInOne(stackSize); - * obj.push(stackNum,value); - * int param_2 = obj.pop(stackNum); - * int param_3 = obj.peek(stackNum); - * boolean param_4 = obj.isEmpty(stackNum); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/03.01.Three in One/Solution.py b/leetcode/lcci/03.01.Three in One/Solution.py deleted file mode 100644 index c84c645a..00000000 --- a/leetcode/lcci/03.01.Three in One/Solution.py +++ /dev/null @@ -1,26 +0,0 @@ -class TripleInOne: - - def __init__(self, stackSize: int): - self._capacity = stackSize - self._s = [[], [], []] - - def push(self, stackNum: int, value: int) -> None: - if len(self._s[stackNum]) < self._capacity: - self._s[stackNum].append(value) - - def pop(self, stackNum: int) -> int: - return -1 if self.isEmpty(stackNum) else self._s[stackNum].pop() - - def peek(self, stackNum: int) -> int: - return -1 if self.isEmpty(stackNum) else self._s[stackNum][-1] - - def isEmpty(self, stackNum: int) -> bool: - return len(self._s[stackNum]) == 0 - - -# Your TripleInOne object will be instantiated and called as such: -# obj = TripleInOne(stackSize) -# obj.push(stackNum,value) -# param_2 = obj.pop(stackNum) -# param_3 = obj.peek(stackNum) -# param_4 = obj.isEmpty(stackNum) diff --git a/leetcode/lcci/03.02.Min Stack/README_EN.md b/leetcode/lcci/03.02.Min Stack/README_EN.md deleted file mode 100644 index 57fb34d7..00000000 --- a/leetcode/lcci/03.02.Min Stack/README_EN.md +++ /dev/null @@ -1,117 +0,0 @@ -# [03.02. Min Stack](https://leetcode-cn.com/problems/min-stack-lcci) - -[中文文档](/lcci/03.02.Min%20Stack/README.md) - -## Description - -

How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element? Push, pop and min should all operate in 0(1) time.

- -

Example:

- -
-
-MinStack minStack = new MinStack();
-
-minStack.push(-2);
-
-minStack.push(0);
-
-minStack.push(-3);
-
-minStack.getMin();   --> return -3.
-
-minStack.pop();
-
-minStack.top();      --> return 0.
-
-minStack.getMin();   --> return -2.
- -## Solutions - - - -### **Python3** - -```python -class MinStack: - - def __init__(self): - """ - initialize your data structure here. - """ - self._s1 = [] - self._s2 = [] - - - def push(self, x: int) -> None: - self._s1.append(x) - self._s2.append(x if len(self._s2) == 0 or self._s2[-1] >= x else self._s2[-1]) - - def pop(self) -> None: - self._s1.pop() - self._s2.pop() - - def top(self) -> int: - return self._s1[-1] - - def getMin(self) -> int: - return self._s2[-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() -``` - -### **Java** - -```java -class MinStack { - private Stack s1; - private Stack s2; - - /** initialize your data structure here. */ - public MinStack() { - s1 = new Stack<>(); - s2 = new Stack<>(); - } - - public void push(int x) { - s1.push(x); - s2.push(s2.empty() || s2.peek() >= x ? x : s2.peek()); - } - - public void pop() { - s1.pop(); - s2.pop(); - } - - public int top() { - return s1.peek(); - } - - public int getMin() { - return s2.empty() ? -1 : s2.peek(); - } -} - -/** - * Your MinStack object will be instantiated and called as such: - * MinStack obj = new MinStack(); - * obj.push(x); - * obj.pop(); - * int param_3 = obj.top(); - * int param_4 = obj.getMin(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/03.02.Min Stack/Solution.py b/leetcode/lcci/03.02.Min Stack/Solution.py deleted file mode 100644 index 49566676..00000000 --- a/leetcode/lcci/03.02.Min Stack/Solution.py +++ /dev/null @@ -1,31 +0,0 @@ -class MinStack: - - def __init__(self): - """ - initialize your data structure here. - """ - self._s1 = [] - self._s2 = [] - - def push(self, x: int) -> None: - self._s1.append(x) - self._s2.append(x if len(self._s2) == - 0 or self._s2[-1] >= x else self._s2[-1]) - - def pop(self) -> None: - self._s1.pop() - self._s2.pop() - - def top(self) -> int: - return self._s1[-1] - - def getMin(self) -> int: - return self._s2[-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() diff --git a/leetcode/lcci/03.04.Implement Queue using Stacks/README_EN.md b/leetcode/lcci/03.04.Implement Queue using Stacks/README_EN.md deleted file mode 100644 index c9efdbd5..00000000 --- a/leetcode/lcci/03.04.Implement Queue using Stacks/README_EN.md +++ /dev/null @@ -1,160 +0,0 @@ -# [03.04. Implement Queue using Stacks](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) - -[中文文档](/lcci/03.04.Implement%20Queue%20using%20Stacks/README.md) - -## Description - -

Implement a MyQueue class which implements a queue using two stacks.

- -  - -

Example:

- -
-
-MyQueue queue = new MyQueue();
-
-
-
-queue.push(1);
-
-queue.push(2);
-
-queue.peek();  // return 1
-
-queue.pop();   // return 1
-
-queue.empty(); // return false
- -

 

- -

Notes:

- -
    -
  • You must use only standard operations of a stack -- which means only push to toppeek/pop from topsize, and is empty operations are valid.
  • -
  • Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.
  • -
  • You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).
  • -
- -

 

- -## Solutions - - - -### **Python3** - -```python -class MyQueue: - - def __init__(self): - """ - Initialize your data structure here. - """ - self._s1, self._s2 = [], [] - - - def push(self, x: int) -> None: - """ - Push element x to the back of queue. - """ - self._s1.append(x) - - - def pop(self) -> int: - """ - Removes the element from in front of queue and returns that element. - """ - if len(self._s2) == 0: - while self._s1: - self._s2.append(self._s1.pop()) - return self._s2.pop() - - - def peek(self) -> int: - """ - Get the front element. - """ - if len(self._s2) == 0: - while self._s1: - self._s2.append(self._s1.pop()) - return self._s2[-1] - - - def empty(self) -> bool: - """ - Returns whether the queue is empty. - """ - return len(self._s1) + len(self._s2) == 0 - - - -# Your MyQueue object will be instantiated and called as such: -# obj = MyQueue() -# obj.push(x) -# param_2 = obj.pop() -# param_3 = obj.peek() -# param_4 = obj.empty() -``` - -### **Java** - -```java -class MyQueue { - private Stack s1; - private Stack s2; - - /** Initialize your data structure here. */ - public MyQueue() { - s1 = new Stack<>(); - s2 = new Stack<>(); - } - - /** Push element x to the back of queue. */ - public void push(int x) { - s1.push(x); - } - - /** Removes the element from in front of queue and returns that element. */ - public int pop() { - if (s2.empty()) { - while (!s1.empty()) { - s2.push(s1.pop()); - } - } - return s2.pop(); - } - - /** Get the front element. */ - public int peek() { - if (s2.empty()) { - while (!s1.empty()) { - s2.push(s1.pop()); - } - } - return s2.peek(); - } - - /** Returns whether the queue is empty. */ - public boolean empty() { - return s1.empty() && s2.empty(); - } -} - -/** - * Your MyQueue object will be instantiated and called as such: - * MyQueue obj = new MyQueue(); - * obj.push(x); - * int param_2 = obj.pop(); - * int param_3 = obj.peek(); - * boolean param_4 = obj.empty(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/03.04.Implement Queue using Stacks/Solution.py b/leetcode/lcci/03.04.Implement Queue using Stacks/Solution.py deleted file mode 100644 index 923ceb88..00000000 --- a/leetcode/lcci/03.04.Implement Queue using Stacks/Solution.py +++ /dev/null @@ -1,45 +0,0 @@ -class MyQueue: - - def __init__(self): - """ - Initialize your data structure here. - """ - self._s1, self._s2 = [], [] - - def push(self, x: int) -> None: - """ - Push element x to the back of queue. - """ - self._s1.append(x) - - def pop(self) -> int: - """ - Removes the element from in front of queue and returns that element. - """ - if len(self._s2) == 0: - while self._s1: - self._s2.append(self._s1.pop()) - return self._s2.pop() - - def peek(self) -> int: - """ - Get the front element. - """ - if len(self._s2) == 0: - while self._s1: - self._s2.append(self._s1.pop()) - return self._s2[-1] - - def empty(self) -> bool: - """ - Returns whether the queue is empty. - """ - return len(self._s1) + len(self._s2) == 0 - - -# Your MyQueue object will be instantiated and called as such: -# obj = MyQueue() -# obj.push(x) -# param_2 = obj.pop() -# param_3 = obj.peek() -# param_4 = obj.empty() diff --git a/leetcode/lcci/03.05.Sort of Stacks/README_EN.md b/leetcode/lcci/03.05.Sort of Stacks/README_EN.md deleted file mode 100644 index d5fb5a2b..00000000 --- a/leetcode/lcci/03.05.Sort of Stacks/README_EN.md +++ /dev/null @@ -1,129 +0,0 @@ -# [03.05. Sort of Stacks](https://leetcode-cn.com/problems/sort-of-stacks-lcci) - -[中文文档](/lcci/03.05.Sort%20of%20Stacks/README.md) - -## Description - -

Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, and isEmpty. When the stack is empty, peek should return -1.

- -

Example1:

- -
-
- Input: 
-
-["SortedStack", "push", "push", "peek", "pop", "peek"]
-
-[[], [1], [2], [], [], []]
-
- Output: 
-
-[null,null,null,1,null,2]
-
-
- -

Example2:

- -
-
- Input:  
-
-["SortedStack", "pop", "pop", "push", "pop", "isEmpty"]
-
-[[], [], [], [1], [], []]
-
- Output: 
-
-[null,null,null,null,null,true]
-
-
- -

Note:

- -
    -
  1. The total number of elements in the stack is within the range [0, 5000].
  2. -
- -## Solutions - - - -### **Python3** - -```python -class SortedStack: - - def __init__(self): - self.s = [] - - def push(self, val: int) -> None: - t = [] - while not self.isEmpty() and self.s[-1] < val: - t.append(self.s.pop()) - self.s.append(val) - while len(t) > 0: - self.s.append(t.pop()) - - def pop(self) -> None: - if not self.isEmpty(): - self.s.pop() - - def peek(self) -> int: - return -1 if self.isEmpty() else self.s[-1] - - def isEmpty(self) -> bool: - return len(self.s) == 0 -``` - -### **Java** - -```java -class SortedStack { - private Stack s; - public SortedStack() { - s = new Stack<>(); - } - - public void push(int val) { - Stack t = new Stack<>(); - while (!isEmpty() && s.peek() < val) { - t.push(s.pop()); - } - s.push(val); - while (!t.isEmpty()) { - s.push(t.pop()); - } - } - - public void pop() { - if (!isEmpty()) { - s.pop(); - } - } - - public int peek() { - return isEmpty() ? -1 : s.peek(); - } - - public boolean isEmpty() { - return s.isEmpty(); - } -} - -/** - * Your SortedStack object will be instantiated and called as such: - * SortedStack obj = new SortedStack(); - * obj.push(val); - * obj.pop(); - * int param_3 = obj.peek(); - * boolean param_4 = obj.isEmpty(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/03.05.Sort of Stacks/Solution.py b/leetcode/lcci/03.05.Sort of Stacks/Solution.py deleted file mode 100644 index 692c7473..00000000 --- a/leetcode/lcci/03.05.Sort of Stacks/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -class SortedStack: - - def __init__(self): - self.s = [] - - def push(self, val: int) -> None: - t = [] - while not self.isEmpty() and self.s[-1] < val: - t.append(self.s.pop()) - self.s.append(val) - while len(t) > 0: - self.s.append(t.pop()) - - def pop(self) -> None: - if not self.isEmpty(): - self.s.pop() - - def peek(self) -> int: - return -1 if self.isEmpty() else self.s[-1] - - def isEmpty(self) -> bool: - return len(self.s) == 0 diff --git a/leetcode/lcci/03.06.Animal Shelter/README_EN.md b/leetcode/lcci/03.06.Animal Shelter/README_EN.md deleted file mode 100644 index 189055fe..00000000 --- a/leetcode/lcci/03.06.Animal Shelter/README_EN.md +++ /dev/null @@ -1,138 +0,0 @@ -# [03.06. Animal Shelter](https://leetcode-cn.com/problems/animal-shelter-lcci) - -[中文文档](/lcci/03.06.Animal%20Shelter/README.md) - -## Description - -

An animal shelter, which holds only dogs and cats, operates on a strictly"first in, first out" basis. People must adopt either the"oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog, and dequeueCat. You may use the built-in Linked list data structure.

- -

enqueue method has a animal parameter, animal[0] represents the number of the animal, animal[1] represents the type of the animal, 0 for cat and 1 for dog.

- -

dequeue* method returns [animal number, animal type], if there's no animal that can be adopted, return [-1, -1].

- -

Example1:

- -
-
- Input: 
-
-["AnimalShelf", "enqueue", "enqueue", "dequeueCat", "dequeueDog", "dequeueAny"]
-
-[[], [[0, 0]], [[1, 0]], [], [], []]
-
- Output: 
-
-[null,null,null,[0,0],[-1,-1],[1,0]]
-
-
- -

Example2:

- -
-
- Input: 
-
-["AnimalShelf", "enqueue", "enqueue", "enqueue", "dequeueDog", "dequeueCat", "dequeueAny"]
-
-[[], [[0, 0]], [[1, 0]], [[2, 1]], [], [], []]
-
- Output: 
-
-[null,null,null,null,[2,1],[0,0],[1,0]]
-
-
- -

Note:

- -
    -
  1. The number of animals in the shelter will not exceed 20000.
  2. -
- -## Solutions - - - -### **Python3** - -```python -class AnimalShelf: - - def __init__(self): - self.cats = [] - self.dogs = [] - - def enqueue(self, animal: List[int]) -> None: - if animal[1] == 0: - self.cats.insert(0, animal[0]) - else: - self.dogs.insert(0, animal[0]) - - def dequeueAny(self) -> List[int]: - if len(self.dogs) == 0: return self.dequeueCat() - if len(self.cats) == 0: return self.dequeueDog() - return self.dequeueDog() if self.dogs[-1] < self.cats[-1] else self.dequeueCat() - - def dequeueDog(self) -> List[int]: - return [-1, -1] if len(self.dogs) == 0 else [self.dogs.pop(), 1] - - def dequeueCat(self) -> List[int]: - return [-1, -1] if len(self.cats) == 0 else [self.cats.pop(), 0] - - -# Your AnimalShelf object will be instantiated and called as such: -# obj = AnimalShelf() -# obj.enqueue(animal) -# param_2 = obj.dequeueAny() -# param_3 = obj.dequeueDog() -# param_4 = obj.dequeueCat() -``` - -### **Java** - -```java -class AnimalShelf { - Queue cats; - Queue dogs; - public AnimalShelf() { - cats = new LinkedList<>(); - dogs = new LinkedList<>(); - } - - public void enqueue(int[] animal) { - if (animal[1] == 0) { - cats.offer(animal[0]); - } else { - dogs.offer(animal[0]); - } - } - - public int[] dequeueAny() { - return dogs.isEmpty() ? dequeueCat() : (cats.isEmpty() ? dequeueDog() : (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat())); - } - - public int[] dequeueDog() { - return dogs.isEmpty() ? new int[]{-1, -1} : new int[]{dogs.poll(), 1}; - } - - public int[] dequeueCat() { - return cats.isEmpty() ? new int[]{-1, -1} : new int[]{cats.poll(), 0}; - } -} - -/** - * Your AnimalShelf object will be instantiated and called as such: - * AnimalShelf obj = new AnimalShelf(); - * obj.enqueue(animal); - * int[] param_2 = obj.dequeueAny(); - * int[] param_3 = obj.dequeueDog(); - * int[] param_4 = obj.dequeueCat(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/03.06.Animal Shelter/Solution.py b/leetcode/lcci/03.06.Animal Shelter/Solution.py deleted file mode 100644 index 093f8c75..00000000 --- a/leetcode/lcci/03.06.Animal Shelter/Solution.py +++ /dev/null @@ -1,32 +0,0 @@ -class AnimalShelf: - - def __init__(self): - self.cats = [] - self.dogs = [] - - def enqueue(self, animal: List[int]) -> None: - if animal[1] == 0: - self.cats.insert(0, animal[0]) - else: - self.dogs.insert(0, animal[0]) - - def dequeueAny(self) -> List[int]: - if len(self.dogs) == 0: - return self.dequeueCat() - if len(self.cats) == 0: - return self.dequeueDog() - return self.dequeueDog() if self.dogs[-1] < self.cats[-1] else self.dequeueCat() - - def dequeueDog(self) -> List[int]: - return [-1, -1] if len(self.dogs) == 0 else [self.dogs.pop(), 1] - - def dequeueCat(self) -> List[int]: - return [-1, -1] if len(self.cats) == 0 else [self.cats.pop(), 0] - - -# Your AnimalShelf object will be instantiated and called as such: -# obj = AnimalShelf() -# obj.enqueue(animal) -# param_2 = obj.dequeueAny() -# param_3 = obj.dequeueDog() -# param_4 = obj.dequeueCat() diff --git a/leetcode/lcci/04.04.Check Balance/README_EN.md b/leetcode/lcci/04.04.Check Balance/README_EN.md deleted file mode 100644 index 1db241ff..00000000 --- a/leetcode/lcci/04.04.Check Balance/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [04.04. Check Balance](https://leetcode-cn.com/problems/check-balance-lcci) - -[中文文档](/lcci/04.04.Check%20Balance/README.md) - -## Description - -

Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

- -


- -Example 1:

- -
-
-Given tree [3,9,20,null,null,15,7]
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-return true.
- -

Example 2:

- -
-
-Given [1,2,2,3,3,null,null,4,4]
-
-      1
-
-     / \
-
-    2   2
-
-   / \
-
-  3   3
-
- / \
-
-4   4
-
-return false.
- -

 

- -## Solutions - - - -### **Python3** - -```python -# 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: - return True - l, r = self._height(root.left), self._height(root.right) - return abs(l - r) < 2 and self.isBalanced(root.left) and self.isBalanced(root.right) - - def _height(self, node): - if not node: - return 0 - return 1 + max(self._height(node.left), self._height(node.right)) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public boolean isBalanced(TreeNode root) { - if (root == null) { - return true; - } - int l = height(root.left), r = height(root.right); - return Math.abs(l - r) < 2 && isBalanced(root.left) && isBalanced(root.right); - } - - private int height(TreeNode node) { - if (node == null) { - return 0; - } - return 1 + Math.max(height(node.left), height(node.right)); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/04.04.Check Balance/Solution.py b/leetcode/lcci/04.04.Check Balance/Solution.py deleted file mode 100644 index df117271..00000000 --- a/leetcode/lcci/04.04.Check Balance/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -# 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: - return True - l, r = self._height(root.left), self._height(root.right) - return abs(l - r) < 2 and self.isBalanced(root.left) and self.isBalanced(root.right) - - def _height(self, node): - if not node: - return 0 - return 1 + max(self._height(node.left), self._height(node.right)) diff --git a/leetcode/lcci/04.05.Legal Binary Search Tree/README_EN.md b/leetcode/lcci/04.05.Legal Binary Search Tree/README_EN.md deleted file mode 100644 index e59cb8ba..00000000 --- a/leetcode/lcci/04.05.Legal Binary Search Tree/README_EN.md +++ /dev/null @@ -1,121 +0,0 @@ -# [04.05. Legal Binary Search Tree](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) - -[中文文档](/lcci/04.05.Legal%20Binary%20Search%20Tree/README.md) - -## Description - -

Implement a function to check if a binary tree is a binary search tree.

- -

Example 1:

- -
-
-Input:
-
-    2
-
-   / \
-
-  1   3
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input:
-
-    5
-
-   / \
-
-  1   4
-
-     / \
-
-    3   6
-
-Output: false
-
-Explanation: Input: [5,1,4,null,null,3,6].
-
-     the value of root node is 5, but its right child has value 4.
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - res, t = True, None - def isValidBST(self, root: TreeNode) -> bool: - self.isValid(root) - return self.res - - def isValid(self, root): - if not root: - return - self.isValid(root.left) - if self.t is None or self.t < root.val: - self.t = root.val - else: - self.res = False - return - self.isValid(root.right) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - private boolean res = true; - private Integer t = null; - public boolean isValidBST(TreeNode root) { - isValid(root); - return res; - } - - private void isValid(TreeNode root) { - if (root == null) { - return; - } - isValid(root.left); - if (t == null || t < root.val) { - t = root.val; - } else { - res = false; - return; - } - isValid(root.right); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/04.05.Legal Binary Search Tree/Solution.py b/leetcode/lcci/04.05.Legal Binary Search Tree/Solution.py deleted file mode 100644 index e9b4aaf5..00000000 --- a/leetcode/lcci/04.05.Legal Binary Search Tree/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - res, t = True, None - def isValidBST(self, root: TreeNode) -> bool: - self.isValid(root) - return self.res - - def isValid(self, root): - if not root: - return - self.isValid(root.left) - if self.t is None or self.t < root.val: - self.t = root.val - else: - self.res = False - return - self.isValid(root.right) \ No newline at end of file diff --git a/leetcode/lcci/04.08.First Common Ancestor/README_EN.md b/leetcode/lcci/04.08.First Common Ancestor/README_EN.md deleted file mode 100644 index 8dd1145b..00000000 --- a/leetcode/lcci/04.08.First Common Ancestor/README_EN.md +++ /dev/null @@ -1,109 +0,0 @@ -# [04.08. First Common Ancestor](https://leetcode-cn.com/problems/first-common-ancestor-lcci) - -[中文文档](/lcci/04.08.First%20Common%20Ancestor/README.md) - -## Description - -

Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.

- -

For example, Given the following tree: root = [3,5,1,6,2,0,8,null,null,7,4]

- -
-
-    3
-
-   / \
-
-  5   1
-
- / \ / \
-
-6  2 0  8
-
-  / \
-
- 7   4
-
-
- -

Example 1:

- -
-
-Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
-
-Input: 3
-
-Explanation: The first common ancestor of node 5 and node 1 is node 3.
- -

Example 2:

- -
-
-Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
-
-Output: 5
-
-Explanation: The first common ancestor of node 5 and node 4 is node 5.
- -

Notes:

- -
    -
  • All node values are pairwise distinct.
  • -
  • p, q are different node and both can be found in the given tree.
  • -
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: - if root is None or root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - return right if left is None else (left if right is None else root) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - if (root == null || root == p || root == q) { - return root; - } - TreeNode left = lowestCommonAncestor(root.left, p, q); - TreeNode right = lowestCommonAncestor(root.right, p, q); - return left == null ? right : (right == null ? left : root); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/04.08.First Common Ancestor/Solution.py b/leetcode/lcci/04.08.First Common Ancestor/Solution.py deleted file mode 100644 index 01cf24bd..00000000 --- a/leetcode/lcci/04.08.First Common Ancestor/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: - if root is None or root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - return right if left is None else (left if right is None else root) \ No newline at end of file diff --git a/leetcode/lcci/04.10.Check SubTree/README_EN.md b/leetcode/lcci/04.10.Check SubTree/README_EN.md deleted file mode 100644 index 4bf9b9a9..00000000 --- a/leetcode/lcci/04.10.Check SubTree/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [04.10. Check SubTree](https://leetcode-cn.com/problems/check-subtree-lcci) - -[中文文档](/lcci/04.10.Check%20SubTree/README.md) - -## Description - -

T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1.

- -

A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n is identical to T2. That is, if you cut off the tree at node n, the two trees would be identical.

- -

Example1:

- -
-
- Input: t1 = [1, 2, 3], t2 = [2]
-
- Output: true
-
-
- -

Example2:

- -
-
- Input: t1 = [1, null, 2, 4], t2 = [3, 2]
-
- Output: false
-
-
- -

Note:

- -
    -
  1. The node numbers of both tree are in [0, 20000].
  2. -
- -## Solutions - -Find the t2 node in t1 first, then use the depth-first search (DFS) algorithm to make sure that the subtree and the subtree of t2 are identical, otherwise return FALSE. - - - -### **Python3** - -```python -class Solution: - def checkSubTree(self, t1: TreeNode, t2: TreeNode) -> bool: - if t1 == None: - return False - if t2 == None: - return True - return self.dfs(t1,t2) or self.checkSubTree(t1.left,t2) or self.checkSubTree(t1.right,t2) - - def dfs(self, t1: TreeNode, t2: TreeNode) -> bool: - if not t1 and t2 : - return False - if not t2 and not t1: - return True - if t1.val != t2.val: - return False - else: - return self.dfs(t1.left,t2.left) and self.dfs(t1.right,t2.right) -``` - -### **Java** - -```java -class Solution { - public boolean checkSubTree(TreeNode t1, TreeNode t2) { - if (t2 == null) - return true; - if (t1 == null) - return false; - return isSubTree(t1, t2) || checkSubTree(t1.left, t2) || checkSubTree(t1.right, t2); - } - - public boolean isSubTree(TreeNode t1, TreeNode t2){ - if (t2 == null) - return true; - if (t1 == null) - return false; - if (t1.val != t2.val) - return false; - return isSubTree(t1.left,t2.left) && isSubTree(t1.right,t2.right); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/04.10.Check SubTree/Solution.py b/leetcode/lcci/04.10.Check SubTree/Solution.py deleted file mode 100644 index 3f47e4cf..00000000 --- a/leetcode/lcci/04.10.Check SubTree/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def checkSubTree(self, t1: TreeNode, t2: TreeNode) -> bool: - if t1 == None: - return False - if t2 == None: - return True - return self.dfs(t1,t2) or self.checkSubTree(t1.left,t2) or self.checkSubTree(t1.right,t2) - - def dfs(self, t1: TreeNode, t2: TreeNode) -> bool: - if not t1 and t2 : - return False - if not t2 and not t1: - return True - if t1.val != t2.val: - return False - else: - return self.dfs(t1.left,t2.left) and self.dfs(t1.right,t2.right) \ No newline at end of file diff --git a/leetcode/lcci/04.12.Paths with Sum/README_EN.md b/leetcode/lcci/04.12.Paths with Sum/README_EN.md deleted file mode 100644 index 664ff004..00000000 --- a/leetcode/lcci/04.12.Paths with Sum/README_EN.md +++ /dev/null @@ -1,125 +0,0 @@ -# [04.12. Paths with Sum](https://leetcode-cn.com/problems/paths-with-sum-lcci) - -[中文文档](/lcci/04.12.Paths%20with%20Sum/README.md) - -## Description - -

You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes).

- -

Example:
- -Given the following tree and  sum = 22,

- -
-
-              5
-
-             / \
-
-            4   8
-
-           /   / \
-
-          11  13  4
-
-         /  \    / \
-
-        7    2  5   1
-
-
- -

Output:

- -
-
-3
-
-Explanation: Paths that have sum 22 are: [5,4,11,2], [5,8,4,5], [4,11,7]
- -

Note:

- -
    -
  • node number <= 10000
  • -
- -## Solutions - -Depth-First-Search - - - -### **Python3** - -Using the idea of recursion, at each recursion to a node. - -- If root.val-sum == 0, add 1 to the result -- Consider two scenarios for inclusion or exclusion of this node from the pathway - -Special case: if the parent node of this node is in the path, this node must be included in the path (the path cannot be broken) - -```python -class Solution: - def pathSum(self, root: TreeNode, sum: int) -> int: - def dfs(root, sum, flag): - nonlocal ans - if not root: - return 0 - if sum-root.val == 0: - ans += 1 - if flag == 0: - dfs(root.left, sum, 0) - dfs(root.right, sum, 0) - dfs(root.left, sum-root.val, 1) - dfs(root.right, sum-root.val, 1) - - if not root: - return 0 - ans = 0 - dfs(root, sum, 0) - return ans -``` - -### **Java** - -Use to 2 recursive processes. - -- BFS: (traverse) traverses each tree node. -- DFS: Starting from each tree node, the nodes sum to see if sum can be satisfied. - -Note that node values can be positive or negative, and all possible paths need to be exhausted. - -```java -class Solution { - int ans = 0; - public int pathSum(TreeNode root, int sum) { - traverse(root, sum); - return ans; - } - - void traverse(TreeNode root, int sum) { - if (root == null) return; - ans += dfs(root, sum, 0); - traverse(root.left, sum); - traverse(root.right, sum); - } - - // check if sum of path is sum. - int dfs(TreeNode root, int sum, int cur) { - if (root == null) return 0; - cur += root.val; - int res = 0; - if (cur == sum) res++; - res += dfs(root.left, sum, cur); - res += dfs(root.right, sum, cur); - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/04.12.Paths with Sum/Solution.py b/leetcode/lcci/04.12.Paths with Sum/Solution.py deleted file mode 100644 index 0c0cafb5..00000000 --- a/leetcode/lcci/04.12.Paths with Sum/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -class Solution: - def pathSum(self, root: TreeNode, sum: int) -> int: - def dfs(root, sum, flag): - nonlocal ans - if not root: - return 0 - if sum-root.val == 0: - ans += 1 - if flag == 0: - dfs(root.left, sum, 0) - dfs(root.right, sum, 0) - dfs(root.left, sum-root.val, 1) - dfs(root.right, sum-root.val, 1) - - if not root: - return 0 - ans = 0 - dfs(root, sum, 0) - return ans \ No newline at end of file diff --git a/leetcode/lcci/05.01.Insert Into Bits/README_EN.md b/leetcode/lcci/05.01.Insert Into Bits/README_EN.md deleted file mode 100644 index 23ed2ae9..00000000 --- a/leetcode/lcci/05.01.Insert Into Bits/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [05.01. Insert Into Bits](https://leetcode-cn.com/problems/insert-into-bits-lcci) - -[中文文档](/lcci/05.01.Insert%20Into%20Bits/README.md) - -## Description - -

You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M = 10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i = 2, because M could not fully fit between bit 3 and bit 2.

- -

Example1:

- -
-
- Input: N = 10000000000, M = 10011, i = 2, j = 6
-
- Output: N = 10001001100
-
-
- -

Example2:

- -
-
- Input:  N = 0, M = 11111, i = 0, j = 4
-
- Output: N = 11111
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int insertBits(int N, int M, int i, int j) { - for (int k = i; k <= j; k++) { - N &= ~(1 << k); - } - return N ^ (M << i); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/05.06.Convert Integer/README_EN.md b/leetcode/lcci/05.06.Convert Integer/README_EN.md deleted file mode 100644 index 5cfc8c24..00000000 --- a/leetcode/lcci/05.06.Convert Integer/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [05.06. Convert Integer](https://leetcode-cn.com/problems/convert-integer-lcci) - -[中文文档](/lcci/05.06.Convert%20Integer/README.md) - -## Description - -

Write a function to determine the number of bits you would need to flip to convert integer A to integer B.

- -

Example1:

- -
-
- Input: A = 29 (0b11101), B = 15 (0b01111)
-
- Output: 2
-
-
- -

Example2:

- -
-
- Input: A = 1,B = 2
-
- Output: 2
-
-
- -

Note:

- -
    -
  1. -2147483648 <= A, B <= 2147483647
  2. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int convertInteger(int A, int B) { - return Integer.bitCount(A ^ B); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/05.07.Exchange/README_EN.md b/leetcode/lcci/05.07.Exchange/README_EN.md deleted file mode 100644 index 96df5b34..00000000 --- a/leetcode/lcci/05.07.Exchange/README_EN.md +++ /dev/null @@ -1,64 +0,0 @@ -# [05.07. Exchange](https://leetcode-cn.com/problems/exchange-lcci) - -[中文文档](/lcci/05.07.Exchange/README.md) - -## Description - -

Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, and so on).

- -

Example1:

- -
-
- Input: num = 2(0b10)
-
- Output 1 (0b01)
-
-
- -

Example2:

- -
-
- Input: num = 3
-
- Output: 3
-
-
- -

Note:

- -
    -
  1. 0 <= num <= 2^30 - 1
  2. -
  3. The result integer fits into 32-bit integer.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int exchangeBits(int num) { - int t1 = num >> 1; - int t2 = num << 1; - return t1 & 0x55555555 | t2 & 0xaaaaaaaa; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/08.01.Three Steps Problem/README_EN.md b/leetcode/lcci/08.01.Three Steps Problem/README_EN.md deleted file mode 100644 index 9ce39db9..00000000 --- a/leetcode/lcci/08.01.Three Steps Problem/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [08.01. Three Steps Problem](https://leetcode-cn.com/problems/three-steps-problem-lcci) - -[中文文档](/lcci/08.01.Three%20Steps%20Problem/README.md) - -## Description - -

A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so return it modulo 1000000007.

- -

Example1:

- -
-
- Input: n = 3 
-
- Output: 4
-
-
- -

Example2:

- -
-
- Input: n = 5
-
- Output: 13
-
-
- -

Note:

- -1. `1 <= n <= 1000000` - -## Solutions - - - -### **Python3** - -```python -class Solution: - def waysToStep(self, n: int) -> int: - if n < 3: - return n - a, b, c = 1, 2, 4 - for _ in range(4, n + 1): - a, b, c = b, c, (a + b + c) % 1000000007 - return c -``` - -### **Java** - -```java -class Solution { - public int waysToStep(int n) { - if (n < 3) { - return n; - } - int a = 1, b = 2, c = 4; - for (int i = 4; i <= n; ++i) { - int t = a; - a = b; - b = c; - c = ((a + b) % 1000000007 + t) % 1000000007; - } - return c; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - int waysToStep(int n) { - if (n < 3) { - return n; - } - int a = 1, b = 2, c = 4, i = 4; - while (i++ <= n) { - int t = ((a + b) % 1000000007 + c) % 1000000007; - a = b; - b = c; - c = t; - } - return c; - } -}; -``` - - diff --git a/leetcode/lcci/08.01.Three Steps Problem/Solution.c b/leetcode/lcci/08.01.Three Steps Problem/Solution.c deleted file mode 100644 index f0d26e0e..00000000 --- a/leetcode/lcci/08.01.Three Steps Problem/Solution.c +++ /dev/null @@ -1,16 +0,0 @@ -int waysToStep(int n) -{ - if (n < 3) - { - return n; - } - int a = 1, b = 2, c = 4, i = 4; - while (i++ <= n) - { - int t = ((a + b) % 1000000007 + c) % 1000000007; - a = b; - b = c; - c = t; - } - return c; -} \ No newline at end of file diff --git a/leetcode/lcci/08.01.Three Steps Problem/Solution.cpp b/leetcode/lcci/08.01.Three Steps Problem/Solution.cpp deleted file mode 100644 index 9542cafb..00000000 --- a/leetcode/lcci/08.01.Three Steps Problem/Solution.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int waysToStep(int n) { - if (n < 3) { - return n; - } - int a = 1, b = 2, c = 4, i = 4; - while (i++ <= n) { - int t = ((a + b) % 1000000007 + c) % 1000000007; - a = b; - b = c; - c = t; - } - return c; - } -}; \ No newline at end of file diff --git a/leetcode/lcci/08.01.Three Steps Problem/Solution.py b/leetcode/lcci/08.01.Three Steps Problem/Solution.py deleted file mode 100644 index ec377133..00000000 --- a/leetcode/lcci/08.01.Three Steps Problem/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def waysToStep(self, n: int) -> int: - if n < 3: - return n - a, b, c = 1, 2, 4 - for _ in range(4, n + 1): - a, b, c = b, c, (a + b + c) % 1000000007 - return c \ No newline at end of file diff --git a/leetcode/lcci/08.09.Bracket/README_EN.md b/leetcode/lcci/08.09.Bracket/README_EN.md deleted file mode 100644 index 5caf97cc..00000000 --- a/leetcode/lcci/08.09.Bracket/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [08.09. Bracket](https://leetcode-cn.com/problems/bracket-lcci) - -[中文文档](/lcci/08.09.Bracket/README.md) - -## Description - -

Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses.

- -

Note: The result set should not contain duplicated subsets.

- -

For example, given n = 3, the result should be:

- -
-
-[
-
-  "((()))",
-
-  "(()())",
-
-  "(())()",
-
-  "()(())",
-
-  "()()()"
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def generateParenthesis(self, n: int) -> List[str]: - res = [] - def generate(state, left, right): - if left > right: - return - if right == 0: - res.append(state) - return - if left > 0: - generate(state + '(', left - 1, right) - if right > 0: - generate(state + ')', left, right - 1) - generate('', n, n) - return res -``` - -### **Java** - -```java -class Solution { - List res; - - public List generateParenthesis(int n) { - res = new ArrayList<>(); - generate("", n, n); - return res; - } - - private void generate(String state, int left, int right) { - if (left > right) { - return; - } - if (right == 0) { - res.add(state); - return; - } - if (left > 0) { - generate(state + "(", left - 1, right); - } - if (right > 0) { - generate(state + ")", left, right - 1); - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/08.09.Bracket/Solution.py b/leetcode/lcci/08.09.Bracket/Solution.py deleted file mode 100644 index bbd57740..00000000 --- a/leetcode/lcci/08.09.Bracket/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def generateParenthesis(self, n: int) -> List[str]: - res = [] - def generate(state, left, right): - if left > right: - return - if right == 0: - res.append(state) - return - if left > 0: - generate(state + '(', left - 1, right) - if right > 0: - generate(state + ')', left, right - 1) - generate('', n, n) - return res \ No newline at end of file diff --git a/leetcode/lcci/08.10.Color Fill/README_EN.md b/leetcode/lcci/08.10.Color Fill/README_EN.md deleted file mode 100644 index 743b458a..00000000 --- a/leetcode/lcci/08.10.Color Fill/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [08.10. Color Fill](https://leetcode-cn.com/problems/color-fill-lcci) - -[中文文档](/lcci/08.10.Color%20Fill/README.md) - -## Description - -

Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.

- -

Example1:

- -
-
-Input: 
-
-image = [[1,1,1],[1,1,0],[1,0,1]] 
-
-sr = 1, sc = 1, newColor = 2
-
-Output: [[2,2,2],[2,2,0],[2,0,1]]
-
-Explanation: 
-
-From the center of the image (with position (sr, sc) = (1, 1)), all pixels connected 
-
-by a path of the same color as the starting pixel are colored with the new color.
-
-Note the bottom corner is not colored 2, because it is not 4-directionally connected
-
-to the starting pixel.
- -

Note:

- -
    -
  • The length of image and image[0] will be in the range [1, 50].
  • -
  • The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
  • -
  • The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { - int oldColor = image[sr][sc]; - dfs(image, sr, sc, oldColor, newColor); - return image; - } - - private void dfs(int[][] image, int sr, int sc, int oldColor, int newColor) { - if (sr < 0 || sc < 0 || sr >= image.length || sc >= image[0].length) { - return; - } - - int color = image[sr][sc]; - if (color != newColor && color == oldColor) { - image[sr][sc] = newColor; - // up down left right - dfs(image, sr, sc + 1, oldColor, newColor); - dfs(image, sr, sc - 1, oldColor, newColor); - dfs(image, sr + 1, sc, oldColor, newColor); - dfs(image, sr - 1, sc, oldColor, newColor); - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/10.09.Sorted Matrix Search/README_EN.md b/leetcode/lcci/10.09.Sorted Matrix Search/README_EN.md deleted file mode 100644 index 5f7eb85e..00000000 --- a/leetcode/lcci/10.09.Sorted Matrix Search/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [10.09. Sorted Matrix Search](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) - -[中文文档](/lcci/10.09.Sorted%20Matrix%20Search/README.md) - -## Description - -

Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element.

- -

Example:

- -

Given matrix:

- -
-
-[
-
-  [1,   4,  7, 11, 15],
-
-  [2,   5,  8, 12, 19],
-
-  [3,   6,  9, 16, 22],
-
-  [10, 13, 14, 17, 24],
-
-  [18, 21, 23, 26, 30]
-
-]
-
-
- -

Given target = 5, return true.

- -

Given target = 20, return false.

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: - if not matrix or not matrix[0]: - return False - rows, cols = len(matrix), len(matrix[0]) - i, j = rows - 1, 0 - while i >= 0 and j < cols: - if matrix[i][j] == target: - return True - if matrix[i][j] > target: - i -= 1 - else: - j += 1 - return False - -``` - -### **Java** - -```java -class Solution { - public boolean searchMatrix(int[][] matrix, int target) { - if (matrix == null || matrix.length == 0 || matrix[0] == null || matrix[0].length == 0) { - return false; - } - int rows = matrix.length, cols = matrix[0].length; - int i = rows - 1, j = 0; - while (i >= 0 && j < cols) { - if (matrix[i][j] == target) { - return true; - } - if (matrix[i][j] > target) { - --i; - } else { - ++j; - } - } - return false; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/10.09.Sorted Matrix Search/Solution.py b/leetcode/lcci/10.09.Sorted Matrix Search/Solution.py deleted file mode 100644 index 7b3bb120..00000000 --- a/leetcode/lcci/10.09.Sorted Matrix Search/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: - if not matrix or not matrix[0]: - return False - rows, cols = len(matrix), len(matrix[0]) - i, j = rows - 1, 0 - while i >= 0 and j < cols: - if matrix[i][j] == target: - return True - if matrix[i][j] > target: - i -= 1 - else: - j += 1 - return False diff --git a/leetcode/lcci/16.01.Swap Numbers/README_EN.md b/leetcode/lcci/16.01.Swap Numbers/README_EN.md deleted file mode 100644 index 46af646f..00000000 --- a/leetcode/lcci/16.01.Swap Numbers/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [16.01. Swap Numbers](https://leetcode-cn.com/problems/swap-numbers-lcci) - -[中文文档](/lcci/16.01.Swap%20Numbers/README.md) - -## Description - -

Write a function to swap a number in place (that is, without temporary vari­ ables).

- -

Example:

- -
-
-Input: numbers = [1,2]
-
-Output: [2,1]
-
-
- -

Note:

- -
    -
  • numbers.length == 2
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def swapNumbers(self, numbers: List[int]) -> List[int]: - numbers[0], numbers[1] = numbers[1], numbers[0] - return numbers -``` - -### **Java** - -```java -class Solution { - public int[] swapNumbers(int[] numbers) { - numbers[0] = numbers[0] ^ numbers[1]; - numbers[1] = numbers[0] ^ numbers[1]; - numbers[0] = numbers[0] ^ numbers[1]; - return numbers; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/16.01.Swap Numbers/Solution.py b/leetcode/lcci/16.01.Swap Numbers/Solution.py deleted file mode 100644 index b800b42b..00000000 --- a/leetcode/lcci/16.01.Swap Numbers/Solution.py +++ /dev/null @@ -1,4 +0,0 @@ -class Solution: - def swapNumbers(self, numbers: List[int]) -> List[int]: - numbers[0], numbers[1] = numbers[1], numbers[0] - return numbers diff --git a/leetcode/lcci/16.06.Smallest Difference/README_EN.md b/leetcode/lcci/16.06.Smallest Difference/README_EN.md deleted file mode 100644 index fb2b2b84..00000000 --- a/leetcode/lcci/16.06.Smallest Difference/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [16.06. Smallest Difference](https://leetcode-cn.com/problems/smallest-difference-lcci) - -[中文文档](/lcci/16.06.Smallest%20Difference/README.md) - -## Description - -

Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference.

- -

Example:

- -
-
-Input: {1, 3, 15, 11, 2}, {23, 127, 235, 19, 8}
-
-Output:  3, the pair (11, 8)
-
-
- -

Note:

- -
    -
  • 1 <= a.length, b.length <= 100000
  • -
  • -2147483648 <= a[i], b[i] <= 2147483647
  • -
  • The result is in the range [-2147483648, 2147483647]
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def smallestDifference(self, a: List[int], b: List[int]) -> int: - a.sort() - b.sort() - i, j, res = 0, 0, 2147483647 - m, n = len(a), len(b) - while i < m and j < n: - if a[i] == b[j]: return 0 - res = min(res, abs(a[i] - b[j])) - if a[i] > b[j]: j += 1 - else: i += 1 - return res - -``` - -### **Java** - -```java -class Solution { - public int smallestDifference(int[] a, int[] b) { - Arrays.sort(a); - Arrays.sort(b); - int m = a.length, n = b.length; - int i = 0, j = 0; - long res = Long.MAX_VALUE; - while (i < m && j < n) { - if (a[i] == b[j]) return 0; - res = Math.min(res, Math.abs((long) a[i] - (long) b[j])); - if (a[i] > b[j]) ++j; - else ++i; - } - return (int) res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/16.06.Smallest Difference/Solution.py b/leetcode/lcci/16.06.Smallest Difference/Solution.py deleted file mode 100644 index c0ceab87..00000000 --- a/leetcode/lcci/16.06.Smallest Difference/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def smallestDifference(self, a: List[int], b: List[int]) -> int: - a.sort() - b.sort() - i, j, res = 0, 0, 2147483647 - m, n = len(a), len(b) - while i < m and j < n: - if a[i] == b[j]: return 0 - res = min(res, abs(a[i] - b[j])) - if a[i] > b[j]: j += 1 - else: i += 1 - return res - \ No newline at end of file diff --git a/leetcode/lcci/16.10.Living People/README_EN.md b/leetcode/lcci/16.10.Living People/README_EN.md deleted file mode 100644 index 4ef5378a..00000000 --- a/leetcode/lcci/16.10.Living People/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [16.10. Living People](https://leetcode-cn.com/problems/living-people-lcci) - -[中文文档](/lcci/16.10.Living%20People/README.md) - -## Description - -

Given a list of people with their birth and death years, implement a method to compute the year with the most number of people alive. You may assume that all people were born between 1900 and 2000 (inclusive). If a person was alive during any portion of that year, they should be included in that year's count. For example, Person (birth= 1908, death= 1909) is included in the counts for both 1908 and 1909.

- -

If there are more than one years that have the most number of people alive, return the smallest one.

- -

Example:

- -
-
-Input: 
-
-birth = {1900, 1901, 1950}
-
-death = {1948, 1951, 2000}
-
-Output:  1901
-
-
- -

Note:

- -
    -
  • 0 < birth.length == death.length <= 10000
  • -
  • birth[i] <= death[i]
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxAliveYear(self, birth: List[int], death: List[int]) -> int: - years = [0] * 101 - for i in range(len(birth)): - start = birth[i] - 1900 - end = death[i] - 1900 - for j in range(start, end + 1): - years[j] += 1 - max_v = years[0] - res = 0 - for i in range(1, 101): - if years[i] > max_v: - max_v = years[i] - res = i - return 1900 + res -``` - -### **Java** - -```java -class Solution { - public int maxAliveYear(int[] birth, int[] death) { - int[] years = new int[101]; - int n = birth.length; - for (int i = 0; i < n; ++i) { - int start = birth[i] - 1900; - int end = death[i] - 1900; - for (int j = start; j <= end; ++j) { - ++years[j]; - } - } - int max = years[0]; - int res = 0; - for (int i = 1; i < 101; ++i) { - if (years[i] > max) { - max = years[i]; - res = i; - } - } - return 1900 + res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/16.10.Living People/Solution.py b/leetcode/lcci/16.10.Living People/Solution.py deleted file mode 100644 index 0aa0c68f..00000000 --- a/leetcode/lcci/16.10.Living People/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def maxAliveYear(self, birth: List[int], death: List[int]) -> int: - years = [0] * 101 - for i in range(len(birth)): - start = birth[i] - 1900 - end = death[i] - 1900 - for j in range(start, end + 1): - years[j] += 1 - max_v = years[0] - res = 0 - for i in range(1, 101): - if years[i] > max_v: - max_v = years[i] - res = i - return 1900 + res \ No newline at end of file diff --git a/leetcode/lcci/16.11.Diving Board/README_EN.md b/leetcode/lcci/16.11.Diving Board/README_EN.md deleted file mode 100644 index 0ef65fac..00000000 --- a/leetcode/lcci/16.11.Diving Board/README_EN.md +++ /dev/null @@ -1,56 +0,0 @@ -# [16.11. Diving Board](https://leetcode-cn.com/problems/diving-board-lcci) - -[中文文档](/lcci/16.11.Diving%20Board/README.md) - -## Description - -

You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks of wood. Write a method to generate all possible lengths for the diving board.

- -

return all lengths in non-decreasing order.

- -

Example:

- -
-
-Input: 
-
-shorter = 1
-
-longer = 2
-
-k = 3
-
-Output:  {3,4,5,6}
-
-
- -

Note:

- -
    -
  • 0 < shorter <= longer
  • -
  • 0 <= k <= 100000
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/16.21.Sum Swap/README_EN.md b/leetcode/lcci/16.21.Sum Swap/README_EN.md deleted file mode 100644 index 4f34d930..00000000 --- a/leetcode/lcci/16.21.Sum Swap/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [16.21. Sum Swap](https://leetcode-cn.com/problems/sum-swap-lcci) - -[中文文档](/lcci/16.21.Sum%20Swap/README.md) - -## Description - -

Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.

- -

Return an array, where the first element is the element in the first array that will be swapped, and the second element is another one in the second array. If there are more than one answers, return any one of them. If there is no answer, return an empty array.

- -

Example:

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

Example:

- -
-
-Input: array1 = [1, 2, 3], array2 = [4, 5, 6]
-
-Output: []
- -

Note:

- -
    -
  • 1 <= array1.length, array2.length <= 100000
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findSwapValues(self, array1: List[int], array2: List[int]) -> List[int]: - diff = sum(array1) - sum(array2) - if diff & 1: return [] - diff >>= 1 - s = set(array2) - for e in array1: - if (e - diff) in s: return [e, e - diff] - return [] -``` - -### **Java** - -```java -class Solution { - public int[] findSwapValues(int[] array1, int[] array2) { - int diff = sum(array1) - sum(array2); - if ((diff & 1) == 1) { - return new int[]{}; - } - diff >>= 1; - Set s = Arrays.stream(array2).boxed().collect(Collectors.toSet()); - for (int e : array1) { - if (s.contains((e - diff))) { - return new int[]{e, e - diff}; - } - } - return new int[]{}; - } - - private int sum(int[] array) { - int res = 0; - for (int e : array) { - res += e; - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/16.21.Sum Swap/Solution.py b/leetcode/lcci/16.21.Sum Swap/Solution.py deleted file mode 100644 index 84f4668e..00000000 --- a/leetcode/lcci/16.21.Sum Swap/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def findSwapValues(self, array1: List[int], array2: List[int]) -> List[int]: - diff = sum(array1) - sum(array2) - if diff & 1: return [] - diff >>= 1 - s = set(array2) - for e in array1: - if (e - diff) in s: return [e, e - diff] - return [] diff --git a/leetcode/lcci/17.01.Add Without Plus/README_EN.md b/leetcode/lcci/17.01.Add Without Plus/README_EN.md deleted file mode 100644 index 1dee2f83..00000000 --- a/leetcode/lcci/17.01.Add Without Plus/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [17.01. Add Without Plus](https://leetcode-cn.com/problems/add-without-plus-lcci) - -[中文文档](/lcci/17.01.Add%20Without%20Plus/README.md) - -## Description - -

Write a function that adds two numbers. You should not use + or any arithmetic operators.

- -

Example:

- -
-
-Input: a = 1, b = 1
-
-Output: 2
- -

 

- -

Note:

- -
    -
  • a and b may be 0 or negative.
  • -
  • The result fits in 32-bit integer.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int add(int a, int b) { - int sum = 0, carry = 0; - while (b != 0) { - sum = a ^ b; - carry = (a & b) << 1; - a = sum; - b = carry; - } - return a; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.04.Missing Number/README_EN.md b/leetcode/lcci/17.04.Missing Number/README_EN.md deleted file mode 100644 index 8d38e6e6..00000000 --- a/leetcode/lcci/17.04.Missing Number/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [17.04. Missing Number](https://leetcode-cn.com/problems/missing-number-lcci) - -[中文文档](/lcci/17.04.Missing%20Number/README.md) - -## Description - -

An array contains all the integers from 0 to n, except for one number which is missing.  Write code to find the missing integer. Can you do it in O(n) time?

- -

Note: This problem is slightly different from the original one the book.

- -

Example 1:

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

 

- -

Example 2:

- -
-
-Input: [9,6,4,2,3,5,7,0,1]
-
-Output: 8
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def missingNumber(self, nums: List[int]) -> int: - res = 0 - for i, num in enumerate(nums): - res ^= i - res ^= num - res ^= len(nums) - return res -``` - -### **Java** - -```java -class Solution { - public int missingNumber(int[] nums) { - int res = 0, n = nums.length; - for (int i = 0; i < n; ++i) { - res ^= i; - res ^= nums[i]; - } - res ^= n; - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.04.Missing Number/Solution.py b/leetcode/lcci/17.04.Missing Number/Solution.py deleted file mode 100644 index 8de166bf..00000000 --- a/leetcode/lcci/17.04.Missing Number/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def missingNumber(self, nums: List[int]) -> int: - res = 0 - for i, num in enumerate(nums): - res ^= i - res ^= num - res ^= len(nums) - return res diff --git a/leetcode/lcci/17.12.BiNode/README_EN.md b/leetcode/lcci/17.12.BiNode/README_EN.md deleted file mode 100644 index 29a4fefe..00000000 --- a/leetcode/lcci/17.12.BiNode/README_EN.md +++ /dev/null @@ -1,104 +0,0 @@ -# [17.12. BiNode](https://leetcode-cn.com/problems/binode-lcci) - -[中文文档](/lcci/17.12.BiNode/README.md) - -## Description - -

The data structure TreeNode is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with TreeNode) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).

- -

Return the head node of the linked list after converting.

- -

Note: This problem is slightly different from the original one in the book.

- -

 

- -

Example:

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

Note:

- -
    -
  • The number of nodes will not exceed 100000.
  • -
- -## Solutions - -See [897. Increasing Order Search Tree](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md). - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def convertBiNode(self, root: TreeNode) -> TreeNode: - if root is None: - return None - left = self.convertBiNode(root.left) - right = self.convertBiNode(root.right) - if left is None: - root.right = right - return root - res = left - while left and left.right: - left = left.right - left.right = root - root.right = right - root.left = None - return res -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public TreeNode convertBiNode(TreeNode root) { - if (root == null) return null; - TreeNode left = convertBiNode(root.left); - TreeNode right = convertBiNode(root.right); - if (left == null) { - root.right = right; - return root; - } - TreeNode res = left; - while (left != null && left.right != null) { - left = left.right; - } - left.right = root; - root.right = right; - root.left = null; - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.12.BiNode/Solution.py b/leetcode/lcci/17.12.BiNode/Solution.py deleted file mode 100644 index b94eedc4..00000000 --- a/leetcode/lcci/17.12.BiNode/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def convertBiNode(self, root: TreeNode) -> TreeNode: - if root is None: - return None - left = self.convertBiNode(root.left) - right = self.convertBiNode(root.right) - if left is None: - root.right = right - return root - res = left - while left and left.right: - left = left.right - left.right = root - root.right = right - root.left = None - return res diff --git a/leetcode/lcci/17.13.Re-Space/README_EN.md b/leetcode/lcci/17.13.Re-Space/README_EN.md deleted file mode 100644 index 7f0ddb61..00000000 --- a/leetcode/lcci/17.13.Re-Space/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [17.13. Re-Space](https://leetcode-cn.com/problems/re-space-lcci) - -[中文文档](/lcci/17.13.Re-Space/README.md) - -## Description - -

Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeritstilldidntboot''. You'll deal with the punctuation and capi­talization later; right now you need to re-insert the spaces. Most of the words are in a dictionary but a few are not. Given a dictionary (a list of strings) and the document (a string), design an algorithm to unconcatenate the document in a way that minimizes the number of unrecognized characters. Return the number of unrecognized characters.

- -

Note: This problem is slightly different from the original one in the book.

- -

 

- -

Example:

- -
-
-Input: 
-
-dictionary = ["looked","just","like","her","brother"]
-
-sentence = "jesslookedjustliketimherbrother"
-
-Output:  7
-
-Explanation:  After unconcatenating, we got "jess looked just like tim her brother", which containing 7 unrecognized characters.
-
-
- -

Note:

- -
    -
  • 0 <= len(sentence) <= 1000
  • -
  • The total number of characters in dictionary is less than or equal to 150000.
  • -
  • There are only lowercase letters in dictionary and sentence.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.16.The Masseuse/README_EN.md b/leetcode/lcci/17.16.The Masseuse/README_EN.md deleted file mode 100644 index b296f4fc..00000000 --- a/leetcode/lcci/17.16.The Masseuse/README_EN.md +++ /dev/null @@ -1,101 +0,0 @@ -# [17.16. The Masseuse](https://leetcode-cn.com/problems/the-masseuse-lcci) - -[中文文档](/lcci/17.16.The%20Masseuse/README.md) - -## Description - -

A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any adjacent requests. Given a sequence of back-to-back appoint­ ment requests, find the optimal (highest total booked minutes) set the masseuse can honor. Return the number of minutes.

- -

Note: This problem is slightly different from the original one in the book.

- -

 

- -

Example 1:

- -
-
-Input:  [1,2,3,1]
-
-Output:  4
-
-Explanation:  Accept request 1 and 3, total minutes = 1 + 3 = 4
-
-
- -

Example 2:

- -
-
-Input:  [2,7,9,3,1]
-
-Output:  12
-
-Explanation:  Accept request 1, 3 and 5, total minutes = 2 + 9 + 1 = 12
-
-
- -

Example 3:

- -
-
-Input:  [2,1,4,5,3,1,1,3]
-
-Output:  12
-
-Explanation:  Accept request 1, 3, 5 and 8, total minutes = 2 + 4 + 3 + 3 = 12
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def massage(self, nums: List[int]) -> int: - if not nums: - return 0 - n = len(nums) - if n < 2: - return nums[0] - a, b = nums[0], max(nums[0], nums[1]) - res = b - for i in range(2, n): - res = max(a + nums[i], b) - a, b = b, res - return res -``` - -### **Java** - -```java -class Solution { - public int massage(int[] nums) { - if (nums == null) { - return 0; - } - int n = nums.length; - if (n < 2) { - return n == 0 ? 0 : nums[0]; - } - int a = nums[0], b = Math.max(nums[0], nums[1]); - int res = b; - for (int i = 2; i < n; ++i) { - res = Math.max(a + nums[i], b); - a = b; - b = res; - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.16.The Masseuse/Solution.py b/leetcode/lcci/17.16.The Masseuse/Solution.py deleted file mode 100644 index 869bdef3..00000000 --- a/leetcode/lcci/17.16.The Masseuse/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def massage(self, nums: List[int]) -> int: - if not nums: - return 0 - n = len(nums) - if n < 2: - return nums[0] - a, b = nums[0], max(nums[0], nums[1]) - res = b - for i in range(2, n): - res = max(a + nums[i], b) - a, b = b, res - return res \ No newline at end of file diff --git a/leetcode/lcci/17.19.Missing Two/README_EN.md b/leetcode/lcci/17.19.Missing Two/README_EN.md deleted file mode 100644 index b30dbe04..00000000 --- a/leetcode/lcci/17.19.Missing Two/README_EN.md +++ /dev/null @@ -1,117 +0,0 @@ -# [17.19. Missing Two](https://leetcode-cn.com/problems/missing-two-lcci) - -[中文文档](/lcci/17.19.Missing%20Two/README.md) - -## Description - -

You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space?

- -

You can return the missing numbers in any order.

- -

Example 1:

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

Example 2:

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

Note:

- -
    -
  • nums.length <= 30000
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def missingTwo(self, nums: List[int]) -> List[int]: - res, n = 0, len(nums) - for i in range(n): - res ^= nums[i] - res ^= (i + 1) - res ^= (n + 1) - res ^= (n + 2) - pos = 0 - while (res & 1) == 0: - pos += 1 - res >>= 1 - - a = b = 0 - for num in nums: - t = num >> pos - if (t & 1) == 0: - a ^= num - else: - b ^= num - - for i in range(1, n + 3): - t = i >> pos - if (t & 1) == 0: - a ^= i - else: - b ^= i - return [a, b] -``` - -### **Java** - -```java -class Solution { - public int[] missingTwo(int[] nums) { - int res = 0, n = nums.length; - for (int i = 0; i < n; ++i) { - res ^= nums[i]; - res ^= (i + 1); - } - res ^= (n + 1); - res ^= (n + 2); - - int pos = 0; - while ((res & 1) == 0) { - pos += 1; - res >>= 1; - } - - int a = 0, b = 0; - for (int num : nums) { - int t = num >> pos; - if ((t & 1) == 0) { - a ^= num; - } else { - b ^= num; - } - } - for (int i = 1; i <= n + 2; ++i) { - int t = i >> pos; - if ((t & 1) == 0) { - a ^= i; - } else { - b ^= i; - } - } - return new int[]{a, b}; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.19.Missing Two/Solution.py b/leetcode/lcci/17.19.Missing Two/Solution.py deleted file mode 100644 index 0ca630d9..00000000 --- a/leetcode/lcci/17.19.Missing Two/Solution.py +++ /dev/null @@ -1,28 +0,0 @@ -class Solution: - def missingTwo(self, nums: List[int]) -> List[int]: - res, n = 0, len(nums) - for i in range(n): - res ^= nums[i] - res ^= (i + 1) - res ^= (n + 1) - res ^= (n + 2) - pos = 0 - while (res & 1) == 0: - pos += 1 - res >>= 1 - - a = b = 0 - for num in nums: - t = num >> pos - if (t & 1) == 0: - a ^= num - else: - b ^= num - - for i in range(1, n + 3): - t = i >> pos - if (t & 1) == 0: - a ^= i - else: - b ^= i - return [a, b] diff --git a/leetcode/lcci/17.20.Continuous Median/README_EN.md b/leetcode/lcci/17.20.Continuous Median/README_EN.md deleted file mode 100644 index 5d7b85c5..00000000 --- a/leetcode/lcci/17.20.Continuous Median/README_EN.md +++ /dev/null @@ -1,115 +0,0 @@ -# [17.20. Continuous Median](https://leetcode-cn.com/problems/continuous-median-lcci) - -[中文文档](/lcci/17.20.Continuous%20Median/README.md) - -## Description - -

Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.

- -

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

- -

For example,

- -

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

- -

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

- -

Design a data structure that supports the following two operations:

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

Example:

- -
-
-addNum(1)
-
-addNum(2)
-
-findMedian() -> 1.5
-
-addNum(3) 
-
-findMedian() -> 2
-
-
- -## Solutions - - - -### **Python3** - -```python -class MedianFinder: - - def __init__(self): - """ - initialize your data structure here. - """ - self.max_heap = [] - self.min_heap = [] - - - def addNum(self, num: int) -> None: - if len(self.max_heap) == len(self.min_heap): - heapq.heappush(self.min_heap, -heapq.heappushpop(self.max_heap, -num)) - else: - heapq.heappush(self.max_heap, -heapq.heappushpop(self.min_heap, num)) - - def findMedian(self) -> float: - return (-self.max_heap[0] + self.min_heap[0]) / 2 if len(self.max_heap) == len(self.min_heap) else self.min_heap[0] - - -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() -``` - -### **Java** - -```java -class MedianFinder { - private Queue minHeap; - private Queue maxHeap; - - /** initialize your data structure here. */ - public MedianFinder() { - minHeap = new PriorityQueue<>(); - maxHeap = new PriorityQueue<>((a, b) -> b - a); - } - - public void addNum(int num) { - if (minHeap.size() == maxHeap.size()) { - maxHeap.offer(num); - minHeap.offer(maxHeap.poll()); - } else { - minHeap.offer(num); - maxHeap.offer(minHeap.poll()); - } - } - - public double findMedian() { - return minHeap.size() == maxHeap.size() ? (minHeap.peek() + maxHeap.peek()) / 2.0 : minHeap.peek(); - } -} - -/** - * Your MedianFinder object will be instantiated and called as such: - * MedianFinder obj = new MedianFinder(); - * obj.addNum(num); - * double param_2 = obj.findMedian(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/lcci/17.20.Continuous Median/Solution.py b/leetcode/lcci/17.20.Continuous Median/Solution.py deleted file mode 100644 index 2af935d6..00000000 --- a/leetcode/lcci/17.20.Continuous Median/Solution.py +++ /dev/null @@ -1,24 +0,0 @@ -class MedianFinder: - - def __init__(self): - """ - initialize your data structure here. - """ - self.max_heap = [] - self.min_heap = [] - - - def addNum(self, num: int) -> None: - if len(self.max_heap) == len(self.min_heap): - heapq.heappush(self.min_heap, -heapq.heappushpop(self.max_heap, -num)) - else: - heapq.heappush(self.max_heap, -heapq.heappushpop(self.min_heap, num)) - - def findMedian(self) -> float: - return (-self.max_heap[0] + self.min_heap[0]) / 2 if len(self.max_heap) == len(self.min_heap) else self.min_heap[0] - - -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() diff --git a/leetcode/lcci/README_EN.md b/leetcode/lcci/README_EN.md deleted file mode 100644 index 9ecb4fc1..00000000 --- a/leetcode/lcci/README_EN.md +++ /dev/null @@ -1,125 +0,0 @@ -# [_Cracking the Coding Interview, 6th Edition_](http://ahmed-badawy.com/blog/wp-content/uploads/2018/10/Cracking-the-Coding-Interview-6th-Edition-189-Programming-Questions-and-Solutions.pdf) - -_Cracking the Coding Interview, 6th Edition_ is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hundreds of software engineers. The result is this book. - -[中文文档](/lcci/README.md) - -## Solutions - -Press Control+F(or Command+F on the Mac) to search anything you want. - -| # | Solution | Tag | Difficulty | -| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------- | -| [01.01](https://leetcode-cn.com/problems/is-unique-lcci) | [Is Unique](/lcci/01.01.Is%20Unique/README_EN.md) | `Array` | Easy | -| [01.02](https://leetcode-cn.com/problems/check-permutation-lcci) | [Check Permutation](/lcci/01.02.Check%20Permutation/README_EN.md) | `Array`,`String` | Easy | -| [01.03](https://leetcode-cn.com/problems/string-to-url-lcci) | [String to URL](/lcci/01.03.String%20to%20URL/README_EN.md) | `String` | Easy | -| [01.04](https://leetcode-cn.com/problems/palindrome-permutation-lcci) | [Palindrome Permutation](/lcci/01.04.Palindrome%20Permutation/README_EN.md) | `Hash Table`,`String` | Easy | -| [01.05](https://leetcode-cn.com/problems/one-away-lcci) | [One Away](/lcci/01.05.One%20Away/README_EN.md) | `String`,`Dynamic Programming` | Medium | -| [01.06](https://leetcode-cn.com/problems/compress-string-lcci) | [Compress String](/lcci/01.06.Compress%20String/README_EN.md) | `String` | Easy | -| [01.07](https://leetcode-cn.com/problems/rotate-matrix-lcci) | [Rotate Matrix](/lcci/01.07.Rotate%20Matrix/README_EN.md) | `Array` | Medium | -| [01.08](https://leetcode-cn.com/problems/zero-matrix-lcci) | [Zero Matrix](/lcci/01.08.Zero%20Matrix/README_EN.md) | `Array` | Medium | -| [01.09](https://leetcode-cn.com/problems/string-rotation-lcci) | [String Rotation](/lcci/01.09.String%20Rotation/README_EN.md) | `String` | Easy | -| [02.01](https://leetcode-cn.com/problems/remove-duplicate-node-lcci) | [Remove Duplicate Node](/lcci/02.01.Remove%20Duplicate%20Node/README_EN.md) | `Linked List` | Easy | -| [02.02](https://leetcode-cn.com/problems/kth-node-from-end-of-list-lcci) | [Kth Node From End of List](/lcci/02.02.Kth%20Node%20From%20End%20of%20List/README_EN.md) | `Linked List`,`Two Pointers` | Easy | -| [02.03](https://leetcode-cn.com/problems/delete-middle-node-lcci) | [Delete Middle Node](/lcci/02.03.Delete%20Middle%20Node/README_EN.md) | `Linked List` | Easy | -| [02.04](https://leetcode-cn.com/problems/partition-list-lcci) | [Partition List](/lcci/02.04.Partition%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | -| [02.05](https://leetcode-cn.com/problems/sum-lists-lcci) | [Sum Lists](/lcci/02.05.Sum%20Lists/README_EN.md) | `Linked List`,`Math` | Medium | -| [02.06](https://leetcode-cn.com/problems/palindrome-linked-list-lcci) | [Palindrome Linked List](/lcci/02.06.Palindrome%20Linked%20List/README_EN.md) | `Linked List` | Easy | -| [02.07](https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci) | [Intersection of Two Linked Lists](/lcci/02.07.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) | `Linked List` | Easy | -| [02.08](https://leetcode-cn.com/problems/linked-list-cycle-lcci) | [Linked List Cycle](/lcci/02.08.Linked%20List%20Cycle/README_EN.md) | `Linked List` | Medium | -| [03.01](https://leetcode-cn.com/problems/three-in-one-lcci) | [Three in One](/lcci/03.01.Three%20in%20One/README_EN.md) | `Design` | Easy | -| [03.02](https://leetcode-cn.com/problems/min-stack-lcci) | [Min Stack](/lcci/03.02.Min%20Stack/README_EN.md) | `Stack` | Easy | -| [03.03](https://leetcode-cn.com/problems/stack-of-plates-lcci) | [Stack of Plates](/lcci/03.03.Stack%20of%20Plates/README_EN.md) | `Design` | Medium | -| [03.04](https://leetcode-cn.com/problems/implement-queue-using-stacks-lcci) | [Implement Queue using Stacks](/lcci/03.04.Implement%20Queue%20using%20Stacks/README_EN.md) | `Stack` | Easy | -| [03.05](https://leetcode-cn.com/problems/sort-of-stacks-lcci) | [Sort of Stacks](/lcci/03.05.Sort%20of%20Stacks/README_EN.md) | `Design` | Medium | -| [03.06](https://leetcode-cn.com/problems/animal-shelter-lcci) | [Animal Shelter](/lcci/03.06.Animal%20Shelter/README_EN.md) | `Design` | Easy | -| [04.01](https://leetcode-cn.com/problems/route-between-nodes-lcci) | [Route Between Nodes](/lcci/04.01.Route%20Between%20Nodes/README_EN.md) | `Graph` | Medium | -| [04.02](https://leetcode-cn.com/problems/minimum-height-tree-lcci) | [Minimum Height Tree](/lcci/04.02.Minimum%20Height%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | -| [04.03](https://leetcode-cn.com/problems/list-of-depth-lcci) | [List of Depth](/lcci/04.03.List%20of%20Depth/README_EN.md) | `Tree`,`Breadth-first Search` | Medium | -| [04.04](https://leetcode-cn.com/problems/check-balance-lcci) | [Check Balance](/lcci/04.04.Check%20Balance/README_EN.md) | `Tree`,`Depth-first Search` | Easy | -| [04.05](https://leetcode-cn.com/problems/legal-binary-search-tree-lcci) | [Legal Binary Search Tree](/lcci/04.05.Legal%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [04.06](https://leetcode-cn.com/problems/successor-lcci) | [Successor](/lcci/04.06.Successor/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [04.08](https://leetcode-cn.com/problems/first-common-ancestor-lcci) | [First Common Ancestor](/lcci/04.08.First%20Common%20Ancestor/README_EN.md) | `Tree` | Medium | -| [04.09](https://leetcode-cn.com/problems/bst-sequences-lcci) | [BST Sequences](/lcci/04.09.BST%20Sequences/README_EN.md) | `Tree`,`Dynamic Programming` | Hard | -| [04.10](https://leetcode-cn.com/problems/check-subtree-lcci) | [Check SubTree](/lcci/04.10.Check%20SubTree/README_EN.md) | `Tree` | Medium | -| [04.12](https://leetcode-cn.com/problems/paths-with-sum-lcci) | [Paths with Sum](/lcci/04.12.Paths%20with%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Medium | -| [05.01](https://leetcode-cn.com/problems/insert-into-bits-lcci) | [Insert Into Bits](/lcci/05.01.Insert%20Into%20Bits/README_EN.md) | `Bit Manipulation` | Easy | -| [05.02](https://leetcode-cn.com/problems/bianry-number-to-string-lcci) | [Bianry Number to String](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md) | `String` | Medium | -| [05.03](https://leetcode-cn.com/problems/reverse-bits-lcci) | [Reverse Bits](/lcci/05.03.Reverse%20Bits/README_EN.md) | `Bit Manipulation` | Easy | -| [05.04](https://leetcode-cn.com/problems/closed-number-lcci) | [Closed Number](/lcci/05.04.Closed%20Number/README_EN.md) | `Bit Manipulation` | Medium | -| [05.06](https://leetcode-cn.com/problems/convert-integer-lcci) | [Convert Integer](/lcci/05.06.Convert%20Integer/README_EN.md) | `Bit Manipulation` | Easy | -| [05.07](https://leetcode-cn.com/problems/exchange-lcci) | [Exchange](/lcci/05.07.Exchange/README_EN.md) | `Bit Manipulation` | Easy | -| [05.08](https://leetcode-cn.com/problems/draw-line-lcci) | [Draw Line](/lcci/05.08.Draw%20Line/README_EN.md) | `Array` | Medium | -| [08.01](https://leetcode-cn.com/problems/three-steps-problem-lcci) | [Three Steps Problem](/lcci/08.01.Three%20Steps%20Problem/README_EN.md) | `Dynamic Programming` | Easy | -| [08.02](https://leetcode-cn.com/problems/robot-in-a-grid-lcci) | [Robot in a Grid](/lcci/08.02.Robot%20in%20a%20Grid/README_EN.md) | `Dynamic Programming` | Medium | -| [08.03](https://leetcode-cn.com/problems/magic-index-lcci) | [Magic Index](/lcci/08.03.Magic%20Index/README_EN.md) | `Array`,`Binary Search` | Easy | -| [08.04](https://leetcode-cn.com/problems/power-set-lcci) | [Power Set](/lcci/08.04.Power%20Set/README_EN.md) | `Bit Manipulation`,`Array`,`Backtracking` | Medium | -| [08.05](https://leetcode-cn.com/problems/recursive-mulitply-lcci) | [Recursive Mulitply](/lcci/08.05.Recursive%20Mulitply/README_EN.md) | `Recursion` | Medium | -| [08.06](https://leetcode-cn.com/problems/hanota-lcci) | [Hanota](/lcci/08.06.Hanota/README_EN.md) | `Recursion` | Easy | -| [08.07](https://leetcode-cn.com/problems/permutation-i-lcci) | [Permutation I](/lcci/08.07.Permutation%20I/README_EN.md) | `Backtracking` | Medium | -| [08.08](https://leetcode-cn.com/problems/permutation-ii-lcci) | [Permutation II](/lcci/08.08.Permutation%20II/README_EN.md) | `Backtracking` | Medium | -| [08.09](https://leetcode-cn.com/problems/bracket-lcci) | [Bracket](/lcci/08.09.Bracket/README_EN.md) | `String`,`Backtracking` | Medium | -| [08.10](https://leetcode-cn.com/problems/color-fill-lcci) | [Color Fill](/lcci/08.10.Color%20Fill/README_EN.md) | `Depth-first Search` | Easy | -| [08.11](https://leetcode-cn.com/problems/coin-lcci) | [Coin](/lcci/08.11.Coin/README_EN.md) | `Dynamic Programming` | Medium | -| [08.12](https://leetcode-cn.com/problems/eight-queens-lcci) | [Eight Queens](/lcci/08.12.Eight%20Queens/README_EN.md) | `Backtracking` | Hard | -| [08.13](https://leetcode-cn.com/problems/pile-box-lcci) | [Pile Box](/lcci/08.13.Pile%20Box/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | -| [08.14](https://leetcode-cn.com/problems/boolean-evaluation-lcci) | [Boolean Evaluation](/lcci/08.14.Boolean%20Evaluation/README_EN.md) | `Stack`,`String` | Medium | -| [10.01](https://leetcode-cn.com/problems/sorted-merge-lcci) | [Sorted Merge](/lcci/10.01.Sorted%20Merge/README_EN.md) | `Array`,`Two Pointers` | Easy | -| [10.02](https://leetcode-cn.com/problems/group-anagrams-lcci) | [Group Anagrams](/lcci/10.02.Group%20Anagrams/README_EN.md) | `Hash Table`,`String` | Medium | -| [10.03](https://leetcode-cn.com/problems/search-rotate-array-lcci) | [Search Rotate Array](/lcci/10.03.Search%20Rotate%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | -| [10.05](https://leetcode-cn.com/problems/sparse-array-search-lcci) | [Sparse Array Search](/lcci/10.05.Sparse%20Array%20Search/README_EN.md) | `Binary Search` | Easy | -| [10.09](https://leetcode-cn.com/problems/sorted-matrix-search-lcci) | [Sorted Matrix Search](/lcci/10.09.Sorted%20Matrix%20Search/README_EN.md) | `Two Pointers`,`Binary Search`,`Divide and Conquer` | Medium | -| [10.10](https://leetcode-cn.com/problems/rank-from-stream-lcci) | [Rank from Stream](/lcci/10.10.Rank%20from%20Stream/README_EN.md) | | Medium | -| [10.11](https://leetcode-cn.com/problems/peaks-and-valleys-lcci) | [Peaks and Valleys](/lcci/10.11.Peaks%20and%20Valleys/README_EN.md) | | Medium | -| [16.01](https://leetcode-cn.com/problems/swap-numbers-lcci) | [Swap Numbers](/lcci/16.01.Swap%20Numbers/README_EN.md) | `Bit Manipulation`,`Math` | Medium | -| [16.02](https://leetcode-cn.com/problems/words-frequency-lcci) | [Words Frequency](/lcci/16.02.Words%20Frequency/README_EN.md) | `Design`,`Hash Table` | Medium | -| [16.03](https://leetcode-cn.com/problems/intersection-lcci) | [Intersection](/lcci/16.03.Intersection/README_EN.md) | `Geometry`,`Math` | Hard | -| [16.04](https://leetcode-cn.com/problems/tic-tac-toe-lcci) | [Tic-Tac-Toe](/lcci/16.04.Tic-Tac-Toe/README_EN.md) | `Array` | Medium | -| [16.05](https://leetcode-cn.com/problems/factorial-zeros-lcci) | [Factorial Zeros](/lcci/16.05.Factorial%20Zeros/README_EN.md) | `Math` | Easy | -| [16.06](https://leetcode-cn.com/problems/smallest-difference-lcci) | [Smallest Difference](/lcci/16.06.Smallest%20Difference/README_EN.md) | `Array`,`Two Pointers` | Medium | -| [16.07](https://leetcode-cn.com/problems/maximum-lcci) | [Maximum](/lcci/16.07.Maximum/README_EN.md) | `Bit Manipulation`,`Math` | Easy | -| [16.08](https://leetcode-cn.com/problems/english-int-lcci) | [English Int](/lcci/16.08.English%20Int/README_EN.md) | `Math`,`String` | Hard | -| [16.09](https://leetcode-cn.com/problems/operations-lcci) | [Operations](/lcci/16.09.Operations/README_EN.md) | `Design` | Medium | -| [16.10](https://leetcode-cn.com/problems/living-people-lcci) | [Living People](/lcci/16.10.Living%20People/README_EN.md) | `Array` | Medium | -| [16.11](https://leetcode-cn.com/problems/diving-board-lcci) | [Diving Board](/lcci/16.11.Diving%20Board/README_EN.md) | `Recursion`,`Memoization` | Easy | -| [16.13](https://leetcode-cn.com/problems/bisect-squares-lcci) | [Bisect Squares](/lcci/16.13.Bisect%20Squares/README_EN.md) | `Geometry` | Medium | -| [16.14](https://leetcode-cn.com/problems/best-line-lcci) | [Best Line](/lcci/16.14.Best%20Line/README_EN.md) | `Geometry`,`Hash Table` | Medium | -| [16.15](https://leetcode-cn.com/problems/master-mind-lcci) | [Master Mind](/lcci/16.15.Master%20Mind/README_EN.md) | `Array` | Easy | -| [16.16](https://leetcode-cn.com/problems/sub-sort-lcci) | [Sub Sort](/lcci/16.16.Sub%20Sort/README_EN.md) | `Sort`,`Array` | Medium | -| [16.17](https://leetcode-cn.com/problems/contiguous-sequence-lcci) | [Contiguous Sequence](/lcci/16.17.Contiguous%20Sequence/README_EN.md) | `Array`,`Divide and Conquer`,`Dynamic Programming` | Easy | -| [16.18](https://leetcode-cn.com/problems/pattern-matching-lcci) | [Pattern Matching](/lcci/16.18.Pattern%20Matching/README_EN.md) | `String` | Medium | -| [16.19](https://leetcode-cn.com/problems/pond-sizes-lcci) | [Pond Sizes](/lcci/16.19.Pond%20Sizes/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | -| [16.20](https://leetcode-cn.com/problems/t9-lcci) | [T9](/lcci/16.20.T9/README_EN.md) | `Array` | Medium | -| [16.21](https://leetcode-cn.com/problems/sum-swap-lcci) | [Sum Swap](/lcci/16.21.Sum%20Swap/README_EN.md) | `Sort`,`Array` | Medium | -| [16.22](https://leetcode-cn.com/problems/langtons-ant-lcci) | [Langtons Ant](/lcci/16.22.Langtons%20Ant/README_EN.md) | `Array` | Medium | -| [16.24](https://leetcode-cn.com/problems/pairs-with-sum-lcci) | [Pairs With Sum](/lcci/16.24.Pairs%20With%20Sum/README_EN.md) | `Array`,`Hash Table` | Medium | -| [16.25](https://leetcode-cn.com/problems/lru-cache-lcci) | [LRU Cache](/lcci/16.25.LRU%20Cache/README_EN.md) | `Design` | Medium | -| [16.26](https://leetcode-cn.com/problems/calculator-lcci) | [Calculator](/lcci/16.26.Calculator/README_EN.md) | `String` | Medium | -| [17.01](https://leetcode-cn.com/problems/add-without-plus-lcci) | [Add Without Plus](/lcci/17.01.Add%20Without%20Plus/README_EN.md) | `Bit Manipulation` | Easy | -| [17.04](https://leetcode-cn.com/problems/missing-number-lcci) | [Missing Number](/lcci/17.04.Missing%20Number/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Easy | -| [17.05](https://leetcode-cn.com/problems/find-longest-subarray-lcci) | [Find Longest Subarray](/lcci/17.05.Find%20Longest%20Subarray/README_EN.md) | `Array` | Medium | -| [17.06](https://leetcode-cn.com/problems/number-of-2s-in-range-lcci) | [Number Of 2s In Range](/lcci/17.06.Number%20Of%202s%20In%20Range/README_EN.md) | `Math`,`Dynamic Programming` | Medium | -| [17.07](https://leetcode-cn.com/problems/baby-names-lcci) | [Baby Names](/lcci/17.07.Baby%20Names/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | -| [17.08](https://leetcode-cn.com/problems/circus-tower-lcci) | [Circus Tower](/lcci/17.08.Circus%20Tower/README_EN.md) | `Sort`,`Binary Search`,`Dynamic Programming` | Medium | -| [17.09](https://leetcode-cn.com/problems/get-kth-magic-number-lcci) | [Get Kth Magic Number](/lcci/17.09.Get%20Kth%20Magic%20Number/README_EN.md) | `Heap`,`Queue`,`Math` | Medium | -| [17.10](https://leetcode-cn.com/problems/find-majority-element-lcci) | [Find Majority Element](/lcci/17.10.Find%20Majority%20Element/README_EN.md) | `Bit Manipulation`,`Array`,`Divide and Conquer` | Easy | -| [17.11](https://leetcode-cn.com/problems/find-closest-lcci) | [Find Closest](/lcci/17.11.Find%20Closest/README_EN.md) | `Two Pointers`,`String` | Medium | -| [17.12](https://leetcode-cn.com/problems/binode-lcci) | [BiNode](/lcci/17.12.BiNode/README_EN.md) | `Tree`,`Binary Search Tree`,`Recursion` | Easy | -| [17.13](https://leetcode-cn.com/problems/re-space-lcci) | [Re-Space](/lcci/17.13.Re-Space/README_EN.md) | `Memoization`,`String` | Medium | -| [17.14](https://leetcode-cn.com/problems/smallest-k-lcci) | [Smallest K](/lcci/17.14.Smallest%20K/README_EN.md) | `Heap`,`Sort`,`Divide and Conquer` | Medium | -| [17.15](https://leetcode-cn.com/problems/longest-word-lcci) | [Longest Word](/lcci/17.15.Longest%20Word/README_EN.md) | `String` | Medium | -| [17.16](https://leetcode-cn.com/problems/the-masseuse-lcci) | [The Masseuse](/lcci/17.16.The%20Masseuse/README_EN.md) | `Dynamic Programming` | Easy | -| [17.17](https://leetcode-cn.com/problems/multi-search-lcci) | [Multi Search](/lcci/17.17.Multi%20Search/README_EN.md) | `Trie`,`String` | Medium | -| [17.18](https://leetcode-cn.com/problems/shortest-supersequence-lcci) | [Shortest Supersequence](/lcci/17.18.Shortest%20Supersequence/README_EN.md) | `Sliding Window` | Medium | -| [17.19](https://leetcode-cn.com/problems/missing-two-lcci) | [Missing Two](/lcci/17.19.Missing%20Two/README_EN.md) | `Array`,`Math` | Hard | -| [17.20](https://leetcode-cn.com/problems/continuous-median-lcci) | [Continuous Median](/lcci/17.20.Continuous%20Median/README_EN.md) | `Heap` | Hard | -| [17.21](https://leetcode-cn.com/problems/volume-of-histogram-lcci) | [Volume of Histogram](/lcci/17.21.Volume%20of%20Histogram/README_EN.md) | `Stack`,`Array`,`Two Pointers` | Hard | -| [17.22](https://leetcode-cn.com/problems/word-transformer-lcci) | [Word Transformer](/lcci/17.22.Word%20Transformer/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Array`,`String` | Medium | -| [17.23](https://leetcode-cn.com/problems/max-black-square-lcci) | [Max Black Square](/lcci/17.23.Max%20Black%20Square/README_EN.md) | `Dynamic Programming` | Medium | -| [17.24](https://leetcode-cn.com/problems/max-submatrix-lcci) | [Max Submatrix](/lcci/17.24.Max%20Submatrix/README_EN.md) | `Dynamic Programming` | Hard | -| [17.25](https://leetcode-cn.com/problems/word-rectangle-lcci) | [Word Rectangle](/lcci/17.25.Word%20Rectangle/README_EN.md) | | Hard | -| [17.26](https://leetcode-cn.com/problems/sparse-similarity-lcci) | [Sparse Similarity](/lcci/17.26.Sparse%20Similarity/README_EN.md) | `Hash Table` | Hard | - -## Copyright - -[@Doocs](https://github.com/doocs) diff --git a/leetcode/lcof/README_EN.md b/leetcode/lcof/README_EN.md deleted file mode 100644 index f4059f3e..00000000 --- a/leetcode/lcof/README_EN.md +++ /dev/null @@ -1,19 +0,0 @@ -# [_Coding Interviews, 2nd Edition_](https://www.researchgate.net/file.PostFileLoader.html?id=5631f4596307d977348b4567&assetKey=AS:289838927499264@1446114393339) - -This book is about coding interview questions from software and Internet companies. It covers five key factors which determine performance of candidates: (1) the basics of programming languages, data structures and algorithms, (2) approaches to writing code with high quality, (3) tips to solve difficult problems, (4) methods to optimize code, (5) soft skills required in interviews. The basics of languages, algorithms and data structures are discussed as well as questions that explore how to write robust solutions after breaking down problems into manageable pieces. It also includes examples to focus on modeling and creative problem solving. - -Interview questions from the most popular companies in the IT industry are taken as examples to illustrate the five factors above. Besides solutions, it contains detailed analysis, how interviewers evaluate solutions, as well as why they like or dislike them. The author makes clever use of the fact that interviewees will have limited time to program meaningful solutions which in turn, limits the options an interviewer has. So the author covers those bases. - -Readers will improve their interview performance after reading this book. It will be beneficial for them even after they get offers, because its topics, such as approaches to analyzing difficult problems, writing robust code and optimizing, are all essential for high-performing coders. - -[中文文档](/lcof/README.md) - -## Solutions - -English Solutions is not available for the book. Please switch to Chinese version. - -Press Control+F(or Command+F on the Mac) to search anything you want. - -## Copyright - -[@Doocs](https://github.com/doocs) diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index c61b60a3..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - int findRepeatNumber(vector& nums) { - int len = nums.size(); - for (int i = 0; i < len; i++) { - while (i != nums[i]) { - // 这一位的值,不等于这一位的数字 - if (nums[i] == nums[nums[i]]) { - // 如果在交换的过程中,发现了相等的数字,直接返回 - return nums[i]; - } - - swap(nums[i], nums[nums[i]]); - } - } - - return 0; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 0072b9ab..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,11 +0,0 @@ -func findRepeatNumber(nums []int) int { - for i := 0; i < len(nums); i++ { - for nums[i] != i { - if nums[i] == nums[nums[i]] { - return nums[i] - } - nums[i], nums[nums[i]] = nums[nums[i]], nums[i] - } - } - return -1 -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 34a5b3a2..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var findRepeatNumber = function (nums) { - let m = {}; - for (let num of nums) { - if (m[num]) return num; - m[num] = 1; - } -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index b70dc93e..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def findRepeatNumber(self, nums: List[int]) -> int: - for i, num in enumerate(nums): - while i != num: - if num == nums[num]: - return num - nums[i], nums[num] = nums[num], nums[i] - num = nums[i] - return -1 diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.go" deleted file mode 100644 index 1b24b326..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.go" +++ /dev/null @@ -1,18 +0,0 @@ -func findNumberIn2DArray(matrix [][]int, target int) bool { - if len(matrix) == 0 { - return false - } - rows, cols := len(matrix), len(matrix[0]) - i, j := rows - 1, 0 - for i >= 0 && j < cols { - if matrix[i][j] == target { - return true - } - if matrix[i][j] > target { - i-- - } else { - j++ - } - } - return false -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" deleted file mode 100644 index eb334c8a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.js" +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @param {number[][]} matrix - * @param {number} target - * @return {boolean} - */ -var findNumberIn2DArray = function (matrix, target) { - let row = matrix.length; - let col = matrix[0].length; - function dfs(i, j) { - if (i < 0 || j >= col) { - return false; - } - if (matrix[i][j] === target) return true; - else if (matrix[i][j] > target) { - return dfs(i - 1, j); - } else { - return dfs(i, j + 1); - } - } - return dfs(row - 1, 0); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.py" deleted file mode 100644 index beecf4a5..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23004. \344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\346\237\245\346\211\276/Solution.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool: - if not matrix or not matrix[0]: - return False - rows, cols = len(matrix), len(matrix[0]) - i, j = rows - 1, 0 - while i >= 0 and j < cols: - if matrix[i][j] == target: - return True - if matrix[i][j] > target: - i -= 1 - else: - j += 1 - return False diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.go" deleted file mode 100644 index 37d32b0d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.go" +++ /dev/null @@ -1,3 +0,0 @@ -func replaceSpace(s string) string { - return strings.Replace(s, " ", "%20", -1 ) -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" deleted file mode 100644 index 4e81b7a1..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.js" +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @param {string} s - * @return {string} - */ -var replaceSpace = function (s) { - return s.split(" ").join("%20"); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.py" deleted file mode 100644 index c47525ef..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23005. \346\233\277\346\215\242\347\251\272\346\240\274/Solution.py" +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def replaceSpace(self, s: str) -> str: - return s.replace(' ', '%20') \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.cpp" deleted file mode 100644 index c2b5b53c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.cpp" +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ - -class Solution { -public: - vector ret; - - void getVal(ListNode* head) { - if (head) { - if (head->next) { - getVal(head->next); - } - ret.push_back(head->val); - } - } - - vector reversePrint(ListNode* head) { - getVal(head); - return ret; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.go" deleted file mode 100644 index c7b7330c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.go" +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ -//insert to the front -func reversePrint(head *ListNode) []int { - res := []int{} - for head != nil { - res = append([]int{head.Val}, res...) - head = head.Next - } - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" deleted file mode 100644 index 40065372..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @return {number[]} - */ -var reversePrint = function (head) { - let node = head; - let res = []; - while (node) { - res.unshift(node.val); - node = node.next; - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.py" deleted file mode 100644 index e06eec47..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23006. \344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250/Solution.py" +++ /dev/null @@ -1,13 +0,0 @@ -# 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 = [] - while head: - res.append(head.val) - head = head.next - return res[::-1] \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.go" deleted file mode 100644 index 301abf74..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.go" +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ -func buildTree(preorder []int, inorder []int) *TreeNode { - return helper(preorder, inorder, 0, 0, len(preorder)-1) -} - -func helper(preorder, inorder []int, index, start, end int) *TreeNode { - if start > end { - return nil - } - root := &TreeNode{Val:preorder[index]} - j := start - for j < end && preorder[index] != inorder[j] { - j++ - } - root.Left = helper(preorder, inorder, index + 1, start, j - 1) - root.Right = helper(preorder, inorder, index + 1 + j -start, j + 1, end) - return root -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" deleted file mode 100644 index b4d0675d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.js" +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {number[]} preorder - * @param {number[]} inorder - * @return {TreeNode} - */ -var buildTree = function (preorder, inorder) { - if (!preorder || !preorder.length) return null; - let preIdx = 0; - let inMap = {}; - for (let i = 0; i < inorder.length; i++) { - inMap[inorder[i]] = i; - } - function func(start, end) { - if (start > end) { - return null; - } - let preVal = preorder[preIdx]; - preIdx++; - let inIdx = inMap[preVal]; - let node = new TreeNode(preVal); - node.left = func(start, inIdx - 1); - node.right = func(inIdx + 1, end); - return node; - } - return func(0, preorder.length - 1); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.py" deleted file mode 100644 index ede88e1a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.py" +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - indexes = {} - def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: - def build(preorder, inorder, p1, p2, i1, i2) -> TreeNode: - if p1 > p2 or i1 > i2: - return None - root_val = preorder[p1] - pos = self.indexes[root_val] - root = TreeNode(root_val) - root.left = None if pos == i1 else build(preorder, inorder, p1 + 1, p1 - i1 + pos, i1, pos - 1) - root.right = None if pos == i2 else build(preorder, inorder, p1 - i1 + pos + 1, p2, pos + 1, i2) - return root - n = len(inorder) - for i in range(n): - self.indexes[inorder[i]] = i - return build(preorder, inorder, 0, n - 1, 0, n - 1) diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.go" deleted file mode 100644 index 3e9da243..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.go" +++ /dev/null @@ -1,33 +0,0 @@ -type CQueue struct { - Stack1 []int - Stack2 []int -} - -// 入队都往S1压入,弹出时判定S2是否为空,S2非空则弹出S2顶,否则,S1的元素从栈顶依次入S2 -//再从S2弹出 - -func Constructor() CQueue { - return CQueue{Stack1: []int{}, Stack2: []int{}} -} - -func (this *CQueue) AppendTail(value int) { - this.Stack1 = append(this.Stack1, value) -} - -func (this *CQueue) DeleteHead() int { - if len(this.Stack1) == 0 && len(this.Stack2) == 0 { - return -1 - } - if len(this.Stack2) > 0 { - res := this.Stack2[len(this.Stack2)-1] - this.Stack2 = this.Stack2[0 : len(this.Stack2)-1] - return res - } - for len(this.Stack1) > 0 { - this.Stack2 = append(this.Stack2, this.Stack1[len(this.Stack1)-1]) - this.Stack1 = this.Stack1[0 : len(this.Stack1)-1] - } - res := this.Stack2[len(this.Stack2)-1] - this.Stack2 = this.Stack2[0 : len(this.Stack2)-1] - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" deleted file mode 100644 index 2114fa6e..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.js" +++ /dev/null @@ -1,28 +0,0 @@ -var CQueue = function () { - this.data = []; - this.helper = []; -}; -/** - * @param {number} value - * @return {void} - */ -CQueue.prototype.appendTail = function (value) { - this.data.push(value); -}; -/** - * @return {number} - */ -CQueue.prototype.deleteHead = function () { - if (this.data.length) { - while (this.data.length > 1) { - this.helper.push(this.data.pop()); - } - let res = this.data.pop(); - while (this.helper.length) { - this.data.push(this.helper.pop()); - } - return res; - } else { - return -1; - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.py" deleted file mode 100644 index 266d262f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.py" +++ /dev/null @@ -1,26 +0,0 @@ -class CQueue: - - def __init__(self): - self.s1 = [] - self.s2 = [] - - def appendTail(self, value: int) -> None: - self.s1.append(value) - if not self.s2: - self._move() - - def deleteHead(self) -> int: - if not self.s2: - self._move() - return -1 if not self.s2 else self.s2.pop() - - def _move(self): - while self.s1: - self.s2.append(self.s1.pop()) - - - -# 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/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.go" deleted file mode 100644 index 3b15e13f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.go" +++ /dev/null @@ -1,12 +0,0 @@ -func fib(n int) int { - if n < 2 { - return n - } - a := make([]int,n+1) - a[0]=0 - a[1]=1 - for i := 2; i < n+1; i++ { - a[i] = (a[i-1]+ a[i-2])%1000000007 - } - return a[n] -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" deleted file mode 100644 index c1341428..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.js" +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var fib = function (n) { - if (!n) return 0; - let pre = 0; - let cur = 1; - for (let i = 2; i <= n; i++) { - let c = (pre + cur) % (1e9 + 7); - pre = cur; - cur = c; - } - return cur; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.py" deleted file mode 100644 index d504836c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.py" +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def fib(self, n: int) -> int: - a, b = 0, 1 - for _ in range(n): - a, b = b, a + b - return a % 1000000007 \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.go" deleted file mode 100644 index f92c7395..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.go" +++ /dev/null @@ -1,15 +0,0 @@ -func numWays(n int) int { - if n == 0 { - return 1 - } - if n <= 2 { - return n - } - a := make([]int, n) - a[0] = 1 - a[1] = 2 - for i := 2; i < n; i++ { - a[i] = (a[i-1] + a[i-2]) % 1000000007 - } - return a[n-1] -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" deleted file mode 100644 index c4be775b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.js" +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var numWays = function (n) { - if (!n) return 1; - let pre = 1; - let cur = 1; - for (let i = 2; i <= n; i++) { - let c = (pre + cur) % (1e9 + 7); - pre = cur; - cur = c; - } - return cur; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.py" deleted file mode 100644 index e3eaa93a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23010- II. \351\235\222\350\233\231\350\267\263\345\217\260\351\230\266\351\227\256\351\242\230/Solution.py" +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def numWays(self, n: int) -> int: - a, b = 0, 1 - for _ in range(n): - a, b = b, a + b - return b % 1000000007 diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.go" deleted file mode 100644 index 9609dcab..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.go" +++ /dev/null @@ -1,14 +0,0 @@ -func minArray(nums []int) int { - l, r := 0, len(nums)-1 - for l < r { - mid := l + (r-l)>>1 - if nums[mid] > nums[r] { - l = mid + 1 - } else if nums[mid] < nums[r] { - r = mid //r 本身不需要被排除 - } else { - r-- - } - } - return nums[l] -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.js" deleted file mode 100644 index 217e5116..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @param {number[]} numbers - * @return {number} - */ -var minArray = function (numbers) { - // return Math.min(...numbers) - let left = 0; - let right = numbers.length - 1; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (numbers[mid] > numbers[right]) { - left = mid + 1; - } else if (numbers[mid] === numbers[right]) { - right--; - } else { - right = mid; - } - } - return numbers[left]; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.py" deleted file mode 100644 index 3143a347..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23011. \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/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def minArray(self, numbers: List[int]) -> int: - l, r = 0, len(numbers) - 1 - while l < r: - m = l + ((r - l) >> 1) - if numbers[m] > numbers[r]: - l = m + 1 - elif numbers[m] < numbers[r]: - r = m - else: - r -= 1 - return numbers[l] diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.cpp" deleted file mode 100644 index f169558b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -class Solution { -public: - bool dfs(vector>& board, string& word, int cur, int x, int y) { - if (board[x][y] != word[cur]) { - return false; - } - - if (cur == word.size()-1) { - return true; - } - - char t = board[x][y]; - board[x][y] = '*'; // 表示查询过了这个字段 - int dx[4] = {-1, 0, 1, 0}; - int dy[4] = {0, 1, 0, -1}; - for (int k = 0; k < 4; k++) { - // 从上、右、下、左四个方向,开始dfs - int a = x + dx[k], b = y + dy[k]; - if (a >= 0 && a < board.size() && b >= 0 && b < board[0].size()) { - if (dfs(board, word, cur+1, a, b)) { - return true; - } - } - } - - board[x][y] = t; - return false; - } - - bool exist(vector>& board, string word) { - int x = board.size(); - int y = board[0].size(); - if (0 == x || 0 == y) { - return false; - } - - for (int i = 0; i < x; i++) { - for (int j = 0; j < y; j++) { - if (dfs(board, word, 0, i, j)) { - return true; - } - } - } - - return false; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.go" deleted file mode 100644 index 058d5a0d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.go" +++ /dev/null @@ -1,36 +0,0 @@ -func exist(board [][]byte, word string) bool { - if len(board) == 0 { - return false - } - // 标记数组 - isVisited := make([][]bool, len(board)) - for i := 0; i < len(board); i++ { - isVisited[i] = make([]bool, len(board[0])) - } - for i := 0; i < len(board); i++ { - for j := 0; j < len(board[0]); j++ { - if board[i][j] == word[0] { - if bfs(board, i, j, isVisited, word, 0) { - return true - } - } - } - } - return false -} - -func bfs(board [][]byte, i, j int, isVisited [][]bool, word string, index int) bool { - if index == len(word) { - return true - } - if i < 0 || j < 0 || i == len(board) || j == len(board[0]) || isVisited[i][j] || board[i][j] != word[index] { - return false - } - isVisited[i][j] = true - res := bfs(board, i+1, j, isVisited, word, index+1) || - bfs(board, i, j+1, isVisited, word, index+1) || - bfs(board, i-1, j, isVisited, word, index+1) || - bfs(board, i, j-1, isVisited, word, index+1) - isVisited[i][j] = false - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" deleted file mode 100644 index 2dfdb071..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.js" +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @param {character[][]} board - * @param {string} word - * @return {boolean} - */ -var exist = function (board, word) { - let row = board.length; - let col = board[0].length; - let res = false; - let isRead = [...new Array(row)].map(() => Array(col).fill(0)); - for (let i = 0; i < row; i++) { - for (let j = 0; j < col; j++) { - if (res) break; - if (board[i][j] === word[0]) { - dfs(i, j, word); - } - } - } - function dfs(i, j, word) { - if ( - i < 0 || - j < 0 || - i >= row || - j >= col || - res || - isRead[i][j] || - board[i][j] !== word[0] - ) { - return; - } - isRead[i][j] = 1; - word = word.substring(1); - if (word.length) { - dfs(i - 1, j, word); - dfs(i + 1, j, word); - dfs(i, j - 1, word); - dfs(i, j + 1, word); - } else { - res = true; - return; - } - isRead[i][j] = 0; - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.py" deleted file mode 100644 index 9056a640..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.py" +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def exist(self, board: List[List[str]], word: str) -> bool: - def dfs(i, j, cur): - if cur == len(word): - return True - if i < 0 or i >= m or j < 0 or j >= n or visited[i][j] or word[cur] != board[i][j]: - return False - visited[i][j] = True - next = cur + 1 - res = dfs(i + 1, j, next) or dfs(i - 1, j, next) or dfs(i, j + 1, next) or dfs(i, j - 1, next) - visited[i][j] = False - return res - m, n = len(board), len(board[0]) - visited = [[False for _ in range(n)] for _ in range(m)] - for i in range(m): - for j in range(n): - res = dfs(i, j, 0) - if res: - return True - return False diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.cpp" deleted file mode 100644 index bb991312..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.cpp" +++ /dev/null @@ -1,37 +0,0 @@ -class Solution { -public: - int checksum(int m, int n, int target) { - int a = 0; - while (m > 0) { - a += m % 10; - m /= 10; - } - int b = 0; - while (n > 0) { - b += n % 10; - n /= 10; - } - return a + b <= target; - } - int moving(int row, int col, vector>& arr, int i, int j, int target) { - int count = 0; - if (checksum(i, j, target) - && i>=0 && i < row && j>=0 && j < col - && arr[i][j] == 0) { - arr[i][j] = 1; - count = 1 + moving(row, col, arr, i-1, j, target) - + moving(row, col, arr, i, j-1, target) - + moving(row, col, arr, i+1, j, target) - + moving(row, col, arr, i, j+1, target); - } - return count; - } - int movingCount(int m, int n, int k) { - if (m == 0 || n == 0) { - return 0; - } - vector> arr(m, vector(n, 0)); - int cnt = moving(m, n, arr, 0, 0, k); - return cnt; - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.go" deleted file mode 100644 index d16f6548..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.go" +++ /dev/null @@ -1,16 +0,0 @@ -func movingCount(m int, n int, k int) int { - var visited [][]bool - visited = make([][]bool, m) - for i := 0; i < m; i++ { - visited[i] = make([]bool, n) - } - return dfs(0, 0, m, n, k, visited) -} - -func dfs(x, y, m, n, k int, visited [][]bool) int { - if x >= m || y >= n || visited[x][y] || (x%10+x/10+y%10+y/10) > k { - return 0 - } - visited[x][y] = true - return 1 + dfs(x+1, y, m, n, k, visited) + dfs(x, y+1, m, n, k, visited) -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" deleted file mode 100644 index 1782cbf0..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.js" +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @param {number} m - * @param {number} n - * @param {number} k - * @return {number} - */ -var movingCount = function (m, n, k) { - let res = 0; - let isRead = [...new Array(m)].map(() => Array(n).fill(0)); - let moving = [ - [0, -1], - [0, 1], - [1, 0], - [-1, 0], - ]; - let queue = [[0, 0]]; - isRead[0][0] = 1; - while (queue.length) { - let [x, y] = queue.shift(); - for (let [dx, dy] of moving) { - let X = x + dx; - let Y = y + dy; - if ( - X >= 0 && - Y >= 0 && - X < m && - Y < n && - !isRead[X][Y] && - isValid(X, Y) - ) { - queue.push([X, Y]); - isRead[X][Y] = 1; - } - } - res++; - } - function isValid(x, y) { - let r = 0; - r += - x - .toString() - .split("") - .reduce((acc, cur) => acc + +cur, 0) + - y - .toString() - .split("") - .reduce((acc, cur) => acc + +cur, 0); - if (r <= k) return true; - else return false; - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.py" deleted file mode 100644 index bfa4f28f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23013. \346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264/Solution.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution: - cnt = 0 - def movingCount(self, m: int, n: int, k: int) -> int: - def cal(m, n): - s = str(m) + str(n) - return sum([int(i) for i in s]) - def dfs(i, j): - if i < 0 or i >= m or j < 0 or j >= n or cal(i, j) > k or visited[i][j]: - return - self.cnt += 1 - visited[i][j] = True - dfs(i + 1, j) - dfs(i - 1, j) - dfs(i, j + 1) - dfs(i, j - 1) - self.cnt = 0 - visited = [[False for _ in range(n)] for _ in range(m)] - dfs(0, 0) - return self.cnt diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.go" deleted file mode 100644 index 77eed398..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.go" +++ /dev/null @@ -1,11 +0,0 @@ -func cuttingRope(n int) int { - if n <= 3 { - return n - 1 - } - sum := 1 - for n > 4 { - sum *= 3 - n -= 3 - } - return sum * n -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" deleted file mode 100644 index 0c3fff55..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- I. \345\211\252\347\273\263\345\255\220/Solution.js" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var cuttingRope = function (n) { - // 数学方法 - if (n <= 3) return n - 1; - let a = ~~(n / 3); - let b = n % 3; - if (b === 1) { - return 3 ** (a - 1) * 2 * 2; - } - if (b === 0) return 3 ** a; - return 3 ** a * b; - // dp 方法 - // let dp = new Array(n+1).fill(0) - // dp[0] = 1 - // for(let i=1;i int: - if n < 4: - return n - 1 - res = 1 - while n > 4: - res *= 3 - n -= 3 - if n == 4: - return res << 2 - return res * n \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.go" deleted file mode 100644 index 465c00c1..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.go" +++ /dev/null @@ -1,12 +0,0 @@ -func cuttingRope(n int) int { - if n <= 3 { - return n - 1 - } - sum := 1 - for n > 4 { - sum *= 3 - sum = sum % 1000000007 - n -= 3 - } - return sum * n % 1000000007 -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" deleted file mode 100644 index bb0dd1e1..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var cuttingRope = function (n) { - if (n <= 3) return n - 1; - let a = ~~(n / 3); - let b = n % 3; - const MOD = 1e9 + 7; - function myPow(x) { - let r = 1; - for (let i = 0; i < x; i++) { - r = (r * 3) % MOD; - } - return r; - } - if (b === 1) { - return (myPow(a - 1) * 4) % MOD; - } - if (b === 0) return myPow(a) % MOD; - return (myPow(a) * 2) % MOD; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.py" deleted file mode 100644 index dbf26cff..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23014- II. \345\211\252\347\273\263\345\255\220 II/Solution.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def cuttingRope(self, n: int) -> int: - if n < 4: - return n - 1 - res = 1 - while n > 4: - res *= 3 - n -= 3 - if n == 4: - return (res << 2) % 1000000007 - return (res * n) % 1000000007 \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.go" deleted file mode 100644 index 7ebdc591..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.go" +++ /dev/null @@ -1,9 +0,0 @@ -func hammingWeight(num uint32) int { - ans := 0 - // num &=num-1 消除最右边的1 - for num != 0 { - num &= num - 1 - ans++ - } - return ans -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" deleted file mode 100644 index 8acf0349..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.js" +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @param {number} n - a positive integer - * @return {number} - */ -var hammingWeight = function (n) { - let cnt = 0; - while (n) { - cnt += n & 1; - n >>>= 1; - } - return cnt; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.py" deleted file mode 100644 index 38e5b4d3..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23015. \344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260/Solution.py" +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - def hammingWeight(self, n: int) -> int: - res = 0 - while n: - n &= (n - 1) - res += 1 - return res \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.go" deleted file mode 100644 index 98bf857e..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.go" +++ /dev/null @@ -1,23 +0,0 @@ -func myPow(x float64, n int) float64 { - p := abs(n) - res := 1.0 - for p != 0 { - if p&1 == 1 { - res *= x - } - x *= x - p = p >>1 - } - if n < 0 { - return 1/res - } - return res -} - -func abs(x int) int { - if x > 0 { - return x - } - return -x -} - diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" deleted file mode 100644 index f80d273f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @param {number} x - * @param {number} n - * @return {number} - */ -var myPow = function (x, n) { - let r = 1; - let tmp = x; - let tag = 0; - if (n < 0) { - tag = 1; - n = -n; - } - while (n) { - if (n & 1) { - r *= tmp; - } - tmp *= tmp; - n >>>= 1; - } - return tag ? 1 / r : r; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.py" deleted file mode 100644 index ad135dfb..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23016. \346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271/Solution.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def myPow(self, x: float, n: int) -> float: - if n == 0: - return 1 - if n == 1: - return x - if n == -1: - return 1 / x - half = self.myPow(x, n // 2) - return half * half * self.myPow(x, n % 2) diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.go" deleted file mode 100644 index 15e76481..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.go" +++ /dev/null @@ -1,11 +0,0 @@ -func printNumbers(n int) []int { - d := 10 - for i := 1; i < n; i++ { - d *= 10 - } - res := make([]int, d - 1) - for i := 1; i < d; i++ { - res[i - 1] = i - } - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.js" deleted file mode 100644 index 1d1f69e7..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.js" +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @param {number} n - * @return {number[]} - */ -var printNumbers = function (n) { - let res = []; - for (let i = 1; i < 10 ** n; ++i) { - res.push(i); - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.py" deleted file mode 100644 index bbd58825..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23017. \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/Solution.py" +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def printNumbers(self, n: int) -> List[int]: - return [i for i in range(1, 10 ** n)] \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.cpp" deleted file mode 100644 index 0ebd944d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ -class Solution { -public: - ListNode* deleteNode(ListNode* head, int val) { - ListNode* cur = head; - if (!head) { - return nullptr; - } - - if (head->val == val) { - // 第一个就匹配的情况 - return head->next; - } - - while (cur && cur->next) { - if (cur->next->val == val) { - // 如果找到了,直接指向下一个 - cur->next = cur->next->next; - break; - } else { - cur = cur->next; - } - } - - return head; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.go" deleted file mode 100644 index 3f79810e..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.go" +++ /dev/null @@ -1,17 +0,0 @@ -func deleteNode(head *ListNode, val int) *ListNode { - res := &ListNode{ - Val: 0, - Next: head, - } - pre := res - cur := res.Next - for cur != nil { - if cur.Val == val { - pre.Next = cur.Next - return res.Next - } - cur = cur.Next - pre = pre.Next - } - return res.Next -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" deleted file mode 100644 index 4a225400..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @param {number} val - * @return {ListNode} - */ -var deleteNode = function (head, val) { - const dummy = new ListNode(0); - dummy.next = head; - let pre = dummy; - while (pre.next && pre.next.val != val) { - pre = pre.next; - } - pre.next = pre.next ? pre.next.next : null; - return dummy.next; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.py" deleted file mode 100644 index bcbc7622..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23018. \345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\350\212\202\347\202\271/Solution.py" +++ /dev/null @@ -1,14 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None -class Solution: - def deleteNode(self, head: ListNode, val: int) -> ListNode: - dummy = ListNode(0) - dummy.next = head - pre = dummy - while pre.next and pre.next.val != val: - pre = pre.next - pre.next = None if not pre.next else pre.next.next - return dummy.next diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.cpp" deleted file mode 100644 index 78da20a8..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23019. \346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215/Solution.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -class Solution { -public: - bool match(string s, string p, int sl, int pl) { - if (sl == s.size() && pl == p.size()) { - return true; - } - - if (sl < s.size() && pl == p.size()) { - return false; - } - - if (p[pl+1] != '*') { - // 如果p的下一个不是*的情况 - if ((s[sl] == p[pl]) || (sl bool: - m, n = len(s) + 1, len(p) + 1 - if n == 1: - return m == 1 - dp = [[False for _ in range(n)] for _ in range(m)] - dp[0][0], dp[0][1] = True, False - for j in range(2, n): - if p[j - 1] == '*': - dp[0][j] = dp[0][j - 2] - for i in range(1, m): - for j in range(1, n): - if s[i - 1] == p[j - 1] or p[j - 1] == '.': - dp[i][j] = dp[i - 1][j - 1] - elif p[j - 1] == '*': - if p[j - 2] == '.' or p[j - 2] == s[i - 1]: - dp[i][j] = dp[i][j - 2] or dp[i - 1][j] - else: - dp[i][j] = dp[i][j - 2] - else: - dp[i][j] = False - return dp[m - 1][n - 1] diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" deleted file mode 100644 index 905f6a8d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.js" +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @param {string} s - * @return {boolean} - */ -var isNumber = function (s) { - return s !== " " && !isNaN(+s); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.py" deleted file mode 100644 index 43f1e711..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23020. \350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262/Solution.py" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution: - def isNumber(self, s: str) -> bool: - if not s or not s.strip(): - return False - s = s.strip() - find_num = find_dot = find_e = False - for i in range(len(s)): - if s[i] == '+' or s[i] == '-': - if i != 0 and s[i - 1] != 'e' and s[i - 1] != 'E': - return False - elif s[i] >= '0' and s[i] <= '9': - find_num = True - elif s[i] == '.': - if find_dot or find_e: - return False - find_dot = True - elif s[i] == 'e' or s[i] == 'E': - if not find_num or find_e: - return False - find_e = True - find_num = False - else: - return False - return find_num \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.js" deleted file mode 100644 index 5a359aeb..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @param {number[]} nums - * @return {number[]} - */ -var exchange = function (nums) { - let left = 0; - let right = nums.length - 1; - while (left < right) { - let c = nums[left]; - nums[left] = nums[right]; - nums[right] = c; - while (nums[left] % 2) { - left++; - } - while (nums[right] % 2 === 0) { - right--; - } - } - return nums; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.py" deleted file mode 100644 index 3f4a8028..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23021. \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/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def exchange(self, nums: List[int]) -> List[int]: - p, q = 0, len(nums) - 1 - while p < q: - if nums[p] & 1 == 1: - p += 1 - continue - if nums[q] & 1 == 0: - q -= 1 - continue - nums[p], nums[q] = nums[q], nums[p] - return nums \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.go" deleted file mode 100644 index 80913485..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.go" +++ /dev/null @@ -1,14 +0,0 @@ -func getKthFromEnd(head *ListNode, k int) *ListNode { - tmp := head - for tmp != nil && k > 0{ - tmp = tmp.Next - k-- - } - slow := head - fast := tmp - for fast != nil { - fast = fast.Next - slow = slow.Next - } - return slow -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.js" deleted file mode 100644 index b27a23fc..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.js" +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @param {ListNode} head - * @param {number} k - * @return {ListNode} - */ -var getKthFromEnd = function (head, k) { - // 递归 - // let cnt = 1 - // function func(node) { - // if(!node || !node.next) return node - // let newNode = func(node.next) - // if(cnt === k) return newNode - // else cnt++ - // return node - // } - // return func(head) - - // 快慢指针 - let slow = head; - let fast = head; - while (k) { - fast = fast.next; - k--; - } - while (fast) { - slow = slow.next; - fast = fast.next; - } - return slow; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.py" deleted file mode 100644 index 1f9158c7..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23022. \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/Solution.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 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: - slow = fast = head - for _ in range(k): - fast = fast.next - while fast: - slow = slow.next - fast = fast.next - return slow \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.go" deleted file mode 100644 index 5e20ffe0..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.go" +++ /dev/null @@ -1,14 +0,0 @@ -func reverseList(head *ListNode) *ListNode { - if head == nil ||head.Next == nil { - return head - } - dummyHead := &ListNode{} - cur := head - for cur != nil { - tmp := cur.Next - cur.Next = dummyHead.Next - dummyHead.Next = cur - cur = tmp - } - return dummyHead.Next -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" deleted file mode 100644 index 19d396c3..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @return {ListNode} - */ -var reverseList = function (head) { - let node = head; - let pre = null; - while (node) { - let cur = node; - node = cur.next; - cur.next = pre; - pre = cur; - } - return pre; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.py" deleted file mode 100644 index d6ded4ca..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23024. \345\217\215\350\275\254\351\223\276\350\241\250/Solution.py" +++ /dev/null @@ -1,15 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def reverseList(self, head: ListNode) -> ListNode: - pre, cur = None, head - while cur: - t = cur.next - cur.next = pre - pre = cur - cur = t - return pre \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.cpp" deleted file mode 100644 index 3b853e13..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.cpp" +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ - -class Solution { -public: - ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { - if (nullptr == l1 && nullptr == l2) { - return nullptr; - } - - if (nullptr == l1 || nullptr == l2) { - return l1 == nullptr ? l2 : l1; - } - - ListNode* node = nullptr; - if (l1->val > l2->val) { - node = l2; - node->next = mergeTwoLists(l1, l2->next); - } else { - node = l1; - node->next = mergeTwoLists(l1->next, l2); - } - - return node; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.go" deleted file mode 100644 index e825a93b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.go" +++ /dev/null @@ -1,14 +0,0 @@ -func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { - if l1 == nil { - return l2 - } - if l2 == nil { - return l1 - } - if l1.Val <= l2.Val { - l1.Next = mergeTwoLists(l1.Next,l2) - return l1 - } - l2.Next = mergeTwoLists(l1, l2.Next) - return l2 -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.js" deleted file mode 100644 index 2e75798c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.js" +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} l1 - * @param {ListNode} l2 - * @return {ListNode} - */ -var mergeTwoLists = function (l1, l2) { - // 法一 - 递归 - if (!l1) return l2; - if (!l2) return l1; - if (l1.val < l2.val) { - l1.next = mergeTwoLists(l1.next, l2); - return l1; - } else { - l2.next = mergeTwoLists(l2.next, l1); - return l2; - } - // 法二 - 遍历 - // if(!l1 || !l2) return l1 ? l1 : l2 - // let a = l1 - // let b = l2 - // let res = l1 - // if(a.val > b.val) { - // let c = a - // a = b - // b = c - // res = l2 - // } - // while(a && b) { - // while(a.next && a.next.val < b.val) { - // a = a.next - // } - // let tmp = a.next - // let rec = b.next - // a.next = b - // a.next.next = tmp - // a = a.next - // b = rec - // } - // return res -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.py" deleted file mode 100644 index 6da45d77..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23025. \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/Solution.py" +++ /dev/null @@ -1,20 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: - dummy = ListNode(0) - p = dummy - while l1 and l2: - if l1.val <= l2.val: - p.next = l1 - l1 = l1.next - else: - p.next = l2 - l2 = l2.next - p = p.next - p.next = l1 or l2 - return dummy.next \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.cpp" deleted file mode 100644 index cf671cde..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.cpp" +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - bool isSubTree(TreeNode* a, TreeNode* b) { - if (nullptr == b) { - // 如果小树走到头,则表示ok了 - return true; - } - - if (nullptr == a) { - // 如果大树走到头,小树却没走到头,说明不对了 - return false; - } - - if (a->val != b->val) { - return false; - } - - return isSubTree(a->left, b->left) && isSubTree(a->right, b->right); - } - - bool isSubStructure(TreeNode* a, TreeNode* b) { - bool ret = false; - if (nullptr != a && nullptr != b) { - if (a->val == b->val) { - // 如果值相等,才进入判定 - ret = isSubTree(a, b); - } - - if (false == ret) { - ret = isSubStructure(a->left, b); - } - - if (false == ret) { - ret = isSubStructure(a->right, b); - } - } - - return ret; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.go" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.go" deleted file mode 100644 index 40b420f5..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.go" +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ -func isSubStructure(A *TreeNode, B *TreeNode) bool { - // 约定空树不是任意一个树的子结构 - if A == nil || B == nil { - return false - } - return helper(A,B) || isSubStructure(A.Left,B) || isSubStructure(A.Right,B) -} - -func helper(a *TreeNode, b *TreeNode) bool { - if b == nil { - return true - } - if a == nil { - return false - } - return a.Val == b.Val && helper(a.Left, b.Left) && helper(a.Right, b.Right) -} \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" deleted file mode 100644 index 17df9f6a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.js" +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} A - * @param {TreeNode} B - * @return {boolean} - */ -var isSubStructure = function (A, B) { - function sub(A, B) { - if (!B) return true; - if (!A) return false; - return A.val == B.val && sub(A.left, B.left) && sub(A.right, B.right); - } - if (!B || !A) return false; - if (A.val != B.val) - return isSubStructure(A.left, B) || isSubStructure(A.right, B); - return sub(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.py" deleted file mode 100644 index 9a9fc79f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.py" +++ /dev/null @@ -1,20 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def isSubStructure(self, A: TreeNode, B: TreeNode) -> bool: - def sub(A, B): - if B is None: - return True - if A is None: - return False - return A.val == B.val and sub(A.left, B.left) and sub(A.right, B.right) - if B is None or A is None: - return False - if A.val != B.val: - return self.isSubStructure(A.left, B) or self.isSubStructure(A.right, B) - return sub(A, B) or self.isSubStructure(A.left, B) or self.isSubStructure(A.right, B) diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 8a98dc14..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ - -class Solution { -public: - TreeNode* mirrorTree(TreeNode* root) { - // 后续遍历 - if (nullptr == root) { - return nullptr; - } - - mirrorTree(root->left); - mirrorTree(root->right); - std::swap(root->left, root->right); - - return root; - - } -}; diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 7a0ddad9..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - func mirrorTree(root *TreeNode) *TreeNode { - if root == nil { - return root - } - root.Left, root.Right = root.Right, root.Left - mirrorTree(root.Left) - mirrorTree(root.Right) - return root -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 4ca5bfca..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {TreeNode} - */ -var mirrorTree = function (root) { - if (!root) return null; - [root.left, root.right] = [root.right, root.left]; - mirrorTree(root.left); - mirrorTree(root.right); - return root; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 641c5fa9..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,15 +0,0 @@ -# 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 root is None: - return None - root.left, root.right = root.right, root.left - self.mirrorTree(root.left) - self.mirrorTree(root.right) - return root diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 262e4339..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - func isSymmetric(root *TreeNode) bool { - if root == nil { - return true - } - return isSymme(root.Left, root.Right) -} - -func isSymme(left *TreeNode, right *TreeNode) bool { - if left == nil && right == nil { - return true - } - if left == nil || right == nil || left.Val != right.Val { - return false - } - return isSymme(left.Left, right.Right) && isSymme(left.Right, right.Left) -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 20249caa..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {boolean} - */ -var isSymmetric = function (root) { - function dfs(left, right) { - if (!left && !right) return true; - if (!left || !right || left.val != right.val) return false; - return dfs(left.left, right.right) && dfs(left.right, right.left); - } - if (!root) return true; - return dfs(root.left, root.right); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index b50e7786..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,18 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def isSymmetric(self, root: TreeNode) -> bool: - def is_symmetric(left, right): - if left is None and right is None: - return True - if left is None or right is None or left.val != right.val: - return False - return is_symmetric(left.left, right.right) and is_symmetric(left.right, right.left) - if root is None: - return True - return is_symmetric(root.left, root.right) diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index fe5d7265..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -class Solution -{ -public: - vector spiralOrder(vector> &matrix) - { - vector ans; - if (matrix.size() == 0) - return ans; - int left = 0, top = 0, bottom = matrix.size() - 1, right = matrix[0].size() - 1; - while (true) - { - for (int i = left; i <= right; i++) - ans.push_back(matrix[top][i]); - top++; - if (top > bottom) - break; - for (int i = top; i <= bottom; i++) - ans.push_back(matrix[i][right]); - right--; - if (right < left) - break; - for (int i = right; i >= left; i--) - ans.push_back(matrix[bottom][i]); - bottom--; - if (bottom < top) - break; - for (int i = bottom; i >= top; i--) - ans.push_back(matrix[i][left]); - left++; - if (left > right) - break; - } - return ans; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 849ab7b4..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @param {number[][]} matrix - * @return {number[]} - */ -var spiralOrder = function (matrix) { - if (!matrix || !matrix.length) return []; - let row = matrix.length; - let col = matrix[0].length; - let res = []; - let moves = { - right: [0, 1], - down: [1, 0], - left: [0, -1], - up: [-1, 0], - }; - let k = 0; - function dfs(i, j, dir) { - if (i < 0 || j < 0 || i >= row || j >= col || res.length === row * col) { - return; - } - res.push(matrix[i][j]); - switch (dir) { - case "right": - if (j === col - 1 - k) dir = "down"; - break; - case "down": - if (i === row - 1 - k) dir = "left"; - break; - case "left": - if (j === k) { - dir = "up"; - k++; - } - break; - case "up": - if (i === k) dir = "right"; - break; - } - let x = i + moves[dir][0]; - let y = j + moves[dir][1]; - dfs(x, y, dir); - } - dfs(0, 0, "right"); - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 4bb2118e..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def spiralOrder(self, matrix: List[List[int]]) -> List[int]: - def add(i1, j1, i2, j2): - if i1 == i2: - return [matrix[i1][j] for j in range(j1, j2 + 1)] - if j1 == j2: - return [matrix[i][j1] for i in range(i1, i2 + 1)] - return [matrix[i1][j] for j in range(j1, j2)] + [matrix[i][j2] for i in range(i1, i2)] + [matrix[i2][j] for j in range(j2, j1, -1)] + [matrix[i][j1] for i in range(i2, i1, -1)] - if not matrix or not matrix[0]: - return [] - m, n = len(matrix), len(matrix[0]) - i1, j1, i2, j2 = 0, 0, m - 1, n - 1 - res = [] - while i1 <= i2 and j1 <= j2: - res += add(i1, j1, i2, j2) - i1, j1, i2, j2 = i1 + 1, j1 + 1, i2 - 1, j2 - 1 - return res diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index b0edfd8d..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,50 +0,0 @@ -/** - * initialize your data structure here. - */ -var MinStack = function () { - this.stack = []; - this.minStack = []; -}; - -/** - * @param {number} x - * @return {void} - */ -MinStack.prototype.push = function (x) { - this.stack.unshift(x); - if (!this.minStack.length || this.minStack[0] >= x) { - this.minStack.unshift(x); - } -}; - -/** - * @return {void} - */ -MinStack.prototype.pop = function () { - if (this.stack.shift() === this.minStack[0]) { - this.minStack.shift(); - } -}; - -/** - * @return {number} - */ -MinStack.prototype.top = function () { - return this.stack[0]; -}; - -/** - * @return {number} - */ -MinStack.prototype.min = function () { - return this.minStack[0]; -}; - -/** - * Your MinStack object will be instantiated and called as such: - * var obj = new MinStack() - * obj.push(x) - * obj.pop() - * var param_3 = obj.top() - * var param_4 = obj.min() - */ diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 933d6fe0..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,30 +0,0 @@ -class MinStack: - - def __init__(self): - """ - initialize your data structure here. - """ - self.s1 = [] - self.s2 = [] - - def push(self, x: int) -> None: - self.s1.append(x) - self.s2.append(x if not self.s2 or self.s2[-1] >= x else self.s2[-1]) - - def pop(self) -> None: - self.s1.pop() - self.s2.pop() - - def top(self) -> int: - return self.s1[-1] - - def min(self) -> int: - return self.s2[-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/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 53ac0892..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @param {number[]} pushed - * @param {number[]} popped - * @return {boolean} - */ -var validateStackSequences = function (pushed, popped) { - let s = []; - let q = 0; - for (let num of pushed) { - s.push(num); - while (s.length > 0 && s[s.length - 1] == popped[q]) { - ++q; - s.pop(); - } - } - return s.length == 0; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 070d2465..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: - s = [] - q = 0 - for num in pushed: - s.append(num) - while s and s[-1] == popped[q]: - s.pop() - q += 1 - return not s diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 1409ec6b..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ - -class Solution { -public: - vector levelOrder(TreeNode* root) { - vector ret; - if (!root) { - return ret; - } - - queue q; - q.push(root); - - while (!q.empty()) { - auto head = q.front(); - q.pop(); - ret.push_back(head->val); - if (head->left) { - q.push(head->left); - } - - if (head->right) { - q.push(head->right); - } - } - - return ret; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 89e49ee8..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,21 +0,0 @@ -func levelOrder(root *TreeNode) []int { - if root == nil { - return []int{} - } - q := []*TreeNode{} - q = append(q,root) - //层序遍历,用队列,遍历到谁,就把谁的左右结点加入队列 - res := []int{} - for len(q) != 0 { - tmp := q[0] - q = q[1:] - res = append(res,tmp.Val) - if tmp.Left != nil { - q = append(q,tmp.Left) - } - if tmp.Right != nil { - q = append(q,tmp.Right) - } - } - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index ed12160e..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number[]} - */ -var levelOrder = function (root) { - if (!root) return []; - let queue = [root]; - let res = []; - while (queue.length) { - let node = queue.shift(); - if (!node) continue; - res.push(node.val); - queue.push(node.left, node.right); - } - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 349c5a5b..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,24 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrder(self, root: TreeNode) -> List[int]: - if root is None: - return [] - q = deque() - q.append(root) - res = [] - while q: - size = len(q) - for _ in range(size): - node = q.popleft() - res.append(node.val) - if node.left: - q.append(node.left) - if node.right: - q.append(node.right) - return res diff --git "a/leetcode/lcof/\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\221 II/Solution.go" "b/leetcode/lcof/\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\221 II/Solution.go" deleted file mode 100644 index cd4531e2..00000000 --- "a/leetcode/lcof/\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\221 II/Solution.go" +++ /dev/null @@ -1,27 +0,0 @@ -func levelOrder(root *TreeNode) [][]int { - if root == nil { - return nil - } - res := [][]int{} - queue := []*TreeNode{} - queue = append(queue,root) - for len(queue) != 0 { - size := len(queue) - ans := []int{} - //利用一个变量记录每层大小 - for size > 0 { - cur := queue[0] - ans = append(ans, cur.Val) - queue = queue[1:] - size-- - if cur.Left != nil { - queue = append(queue, cur.Left) - } - if cur.Right != nil { - queue = append(queue, cur.Right) - } - } - res = append(res, ans) - } - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\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\221 II/Solution.js" "b/leetcode/lcof/\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\221 II/Solution.js" deleted file mode 100644 index 3647f4ad..00000000 --- "a/leetcode/lcof/\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\221 II/Solution.js" +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number[][]} - */ -var levelOrder = function (root) { - if (!root) return []; - let queue = [root]; - let res = []; - let depth = 0; - while (queue.length) { - let len = queue.length; - for (let i = 0; i < len; i++) { - let node = queue.shift(); - if (!node) continue; - if (!res[depth]) res[depth] = []; - res[depth].push(node.val); - queue.push(node.left, node.right); - } - depth++; - } - return res; -}; diff --git "a/leetcode/lcof/\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\221 II/Solution.py" "b/leetcode/lcof/\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\221 II/Solution.py" deleted file mode 100644 index 2e05782a..00000000 --- "a/leetcode/lcof/\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\221 II/Solution.py" +++ /dev/null @@ -1,26 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrder(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - q = deque() - res = [] - q.append(root) - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.popleft() - t.append(node.val) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - res.append(t) - return res diff --git "a/leetcode/lcof/\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\221 III/Solution.go" "b/leetcode/lcof/\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\221 III/Solution.go" deleted file mode 100644 index c0c6fb6b..00000000 --- "a/leetcode/lcof/\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\221 III/Solution.go" +++ /dev/null @@ -1,34 +0,0 @@ -func levelOrder(root *TreeNode) [][]int { - if root == nil { - return nil - } - res := [][]int{} - queue := []*TreeNode{} - queue = append(queue,root) - level := 0 - for len(queue) != 0 { - size := len(queue) - ans := []int{} - //size记录每层大小,level记录层数 - for size > 0 { - cur := queue[0] - if level & 1 == 0 { - ans = append(ans, cur.Val) - } else { - ans = append([]int{cur.Val},ans...) - } - - queue = queue[1:] - size-- - if cur.Left != nil { - queue = append(queue, cur.Left) - } - if cur.Right != nil { - queue = append(queue, cur.Right) - } - } - level++ - res = append(res, ans) - } - return res -} \ No newline at end of file diff --git "a/leetcode/lcof/\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\221 III/Solution.js" "b/leetcode/lcof/\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\221 III/Solution.js" deleted file mode 100644 index e8411332..00000000 --- "a/leetcode/lcof/\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\221 III/Solution.js" +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number[][]} - */ -var levelOrder = function (root) { - if (!root) return []; - let queue = [root]; - let res = []; - let depth = 0; - let dir = true; - while (queue.length) { - let len = queue.length; - for (let i = 0; i < len; i++) { - let node = queue.shift(); - if (!node) continue; - if (!res[depth]) res[depth] = []; - if (dir) { - res[depth].push(node.val); - } else { - res[depth].unshift(node.val); - } - queue.push(node.left, node.right); - } - depth++; - dir = !dir; - } - return res; -}; diff --git "a/leetcode/lcof/\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\221 III/Solution.py" "b/leetcode/lcof/\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\221 III/Solution.py" deleted file mode 100644 index 76658bed..00000000 --- "a/leetcode/lcof/\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\221 III/Solution.py" +++ /dev/null @@ -1,26 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrder(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - q = deque() - res = [] - q.append(root) - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.popleft() - t.append(node.val) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - res.append(t if len(res) & 1 == 0 else t[::-1]) - return res diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index a0a12aff..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,28 +0,0 @@ -func verifyPostorder(postorder []int) bool { - if len(postorder) < 2 { - return true - } - return helper(postorder, 0, len(postorder)-1) -} -// 递归 -func helper(postorder []int , left,right int) bool { - if left >= right { - return true - } - // 最后一位即根 - rootValue := postorder[right] - // 从左开始往右遍历,直到大于根停止,小于部分是左子树 - i := left - for i < right && postorder[i] < rootValue { - i++ - } - // 剩下部分是右子树,检查是否都大于根值 - for j := i; j < right; j++ { - if postorder[j] < rootValue { - return false - } - } - l := helper(postorder,left,i-1) // 检查左子树,左子树i要减一 - r := helper(postorder,i,right-1)// 检查右子树,剔除最后一位是根 - return l && r -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 76f31619..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @param {number[]} postorder - * @return {boolean} - */ -var verifyPostorder = function (postorder) { - if (!postorder || postorder.length < 2) return true; - let mid = 0; - let root = postorder[postorder.length - 1]; - for (let i = 0; i < postorder.length - 1 && postorder[i] < root; i++) { - mid++; - } - for (let i = mid + 1; i < postorder.length - 1; i++) { - if (postorder[i] < root) return false; - } - return ( - verifyPostorder(postorder.slice(0, mid)) && - verifyPostorder(postorder.slice(mid + 1, postorder.length - 1)) - ); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index d06eac4b..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def verifyPostorder(self, postorder: List[int]) -> bool: - def verify(p1, p2): - if p1 > p2: - return True - pos = p1 - while pos < p2 and postorder[pos] < postorder[p2]: - pos += 1 - p = pos - while pos < p2: - if postorder[pos] < postorder[p2]: - return False - pos += 1 - return verify(p1, p - 1) and verify(p, p2 - 1) - if not postorder: - return True - return verify(0, len(postorder) - 1) diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 5a3e06a9..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,25 +0,0 @@ -var res [][]int -func pathSum(root *TreeNode, sum int) [][]int { - res = [][]int{} - if root == nil { - return res - } - helper(root, sum, []int{}) - return res -} - -func helper(node *TreeNode, target int, ans []int) { - if node == nil { - return - } - ans = append(ans,node.Val) - target -= node.Val - if target == 0 && node.Left == nil && node.Right == nil { - tmp := make([]int,len(ans)) - copy(tmp,ans) - res = append(res,tmp) - } else { - helper(node.Left, target, ans) - helper(node.Right, target, ans) - } -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 94e89520..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {number} sum - * @return {number[][]} - */ -var pathSum = function (root, sum) { - if (!root) return []; - let res = []; - function dfs(node, sum, arr) { - if (!node) return; - arr = [...arr, node.val]; - if (node.val === sum && !node.left && !node.right) { - res.push(arr); - return; - } - dfs(node.left, sum - node.val, arr); - dfs(node.right, sum - node.val, arr); - } - dfs(root, sum, []); - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index dfa78edc..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,24 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: - def dfs(root, sum): - if root is None: - return - path.append(root.val) - if root.val == sum and root.left is None and root.right is None: - res.append(path.copy()) - dfs(root.left, sum - root.val) - dfs(root.right, sum - root.val) - path.pop() - if not root: - return [] - res = [] - path = [] - dfs(root, sum) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index 4c3db0ca..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,44 +0,0 @@ -func copyRandomList(head *Node) *Node { - if head == nil { - return nil - } - cur, next := head,head - //完成对当前节点的复制 - for cur != nil { - next = cur.Next - cur.Next = &Node{ - Val: cur.Val, - Next: next, - Random: nil, - } - cur = next - } - //设置复制节点的random节点 - cur = head - curCopy := head - for cur != nil { - next = cur.Next.Next - curCopy = cur.Next - if cur.Random == nil { - curCopy.Random = nil - } else { - curCopy.Random = cur.Random.Next - } - cur = next - } - res := head.Next - cur = head - for cur != nil { - next = cur.Next.Next - curCopy = cur.Next - cur.Next = next - if next != nil { - curCopy.Next = next.Next - } else { - curCopy.Next = nil - } - cur = cur.Next - } - return res - -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 17301c76..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,25 +0,0 @@ -/** - * // Definition for a Node. - * function Node(val, next, random) { - * this.val = val; - * this.next = next; - * this.random = random; - * }; - */ -/** - * @param {Node} head - * @return {Node} - */ -var copyRandomList = function (head) { - function copy(node) { - if (!node) return null; - if (isRead.get(node)) return isRead.get(node); - let newNode = new Node(node.val); - isRead.set(node, newNode); - newNode.random = copy(node.random); - newNode.next = copy(node.next); - return newNode; - } - let isRead = new Map(); - return copy(head); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 82aede24..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,26 +0,0 @@ -""" -# 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 None - copy_head = Node(-1) - cur, t = copy_head, head - cache = {} - while t: - cur.next = Node(t.val) - cache[t] = cur.next - cur, t = cur.next, t.next - t, cur = head, copy_head.next - while t: - cur.random = cache.get(t.random) - cur, t = cur.next, t.next - return copy_head.next diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 8edd9c4f..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,29 +0,0 @@ -/** - * // Definition for a Node. - * function Node(val,left,right) { - * this.val = val; - * this.left = left; - * this.right = right; - * }; - */ -/** - * @param {Node} root - * @return {Node} - */ -var treeToDoublyList = function (root) { - function dfs(cur) { - if (!cur) return; - dfs(cur.left); - if (!pre) head = cur; - else pre.right = cur; - cur.left = pre; - pre = cur; - dfs(cur.right); - } - if (!root) return null; - let head, pre; - dfs(root); - head.left = pre; - pre.right = head; - return head; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 3b425cca..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,28 +0,0 @@ -""" -# Definition for a Node. -class Node: - def __init__(self, val, left=None, right=None): - self.val = val - self.left = left - self.right = right -""" -class Solution: - def treeToDoublyList(self, root: 'Node') -> 'Node': - def dfs(cur): - if cur is None: - return - dfs(cur.left) - if self.pre is None: - self.head = cur - else: - self.pre.right = cur - cur.left = self.pre - self.pre = cur - dfs(cur.right) - if root is None: - return None - self.head = self.pre = None - dfs(root) - self.head.left = self.pre - self.pre.right = self.head - return self.head diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" deleted file mode 100644 index 367c42e8..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.js" +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ - -/** - * Encodes a tree to a single string. - * - * @param {TreeNode} root - * @return {string} - */ -var serialize = function (root) { - if (!root) return "[]"; - let queue = [root]; - let res = ""; - while (queue.length) { - let node = queue.shift(); - if (node) { - res += node.val + ","; - queue.push(node.left); - queue.push(node.right); - } else { - res += "null" + ","; - } - } - return `[${res.substring(0, res.length - 1)}]`; -}; - -/** - * Decodes your encoded data to tree. - * - * @param {string} data - * @return {TreeNode} - */ -var deserialize = function (data) { - if (!data || data.length <= 2) return null; - let arr = data.substring(1, data.length - 1).split(","); - let root = new TreeNode(arr.shift()); - let queue = [root]; - while (queue.length) { - let node = queue.shift(); - let leftVal = arr.shift(); - if (leftVal !== "null") { - node.left = new TreeNode(leftVal); - queue.push(node.left); - } - let rightVal = arr.shift(); - if (rightVal !== "null") { - node.right = new TreeNode(rightVal); - queue.push(node.right); - } - } - return root; -}; - -/** - * Your functions will be called as such: - * deserialize(serialize(root)); - */ diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.py" deleted file mode 100644 index f2178846..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23037. \345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221/Solution.py" +++ /dev/null @@ -1,60 +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 Codec: - - def serialize(self, root): - """Encodes a tree to a single string. - - :type root: TreeNode - :rtype: str - """ - if not root: - return '[]' - queue = collections.deque() - queue.append(root) - res = [] - while queue: - node = queue.popleft() - if node: - res.append(str(node.val)) - queue.append(node.left) - queue.append(node.right) - else: - res.append('null') - return f'[{",".join(res)}]' - - - def deserialize(self, data): - """Decodes your encoded data to tree. - - :type data: str - :rtype: TreeNode - """ - if not data or data == '[]': - return None - queue = collections.deque() - nodes = data[1:-1].split(',') - root = TreeNode(nodes[0]) - queue.append(root) - idx = 1 - while queue and idx < len(nodes): - node = queue.popleft() - if nodes[idx] != 'null': - node.left = TreeNode(nodes[idx]) - queue.append(node.left) - idx += 1 - if nodes[idx] != 'null': - node.right = TreeNode(nodes[idx]) - queue.append(node.right) - idx += 1 - return root - - -# Your Codec object will be instantiated and called as such: -# codec = Codec() -# codec.deserialize(codec.serialize(root)) \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 3d3775e4..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,25 +0,0 @@ -class Solution { -public: - void func(string str, int index, set& mySet) { - if (index == str.size()) { - mySet.insert(str); - } else { - for (int i = index; i < str.size(); i++) { - swap(str[i], str[index]); - int temp = index + 1; - func(str, temp, mySet); - swap(str[i], str[index]); - } - } - } - - vector permutation(string s) { - set mySet; - func(s, 0, mySet); - vector ret; - for (string x : mySet) { - ret.push_back(x); - } - return ret; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 4e0077b2..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @param {string} s - * @return {string[]} - */ -var permutation = function (s) { - let len = s.length; - let res = new Set(); - function dfs(str, isRead) { - if (str.length === len) { - res.add(str); - return; - } - for (let i = 0; i < len; i++) { - if (isRead[i]) continue; - isRead[i] = 1; - dfs(str.concat(s[i]), isRead); - isRead[i] = 0; - } - } - dfs("", {}); - return [...res]; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 5e8f06e2..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def permutation(self, s: str) -> List[str]: - def dfs(x): - if x == len(s) - 1: - res.append("".join(chars)) - return - t = set() - for i in range(x, len(s)): - if chars[i] in t: - continue - t.add(chars[i]) - chars[i], chars[x] = chars[x], chars[i] - dfs(x + 1) - chars[i], chars[x] = chars[x], chars[i] - chars, res = list(s), [] - dfs(0) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 62cac584..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var majorityElement = function (nums) { - let cnt = 0; - let mode = -1; - for (let num of nums) { - if (!cnt) { - mode = num; - cnt++; - } else { - if (mode === num) cnt++; - else cnt--; - } - } - return mode; - // return nums.sort((a,b)=>a-b)[~~(nums.length/2)] -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index dc14c18c..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def majorityElement(self, nums: List[int]) -> int: - cnt = major = 0 - for num in nums: - if cnt == 0: - major = num - cnt += 1 - else: - cnt += (1 if major == num else -1) - return major \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.cpp" deleted file mode 100644 index 765e4d6d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.cpp" +++ /dev/null @@ -1,43 +0,0 @@ -class Solution { -public: - int partition(vector& arr, int begin, int end) { - int l = begin; - int r = end; - int povit = arr[begin]; - - while (l < r) { - // 从右边开始,找到第一个小于povit的数字(用于交换) - while (l < r && arr[r] >= povit) { r--; } - while (l < r && arr[l] <= povit) { l++; } - if (l < r) { swap(arr[l], arr[r]); } - } - - swap(arr[begin], arr[l]); - return l; - } - - void partSort(vector& arr, int begin, int end, int target) { - if (begin >= end) { - return; - } - - // 思路类似快排,这样做比堆排序时间复杂度低 - // C++中,stl提供partial_sort()方法,就是这种实现方式 - int mid = partition(arr, begin, end); - if (mid == target) { - return; - } else if (target < mid) { - partSort(arr, begin, mid - 1, target); - } else { - partSort(arr, mid + 1, end, target); - } - - return; - } - - vector getLeastNumbers(vector& arr, int k) { - partSort(arr, 0, arr.size() - 1, k - 1); - vector ret(arr.begin(), arr.begin() + k); - return ret; - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" deleted file mode 100644 index 6635277b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.js" +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @param {number[]} arr - * @param {number} k - * @return {number[]} - */ -var getLeastNumbers = function (arr, k) { - // 排序 - // return arr.sort((a,b)=>a-b).slice(0,k) - // ========================================== - // 快排思想 - let left = 0; - let right = arr.length - 1; - while (left < right) { - let i = partition(left, right); - if (i <= k) { - left = i + 1; - } - if (i >= k) { - right = i - 1; - } - } - function partition(left, right) { - let pivot = arr[left]; - while (left < right) { - while (left < right && arr[right] >= pivot) { - right--; - } - arr[left] = arr[right]; - while (left < right && arr[left] <= pivot) { - left++; - } - arr[right] = arr[left]; - } - arr[left] = pivot; - return left; - } - return arr.slice(0, k); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.py" deleted file mode 100644 index c3a1842b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23040. \346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260/Solution.py" +++ /dev/null @@ -1,10 +0,0 @@ -import heapq - -class Solution: - def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: - if k == 0: - return [] - heap = [] - for e in arr: - heapq.heappush(heap, e) - return heapq.nsmallest(k, heap) \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" deleted file mode 100644 index 53a75740..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.js" +++ /dev/null @@ -1,34 +0,0 @@ -/** - * initialize your data structure here. - */ -var MedianFinder = function () { - this.val = []; -}; - -/** - * @param {number} num - * @return {void} - */ -MedianFinder.prototype.addNum = function (num) { - let left = 0; - let right = this.val.length; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (num > this.val[mid]) { - left = mid + 1; - } else { - right = mid; - } - } - this.val.splice(left, 0, num); -}; - -/** - * @return {number} - */ -MedianFinder.prototype.findMedian = function () { - let mid = ~~(this.val.length / 2); - return this.val.length % 2 - ? this.val[mid] - : (this.val[mid - 1] + this.val[mid]) / 2; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.py" deleted file mode 100644 index 92906fe3..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.py" +++ /dev/null @@ -1,24 +0,0 @@ -class MedianFinder: - - def __init__(self): - """ - initialize your data structure here. - """ - self.max_heap = [] - self.min_heap = [] - - - def addNum(self, num: int) -> None: - if len(self.max_heap) == len(self.min_heap): - heapq.heappush(self.min_heap, -heapq.heappushpop(self.max_heap, -num)) - else: - heapq.heappush(self.max_heap, -heapq.heappushpop(self.min_heap, num)) - - def findMedian(self) -> float: - return (-self.max_heap[0] + self.min_heap[0]) / 2 if len(self.max_heap) == len(self.min_heap) else self.min_heap[0] - - -# Your MedianFinder object will be instantiated and called as such: -# obj = MedianFinder() -# obj.addNum(num) -# param_2 = obj.findMedian() \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 34bfffa3..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var maxSubArray = function (nums) { - if (!nums || !nums.length) return null; - let len = nums.length; - let dp = new Array(len); - dp[0] = nums[0]; - for (let i = 1; i < len; i++) { - dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]); - } - return Math.max(...dp); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index a2c4b9ea..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def maxSubArray(self, nums: List[int]) -> int: - n = len(nums) - res = f = nums[0] - for i in range(1, n): - f = nums[i] + max(f, 0) - res = max(res, f) - return res diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" deleted file mode 100644 index ce8b7bb7..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var countDigitOne = function (n) { - let res = 0; - let i = 1; - while (i <= n) { - let high = ~~(n / i / 10); - let cur = ~~(n / i) % 10; - let low = n - ~~(n / i) * i; - switch (cur) { - case 0: - res += high * i; - break; - case 1: - res += high * i + low + 1; - break; - default: - res += (high + 1) * i; - } - i *= 10; - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" deleted file mode 100644 index d8d9ef7f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23043. 1\357\275\236n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -from functools import lru_cache - -class Solution: - @lru_cache - def countDigitOne(self, n: int) -> int: - if n < 1: - return 0 - s = str(n) - high = int(s[0]) - base = pow(10, len(s) - 1) - lows = n % base - return self.countDigitOne(base - 1) + lows + 1 + self.countDigitOne(lows) if high == 1 else high * self.countDigitOne(base - 1) + base + self.countDigitOne(lows) \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" deleted file mode 100644 index 815d5889..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.js" +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var findNthDigit = function (n) { - let i = 9; - let a = 1; - let remain = n; - while (i * a < remain) { - remain -= i * a; - i *= 10; - a++; - } - let b = remain % a; - let res = 10 ** (a - 1) + ~~(remain / a); - if (b === 0) { - b = a; - res--; - } - return res.toString()[b - 1]; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.py" deleted file mode 100644 index 082ad95a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23044. \346\225\260\345\255\227\345\272\217\345\210\227\344\270\255\346\237\220\344\270\200\344\275\215\347\232\204\346\225\260\345\255\227/Solution.py" +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def findNthDigit(self, n: int) -> int: - def get_bit_num(): - return 10 if p == 0 else 9 * pow(10, p) * (p + 1) - - if n < 10: - return n - p = count = 0 - while 1: - count = get_bit_num() - if n < count: break - n -= count - p += 1 - num = n // (p + 1) + pow(10, p) - return int(str(num)[n % (p + 1)]) - - diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" deleted file mode 100644 index 4c67f3da..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.js" +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @param {number[]} nums - * @return {string} - */ -var minNumber = function (nums) { - nums.sort((a, b) => { - let s1 = a + "" + b; - let s2 = b + "" + a; - if (s1 < s2) { - return -1; - } else return 1; - }); - return nums.join(""); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.py" deleted file mode 100644 index 1b45ea3d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.py" +++ /dev/null @@ -1,16 +0,0 @@ -import functools - - -class Solution: - def minNumber(self, nums: List[int]) -> str: - if not nums: - return '' - - def compare(s1, s2): - if s1 + s2 < s2 + s1: - return -1 - if s1 + s2 > s2 + s1: - return 1 - return 0 - - return ''.join(sorted([str(x) for x in nums], key=functools.cmp_to_key(compare))) diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" deleted file mode 100644 index efd6471e..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.js" +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @param {number} num - * @return {number} - */ -var translateNum = function (num) { - let res = 0; - num = num.toString(); - function dfs(i) { - if (i >= num.length) { - res++; - return; - } - dfs(i + 1); - let tmp = +(num[i] + num[i + 1]); - if (num[i] !== "0" && tmp >= 0 && tmp < 26) { - dfs(i + 2); - } - } - dfs(0); - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.py" deleted file mode 100644 index 2778f8d1..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23046. \346\212\212\346\225\260\345\255\227\347\277\273\350\257\221\346\210\220\345\255\227\347\254\246\344\270\262/Solution.py" +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def translateNum(self, num: int) -> int: - def cal(s): - if len(s) < 2: - return 1 - t = int(s[:2]) - return cal(s[1:]) if t < 10 or t > 25 else cal(s[1:]) + cal(s[2:]) - return cal(str(num)) \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index d957d8d5..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {number[][]} grid - * @return {number} - */ -var maxValue = function (grid) { - let row = grid.length; - let col = grid[0].length; - let dp = [...new Array(row + 1)].map(() => Array(col + 1).fill(0)); - for (let i = 1; i <= row; i++) { - for (let j = 1; j <= col; j++) { - dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + grid[i - 1][j - 1]; - } - } - return dp[row][col]; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 827d2d5c..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def maxValue(self, grid: List[List[int]]) -> int: - rows, cols = len(grid), len(grid[0]) - vals = [[0 for _ in range(cols)] for _ in range(rows)] - vals[0][0] = grid[0][0] - for i in range(1, rows): - vals[i][0] = vals[i - 1][0] + grid[i][0] - for j in range(1, cols): - vals[0][j] = vals[0][j - 1] + grid[0][j] - for i in range(1, rows): - for j in range(1, cols): - vals[i][j] = grid[i][j] + max(vals[i - 1][j], vals[i][j - 1]) - return vals[rows - 1][cols - 1] diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.cpp" deleted file mode 100644 index 51b8def3..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.cpp" +++ /dev/null @@ -1,32 +0,0 @@ -class Solution { -public: - int lengthOfLongestSubstring(string s) { - int arr[1024]; // 本题的用例中,有不为小写字母的情况 - for (int i = 0; i < 1024; i++) { - arr[i] = -1; - } - - int curLen = 0; - int maxLen = 0; - - int len = s.size(); - for (int i = 0; i < len; i++) { - int prev = arr[int(s[i])]; // 之前位置的index - if (prev < 0 || i - prev > curLen) { - // 其中,prev>0表示之前没有遇到过该字符 - // i - prev > curLen 表示之前遇到的当前字符,远超当前限定的范围 - // 这两种情况下,都是直接继续加就可以了 - curLen++; - } else { - if (curLen > maxLen) { - maxLen = curLen; - } - curLen = i - prev; // curLen重新开始计数 - } - - arr[int(s[i])] = i; - } - - return maxLen > curLen ? maxLen : curLen; - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" deleted file mode 100644 index 32e3477f..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.js" +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @param {string} s - * @return {number} - */ -var lengthOfLongestSubstring = function (s) { - let left = 0; - let right = 0; - let res = 0; - let len = s.length; - let rec = {}; - while (right < len) { - let tmp = "*"; - while (right < len) { - tmp = s[right]; - if (!rec[tmp]) rec[tmp] = 0; - rec[tmp]++; - if (rec[tmp] > 1) break; - right++; - } - res = Math.max(res, right - left); - while (rec[tmp] > 1) rec[s[left++]]--; - right++; - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.py" deleted file mode 100644 index 3cb97440..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23048. \346\234\200\351\225\277\344\270\215\345\220\253\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\345\255\220\345\255\227\347\254\246\344\270\262/Solution.py" +++ /dev/null @@ -1,19 +0,0 @@ -class Solution: - def lengthOfLongestSubstring(self, s: str) -> int: - if not s: - return 0 - cache = {} - cache[s[0]] = 0 - dp = [0 for _ in s] - dp[0] = res = 1 - for i in range(1, len(s)): - if s[i] == s[i - 1]: - dp[i] = 1 - else: - if cache.get(s[i]) is None: - dp[i] = dp[i - 1] + 1 - else: - dp[i] = min(dp[i - 1] + 1, i - cache[s[i]]) - cache[s[i]] = i - res = max(res, dp[i]) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" deleted file mode 100644 index d1da4ed6..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var nthUglyNumber = function (n) { - let res = [1]; - //三指针 - let a = 0; //2 - let b = 0; //3 - let c = 0; //5 - let min = 0; - for (let i = 1; i < n; i++) { - min = Math.min(res[a] * 2, res[b] * 3, res[c] * 5); - if (min === res[a] * 2) a++; - if (min === res[b] * 3) b++; - if (min === res[c] * 5) c++; - res.push(min); - } - return res[n - 1]; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.py" deleted file mode 100644 index 0b439d9d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23049. \344\270\221\346\225\260/Solution.py" +++ /dev/null @@ -1,16 +0,0 @@ -class Solution: - def nthUglyNumber(self, n: int) -> int: - if n < 7: - return n - dp = [1 for _ in range(n)] - i2 = i3 = i5 = 0 - for i in range(1, n): - next2, next3, next5 = dp[i2] * 2, dp[i3] * 3, dp[i5] * 5 - dp[i] = min(next2, next3, next5) - if dp[i] == next2: - i2 += 1 - if dp[i] == next3: - i3 += 1 - if dp[i] == next5: - i5 += 1 - return dp[n - 1] diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 380efd25..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {string} s - * @return {character} - */ -var firstUniqChar = function (s) { - let t = new Array(26).fill(0); - let code = "a".charCodeAt(); - for (let i = 0; i < s.length; i++) { - t[s[i].charCodeAt() - code]++; - } - for (let i = 0; i < s.length; i++) { - if (t[s[i].charCodeAt() - code] === 1) return s[i]; - } - return " "; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index e2114c4e..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,13 +0,0 @@ -import collections - -class Solution: - def firstUniqChar(self, s: str) -> str: - if s == '': - return ' ' - cache = collections.OrderedDict() - for c in s: - cache[c] = 1 if cache.get(c) is None else cache[c] + 1 - for k, v in cache.items(): - if v == 1: - return k - return ' ' \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" deleted file mode 100644 index 58d38881..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.js" +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var reversePairs = function (nums) { - if (!nums || nums.length < 2) return 0; - let res = 0; - function mergeSort(arr) { - if (arr.length === 1) { - return arr; - } - let mid = ~~(arr.length / 2); - return merge(mergeSort(arr.slice(0, mid)), mergeSort(arr.slice(mid))); - } - function merge(a, b) { - let r = []; - let cnt = 0; - while (a && b && a.length && b.length) { - if (a[0] <= b[0]) { - res += cnt; - r.push(a.shift()); - } else { - r.push(b.shift()); - cnt++; - } - } - res += a.length * cnt; - return r.concat(a, b); - } - mergeSort(nums); - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.py" deleted file mode 100644 index f77dd234..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23051. \346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271/Solution.py" +++ /dev/null @@ -1,36 +0,0 @@ -class Solution: - def reversePairs(self, nums: List[int]) -> int: - self.res = 0 - - def merge(part1, part2, nums): - len1, len2 = len(part1) - 1, len(part2) - 1 - t = len(nums) - 1 - while len1 >= 0 and len2 >= 0: - if part1[len1] > part2[len2]: - self.res += (len2 + 1) - nums[t] = part1[len1] - len1 -= 1 - else: - nums[t] = part2[len2] - len2 -= 1 - t -= 1 - while len1 >= 0: - nums[t] = part1[len1] - t -= 1 - len1 -= 1 - while len2 >= 0: - nums[t] = part2[len2] - t -= 1 - len2 -= 1 - - def merge_sort(nums): - if len(nums) < 2: - return - mid = len(nums) // 2 - s1, s2 = nums[:mid], nums[mid:] - merge_sort(s1) - merge_sort(s2) - merge(s1, s2, nums) - - merge_sort(nums) - return self.res diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 098df8e6..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ - -class Solution { -public: - ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { - ListNode* a = headA; - ListNode* b = headB; - while (a != b) { - a = (a == nullptr) ? headB : a->next; - b = (b == nullptr) ? headA : b->next; - } - - return a; - } -}; diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index af5703f7..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ - -/** - * @param {ListNode} headA - * @param {ListNode} headB - * @return {ListNode} - */ -var getIntersectionNode = function (headA, headB) { - let h1 = headA; - let h2 = headB; - while (h1 !== h2) { - h1 = h1 === null ? headB : h1.next; - h2 = h2 === null ? headA : h2.next; - } - return h2; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 1c32b806..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,29 +0,0 @@ -# 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 headA is None or headB is None: - return None - len1 = len2 = 0 - p, q = headA, headB - while p: - p = p.next - len1 += 1 - while q: - q = q.next - len2 += 1 - p, q = headA, headB - if len1 > len2: - p, q = q, p - for _ in range(abs(len1 - len2)): - q = q.next - while p and q: - if p == q: - return p - p = p.next - q = q.next - diff --git "a/leetcode/lcof/\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\227 I/Solution.js" "b/leetcode/lcof/\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\227 I/Solution.js" deleted file mode 100644 index 3b209739..00000000 --- "a/leetcode/lcof/\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\227 I/Solution.js" +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @param {number[]} nums - * @param {number} target - * @return {number} - */ -var search = function (nums, target) { - if (!nums || !nums.length) return 0; - let left = 0; - let right = nums.length - 1; - let res = 0; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (nums[mid] < target) { - left = mid + 1; - } else if (nums[mid] > target) { - right = mid; - } else { - left = mid; - right = mid; - break; - } - } - while (nums[left] === target) { - res++; - left--; - } - while (nums[++right] === target) { - res++; - } - return res; -}; diff --git "a/leetcode/lcof/\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\227 I/Solution.py" "b/leetcode/lcof/\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\227 I/Solution.py" deleted file mode 100644 index 0c0ef69b..00000000 --- "a/leetcode/lcof/\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\227 I/Solution.py" +++ /dev/null @@ -1,29 +0,0 @@ -class Solution: - def search(self, nums: List[int], target: int) -> int: - if not nums: - return 0 - l, r = 0, len(nums) - 1 - while l <= r: - m = l + ((r - l) >> 1) - if nums[m] == target: - return self._count(nums, l, r, m) - if nums[m] < target: - l = m + 1 - else: - r = m - 1 - return 0 - - def _count(self, nums, l, r, m) -> int: - cnt = 0 - for i in range(m, l - 1, -1): - if nums[i] == nums[m]: - cnt += 1 - elif nums[i] < nums[m]: - break - - for i in range(m + 1, r + 1): - if nums[i] == nums[m]: - cnt += 1 - elif nums[i] > nums[m]: - break - return cnt \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 6a033697..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var missingNumber = function (nums) { - if (!nums || !nums.length) return 0; - let left = 0; - let right = nums.length - 1; - while (left < right) { - let mid = left + ~~((right - left) / 2); - if (nums[mid] !== mid) { - right = mid; - } else { - left = mid + 1; - } - } - return nums[left] === left ? nums.length : left; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 6d673952..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def missingNumber(self, nums: List[int]) -> int: - l, r = 0, len(nums) - 1 - if r == 0 or nums[0] == 1: - return nums[0] ^ 1 - if nums[r] == r: - return r + 1 - while r - l > 1: - m = l + ((r - l) >> 1) - if nums[m] == m: - l = m - else: - r = m - return nums[r] - 1 \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 55cf9716..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {number} k - * @return {number} - */ -var kthLargest = function (root, k) { - let res; - let t = 0; - function traversal(node) { - if (!node) return; - traversal(node.right); - if (++t === k) res = node.val; - traversal(node.left); - } - traversal(root); - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 1e9bc7f3..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,24 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - - -class Solution: - t, res = 0, -1 - - def kthLargest(self, root: TreeNode, k: int) -> int: - self.t = k - self._traverse(root) - return self.res - - def _traverse(self, node): - if node: - self._traverse(node.right) - self.t -= 1 - if self.t == 0: - self.res = node.val - return - self._traverse(node.left) diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index f7229d20..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ - -class Solution { -public: - int maxDepth(TreeNode* root) { - if (nullptr == root) { - return 0; - } - - int left = maxDepth(root->left); - int right = maxDepth(root->right); - return std::max(left, right) + 1; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 5d4a90fa..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number} - */ -var maxDepth = function (root) { - let res = 0; - function traversal(node, depth) { - if (!node) { - res = Math.max(res, depth); - return; - } - traversal(node.left, depth + 1); - traversal(node.right, depth + 1); - } - traversal(root, 0); - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index d29203d4..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -# 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 root is None: - return 0 - return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.cpp" deleted file mode 100644 index 33360a0a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.cpp" +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ - -class Solution { -public: - bool isBalanced(TreeNode* root, int* depth) { - if (root == nullptr) { - *depth = 0; - return true; - } - - int left = 0; - int right = 0; - if (isBalanced(root->left, &left) - && isBalanced(root->right, &right)) { - int diff = left - right; - if (diff > 1 || diff < -1) { - // 如果有一处不符合 -1 < diff < 1,则直接返回false - return false; - } else { - // 如果符合,则记录当前深度,然后返回上一层继续计算 - *depth = max(left, right) + 1; - return true; - } - } - - return false; // 如果有一处已经确定不是平衡二叉树了,则直接返回false - } - - bool isBalanced(TreeNode* root) { - if (!root) { - return true; - } - - int depth = 0; - return isBalanced(root, &depth); - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" deleted file mode 100644 index 05db6eaf..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.js" +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {boolean} - */ -var isBalanced = function (root) { - if (!root) return true; - if (!isBalanced(root.left) || !isBalanced(root.right)) return false; - if (Math.abs(getDepth(root.left) - getDepth(root.right)) > 1) return false; - return true; -}; - -function getDepth(node) { - if (!node) return 0; - return Math.max(getDepth(node.left), getDepth(node.right)) + 1; -} diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.py" deleted file mode 100644 index 99c9f362..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.py" +++ /dev/null @@ -1,17 +0,0 @@ -# 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 root is None: - return True - return abs(self._height(root.left) - self._height(root.right)) <= 1 and self.isBalanced(root.left) and self.isBalanced(root.right) - - def _height(self, tree): - if tree is None: - return 0 - return 1 + max(self._height(tree.left), self._height(tree.right)) \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" deleted file mode 100644 index edc9f367..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.js" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @param {number[]} nums - * @return {number[]} - */ -var singleNumbers = function (nums) { - let xor = 0; - let bit = 1; - let res = [0, 0]; - for (let num of nums) { - xor ^= num; - } - while ((xor & 1) === 0) { - xor >>= 1; - bit <<= 1; - } - for (let num of nums) { - if ((num & bit) === 0) { - res[0] ^= num; - } else { - res[1] ^= num; - } - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" deleted file mode 100644 index b5607257..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - I. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260/Solution.py" +++ /dev/null @@ -1,18 +0,0 @@ -class Solution: - def singleNumbers(self, nums: List[int]) -> List[int]: - xor_res = 0 - for num in nums: - xor_res ^= num - pos = 0 - while (xor_res & 1) == 0: - pos += 1 - xor_res >>= 1 - - a = b = 0 - for num in nums: - t = num >> pos - if (t & 1) == 0: - a ^= num - else: - b ^= num - return [a, b] \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" deleted file mode 100644 index 104282b4..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.js" +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var singleNumber = function (nums) { - let a = 0; - let b = 0; - for (let num of nums) { - a = (a ^ num) & ~b; - b = (b ^ num) & ~a; - } - return a; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.py" deleted file mode 100644 index 70aa1f0a..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23056 - II. \346\225\260\347\273\204\344\270\255\346\225\260\345\255\227\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260 II/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def singleNumber(self, nums: List[int]) -> int: - bits = [0 for _ in range(32)] - for num in nums: - for i in range(32): - bits[i] += (num & 1) - num >>= 1 - res = 0 - for i in range(32): - if bits[i] % 3 == 1: - res += (1 << i) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 16c899bb..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,44 +0,0 @@ -class Solution { -public: - vector build(int small, int big) { - vector ret; - for (int i = small; i <= big; i++) { - ret.push_back(i); - } - - return ret; - } - - vector> findContinuousSequence(int target) { - vector> ret; - int small = 1; - int big = 2; - int mid = (target + 1) / 2; - int curSum = small + big; - - if (target < 3) { - ret; - } - - while(small < mid) { - if (curSum == target) { - ret.push_back(build(small, big)); - } - - while (curSum > target && small < mid) { - // 一直减去,减去到比target小停止 - curSum -= small; - small++; - - if (curSum == target && small < mid) { - ret.push_back(build(small, big)); - } - } - - big++; - curSum += big; - } - - return ret; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 83491c4e..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @param {number} target - * @return {number[][]} - */ -var findContinuousSequence = function (target) { - let res = []; - let window = []; - let i = 1; - let sum = 0; - while (1) { - if (sum < target) { - window.push(i); - sum += i; - i++; - } else if (sum > target) { - let a = window.shift(); - if (window.length < 2) break; - sum -= a; - } else { - res.push([...window]); - window.push(i); - sum += i; - i++; - if (window.length === 2) break; - } - } - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 1ff711c2..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def findContinuousSequence(self, target: int) -> List[List[int]]: - res = [] - p, q = 1, 2 - while p < q: - s = (p + q) * (q - p + 1) >> 1 - if s == target: - res.append([i for i in range(p, q + 1)]) - p += 1 - elif s < target: - q += 1 - else: - p += 1 - return res \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 9964e4dc..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @param {number[]} nums - * @param {number} target - * @return {number[]} - */ -var twoSum = function (nums, target) { - let left = 0; - let right = nums.length - 1; - while (left < right) { - let sum = nums[left] + nums[right]; - if (sum === target) { - return [nums[left], nums[right]]; - } else if (sum > target) { - right--; - } else { - left++; - } - } -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 0f95ba0d..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def twoSum(self, nums: List[int], target: int) -> List[int]: - p, q = 0, len(nums) - 1 - while p < q: - s = nums[p] + nums[q] - if s == target: - return [nums[p], nums[q]] - if s < target: - p += 1 - else: - q -= 1 diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" deleted file mode 100644 index 5b6b16a3..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.js" +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @param {string} s - * @return {string} - */ -var reverseWords = function (s) { - return s - .split(" ") - .reduce((acc, cur) => (cur !== "" ? acc.concat(cur) : acc), []) - .reverse() - .join(" "); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.py" deleted file mode 100644 index 8cf6ca50..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23058 - I. \347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217/Solution.py" +++ /dev/null @@ -1,5 +0,0 @@ -class Solution: - def reverseWords(self, s: str) -> str: - if s is None: - return s - return ' '.join(list(filter(lambda x: x != '', s.strip(' ').split(' ')))[::-1]) \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index c6f9f529..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @param {string} s - * @param {number} n - * @return {string} - */ -var reverseLeftWords = function (s, n) { - return s.substring(n) + s.substr(0, n); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index b2719ef3..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def reverseLeftWords(self, s: str, n: int) -> str: - return s[n:] + s[:n] diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" deleted file mode 100644 index 9e45e78c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.js" +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @param {number[]} nums - * @param {number} k - * @return {number[]} - */ -var maxSlidingWindow = function (nums, k) { - if (!nums.length || !k) return []; - if (k === 1) return nums; - let res = []; - let tmpMax = -Infinity; - let len = nums.length; - let window = []; - for (let i = 0; i < k; i++) { - tmpMax = Math.max(nums[i], tmpMax); - window.push(nums[i]); - } - res.push(tmpMax); - for (let i = k; i < len; i++) { - let a = window.shift(); - window.push(nums[i]); - if (nums[i] > tmpMax) { - tmpMax = nums[i]; - } else if (tmpMax === a) { - tmpMax = Math.max(...window); - } - res.push(tmpMax); - } - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.py" deleted file mode 100644 index 5b3a1a59..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23059 - I. \346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274/Solution.py" +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: - q, res = [], [] - for i, num in enumerate(nums): - while len(q) != 0 and nums[q[-1]] <= num: - q.pop(-1) - q.append(i) - - if q[0] == i - k: - q = q[1:] - if i >= k - 1: - res.append(nums[q[0]]) - return res diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index bdedb1b8..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,47 +0,0 @@ -var MaxQueue = function () { - this.queue = []; - this.maxValue = -Infinity; - this.maxIdx = -1; -}; - -/** - * @return {number} - */ -MaxQueue.prototype.max_value = function () { - if (!this.queue.length) return -1; - return this.maxValue; -}; - -/** - * @param {number} value - * @return {void} - */ -MaxQueue.prototype.push_back = function (value) { - this.queue.push(value); - if (value >= this.maxValue) { - this.maxIdx = this.queue.length - 1; - this.maxValue = value; - } -}; - -/** - * @return {number} - */ -MaxQueue.prototype.pop_front = function () { - if (!this.queue.length) return -1; - let a = this.queue.shift(); - this.maxIdx--; - if (this.maxIdx < 0) { - let tmp = -Infinity; - let id = -1; - for (let i = 0; i < this.queue.length; i++) { - if (this.queue[i] > tmp) { - tmp = this.queue[i]; - id = i; - } - } - this.maxIdx = id; - this.maxValue = tmp; - } - return a; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 7857c2d6..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,32 +0,0 @@ -from collections import deque - - -class MaxQueue: - - def __init__(self): - self.p = deque() - self.q = deque() - - def max_value(self) -> int: - return -1 if not self.q else self.q[0] - - def push_back(self, value: int) -> None: - while self.q and self.q[-1] < value: - self.q.pop() - self.p.append(value) - self.q.append(value) - - def pop_front(self) -> int: - if not self.p: - return -1 - res = self.p.popleft() - if self.q[0] == res: - self.q.popleft() - return res - - -# 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() diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" deleted file mode 100644 index e742a32d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.js" +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @param {number} n - * @return {number[]} - */ -var twoSum = function (n) { - function backtrack(sum, time) { - if (time === n) { - res[sum]++; - return; - } - for (let i = 1; i <= 6; i++) { - backtrack(sum + i, time + 1); - } - } - let len = n * 6; - let t = 6 ** n; - let res = new Array(len + 1).fill(0); - backtrack(0, 0); - return res.slice(n).map((e) => e / t); -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.py" deleted file mode 100644 index 977571ae..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23060. n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260/Solution.py" +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def twoSum(self, n: int) -> List[float]: - dp = [[0 for _ in range(6 * n + 1)] for _ in range(n + 1)] - for j in range(1, 7): - dp[1][j] = 1 - for i in range(2, n + 1): - for j in range(i, 6 * i + 1): - for k in range(1, 7): - if j <= k: - break - dp[i][j] += dp[i - 1][j - k] - res, total = [], pow(6, n) - for i in range(5 * n + 1): - res.append(dp[n][n + i] / total) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.cpp" deleted file mode 100644 index 66bbfb8b..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -class Solution { -public: - bool isStraight(vector& nums) { - if (nums.size() != 5) { - return false; - } - - std::sort(nums.begin(), nums.end()); - int zeroNum = 0; - for (int i = 0; i < nums.size(); i++) { - if (nums[i] != 0) { - // 这题的用例中,会出现超过两个0的情况 - break; - } - zeroNum++; - } - - for (int i = zeroNum; i < nums.size()-1; i++) { - if (nums[i] == nums[i+1]) { - return false; - } - } - - return nums[4] - nums[zeroNum] <= 4; - } -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" deleted file mode 100644 index 1fe7185d..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.js" +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @param {number[]} nums - * @return {boolean} - */ -var isStraight = function (nums) { - let zeroCnt = 0; - nums.sort((a, b) => a - b); - for (let i = 0; i < nums.length - 1; i++) { - if (nums[i] === 0) zeroCnt++; - else { - if (nums[i] === nums[i + 1]) return false; - else if (nums[i] === nums[i + 1] - 1) { - continue; - } else if (nums[i] >= nums[i + 1] - zeroCnt - 1) { - zeroCnt--; - } else { - return false; - } - } - if (zeroCnt < 0) return false; - } - return true; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.py" deleted file mode 100644 index e0291573..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23061. \346\211\221\345\205\213\347\211\214\344\270\255\347\232\204\351\241\272\345\255\220/Solution.py" +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def isStraight(self, nums: List[int]) -> bool: - t = [False for _ in range(14)] - max_val, min_val = 0, 14 - for num in nums: - if num == 0: - continue - if t[num]: - return False - t[num] = True - max_val = max(max_val, num) - min_val = min(min_val, num) - return max_val - min_val <= 4 - diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 87dfa53d..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @param {number} n - * @param {number} m - * @return {number} - */ -var lastRemaining = function (n, m) { - // 约瑟夫环 - let res = 0; - for (let i = 1; i <= n; i++) { - res = (res + m) % i; - } - return res; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 56ead9a8..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def lastRemaining(self, n: int, m: int) -> int: - f = 0 - for i in range(2, n + 1): - f = (f + m) % i - return f diff --git "a/leetcode/lcof/\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/Solution.cpp" "b/leetcode/lcof/\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/Solution.cpp" deleted file mode 100644 index 40d90645..00000000 --- "a/leetcode/lcof/\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/Solution.cpp" +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - if (prices.size() < 2) { - return 0; - } - - int curMin = prices[0]; - int maxDiff = prices[1] - prices[0]; - - for (int i = 2; i < prices.size(); i++) { - if (curMin > prices[i-1]) { - curMin = prices[i-1]; - } - - int diff = prices[i] - curMin; - if (maxDiff < diff) { - maxDiff = diff; - } - } - - return maxDiff > 0 ? maxDiff : 0; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 924c98e3..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @param {number[]} prices - * @return {number} - */ -var maxProfit = function (prices) { - let a = 0; - let b = Infinity; - for (let p of prices) { - a = Math.max(a, p - b); - b = Math.min(b, p); - } - return a; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 98667c75..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def maxProfit(self, prices: List[int]) -> int: - if len(prices) == 0: - return 0 - mi = prices[0] - res = 0 - for val in prices[1:]: - res = max(res, val - mi) - mi = min(mi, val) - return res \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" deleted file mode 100644 index 9f820175..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" +++ /dev/null @@ -1,9 +0,0 @@ -class Solution -{ -public: - int sumNums(int n) - { - n && (n += sumNums(n - 1)); - return n; - } -}; \ No newline at end of file diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" deleted file mode 100644 index d3d371ff..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.js" +++ /dev/null @@ -1,7 +0,0 @@ -/** - * @param {number} n - * @return {number} - */ -var sumNums = function (n) { - return (n ** 2 + n) >> 1; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.py" deleted file mode 100644 index d4962b0c..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.py" +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def sumNums(self, n: int) -> int: - return n and (n + self.sumNums(n - 1)) \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.go" "b/leetcode/lcof/\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/Solution.go" deleted file mode 100644 index bc792522..00000000 --- "a/leetcode/lcof/\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/Solution.go" +++ /dev/null @@ -1,6 +0,0 @@ -func add(a int, b int) int { - if b == 0 { - return a - } - return add(a ^ b, (a & b) << 1) -} \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 48d2ce89..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @param {number} a - * @param {number} b - * @return {number} - */ -var add = function (a, b) { - if (b == 0) return a; - return add(a ^ b, (a & b) << 1); -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index d9faac52..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def add(self, a: int, b: int) -> int: - a, b = a & 0xffffffff, b & 0xffffffff - s = carry = 0 - while b: - s = a ^ b - carry = ((a & b) << 1) & 0xffffffff - a, b = s, carry - return a if a < 0x80000000 else ~(a ^ 0xffffffff) \ No newline at end of file diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index c95adef6..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @param {number[]} a - * @return {number[]} - */ -var constructArr = function (a) { - const n = a.length; - let output = new Array(n); - for (let i = 0, left = 1; i < n; ++i) { - output[i] = left; - left *= a[i]; - } - for (let i = n - 1, right = 1; i >= 0; --i) { - output[i] *= right; - right *= a[i]; - } - return output; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 2d5252e9..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def constructArr(self, a: List[int]) -> List[int]: - n = len(a) - output = [1 for _ in a] - left = right = 1 - for i in range(n): - output[i] = left - left *= a[i] - for i in range(n - 1, -1, -1): - output[i] *= right - right *= a[i] - return output diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" deleted file mode 100644 index f6b2f8ac..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.js" +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @param {string} str - * @return {number} - */ -var strToInt = function (str) { - let res = ""; - let l = 1; - for (let i = 0; i < str.length; i++) { - if (l && str[i] === " ") continue; - if (l && (str[i] === "+" || str[i] === "-")) { - l = 0; - res += str[i]; - continue; - } - if (str[i].match(/[0-9]/)) { - l = 0; - res += str[i]; - } else break; - } - res = isNaN(+res) ? 0 : +res; - if (res > 2147483647) return 2147483647; - if (res < -2147483648) return -2147483648; - return res; -}; diff --git "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.py" "b/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.py" deleted file mode 100644 index 350669ae..00000000 --- "a/leetcode/lcof/\351\235\242\350\257\225\351\242\23067. \346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260/Solution.py" +++ /dev/null @@ -1,28 +0,0 @@ -class Solution: - def strToInt(self, str: str) -> int: - if not str: - return 0 - n = len(str) - if n == 0: - return 0 - i = 0 - while str[i] == ' ': - i += 1 - # 仅包含空格 - if i == n: - return 0 - sign = -1 if str[i] == '-' else 1 - if str[i] in ['-', '+']: - i += 1 - res, flag = 0, (2 ** 31 - 1) // 10 - while i < n: - # 非数字,跳出循环 - if not str[i].isdigit(): - break - c = int(str[i]) - # 溢出判断 - if res > flag or (res == flag and c > 7): - return 2 ** 31 - 1 if sign > 0 else -2 ** 31 - res = res * 10 + c - i += 1 - return sign * res diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 860f057f..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {TreeNode} p - * @param {TreeNode} q - * @return {TreeNode} - */ -var lowestCommonAncestor = function (root, p, q) { - // 递归 - if (!root) return null; - if (root.val < p.val && root.val < q.val) { - return lowestCommonAncestor(root.right, p, q); - } else if (root.val > p.val && root.val > q.val) { - return lowestCommonAncestor(root.left, p, q); - } - return root; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index 6b546b63..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,19 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - - -class Solution: - def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: - if p == q: - return p - while root: - if root.val < p.val and root.val < q.val: - root = root.right - elif root.val > p.val and root.val > q.val: - root = root.left - else: - return root diff --git "a/leetcode/lcof/\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/Solution.js" "b/leetcode/lcof/\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/Solution.js" deleted file mode 100644 index 9eb1249f..00000000 --- "a/leetcode/lcof/\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/Solution.js" +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {TreeNode} p - * @param {TreeNode} q - * @return {TreeNode} - */ -var lowestCommonAncestor = function (root, p, q) { - if (!root || root == p || root == q) return root; - const left = lowestCommonAncestor(root.left, p, q); - const right = lowestCommonAncestor(root.right, p, q); - if (!left) return right; - if (!right) return left; - return root; -}; diff --git "a/leetcode/lcof/\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/Solution.py" "b/leetcode/lcof/\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/Solution.py" deleted file mode 100644 index c24ccfbe..00000000 --- "a/leetcode/lcof/\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/Solution.py" +++ /dev/null @@ -1,18 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode: - if root is None or root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - if left is None: - return right - if right is None: - return left - return root diff --git a/leetcode/solution/0000-0099/0001.Two Sum/README_EN.md b/leetcode/solution/0000-0099/0001.Two Sum/README_EN.md deleted file mode 100644 index b22bf0e9..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [1. Two Sum](https://leetcode.com/problems/two-sum) - -[中文文档](/solution/0000-0099/0001.Two%20Sum/README.md) - -## Description - -

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

- -

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

- -

Example:

- -
-
-Given nums = [2, 7, 11, 15], target = 9,
-
-
-
-Because nums[0] + nums[1] = 2 + 7 = 9,
-
-return [0, 1].
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def twoSum(self, nums: List[int], target: int) -> List[int]: - helper = {} - for i, v in enumerate(nums): - num = target - v - if num in helper: - return [helper[num], i] - helper[v] = i -``` - -### **Java** - -```java -class Solution { - public int[] twoSum(int[] nums, int target) { - Map map = new HashMap<>(); - for (int i = 0, n = nums.length; i < n; ++i) { - int num = target - nums[i]; - if (map.containsKey(num)) { - return new int[]{map.get(num), i}; - } - map.put(nums[i], i); - } - return null; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.cpp b/leetcode/solution/0000-0099/0001.Two Sum/Solution.cpp deleted file mode 100644 index 27cc0a7d..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) - { - vector res ; - unordered_map hash ; - - for (int i = 0; i < nums.size(); ++i) - { - int aim = target - nums[i] ; - int local = hash[aim] ; - if (local != NULL) - { - res.push_back(local-1) ; - res.push_back(i) ; - return res ; - } - else - hash[nums[i]] = i+1 ; - } - - return res ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.cs b/leetcode/solution/0000-0099/0001.Two Sum/Solution.cs deleted file mode 100644 index 4d4e111b..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int[] TwoSum(int[] nums, int target) { - var dict = new Dictionary(); - for (var i = 0; i < nums.Length; ++i) - { - int index; - if (dict.TryGetValue(target - nums[i], out index)) - { - return new [] { index, i}; - } - if (!dict.ContainsKey(nums[i])) - { - dict.Add(nums[i], i); - } - } - return null; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.go b/leetcode/solution/0000-0099/0001.Two Sum/Solution.go deleted file mode 100644 index caed58a4..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.go +++ /dev/null @@ -1,12 +0,0 @@ -func twoSum(nums []int, target int) []int { - var numsMap map[int]int - numsMap = make(map[int]int) - for i := 0; i < len(nums); i++ { - if _, ok := numsMap[target-nums[i]]; ok { - - return []int{numsMap[target-nums[i]], i} - } - numsMap[nums[i]] = i - } - return nil -} diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.js b/leetcode/solution/0000-0099/0001.Two Sum/Solution.js deleted file mode 100644 index 65dce780..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Author: limbowandering - */ - -const twoSum = function (nums, target) { - const map = {}; - for (let i = 0; i < nums.length; i++) { - if (map[nums[i]] !== undefined) { - return [map[nums[i]], i]; - } else { - map[target - nums[i]] = i; - } - } -}; - -/** - * Author: Mcnwork2018 - */ - -var twoSum = function (nums, target) { - let len = nums.length; - let n = {}; - for (let i = 0; i < len; i++) { - if (n[target - nums[i]] !== undefined) { - return [n[target - nums[i]], i]; - } - n[nums[i]] = i; - } -}; - -/** - * Author: rookie - */ - -var twoSum = function (nums, target) { - const map = new Map(); - for (let i = 0; i < nums.length; i++) { - if (map.has(target - nums[i])) { - return [map.get(target - nums[i]), i]; - } - map.set(nums[i], i); - } -}; diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.py b/leetcode/solution/0000-0099/0001.Two Sum/Solution.py deleted file mode 100644 index d0842466..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def twoSum(self, nums: List[int], target: int) -> List[int]: - helper = {} - for i, v in enumerate(nums): - num = target - v - if num in helper: - return [helper[num], i] - helper[v] = i diff --git a/leetcode/solution/0000-0099/0001.Two Sum/Solution.rb b/leetcode/solution/0000-0099/0001.Two Sum/Solution.rb deleted file mode 100644 index 26235fca..00000000 --- a/leetcode/solution/0000-0099/0001.Two Sum/Solution.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @param {Integer[]} nums -# @param {Integer} target -# @return {Integer[]} -def two_sum(nums, target) - nums.each_with_index do |x, idx| - if nums.include? target - x - return [idx, nums.index(target - x)] if nums.index(target - x) != idx - end - next - end -end diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/README_EN.md b/leetcode/solution/0000-0099/0002.Add Two Numbers/README_EN.md deleted file mode 100644 index d7f832a7..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/README_EN.md +++ /dev/null @@ -1,120 +0,0 @@ -# [2. Add Two Numbers](https://leetcode.com/problems/add-two-numbers) - -[中文文档](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md) - -## Description - -

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

- -

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

- -

Example:

- -
-
-Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
-
-Output: 7 -> 0 -> 8
-
-Explanation: 342 + 465 = 807.
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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: ListNode, l2: ListNode) -> ListNode: - carry = 0 - dummy = ListNode(-1) - cur = dummy - while l1 or l2 or carry: - t = (0 if not l1 else l1.val) + (0 if not l2 else l2.val) + carry - carry = t // 10 - cur.next = ListNode(t % 10) - cur = cur.next - l1 = None if not l1 else l1.next - l2 = None if not l2 else l2.next - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode addTwoNumbers(ListNode l1, ListNode l2) { - int carry = 0; - ListNode dummy = new ListNode(-1); - ListNode cur = dummy; - while (l1 != null || l2 != null || carry != 0) { - int t = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry; - carry = t / 10; - cur.next = new ListNode(t % 10); - cur = cur.next; - l1 = l1 == null ? null : l1.next; - l2 = l2 == null ? null : l2.next; - } - return dummy.next; - } -} -``` - -### **C#** - -```cs -/** - * Definition for singly-linked list. - * public class ListNode { - * public int val; - * public ListNode next; - * public ListNode(int val=0, ListNode next=null) { - * this.val = val; - * this.next = next; - * } - * } - */ -public class Solution { - public ListNode AddTwoNumbers(ListNode l1, ListNode l2) { - ListNode dummy = new ListNode(-1); - ListNode cur = dummy; - var carry = 0; - while (l1 != null || l2 != null || carry != 0) - { - int t = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry; - carry = t / 10; - cur.next = new ListNode(t % 10); - cur = cur.next; - l1 = l1 == null ? null : l1.next; - l2 = l2 == null ? null : l2.next; - } - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cpp b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cpp deleted file mode 100644 index fc01eaeb..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -class Solution { -public: - ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { - - ListNode *ans_l = new ListNode(0); - ListNode *head = ans_l; - int tmp = 0; - while(l1 != NULL && l2 != NULL){ - tmp += l1->val + l2->val; - ans_l->next = new ListNode(tmp % 10); - tmp = tmp / 10; - ans_l = ans_l->next; - l1 = l1->next; - l2 = l2->next; - } - - while(l1 != NULL){ - tmp += l1->val; - ans_l->next = new ListNode(tmp % 10); - tmp = tmp / 10; - ans_l = ans_l->next; - l1 = l1->next; - } - - while(l2 != NULL){ - tmp += l2->val; - ans_l->next = new ListNode(tmp % 10); - tmp = tmp / 10; - ans_l = ans_l->next; - l2 = l2->next; - } - - if(tmp)ans_l->next = new ListNode(tmp); - - return head->next; - } -}; diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cs b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cs deleted file mode 100644 index c80a5985..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.cs +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Definition for singly-linked list. - * public class ListNode { - * public int val; - * public ListNode next; - * public ListNode(int val=0, ListNode next=null) { - * this.val = val; - * this.next = next; - * } - * } - */ -public class Solution { - public ListNode AddTwoNumbers(ListNode l1, ListNode l2) { - ListNode dummy = new ListNode(-1); - ListNode cur = dummy; - var carry = 0; - while (l1 != null || l2 != null || carry != 0) - { - int t = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry; - carry = t / 10; - cur.next = new ListNode(t % 10); - cur = cur.next; - l1 = l1 == null ? null : l1.next; - l2 = l2 == null ? null : l2.next; - } - return dummy.next; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.go b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.go deleted file mode 100644 index b1277fa6..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.go +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - * - * Report by leetcode.com - * Runtime: 12 ms, Memory Usage: 5 MB - */ -func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { - head := &ListNode{} - currentNode1 := l1 - currentNode2 := l2 - currentHead := head - sum := 0 - nextSum := 0 - - for true { - if currentNode1 != nil || currentNode2 != nil { - if currentNode1 == nil { - sum = nextSum + currentNode2.Val - nextSum = sum / 10 - currentNode2 = currentNode2.Next - } else if currentNode2 == nil { - sum = nextSum + currentNode1.Val - nextSum = sum / 10 - currentNode1 = currentNode1.Next - } else { - sum = nextSum + currentNode1.Val + currentNode2.Val - nextSum = sum / 10 - currentNode1 = currentNode1.Next - currentNode2 = currentNode2.Next - } - currentHead.Val = sum % 10 - // If there are elements present in the nodes then - // make a new node for future addition otherwise we - // will get unnecessary (0 --> ) node in the end. - if currentNode1 != nil || currentNode2 != nil { - currentHead.Next = &ListNode{} - currentHead = currentHead.Next - } else if nextSum != 0 { - // If nextSum is not 0 this means that there was some carry value - // left in it which should be further. - currentHead.Next = &ListNode{nextSum, nil} - } - } else { - break - } - } - - return head -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.js b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.js deleted file mode 100644 index e2122af2..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} l1 - * @param {ListNode} l2 - * @return {ListNode} - */ - -/** - * Author: Mcnwork2018 - */ -var addTwoNumbers = function (l1, l2) { - let c1 = l1, - c2 = l2, - c3 = 0, - l3 = 0, - carry = 0; - while (c1 || c2 || carry) { - var v1 = 0, - v2 = 0; - if (c1) { - v1 = c1.val; - c1 = c1.next; - } - if (c2) { - v2 = c2.val; - c2 = c2.next; - } - var sum = v1 + v2 + carry; - carry = (sum - (sum % 10)) / 10; - if (!c3) { - l3 = new ListNode(sum % 10); - c3 = l3; - } else { - c3.next = new ListNode(sum % 10); - c3 = c3.next; - } - } - return l3; -}; diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.py b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.py deleted file mode 100644 index 1273058e..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -# 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: ListNode, l2: ListNode) -> ListNode: - carry = 0 - dummy = ListNode(-1) - cur = dummy - while l1 or l2 or carry: - t = (0 if not l1 else l1.val) + (0 if not l2 else l2.val) + carry - carry = t // 10 - cur.next = ListNode(t % 10) - cur = cur.next - l1 = None if not l1 else l1.next - l2 = None if not l2 else l2.next - return dummy.next diff --git a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.rb b/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.rb deleted file mode 100644 index e399fe92..00000000 --- a/leetcode/solution/0000-0099/0002.Add Two Numbers/Solution.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Definition for singly-linked list. -# class ListNode -# attr_accessor :val, :next -# def initialize(val) -# @val = val -# @next = nil -# end -# end - -# @param {ListNode} l1 -# @param {ListNode} l2 -# @return {ListNode} - -def add_two_numbers(l1, l2) - return l2 if l1 == nil - return l1 if l2 == nil - cur_val = l1.val + l2.val - l3 = ListNode.new(cur_val % 10) - add = cur_val >= 10 ? 1 : 0 - tmp = l3 - - l1 = l1.next - l2 = l2.next - while !l1.nil? || !l2.nil? || add > 0 - cur_val = add - cur_val += l1.nil? ? 0 : l1.val - cur_val += l2.nil? ? 0 : l2.val - tmp.next = ListNode.new(cur_val % 10) - tmp = tmp.next - add = cur_val >= 10 ? 1 : 0 - - l1 = l1.nil? ? l1 : l1.next - l2 = l2.nil? ? l2 : l2.next - end - - l3 -end diff --git a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md b/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md deleted file mode 100644 index 6ef858c2..00000000 --- a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters) - -[中文文档](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md) - -## Description - -

Given a string, find the length of the longest substring without repeating characters.

- -
- -

Example 1:

- -
-
-Input: "abcabcbb"
-
-Output: 3 
-
-Explanation: The answer is "abc", with the length of 3. 
-
-
- -
- -

Example 2:

- -
-
-Input: "bbbbb"
-
-Output: 1
-
-Explanation: The answer is "b", with the length of 1.
-
-
- -
- -

Example 3:

- -
-
-Input: "pwwkew"
-
-Output: 3
-
-Explanation: The answer is "wke", with the length of 3. 
-
-             Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
-
-
- -
- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.cs b/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.cs deleted file mode 100644 index 3f00d915..00000000 --- a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int LengthOfLongestSubstring(string s) { - var hashSet = new HashSet(); - var maxLength = 0; - int i = 0, j = 0; - while (i < s.Length) - { - while (hashSet.Contains(s[i])) - { - hashSet.Remove(s[j++]); - } - hashSet.Add(s[i++]); - if (i - j > maxLength) - { - maxLength = i - j; - } - } - return maxLength; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.go b/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.go deleted file mode 100644 index fc2a3bd1..00000000 --- a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.go +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Report by leetcode.com - * Runtime: 8 ms, Memory Usage: 3.2 MB - */ -func lengthOfLongestSubstring(s string) int { - mathMax := func(a, b int) int { - if a > b { - return a - } - return b - } - cache := map[rune]int{} - var max, position int - for i, r := range s { - if num, ok := cache[r]; ok { - position = mathMax(position, num+1) - } - cache[r] = i - max = mathMax(max, i-position+1) - } - return max -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js b/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js deleted file mode 100644 index 7e9cd0a4..00000000 --- a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @param {string} s - * @return {number} - */ -var lengthOfLongestSubstring = function (s) { - var start = 0; // 非重复字符串开始索引 - var max = 0; // 最长字符串长度 - var visitedCharByPosition = {}; - for (var position = 0; position < s.length; position++) { - var nextChar = s[position]; - if ( - nextChar in visitedCharByPosition && - visitedCharByPosition[nextChar] >= start - ) { - // 有重复,非重复字符串索引从下一个 index 开始 - start = visitedCharByPosition[nextChar] + 1; - visitedCharByPosition[nextChar] = position; - } else { - visitedCharByPosition[nextChar] = position; - // 非重复,求非重复值 - max = Math.max(max, position + 1 - start); - } - } - return max; -}; diff --git a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.py b/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.py deleted file mode 100644 index fc699d1e..00000000 --- a/leetcode/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def lengthOfLongestSubstring(self, s: str): - max = 0 - length = len(s) - substr = "" - for i in range(0, length): - index = substr.find(s[i]) - if index > -1: - substr = substr[index + 1:] - substr += s[i] - max = (max if (max > len(substr)) else len(substr)) - return max \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md deleted file mode 100644 index 33c3adba..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [4. Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays) - -[中文文档](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md) - -## Description - -

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

- -

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

- -

You may assume nums1 and nums2 cannot be both empty.

- -

Example 1:

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

Example 2:

- -
-
-nums1 = [1, 2]
-
-nums2 = [3, 4]
-
-
-
-The median is (2 + 3)/2 = 2.5
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cpp b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cpp deleted file mode 100644 index 2496313f..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cpp +++ /dev/null @@ -1,36 +0,0 @@ -class Solution { -public: - double findMedianSortedArrays(vector& nums1, vector& nums2) { - int nums[10000] = { 0 }; - int index = 0; - vector::iterator it1 = nums1.begin(); - vector::iterator it2 = nums2.begin(); - for (; it1 != nums1.end() && it2 != nums2.end();) { - if (*it1 >= *it2) { - nums[index++] = *it2; - it2++; - } - else { - nums[index++] = *it1; - it1++; - } - } - - while (it1 != nums1.end()) { - nums[index++] = *it1; - it1++; - } - while (it2 != nums2.end()) { - nums[index++] = *it2; - it2++; - } - - if (index % 2 == 0) { - return (double)((nums[index/2] + nums[index/2 - 1])/2.0); - } - else { - return (double)(nums[index/2]); - } - - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cs b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cs deleted file mode 100644 index 494e0c85..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Linq; - -class Range -{ - public static Range Empty = new Range(new int[0], 0, -1); - - public readonly int[] Numbers; - public readonly int LeftIndex; - public readonly int RightIndex; - - public int Count { get { return RightIndex - LeftIndex + 1; } } - - public int this[int index] - { - get - { - if (index >= Count) - { - throw new IndexOutOfRangeException(); - } - return Numbers[LeftIndex + index]; - } - } - - public Range(int[] numbers) : this(numbers, 0, numbers.Length - 1) - { - } - - public Range(int[] numbers, int leftIndex, int rightIndex) - { - Numbers = numbers; - LeftIndex = leftIndex; - RightIndex = rightIndex; - if (RightIndex < LeftIndex) RightIndex = LeftIndex - 1; - } - - public Range GetSubRange(int lowerBound, int upperBound) - { - if (lowerBound > upperBound) return Empty; - var leftIndex = lowerBound == int.MinValue ? LeftIndex : Search(lowerBound); - var rightIndex = upperBound == int.MaxValue ? RightIndex : Search(upperBound + 1) - 1; - return new Range(Numbers, leftIndex, rightIndex); - } - - private int Search(int target) - { - var l = 0; - var r = Numbers.Length - 1; - while (l < r) - { - var mid = (l + r) / 2; - if (Numbers[mid] < target) - { - l = mid + 1; - } - else - { - r = mid; - } - } - return Numbers[l] >= target ? l : l + 1; - } -} - -public class Solution { - public double FindMedianSortedArrays(int[] nums1, int[] nums2) - { - var totalNumbers = nums1.Length + nums2.Length; - var targetOrder1 = (totalNumbers + 1)/2; - var targetOrder2 = (totalNumbers + 2)/2; - var range1 = new Range(nums1); - var range2 = new Range(nums2); - var number1 = FindMedianSortedArrays(range1, range2, targetOrder1); - var number2 = targetOrder1 == targetOrder2 ? number1 : FindMedianSortedArrays(range1, range2, targetOrder2); - return ((double) number1 + number2)/2; - } - - private int FindMedianSortedArrays(Range range1, Range range2, int targetOrder) - { - if (range1.Count == 0) - { - return range2[targetOrder - 1]; - } - if (range2.Count == 0) - { - return range1[targetOrder - 1]; - } - - var midNumber = range1[(range1.Count - 1)/2]; - var midRanges = new[] { range1.GetSubRange(midNumber, midNumber), range2.GetSubRange(midNumber, midNumber) }; - var leftRanges = new[] - { - new Range(range1.Numbers, range1.LeftIndex, midRanges[0].LeftIndex - 1), - new Range(range2.Numbers, range2.LeftIndex, midRanges[1].LeftIndex - 1) - }; - var rightRanges = new[] - { - new Range(range1.Numbers, midRanges[0].RightIndex + 1, range1.RightIndex), - new Range(range2.Numbers, midRanges[1].RightIndex + 1, range2.RightIndex) - }; - - var leftCount = leftRanges.Sum(r => r.Count); - var midCount = midRanges.Sum(r => r.Count); - var rightCount = rightRanges.Sum(r => r.Count); - - if (leftCount == 0 && rightCount == 0) - { - return midNumber; - } - if (leftCount >= targetOrder) - { - return FindMedianSortedArrays(leftRanges[0], leftRanges[1], targetOrder); - } - if (leftCount + midCount >= targetOrder) - { - return FindMedianSortedArrays(midRanges[0], midRanges[1], targetOrder - leftCount); - } - return FindMedianSortedArrays(rightRanges[0], rightRanges[1], targetOrder - leftCount - midCount); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.go b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.go deleted file mode 100644 index f0e8c449..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.go +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Report by leetcode.com - * Runtime: 16 ms, Memory Usage: 5.4 MB - */ -func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { - mathMax := func(a, b int) int { - if a > b { - return a - } - return b - } - mathMin := func(a, b int) int { - if a < b { - return a - } - return b - } - - var len1, len2 int - len1 = len(nums1) - len2 = len(nums2) - if len1 > len2 { - var tmp []int = nums1 - nums1 = nums2 - nums2 = tmp - var t int = len1 - len1 = len2 - len2 = t - } - - var min, max int = 0, 0 - max = len1 - - halfLen := (len1 + len2 + 1) / 2 - - for min <= max { - i := (min + max) / 2 - j := halfLen - i - - if i < max && nums2[j-1] > nums1[i] { - min++ - } else if i > min && nums1[i-1] > nums2[j] { - max-- - } else { - var maxLeft int - if i == 0 { - maxLeft = nums2[j-1] - } else if j == 0 { - maxLeft = nums1[i-1] - } else { - maxLeft = mathMax(nums1[i-1], nums2[j-1]) - } - if ((len1 + len2) & 1) == 1 { - return float64(maxLeft) - } - var minRight int - if i == len1 { - minRight = nums2[j] - } else if j == len2 { - minRight = nums1[i] - } else { - minRight = mathMin(nums2[j], nums1[i]) - } - return float64(maxLeft+minRight) / 2 - } - } - return 0 -} diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js deleted file mode 100644 index 929b6e5d..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @param {number[]} nums1 - * @param {number[]} nums2 - * @return {number} 012345 - */ -var findMedianSortedArrays = function (nums1, nums2) { - if (nums1.length == 0 || nums2.length == 0) { - if ((nums1.length + nums2.length) % 2 == 1) { - const index = parseInt((nums1.length + nums2.length) / 2); - return nums2.length == 0 ? nums1[index] : nums2[index]; - } else { - let nums = nums2.length == 0 ? nums1 : nums2; - const index = nums.length / 2; - return (nums[index - 1] + nums[index]) / 2; - } - } - - if (nums1.length > nums2.length) { - swap(nums1, nums2); - } - const M = nums1.length, - N = nums2.length; - let min = 0, - max = M, - half = parseInt((M + N + 1) / 2); // 连个数组合并的中间值 - while (min <= max) { - let i = parseInt((min + max) / 2); // nums1 的索引值 - let j = half - i; // num2 的索引值 - if (i < max && nums2[j - 1] > nums1[i]) { - min++; - } else if (i > min && nums1[i - 1] > nums2[j]) { - max--; - } else { - let maxLeft = 0; - if (i == 0) { - maxLeft = nums2[j - 1]; - } else if (j == 0) { - maxLeft = nums1[i - 1]; - } else { - maxLeft = Math.max(nums1[i - 1], nums2[j - 1]); - } - if ((M + N) % 2 == 1) { - return maxLeft; - } - let minRight = 0; - if (i == M) { - minRight = nums2[j]; - } else if (j == N) { - minRight = nums1[i]; - } else { - minRight = Math.min(nums1[i], nums2[j]); - } - return (maxLeft + minRight) / 2; - } - } - return 0; -}; - -function swap(a, b) { - let tmp = a; - a = b; - b = tmp; -} - -const nums1 = [4, 5]; -const nums2 = [1, 2, 3]; -findMedianSortedArrays(nums1, nums2); - -/** - * 实现思路 - * 先排除空数组的情况 - * 数组从小到大排序 - * 取小数组的中间值 - * 取大数组的索引 = 总中间值-小数组中间值 - * 循环直到符合条件 - * 如果都不符合条件,那么说明中间值在两个数组的左边或者右边 - */ diff --git a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.py b/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.py deleted file mode 100644 index e45030c7..00000000 --- a/leetcode/solution/0000-0099/0004.Median of Two Sorted Arrays/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: - # concatenate the 2 lists and sort them - nums1 += nums2 - nums1.sort() - length = len(nums1) - value = length/2 - if length % 2 == 0: - value = int(value) - return (nums1[value-1] + nums1[value])/2 - else: - return nums1[int(value)] diff --git a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md b/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md deleted file mode 100644 index b2783c48..00000000 --- a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) - -[中文文档](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md) - -## Description - -

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

- -

Example 1:

- -
-
-Input: "babad"
-
-Output: "bab"
-
-Note: "aba" is also a valid answer.
-
-
- -

Example 2:

- -
-
-Input: "cbbd"
-
-Output: "bb"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.cs b/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.cs deleted file mode 100644 index 984dda03..00000000 --- a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.cs +++ /dev/null @@ -1,31 +0,0 @@ -public class Solution { - public string LongestPalindrome(string s) { - var f = new bool[s.Length]; - var maxLen = 0; - var index = 0; - for (var p = 0; p <= 1; ++p) - { - for (var l = 1 + p; l <= s.Length; l += 2) - { - for (var i = 0; i <= s.Length - l; ++i) - { - if (l <= 2) - { - f[i] = s[i] == s[i + l - 1]; - } - else - { - f[i] = f[i + 1] && s[i] == s[i + l - 1]; - } - if (f[i] && l > maxLen) - { - maxLen = l; - index = i; - } - } - } - } - - return s.Substring(index, maxLen); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.go b/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.go deleted file mode 100644 index dd27eaa3..00000000 --- a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.go +++ /dev/null @@ -1,28 +0,0 @@ -func longestPalindrome(s string) string { - length := len(s) - if length == 0 { - return "" - } - res := make([][]bool, length) - for i := 0; i < length; i++ { - res[i] = make([]bool, length) - } - max := 1 - start := 0 - for i := 0; i < length; i++ { - for j := 0; j <= i; j++ { - if i - j < 2 { - res[j][i] = s[j] == s[i] - } else { - res[j][i] = s[j] == s[i] && res[j+1][i-1] - } - - if res[j][i] && max < i - j + 1 { - max = i - j + 1 - start = j - } - } - } - - return s[start:start + max] -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js b/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js deleted file mode 100644 index 9a77a283..00000000 --- a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @param {string} s - * @return {string} - */ -var longestPalindrome = function (s) { - let maxLength = 0, - left = 0, - right = 0; - for (let i = 0; i < s.length; i++) { - let singleCharLength = getPalLenByCenterChar(s, i, i); - let doubleCharLength = getPalLenByCenterChar(s, i, i + 1); - let max = Math.max(singleCharLength, doubleCharLength); - if (max > maxLength) { - maxLength = max; - left = i - parseInt((max - 1) / 2); - right = i + parseInt(max / 2); - } - } - return s.slice(left, right + 1); -}; - -function getPalLenByCenterChar(s, left, right) { - // 中间值为两个字符,确保两个字符相等 - if (s[left] != s[right]) { - return right - left; // 不相等返回为1个字符串 - } - while (left > 0 && right < s.length - 1) { - // 先加减再判断 - left--; - right++; - if (s[left] != s[right]) { - return right - left - 1; - } - } - return right - left + 1; -} - -console.log(longestPalindrome("cbbd")); diff --git a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.py b/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.py deleted file mode 100644 index feee8060..00000000 --- a/leetcode/solution/0000-0099/0005.Longest Palindromic Substring/Solution.py +++ /dev/null @@ -1,24 +0,0 @@ -class Solution: - def longestPalindrome(self, s: str) -> str: - dp = [[0 for _ in range(len(s) + 1)] for _ in range(len(s) + 1)] - - for i in range(len(s)): - dp[i][i] = 1 - - for i in range(len(s) - 1, -1, -1): - for j in range(i + 1, len(s)): - if s[i] == s[j]: - if i + 1 == j: - dp[i][j] = 2 - elif i + 2 == j: - dp[i][j] = 3 - else: - if dp[i + 1][j - 1] != 0: - dp[i][j] = 2 + dp[i + 1][j - 1] - maximum = max(map(max, dp)) - if maximum == 0: - return "" - for i in range(len(s)): - for j in range(len(s)): - if dp[i][j] == maximum: - return s[i: j + 1] diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/README_EN.md b/leetcode/solution/0000-0099/0006.ZigZag Conversion/README_EN.md deleted file mode 100644 index 3a10fcad..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [6. ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion) - -[中文文档](/solution/0000-0099/0006.ZigZag%20Conversion/README.md) - -## Description - -

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

- -
-
-P   A   H   N
-
-A P L S I I G
-
-Y   I   R
-
-
- -

And then read line by line: "PAHNAPLSIIGYIR"

- -

Write the code that will take a string and make this conversion given a number of rows:

- -
-
-string convert(string s, int numRows);
- -

Example 1:

- -
-
-Input: s = "PAYPALISHIRING", numRows = 3
-
-Output: "PAHNAPLSIIGYIR"
-
-
- -

Example 2:

- -
-
-Input: s = "PAYPALISHIRING", numRows = 4
-
-Output: "PINALSIGYAHRPI"
-
-Explanation:
-
-
-
-P     I    N
-
-A   L S  I G
-
-Y A   H R
-
-P     I
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cpp b/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cpp deleted file mode 100644 index 44d9edaa..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// @ID:6. ZigZag Conversion -// @author:jxdeng3989 - -class Solution { -public: - string convert(string s, int numRows) { - string retstr; - if(1==numRows) - return s; - for(int i=0; i=s.size()) - break; - cntpos += span1; - retstr.push_back(s[cntpos]); - - if(cntpos+span2>=s.size()) - break; - cntpos += span2; - retstr.push_back(s[cntpos]); - } - } - return retstr; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cs b/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cs deleted file mode 100644 index 43e3ea8e..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public string Convert(string s, int numRows) { - if (numRows == 1) return s; - if (numRows > s.Length) numRows = s.Length; - var rows = new List[numRows]; - var i = 0; - var j = 0; - var down = true; - while (i < s.Length) - { - if (rows[j] == null) - { - rows[j] = new List(); - } - rows[j].Add(s[i]); - j = j + (down ? 1 : -1); - if (j == numRows || j < 0) - { - down = !down; - j = j + (down ? 2 : -2); - } - ++i; - } - return new string(rows.SelectMany(row => row).ToArray()); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.go b/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.go deleted file mode 100644 index 929878fa..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.go +++ /dev/null @@ -1,20 +0,0 @@ -func convert(s string, numRows int) string { - if numRows == 1 { - return s - } - length := len(s) - result := make([]byte, length) - step := 2 * numRows - 2 - count := 0 - for i := 0; i < numRows; i++ { - for j := 0; j + i < length; j += step { - result[count] = s[i+j] - count++ - if i != 0 && i != numRows - 1 && j + step - i < length { - result[count] = s[j+step-i] - count++ - } - } - } - return string(result) -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.js b/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.js deleted file mode 100644 index 62f9913c..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @param {string} s - * @param {number} numRows - * @return {string} - */ -var convert = function (s, numRows) { - if (numRows == 1) return s; - let arr = new Array(numRows); - for (let i = 0; i < numRows; i++) arr[i] = []; - let index = 0, - len = s.length, - mi = 0, - isDown = true; - while (index < len) { - arr[mi].push(s[index]); - index++; - - if (mi >= numRows - 1) isDown = false; - else if (mi <= 0) isDown = true; - - if (isDown) mi++; - else mi--; - } - let ans = []; - for (let item of arr) { - ans = ans.concat(item); - } - return ans.join(""); -}; - -const s = "AB", - numRows = 1; - -console.log(convert(s, numRows)); diff --git a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.py b/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.py deleted file mode 100644 index f29dad49..00000000 --- a/leetcode/solution/0000-0099/0006.ZigZag Conversion/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -class Solution: - def convert(self, s, numRows): - """ - :type s: str - :type numRows: int - :rtype: str - """ - - if numRows == 0: - return "" - elif numRows == 1: - return s - - Ret = [[] for i in range(numRows)] - i = 0 - while i < len(s): - j = 0 - while i0: # Diagonal lines - Ret[j].append(s[i]) - j-=1 - i+=1 - - return "".join(["".join(row) for row in Ret]) - diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/README_EN.md b/leetcode/solution/0000-0099/0007.Reverse Integer/README_EN.md deleted file mode 100644 index 77cefc2b..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [7. Reverse Integer](https://leetcode.com/problems/reverse-integer) - -[中文文档](/solution/0000-0099/0007.Reverse%20Integer/README.md) - -## Description - -

Given a 32-bit signed integer, reverse digits of an integer.

- -

Example 1:

- -
-
-Input: 123
-
-Output: 321
-
-
- -

Example 2:

- -
-
-Input: -123
-
-Output: -321
-
-
- -

Example 3:

- -
-
-Input: 120
-
-Output: 21
-
-
- -

Note:
- -Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.cs b/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.cs deleted file mode 100644 index eff0ff2a..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.cs +++ /dev/null @@ -1,15 +0,0 @@ -public class Solution { - public int Reverse(int x) { - var negative = x < 0; - if (negative) x = -x; - long result = 0; - while (x > 0) - { - result = (result * 10) + x % 10; - x /= 10; - } - if (negative) result = -result; - if (result > int.MaxValue || result < int.MinValue) result = 0; - return (int) result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.go b/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.go deleted file mode 100644 index 05dc2afb..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.go +++ /dev/null @@ -1,23 +0,0 @@ -func reverse(x int) int { - slot := make([]int, 11) - count := 0 - for x != 0 { - n := x%10 - slot[count] = n - count++ - x /= 10 - } - result := 0 - flag := true - for i := 0; i < count; i++ { - if flag && slot[i] == 0 { - continue - } - flag = false - result = 10 * result + slot[i] - } - if result > math.MaxInt32 || result < math.MinInt32 { - return 0 - } - return result -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.js b/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.js deleted file mode 100644 index 0812a570..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @param {number} x - * @return {number} - */ - -/** - * Author: mcnwork2018 - */ - -var reverse = function (x) { - let min = -Math.pow(2, 31), - max = Math.pow(2, 31) - 1; - let rev = 0; - while (x != 0) { - let pop = x % 10; - x = (x - pop) / 10; - if (rev > max / 10 || (rev == max / 10 && pop > 7)) return 0; - if (rev < min / 10 || (rev == min / 10 && pop < -8)) return 0; - rev = rev * 10 + pop; - } - return rev; -}; - -/** - * Author: rookie - */ - -var reverse = function (x) { - const s = x + ""; - let i = 0; - let sign = 1; - if (s[i] == "-") { - i++; - sign = -1; - } - if (s[i] == "+") { - i++; - } - let num = 0; - for (let j = s.length - 1; j >= i; j--) { - num = num * 10 + parseInt(s[j]); - } - num *= sign; - let max = 2; - for (let n = 0; n < 30; n++) { - max *= 2; - } - if (num > max || num < -max) { - return 0; - } - return num; -}; diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.py b/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.py deleted file mode 100644 index 83325e1c..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def reverse(self, x): - """ - :type x: int - :rtype: int - """ - if x==0: - return 0 - y=str(abs(x)) - y=y[::-1] - y=int(y) - if x<0: - tmp=-y - else: - tmp=y - - if tmp>=2**31-1 or tmp<-(2**31): - return 0 - else: - return tmp \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.rb b/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.rb deleted file mode 100644 index ca44c6f8..00000000 --- a/leetcode/solution/0000-0099/0007.Reverse Integer/Solution.rb +++ /dev/null @@ -1,21 +0,0 @@ -# @param {Integer} x -# @return {Integer} -def reverse(x) - neg = x < 0 - - x = x.abs - s = '' - - x /= 10 while x > 0 && (x % 10).zero? - - while x > 0 - s += (x % 10).to_s - x /= 10 - end - - s = neg ? '-' + s : s - - # have to explicitly constraint the int boundary as per the dummy test case - res = s.to_i - res <= 214_748_364_7 && res >= -214_748_364_8 ? res : 0 -end diff --git a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md b/leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md deleted file mode 100644 index d78018a9..00000000 --- a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md +++ /dev/null @@ -1,156 +0,0 @@ -# [8. String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) - -[中文文档]() - -## Description - -

Implement atoi which converts a string to an integer.

- -

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

- -

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

- -

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

- -

If no valid conversion could be performed, a zero value is returned.

- -

Note:

- -
    -
  • Only the space character ' ' is considered as whitespace character.
  • -
  • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
  • -
- -

Example 1:

- -
-
-Input: "42"
-
-Output: 42
-
-
- -

Example 2:

- -
-
-Input: "   -42"
-
-Output: -42
-
-Explanation: The first non-whitespace character is '-', which is the minus sign.
-
-             Then take as many numerical digits as possible, which gets 42.
-
-
- -

Example 3:

- -
-
-Input: "4193 with words"
-
-Output: 4193
-
-Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
-
-
- -

Example 4:

- -
-
-Input: "words and 987"
-
-Output: 0
-
-Explanation: The first non-whitespace character is 'w', which is not a numerical 
-
-             digit or a +/- sign. Therefore no valid conversion could be performed.
- -

Example 5:

- -
-
-Input: "-91283472332"
-
-Output: -2147483648
-
-Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
-
-             Thefore INT_MIN (−231) is returned.
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def myAtoi(self, s: str) -> int: - if not s: - return 0 - n = len(s) - if n == 0: - return 0 - i = 0 - while s[i] == ' ': - i += 1 - # only contains blank space - if i == n: - return 0 - sign = -1 if s[i] == '-' else 1 - if s[i] in ['-', '+']: - i += 1 - res, flag = 0, (2 ** 31 - 1) // 10 - while i < n: - # not a number, exit the loop - if not s[i].isdigit(): - break - c = int(s[i]) - # if overflows - if res > flag or (res == flag and c > 7): - return 2 ** 31 - 1 if sign > 0 else -2 ** 31 - res = res * 10 + c - i += 1 - return sign * res -``` - -### **Java** - -```java -class Solution { - public int myAtoi(String s) { - if (s == null) return 0; - int n = s.length(); - if (n == 0) return 0; - int i = 0; - while (s.charAt(i) == ' ') { - // only contains blank space - if (++i == n) return 0; - } - int sign = 1; - if (s.charAt(i) == '-') sign = -1; - if (s.charAt(i) == '-' || s.charAt(i) == '+') ++i; - int res = 0, flag = Integer.MAX_VALUE / 10; - for (; i < n; ++i) { - // not a number, exit the loop - if (s.charAt(i) < '0' || s.charAt(i) > '9') break; - // if overflows - if (res > flag || (res == flag && s.charAt(i) > '7')) return sign > 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE; - res = res * 10 + (s.charAt(i) - '0'); - } - return sign * res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.cs b/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.cs deleted file mode 100644 index dc30aefb..00000000 --- a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.cs +++ /dev/null @@ -1,46 +0,0 @@ -// https://leetcode.com/problems/string-to-integer-atoi/ - -public partial class Solution -{ - public int MyAtoi(string str) - { - int i = 0; - long result = 0; - bool minus = false; - while (i < str.Length && char.IsWhiteSpace(str[i])) - { - ++i; - } - if (i < str.Length) - { - if (str[i] == '+') - { - ++i; - } - else if (str[i] == '-') - { - minus = true; - ++i; - } - } - while (i < str.Length && char.IsDigit(str[i])) - { - result = result * 10 + str[i] - '0'; - if (result > int.MaxValue) - { - break; - } - ++i; - } - if (minus) result = -result; - if (result > int.MaxValue) - { - result = int.MaxValue; - } - if (result < int.MinValue) - { - result = int.MinValue; - } - return (int)result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.go b/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.go deleted file mode 100644 index 230cf220..00000000 --- a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.go +++ /dev/null @@ -1,37 +0,0 @@ -func myAtoi(str string) int { - cer := 0 - result := 0 - tmpResult := 0 - flag := false - for _, n := range str { - if !flag && n == ' ' { - continue - } - flag = true - if cer == 0 { - if n >= '0' && n <= '9' { - cer = 1 - } else if n == '+' { - cer = 1 - continue - } else if cer == 0 && (n == '-') { - cer = -1 - continue - } - } - - if n >= '0' && n <= '9' { - tmpResult = tmpResult * 10 + ((int)(n) - 48) - result = cer * tmpResult - } else { - break - } - if result < math.MinInt32 { - return math.MinInt32 - } - if result > math.MaxInt32 { - return math.MaxInt32 - } - } - return result -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.js b/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.js deleted file mode 100644 index e73b6cd7..00000000 --- a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.js +++ /dev/null @@ -1,24 +0,0 @@ -const myAtoi = function (str) { - str = str.trim(); - if (!str) return 0; - let isPositive = 1; - let i = 0, - ans = 0; - if (str[i] === "+") { - isPositive = 1; - i++; - } else if (str[i] === "-") { - isPositive = 0; - i++; - } - for (; i < str.length; i++) { - let t = str.charCodeAt(i) - 48; - if (t > 9 || t < 0) break; - if (ans > 2147483647 / 10 || ans > (2147483647 - t) / 10) { - return isPositive ? 2147483647 : -2147483648; - } else { - ans = ans * 10 + t; - } - } - return isPositive ? ans : -ans; -}; diff --git a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.py b/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.py deleted file mode 100644 index 42a02ff9..00000000 --- a/leetcode/solution/0000-0099/0008.String to Integer (atoi)/Solution.py +++ /dev/null @@ -1,28 +0,0 @@ -class Solution: - def myAtoi(self, s: str) -> int: - if not s: - return 0 - n = len(s) - if n == 0: - return 0 - i = 0 - while s[i] == ' ': - i += 1 - # only contains blank space - if i == n: - return 0 - sign = -1 if s[i] == '-' else 1 - if s[i] in ['-', '+']: - i += 1 - res, flag = 0, (2 ** 31 - 1) // 10 - while i < n: - # not a number, exit the loop - if not s[i].isdigit(): - break - c = int(s[i]) - # if overflows - if res > flag or (res == flag and c > 7): - return 2 ** 31 - 1 if sign > 0 else -2 ** 31 - res = res * 10 + c - i += 1 - return sign * res diff --git a/leetcode/solution/0000-0099/0009.Palindrome Number/README_EN.md b/leetcode/solution/0000-0099/0009.Palindrome Number/README_EN.md deleted file mode 100644 index 4c7a2094..00000000 --- a/leetcode/solution/0000-0099/0009.Palindrome Number/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [9. Palindrome Number](https://leetcode.com/problems/palindrome-number) - -[中文文档](/solution/0000-0099/0009.Palindrome%20Number/README.md) - -## Description - -

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

- -

Example 1:

- -
-
-Input: 121
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: -121
-
-Output: false
-
-Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
-
-
- -

Example 3:

- -
-
-Input: 10
-
-Output: false
-
-Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
-
-
- -

Follow up:

- -

Coud you solve it without converting the integer to a string?

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isPalindrome(self, x: int) -> bool: - if x < 0: - return False - y, t = 0, x - while t: - y = y * 10 + t % 10 - t //= 10 - return x == y -``` - -### **Java** - -```java -class Solution { - public boolean isPalindrome(int x) { - if (x < 0) return false; - int y = 0, t = x; - while (t != 0) { - y = y * 10 + t % 10; - t /= 10; - } - return x == y; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.go b/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.go deleted file mode 100644 index 0520bf78..00000000 --- a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.go +++ /dev/null @@ -1,12 +0,0 @@ -func isPalindrome(x int) bool { - if x < 0 { - return false - } - result := 0 - y := x - for y != 0 { - result = result * 10 + y%10 - y /= 10 - } - return result == x -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.js b/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.js deleted file mode 100644 index 355cce79..00000000 --- a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {number} x - * @return {boolean} - */ -var isPalindrome = function (x) { - let str = x + ""; - let left = 0, - right = str.length - 1; - while (left < right) { - if (str[left] != str[right]) return false; - left++; - right--; - } - return true; -}; diff --git a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.py b/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.py deleted file mode 100644 index 20666fee..00000000 --- a/leetcode/solution/0000-0099/0009.Palindrome Number/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def isPalindrome(self, x: int) -> bool: - if x < 0: - return False - y, t = 0, x - while t: - y = y * 10 + t % 10 - t //= 10 - return x == y diff --git a/leetcode/solution/0000-0099/0010.Regular Expression Matching/README_EN.md b/leetcode/solution/0000-0099/0010.Regular Expression Matching/README_EN.md deleted file mode 100644 index ee5191b4..00000000 --- a/leetcode/solution/0000-0099/0010.Regular Expression Matching/README_EN.md +++ /dev/null @@ -1,94 +0,0 @@ -# [10. Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching) - -[中文文档](/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md) - -## Description - -

Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.

- -
-'.' Matches any single character.
-'*' Matches zero or more of the preceding element.
-
- -

The matching should cover the entire input string (not partial).

- -

Note:

- -
    -
  • s could be empty and contains only lowercase letters a-z.
  • -
  • p could be empty and contains only lowercase letters a-z, and characters like . or *.
  • -
- -

Example 1:

- -
-Input:
-s = "aa"
-p = "a"
-Output: false
-Explanation: "a" does not match the entire string "aa".
-
- -

Example 2:

- -
-Input:
-s = "aa"
-p = "a*"
-Output: true
-Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
-
- -

Example 3:

- -
-Input:
-s = "ab"
-p = ".*"
-Output: true
-Explanation: ".*" means "zero or more (*) of any character (.)".
-
- -

Example 4:

- -
-Input:
-s = "aab"
-p = "c*a*b"
-Output: true
-Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".
-
- -

Example 5:

- -
-Input:
-s = "mississippi"
-p = "mis*is*p*."
-Output: false
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.cs b/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.cs deleted file mode 100644 index 248587ab..00000000 --- a/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.cs +++ /dev/null @@ -1,47 +0,0 @@ -public class Solution { - public bool IsMatch(string s, string p) { - var f = new bool[s.Length + 1, p.Length + 1]; - f[0, 0] = true; - for (var i = 0; i <= s.Length; ++i) - { - for (var j = 0; j <= p.Length; ++j) - { - if (i != 0 || j != 0) - { - if (j == 0) - { - f[i, j] = false; - } - else if (i == 0) - { - if (p[j - 1] == '*') - { - f[i, j] = f[i, j - 2]; - } - else - { - f[i, j] = false; - } - } - else - { - if (p[j - 1] == '.') - { - f[i, j] = f[i - 1, j - 1]; - } - else if (p[j - 1] == '*') - { - f[i, j] = f[i - 1, j] && (s[i - 1] == p[j - 2] || p[j - 2] == '.') || f[i, j - 2]; - } - else - { - f[i, j] = f[i - 1, j - 1] && s[i - 1] == p[j - 1]; - } - } - } - } - } - - return f[s.Length, p.Length]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.go b/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.go deleted file mode 100644 index 559dfa39..00000000 --- a/leetcode/solution/0000-0099/0010.Regular Expression Matching/Solution.go +++ /dev/null @@ -1,15 +0,0 @@ -func isMatch(s string, p string) bool { - //p only contains `.` or `*` or `[a-z]` - lenP := len(p) - lenS := len(s) - if lenP == 0 { - return lenS == 0 - } - fm := lenS != 0 && (s[0] == p[0] || p[0] == '.') - - if len(p) >= 2 && p[1] == '*' { - return isMatch(s, p[2:]) || fm && isMatch(s[1:], p) - } else { - return fm && isMatch(s[1:], p[1:]) - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0011.Container With Most Water/README_EN.md b/leetcode/solution/0000-0099/0011.Container With Most Water/README_EN.md deleted file mode 100644 index c7fc7a6f..00000000 --- a/leetcode/solution/0000-0099/0011.Container With Most Water/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [11. Container With Most Water](https://leetcode.com/problems/container-with-most-water) - -[中文文档](/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md) - -## Description - -

Given n non-negative integers a1, a2, ..., a, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

- -

Note: You may not slant the container and n is at least 2.

- -

 

- -![](./images/question_11.jpg) - -

The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.

- -

 

- -

Example:

- -
-
-Input: [1,8,6,2,5,4,8,3,7]
-
-Output: 49
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.cpp b/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.cpp deleted file mode 100644 index 50d2b7b7..00000000 --- a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int maxArea(vector& height) { - int Max = -1, Min, area; - int s = 0, e = height.size()-1; - - while( s < e ){ - if( height[s] < height[e] ){ - area = (e-s) * height[s]; - s++; - } - else{ - area = (e-s) * height[e]; - e--; - } - if( area > Max ) Max = area; - } - return Max; - } -}; diff --git a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.go b/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.go deleted file mode 100644 index 23b50940..00000000 --- a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.go +++ /dev/null @@ -1,30 +0,0 @@ -func maxArea(height []int) int { - maxArea := 0 - i := 0 - j := len(height) - 1 - for i != j { - hi := height[i] - hj := height[j] - maxArea = maxInt(maxArea, (j-i) * minInt(hi, hj)) - if hi >= hj { - j-- - } else { - i++ - } - } - return maxArea -} - -func minInt(a, b int) int { - if a >= b { - return b - } - return a -} - -func maxInt(a, b int) int { - if a >= b { - return a - } - return b -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.js b/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.js deleted file mode 100644 index 3728062a..00000000 --- a/leetcode/solution/0000-0099/0011.Container With Most Water/Solution.js +++ /dev/null @@ -1,20 +0,0 @@ -const maxArea2 = function (height) { - let result = 0; - for (let i = 0; i < height.length; i++) { - for (let j = i + 1; j < height.length; j++) { - result = Math.max(result, Math.min(height[i], height[j]) * (j - i)); - } - } - return result; -}; - -const maxArea = function (height) { - let result = 0, - l = 0, - r = height.length - 1; - while (l < r) { - result = Math.max(result, Math.min(height[l], height[r]) * (r - l)); - height[l] < height[r] ? l++ : r--; - } - return result; -}; diff --git a/leetcode/solution/0000-0099/0012.Integer to Roman/README_EN.md b/leetcode/solution/0000-0099/0012.Integer to Roman/README_EN.md deleted file mode 100644 index fcc72887..00000000 --- a/leetcode/solution/0000-0099/0012.Integer to Roman/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [12. Integer to Roman](https://leetcode.com/problems/integer-to-roman) - -[中文文档](/solution/0000-0099/0012.Integer%20to%20Roman/README.md) - -## Description - -

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

- -
-
-Symbol       Value
-
-I             1
-
-V             5
-
-X             10
-
-L             50
-
-C             100
-
-D             500
-
-M             1000
- -

For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

- -

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

- -
    -
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • -
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • -
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • -
- -

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.

- -

Example 1:

- -
-
-Input: 3
-
-Output: "III"
- -

Example 2:

- -
-
-Input: 4
-
-Output: "IV"
- -

Example 3:

- -
-
-Input: 9
-
-Output: "IX"
- -

Example 4:

- -
-
-Input: 58
-
-Output: "LVIII"
-
-Explanation: L = 50, V = 5, III = 3.
-
-
- -

Example 5:

- -
-
-Input: 1994
-
-Output: "MCMXCIV"
-
-Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0012.Integer to Roman/Solution.go b/leetcode/solution/0000-0099/0012.Integer to Roman/Solution.go deleted file mode 100644 index a08d8d64..00000000 --- a/leetcode/solution/0000-0099/0012.Integer to Roman/Solution.go +++ /dev/null @@ -1,49 +0,0 @@ -// 字符 数值 -// I 1 -// V 5 -// X 10 -// L 50 -// C 100 -// D 500 -// M 1000 -var table = make(map[int]string) -var keys = []int{1,4,5,9,10,40,50,90,100,400,500,900,1000} - -func init() { - table[1] = "I" - table[4] = "IV" - table[5] = "V" - table[9] = "IX" - table[10] = "X" - table[40] = "XL" - table[50] = "L" - table[90] = "XC" - table[100] = "C" - table[400] = "CD" - table[500] = "D" - table[900] = "CM" - table[1000] = "M" -} - -func intToRoman(num int) string { - if n, exist := table[num]; exist { - return n - } - var result string - lenKeys := len(keys) - for i:=lenKeys-1; i>=0; i-- { - d := keys[i] - count := num/d - result += genreateRoman(d, count) - num = num - d * count - } - return result -} - -func genreateRoman(n, count int) string { - var r string - for i:=0; iRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

- -
-
-Symbol       Value
-
-I             1
-
-V             5
-
-X             10
-
-L             50
-
-C             100
-
-D             500
-
-M             1000
- -

For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

- -

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

- -
    -
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • -
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • -
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • -
- -

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.

- -

Example 1:

- -
-
-Input: "III"
-
-Output: 3
- -

Example 2:

- -
-
-Input: "IV"
-
-Output: 4
- -

Example 3:

- -
-
-Input: "IX"
-
-Output: 9
- -

Example 4:

- -
-
-Input: "LVIII"
-
-Output: 58
-
-Explanation: L = 50, V= 5, III = 3.
-
-
- -

Example 5:

- -
-
-Input: "MCMXCIV"
-
-Output: 1994
-
-Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0013.Roman to Integer/Solution.go b/leetcode/solution/0000-0099/0013.Roman to Integer/Solution.go deleted file mode 100644 index 375e8ab2..00000000 --- a/leetcode/solution/0000-0099/0013.Roman to Integer/Solution.go +++ /dev/null @@ -1,41 +0,0 @@ -// 字符 数值 -// I 1 -// V 5 -// X 10 -// L 50 -// C 100 -// D 500 -// M 1000 -var table = make(map[string]int) - -func init() { - table["I"] = 1 - table["IV"] = 4 - table["V"] = 5 - table["IX"] = 9 - table["X"] = 10 - table["XL"] = 40 - table["L"] = 50 - table["XC"] = 90 - table["C"] = 100 - table["CD"] = 400 - table["D"] = 500 - table["CM"] = 900 - table["M"] = 1000 -} - -func romanToInt(s string) int { - var result int - lenS := len(s) - for i:=0; i 1, - 'V' => 5, - 'X' => 10, - 'L' => 50, - 'C' => 100, - 'D' => 500, - 'M' => 1000, - 'IV' => 4, - 'IX' => 9, - 'XL' => 40, - 'XC' => 90, - 'CD' => 400, - 'CM' => 900 - ] - res = 0 - i = 0 - while i < s.length - if i < s.length - 1 && !hash[s[i..i+1]].nil? - res += hash[s[i..i+1]] - i += 2 - else - res += hash[s[i]] - i += 1 - end - end - - res -end diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/README_EN.md b/leetcode/solution/0000-0099/0014.Longest Common Prefix/README_EN.md deleted file mode 100644 index bacab3e1..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [14. Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) - -[中文文档](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md) - -## Description - -

Write a function to find the longest common prefix string amongst an array of strings.

- -

If there is no common prefix, return an empty string "".

- -

Example 1:

- -
-
-Input: ["flower","flow","flight"]
-
-Output: "fl"
-
-
- -

Example 2:

- -
-
-Input: ["dog","racecar","car"]
-
-Output: ""
-
-Explanation: There is no common prefix among the input strings.
-
-
- -

Note:

- -

All given inputs are in lowercase letters a-z.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.cpp b/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.cpp deleted file mode 100644 index e61fcae7..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -static int x=[](){ - std::ios::sync_with_stdio(false); - cin.tie(NULL); - return 0; -}(); -string Compare(string s1,string s2) -{ - if(s1.size()==0||s2.size()==0) - return ""; - int num=s1.size()& strs) { - if(strs.size()==0) - return ""; - string prefix=strs[0]; - for(int i=1;i str.Length > i && str[i] == ch)) - { - sb.Append(ch); - } - else - { - break; - } - } - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.go b/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.go deleted file mode 100644 index e57364be..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.go +++ /dev/null @@ -1,14 +0,0 @@ -func longestCommonPrefix(strs []string) string { - result := "" - for i, v := range strs { - if i == 0 { - result = v - } - index := 0 - for index < len(result) && index < len(v) && result[index] == v[index] { - index++ - } - result = result[:index] - } - return result -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.js b/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.js deleted file mode 100644 index ef7ba23b..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.js +++ /dev/null @@ -1,11 +0,0 @@ -const longestCommonPrefix = function (strs) { - if (strs.length === 0) return ""; - for (let j = 0; j < strs[0].length; j++) { - for (let i = 0; i < strs.length; i++) { - if (strs[0][j] !== strs[i][j]) { - return strs[0].substring(0, j); - } - } - } - return strs[0]; -}; diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.py b/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.py deleted file mode 100644 index 676988f4..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.py +++ /dev/null @@ -1,25 +0,0 @@ -class Solution: - def longestCommonPrefix(self, strs): - """ - :type strs: List[str] - :rtype: str - """ - if strs == []: - return '' - if len(strs) == 1: - return strs[0] - strs.sort(key=lambda x : len(x)) - flag=False - prefix='' - for j in range(1,len(strs[0])+1): - prefix=strs[0][:j] - for i in range(1,len(strs)): - if prefix == strs[i][:j]: - flag=True - else: - flag=False - if not flag: - prefix0=prefix[:-1] - return prefix0 - break - return prefix \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.rb b/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.rb deleted file mode 100644 index ca78369b..00000000 --- a/leetcode/solution/0000-0099/0014.Longest Common Prefix/Solution.rb +++ /dev/null @@ -1,25 +0,0 @@ -# @param {String[]} strs -# @return {String} -def longest_common_prefix(strs) - return '' if strs.nil? || strs.length.zero? - - return strs[0] if strs.length == 1 - - idx = 0 - while idx < strs[0].length - cur_char = strs[0][idx] - - str_idx = 1 - while str_idx < strs.length - return idx > 0 ? strs[0][0..idx-1] : '' if strs[str_idx].length <= idx - - return '' if strs[str_idx][idx] != cur_char && idx.zero? - return strs[0][0..idx - 1] if strs[str_idx][idx] != cur_char - str_idx += 1 - end - - idx += 1 - end - - idx > 0 ? strs[0][0..idx] : '' -end diff --git a/leetcode/solution/0000-0099/0015.3Sum/README_EN.md b/leetcode/solution/0000-0099/0015.3Sum/README_EN.md deleted file mode 100644 index 1998b593..00000000 --- a/leetcode/solution/0000-0099/0015.3Sum/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [15. 3Sum](https://leetcode.com/problems/3sum) - -[中文文档](/solution/0000-0099/0015.3Sum/README.md) - -## Description - -

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

- -

Note:

- -

The solution set must not contain duplicate triplets.

- -

Example:

- -
-
-Given array nums = [-1, 0, 1, 2, -1, -4],
-
-
-
-A solution set is:
-
-[
-
-  [-1, 0, 1],
-
-  [-1, -1, 2]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def threeSum(self, nums: List[int]) -> List[List[int]]: - if nums is None or len(nums) < 3: - return [] - nums.sort() - n = len(nums) - res = [] - for i in range(n - 2): - if i > 0 and nums[i] == nums[i - 1]: - continue - p, q = i + 1, n - 1 - while p < q: - if p > i + 1 and nums[p] == nums[p - 1]: - p += 1 - continue - if q < n - 1 and nums[q] == nums[q + 1]: - q -= 1 - continue - if nums[i] + nums[p] + nums[q] < 0: - p += 1 - elif nums[i] + nums[p] + nums[q] > 0: - q -= 1 - else: - res.append([nums[i], nums[p], nums[q]]) - p += 1 - q -= 1 - return res -``` - -### **Java** - -```java -class Solution { - public List> threeSum(int[] nums) { - int n; - if (nums == null || (n = nums.length) < 3) { - return Collections.emptyList(); - } - Arrays.sort(nums); - List> res = new ArrayList<>(); - for (int i = 0; i < n - 2; ++i) { - if (i > 0 && nums[i] == nums[i - 1]) { - continue; - } - int p = i + 1, q = n - 1; - while (p < q) { - if (p > i + 1 && nums[p] == nums[p - 1]) { - ++p; - continue; - } - if (q < n - 1 && nums[q] == nums[q + 1]) { - --q; - continue; - } - if (nums[p] + nums[q] + nums[i] < 0) { - ++p; - } else if (nums[p] + nums[q] + nums[i] > 0) { - --q; - } else { - res.add(Arrays.asList(nums[p], nums[q], nums[i])); - ++p; - --q; - } - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0015.3Sum/Solution.cpp b/leetcode/solution/0000-0099/0015.3Sum/Solution.cpp deleted file mode 100644 index d28755dd..00000000 --- a/leetcode/solution/0000-0099/0015.3Sum/Solution.cpp +++ /dev/null @@ -1,40 +0,0 @@ -class Solution { -public: - vector> threeSum(vector& nums) { - sort(nums.begin(),nums.end()); - - vector> ans; - - int sum; - int len = nums.size(); - int left,right; - for(int i = 0; i< len;i++){ - left = i + 1; - right = len - 1; - while(left < right){ - sum = nums[i] + nums[left] + nums[right]; - if(sum == 0){ - vector vec; - vec.push_back(nums[i]); - vec.push_back(nums[left]); - vec.push_back(nums[right]); - ans.push_back(vec); - - while(left < right && nums[left] == nums[left + 1])left++; - while(left < right && nums[right] == nums[right - 1])right--; - - left++; - right--; - - } - if(sum > 0)right--; - if(sum < 0)left++; - } - - while(i> -{ - public bool Equals(IList left, IList right) - { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2]; - } - - public int GetHashCode(IList obj) - { - return (obj[0] ^ obj[1] ^ obj[2]).GetHashCode(); - } -} - -public class Solution { - public IList> ThreeSum(int[] nums) { - Array.Sort(nums); - var results = new HashSet>(new ThreeSumComparer()); - - var cIndex = Array.BinarySearch(nums, 0); - if (cIndex < 0) cIndex = ~cIndex; - while (cIndex < nums.Length) - { - var c = nums[cIndex]; - var aIndex = 0; - var bIndex = cIndex - 1; - while (aIndex < bIndex) - { - if (nums[aIndex] + nums[bIndex] + c < 0) - { - var step = 1; - while (aIndex + step < bIndex && nums[aIndex + step] + nums[bIndex] + c < 0) - { - aIndex += step; - step *= 2; - } - step /= 2; - while (step > 0) - { - if (aIndex + step < bIndex && nums[aIndex + step] + nums[bIndex] + c < 0) - { - aIndex += step; - } - step /= 2; - } - } - - if (nums[aIndex] + nums[bIndex] + c > 0) - { - var step = 1; - while (aIndex < bIndex - step && nums[aIndex] + nums[bIndex - step] + c > 0) - { - bIndex -= step; - step *= 2; - } - step /= 2; - while (step > 0) - { - if (aIndex < bIndex - step && nums[aIndex] + nums[bIndex - step] + c > 0) - { - bIndex -= step; - } - step /= 2; - } - } - - if (nums[aIndex] + nums[bIndex] + c == 0) - { - var list = new List { nums[aIndex], nums[bIndex], c }; - results.Add(list); - ++aIndex; - --bIndex; - } - else if (nums[aIndex] + nums[bIndex] + c < 0) - { - ++aIndex; - } - else - { - --bIndex; - } - } - ++cIndex; - } - - return results.ToList(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0015.3Sum/Solution.go b/leetcode/solution/0000-0099/0015.3Sum/Solution.go deleted file mode 100644 index 6bfa4602..00000000 --- a/leetcode/solution/0000-0099/0015.3Sum/Solution.go +++ /dev/null @@ -1,57 +0,0 @@ -func threeSum(nums []int) [][]int { - sort(nums) - result := make([][]int, 0) - for i, n := range nums { - if n > 0 { - break - } - if i > 0 && nums[i] == nums[i-1] { - continue - } - left := i + 1 - right := len(nums) - 1 - for left < right { - r := nums[left] + nums[right] + n - if r == 0 { - result = append(result, []int{nums[left], nums[right], n}) - left++ - for left < right && nums[left] == nums[left-1] { - left++ - } - right-- - for left < right && nums[right] == nums[right+1] { - right-- - } - } else if r < 0 { - left++ - } else if r > 0 { - right-- - } - } - } - return result -} - -// quick sort -func sort(array []int) { - if len(array) == 0 { - return - } - left := 0 - right := len(array) - 1 - obj := array[left] - for left < right { - for left < right && array[right] >= obj { - right-- - } - array[left] = array[right] - - for left < right && array[left] <= obj { - left++ - } - array[right] = array[left] - } - array[left] = obj - sort(array[:left]) - sort(array[right+1:]) -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0015.3Sum/Solution.py b/leetcode/solution/0000-0099/0015.3Sum/Solution.py deleted file mode 100644 index 917e5570..00000000 --- a/leetcode/solution/0000-0099/0015.3Sum/Solution.py +++ /dev/null @@ -1,27 +0,0 @@ -class Solution: - def threeSum(self, nums: List[int]) -> List[List[int]]: - if nums is None or len(nums) < 3: - return [] - nums.sort() - n = len(nums) - res = [] - for i in range(n - 2): - if i > 0 and nums[i] == nums[i - 1]: - continue - p, q = i + 1, n - 1 - while p < q: - if p > i + 1 and nums[p] == nums[p - 1]: - p += 1 - continue - if q < n - 1 and nums[q] == nums[q + 1]: - q -= 1 - continue - if nums[i] + nums[p] + nums[q] < 0: - p += 1 - elif nums[i] + nums[p] + nums[q] > 0: - q -= 1 - else: - res.append([nums[i], nums[p], nums[q]]) - p += 1 - q -= 1 - return res diff --git a/leetcode/solution/0000-0099/0015.3Sum/Solution.rb b/leetcode/solution/0000-0099/0015.3Sum/Solution.rb deleted file mode 100644 index 6714ce32..00000000 --- a/leetcode/solution/0000-0099/0015.3Sum/Solution.rb +++ /dev/null @@ -1,28 +0,0 @@ -# @param {Integer[]} nums -# @return {Integer[][]} -def three_sum(nums) - res = [] - nums.sort! - - for i in 0..(nums.length - 3) - next if i > 0 && nums[i - 1] == nums[i] - j = i + 1 - k = nums.length - 1 - while j < k do - sum = nums[i] + nums[j] + nums[k] - if sum < 0 - j += 1 - elsif sum > 0 - k -= 1 - else - res += [[nums[i], nums[j], nums[k]]] - j += 1 - k -= 1 - j += 1 while nums[j] == nums[j - 1] - k -= 1 while nums[k] == nums[k + 1] - end - end - end - - res -end diff --git a/leetcode/solution/0000-0099/0016.3Sum Closest/README_EN.md b/leetcode/solution/0000-0099/0016.3Sum Closest/README_EN.md deleted file mode 100644 index 8a3aaa24..00000000 --- a/leetcode/solution/0000-0099/0016.3Sum Closest/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -# [16. 3Sum Closest](https://leetcode.com/problems/3sum-closest) - -[中文文档](/solution/0000-0099/0016.3Sum%20Closest/README.md) - -## Description - -

Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

- -

Example:

- -
-
-Given array nums = [-1, 2, 1, -4], and target = 1.
-
-
-
-The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0016.3Sum Closest/Solution.go b/leetcode/solution/0000-0099/0016.3Sum Closest/Solution.go deleted file mode 100644 index a70c2440..00000000 --- a/leetcode/solution/0000-0099/0016.3Sum Closest/Solution.go +++ /dev/null @@ -1,54 +0,0 @@ -func threeSumClosest(nums []int, target int) int { - sort(nums) - lenNums := len(nums) - result := nums[0] + nums[1] + nums[2] - for i, n := range nums { - left := i + 1 - right := lenNums - 1 - for left < right { - r := nums[left] + nums[right] + n - if abs(r - target) < abs(result - target) { - result = r - } - if r > target { - right-- - } else if r < target { - left++ - } else { - return result - } - } - } - return result -} - -func abs(a int) int { - if a >= 0 { - return a - } - return -a; -} - -// quick sort -func sort(array []int) { - if len(array) == 0 { - return - } - left := 0 - right := len(array) - 1 - obj := array[left] - for left < right { - for left < right && array[right] >= obj { - right-- - } - array[left] = array[right] - - for left < right && array[left] <= obj { - left++ - } - array[right] = array[left] - } - array[left] = obj - sort(array[:left]) - sort(array[right+1:]) -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md b/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md deleted file mode 100644 index ff94318c..00000000 --- a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [17. Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number) - -[中文文档](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md) - -## Description - -

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

- -

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

- -![](./images/17_telephone_keypad.png) - -

Example:

- -
-
-Input: "23"
-
-Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
-
-
- -

Note:

- -

Although the above answer is in lexicographical order, your answer could be in any order you want.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.cs b/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.cs deleted file mode 100644 index fa574f86..00000000 --- a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - private static string[] chars = { - "abc", - "def", - "ghi", - "jkl", - "mno", - "pqrs", - "tuv", - "wxyz" - }; - - public IList LetterCombinations(string digits) { - var numbers = digits.Where(d => d >= '2' && d <= '9').Select(d => d - '2').ToArray(); - var states = new int[numbers.Length]; - var results = new List(); - if (numbers.Length == 0) return results; - while (true) { - results.Add(new string(states.Select((s, j) => chars[numbers[j]][s]).ToArray())); - var i = states.Length - 1; - ++states[i]; - while (i >= 0 && states[i] == chars[numbers[i]].Length) - { - states[i] = 0; - --i; - if (i >= 0) - { - ++states[i]; - } - } - if (i < 0) return results; - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.go b/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.go deleted file mode 100644 index 55ae341c..00000000 --- a/leetcode/solution/0000-0099/0017.Letter Combinations of a Phone Number/Solution.go +++ /dev/null @@ -1,28 +0,0 @@ -var table = map[string][]string { - "2": {"a", "b", "c"}, - "3": {"d", "e", "f"}, - "4": {"g", "h", "i"}, - "5": {"j", "k", "l"}, - "6": {"m", "n", "o"}, - "7": {"p", "q", "r", "s"}, - "8": {"t", "u", "v"}, - "9": {"w", "x", "y", "z"}, -} - -func letterCombinations(digits string) []string { - if digits == "" { - return make([]string, 0) - } - var result = table[string(digits[0])] - for i:=1; iGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

- -

Note:

- -

The solution set must not contain duplicate quadruplets.

- -

Example:

- -
-
-Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.
-
-
-
-A solution set is:
-
-[
-
-  [-1,  0, 0, 1],
-
-  [-2, -1, 1, 2],
-
-  [-2,  0, 0, 2]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def fourSum(self, nums: List[int], target: int) -> List[List[int]]: - res = [] - if nums is None or len(nums) < 4: - return res - n = len(nums) - nums.sort() - for i in range(n - 3): - if i > 0 and nums[i] == nums[i - 1]: - continue - for j in range(i + 1, n - 2): - if j > i + 1 and nums[j] == nums[j - 1]: - continue - p, q = j + 1, n - 1 - while p < q: - if p > j + 1 and nums[p] == nums[p - 1]: - p += 1 - continue - if q < n - 1 and nums[q] == nums[q + 1]: - q -= 1 - continue - t = nums[i] + nums[j] + nums[p] + nums[q] - if t == target: - res.append([nums[i], nums[j], nums[p], nums[q]]) - p += 1 - q -= 1 - elif t < target: - p += 1 - else: - q -= 1 - return res -``` - -### **Java** - -```java -class Solution { - public List> fourSum(int[] nums, int target) { - int n; - if (nums == null || (n = (nums.length)) < 4) { - return Collections.emptyList(); - } - Arrays.sort(nums); - List> res = new ArrayList<>(); - for (int i = 0; i < n - 3; ++i) { - if (i > 0 && nums[i] == nums[i - 1]) { - continue; - } - for (int j = i + 1; j < n - 2; ++j) { - if (j > i + 1 && nums[j] == nums[j - 1]) { - continue; - } - int p = j + 1, q = n - 1; - while (p < q) { - if (p > j + 1 && nums[p] == nums[p - 1]) { - ++p; - continue; - } - if (q < n - 1 && nums[q] == nums[q + 1]) { - --q; - continue; - } - int t = nums[i] + nums[j] + nums[p] + nums[q]; - if (t == target) { - res.add(Arrays.asList(nums[i], nums[j], nums[p], nums[q])); - ++p; - --q; - } else if (t < target) { - ++p; - } else { - --q; - } - } - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0018.4Sum/Solution.cpp b/leetcode/solution/0000-0099/0018.4Sum/Solution.cpp deleted file mode 100644 index ae0b4e81..00000000 --- a/leetcode/solution/0000-0099/0018.4Sum/Solution.cpp +++ /dev/null @@ -1,40 +0,0 @@ -class Solution { -public: - vector> fourSum(vector& nums, int target) { - int len = nums.size(); - vector> ans; - if(len < 4)return ans; - sort(nums.begin(),nums.end()); - - int left; - int right; - int sum; - for(int i = 0;i 0 && nums[i] == nums[i-1])continue; - for(int j = i + 1;j i+1 && nums[j] == nums[j-1])continue; - - left = j+1; - right = len - 1; - - while(left < right){ - - sum = nums[i] + nums[j] + nums[left] + nums[right]; - - if(sum == target){ - vector tmp{nums[i],nums[j],nums[left],nums[right]}; - ans.push_back(tmp); - - while(left < right && nums[left] == nums[left+1])left++; - while(left < right && nums[right] == nums[right-1])right--; - left++; - right--; - } - else if(sum < target)left++; - else if(sum > target)right--; - } - } - } - return ans; - } -}; diff --git a/leetcode/solution/0000-0099/0018.4Sum/Solution.cs b/leetcode/solution/0000-0099/0018.4Sum/Solution.cs deleted file mode 100644 index fa9a6c71..00000000 --- a/leetcode/solution/0000-0099/0018.4Sum/Solution.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -class FourSumComparer : IEqualityComparer> -{ - public bool Equals(IList left, IList right) - { - return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && left[3] == right[3]; - } - - public int GetHashCode(IList obj) - { - return (obj[0] ^ obj[1] ^ obj[2] ^ obj[3]).GetHashCode(); - } -} - -public class Solution { - public IList> FourSum(int[] nums, int target) { - Array.Sort(nums); - var results = new HashSet>(new FourSumComparer()); - for (var i = 0; i < nums.Length; ++i) - { - for (var j = i + 1; j < nums.Length; ++j) - { - var sum = target - nums[i] - nums[j]; - var k = j + 1; - var l = nums.Length - 1; - var step = (int)Math.Sqrt(nums.Length); - while (k < l) - { - while (k + step < l && nums[k + step] + nums[l] < sum) - { - k += step; - } - while (k < l && nums[k] + nums[l] < sum) - { - k += 1; - } - if (k < l && nums[k] + nums[l] == sum) - { - results.Add(new [] { nums[i], nums[j], nums[k], nums[l] }); - ++k; - } - while (k + step < l && nums[k] + nums[l - step] > sum) - { - l -= step; - } - while (k < l && nums[k] + nums[l] > sum) - { - l -= 1; - } - if (k < l && nums[k] + nums[l] == sum) - { - results.Add(new [] { nums[i], nums[j], nums[k], nums[l] }); - --l; - } - } - } - } - - return results.ToList(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0018.4Sum/Solution.go b/leetcode/solution/0000-0099/0018.4Sum/Solution.go deleted file mode 100644 index 78ec3b19..00000000 --- a/leetcode/solution/0000-0099/0018.4Sum/Solution.go +++ /dev/null @@ -1,78 +0,0 @@ -import "strconv" - -type Entry struct { - a1, a2, a3, a4 int -} - -func(e *Entry) String() string { - return strconv.FormatInt(int64(e.a1), 10) + - "," + strconv.FormatInt(int64(e.a2), 10) + - "," + strconv.FormatInt(int64(e.a3), 10) + - "," + strconv.FormatInt(int64(e.a4), 10) -} - -func fourSum(nums []int, target int) [][]int { - flag := make(map[string]bool) - sort(nums) - result := make([][]int, 0) - begin := 0 - lenNums := len(nums) - 1 - for begin + 2 < lenNums { - left := begin + 1 - right := lenNums - lt := target - nums[begin] - for left + 1 < right { - i := left + 1 - j := right - subTarget := lt - nums[left] - for i < j { - if nums[i] + nums[j] > subTarget { - j-- - } else if nums[i] + nums[j] < subTarget { - i++ - } else { - entry := &Entry{ - a1:nums[begin], - a2:nums[left], - a3:nums[i], - a4:nums[j], - } - if !flag[entry.String()] { - r := []int{nums[begin], nums[left], nums[i], nums[j]} - result = append(result, r) - flag[entry.String()] = true - } - i++ - j-- - } - } - left++ - } - begin++ - } - return result -} - -// quick sort -func sort(array []int) { - if len(array) == 0 { - return - } - left := 0 - right := len(array) - 1 - obj := array[left] - for left < right { - for left < right && array[right] >= obj { - right-- - } - array[left] = array[right] - - for left < right && array[left] <= obj { - left++ - } - array[right] = array[left] - } - array[left] = obj - sort(array[:left]) - sort(array[right+1:]) -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0018.4Sum/Solution.py b/leetcode/solution/0000-0099/0018.4Sum/Solution.py deleted file mode 100644 index 196ac70a..00000000 --- a/leetcode/solution/0000-0099/0018.4Sum/Solution.py +++ /dev/null @@ -1,31 +0,0 @@ -class Solution: - def fourSum(self, nums: List[int], target: int) -> List[List[int]]: - res = [] - if nums is None or len(nums) < 4: - return res - n = len(nums) - nums.sort() - for i in range(n - 3): - if i > 0 and nums[i] == nums[i - 1]: - continue - for j in range(i + 1, n - 2): - if j > i + 1 and nums[j] == nums[j - 1]: - continue - p, q = j + 1, n - 1 - while p < q: - if p > j + 1 and nums[p] == nums[p - 1]: - p += 1 - continue - if q < n - 1 and nums[q] == nums[q + 1]: - q -= 1 - continue - t = nums[i] + nums[j] + nums[p] + nums[q] - if t == target: - res.append([nums[i], nums[j], nums[p], nums[q]]) - p += 1 - q -= 1 - elif t < target: - p += 1 - else: - q -= 1 - return res \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md deleted file mode 100644 index 55f0a9cb..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list) - -[中文文档](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md) - -## Description - -

Given a linked list, remove the n-th node from the end of list and return its head.

- -

Example:

- -
-
-Given linked list: 1->2->3->4->5, and n = 2.
-
-
-
-After removing the second node from the end, the linked list becomes 1->2->3->5.
-
-
- -

Note:

- -

Given n will always be valid.

- -

Follow up:

- -

Could you do this in one pass?

- -## Solutions - - - -### **Python3** - -```python -# 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: ListNode, n: int) -> ListNode: - dummy = ListNode(0, head) - p = q = dummy - for i in range(n): - p = p.next - while p.next is not None: - p = p.next - q = q.next - q.next = q.next.next - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode removeNthFromEnd(ListNode head, int n) { - ListNode dummy = new ListNode(0, head); - ListNode p = dummy, q = dummy; - while (n-- > 0) { - p = p.next; - } - while (p.next != null) { - p = p.next; - q = q.next; - } - q.next = q.next.next; - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.cpp b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.cpp deleted file mode 100644 index d9e9248e..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.cpp +++ /dev/null @@ -1,25 +0,0 @@ -class Solution { -public: - ListNode* removeNthFromEnd(ListNode* head, int n) { - ListNode *p, *q ; - q = head ; - p = head ; - - for (int i = 0; i < n; ++i) - q = q->next ; - - if (!q) - { - return head->next ; - } - - while (q->next) - { - q = q->next ; - p = p->next ; - } - - p->next = p->next->next ; - return head ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.go b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.go deleted file mode 100644 index 1f754b39..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ - func removeNthFromEnd(head *ListNode, n int) *ListNode { - node0 := &ListNode{Val:0} - node0.Next = head - left := node0 - right := node0 - for n>0 { - right = right.Next - n-- - } - for right.Next != nil { - left = left.Next - right = right.Next - } - left.Next = left.Next.Next - return node0.Next -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js deleted file mode 100644 index cca2368b..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.js +++ /dev/null @@ -1,15 +0,0 @@ -const removeNthFromEnd = function (head, n) { - let left, - before, - right = head; - left = before = { next: head }; - while (n--) { - right = right.next; - } - while (right) { - right = right.next; - left = left.next; - } - left.next = left.next.next; - return before.next; -}; diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.py b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.py deleted file mode 100644 index 9666d7ab..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -# 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: ListNode, n: int) -> ListNode: - dummy = ListNode(0, head) - p = q = dummy - for i in range(n): - p = p.next - while p.next is not None: - p = p.next - q = q.next - q.next = q.next.next - return dummy.next \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.rb b/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.rb deleted file mode 100644 index 9654f08b..00000000 --- a/leetcode/solution/0000-0099/0019.Remove Nth Node From End of List/Solution.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Definition for singly-linked list. -# class ListNode -# attr_accessor :val, :next -# def initialize(val) -# @val = val -# @next = nil -# end -# end - -# @param {ListNode} head -# @param {Integer} n -# @return {ListNode} -def remove_nth_from_end(head, n) - return nil if head.next.nil? - count = 1 - q = head - s = head - - while q.next do - q = q.next - s = s.next if count > n - count += 1 - end - return head.next if count == n - s.next = s.next.next - head -end diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/README_EN.md b/leetcode/solution/0000-0099/0020.Valid Parentheses/README_EN.md deleted file mode 100644 index 14df331e..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/README_EN.md +++ /dev/null @@ -1,135 +0,0 @@ -# [20. Valid Parentheses](https://leetcode.com/problems/valid-parentheses) - -[中文文档](/solution/0000-0099/0020.Valid%20Parentheses/README.md) - -## Description - -

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

- -

An input string is valid if:

- -
    -
  1. Open brackets must be closed by the same type of brackets.
  2. -
  3. Open brackets must be closed in the correct order.
  4. -
- -

Note that an empty string is also considered valid.

- -

Example 1:

- -
-
-Input: "()"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: "()[]{}"
-
-Output: true
-
-
- -

Example 3:

- -
-
-Input: "(]"
-
-Output: false
-
-
- -

Example 4:

- -
-
-Input: "([)]"
-
-Output: false
-
-
- -

Example 5:

- -
-
-Input: "{[]}"
-
-Output: true
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isValid(self, s: str) -> bool: - q = [] - parentheses = {'()', '[]', '{}'} - for ch in s: - if ch in '([{': - q.append(ch) - elif not q or q.pop() + ch not in parentheses: - return False - return not q -``` - -### **Java** - -```java -class Solution { - public boolean isValid(String s) { - char[] chars = s.toCharArray(); - Deque q = new ArrayDeque<>(); - for (char ch : chars) { - boolean left = ch == '(' || ch == '[' || ch == '{'; - if (left) q.push(ch); - else if (q.isEmpty() || !match(q.pop(), ch)) return false; - } - return q.isEmpty(); - } - - private boolean match(char l, char r) { - return (l == '(' && r == ')') || (l == '{' && r == '}') || (l == '[' && r == ']'); - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - bool isValid(string s) { - stack q; - for (int i = 0, n = s.length(); i < n; ++i) { - if (s[i] == '{' || s[i] == '[' || s[i] == '(') q.push(s[i]); - else if (q.empty() || !match(q.top(), s[i])) return false; - else q.pop(); - } - return q.empty(); - } -private: - bool match(char l, char r) { - return (l == '(' && r == ')') || (l == '[' && r == ']') || (l == '{' && r == '}'); - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.cpp b/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.cpp deleted file mode 100644 index 3ac88b2d..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - bool isValid(string s) { - stack q; - for (int i = 0, n = s.length(); i < n; ++i) { - if (s[i] == '{' || s[i] == '[' || s[i] == '(') q.push(s[i]); - else if (q.empty() || !match(q.top(), s[i])) return false; - else q.pop(); - } - return q.empty(); - } -private: - bool match(char l, char r) { - return (l == '(' && r == ')') || (l == '[' && r == ']') || (l == '{' && r == '}'); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.go b/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.go deleted file mode 100644 index fdf38faf..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.go +++ /dev/null @@ -1,54 +0,0 @@ -func isValid(s string) bool { - stack := newStack() - for _, str := range s { - if str == '(' || str == '[' || str == '{' { - stack.push(byte(str)) - } else if str == ')' { - if stack.pop() != (byte('(')) { - return false - } - } else if str == ']' { - if stack.pop() != (byte('[')) { - return false - } - } else if str == '}' { - if stack.pop() != (byte('{')) { - return false - } - } - } - return stack.size() == 0 -} - -type Stack struct { - data []byte - index int -} - -func newStack() *Stack { - return &Stack{ - data: make([]byte, 10), - } -} - -func (s *Stack) pop() byte { - if s.index == 0 { - return 0 - } - s.index-- - r := s.data[s.index] - return r -} - -func (s *Stack) push(b byte) { - if len(s.data) - 1 <= s.index { - newData := make([]byte, len(s.data)) - s.data = append(s.data, newData[:]...) - } - s.data[s.index] = b - s.index++ -} - -func (s *Stack) size() int { - return s.index -} diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.js b/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.js deleted file mode 100644 index 1762946b..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.js +++ /dev/null @@ -1,14 +0,0 @@ -const isValid = function (s) { - let arr = []; - for (let i = 0; i < s.length; i++) { - if (s[i] === "{" || s[i] === "[" || s[i] === "(") { - arr.push(s[i]); - } else { - if (s[i] === ")" && arr[arr.length - 1] === "(") arr.pop(); - else if (s[i] === "]" && arr[arr.length - 1] === "[") arr.pop(); - else if (s[i] === "}" && arr[arr.length - 1] === "{") arr.pop(); - else return false; - } - } - return arr.length === 0; -}; diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.py b/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.py deleted file mode 100644 index 1ffb720b..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def isValid(self, s: str) -> bool: - q = [] - parentheses = {'()', '[]', '{}'} - for ch in s: - if ch in '([{': - q.append(ch) - elif not q or q.pop() + ch not in parentheses: - return False - return not q diff --git a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.rb b/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.rb deleted file mode 100644 index 68a94038..00000000 --- a/leetcode/solution/0000-0099/0020.Valid Parentheses/Solution.rb +++ /dev/null @@ -1,22 +0,0 @@ -# @param {String} s -# @return {Boolean} -def is_valid(s) - stack = '' - s.split('').each do |c| - if ['{', '[', '('].include?(c) - stack += c - else - if c == '}' && stack[stack.length - 1] == '{' - - stack = stack.length > 1 ? stack[0..stack.length - 2] : "" - elsif c == ']' && stack[stack.length - 1] == '[' - stack = stack.length > 1 ? stack[0..stack.length - 2] : "" - elsif c == ')' && stack[stack.length - 1] == '(' - stack = stack.length > 1 ? stack[0..stack.length - 2] : "" - else - return false - end - end - end - stack == '' -end diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md deleted file mode 100644 index fc933786..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [21. Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists) - -[中文文档](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md) - -## Description - -

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

- -

Example: - -

-
-Input: 1->2->4, 1->3->4
-
-Output: 1->1->2->3->4->4
-
-
- -

- -## Solutions - - - -### **Python3** - -```python -# 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, l1: ListNode, l2: ListNode) -> ListNode: - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode mergeTwoLists(ListNode l1, ListNode l2) { - ListNode dummy = new ListNode(0); - ListNode cur = dummy; - while (l1 != null && l2 != null) { - if (l1.val <= l2.val) { - cur.next = l1; - l1 = l1.next; - } else { - cur.next = l2; - l2 = l2.next; - } - cur = cur.next; - } - cur.next = l1 == null ? l2 : l1; - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.cpp b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.cpp deleted file mode 100644 index 1f80f78c..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ -class Solution { -public: - ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { - ListNode *a1=new ListNode(0); - ListNode *head=a1; - while(l1!=NULL&&l2!=NULL) - { - if(l1->valval) - { - a1->next=l1; - l1=l1->next; - a1=a1->next; - } - else - { - a1->next=l2; - l2=l2->next; - a1=a1->next; - } - } - if(l1==NULL) - a1->next=l2; - if(l2==NULL) - a1->next=l1; - return head->next; - - - } -}; diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.go b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.go deleted file mode 100644 index dd15c51c..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.go +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ - func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { - if l1==nil { - return l2 - } - - if l2==nil { - return l1 - } - - var p *ListNode - - if l1.Val > l2.Val { - p = l2 - l2 = l2.Next - }else{ - p = l1 - l1 = l1.Next - } - var head *ListNode = p - p.Next = nil - - for l1 != nil && l2 != nil { - if l1.Val > l2.Val { - p.Next = l2 - l2 = l2.Next - }else{ - p.Next = l1 - l1 = l1.Next - } - p = p.Next - p.Next = nil - } - - if l1 != nil{ - p.Next = l1 - } - if l2 != nil{ - p.Next = l2 - } - - return head -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js deleted file mode 100644 index 83553675..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.js +++ /dev/null @@ -1,58 +0,0 @@ -const mergeTwoLists2 = function (l1, l2) { - if (l1 === null && l2 === null) { - return null; - } - if (l1 !== null && l2 === null) { - return l1; - } - if (l1 === null && l2 !== null) { - return l2; - } - if (l1 !== null && l2 !== null) { - let t = null, - h = null; - if (l1.val > l2.val) { - t = l2; - h = l2; - l2 = l2.next; - } else { - t = l1; - h = l1; - l1 = l1.next; - } - while (l1 !== null && l2 !== null) { - if (l1.val > l2.val) { - t.next = l2; - t = t.next; - l2 = l2.next; - } else { - t.next = l1; - t = t.next; - l1 = l1.next; - } - } - while (l1 !== null) { - t.next = l1; - l1 = l1.next; - t = t.next; - } - while (l2 !== null) { - t.next = l2; - l2 = l2.next; - t = t.next; - } - return h; - } -}; - -const mergeTwoLists = function (l1, l2) { - if (l1 === null) return l2; - if (l2 === null) return l1; - if (l1.val < l2.val) { - l1.next = mergeTwoLists(l1.next, l2); - return l1; - } else { - l2.next = mergeTwoLists(l1, l2.next); - return l2; - } -}; diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.py b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.py deleted file mode 100644 index 33c5af90..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -# 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, l1: ListNode, l2: ListNode) -> ListNode: - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rb b/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rb deleted file mode 100644 index 337a7573..00000000 --- a/leetcode/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Definition for singly-linked list. -# class ListNode -# attr_accessor :val, :next -# def initialize(val) -# @val = val -# @next = nil -# end -# end - -# @param {ListNode} l1 -# @param {ListNode} l2 -# @return {ListNode} -def merge_two_lists(l1, l2) - if l1.nil? - l2 - elsif l2.nil? - l1 - elsif l1.val < l2.val - l1.next = merge_two_lists(l1.next, l2) - l1 - else - l2.next = merge_two_lists(l1, l2.next) - l2 - end -end diff --git a/leetcode/solution/0000-0099/0022.Generate Parentheses/README_EN.md b/leetcode/solution/0000-0099/0022.Generate Parentheses/README_EN.md deleted file mode 100644 index 73ca9e10..00000000 --- a/leetcode/solution/0000-0099/0022.Generate Parentheses/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [22. Generate Parentheses](https://leetcode.com/problems/generate-parentheses) - -[中文文档](/solution/0000-0099/0022.Generate%20Parentheses/README.md) - -## Description - -

- -Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. - -

- -

- -For example, given n = 3, a solution set is: - -

- -
-
-[
-
-  "((()))",
-
-  "(()())",
-
-  "(())()",
-
-  "()(())",
-
-  "()()()"
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0022.Generate Parentheses/Solution.go b/leetcode/solution/0000-0099/0022.Generate Parentheses/Solution.go deleted file mode 100644 index e087ab2c..00000000 --- a/leetcode/solution/0000-0099/0022.Generate Parentheses/Solution.go +++ /dev/null @@ -1,19 +0,0 @@ -func generateParenthesis(n int) []string { - result := make([]string, 0) - backParenthesis(&result, "", 0, 0, n) - return result -} - -func backParenthesis(result *[]string, cur string, open, close, max int) { - if len(cur) == 2 * max { - *result = append(*result, cur) - return - } - - if open < max { - backParenthesis(result, cur+"(", open+1, close, max) - } - if close < open { - backParenthesis(result, cur+")", open, close+1, max) - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md b/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md deleted file mode 100644 index 4da1986a..00000000 --- a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [23. Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists) - -[中文文档](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md) - -## Description - -

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

- -

Example:

- -
-
-Input:
-
-[
-
-  1->4->5,
-
-  1->3->4,
-
-  2->6
-
-]
-
-Output: 1->1->2->3->4->4->5->6
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def mergeKLists(self, lists: List[ListNode]) -> ListNode: - if not lists: - return None - n = len(lists) - for i in range(1, n): - lists[i] = self.mergeTwoLists(lists[i - 1], lists[i]) - return lists[n - 1] - - - def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode mergeKLists(ListNode[] lists) { - int n; - if (lists == null || (n = lists.length) == 0) { - return null; - } - for (int i = 1; i < n; ++i) { - lists[i] = mergeTwoLists(lists[i - 1], lists[i]); - } - return lists[n - 1]; - } - - private ListNode mergeTwoLists(ListNode l1, ListNode l2) { - ListNode dummy = new ListNode(0); - ListNode cur = dummy; - while (l1 != null && l2 != null) { - if (l1.val <= l2.val) { - cur.next = l1; - l1 = l1.next; - } else { - cur.next = l2; - l2 = l2.next; - } - cur = cur.next; - } - cur.next = l1 == null ? l2 : l1; - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cpp b/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cpp deleted file mode 100644 index 100de858..00000000 --- a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cpp +++ /dev/null @@ -1,105 +0,0 @@ -class compare -{ -public: - bool operator()(ListNode *l1,ListNode *l2){ - //if(!l1 || !l2) - // return !l1; - - if(l1 == NULL)return 1; - if(l2 == NULL)return 0; - return l1->val > l2->val; - //这里比较的是优先级,默认优先级排序是“<”号,若 l1Val > l2Val 返回真,即表示l1优先级比l2小,l2先入队 - //队列的top()函数指的就是优先级最高的元素,即队头元素 - } -}; - - -class Solution{ -public: - ListNode* mergeKLists(vector& lists) { - int len = lists.size(); - if(len == 0)return NULL; - - priority_queue,compare> Q;//调用小顶堆的方法构造队列!!! - - for(int i = 0;i < len;i++) - { - if(lists[i])Q.push(lists[i]); - } - - ListNode *head = new ListNode(0); - ListNode *tail = head; - while(!Q.empty() && Q.top() != NULL) - { - ListNode *tmp = Q.top(); - Q.pop(); - tail->next = tmp; - tail = tail->next; - Q.push(tmp->next); - } - return head->next; - } -}; - ------------------------------------------------------------------------ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ -class Solution { -public: - ListNode* merge(ListNode*l1,ListNode*l2){ //将两个链表合并的函数 - if(l1==NULL&&l2!=NULL) //如果两个链表有一个为空,那么返回另外一个。如果都为空,返回NULL。 - return l2; - else if(l1!=NULL&&l2==NULL) - return l1; - else if(l1==NULL&&l2==NULL) - return NULL; - - ListNode*ans,*p; - if(l1->val<=l2->val){ //处理首节点 - ans=l1; - l1=l1->next; - } - else{ - ans=l2; - l2=l2->next; - } - p=ans; - while(l1!=NULL&&l2!=NULL){ //每次从两个链表中取出一个结点放到结果链表当中 - if(l1->val<=l2->val) - { - p->next=l1; - l1=l1->next; - } - else - { - p->next=l2; - l2=l2->next; - } - p = p->next; - } - - - if(l1!=NULL)p->next=l1; - if(l2!=NULL)p->next=l2; - - return ans; - } - - ListNode* mergeKLists(vector& lists) { - int len = lists.size(); - if(len == 0)return NULL; - - ListNode *ans = lists[0]; - for(int i = 1; i < len;i++){ - ans = merge(ans,lists[i]); - } - - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cs b/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cs deleted file mode 100644 index d64f94a0..00000000 --- a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -class Comparer : IComparer> -{ - public int Compare(Tuple left, Tuple right) - { - var result = left.Item1.val.CompareTo(right.Item1.val); - if (result == 0) - { - result = left.Item2.CompareTo(right.Item2); - } - return result; - } -} - -public class Solution { - public ListNode MergeKLists(ListNode[] lists) { - var heap = new SortedSet>(new Comparer()); - for (var i = 0; i < lists.Length; ++i) - { - if (lists[i] != null) heap.Add(Tuple.Create(lists[i], i)); - } - ListNode head = null; - ListNode current = null; - while (heap.Any()) - { - var min = heap.Min; - heap.Remove(min); - if (min.Item1.next != null) heap.Add(Tuple.Create(min.Item1.next, min.Item2)); - if (head == null) - { - head = min.Item1; - current = head; - } - else - { - current.next = min.Item1; - current = current.next; - } - } - return head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.go b/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.go deleted file mode 100644 index 4d129b82..00000000 --- a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.go +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ - func mergeKLists(lists []*ListNode) *ListNode { - if len(lists) == 0 { - return nil - } - for len(lists) != 1 { - newLists := make([]*ListNode, 0) - for i:=0; i ListNode: - if not lists: - return None - n = len(lists) - for i in range(1, n): - lists[i] = self.mergeTwoLists(lists[i - 1], lists[i]) - return lists[n - 1] - - - def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.rb b/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.rb deleted file mode 100644 index bd72b12f..00000000 --- a/leetcode/solution/0000-0099/0023.Merge k Sorted Lists/Solution.rb +++ /dev/null @@ -1,39 +0,0 @@ -# Definition for singly-linked list. -# class ListNode -# attr_accessor :val, :next -# def initialize(val) -# @val = val -# @next = nil -# end -# end - -# @param {ListNode[]} lists -# @return {ListNode} -def merge_k_lists(lists) - if lists.nil? - nil - elsif lists.length == 1 - lists[0] - else - cur_list = lists[0] - for i in 1..lists.length - 1 - cur_list = merge_2_lists(cur_list, lists[i]) - end - cur_list - end - -end - -def merge_2_lists(list_a, list_b) - if list_a.nil? - list_b - elsif list_b.nil? - list_a - elsif list_a.val < list_b.val - list_a.next = merge_2_lists(list_a.next, list_b) - list_a - else - list_b.next = merge_2_lists(list_a, list_b.next) - list_b - end -end diff --git a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md b/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md deleted file mode 100644 index c9d3d45e..00000000 --- a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) - -[中文文档](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md) - -## Description - -

Given a linked list, swap every two adjacent nodes and return its head.

- -

You may not modify the values in the list's nodes, only nodes itself may be changed.

- -

 

- -

Example:

- -
-
-Given 1->2->3->4, you should return the list as 2->1->4->3.
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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: ListNode) -> ListNode: - dummy = ListNode(next=head) - pre, cur = dummy, head - while cur and cur.next: - t = cur.next - cur.next = t.next - t.next = cur - pre.next = t - pre = cur - cur = pre.next - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode swapPairs(ListNode head) { - ListNode dummy = new ListNode(0, head); - ListNode pre = dummy, cur = head; - while (cur != null && cur.next != null) { - ListNode t = cur.next; - cur.next = t.next; - t.next = cur; - pre.next = t; - pre = cur; - cur = pre.next; - - } - return dummy.next; - } -} -``` - -### **C++** - -```cpp -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode() : val(0), next(nullptr) {} - * ListNode(int x) : val(x), next(nullptr) {} - * ListNode(int x, ListNode *next) : val(x), next(next) {} - * }; - */ -class Solution { -public: - ListNode* swapPairs(ListNode* head) { - ListNode* dummy = new ListNode(0, head); - ListNode* pre = dummy; - ListNode* cur = head; - while (cur != nullptr && cur->next != nullptr) { - ListNode* t = cur->next; - cur->next = t->next; - t->next = cur; - pre->next = t; - pre = cur; - cur = pre->next; - } - return dummy->next; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.cpp b/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.cpp deleted file mode 100644 index 7ec36020..00000000 --- a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode() : val(0), next(nullptr) {} - * ListNode(int x) : val(x), next(nullptr) {} - * ListNode(int x, ListNode *next) : val(x), next(next) {} - * }; - */ -class Solution { -public: - ListNode* swapPairs(ListNode* head) { - ListNode* dummy = new ListNode(0, head); - ListNode* pre = dummy; - ListNode* cur = head; - while (cur != nullptr && cur->next != nullptr) { - ListNode* t = cur->next; - cur->next = t->next; - t->next = cur; - pre->next = t; - pre = cur; - cur = pre->next; - } - return dummy->next; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.go b/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.go deleted file mode 100644 index 48dde9d1..00000000 --- a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.go +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ - func swapPairs(head *ListNode) *ListNode { - if head == nil || head.Next == nil { - return head - } - first := head - second := head.Next - r := second - var p *ListNode = nil - for first != nil && second != nil { - t := second.Next - second.Next = first - first.Next = t - if p != nil { - p.Next = second - } - p = first - if t != nil { - second = t.Next - } else { - second = nil - } - first = t - } - return r -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.py b/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.py deleted file mode 100644 index 6811d2bc..00000000 --- a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -# 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: ListNode) -> ListNode: - dummy = ListNode(next=head) - pre, cur = dummy, head - while cur and cur.next: - t = cur.next - cur.next = t.next - t.next = cur - pre.next = t - pre = cur - cur = pre.next - return dummy.next diff --git a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.rb b/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.rb deleted file mode 100644 index dd41bcfb..00000000 --- a/leetcode/solution/0000-0099/0024.Swap Nodes in Pairs/Solution.rb +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for singly-linked list. -# class ListNode -# attr_accessor :val, :next -# def initialize(val) -# @val = val -# @next = nil -# end -# end - -# @param {ListNode} head -# @return {ListNode} -def swap_pairs(head) - if head.nil? || head.next.nil? - return head - end - - res = head.next - tmp = head.next.next - head.next.next = head - head.next = swap_pairs(tmp) - - res -end diff --git a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md b/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md deleted file mode 100644 index f2ee5e78..00000000 --- a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/README_EN.md +++ /dev/null @@ -1,52 +0,0 @@ -# [25. Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group) - -[中文文档](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md) - -## Description - -

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

- -

k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

- -
    - -
- -

Example:

- -

Given this linked list: 1->2->3->4->5

- -

For k = 2, you should return: 2->1->4->3->5

- -

For k = 3, you should return: 3->2->1->4->5

- -

Note:

- -
    -
  • Only constant extra memory is allowed.
  • -
  • You may not alter the values in the list's nodes, only nodes itself may be changed.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.cs b/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.cs deleted file mode 100644 index 4deadf8b..00000000 --- a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.cs +++ /dev/null @@ -1,52 +0,0 @@ -public class Solution { - public ListNode ReverseKGroup(ListNode head, int k) { - if (k < 2) return head; - ListNode newHead = null; - ListNode newTail = null; - var current = head; - while (current != null) - { - ListNode segmentHead = null; - ListNode segmentTail = null; - var count = 0; - while (current != null && count < k) - { - if (segmentHead == null) segmentHead = current; - segmentTail = current; - current = current.next; - ++count; - } - segmentTail.next = null; - if (count == k) - { - segmentTail = segmentHead; - segmentHead = ReverseList(segmentHead); - } - if (newHead == null) - { - newHead = segmentHead; - newTail = segmentTail; - } - else - { - newTail.next = segmentHead; - newTail = segmentTail; - } - } - return newHead; - } - - private ListNode ReverseList(ListNode head) - { - var current = head; - head = null; - while (current != null) - { - var next = current.next; - current.next = head; - head = current; - current = next; - } - return head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.go b/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.go deleted file mode 100644 index 93e68b66..00000000 --- a/leetcode/solution/0000-0099/0025.Reverse Nodes in k-Group/Solution.go +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ - func reverseKGroup(head *ListNode, k int) *ListNode { - start := head - var h *ListNode = nil - var t *ListNode = nil - ok := false - if h, t, ok = revert(start, k); !ok { - return head - } - r := h - p := t - print(2, r) - for ok { - start = t.Next - h, t, ok = revert(start, k) - p.Next = h - p = t - } - return r -} - -func revert(head *ListNode, k int) (h, t *ListNode, ok bool) { - c := head - if !check(c, k) { - return head, nil, false - } - - t = head - var p *ListNode = nil - for k > 0 { - temp := head - head = head.Next - temp.Next = p - p = temp - k-- - } - h = p - t.Next = head - ok = true - print(11, h) - return -} - -func check(head *ListNode, k int) bool { - for k > 0 { - if head == nil { - return false - } - k-- - head = head.Next - } - return true -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md b/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md deleted file mode 100644 index f5a82bca..00000000 --- a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md +++ /dev/null @@ -1,124 +0,0 @@ -# [26. Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) - -[中文文档](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md) - -## Description - -

Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.

- -

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

- -

Example 1:

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

Example 2:

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

Clarification:

- -

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

- -

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

- -

Internally you can think of this:

- -
-
-// nums is passed in by reference. (i.e., without making a copy)
-
-int len = removeDuplicates(nums);
-
-
-
-// any modification to nums in your function would be known by the caller.
-
-// using the length returned by your function, it prints the first len elements.
-
-for (int i = 0; i < len; i++) {
-
-    print(nums[i]);
-
-}
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def removeDuplicates(self, nums: List[int]) -> int: - cnt, n = 0, len(nums) - for i in range(1, n): - if nums[i] == nums[i - 1]: - cnt += 1 - else: - nums[i - cnt] = nums[i] - return n - cnt -``` - -### **Java** - -```java -class Solution { - public int removeDuplicates(int[] nums) { - int cnt = 0, n = nums.length; - for (int i = 1; i < n; ++i) { - if (nums[i] == nums[i - 1]) ++cnt; - else nums[i - cnt] = nums[i]; - } - return n - cnt; - } -} -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @return {number} - */ -var removeDuplicates = function (nums) { - let cnt = 0; - const n = nums.length; - for (let i = 1; i < n; ++i) { - if (nums[i] == nums[i - 1]) ++cnt; - else nums[i - cnt] = nums[i]; - } - return n - cnt; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.cs b/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.cs deleted file mode 100644 index 359db003..00000000 --- a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.cs +++ /dev/null @@ -1,16 +0,0 @@ -public class Solution { - public int RemoveDuplicates(int[] nums) { - if (nums.Length < 2) return nums.Length; - var i = 0; - var j = 1; - while (j < nums.Length) - { - if (nums[i] != nums[j]) - { - nums[++i] = nums[j]; - } - ++j; - } - return i + 1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.go b/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.go deleted file mode 100644 index eefc3be3..00000000 --- a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.go +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @lc app=leetcode.cn id=26 lang=golang - * Accepted - * 161/161 cases passed (144 ms) - * Your runtime beats 36.91 % of golang submissions - * Your memory usage beats 40.4 % of golang submissions (8.2 MB) - */ - -func removeDuplicates(nums []int) int { - if nums == nil || len(nums) == 0 { - return 0 - } - j := 0 - for i := 1; i < len(nums); i++ { - if nums[j] != nums[i] { - j++ - nums[j] = nums[i] - } - } - return j + 1 -} diff --git a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js b/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js deleted file mode 100644 index 105efa46..00000000 --- a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var removeDuplicates = function (nums) { - let cnt = 0; - const n = nums.length; - for (let i = 1; i < n; ++i) { - if (nums[i] == nums[i - 1]) ++cnt; - else nums[i - cnt] = nums[i]; - } - return n - cnt; -}; diff --git a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.py b/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.py deleted file mode 100644 index fb3d0986..00000000 --- a/leetcode/solution/0000-0099/0026.Remove Duplicates from Sorted Array/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def removeDuplicates(self, nums: List[int]) -> int: - cnt, n = 0, len(nums) - for i in range(1, n): - if nums[i] == nums[i - 1]: - cnt += 1 - else: - nums[i - cnt] = nums[i] - return n - cnt diff --git a/leetcode/solution/0000-0099/0027.Remove Element/README_EN.md b/leetcode/solution/0000-0099/0027.Remove Element/README_EN.md deleted file mode 100644 index f6d9c15f..00000000 --- a/leetcode/solution/0000-0099/0027.Remove Element/README_EN.md +++ /dev/null @@ -1,134 +0,0 @@ -# [27. Remove Element](https://leetcode.com/problems/remove-element) - -[中文文档](/solution/0000-0099/0027.Remove%20Element/README.md) - -## Description - -

Given an array nums and a value val, remove all instances of that value in-place and return the new length.

- -

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

- -

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

- -

Example 1:

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

Example 2:

- -
-
-Given nums = [0,1,2,2,3,0,4,2], val = 2,
-
-
-
-Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.
-
-
-
-Note that the order of those five elements can be arbitrary.
-
-
-
-It doesn't matter what values are set beyond the returned length.
- -

Clarification:

- -

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

- -

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

- -

Internally you can think of this:

- -
-
-// nums is passed in by reference. (i.e., without making a copy)
-
-int len = removeElement(nums, val);
-
-
-
-// any modification to nums in your function would be known by the caller.
-
-// using the length returned by your function, it prints the first len elements.
-
-for (int i = 0; i < len; i++) {
-
-    print(nums[i]);
-
-}
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def removeElement(self, nums: List[int], val: int) -> int: - cnt, n = 0, len(nums) - for i in range(n): - if nums[i] == val: - cnt += 1 - else: - nums[i - cnt] = nums[i] - return n - cnt -``` - -### **Java** - -```java -class Solution { - public int removeElement(int[] nums, int val) { - int cnt = 0, n = nums.length; - for (int i = 0; i < n; ++i) { - if (nums[i] == val) { - ++cnt; - } else { - nums[i - cnt] = nums[i]; - } - } - return n - cnt; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - int removeElement(vector& nums, int val) { - int cnt = 0, n = nums.size(); - for (int i = 0; i < n; ++i) { - if (nums[i] == val) { - ++cnt; - } else { - nums[i - cnt] = nums[i]; - } - } - return n - cnt; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0027.Remove Element/Solution.cpp b/leetcode/solution/0000-0099/0027.Remove Element/Solution.cpp deleted file mode 100644 index 64265012..00000000 --- a/leetcode/solution/0000-0099/0027.Remove Element/Solution.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int removeElement(vector& nums, int val) { - int cnt = 0, n = nums.size(); - for (int i = 0; i < n; ++i) { - if (nums[i] == val) { - ++cnt; - } else { - nums[i - cnt] = nums[i]; - } - } - return n - cnt; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0027.Remove Element/Solution.go b/leetcode/solution/0000-0099/0027.Remove Element/Solution.go deleted file mode 100644 index 4a9bdb13..00000000 --- a/leetcode/solution/0000-0099/0027.Remove Element/Solution.go +++ /dev/null @@ -1,13 +0,0 @@ -func removeElement(nums []int, val int) int { - if len(nums) == 0 { - return 0 - } - i := 0 - for j := 0; j < len(nums); j++ { - if nums[j] != val { - nums[i] = nums[j] - i++ - } - } - return i -} diff --git a/leetcode/solution/0000-0099/0027.Remove Element/Solution.js b/leetcode/solution/0000-0099/0027.Remove Element/Solution.js deleted file mode 100644 index 9a6bc0c7..00000000 --- a/leetcode/solution/0000-0099/0027.Remove Element/Solution.js +++ /dev/null @@ -1,39 +0,0 @@ -var removeElement3 = function (nums, val) { - let len = nums.length; - if (len < 1) { - return 0; - } - - let i = 0; - while (i < len) { - if (nums[i] === val) { - nums[i] = nums[len - 1]; - len--; - } else { - i++; - } - } - return len; -}; - -var removeElement2 = function (nums, val) { - let i = 0; - for (let j = 0; j < nums.length; j++) { - if (nums[j] !== val) { - nums[i] = nums[j]; - i++; - } - } - return i; -}; - -var removeElement = function (nums, val) { - let len = nums.length; - for (let i = 0; i < len; i++) { - if (nums[i] === val) { - nums.splice(i, 1); - i--; - } - } - return len; -}; diff --git a/leetcode/solution/0000-0099/0027.Remove Element/Solution.py b/leetcode/solution/0000-0099/0027.Remove Element/Solution.py deleted file mode 100644 index 2c48a9c6..00000000 --- a/leetcode/solution/0000-0099/0027.Remove Element/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def removeElement(self, nums: List[int], val: int) -> int: - cnt, n = 0, len(nums) - for i in range(n): - if nums[i] == val: - cnt += 1 - else: - nums[i - cnt] = nums[i] - return n - cnt diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/README_EN.md b/leetcode/solution/0000-0099/0028.Implement strStr()/README_EN.md deleted file mode 100644 index b6929028..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [28. Implement strStr()](https://leetcode.com/problems/implement-strstr) - -[中文文档]() - -## Description - -

Implement strStr().

- -

Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

- -

Example 1:

- -
-
-Input: haystack = "hello", needle = "ll"
-
-Output: 2
-
-
- -

Example 2:

- -
-
-Input: haystack = "aaaaa", needle = "bba"
-
-Output: -1
-
-
- -

Clarification:

- -

What should we return when needle is an empty string? This is a great question to ask during an interview.

- -

For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cpp b/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cpp deleted file mode 100644 index 3ac257af..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cpp +++ /dev/null @@ -1,54 +0,0 @@ -class Solution { -private: - vector Next(string str) - { - vector n(str.length()) ; - n[0] = -1 ; - int i = 0, pre = -1 ; - int len = str.length() ; - while (i < len) - { - while (pre >= 0 && str[i] != str[pre]) - pre = n[pre] ; - ++i, ++pre ; - if (i >= len) - break ; - if (str[i] == str[pre]) - n[i] = n[pre] ; - else - n[i] = pre ; - } - return n ; - } -public: - int strStr(string haystack, string needle) { - if (0 == needle.length()) - return 0 ; - - vector n(Next(needle)) ; - - int len = haystack.length() - needle.length() + 1 ; - for (int i = 0; i < len; ++i) - { - int j = 0, k = i ; - while (j < needle.length() && k < haystack.length()) - { - if (haystack[k] != needle[j]) - { - if (n[j] >= 0) - { - j = n[j] ; - continue ; - } - else - break ; - } - ++k, ++j ; - } - if (j >= needle.length()) - return k-j ; - } - - return -1 ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cs b/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cs deleted file mode 100644 index 20539523..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.cs +++ /dev/null @@ -1,14 +0,0 @@ -public class Solution { - public int StrStr(string haystack, string needle) { - for (var i = 0; i < haystack.Length - needle.Length + 1; ++i) - { - var j = 0; - for (; j < needle.Length; ++j) - { - if (haystack[i + j] != needle[j]) break; - } - if (j == needle.Length) return i; - } - return -1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.go b/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.go deleted file mode 100644 index c7dd40ef..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.go +++ /dev/null @@ -1,26 +0,0 @@ -func strStr(haystack string, needle string) int { - switch { - case len(needle) == 0: - return 0 - case len(needle) > len(haystack): - return -1 - case len(needle) == len(haystack): - if needle == haystack { - return 0 - } - return -1 - } - cursor := 0 - for i := 0; i < len(haystack); i++ { - if haystack[i] == needle[cursor] { - cursor++ - if cursor == len(needle) { - return i - cursor + 1 - } - } else { - i -= cursor - cursor = 0 - } - } - return -1 -} diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.js b/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.js deleted file mode 100644 index 76e29dae..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @param {string} haystack - * @param {string} needle - * @return {number} - */ -var strStr = function (haystack, needle) { - const slen = haystack.length; - const plen = needle.length; - if (slen == plen) { - return haystack == needle ? 0 : -1; - } - for (let i = 0; i <= slen - plen; i++) { - let j; - for (j = 0; j < plen; j++) { - if (haystack[i + j] != needle[j]) { - break; - } - } - if (j == plen) return i; - } - return -1; -}; diff --git a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.py b/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.py deleted file mode 100644 index fb8987f3..00000000 --- a/leetcode/solution/0000-0099/0028.Implement strStr()/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution: - def strStr(self, haystack, needle): - """ - :type haystack: str - :type needle: str - :rtype: int - """ - for i in range(len(haystack)-len(needle)+1): - p = i - q = 0 - while p < len(haystack) and q < len(needle) and haystack[p] == needle[q]: - p += 1 - q += 1 - - if q == len(needle): - return i - - return -1 diff --git a/leetcode/solution/0000-0099/0029.Divide Two Integers/README_EN.md b/leetcode/solution/0000-0099/0029.Divide Two Integers/README_EN.md deleted file mode 100644 index 41687328..00000000 --- a/leetcode/solution/0000-0099/0029.Divide Two Integers/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [29. Divide Two Integers](https://leetcode.com/problems/divide-two-integers) - -[中文文档](/solution/0000-0099/0029.Divide%20Two%20Integers/README.md) - -## Description - -

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

- -

Return the quotient after dividing dividend by divisor.

- -

The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2.

- -

Example 1:

- -
-Input: dividend = 10, divisor = 3
-Output: 3
-Explanation: 10/3 = truncate(3.33333..) = 3.
-
- -

Example 2:

- -
-Input: dividend = 7, divisor = -3
-Output: -2
-Explanation: 7/-3 = truncate(-2.33333..) = -2.
-
- -

Note:

- -
    -
  • Both dividend and divisor will be 32-bit signed integers.
  • -
  • The divisor will never be 0.
  • -
  • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.cs b/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.cs deleted file mode 100644 index f907d183..00000000 --- a/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.cs +++ /dev/null @@ -1,49 +0,0 @@ -public class Solution { - public int Divide(int dividend, int divisor) { - return (int)DivideInternal(dividend, divisor); - } - - public long GetHighestBit(long x) - { - if (x == 0) return 0; - long k = 0x80000000; - while ((x & k) == 0) - { - k >>= 1; - } - return k; - } - - public long DivideInternal(long dividend, long divisor) - { - int sign = (dividend > 0) ^ (divisor > 0) ? -1 : 1; - if (dividend < 0) dividend = -dividend; - if (divisor < 0) divisor = -divisor; - - long result = 0; - long pointer = GetHighestBit(dividend); - long currentHeader = 1; - dividend = dividend ^ pointer; - while (pointer > 0) - { - result <<= 1; - if (currentHeader >= divisor) - { - ++result; - currentHeader -= divisor; - } - pointer >>= 1; - bool nextIsOne = (dividend & pointer) != 0; - currentHeader = (currentHeader << 1) + (nextIsOne ? 1 : 0); - dividend = dividend ^ (nextIsOne ? pointer : 0); - } - - result = sign * result; - - if (result > int.MaxValue || result < int.MinValue) - { - return int.MaxValue; - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.py b/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.py deleted file mode 100644 index 1f130d1f..00000000 --- a/leetcode/solution/0000-0099/0029.Divide Two Integers/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -class Solution(object): - def divide(self, dividend, divisor): - """ - :type dividend: int - :type divisor: int - :rtype: int - """ - if dividend == 0: - return 0 - if divisor == 0: - return 2 ** 31 - 1 - - sign = (dividend < 0) ^ (divisor < 0) - - quotient = 0 - dividend = abs(dividend) - divisor = abs(divisor) - while dividend >= divisor: - tmp, i = divisor, 1 - while dividend >= tmp: - dividend -= tmp - quotient += i - tmp <<= 1 - print('Value of temp: '+str(tmp)) - i <<= 1 - print('Value of i: '+str(i)) - quotient *= (-1) ** sign - - return min(max(quotient, - 2 ** 31), 2 ** 31 - 1) diff --git a/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md b/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md deleted file mode 100644 index aea840fe..00000000 --- a/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [30. Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words) - -[中文文档](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md) - -## Description - -

You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.

- -

 

- -

Example 1:

- -
-Input:
-  s = "barfoothefoobarman",
-  words = ["foo","bar"]
-Output: [0,9]
-Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively.
-The output order does not matter, returning [9,0] is fine too.
-
- -

Example 2:

- -
-Input:
-  s = "wordgoodgoodgoodbestword",
-  words = ["word","good","best","word"]
-Output: []
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/Solution.cs b/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/Solution.cs deleted file mode 100644 index 20f85aa5..00000000 --- a/leetcode/solution/0000-0099/0030.Substring with Concatenation of All Words/Solution.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public IList FindSubstring(string s, string[] words) { - if (words.Length == 0) return new List(); - - var wordsDict = new Dictionary(); - foreach (var word in words) - { - if (!wordsDict.ContainsKey(word)) - { - wordsDict.Add(word, 1); - } - else - { - ++wordsDict[word]; - } - } - - var wordOfS = new string[s.Length]; - var wordLength = words[0].Length; - var wordCount = words.Length; - for (var i = 0; i <= s.Length - wordLength; ++i) - { - var substring = s.Substring(i, wordLength); - if (wordsDict.ContainsKey(substring)) - { - wordOfS[i] = substring; - } - } - - var result = new List(); - for (var i = 0; i <= s.Length - wordLength * wordCount; ++i) - { - var tempDict = new Dictionary(wordsDict); - var tempCount = 0; - for (var j = i; j <= i + wordLength * (wordCount - 1); j += wordLength) - { - if (wordOfS[j] != null && tempDict[wordOfS[j]] > 0) - { - --tempDict[wordOfS[j]]; - ++tempCount; - } - else - { - break; - } - } - if (tempCount == wordCount) - { - result.Add(i); - } - } - - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0031.Next Permutation/README_EN.md b/leetcode/solution/0000-0099/0031.Next Permutation/README_EN.md deleted file mode 100644 index 46c660f5..00000000 --- a/leetcode/solution/0000-0099/0031.Next Permutation/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -# [31. Next Permutation](https://leetcode.com/problems/next-permutation) - -[中文文档](/solution/0000-0099/0031.Next%20Permutation/README.md) - -## Description - -

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

- -

If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).

- -

The replacement must be in-place and use only constant extra memory.

- -

Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.

- -

1,2,31,3,2
- -3,2,11,2,3
- -1,1,51,5,1

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cpp b/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cpp deleted file mode 100644 index 72ee7586..00000000 --- a/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - void nextPermutation(vector &nums) { - int len = nums.size(); - - if (len == 0)return; - int i,j; - for(i = len - 2;i>=0;i--){ - if(nums[i+1] > nums[i]){ - for(j = len - 1;j>i;j--){ - if(nums[j]>nums[i])break; - } - swap(nums[i],nums[j]); - reverse(nums.begin()+i+1,nums.end()); - return; - } - } - reverse(nums.begin(),nums.end()); - } -}; diff --git a/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cs b/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cs deleted file mode 100644 index 1a38df58..00000000 --- a/leetcode/solution/0000-0099/0031.Next Permutation/Solution.cs +++ /dev/null @@ -1,26 +0,0 @@ -public class Solution { - public void NextPermutation(int[] nums) { - var index1 = -1; - var index2 = 0; - for (var i = 1; i < nums.Length; ++i) - { - if (nums[i - 1] < nums[i]) - { - index1 = i - 1; - index2 = i; - } - else if (index1 >= 0 && nums[index1] < nums[i]) - { - index2 = i; - } - } - - if (index1 >= 0) - { - var temp = nums[index1]; - nums[index1] = nums[index2]; - nums[index2] = temp; - } - System.Array.Sort(nums, index1 + 1, nums.Length - index1 - 1); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md b/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md deleted file mode 100644 index f6f24126..00000000 --- a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [32. Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses) - -[中文文档](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md) - -## Description - -

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

- -

Example 1:

- -
-
-Input: "(()"
-
-Output: 2
-
-Explanation: The longest valid parentheses substring is "()"
-
-
- -

Example 2:

- -
-
-Input: ")()())"
-
-Output: 4
-
-Explanation: The longest valid parentheses substring is "()()"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.cs b/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.cs deleted file mode 100644 index d482cbfe..00000000 --- a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int LongestValidParentheses(string s) { - var result = 0; - var baseCount = 0; - var stack = new Stack(); - foreach (var ch in s) - { - switch (ch) - { - case '(': - stack.Push(1); - break; - case ')': - if (stack.Count > 0) - { - var count = stack.Pop() + 1; - if (stack.Count > 0) - { - count += stack.Pop(); - stack.Push(count); - if (count - 1 > result) result = count - 1; - } - else - { - baseCount += count; - if (baseCount > result) result = baseCount; - } - } - else - { - baseCount = 0; - } - break; - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.py b/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.py deleted file mode 100644 index 526885d6..00000000 --- a/leetcode/solution/0000-0099/0032.Longest Valid Parentheses/Solution.py +++ /dev/null @@ -1,24 +0,0 @@ -class Solution: - def longestValidParentheses(self, s): - """ - :type s: string - :rtype int - """ - - Longest = temp = 0 - stack = [] - - for i in s: - if i == '(' : - stack.append(i) - elif len(stack) != 0 and stack[-1] == '(' : - stack.pop() - temp += 2 - else: - stack=[] - if temp > Longest: - Longest = temp - temp = 0 - if temp > Longest: - Longest = temp - return Longest \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md b/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md deleted file mode 100644 index 5769ad8a..00000000 --- a/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [33. Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array) - -[中文文档](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md) - -## Description - -

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

- -

(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

- -

You are given a target value to search. If found in the array return its index, otherwise return -1.

- -

You may assume no duplicate exists in the array.

- -

Your algorithm's runtime complexity must be in the order of O(log n).

- -

Example 1:

- -
-
-Input: nums = [4,5,6,7,0,1,2], target = 0
-
-Output: 4
-
-
- -

Example 2:

- -
-
-Input: nums = [4,5,6,7,0,1,2], target = 3
-
-Output: -1
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.cpp b/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.cpp deleted file mode 100644 index e4fce73a..00000000 --- a/leetcode/solution/0000-0099/0033.Search in Rotated Sorted Array/Solution.cpp +++ /dev/null @@ -1,36 +0,0 @@ -class Solution { -public: - int search(vector& nums, int target) { - int len = nums.size(); - int left = 0; - int right = len - 1; - int mid; - while(left <= right) { - mid = (left + right) / 2; - if(nums[mid] == target)return mid; - - if(nums[mid] < nums[right]) { - if(nums[right] >= target && nums[mid] < target)left = mid + 1; - else right = mid - 1; - } - else { - if(nums[left] <= target && nums[mid] > target)right = mid - 1; - else left = mid + 1; - } - } - return -1; - } -}; - ---------------- -class Solution { -public: - int search(vector& nums, int target) { - int len = nums.size(); - for(int i = 0;iGiven an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

- -

Your algorithm's runtime complexity must be in the order of O(log n).

- -

If the target is not found in the array, return [-1, -1].

- -

Example 1:

- -
-
-Input: nums = [5,7,7,8,8,10], target = 8
-
-Output: [3,4]
- -

Example 2:

- -
-
-Input: nums = [5,7,7,8,8,10], target = 6
-
-Output: [-1,-1]
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.cpp b/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.cpp deleted file mode 100644 index 7db0428a..00000000 --- a/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.cpp +++ /dev/null @@ -1,46 +0,0 @@ -class Solution { -public: - bool binarySearch(vector &nums,int &target,int &pos,int left,int right){ - int mid = left + ((right - left) >> 1); - if(nums[left] == target){ - pos = left; - return true; - } - if(nums[right] == target){ - pos = right; - return true; - } - if(nums[mid] == target){ - pos = mid; - return true; - } - - if(left == mid){ - return false; - } - else if(nums[mid] > target){ - return binarySearch(nums,target,pos,left,mid-1); - } - else if(nums[mid] < target){ - return binarySearch(nums,target,pos,mid+1,right); - } - - return false; - } - - vector searchRange(vector& nums, int target) { - int pos = 0; - int len = nums.size(); - if(len == 0)return {-1,-1}; - if(binarySearch(nums,target,pos,0,len-1)){ - int left = pos; - int right = pos; - while(left>0 && nums[left-1] == nums[pos])left--; - while(right target { - r = m - 1 - } - } - return []int{-1, -1} -} - -func findFirst(nums []int, l, r, target int) int { - var m int - for l < r { - m = (l + r) / 2 - if nums[m] < target { - l = m + 1 - } else if nums[m] == target { - r = m - } - } - return l -} -func findEnd(nums []int, l, r, target int) int { - var m int - for l < r { - m = (l + r + 1) / 2 // 需要加一,否则陷入死循环 - if nums[m] > target { - r = m - 1 - } else if nums[m] == target { - l = m - } - } - return l -} - diff --git a/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.py b/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.py deleted file mode 100644 index 27c09f80..00000000 --- a/leetcode/solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.py +++ /dev/null @@ -1,41 +0,0 @@ -class Solution(object): - def searchRange(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - - if not nums or target < nums[0] or target > nums[-1]: - return [-1, -1] - - # Finding the lower limit - left = 0 - right = len(nums) - - while left < right: - middle = (left + right)/2 - if nums[middle] >= target: - right = middle - - else: - left = middle + 1 - - - low = left - # Finding the higher limit - left = 0 - right = len(nums) - - while left < right-1: - middle = (left + right) / 2 - if nums[middle] > target: - right = middle - else: - left = middle - high = left - - if nums[low] == target and nums[high] == target: - return [low, high] - else: - return [-1, -1] diff --git a/leetcode/solution/0000-0099/0035.Search Insert Position/README_EN.md b/leetcode/solution/0000-0099/0035.Search Insert Position/README_EN.md deleted file mode 100644 index 94c2e6e1..00000000 --- a/leetcode/solution/0000-0099/0035.Search Insert Position/README_EN.md +++ /dev/null @@ -1,154 +0,0 @@ -# [35. Search Insert Position](https://leetcode.com/problems/search-insert-position) - -[中文文档](/solution/0000-0099/0035.Search%20Insert%20Position/README.md) - -## Description - -

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

- -

You may assume no duplicates in the array.

- -

Example 1:

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

Example 2:

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

Example 3:

- -
-
-Input: [1,3,5,6], 7
-
-Output: 4
-
-
- -

Example 4:

- -
-
-Input: [1,3,5,6], 0
-
-Output: 0
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def searchInsert(self, nums: List[int], target: int) -> int: - l, h = 0, len(nums) - 1 - while l <= h: - m = l + ((h - l) >> 1) - if nums[m] == target: - return m - if nums[m] < target: - l = m + 1 - else: - h = m - 1 - return l -``` - -### **Java** - -```java -class Solution { - public int searchInsert(int[] nums, int target) { - int l = 0, h = nums.length - 1; - while (l <= h) { - int m = l + ((h - l) >> 1); - if (nums[m] == target) return m; - if (nums[m] < target) l = m + 1; - else h = m - 1; - } - return l; - } -} -``` - -### **Go** - -```go -func searchInsert(nums []int, target int) int { - l, h := 0, len(nums) - 1 - for l <= h { - m := l + ((h - l) >> 1) - if nums[m] == target { - return m - } - if nums[m] < target { - l = m + 1 - } else { - h = m - 1 - } - } - return l -} -``` - -### **C++** - -```cpp -class Solution { -public: - int searchInsert(vector& nums, int target) { - int l = 0, h = nums.size() - 1; - while (l <= h) { - int m = l + ((h - l) >> 1); - if (nums[m] == target) return m; - if (nums[m] < target) l = m + 1; - else h = m - 1; - } - return l; - } -}; -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @param {number} target - * @return {number} - */ -var searchInsert = function (nums, target) { - let l = 0, - h = nums.length; - while (l <= h) { - const m = l + ((h - l) >> 1); - if (nums[m] == target) return m; - if (nums[m] < target) l = m + 1; - else h = m - 1; - } - return l; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.cpp b/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.cpp deleted file mode 100644 index 1eca6a02..00000000 --- a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - int searchInsert(vector& nums, int target) { - int l = 0, h = nums.size() - 1; - while (l <= h) { - int m = l + ((h - l) >> 1); - if (nums[m] == target) return m; - if (nums[m] < target) l = m + 1; - else h = m - 1; - } - return l; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.go b/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.go deleted file mode 100644 index 061b2b70..00000000 --- a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.go +++ /dev/null @@ -1,15 +0,0 @@ -func searchInsert(nums []int, target int) int { - l, h := 0, len(nums) - 1 - for l <= h { - m := l + ((h - l) >> 1) - if nums[m] == target { - return m - } - if nums[m] < target { - l = m + 1 - } else { - h = m - 1 - } - } - return l -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.js b/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.js deleted file mode 100644 index 1ac01948..00000000 --- a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @param {number[]} nums - * @param {number} target - * @return {number} - */ -var searchInsert = function (nums, target) { - let l = 0, - h = nums.length; - while (l <= h) { - const m = l + ((h - l) >> 1); - if (nums[m] == target) return m; - if (nums[m] < target) l = m + 1; - else h = m - 1; - } - return l; -}; diff --git a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.py b/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.py deleted file mode 100644 index 5dac6c0f..00000000 --- a/leetcode/solution/0000-0099/0035.Search Insert Position/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def searchInsert(self, nums: List[int], target: int) -> int: - l, h = 0, len(nums) - 1 - while l <= h: - m = l + ((h - l) >> 1) - if nums[m] == target: - return m - if nums[m] < target: - l = m + 1 - else: - h = m - 1 - return l diff --git a/leetcode/solution/0000-0099/0036.Valid Sudoku/README_EN.md b/leetcode/solution/0000-0099/0036.Valid Sudoku/README_EN.md deleted file mode 100644 index 2882c8bb..00000000 --- a/leetcode/solution/0000-0099/0036.Valid Sudoku/README_EN.md +++ /dev/null @@ -1,120 +0,0 @@ -# [36. Valid Sudoku](https://leetcode.com/problems/valid-sudoku) - -[中文文档](/solution/0000-0099/0036.Valid%20Sudoku/README.md) - -## Description - -

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

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


- -A partially filled sudoku which is valid.

- -

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

- -

Example 1:

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

Example 2:

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

Note:

- -
    -
  • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
  • -
  • Only the filled cells need to be validated according to the mentioned rules.
  • -
  • The given board contain only digits 1-9 and the character '.'.
  • -
  • The given board size is always 9x9.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0036.Valid Sudoku/Solution.js b/leetcode/solution/0000-0099/0036.Valid Sudoku/Solution.js deleted file mode 100644 index a58a823d..00000000 --- a/leetcode/solution/0000-0099/0036.Valid Sudoku/Solution.js +++ /dev/null @@ -1,94 +0,0 @@ -const isValidSudoku = function (board) { - let existed = new Set(); - for (let i = 0; i < 9; i++) { - for (let j = 0; j < 9; j++) { - let number = board[i][j]; - if (board[i][j] !== ".") { - if ( - existed.has(number + " in row " + i) || - existed.has(number + " in column " + j) || - existed.has( - number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3) - ) - ) { - return false; - } else { - existed.add(number + " in row " + i); - existed.add(number + " in column " + j); - existed.add( - number + "in block " + parseInt(i / 3) + "-" + parseInt(j / 3) - ); - } - } - } - } - return true; -}; - -/** - * @param {character[][]} board - * @return {boolean} - */ -const isValidSudoku2 = function (board) { - function lineTest(arr) { - for (let i = 0; i < 9; i++) { - for (let j = 0; j < 9; j++) { - for (let k = j + 1; k < 9; k++) { - if (arr[i][j] === arr[i][k] && arr[i][j] !== ".") { - return false; - } - } - } - } - return true; - } - function columnTest(arr) { - for (let i = 0; i < 9; i++) { - for (let j = 0; j < 9; j++) { - for (let k = j + 1; k < 9; k++) { - if (arr[j][i] === arr[k][i] && arr[j][i] !== ".") { - return false; - } - } - } - } - return true; - } - function squareTest(arr) { - let p = [ - [1, 1], - [1, 4], - [1, 7], - [4, 1], - [4, 4], - [4, 7], - [7, 1], - [7, 4], - [7, 7], - ]; - - for (let i = 0; i < p.length; i++) { - let a = []; - let x = p[i][0]; - let y = p[i][1]; - a.push(arr[x - 1][y - 1]); - a.push(arr[x - 1][y]); - a.push(arr[x - 1][y + 1]); - a.push(arr[x][y - 1]); - a.push(arr[x][y]); - a.push(arr[x][y + 1]); - a.push(arr[x + 1][y - 1]); - a.push(arr[x + 1][y]); - a.push(arr[x + 1][y + 1]); - for (let j = 0; j < a.length; j++) { - for (let k = j + 1; k < a.length; k++) { - if (a[j] === a[k] && a[j] !== ".") { - return false; - } - } - } - } - return true; - } - return lineTest(board) && columnTest(board) && squareTest(board); -}; diff --git a/leetcode/solution/0000-0099/0037.Sudoku Solver/README_EN.md b/leetcode/solution/0000-0099/0037.Sudoku Solver/README_EN.md deleted file mode 100644 index 3f1e862c..00000000 --- a/leetcode/solution/0000-0099/0037.Sudoku Solver/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [37. Sudoku Solver](https://leetcode.com/problems/sudoku-solver) - -[中文文档](/solution/0000-0099/0037.Sudoku%20Solver/README.md) - -## Description - -

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

- -

A sudoku solution must satisfy all of the following rules:

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

Empty cells are indicated by the character '.'.

- -


- -A sudoku puzzle...

- -


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

- -

Note:

- -
    -
  • The given board contain only digits 1-9 and the character '.'.
  • -
  • You may assume that the given Sudoku puzzle will have a single unique solution.
  • -
  • The given board size is always 9x9.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0037.Sudoku Solver/Solution.cs b/leetcode/solution/0000-0099/0037.Sudoku Solver/Solution.cs deleted file mode 100644 index c5b39670..00000000 --- a/leetcode/solution/0000-0099/0037.Sudoku Solver/Solution.cs +++ /dev/null @@ -1,131 +0,0 @@ -public class Solution { - public void SolveSudoku(char[][] board) { - this.board = new ushort?[9,9]; - for (var i = 0; i < 9; ++i) - { - for (var j = 0; j < 9; ++j) - { - if (board[i][j] != '.') - { - this.board[i, j] = (ushort) (1 << (board[i][j] - '0' - 1)); - } - } - } - - if (SolveSudoku(0, 0)) - { - for (var i = 0; i < 9; ++i) - { - for (var j = 0; j < 9; ++j) - { - if (board[i][j] == '.') - { - board[i][j] = '0'; - while (this.board[i, j].Value != 0) - { - board[i][j] = (char)(board[i][j] + 1); - this.board[i, j] >>= 1; - } - } - } - } - } - } - - private ushort?[,] board; - - private bool ValidateHorizontalRule(int row) - { - ushort temp = 0; - for (var i = 0; i < 9; ++i) - { - if (board[row, i].HasValue) - { - if ((temp | board[row, i].Value) == temp) - { - return false; - } - temp |= board[row, i].Value; - } - } - return true; - } - - private bool ValidateVerticalRule(int column) - { - ushort temp = 0; - for (var i = 0; i < 9; ++i) - { - if (board[i, column].HasValue) - { - if ((temp | board[i, column].Value) == temp) - { - return false; - } - temp |= board[i, column].Value; - } - } - return true; - } - - private bool ValidateBlockRule(int row, int column) - { - var startRow = row / 3 * 3; - var startColumn = column / 3 * 3; - ushort temp = 0; - for (var i = startRow; i < startRow + 3; ++i) - { - for (var j = startColumn; j < startColumn + 3; ++j) - { - if (board[i, j].HasValue) - { - if ((temp | board[i, j].Value) == temp) - { - return false; - } - temp |= board[i, j].Value; - } - } - } - return true; - } - - private bool SolveSudoku(int i, int j) - { - while (true) - { - if (j == 9) - { - ++i; - j = 0; - } - if (i == 9) - { - return true; - } - if (board[i, j].HasValue) - { - ++j; - } - else - { - break; - } - } - - ushort stop = 1 << 9; - for (ushort t = 1; t != stop; t <<= 1) - { - board[i, j] = t; - if (ValidateHorizontalRule(i) && ValidateVerticalRule(j) && ValidateBlockRule(i, j)) - { - if (SolveSudoku(i, j + 1)) - { - return true; - } - } - } - board[i, j] = null; - return false; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0038.Count and Say/README_EN.md b/leetcode/solution/0000-0099/0038.Count and Say/README_EN.md deleted file mode 100644 index 51154c70..00000000 --- a/leetcode/solution/0000-0099/0038.Count and Say/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [38. Count and Say](https://leetcode.com/problems/count-and-say) - -[中文文档](/solution/0000-0099/0038.Count%20and%20Say/README.md) - -## Description - -

The count-and-say sequence is the sequence of integers with the first five terms as following:

- -
-1.     1
-2.     11
-3.     21
-4.     1211
-5.     111221
-
- -

1 is read off as "one 1" or 11.
-11 is read off as "two 1s" or 21.
-21 is read off as "one 2, then one 1" or 1211.

- -

Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.

- -

Note: Each term of the sequence of integers will be represented as a string.

- -

 

- -

Example 1:

- -
-Input: 1
-Output: "1"
-Explanation: This is the base case.
-
- -

Example 2:

- -
-Input: 4
-Output: "1211"
-Explanation: For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211".
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0038.Count and Say/Solution.cs b/leetcode/solution/0000-0099/0038.Count and Say/Solution.cs deleted file mode 100644 index ff91620e..00000000 --- a/leetcode/solution/0000-0099/0038.Count and Say/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Text; -public class Solution { - public string CountAndSay(int n) { - var s = "1"; - while (n > 1) - { - var sb = new StringBuilder(); - var lastChar = '1'; - var count = 0; - foreach (var ch in s) - { - if (count > 0 && lastChar == ch) - { - ++count; - } - else - { - if (count > 0) - { - sb.Append(count); - sb.Append(lastChar); - } - lastChar = ch; - count = 1; - } - } - if (count > 0) - { - sb.Append(count); - sb.Append(lastChar); - } - s = sb.ToString(); - --n; - } - return s; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0038.Count and Say/Solution.go b/leetcode/solution/0000-0099/0038.Count and Say/Solution.go deleted file mode 100644 index 63e7d0dc..00000000 --- a/leetcode/solution/0000-0099/0038.Count and Say/Solution.go +++ /dev/null @@ -1,22 +0,0 @@ -func countAndSay(n int) string { - buf := bytes.NewBufferString("1") - for i := 2; i <= n; i++ { - s := buf.String() - c, l := s[0:1], len(s) - buf.Reset() - count := 0 - for j := 0; j < l; j++ { - if c == s[j:j+1] { - count++ - } else { - buf.WriteByte(byte(48 + count)) - buf.WriteString(c) - count = 1 - c = s[j : j+1] - } - } - buf.WriteByte(byte(48 + count)) - buf.WriteString(c) - } - return buf.String() -} diff --git a/leetcode/solution/0000-0099/0038.Count and Say/Solution.js b/leetcode/solution/0000-0099/0038.Count and Say/Solution.js deleted file mode 100644 index 972b40d3..00000000 --- a/leetcode/solution/0000-0099/0038.Count and Say/Solution.js +++ /dev/null @@ -1,20 +0,0 @@ -const countAndSay = function (n) { - let s = "1"; - - for (let i = 2; i <= n; i++) { - let count = 1, - str = "", - len = s.length; - - for (let j = 0; j < len; j++) { - if (j < len - 1 && s[j] === s[j + 1]) { - count++; - } else { - str += `${count}${s[j]}`; - count = 1; - } - } - s = str; - } - return s; -}; diff --git a/leetcode/solution/0000-0099/0038.Count and Say/Solution.py b/leetcode/solution/0000-0099/0038.Count and Say/Solution.py deleted file mode 100644 index e646f64c..00000000 --- a/leetcode/solution/0000-0099/0038.Count and Say/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution(object): - def countAndSay(self, n): - s = '1' #初始化第一个数字 - for i in range(n-1): #n-1个数 - temp = '' #一个空数列 - num = s[0] #s的第一位数字 - count = 0 #当前数字的个数 - - for j in s: #遍历s中的每个字母 - if num == j: #如果这个字母和num一样 - count += 1 #计数+1 - else: - temp += str(count)+str(num) #存下“几”个“什么数” - num = j #num改成当前数字 - count = 1 #计数回到1 - temp += str(count)+str(num) #加的是最后一个 - s = temp - return s diff --git a/leetcode/solution/0000-0099/0039.Combination Sum/README_EN.md b/leetcode/solution/0000-0099/0039.Combination Sum/README_EN.md deleted file mode 100644 index 3e850c83..00000000 --- a/leetcode/solution/0000-0099/0039.Combination Sum/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [39. Combination Sum](https://leetcode.com/problems/combination-sum) - -[中文文档](/solution/0000-0099/0039.Combination%20Sum/README.md) - -## Description - -

Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

- -

The same repeated number may be chosen from candidates unlimited number of times.

- -

Note:

- -
    -
  • All numbers (including target) will be positive integers.
  • -
  • The solution set must not contain duplicate combinations.
  • -
- -

Example 1:

- -
-
-Input: candidates = [2,3,6,7], target = 7,
-
-A solution set is:
-
-[
-
-  [7],
-
-  [2,2,3]
-
-]
-
-
- -

Example 2:

- -
-
-Input: candidates = [2,3,5], target = 8,
-
-A solution set is:
-
-[
-
-  [2,2,2,2],
-
-  [2,3,3],
-
-  [3,5]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cpp b/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cpp deleted file mode 100644 index dfd77c92..00000000 --- a/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution { -public: - vector> combinationSum(vector& candidates, int target) { - int len = candidates.size(); - vector> ans; - vector tmp; - sort(candidates.begin(),candidates.end()); - dfs(ans,tmp,candidates,target,len,0); - - return ans; - } - - void dfs(vector> &ans,vector &tmp,vector &nums,int target,int len,int index){ - - if(target == 0) ans.push_back(tmp); - - for(int i = index;i= nums[i];i++){ - tmp.push_back(nums[i]); - dfs(ans,tmp,nums,target-nums[i],len,i); - tmp.pop_back(); - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cs b/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cs deleted file mode 100644 index 6e618652..00000000 --- a/leetcode/solution/0000-0099/0039.Combination Sum/Solution.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Solution -{ - public IList> CombinationSum(int[] candidates, int target) - { - Array.Sort(candidates); - candidates = candidates.Distinct().ToArray(); - - var paths = new List[target + 1]; - paths[0] = new List(); - foreach (var c in candidates) - { - for (var j = c; j <= target; ++j) - { - if (paths[j - c] != null) - { - if (paths[j] == null) - { - paths[j] = new List(); - } - paths[j].Add(c); - } - } - } - - var results = new List>(); - if (paths[target] != null) GenerateResults(results, new Stack(), paths, target, paths[target].Count - 1); - return results; - } - - private void GenerateResults(IList> results, Stack result, List[] paths, int remaining, - int maxIndex) - { - if (remaining == 0) - { - results.Add(new List(result)); - return; - } - for (var i = maxIndex; i >= 0; --i) - { - var value = paths[remaining][i]; - result.Push(value); - var nextMaxIndex = paths[remaining - value].BinarySearch(value); - if (nextMaxIndex < 0) - { - nextMaxIndex = ~nextMaxIndex - 1; - } - GenerateResults(results, result, paths, remaining - value, nextMaxIndex); - result.Pop(); - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0040.Combination Sum II/README_EN.md b/leetcode/solution/0000-0099/0040.Combination Sum II/README_EN.md deleted file mode 100644 index 45f9f9f6..00000000 --- a/leetcode/solution/0000-0099/0040.Combination Sum II/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [40. Combination Sum II](https://leetcode.com/problems/combination-sum-ii) - -[中文文档](/solution/0000-0099/0040.Combination%20Sum%20II/README.md) - -## Description - -

Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.

- -

Each number in candidates may only be used once in the combination.

- -

Note:

- -
    -
  • All numbers (including target) will be positive integers.
  • -
  • The solution set must not contain duplicate combinations.
  • -
- -

Example 1:

- -
-
-Input: candidates = [10,1,2,7,6,1,5], target = 8,
-
-A solution set is:
-
-[
-
-  [1, 7],
-
-  [1, 2, 5],
-
-  [2, 6],
-
-  [1, 1, 6]
-
-]
-
-
- -

Example 2:

- -
-
-Input: candidates = [2,5,2,1,2], target = 5,
-
-A solution set is:
-
-[
-
-  [1,2,2],
-
-  [5]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cpp b/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cpp deleted file mode 100644 index f935d698..00000000 --- a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -class Solution { -public: - vector> combinationSum2(vector& candidates, int target) { - vector> ans; - vector tmp; - sort(candidates.begin(),candidates.end()); - int len = candidates.size(); - - dfs(ans,tmp,candidates,target,len,0); - - return ans; - } - - void dfs(vector> &ans,vector &tmp,vector &nums,int target,int len,int index) { - - if(target == 0){ - auto iter = find(ans.begin(),ans.end(),tmp); - if(iter == ans.end())ans.push_back(tmp); - } - - for(int i = index;i= nums[i];i++){ - tmp.push_back(nums[i]); - dfs(ans,tmp,nums,target - nums[i],len,i+1);//注意i+1 - tmp.pop_back(); - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cs b/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cs deleted file mode 100644 index 8bf55da4..00000000 --- a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Solution -{ - public IList> CombinationSum2(int[] candidates, int target) - { - var dict = new SortedDictionary(candidates.GroupBy(c => c).ToDictionary(g => g.Key, g => g.Count())); - var paths = new List>[target + 1]; - paths[0] = new List>(); - foreach (var pair in dict) - { - for (var j = target; j >= 0; --j) - { - for (var k = 1; k <= pair.Value && j - pair.Key * k >= 0; ++k) - { - if (paths[j - pair.Key * k] != null) - { - if (paths[j] == null) - { - paths[j] = new List>(); - } - paths[j].Add(Tuple.Create(pair.Key, k)); - } - } - } - } - - var results = new List>(); - if (paths[target] != null) GenerateResults(results, new Stack(), paths, target, paths[target].Count - 1); - return results; - } - - private void GenerateResults(IList> results, Stack result, List>[] paths, int remaining, - int maxIndex) - { - if (remaining == 0) - { - results.Add(new List(result)); - return; - } - for (var i = maxIndex; i >= 0; --i) - { - var path = paths[remaining][i]; - for (var j = 0; j < path.Item2; ++j) - { - result.Push(path.Item1); - } - var nextMaxIndex = paths[remaining - path.Item1 * path.Item2].BinarySearch(Tuple.Create(path.Item1, int.MinValue), Comparer.Instance); - nextMaxIndex = ~nextMaxIndex - 1; - GenerateResults(results, result, paths, remaining - path.Item1 * path.Item2, nextMaxIndex); - for (var j = 0; j < path.Item2; ++j) - { - result.Pop(); - } - } - } -} - -class Comparer : IComparer> -{ - public int Compare(Tuple x, Tuple y) - { - if (x.Item1 < y.Item1) return -1; - if (x.Item1 > y.Item1) return 1; - return x.Item2.CompareTo(y.Item2); - } - - public static Comparer Instance = new Comparer(); -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.go b/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.go deleted file mode 100644 index 19ee5882..00000000 --- a/leetcode/solution/0000-0099/0040.Combination Sum II/Solution.go +++ /dev/null @@ -1,26 +0,0 @@ -func combinationSum2(candidates []int, target int) [][]int { - //排序,然后递归搜索 - sort.Ints(candidates) - return dfs(candidates,target) -} - -func dfs(nums []int, target int) [][]int { - ret := [][]int{} - for i, n := range nums { - //跳过与之前迭代相同的值 - if i > 0 && nums[i-1] == n { - continue - } else if target < n { - break - } else if target == n { - ret = append(ret, []int{n}) - continue - } - //不能使用同一位置数字 - for _,v := range dfs(nums[i+1:], target - n) { - ret = append(ret,append([]int{n}, v...)) - } - } - - return ret -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0041.First Missing Positive/README_EN.md b/leetcode/solution/0000-0099/0041.First Missing Positive/README_EN.md deleted file mode 100644 index 6ea33b83..00000000 --- a/leetcode/solution/0000-0099/0041.First Missing Positive/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [41. First Missing Positive](https://leetcode.com/problems/first-missing-positive) - -[中文文档](/solution/0000-0099/0041.First%20Missing%20Positive/README.md) - -## Description - -

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

- -

Example 1:

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

Example 2:

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

Example 3:

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

Note:

- -

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

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.c b/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.c deleted file mode 100644 index 6e859a40..00000000 --- a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.c +++ /dev/null @@ -1,22 +0,0 @@ -int firstMissingPositive(int* nums, int numsSize) { - - int Max = nums[0], i, *Count; - - for(i = 1; i 0){ - Count[nums[i]]++; - } - } - - i = 1; - while(Count[i] != 0){ - i++; - } - - return i; -} diff --git a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cpp b/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cpp deleted file mode 100644 index ea29dcf0..00000000 --- a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int firstMissingPositive(vector& nums) { - sort(nums.begin(),nums.end()); - int len = nums.size(); - if(len == 0)return 1; - int i = 0; - while(nums[i] <= 0 && i < len)i++; - if(i == len)return 1; - - int tmp = 1; - while(ii+1 && nums[i] == nums[i+1])i++;//去重 - i++; - tmp++; - } - return tmp; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cs b/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cs deleted file mode 100644 index c7122e6b..00000000 --- a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.cs +++ /dev/null @@ -1,35 +0,0 @@ -public class Solution { - public int FirstMissingPositive(int[] nums) { - var i = 0; - while (i < nums.Length) - { - if (nums[i] > 0 && nums[i] <= nums.Length) - { - var index = nums[i] -1; - if (index != i && nums[index] != nums[i]) - { - var temp = nums[i]; - nums[i] = nums[index]; - nums[index] = temp; - } - else - { - ++i; - } - } - else - { - ++i; - } - } - - for (i = 0; i < nums.Length; ++i) - { - if (nums[i] != i + 1) - { - return i + 1; - } - } - return nums.Length + 1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.py b/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.py deleted file mode 100644 index 94dd8568..00000000 --- a/leetcode/solution/0000-0099/0041.First Missing Positive/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def firstMissingPositive(self, nums): - """ - :type nums: List[int] - :rtype: int - """ - - i = 1 - while i in nums: - i += 1 - return i diff --git a/leetcode/solution/0000-0099/0042.Trapping Rain Water/README_EN.md b/leetcode/solution/0000-0099/0042.Trapping Rain Water/README_EN.md deleted file mode 100644 index 3dede449..00000000 --- a/leetcode/solution/0000-0099/0042.Trapping Rain Water/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -# [42. Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water) - -[中文文档](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md) - -## Description - -

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

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

- -

Example:

- -
-
-Input: [0,1,0,2,1,0,1,3,2,1,2,1]
-
-Output: 6
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0042.Trapping Rain Water/Solution.cpp b/leetcode/solution/0000-0099/0042.Trapping Rain Water/Solution.cpp deleted file mode 100644 index c2c7dd08..00000000 --- a/leetcode/solution/0000-0099/0042.Trapping Rain Water/Solution.cpp +++ /dev/null @@ -1,38 +0,0 @@ -class Solution { -public: - int trap(vector& height) { - int len = height.size(); - if(len == 0 || len == 1)return 0; - - int slow = 0; - int fast = 1; - - int stopPoint; - - int total = 0; - int bottom; - int tmp = 0; - while(fast < len){ - //每次更新stopPoint - stopPoint = fast; - while(fast < len && height[fast] <= height[slow]){ - if(height[fast] > height[stopPoint]) - stopPoint = fast; - fast++; - } - - //越界了要回到stopPoint - if(fast >= len)fast = stopPoint; - - tmp = 0; - bottom = min(height[slow],height[fast]); - for(int i = slow+1;i height[stopPoint]: - stopPoint = fast - fast += 1 - # 越界了要回到stopPoint - if fast >= length: - fast = stopPoint - tmp = 0 - bottom = min(height[slow], height[fast]) - for i in range(slow + 1, fast): - tmp += bottom - height[i] - slow = fast - total += tmp - fast += 1 - return total diff --git a/leetcode/solution/0000-0099/0043.Multiply Strings/README_EN.md b/leetcode/solution/0000-0099/0043.Multiply Strings/README_EN.md deleted file mode 100644 index 1781f8c6..00000000 --- a/leetcode/solution/0000-0099/0043.Multiply Strings/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [43. Multiply Strings](https://leetcode.com/problems/multiply-strings) - -[中文文档](/solution/0000-0099/0043.Multiply%20Strings/README.md) - -## Description - -

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

- -

Example 1:

- -
-
-Input: num1 = "2", num2 = "3"
-
-Output: "6"
- -

Example 2:

- -
-
-Input: num1 = "123", num2 = "456"
-
-Output: "56088"
-
-
- -

Note:

- -
    -
  1. The length of both num1 and num2 is < 110.
  2. -
  3. Both num1 and num2 contain only digits 0-9.
  4. -
  5. Both num1 and num2 do not contain any leading zero, except the number 0 itself.
  6. -
  7. You must not use any built-in BigInteger library or convert the inputs to integer directly.
  8. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.cs b/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.cs deleted file mode 100644 index f73a98c1..00000000 --- a/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Text; - -public class Solution { - public string Multiply(string num1, string num2) { - var digits = new int[num1.Length + num2.Length]; - for (var i = 0; i < num1.Length; ++i) - { - for (var j = 0; j < num2.Length; ++j) - { - var digit1 = num1[num1.Length - i - 1] - '0'; - var digit2 = num2[num2.Length - j - 1] - '0'; - var product = digit1 * digit2; - digits[i + j] += product; - } - } - - var carry = 0; - for (var i = 0; i < digits.Length; ++i) - { - digits[i] += carry; - carry = digits[i] / 10; - digits[i] %= 10; - } - - var sb = new StringBuilder(); - for (var i = digits.Length - 1; i >= 0; --i) - { - if (digits[i] > 0 || sb.Length > 0) - { - sb.Append((char)(digits[i] + '0')); - } - } - if (sb.Length == 0) sb.Append('0'); - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.py b/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.py deleted file mode 100644 index e8679441..00000000 --- a/leetcode/solution/0000-0099/0043.Multiply Strings/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution(object): - def multiply(self, num1, num2): - - # Create a dictionary to store 0-9 key-value pairs - dict_nums={"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9} - number1 = 0 - number2 = 0 - - # Convert num1 in integer format - for i in num1: - key = dict_nums[i] - number1 = (number1 * 10) + key - - - # Convert num2 in integer format - for i in num2: - key = dict_nums[i] - number2 = (number2 * 10) + key - - return str(number1 * number2) diff --git a/leetcode/solution/0000-0099/0044.Wildcard Matching/README_EN.md b/leetcode/solution/0000-0099/0044.Wildcard Matching/README_EN.md deleted file mode 100644 index 077d5094..00000000 --- a/leetcode/solution/0000-0099/0044.Wildcard Matching/README_EN.md +++ /dev/null @@ -1,126 +0,0 @@ -# [44. Wildcard Matching](https://leetcode.com/problems/wildcard-matching) - -[中文文档](/solution/0000-0099/0044.Wildcard%20Matching/README.md) - -## Description - -

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

- -
-
-'?' Matches any single character.
-
-'*' Matches any sequence of characters (including the empty sequence).
-
-
- -

The matching should cover the entire input string (not partial).

- -

Note:

- -
    -
  • s could be empty and contains only lowercase letters a-z.
  • -
  • p could be empty and contains only lowercase letters a-z, and characters like ? or *.
  • -
- -

Example 1:

- -
-
-Input:
-
-s = "aa"
-
-p = "a"
-
-Output: false
-
-Explanation: "a" does not match the entire string "aa".
-
-
- -

Example 2:

- -
-
-Input:
-
-s = "aa"
-
-p = "*"
-
-Output: true
-
-Explanation: '*' matches any sequence.
-
-
- -

Example 3:

- -
-
-Input:
-
-s = "cb"
-
-p = "?a"
-
-Output: false
-
-Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.
-
-
- -

Example 4:

- -
-
-Input:
-
-s = "adceb"
-
-p = "*a*b"
-
-Output: true
-
-Explanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".
-
-
- -

Example 5:

- -
-
-Input:
-
-s = "acdcb"
-
-p = "a*c?b"
-
-Output: false
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0044.Wildcard Matching/Solution.cs b/leetcode/solution/0000-0099/0044.Wildcard Matching/Solution.cs deleted file mode 100644 index d67136b7..00000000 --- a/leetcode/solution/0000-0099/0044.Wildcard Matching/Solution.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Linq; - -public class Solution { - public bool IsMatch(string s, string p) { - if (p.Count(ch => ch != '*') > s.Length) - { - return false; - } - - bool[,] f = new bool[s.Length + 1, p.Length + 1]; - bool[] d = new bool[s.Length + 1]; // d[i] means f[0, j] || f[1, j] || ... || f[i, j] - for (var j = 0; j <= p.Length; ++j) - { - d[0] = j == 0 ? true : d[0] && p[j - 1] == '*'; - for (var i = 0; i <= s.Length; ++i) - { - if (j == 0) - { - f[i, j] = i == 0; - continue; - } - - if (p[j - 1] == '*') - { - if (i > 0) - { - d[i] = f[i, j - 1] || d[i - 1]; - } - f[i, j] = d[i]; - } - else if (p[j - 1] == '?') - { - f[i, j] = i > 0 && f[i - 1, j - 1]; - } - else - { - f[i, j] = i > 0 && f[i - 1, j - 1] && s[i - 1] == p[j - 1]; - } - } - } - return f[s.Length, p.Length]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0045.Jump Game II/README_EN.md b/leetcode/solution/0000-0099/0045.Jump Game II/README_EN.md deleted file mode 100644 index 66a24073..00000000 --- a/leetcode/solution/0000-0099/0045.Jump Game II/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [45. Jump Game II](https://leetcode.com/problems/jump-game-ii) - -[中文文档](/solution/0000-0099/0045.Jump%20Game%20II/README.md) - -## Description - -

Given an array of non-negative integers, you are initially positioned at the first index of the array.

- -

Each element in the array represents your maximum jump length at that position.

- -

Your goal is to reach the last index in the minimum number of jumps.

- -

Example:

- -
-
-Input: [2,3,1,1,4]
-
-Output: 2
-
-Explanation: The minimum number of jumps to reach the last index is 2.
-
-    Jump 1 step from index 0 to 1, then 3 steps to the last index.
- -

Note:

- -

You can assume that you can always reach the last index.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0045.Jump Game II/Solution.cs b/leetcode/solution/0000-0099/0045.Jump Game II/Solution.cs deleted file mode 100644 index 4002aa85..00000000 --- a/leetcode/solution/0000-0099/0045.Jump Game II/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -public class Solution { - public int Jump(int[] nums) { - var steps = 0; - var maxJump = 0; - var i = 0; - while (maxJump + 1 < nums.Length) - { - var newMaxJump = maxJump; - for (var j = i; j < nums.Length && j <= maxJump; ++j) - { - newMaxJump = Math.Max(newMaxJump, j + nums[j]); - } - i = maxJump + 1; - if (newMaxJump > maxJump) - { - maxJump = newMaxJump; - ++steps; - } - else - { - break; - } - } - if (maxJump + 1 >= nums.Length) return steps; - return -1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0046.Permutations/README_EN.md b/leetcode/solution/0000-0099/0046.Permutations/README_EN.md deleted file mode 100644 index c39f1319..00000000 --- a/leetcode/solution/0000-0099/0046.Permutations/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [46. Permutations](https://leetcode.com/problems/permutations) - -[中文文档](/solution/0000-0099/0046.Permutations/README.md) - -## Description - -

Given a collection of distinct integers, return all possible permutations.

- -

Example:

- -
-
-Input: [1,2,3]
-
-Output:
-
-[
-
-  [1,2,3],
-
-  [1,3,2],
-
-  [2,1,3],
-
-  [2,3,1],
-
-  [3,1,2],
-
-  [3,2,1]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0046.Permutations/Solution.cpp b/leetcode/solution/0000-0099/0046.Permutations/Solution.cpp deleted file mode 100644 index 53c6d493..00000000 --- a/leetcode/solution/0000-0099/0046.Permutations/Solution.cpp +++ /dev/null @@ -1,35 +0,0 @@ -class Solution { -public: - vector> permute(vector& nums) { - if (nums.size() == 0) return{}; - vector> res; - vector curr_vec; - vector used; - for (int i = 0; i < nums.size(); i++) - { - used.push_back(false); - } - dfs(res, nums, 0, curr_vec, used); - return res; - } - - void dfs(vector>& res, vector& nums, int depth, vector curr_vec, vector used) - { - - if (depth >= nums.size()) - { - res.emplace_back(curr_vec); - return; - } - - for (int i = 0; i < nums.size(); i++) - { - if (used[i]) continue; - used[i] = true; - curr_vec.emplace_back(nums[i]); - dfs(res, nums, depth + 1, curr_vec, used); - curr_vec.pop_back(); - used[i] = false; - } - } -}; diff --git a/leetcode/solution/0000-0099/0046.Permutations/Solution.cs b/leetcode/solution/0000-0099/0046.Permutations/Solution.cs deleted file mode 100644 index 64ed61f2..00000000 --- a/leetcode/solution/0000-0099/0046.Permutations/Solution.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public IList> Permute(int[] nums) { - var results = new List>(); - var temp = new List(); - var visited = new bool[nums.Length]; - Search(nums, visited, temp, results); - return results; - } - - private void Search(int[] nums, bool[] visited, IList temp, IList> results) - { - int count = 0; - for (var i = 0; i < nums.Length; ++i) - { - if (visited[i]) continue; - ++count; - temp.Add(nums[i]); - visited[i] = true; - Search(nums, visited, temp, results); - temp.RemoveAt(temp.Count - 1); - visited[i] = false; - } - if (count == 0 && temp.Any()) - { - results.Add(new List(temp)); - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0046.Permutations/Solution.go b/leetcode/solution/0000-0099/0046.Permutations/Solution.go deleted file mode 100644 index 70a7410c..00000000 --- a/leetcode/solution/0000-0099/0046.Permutations/Solution.go +++ /dev/null @@ -1,32 +0,0 @@ -func permute(nums []int) [][]int { - - n := len(nums) - tmp := make([]int,n) - ans := make([][]int,0) - idx := make([]bool,n) //默认0 - dfs(&ans,idx,tmp,nums,n,0) - return ans -} - - -func dfs(ans *[][]int,idx []bool,tmp []int,nums []int,n int,cur int) { - - if cur == n { - t := make([]int,n) - copy(t,tmp) - *ans = append(*ans,t) - return - } - - for i := 0;i < n;i++{ - if idx[i] == true{ - continue - } - - idx[i] = true - tmp[cur] = nums[i] - dfs(ans,idx,tmp,nums,n,cur+1) - idx[i] = false - } -} - diff --git a/leetcode/solution/0000-0099/0046.Permutations/Solution.py b/leetcode/solution/0000-0099/0046.Permutations/Solution.py deleted file mode 100644 index 876d44a2..00000000 --- a/leetcode/solution/0000-0099/0046.Permutations/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def permute(self, nums): - """ - :type nums: List[int] - :rtype: List[List[int]] - """ - if len(nums) <= 1: - return [nums] - ans = [] - for i, num in enumerate(nums): - n = nums[:i] + nums[i+1:] - for y in self.permute(n): - ans.append([num] + y) - return ans - \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0047.Permutations II/README_EN.md b/leetcode/solution/0000-0099/0047.Permutations II/README_EN.md deleted file mode 100644 index 9c2bd8ca..00000000 --- a/leetcode/solution/0000-0099/0047.Permutations II/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [47. Permutations II](https://leetcode.com/problems/permutations-ii) - -[中文文档](/solution/0000-0099/0047.Permutations%20II/README.md) - -## Description - -

Given a collection of numbers that might contain duplicates, return all possible unique permutations.

- -

Example:

- -
-
-Input: [1,1,2]
-
-Output:
-
-[
-
-  [1,1,2],
-
-  [1,2,1],
-
-  [2,1,1]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0047.Permutations II/Solution.cpp b/leetcode/solution/0000-0099/0047.Permutations II/Solution.cpp deleted file mode 100644 index ebbe2211..00000000 --- a/leetcode/solution/0000-0099/0047.Permutations II/Solution.cpp +++ /dev/null @@ -1,41 +0,0 @@ -class Solution { -public: - vector> permuteUnique(vector& nums) { - if (nums.size() <= 0) return{}; - - sort(nums.begin(), nums.end()); - - vector> res; - vector used; - vector curr; - - for (auto item : nums) - { - used.push_back(false); - } - - dfs(res, nums, curr, used, 0); - return res; - } - - void dfs(vector>& res, vector& nums, vector curr, vector used, int depth) - { - if (depth >= nums.size()) - { - res.emplace_back(curr); - return; - } - - for (int i = 0; i < nums.size(); i++) - { - if (used[i]) continue; - if (i > 0 && nums[i] == nums[i - 1] && !used[i-1]) continue; - - used[i] = true; - curr.emplace_back(nums[i]); - dfs(res, nums, curr, used, depth + 1); - curr.pop_back(); - used[i] = false; - } - } -}; diff --git a/leetcode/solution/0000-0099/0047.Permutations II/Solution.cs b/leetcode/solution/0000-0099/0047.Permutations II/Solution.cs deleted file mode 100644 index 6a13dfb1..00000000 --- a/leetcode/solution/0000-0099/0047.Permutations II/Solution.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public IList> PermuteUnique(int[] nums) { - var results = new List>(); - var temp = new List(); - var count = nums.GroupBy(n => n).ToDictionary(g => g.Key, g => g.Count()); - Search(count, temp, results); - return results; - } - - private void Search(Dictionary count, IList temp, IList> results) - { - if (!count.Any() && temp.Any()) - { - results.Add(new List(temp)); - return; - } - var keys = count.Keys.ToList(); - foreach (var key in keys) - { - temp.Add(key); - --count[key]; - if (count[key] == 0) count.Remove(key); - Search(count, temp, results); - temp.RemoveAt(temp.Count - 1); - if (count.ContainsKey(key)) - { - ++count[key]; - } - else - { - count[key] = 1; - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0047.Permutations II/Solution.py b/leetcode/solution/0000-0099/0047.Permutations II/Solution.py deleted file mode 100644 index 8349de0e..00000000 --- a/leetcode/solution/0000-0099/0047.Permutations II/Solution.py +++ /dev/null @@ -1,40 +0,0 @@ -class Solution: - def permuteUnique(self, nums): - ans = [[]] - for n in nums: - new_ans = [] - for l in ans: - for i in range(len(l)+1): - new_ans.append(l[:i]+[n]+l[i:]) - if iYou are given an n x n 2D matrix representing an image.

- -

Rotate the image by 90 degrees (clockwise).

- -

Note:

- -

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

- -

Example 1:

- -
-
-Given input matrix = 
-
-[
-
-  [1,2,3],
-
-  [4,5,6],
-
-  [7,8,9]
-
-],
-
-
-
-rotate the input matrix in-place such that it becomes:
-
-[
-
-  [7,4,1],
-
-  [8,5,2],
-
-  [9,6,3]
-
-]
-
-
- -

Example 2:

- -
-
-Given input matrix =
-
-[
-
-  [ 5, 1, 9,11],
-
-  [ 2, 4, 8,10],
-
-  [13, 3, 6, 7],
-
-  [15,14,12,16]
-
-], 
-
-
-
-rotate the input matrix in-place such that it becomes:
-
-[
-
-  [15,13, 2, 5],
-
-  [14, 3, 4, 1],
-
-  [12, 6, 8, 9],
-
-  [16, 7,10,11]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def rotate(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ - s, n = 0, len(matrix) - while s < (n >> 1): - e = n - s - 1 - for i in range(s, e): - t = matrix[i][e] - matrix[i][e] = matrix[s][i] - matrix[s][i] = matrix[n - i - 1][s] - matrix[n - i - 1][s] = matrix[e][n - i - 1] - matrix[e][n - i - 1] = t - s += 1 -``` - -### **Java** - -```java -class Solution { - public void rotate(int[][] matrix) { - int s = 0, n = matrix.length; - while (s < (n >> 1)) { - int e = n - s - 1; - for (int i = s; i < e; ++i) { - int t = matrix[i][e]; - matrix[i][e] = matrix[s][i]; - matrix[s][i] = matrix[n - i - 1][s]; - matrix[n - i - 1][s] = matrix[e][n - i - 1]; - matrix[e][n - i - 1] = t; - } - ++s; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.cpp b/leetcode/solution/0000-0099/0048.Rotate Image/Solution.cpp deleted file mode 100644 index 5c5418ad..00000000 --- a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - void rotate(vector>& matrix) { - - int n = matrix.size(); - if(n <= 1)return ; - - //先做转置 - for(int i = 0 ; i < n ; i++){ - for(int j = i;j < n ;j++){ - swap(matrix[i][j],matrix[j][i]); - } - } - - //再做水平互换 - for(int i = 0 ; i < n ; i++){ - for(int j = 0;j < n/2;j++){ - swap(matrix[i][j],matrix[i][n-1-j]); - } - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.js b/leetcode/solution/0000-0099/0048.Rotate Image/Solution.js deleted file mode 100644 index 168962e3..00000000 --- a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @param {number[][]} matrix - * @return {void} Do not return anything, modify matrix in-place instead. - */ -const rotate1 = function (matrix) { - // function swap(x,y){ - // console.log(x,y); - // let z = x; - // x = y; - // y = z; - // } - for (let i = 0; i < matrix.length; i++) { - for (let j = 0; j <= i; j++) { - // swap(matrix[i][j],matrix[j][i]); - // let t = matrix[i][j]; - // matrix[i][j] = matrix[j][i]; - // matrix[j][i] = t; - [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; - } - } - for (let i = 0, j = matrix.length - 1; i < j; i++, j--) { - for (let k = 0; k < matrix.length; k++) { - // swap(matrix[k][i], matrix[k][j]); - // let t = matrix[k][i]; - // matrix[k][i] = matrix[k][j]; - // matrix[k][j] = t; - [matrix[k][i], matrix[k][j]] = [matrix[k][j], matrix[k][i]]; - } - } -}; - -const rotate = function (matrix) { - matrix = matrix.reverse(); - for (let i = 0; i < matrix.length; i++) { - for (let j = 0; j < i; j++) { - [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; - } - } -}; diff --git a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.py b/leetcode/solution/0000-0099/0048.Rotate Image/Solution.py deleted file mode 100644 index e4d50d5e..00000000 --- a/leetcode/solution/0000-0099/0048.Rotate Image/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def rotate(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ - s, n = 0, len(matrix) - while s < (n >> 1): - e = n - s - 1 - for i in range(s, e): - t = matrix[i][e] - matrix[i][e] = matrix[s][i] - matrix[s][i] = matrix[n - i - 1][s] - matrix[n - i - 1][s] = matrix[e][n - i - 1] - matrix[e][n - i - 1] = t - s += 1 diff --git a/leetcode/solution/0000-0099/0049.Group Anagrams/README_EN.md b/leetcode/solution/0000-0099/0049.Group Anagrams/README_EN.md deleted file mode 100644 index 5192122f..00000000 --- a/leetcode/solution/0000-0099/0049.Group Anagrams/README_EN.md +++ /dev/null @@ -1,56 +0,0 @@ -# [49. Group Anagrams](https://leetcode.com/problems/group-anagrams) - -[中文文档](/solution/0000-0099/0049.Group%20Anagrams/README.md) - -## Description - -

Given an array of strings, group anagrams together.

- -

Example:

- -
-
-Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
-
-Output:
-
-[
-
-  ["ate","eat","tea"],
-
-  ["nat","tan"],
-
-  ["bat"]
-
-]
- -

Note:

- -
    -
  • All inputs will be in lowercase.
  • -
  • The order of your output does not matter.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0049.Group Anagrams/Solution.cs b/leetcode/solution/0000-0099/0049.Group Anagrams/Solution.cs deleted file mode 100644 index a3bf6ba3..00000000 --- a/leetcode/solution/0000-0099/0049.Group Anagrams/Solution.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections.Generic; - -public class Comparer : IEqualityComparer -{ - public bool Equals(string left, string right) - { - if (left.Length != right.Length) return false; - - var leftCount = new int[26]; - foreach (var ch in left) - { - ++leftCount[ch - 'a']; - } - - var rightCount = new int[26]; - foreach (var ch in right) - { - var index = ch - 'a'; - if (++rightCount[index] > leftCount[index]) return false; - } - - return true; - } - - public int GetHashCode(string obj) - { - var hashCode = 0; - for (int i = 0; i < obj.Length; ++i) - { - hashCode ^= 1 << (obj[i] - 'a'); - } - return hashCode; - } -} - -public class Solution { - public IList> GroupAnagrams(string[] strs) { - var dict = new Dictionary>(new Comparer()); - foreach (var str in strs) - { - List list; - if (!dict.TryGetValue(str, out list)) - { - list = new List(); - dict.Add(str, list); - } - list.Add(str); - } - foreach (var list in dict.Values) - { - list.Sort(); - } - return new List>(dict.Values); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0050.Pow(x, n)/README_EN.md b/leetcode/solution/0000-0099/0050.Pow(x, n)/README_EN.md deleted file mode 100644 index 9e704fda..00000000 --- a/leetcode/solution/0000-0099/0050.Pow(x, n)/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [50. Pow(x, n)](https://leetcode.com/problems/powx-n) - -[中文文档]() - -## Description - -

Implement pow(x, n), which calculates x raised to the power n (xn).

- -

Example 1:

- -
-
-Input: 2.00000, 10
-
-Output: 1024.00000
-
-
- -

Example 2:

- -
-
-Input: 2.10000, 3
-
-Output: 9.26100
-
-
- -

Example 3:

- -
-
-Input: 2.00000, -2
-
-Output: 0.25000
-
-Explanation: 2-2 = 1/22 = 1/4 = 0.25
-
-
- -

Note:

- -
    -
  • -100.0 < x < 100.0
  • -
  • n is a 32-bit signed integer, within the range [−231, 231 − 1]
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.js b/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.js deleted file mode 100644 index 8a4a7dad..00000000 --- a/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {number} x - * @param {number} n - * @return {number} - */ -var myPow = function (x, n) { - if (n == 0) return 1; - if (n < 0) { - n = -n; - x = 1 / x; - } - return n % 2 == 0 - ? Math.pow(x * x, parseInt(n / 2)) - : x * Math.pow(x * x, parseInt(n / 2)); -}; diff --git a/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.py b/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.py deleted file mode 100644 index f59be290..00000000 --- a/leetcode/solution/0000-0099/0050.Pow(x, n)/Solution.py +++ /dev/null @@ -1,21 +0,0 @@ -class Solution: - def myPow(self, x: float, n: int) -> float: - - """ - :type x: float - :type n: int - :rtype: float - """ - - answer = 1 - if x == 1 or n == 0: - return 1 - if x == -1: - return 1 if n%2 == 0 else -1 - - for i in range(abs(n)): - answer *= x - if (abs(answer) < 10 ** -5 and n > 0) or (abs(answer) > 10 ** 5 and n < 0): - return 0 - - return answer if n > 0 else 1/answer diff --git a/leetcode/solution/0000-0099/0051.N-Queens/README_EN.md b/leetcode/solution/0000-0099/0051.N-Queens/README_EN.md deleted file mode 100644 index 93cd62a3..00000000 --- a/leetcode/solution/0000-0099/0051.N-Queens/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [51. N-Queens](https://leetcode.com/problems/n-queens) - -[中文文档](/solution/0000-0099/0051.N-Queens/README.md) - -## Description - -

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

- -![](./images/8-queens.png) - -

Given an integer n, return all distinct solutions to the n-queens puzzle.

- -

Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively.

- -

Example:

- -
-
-Input: 4
-
-Output: [
-
- [".Q..",  // Solution 1
-
-  "...Q",
-
-  "Q...",
-
-  "..Q."],
-
-
-
- ["..Q.",  // Solution 2
-
-  "Q...",
-
-  "...Q",
-
-  ".Q.."]
-
-]
-
-Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0051.N-Queens/Solution.cs b/leetcode/solution/0000-0099/0051.N-Queens/Solution.cs deleted file mode 100644 index fb8a710a..00000000 --- a/leetcode/solution/0000-0099/0051.N-Queens/Solution.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; -using System.Text; - -public class Solution { - private IList> results = new List>(); - private int n; - - public IList> SolveNQueens(int n) { - this.n = n; - Search(new List(), 0, 0, 0); - return results; - } - - private void Search(IList state, int left, int right, int vertical) - { - if (state.Count == n) - { - Print(state); - return; - } - int available = ~(left | right | vertical) & ((1 << n) - 1); - while (available != 0) - { - int x = available & -available; - state.Add(x); - Search(state, (left | x ) << 1, (right | x ) >> 1, vertical | x); - state.RemoveAt(state.Count - 1); - available &= ~x; - } - } - - private void Print(IList state) - { - var result = new List(); - var sb = new StringBuilder(n); - foreach (var s in state) - { - var x = s; - for (var i = 0; i < n; ++i) - { - sb.Append((x & 1) != 0 ? 'Q': '.'); - x >>= 1; - } - result.Add(sb.ToString()); - sb.Clear(); - } - results.Add(result); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0052.N-Queens II/README_EN.md b/leetcode/solution/0000-0099/0052.N-Queens II/README_EN.md deleted file mode 100644 index 55ea9c2c..00000000 --- a/leetcode/solution/0000-0099/0052.N-Queens II/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [52. N-Queens II](https://leetcode.com/problems/n-queens-ii) - -[中文文档](/solution/0000-0099/0052.N-Queens%20II/README.md) - -## Description - -

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.

- -![](./images/8-queens.png) - -

Given an integer n, return the number of distinct solutions to the n-queens puzzle.

- -

Example:

- -
-
-Input: 4
-
-Output: 2
-
-Explanation: There are two distinct solutions to the 4-queens puzzle as shown below.
-
-[
-
- [".Q..",  // Solution 1
-
-  "...Q",
-
-  "Q...",
-
-  "..Q."],
-
-
-
- ["..Q.",  // Solution 2
-
-  "Q...",
-
-  "...Q",
-
-  ".Q.."]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0053.Maximum Subarray/README_EN.md b/leetcode/solution/0000-0099/0053.Maximum Subarray/README_EN.md deleted file mode 100644 index 4a7b0465..00000000 --- a/leetcode/solution/0000-0099/0053.Maximum Subarray/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [53. Maximum Subarray](https://leetcode.com/problems/maximum-subarray) - -[中文文档](/solution/0000-0099/0053.Maximum%20Subarray/README.md) - -## Description - -

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

- -

Example:

- -
-
-Input: [-2,1,-3,4,-1,2,1,-5,4],
-
-Output: 6
-
-Explanation: [4,-1,2,1] has the largest sum = 6.
-
-
- -

Follow up:

- -

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxSubArray(self, nums: List[int]) -> int: - n = len(nums) - res = f = nums[0] - for i in range(1, n): - f = nums[i] + max(f, 0) - res = max(res, f) - return res -``` - -### **Java** - -```java -class Solution { - public int maxSubArray(int[] nums) { - int f = nums[0], res = nums[0]; - for (int i = 1, n = nums.length; i < n; ++i) { - f = nums[i] + Math.max(f, 0); - res = Math.max(res, f); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.cpp b/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.cpp deleted file mode 100644 index 588e58ac..00000000 --- a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * @lc app=leetcode.cn id=53 lang=cpp - * - * [53] 最大子序和 - * - * https://leetcode-cn.com/problems/maximum-subarray/description/ - * - * algorithms - * Easy (46.59%) - * Likes: 2144 - * Dislikes: 0 - * Total Accepted: 270.6K - * Total Submissions: 524.4K - * Testcase Example: '[-2,1,-3,4,-1,2,1,-5,4]' - * - * 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 - * - * 示例: - * - * 输入: [-2,1,-3,4,-1,2,1,-5,4], - * 输出: 6 - * 解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。 - * - * - * 进阶: - * - * 如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。 - * - */ - -#include - -using std::vector; - -// 贪心 -class Solution0 { - public: - int maxSubArray(vector& nums) { - if (nums.size() == 0) { - return 0; - } - int result = nums[0]; - int temp = nums[0]; - for (int i = 1; i < nums.size(); i++) { - if (temp >= 0) { - temp += nums[i]; - } else { - temp = nums[i]; - } - result = std::max(result, temp); - } - return result; - } -}; - -// @lc code=start -// 动态规划 -class Solution { - public: - int maxSubArray(vector& nums) { - if (nums.size() == 0) { - return 0; - } - vector dp = vector(nums.size()); - dp[0] = nums[0]; - int result = nums[0]; - for (int i = 1; i < nums.size(); i++) { - dp[i] = std::max(dp[i - 1] + nums[i], nums[i]); - result = std::max(dp[i], result); - } - return result; - } -}; -// @lc code=end diff --git a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.go b/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.go deleted file mode 100644 index 1b4833ab..00000000 --- a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.go +++ /dev/null @@ -1,15 +0,0 @@ -func maxSubArray(nums []int) int { - ans := nums[0] - sum := 0 - for _, n := range nums { - if sum > 0 { - sum += n - } else { - sum = n - } - if sum > ans { - ans = sum - } - } - return ans -} diff --git a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.js b/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.js deleted file mode 100644 index 3225c463..00000000 --- a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.js +++ /dev/null @@ -1,10 +0,0 @@ -const maxSubArray = function (nums) { - if (nums.length === 0) return 0; - let ans = nums[0], - tmp = nums[0]; - for (let i = 1; i < nums.length; i++) { - tmp = Math.max(tmp + nums[i], nums[i]); - ans = Math.max(ans, tmp); - } - return ans; -}; diff --git a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.py b/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.py deleted file mode 100644 index a2c4b9ea..00000000 --- a/leetcode/solution/0000-0099/0053.Maximum Subarray/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def maxSubArray(self, nums: List[int]) -> int: - n = len(nums) - res = f = nums[0] - for i in range(1, n): - f = nums[i] + max(f, 0) - res = max(res, f) - return res diff --git a/leetcode/solution/0000-0099/0054.Spiral Matrix/README_EN.md b/leetcode/solution/0000-0099/0054.Spiral Matrix/README_EN.md deleted file mode 100644 index 8c265b34..00000000 --- a/leetcode/solution/0000-0099/0054.Spiral Matrix/README_EN.md +++ /dev/null @@ -1,133 +0,0 @@ -# [54. Spiral Matrix](https://leetcode.com/problems/spiral-matrix) - -[中文文档](/solution/0000-0099/0054.Spiral%20Matrix/README.md) - -## Description - -

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

- -

Example 1:

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

Example 2:

- -
-
-Input:
-
-[
-
-  [1, 2, 3, 4],
-
-  [5, 6, 7, 8],
-
-  [9,10,11,12]
-
-]
-
-Output: [1,2,3,4,8,12,11,10,9,5,6,7]
-
-
- -**Constraints:** - -- m == matrix.length -- n == matrix[i].length -- 1 <= m, n <= 10 -- -100 <= matrix[i][j] <= 100 - -## Solutions - - - -### **Python3** - -```python -class Solution: - def spiralOrder(self, matrix: List[List[int]]) -> List[int]: - def add(i1, j1, i2, j2): - if i1 == i2: - return [matrix[i1][j] for j in range(j1, j2 + 1)] - if j1 == j2: - return [matrix[i][j1] for i in range(i1, i2 + 1)] - return [matrix[i1][j] for j in range(j1, j2)] + [matrix[i][j2] for i in range(i1, i2)] + [matrix[i2][j] for j in range(j2, j1, -1)] + [matrix[i][j1] for i in range(i2, i1, -1)] - - m, n = len(matrix), len(matrix[0]) - i1, j1, i2, j2 = 0, 0, m - 1, n - 1 - res = [] - while i1 <= i2 and j1 <= j2: - res += add(i1, j1, i2, j2) - i1, j1, i2, j2 = i1 + 1, j1 + 1, i2 - 1, j2 - 1 - return res -``` - -### **Java** - -```java -class Solution { - private List res; - - public List spiralOrder(int[][] matrix) { - int m = matrix.length, n = matrix[0].length; - res = new ArrayList<>(); - int i1 = 0, i2 = m - 1; - int j1 = 0, j2 = n - 1; - while (i1 <= i2 && j1 <= j2) { - add(matrix, i1++, j1++, i2--, j2--); - } - return res; - } - - private void add(int[][] matrix, int i1, int j1, int i2, int j2) { - if (i1 == i2) { - for (int j = j1; j <= j2; ++j) { - res.add(matrix[i1][j]); - } - return; - } - if (j1 == j2) { - for (int i = i1; i <= i2; ++i) { - res.add(matrix[i][j1]); - } - return; - } - for (int j = j1; j < j2; ++j) { - res.add(matrix[i1][j]); - } - for (int i = i1; i < i2; ++i) { - res.add(matrix[i][j2]); - } - for (int j = j2; j > j1; --j) { - res.add(matrix[i2][j]); - } - for (int i = i2; i > i1; --i) { - res.add(matrix[i][j1]); - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cpp b/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cpp deleted file mode 100644 index fd96d822..00000000 --- a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cpp +++ /dev/null @@ -1,51 +0,0 @@ -class Solution { -public: - vector spiralOrder(vector>& matrix) { - int row=matrix.size(); - if(row==0) - { - vector zero; - zero.clear(); - return zero; - } - int col=matrix[0].size(); - if(row==1) - return matrix[0]; - if(col==0) - { - vector zero; - zero.clear(); - return zero; - } - if(col==1) - { - vector temp; - for(int i=0;i result; - result=matrix[0];//result存储第一行 - //temp=matirx.pop_back(); - for(int i=1;i zz(matrix[row-i-1].begin()+1,matrix[row-i-1].end()-1);//将中间行去除第一个和最后一个数 - matrix[row-i-1]=zz; - } - vector> m2(matrix.begin()+1,matrix.end()-1);//将matrix去除第一行和最后一行,递归调用 - //cout< l=spiralOrder(m2); - result.insert(result.end(),l.begin(),l.end());//将递归结果插入result后面 - return result; - - } -}; diff --git a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cs b/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cs deleted file mode 100644 index 66d3ce41..00000000 --- a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - public IList SpiralOrder(int[][] matrix) { - var lenI = matrix.Length; - var lenJ = lenI == 0 ? 0 : matrix[0].Length; - var result = new List(lenI * lenJ); - var rounds = (Math.Min(lenI, lenJ) + 1) / 2; - for (var r = 0; r < rounds; ++r) - { - if (lenI - r * 2 == 1) - { - for (var j = r; j < lenJ - r; ++j) - { - result.Add(matrix[r][j]); - } - } - else if (lenJ - r * 2 == 1) - { - for (var i = r; i < lenI - r; ++i) - { - result.Add(matrix[i][r]); - } - } - else - { - for (var j = r; j < lenJ - r - 1; ++j) - { - result.Add(matrix[r][j]); - } - for (var i = r; i < lenI - r - 1; ++i) - { - result.Add(matrix[i][lenJ - r - 1]); - } - for (var j = lenJ - r - 1; j > r; --j) - { - result.Add(matrix[lenI - r - 1][j]); - } - for (var i = lenI - r - 1; i > r; --i) - { - result.Add(matrix[i][r]); - } - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.py b/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.py deleted file mode 100644 index e04f2652..00000000 --- a/leetcode/solution/0000-0099/0054.Spiral Matrix/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -class Solution: - def spiralOrder(self, matrix: List[List[int]]) -> List[int]: - def add(i1, j1, i2, j2): - if i1 == i2: - return [matrix[i1][j] for j in range(j1, j2 + 1)] - if j1 == j2: - return [matrix[i][j1] for i in range(i1, i2 + 1)] - return [matrix[i1][j] for j in range(j1, j2)] + [matrix[i][j2] for i in range(i1, i2)] + [matrix[i2][j] for j in range(j2, j1, -1)] + [matrix[i][j1] for i in range(i2, i1, -1)] - - m, n = len(matrix), len(matrix[0]) - i1, j1, i2, j2 = 0, 0, m - 1, n - 1 - res = [] - while i1 <= i2 and j1 <= j2: - res += add(i1, j1, i2, j2) - i1, j1, i2, j2 = i1 + 1, j1 + 1, i2 - 1, j2 - 1 - return res diff --git a/leetcode/solution/0000-0099/0055.Jump Game/README_EN.md b/leetcode/solution/0000-0099/0055.Jump Game/README_EN.md deleted file mode 100644 index 1ff3569b..00000000 --- a/leetcode/solution/0000-0099/0055.Jump Game/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [55. Jump Game](https://leetcode.com/problems/jump-game) - -[中文文档](/solution/0000-0099/0055.Jump%20Game/README.md) - -## Description - -

Given an array of non-negative integers, you are initially positioned at the first index of the array.

- -

Each element in the array represents your maximum jump length at that position.

- -

Determine if you are able to reach the last index.

- -

Example 1:

- -
-
-Input: [2,3,1,1,4]
-
-Output: true
-
-Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
-
-
- -

Example 2:

- -
-
-Input: [3,2,1,0,4]
-
-Output: false
-
-Explanation: You will always arrive at index 3 no matter what. Its maximum
-
-             jump length is 0, which makes it impossible to reach the last index.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0055.Jump Game/Solution.cs b/leetcode/solution/0000-0099/0055.Jump Game/Solution.cs deleted file mode 100644 index 6d91e1e7..00000000 --- a/leetcode/solution/0000-0099/0055.Jump Game/Solution.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -public class Solution { - public bool CanJump(int[] nums) { - var maxJump = 0; - for (var i = 0; i < nums.Length; ++i) - { - if (i <= maxJump) - { - maxJump = Math.Max(maxJump, i + nums[i]); - } - else - { - return false; - } - } - return true; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0056.Merge Intervals/README_EN.md b/leetcode/solution/0000-0099/0056.Merge Intervals/README_EN.md deleted file mode 100644 index a623ce44..00000000 --- a/leetcode/solution/0000-0099/0056.Merge Intervals/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [56. Merge Intervals](https://leetcode.com/problems/merge-intervals) - -[中文文档](/solution/0000-0099/0056.Merge%20Intervals/README.md) - -## Description - -

Given a collection of intervals, merge all overlapping intervals.

- -

Example 1:

- -
-
-Input: [[1,3],[2,6],[8,10],[15,18]]
-
-Output: [[1,6],[8,10],[15,18]]
-
-Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
-
-
- -

Example 2:

- -
-
-Input: [[1,4],[4,5]]
-
-Output: [[1,5]]
-
-Explanation: Intervals [1,4] and [4,5] are considered overlapping.
- -

NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cpp b/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cpp deleted file mode 100644 index 4b9fb7a7..00000000 --- a/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Definition for an interval. - * struct Interval { - * int start; - * int end; - * Interval() : start(0), end(0) {} - * Interval(int s, int e) : start(s), end(e) {} - * }; - */ -bool cmp(Interval &val1,Interval &val2){ - return !(val1.start >= val2.start); -} - -class Solution { -public: - vector merge(vector& intervals) { - - int len = intervals.size(); - if(len <= 1)return intervals; - - sort(intervals.begin(),intervals.end(),cmp); - - vector ans; - ans.push_back(intervals[0]); - - for(int i = 1;i= intervals[i].start){ - ans.back().end = max(ans.back().end,intervals[i].end); - } - else{ - ans.push_back(intervals[i]); - } - } - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cs b/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cs deleted file mode 100644 index 685b8b56..00000000 --- a/leetcode/solution/0000-0099/0056.Merge Intervals/Solution.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public int[][] Merge(int[][] intervals) { - var result = new List(); - foreach (var interval in intervals.OrderBy(i => i[0])) - { - if (!result.Any()) - { - result.Add(interval); - } - else - { - var last = result.Last(); - if (last[1] < interval[0]) - { - result.Add(interval); - } - else if (last[1] < interval[1]) - { - last[1] = interval[1]; - } - } - } - return result.ToArray(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0057.Insert Interval/README_EN.md b/leetcode/solution/0000-0099/0057.Insert Interval/README_EN.md deleted file mode 100644 index 8c90b2af..00000000 --- a/leetcode/solution/0000-0099/0057.Insert Interval/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [57. Insert Interval](https://leetcode.com/problems/insert-interval) - -[中文文档](/solution/0000-0099/0057.Insert%20Interval/README.md) - -## Description - -

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

- -

You may assume that the intervals were initially sorted according to their start times.

- -

Example 1:

- -
-
-Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
-
-Output: [[1,5],[6,9]]
-
-
- -

Example 2:

- -
-
-Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
-
-Output: [[1,2],[3,10],[12,16]]
-
-Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
- -

NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cpp b/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cpp deleted file mode 100644 index f37571cf..00000000 --- a/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cpp +++ /dev/null @@ -1,32 +0,0 @@ -bool cmp(Interval &val1,Interval &val2){ - return val1.start < val2.start; -} - -class Solution { -public: - vector insert(vector& intervals, Interval newInterval) { - //先插进去,重复56题 - - intervals.push_back(newInterval); - - int len = intervals.size(); - if(len <= 1)return intervals; - - sort(intervals.begin(),intervals.end(),cmp); - - vector ans; - - ans.push_back(intervals[0]); - - for(int i = 1;i= intervals[i].start){ - ans.back().end = max(ans.back().end,intervals[i].end); - } - else{ - ans.push_back(intervals[i]); - } - } - - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cs b/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cs deleted file mode 100644 index 7a01f74e..00000000 --- a/leetcode/solution/0000-0099/0057.Insert Interval/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - public int[][] Insert(int[][] intervals, int[] newInterval) { - var result = new List(); - var i = 0; - - while (i < intervals.Length && intervals[i][1] < newInterval[0]) - { - result.Add(intervals[i++]); - } - - while (i < intervals.Length && intervals[i][0] <= newInterval[1] && intervals[i][1] >= newInterval[0]) - { - newInterval[0] = Math.Min(intervals[i][0], newInterval[0]); - newInterval[1] = Math.Max(intervals[i][1], newInterval[1]); - ++i; - } - result.Add(newInterval); - - while (i < intervals.Length) - { - result.Add(intervals[i++]); - } - - return result.ToArray(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0058.Length of Last Word/README_EN.md b/leetcode/solution/0000-0099/0058.Length of Last Word/README_EN.md deleted file mode 100644 index 1c8fe660..00000000 --- a/leetcode/solution/0000-0099/0058.Length of Last Word/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [58. Length of Last Word](https://leetcode.com/problems/length-of-last-word) - -[中文文档](/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md) - -## Description - -

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

- -

If the last word does not exist, return 0.

- -

Note: A word is defined as a maximal substring consisting of non-space characters only.

- -

Example:

- -
-Input: "Hello World"
-Output: 5
-
- -

 

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def lengthOfLastWord(self, s: str) -> int: - last_word_length = 0 - meet_word = False - for i in range(len(s) - 1, -1, -1): - ch = ord(s[i]) - if ch >= 65 and ch <= 122: - meet_word = True - last_word_length += 1 - elif meet_word: - break - return last_word_length -``` - -### **Java** - -```java -class Solution { - public int lengthOfLastWord(String s) { - int n = s.length(); - int lastWordLength = 0; - boolean meetWord = false; - for (int i = n - 1; i >= 0; --i) { - char ch = s.charAt(i); - if (ch >= 'A' && ch <= 'z') { - meetWord = true; - ++lastWordLength; - } else if (meetWord) { - break; - } - } - return lastWordLength; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.go b/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.go deleted file mode 100644 index 9fad11e9..00000000 --- a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.go +++ /dev/null @@ -1,18 +0,0 @@ -func lengthOfLastWord(s string) int { - if len(s) == 0 { - return 0 - } - space := []byte(" ")[0] - for len(s) != 0 && s[len(s)-1] == space { - s = s[:len(s)-1] - } - ret := 0 - for i := len(s) - 1; i >= 0; i-- { - if s[i] != space { - ret++ - } else { - return ret - } - } - return ret -} diff --git a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.js b/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.js deleted file mode 100644 index 348d2344..00000000 --- a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.js +++ /dev/null @@ -1,16 +0,0 @@ -var lengthOfLastWord = function (s) { - s = s.trim(); - return s.length - s.lastIndexOf(" ") - 1; -}; - -var lengthOfLastWord2 = function (s) { - let res = 0; - for (let i = 0; i < s.length; i++) { - if (s[i] !== " " && (i === 0 || s[i - 1] === " ")) { - res = 1; - } else if (s[i] !== " ") { - res++; - } - } - return res; -}; diff --git a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.py b/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.py deleted file mode 100644 index 37b97e24..00000000 --- a/leetcode/solution/0000-0099/0058.Length of Last Word/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def lengthOfLastWord(self, s: str) -> int: - last_word_length = 0 - meet_word = False - for i in range(len(s) - 1, -1, -1): - ch = ord(s[i]) - if ch >= 65 and ch <= 122: - meet_word = True - last_word_length += 1 - elif meet_word: - break - return last_word_length diff --git a/leetcode/solution/0000-0099/0059.Spiral Matrix II/README_EN.md b/leetcode/solution/0000-0099/0059.Spiral Matrix II/README_EN.md deleted file mode 100644 index f331f4bc..00000000 --- a/leetcode/solution/0000-0099/0059.Spiral Matrix II/README_EN.md +++ /dev/null @@ -1,133 +0,0 @@ -# [59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) - -[中文文档](/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md) - -## Description - -

Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

- -

Example:

- -
-
-Input: 3
-
-Output:
-
-[
-
- [ 1, 2, 3 ],
-
- [ 8, 9, 4 ],
-
- [ 7, 6, 5 ]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def generateMatrix(self, n: int) -> List[List[int]]: - res = [[0] * n for _ in range(n)] - num = 1 - m1, m2 = 0, n - 1 - while m1 < m2: - for j in range(m1, m2): - res[m1][j] = num - num += 1 - for i in range(m1, m2): - res[i][m2] = num - num += 1 - for j in range(m2, m1, -1): - res[m2][j] = num - num += 1 - for i in range(m2, m1, -1): - res[i][m1] = num - num += 1 - m1 += 1 - m2 -= 1 - if m1 == m2: - res[m1][m1] = num - return res -``` - -### **Java** - -```java -class Solution { - public int[][] generateMatrix(int n) { - int[][] res = new int[n][n]; - int num = 1; - int m1 = 0, m2 = n - 1; - while (m1 < m2) { - for (int j = m1; j < m2; ++j) { - res[m1][j] = num++; - } - for (int i = m1; i < m2; ++i) { - res[i][m2] = num++; - } - for (int j = m2; j > m1; --j) { - res[m2][j] = num++; - } - for (int i = m2; i > m1; --i) { - res[i][m1] = num++; - } - ++m1; - --m2; - } - if (m1 == m2) { - res[m1][m1] = num; - } - - return res; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - vector> generateMatrix(int n) { - vector> res(n, vector(n, 0)); - int num = 1; - int m1 = 0, m2 = n - 1; - while (m1 < m2) { - for (int j = m1; j < m2; ++j) { - res[m1][j] = num++; - } - for (int i = m1; i < m2; ++i) { - res[i][m2] = num++; - } - for (int j = m2; j > m1; --j) { - res[m2][j] = num++; - } - for (int i = m2; i > m1; --i) { - res[i][m1] = num++; - } - ++m1; - --m2; - } - if (m1 == m2) { - res[m1][m1] = num; - } - return res; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.cpp b/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.cpp deleted file mode 100644 index 1368f2a9..00000000 --- a/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.cpp +++ /dev/null @@ -1,28 +0,0 @@ -class Solution { -public: - vector> generateMatrix(int n) { - vector> res(n, vector(n, 0)); - int num = 1; - int m1 = 0, m2 = n - 1; - while (m1 < m2) { - for (int j = m1; j < m2; ++j) { - res[m1][j] = num++; - } - for (int i = m1; i < m2; ++i) { - res[i][m2] = num++; - } - for (int j = m2; j > m1; --j) { - res[m2][j] = num++; - } - for (int i = m2; i > m1; --i) { - res[i][m1] = num++; - } - ++m1; - --m2; - } - if (m1 == m2) { - res[m1][m1] = num; - } - return res; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.py b/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.py deleted file mode 100644 index 1f1905da..00000000 --- a/leetcode/solution/0000-0099/0059.Spiral Matrix II/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -class Solution: - def generateMatrix(self, n: int) -> List[List[int]]: - res = [[0] * n for _ in range(n)] - num = 1 - m1, m2 = 0, n - 1 - while m1 < m2: - for j in range(m1, m2): - res[m1][j] = num - num += 1 - for i in range(m1, m2): - res[i][m2] = num - num += 1 - for j in range(m2, m1, -1): - res[m2][j] = num - num += 1 - for i in range(m2, m1, -1): - res[i][m1] = num - num += 1 - m1 += 1 - m2 -= 1 - if m1 == m2: - res[m1][m1] = num - return res diff --git a/leetcode/solution/0000-0099/0060.Permutation Sequence/README_EN.md b/leetcode/solution/0000-0099/0060.Permutation Sequence/README_EN.md deleted file mode 100644 index cce4dbc7..00000000 --- a/leetcode/solution/0000-0099/0060.Permutation Sequence/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [60. Permutation Sequence](https://leetcode.com/problems/permutation-sequence) - -[中文文档](/solution/0000-0099/0060.Permutation%20Sequence/README.md) - -## Description - -

The set [1,2,3,...,n] contains a total of n! unique permutations.

- -

By listing and labeling all of the permutations in order, we get the following sequence for n = 3:

- -
    -
  1. "123"
  2. -
  3. "132"
  4. -
  5. "213"
  6. -
  7. "231"
  8. -
  9. "312"
  10. -
  11. "321"
  12. -
- -

Given n and k, return the kth permutation sequence.

- -

Note:

- -
    -
  • Given n will be between 1 and 9 inclusive.
  • -
  • Given k will be between 1 and n! inclusive.
  • -
- -

Example 1:

- -
-
-Input: n = 3, k = 3
-
-Output: "213"
-
-
- -

Example 2:

- -
-
-Input: n = 4, k = 9
-
-Output: "2314"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0060.Permutation Sequence/Solution.cs b/leetcode/solution/0000-0099/0060.Permutation Sequence/Solution.cs deleted file mode 100644 index 5446c2c0..00000000 --- a/leetcode/solution/0000-0099/0060.Permutation Sequence/Solution.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; - -public class Solution { - public string GetPermutation(int n, int k) { - --k; - var factorial = Enumerable.Range(0, n).Select(i => Enumerable.Range(1, i).Aggregate(1, (agg, x) => agg * x)).ToArray(); - var numbers = new SortedSet(Enumerable.Range(1, n)); - var sb = new StringBuilder(); - while (sb.Length < n) - { - var f = factorial[numbers.Count - 1]; - var index = k / f; - var number = numbers.ElementAt(index); - sb.Append(number); - numbers.Remove(number); - k %= f; - } - return sb.ToString(); - } -} diff --git a/leetcode/solution/0000-0099/0061.Rotate List/README_EN.md b/leetcode/solution/0000-0099/0061.Rotate List/README_EN.md deleted file mode 100644 index d49f8d3b..00000000 --- a/leetcode/solution/0000-0099/0061.Rotate List/README_EN.md +++ /dev/null @@ -1,128 +0,0 @@ -# [61. Rotate List](https://leetcode.com/problems/rotate-list) - -[中文文档](/solution/0000-0099/0061.Rotate%20List/README.md) - -## Description - -

Given a linked list, rotate the list to the right by k places, where k is non-negative.

- -

Example 1:

- -
-
-Input: 1->2->3->4->5->NULL, k = 2
-
-Output: 4->5->1->2->3->NULL
-
-Explanation:
-
-rotate 1 steps to the right: 5->1->2->3->4->NULL
-
-rotate 2 steps to the right: 4->5->1->2->3->NULL
-
-
- -

Example 2:

- -
-
-Input: 0->1->2->NULL, k = 4
-
-Output: 2->0->1->NULL
-
-Explanation:
-
-rotate 1 steps to the right: 2->0->1->NULL
-
-rotate 2 steps to the right: 1->2->0->NULL
-
-rotate 3 steps to the right: 0->1->2->NULL
-
-rotate 4 steps to the right: 2->0->1->NULL
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def rotateRight(self, head: ListNode, k: int) -> ListNode: - if head is None or head.next is None or k == 0: - return head - n = 0 - cur = head - while cur: - n += 1 - cur = cur.next - k %= n - if k == 0: - return head - p = q = head - for i in range(k): - q = q.next - while q.next: - p, q = p.next, q.next - start = p.next - p.next = None - q.next = head - return start -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode rotateRight(ListNode head, int k) { - if (head == null || head.next == null) { - return head; - } - int n = 0; - ListNode cur = head; - while (cur != null) { - ++n; - cur = cur.next; - } - k %= n; - if (k == 0) { - return head; - } - ListNode p = head, q = head; - for (int i = 0; i < k; ++i) { - q = q.next; - } - while (q.next != null) { - p = p.next; - q = q.next; - } - ListNode start = p.next; - p.next = null; - q.next = head; - return start; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0061.Rotate List/Solution.cs b/leetcode/solution/0000-0099/0061.Rotate List/Solution.cs deleted file mode 100644 index 61a01fbe..00000000 --- a/leetcode/solution/0000-0099/0061.Rotate List/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -public class Solution { - public ListNode RotateRight(ListNode head, int k) { - var length = 0; - var temp = head; - var last = head; - while (temp != null) - { - ++length; - last = temp; - temp = temp.next; - } - if (length == 0) return null; - - k %= length; - if (k == 0) return head; - k = length - k; - - ListNode kNode = head; - for (var i = 1; i < k; ++i) - { - kNode = kNode.next; - } - - last.next = head; - head = kNode.next; - kNode.next = null; - return head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0061.Rotate List/Solution.py b/leetcode/solution/0000-0099/0061.Rotate List/Solution.py deleted file mode 100644 index 7995d1da..00000000 --- a/leetcode/solution/0000-0099/0061.Rotate List/Solution.py +++ /dev/null @@ -1,26 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def rotateRight(self, head: ListNode, k: int) -> ListNode: - if head is None or head.next is None or k == 0: - return head - n = 0 - cur = head - while cur: - n += 1 - cur = cur.next - k %= n - if k == 0: - return head - p = q = head - for i in range(k): - q = q.next - while q.next: - p, q = p.next, q.next - start = p.next - p.next = None - q.next = head - return start diff --git a/leetcode/solution/0000-0099/0062.Unique Paths/README_EN.md b/leetcode/solution/0000-0099/0062.Unique Paths/README_EN.md deleted file mode 100644 index 77e40266..00000000 --- a/leetcode/solution/0000-0099/0062.Unique Paths/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [62. Unique Paths](https://leetcode.com/problems/unique-paths) - -[中文文档](/solution/0000-0099/0062.Unique%20Paths/README.md) - -## Description - -

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

- -

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

- -

How many possible unique paths are there?

- -![](./images/robot_maze.png) - -Above is a 7 x 3 grid. How many possible unique paths are there?

- -

 

-

Example 1:

- -
-Input: m = 3, n = 2
-Output: 3
-Explanation:
-From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
-1. Right -> Right -> Down
-2. Right -> Down -> Right
-3. Down -> Right -> Right
-
- -

Example 2:

- -
-Input: m = 7, n = 3
-Output: 28
-
- -

 

-

Constraints:

- -
    -
  • 1 <= m, n <= 100
  • -
  • It's guaranteed that the answer will be less than or equal to 2 * 10 ^ 9.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0062.Unique Paths/Solution.cpp b/leetcode/solution/0000-0099/0062.Unique Paths/Solution.cpp deleted file mode 100644 index d17eb627..00000000 --- a/leetcode/solution/0000-0099/0062.Unique Paths/Solution.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - int uniquePaths(int m, int n) { - if(m<=0||n<=0) - return 0; - if(m==1||n==1) - return 1; - int arr[m][n]={0}; - arr[0][0]=1; - for(int i=1;iA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

- -

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

- -

Now consider if some obstacles are added to the grids. How many unique paths would there be?

- -![](./images/robot_maze.png) - -

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

- -

Note: m and n will be at most 100.

- -

Example 1:

- -
-
-Input:
-
-[
-
-  [0,0,0],
-
-  [0,1,0],
-
-  [0,0,0]
-
-]
-
-Output: 2
-
-Explanation:
-
-There is one obstacle in the middle of the 3x3 grid above.
-
-There are two ways to reach the bottom-right corner:
-
-1. Right -> Right -> Down -> Down
-
-2. Down -> Down -> Right -> Right
-
-
- -## Solutions - -### **Go** - -```go -func uniquePathsWithObstacles(obstacleGrid [][]int) int { - m,n := len(obstacleGrid),len(obstacleGrid[0]) - dp := make([][]int,m) - for i:=0; i < m;i++ { - dp[i] = make([]int,n) - } - for i := 0; i < m; i++ { - for j := 0; j < n; j++ { - if obstacleGrid[i][j] == 0 { - if i == 0 && j == 0 { - dp[i][j] = 1 - } else if i > 0 && j >0 { - dp[i][j] = dp[i][j-1]+dp[i-1][j] - } else if i > 0 { - dp[i][j] = dp[i-1][j] - } else { - dp[i][j] = dp[i][j-1] - } - } - } - } - return dp[m-1][n-1] -} -``` - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.go b/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.go deleted file mode 100644 index 1089ae4e..00000000 --- a/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.go +++ /dev/null @@ -1,23 +0,0 @@ -func uniquePathsWithObstacles(obstacleGrid [][]int) int { - m,n := len(obstacleGrid),len(obstacleGrid[0]) - dp := make([][]int,m) - for i:=0; i < m;i++ { - dp[i] = make([]int,n) - } - for i := 0; i < m; i++ { - for j := 0; j < n; j++ { - if obstacleGrid[i][j] == 0 { - if i == 0 && j == 0 { - dp[i][j] = 1 - } else if i > 0 && j >0 { - dp[i][j] = dp[i][j-1]+dp[i-1][j] - } else if i > 0 { - dp[i][j] = dp[i-1][j] - } else { - dp[i][j] = dp[i][j-1] - } - } - } - } - return dp[m-1][n-1] -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.py b/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.py deleted file mode 100644 index 1a007d3f..00000000 --- a/leetcode/solution/0000-0099/0063.Unique Paths II/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -class Solution(object): - def uniquePathsWithObstacles(self, obstacleGrid): - """ - :type obstacleGrid: List[List[int]] - :rtype: int - """ - m, n = len(obstacleGrid), len(obstacleGrid[0]) - martix = [[0] * n] * m - for i in range(m): - for j in range(n): - if obstacleGrid[i][j] == 1: - martix[i][j] = 0 - else: - if i == 0 and j == 0: - martix[i][j] = 1 - elif i == 0: - martix[i][j] = martix[i][j - 1] - elif j == 0: - martix[i][j] = martix[i - 1][j] - else: - martix[i][j] = martix[i - 1][j] + martix[i][j - 1] - return martix[m - 1][n - 1] \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0064.Minimum Path Sum/README_EN.md b/leetcode/solution/0000-0099/0064.Minimum Path Sum/README_EN.md deleted file mode 100644 index 5bc409fd..00000000 --- a/leetcode/solution/0000-0099/0064.Minimum Path Sum/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [64. Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum) - -[中文文档](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md) - -## Description - -

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.

- -

Note: You can only move either down or right at any point in time.

- -

Example:

- -
-
-Input:
-
-[
-
-  [1,3,1],
-
-  [1,5,1],
-
-  [4,2,1]
-
-]
-
-Output: 7
-
-Explanation: Because the path 1→3→1→1→1 minimizes the sum.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0064.Minimum Path Sum/Solution.cpp b/leetcode/solution/0000-0099/0064.Minimum Path Sum/Solution.cpp deleted file mode 100644 index 619b9cc9..00000000 --- a/leetcode/solution/0000-0099/0064.Minimum Path Sum/Solution.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - int minPathSum(vector>& grid) { - int row = grid.size(); - if(row == 0)return 0; - int column = grid[0].size(); - - vector> path(row,vector(column,0)); - path[0][0] = grid[0][0]; - for(int i = 1 ; i < column ; i++)path[0][i] = path[0][i-1] + grid[0][i]; - for(int i = 1 ; i < row;i++)path[i][0] = path[i-1][0]+grid[i][0]; - - for(int i = 1;iValidate if a given string can be interpreted as a decimal number.

- -

Some examples:
- -"0" => true
- -" 0.1 " => true
- -"abc" => false
- -"1 a" => false
- -"2e10" => true
- -" -90e3   " => true
- -" 1e" => false
- -"e3" => false
- -" 6e-1" => true
- -" 99e2.5 " => false
- -"53.5e93" => true
- -" --6 " => false
- -"-+3" => false
- -"95a54e53" => false

- -

Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:

- -
    -
  • Numbers 0-9
  • -
  • Exponent - "e"
  • -
  • Positive/negative sign - "+"/"-"
  • -
  • Decimal point - "."
  • -
- -

Of course, the context of these characters also matters in the input.

- -

Update (2015-02-10):
- -The signature of the C++ function had been updated. If you still see your function signature accepts a const char \* argument, please click the reload button to reset your code definition.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0065.Valid Number/Solution.cs b/leetcode/solution/0000-0099/0065.Valid Number/Solution.cs deleted file mode 100644 index 04eb872a..00000000 --- a/leetcode/solution/0000-0099/0065.Valid Number/Solution.cs +++ /dev/null @@ -1,12 +0,0 @@ -// https://leetcode.com/problems/valid-number/ - -using System.Text.RegularExpressions; - -public partial class Solution -{ - private readonly Regex _isNumber_Regex = new Regex(@"^\s*[+-]?(\d+(\.\d*)?|\.\d+)([Ee][+-]?\d+)?\s*$"); - public bool IsNumber(string s) - { - return _isNumber_Regex.IsMatch(s); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0065.Valid Number/Solution.py b/leetcode/solution/0000-0099/0065.Valid Number/Solution.py deleted file mode 100644 index 2d0c1e35..00000000 --- a/leetcode/solution/0000-0099/0065.Valid Number/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def isNumber(self, s): - """ - :type s: str - :rtype: bool - """ - - NumberRE = "[\+\-]?((\d+\.?\d*|\d*\.?\d+)(e[\+\-]?\d+)?)" - - s = s.strip() - - Ans = re.match(NumberRE, s) - - if Ans and len(s) == Ans.regs[0][1] : - return True - - return False diff --git a/leetcode/solution/0000-0099/0066.Plus One/README_EN.md b/leetcode/solution/0000-0099/0066.Plus One/README_EN.md deleted file mode 100644 index 69f4587c..00000000 --- a/leetcode/solution/0000-0099/0066.Plus One/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [66. Plus One](https://leetcode.com/problems/plus-one) - -[中文文档](/solution/0000-0099/0066.Plus%20One/README.md) - -## Description - -

Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

- -

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

- -

You may assume the integer does not contain any leading zero, except the number 0 itself.

- -

Example 1:

- -
-
-Input: [1,2,3]
-
-Output: [1,2,4]
-
-Explanation: The array represents the integer 123.
-
-
- -

Example 2:

- -
-
-Input: [4,3,2,1]
-
-Output: [4,3,2,2]
-
-Explanation: The array represents the integer 4321.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0066.Plus One/Solution.cpp b/leetcode/solution/0000-0099/0066.Plus One/Solution.cpp deleted file mode 100644 index 17cf7338..00000000 --- a/leetcode/solution/0000-0099/0066.Plus One/Solution.cpp +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - vector plusOne(vector& digits) { - int len = digits.size(); - if(len == 0)return digits; - digits[len-1]++; - int num = digits[len - 1]; - for(int i = len - 1;i>=1;i--){ - digits[i-1] = digits[i-1] + digits[i]/10; - digits[i] %= 10; - } - - if(digits[0] >= 10){ - digits.insert(digits.begin(),digits[0]/10); - digits[1] = digits[1] % 10; - } - return digits; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0066.Plus One/Solution.go b/leetcode/solution/0000-0099/0066.Plus One/Solution.go deleted file mode 100644 index 87a9d19b..00000000 --- a/leetcode/solution/0000-0099/0066.Plus One/Solution.go +++ /dev/null @@ -1,11 +0,0 @@ -func plusOne(digits []int) []int { - for right := len(digits) - 1; right >= 0; right-- { - digits[right] = (digits[right] + 1) % 10 - if digits[right] != 0 { - return digits - } - } - ret := make([]int, len(digits)+1) - ret[0] = 1 - return ret -} diff --git a/leetcode/solution/0000-0099/0066.Plus One/Solution.js b/leetcode/solution/0000-0099/0066.Plus One/Solution.js deleted file mode 100644 index f72bcc36..00000000 --- a/leetcode/solution/0000-0099/0066.Plus One/Solution.js +++ /dev/null @@ -1,12 +0,0 @@ -const plusOne = function (digits) { - for (let i = digits.length - 1; i >= 0; i--) { - if (digits[i] === 9) { - digits[i] = 0; - } else { - digits[i] += 1; - return digits; - } - } - digits.unshift(1); - return digits; -}; diff --git a/leetcode/solution/0000-0099/0066.Plus One/Solution.py b/leetcode/solution/0000-0099/0066.Plus One/Solution.py deleted file mode 100644 index 9af96eca..00000000 --- a/leetcode/solution/0000-0099/0066.Plus One/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def plusOne(self, digits): - """ - :type digits: List[int] - :rtype: List[int] - """ - - i = len(digits)-1 - digits[i] += 1 - - while i > 0 and digits[i] > 9 : - digits[i] = 0 - i -= 1 - digits[i] += 1 - - if digits[0] > 9: - digits[0] = 0 - digits.insert(0, 1) - - return digits diff --git a/leetcode/solution/0000-0099/0067.Add Binary/README_EN.md b/leetcode/solution/0000-0099/0067.Add Binary/README_EN.md deleted file mode 100644 index 55da7917..00000000 --- a/leetcode/solution/0000-0099/0067.Add Binary/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [67. Add Binary](https://leetcode.com/problems/add-binary) - -[中文文档](/solution/0000-0099/0067.Add%20Binary/README.md) - -## Description - -

Given two binary strings, return their sum (also a binary string).

- -

The input strings are both non-empty and contains only characters 1 or 0.

- -

Example 1:

- -
-
-Input: a = "11", b = "1"
-
-Output: "100"
- -

Example 2:

- -
-
-Input: a = "1010", b = "1011"
-
-Output: "10101"
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0067.Add Binary/Solution.cs b/leetcode/solution/0000-0099/0067.Add Binary/Solution.cs deleted file mode 100644 index dffa1ce3..00000000 --- a/leetcode/solution/0000-0099/0067.Add Binary/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - public string AddBinary(string a, string b) { - var list = new List(Math.Max(a.Length, b.Length) + 1); - var i = a.Length - 1; - var j = b.Length - 1; - var carry = 0; - while (i >= 0 || j >= 0) - { - if (i >= 0) - { - carry += a[i] - '0'; - } - if (j >= 0) - { - carry += b[j] - '0'; - } - list.Add((char)((carry % 2) + '0')); - carry /= 2; - --i; - --j; - } - if (carry > 0) list.Add((char) (carry + '0')); - list.Reverse(); - return new string(list.ToArray()); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0067.Add Binary/Solution.go b/leetcode/solution/0000-0099/0067.Add Binary/Solution.go deleted file mode 100644 index 4f93ef94..00000000 --- a/leetcode/solution/0000-0099/0067.Add Binary/Solution.go +++ /dev/null @@ -1,24 +0,0 @@ -func addBinary(a string, b string) string { - for len(a) > len(b) { - b = "0" + b - } - for len(a) < len(b) { - a = "0" + a - } - zero := []byte("0")[0] - ret := make([]byte, len(a)) - for right := len(a) - 1; right > 0; right-- { - t := ret[right] + a[right] + b[right] - zero*2 - ret[right] = t%2 + zero - if t >= 2 { - ret[right-1] = 1 - } - } - t := ret[0] + a[0] + b[0] - zero*2 - ret[0] = t%2 + zero - if t >= 2 { - ret = append([]byte("1"), ret...) - } - - return string(ret) -} diff --git a/leetcode/solution/0000-0099/0068.Text Justification/README_EN.md b/leetcode/solution/0000-0099/0068.Text Justification/README_EN.md deleted file mode 100644 index dbc99a3f..00000000 --- a/leetcode/solution/0000-0099/0068.Text Justification/README_EN.md +++ /dev/null @@ -1,131 +0,0 @@ -# [68. Text Justification](https://leetcode.com/problems/text-justification) - -[中文文档](/solution/0000-0099/0068.Text%20Justification/README.md) - -## Description - -

Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

- -

You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.

- -

Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

- -

For the last line of text, it should be left justified and no extra space is inserted between words.

- -

Note:

- -
    -
  • A word is defined as a character sequence consisting of non-space characters only.
  • -
  • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
  • -
  • The input array words contains at least one word.
  • -
- -

Example 1:

- -
-
-Input:
-
-words = ["This", "is", "an", "example", "of", "text", "justification."]
-
-maxWidth = 16
-
-Output:
-
-[
-
-   "This    is    an",
-
-   "example  of text",
-
-   "justification.  "
-
-]
-
-
- -

Example 2:

- -
-
-Input:
-
-words = ["What","must","be","acknowledgment","shall","be"]
-
-maxWidth = 16
-
-Output:
-
-[
-
-  "What   must   be",
-
-  "acknowledgment  ",
-
-  "shall be        "
-
-]
-
-Explanation: Note that the last line is "shall be    " instead of "shall     be",
-
-             because the last line must be left-justified instead of fully-justified.
-
-             Note that the second line is also left-justified becase it contains only one word.
-
-
- -

Example 3:

- -
-
-Input:
-
-words = ["Science","is","what","we","understand","well","enough","to","explain",
-
-         "to","a","computer.","Art","is","everything","else","we","do"]
-
-maxWidth = 20
-
-Output:
-
-[
-
-  "Science  is  what we",
-
-  "understand      well",
-
-  "enough to explain to",
-
-  "a  computer.  Art is",
-
-  "everything  else  we",
-
-  "do                  "
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0068.Text Justification/Solution.cs b/leetcode/solution/0000-0099/0068.Text Justification/Solution.cs deleted file mode 100644 index 5df9c08e..00000000 --- a/leetcode/solution/0000-0099/0068.Text Justification/Solution.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; - -public class Solution { - public IList FullJustify(string[] words, int maxWidth) { - var result = new List(); - var buffer = new List(); - var sb = new StringBuilder(); - var len = 0; - - for (var i = 0; i < words.Length; ++i) - { - var newLen = words[i].Length + (len == 0 ? 0 : len + 1); - if (newLen <= maxWidth) - { - buffer.Add(words[i]); - len = newLen; - } - else - { - if (buffer.Count == 1) - { - sb.Append(buffer[0]); - sb.Append(' ', maxWidth - buffer[0].Length); - } - else - { - var spaceCount = maxWidth - len + buffer.Count - 1; - for (var j = 0; j < buffer.Count - 1; ++j) - { - sb.Append(buffer[j]); - var spaceToAdd = (spaceCount - 1) / (buffer.Count - j - 1) + 1; - sb.Append(' ', spaceToAdd); - spaceCount -= spaceToAdd; - } - sb.Append(buffer.Last()); - } - result.Add(sb.ToString()); - buffer.Clear(); - buffer.Add(words[i]); - sb.Clear(); - len = words[i].Length; - } - } - - if (buffer.Count > 0) - { - for (var j = 0; j < buffer.Count; ++j) - { - if (sb.Length > 0) - { - sb.Append(' '); - } - sb.Append(buffer[j]); - } - if (sb.Length < maxWidth) - { - sb.Append(' ', maxWidth - sb.Length); - } - result.Add(sb.ToString()); - } - - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0069.Sqrt(x)/README_EN.md b/leetcode/solution/0000-0099/0069.Sqrt(x)/README_EN.md deleted file mode 100644 index eccd6485..00000000 --- a/leetcode/solution/0000-0099/0069.Sqrt(x)/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [69. Sqrt(x)](https://leetcode.com/problems/sqrtx) - -[中文文档]() - -## Description - -

Implement int sqrt(int x).

- -

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

- -

Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

- -

Example 1:

- -
-
-Input: 4
-
-Output: 2
-
-
- -

Example 2:

- -
-
-Input: 8
-
-Output: 2
-
-Explanation: The square root of 8 is 2.82842..., and since 
-
-             the decimal part is truncated, 2 is returned.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.cs b/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.cs deleted file mode 100644 index 52ce6d18..00000000 --- a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.cs +++ /dev/null @@ -1,30 +0,0 @@ -public class Solution { - public int MySqrt(int x) { - long l = 0; - long r = x; - while (l < r) - { - var mid = (l + r) / 2; - if (mid * mid <= x) - { - l = mid; - if (l == mid) - { - if (r * r <= x) - { - l = r; - } - else - { - --r; - } - } - } - else - { - r = mid; - } - } - return (int) l; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.go b/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.go deleted file mode 100644 index 70f24ec2..00000000 --- a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.go +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @lc app=leetcode.cn id=69 lang=golang - * Accepted - * 1017/1017 cases passed (0 ms) - * Your runtime beats 100 % of golang submissions - * Your memory usage beats 25.49 % of golang submissions (2.2 MB) - */ - -func mySqrt(x int) int { - if x == 0 || x == 1 { - return x - } - l, r, t := 1, x, 0 - m := (l + r) / 2 - for l != m { - t = m * m - if t == x { - return m - } - if t < x { - l = m - } else { - r = m - } - m = (l + r) / 2 - } - return m -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.js b/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.js deleted file mode 100644 index 5b243199..00000000 --- a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @param {number} x - * @return {number} - */ -var mySqrt = function (x) { - var left = 1; - var right = x; - var middle = Math.floor((left + right) / 2); - while (middle !== left) { - if (middle * middle <= x) { - left = middle; - } else { - right = middle; - } - middle = Math.floor((left + right) / 2); - } - return middle; -}; diff --git a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.py b/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.py deleted file mode 100644 index f488c525..00000000 --- a/leetcode/solution/0000-0099/0069.Sqrt(x)/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -# binary search [python2] - 40ms - -class Solution(object): - def mySqrt(self, x): - if x == 0: - return 0 - - left = 0 - right = x - while True: - mid = left + (right-left)/2 - if (mid * mid > x): - right = mid - 1 - else: - if (mid+1) * (mid+1) > x: - return mid - left = mid + 1 - diff --git a/leetcode/solution/0000-0099/0070.Climbing Stairs/README_EN.md b/leetcode/solution/0000-0099/0070.Climbing Stairs/README_EN.md deleted file mode 100644 index be2b26aa..00000000 --- a/leetcode/solution/0000-0099/0070.Climbing Stairs/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [70. Climbing Stairs](https://leetcode.com/problems/climbing-stairs) - -[中文文档](/solution/0000-0099/0070.Climbing%20Stairs/README.md) - -## Description - -

You are climbing a stair case. It takes n steps to reach to the top.

- -

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

- -

Note: Given n will be a positive integer.

- -

Example 1:

- -
-
-Input: 2
-
-Output: 2
-
-Explanation: There are two ways to climb to the top.
-
-1. 1 step + 1 step
-
-2. 2 steps
-
-
- -

Example 2:

- -
-
-Input: 3
-
-Output: 3
-
-Explanation: There are three ways to climb to the top.
-
-1. 1 step + 1 step + 1 step
-
-2. 1 step + 2 steps
-
-3. 2 steps + 1 step
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.cpp b/leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.cpp deleted file mode 100644 index 30cf14ab..00000000 --- a/leetcode/solution/0000-0099/0070.Climbing Stairs/Solution.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - int climbStairs(int n) { - - if(n==1) - return 1; - if(n==2) - return 2; - int arr[n]={0}; - arr[0]=1; - arr[1]=2; - for(int i=2;iGiven an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.

- -

In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period .. moves the directory up a level. For more information, see: Absolute path vs relative path in Linux/Unix

- -

Note that the returned canonical path must always begin with a slash /, and there must be only a single slash / between two directory names. The last directory name (if it exists) must not end with a trailing /. Also, the canonical path must be the shortest string representing the absolute path.

- -

 

- -

Example 1:

- -
-
-Input: "/home/"
-
-Output: "/home"
-
-Explanation: Note that there is no trailing slash after the last directory name.
-
-
- -

Example 2:

- -
-
-Input: "/../"
-
-Output: "/"
-
-Explanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
-
-
- -

Example 3:

- -
-
-Input: "/home//foo/"
-
-Output: "/home/foo"
-
-Explanation: In the canonical path, multiple consecutive slashes are replaced by a single one.
-
-
- -

Example 4:

- -
-
-Input: "/a/./b/../../c/"
-
-Output: "/c"
-
-
- -

Example 5:

- -
-
-Input: "/a/../../b/../c//.//"
-
-Output: "/c"
-
-
- -

Example 6:

- -
-
-Input: "/a//b////c/d//././/.."
-
-Output: "/a/b/c"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0071.Simplify Path/Solution.cs b/leetcode/solution/0000-0099/0071.Simplify Path/Solution.cs deleted file mode 100644 index 3f47366a..00000000 --- a/leetcode/solution/0000-0099/0071.Simplify Path/Solution.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; - -public class Solution { - public string SimplifyPath(string path) { - var stack = new Stack(); - var sb = new StringBuilder(); - foreach (var ch in ((IEnumerable)path).Concat(Enumerable.Repeat('/', 1))) - { - if (ch == '/') - { - if (sb.Length > 0) - { - var folder = sb.ToString(); - sb.Clear(); - switch (folder) - { - case ".": - break; - case "..": - if (stack.Any()) - { - stack.Pop(); - } - break; - default: - stack.Push(folder); - break; - } - } - } - else - { - sb.Append(ch); - } - } - - if (stack.Count == 0) - { - sb.Append('/'); - } - foreach (var folder in ((IEnumerable)stack.ToList()).Reverse()) - { - sb.Append('/'); - sb.Append(folder); - } - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0072.Edit Distance/README_EN.md b/leetcode/solution/0000-0099/0072.Edit Distance/README_EN.md deleted file mode 100644 index cfb43fba..00000000 --- a/leetcode/solution/0000-0099/0072.Edit Distance/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [72. Edit Distance](https://leetcode.com/problems/edit-distance) - -[中文文档](/solution/0000-0099/0072.Edit%20Distance/README.md) - -## Description - -

Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.

- -

You have the following 3 operations permitted on a word:

- -
    -
  1. Insert a character
  2. -
  3. Delete a character
  4. -
  5. Replace a character
  6. -
- -

Example 1:

- -
-
-Input: word1 = "horse", word2 = "ros"
-
-Output: 3
-
-Explanation: 
-
-horse -> rorse (replace 'h' with 'r')
-
-rorse -> rose (remove 'r')
-
-rose -> ros (remove 'e')
-
-
- -

Example 2:

- -
-
-Input: word1 = "intention", word2 = "execution"
-
-Output: 5
-
-Explanation: 
-
-intention -> inention (remove 't')
-
-inention -> enention (replace 'i' with 'e')
-
-enention -> exention (replace 'n' with 'x')
-
-exention -> exection (replace 'n' with 'c')
-
-exection -> execution (insert 'u')
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md b/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md deleted file mode 100644 index 7998ecbb..00000000 --- a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [73. Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes) - -[中文文档](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md) - -## Description - -

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

- -

Example 1:

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

Example 2:

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

Follow up:

- -
    -
  • A straight forward solution using O(mn) space is probably a bad idea.
  • -
  • A simple improvement uses O(m + n) space, but still not the best solution.
  • -
  • Could you devise a constant space solution?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.cpp b/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.cpp deleted file mode 100644 index ed582f0c..00000000 --- a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.cpp +++ /dev/null @@ -1,113 +0,0 @@ -//Solution1 -class Solution { -public: - void setZeroes(vector>& matrix) { - if(matrix.empty())return; - //行数组,列数组 - int rowNum = matrix.size(); - int columnNum = matrix[0].size(); - vector rowVec; - vector columnVec; - - - for(int i = 0;i>& matrix) { - if(matrix.empty()) return; - int m = matrix.size(); - int n = matrix[0].size(); - bool row = false , column = false; - - - for(int i = 0; i < m; i++)//判断第1列的0; - { - if(matrix[i][0] == 0) - { - column = true; - break; - } - } - for(int i = 0; i < n; i ++)//判断第1行的0; - { - if(matrix[0][i] == 0) - { - row = true; - break; - } - } - - for(int i = 1; i < m;i++) - { - for(int j = 1; j < n;j++) - { - if(matrix[i][j] == 0) - { - matrix[0][j] = 0; - matrix[i][0] = 0; - } - } - } - for(int i = 1; i < m;i++) - { - for(int j = 1; j < n;j++) - { - if(matrix[i][0] == 0 || matrix[0][j] == 0) - { - matrix[i][j] = 0; - } - } - } - if(row) - for(int i = 0; i < n;i++) - matrix[0][i] = 0; - if(column) - for(int i = 0; i < m;i++) - matrix[i][0] = 0; - - return; - - - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.py b/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.py deleted file mode 100644 index d432b8ae..00000000 --- a/leetcode/solution/0000-0099/0073.Set Matrix Zeroes/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def setZeroes(self, matrix): - """ - :type matrix: List[List[int]] - :rtype: void Do not return anything, modify matrix in-place instead. - """ - - coord = [] - for i in range(len(matrix)): - for j in range(len(matrix[i])): - if matrix[i][j] == 0: - coord.append((i, j)) - - for i, j in coord: - matrix[i] = [0]*len(matrix[i]) - for x in range(len(matrix)): - matrix[x][j] = 0 diff --git a/leetcode/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md b/leetcode/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md deleted file mode 100644 index e5087fbe..00000000 --- a/leetcode/solution/0000-0099/0074.Search a 2D Matrix/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [74. Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix) - -[中文文档](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md) - -## Description - -

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

- -
    -
  • Integers in each row are sorted from left to right.
  • -
  • The first integer of each row is greater than the last integer of the previous row.
  • -
- -

Example 1:

- -
-
-Input:
-
-matrix = [
-
-  [1,   3,  5,  7],
-
-  [10, 11, 16, 20],
-
-  [23, 30, 34, 50]
-
-]
-
-target = 3
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input:
-
-matrix = [
-
-  [1,   3,  5,  7],
-
-  [10, 11, 16, 20],
-
-  [23, 30, 34, 50]
-
-]
-
-target = 13
-
-Output: false
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0074.Search a 2D Matrix/Solution.cpp b/leetcode/solution/0000-0099/0074.Search a 2D Matrix/Solution.cpp deleted file mode 100644 index 89ebc98f..00000000 --- a/leetcode/solution/0000-0099/0074.Search a 2D Matrix/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - bool searchMatrix(vector>& matrix, int target) { - if(matrix.empty())return false; - - size_t row = matrix.size(); - size_t column = matrix[0].size(); - if(column == 0 || column == 0)return false; - - if(target < matrix[0][0] || target > matrix[row-1][column-1])return false; - - for(int i = 0;i target: - e = mid-1 - else: - s = mid+1 - - return False - - return False diff --git a/leetcode/solution/0000-0099/0075.Sort Colors/README_EN.md b/leetcode/solution/0000-0099/0075.Sort Colors/README_EN.md deleted file mode 100644 index 9a355199..00000000 --- a/leetcode/solution/0000-0099/0075.Sort Colors/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [75. Sort Colors](https://leetcode.com/problems/sort-colors) - -[中文文档](/solution/0000-0099/0075.Sort%20Colors/README.md) - -## Description - -

Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.

- -

Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.

- -

Note: You are not suppose to use the library's sort function for this problem.

- -

Example:

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

Follow up:

- -
    -
  • A rather straight forward solution is a two-pass algorithm using counting sort.
    - First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
  • -
  • Could you come up with a one-pass algorithm using only constant space?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0075.Sort Colors/Solution.cpp b/leetcode/solution/0000-0099/0075.Sort Colors/Solution.cpp deleted file mode 100644 index c99c4444..00000000 --- a/leetcode/solution/0000-0099/0075.Sort Colors/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - void sortColors(vector& nums) { - if(nums.empty())return ; - - int count[3] = {0}; - size_t len = nums.size(); - - for(int i = 0;iGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).

- -

Example:

- -
-
-Input: S = "ADOBECODEBANC", T = "ABC"
-
-Output: "BANC"
-
-
- -

Note:

- -
    -
  • If there is no such window in S that covers all characters in T, return the empty string "".
  • -
  • If there is such window, you are guaranteed that there will always be only one unique minimum window in S.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0076.Minimum Window Substring/Solution.cs b/leetcode/solution/0000-0099/0076.Minimum Window Substring/Solution.cs deleted file mode 100644 index f88339cc..00000000 --- a/leetcode/solution/0000-0099/0076.Minimum Window Substring/Solution.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Linq; - -public class Solution { - public string MinWindow(string s, string t) { - var dict = t.Distinct().ToDictionary(ch => ch, ch => 0); - var goalDict = t.GroupBy(ch => ch).ToDictionary(g => g.Key, g => g.Count()); - var goal = goalDict.Count; - - var minI = int.MaxValue; - var minJ = 0; - var i = 0; - var j = 0; - var current = 0; - - while (true) - { - while (current < goal && i < s.Length) - { - if (dict.ContainsKey(s[i])) - { - if (++dict[s[i]] == goalDict[s[i]]) - { - ++current; - } - } - ++i; - } - - while (current == goal && j < s.Length) - { - if (dict.ContainsKey(s[j])) - { - if (dict[s[j]] == goalDict[s[j]]) - { - break; - } - else - { - --dict[s[j]]; - } - } - ++j; - } - - if (current == goal) - { - if (i - j < minI - minJ) - { - minI = i; - minJ = j; - } - --dict[s[j]]; - --current; - ++j; - } - else - { - break; - } - } - - if (minI == int.MaxValue) - { - return string.Empty; - } - else - { - return s.Substring(minJ, minI - minJ); - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0077.Combinations/README_EN.md b/leetcode/solution/0000-0099/0077.Combinations/README_EN.md deleted file mode 100644 index 67dab32b..00000000 --- a/leetcode/solution/0000-0099/0077.Combinations/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [77. Combinations](https://leetcode.com/problems/combinations) - -[中文文档](/solution/0000-0099/0077.Combinations/README.md) - -## Description - -

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

- -

Example:

- -
-
-Input: n = 4, k = 2
-
-Output:
-
-[
-
-  [2,4],
-
-  [3,4],
-
-  [2,3],
-
-  [1,2],
-
-  [1,3],
-
-  [1,4],
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0078.Subsets/README_EN.md b/leetcode/solution/0000-0099/0078.Subsets/README_EN.md deleted file mode 100644 index b85820e6..00000000 --- a/leetcode/solution/0000-0099/0078.Subsets/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [78. Subsets](https://leetcode.com/problems/subsets) - -[中文文档](/solution/0000-0099/0078.Subsets/README.md) - -## Description - -

Given a set of distinct integers, nums, return all possible subsets (the power set).

- -

Note: The solution set must not contain duplicate subsets.

- -

Example:

- -
-
-Input: nums = [1,2,3]
-
-Output:
-
-[
-
-  [3],
-
-  [1],
-
-  [2],
-
-  [1,2,3],
-
-  [1,3],
-
-  [2,3],
-
-  [1,2],
-
-  []
-
-]
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0078.Subsets/Solution.cpp b/leetcode/solution/0000-0099/0078.Subsets/Solution.cpp deleted file mode 100644 index 505104e2..00000000 --- a/leetcode/solution/0000-0099/0078.Subsets/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - vector> subsets(vector& nums) { - vector> ans; - vector tmp; - int n = nums.size(); - dfs(ans,nums,tmp,0,n); - - return ans; - } - - - void dfs(vector> &ans,vector& nums,vector &tmp,int k,int n){ - ans.push_back(tmp); - for(int i = k;i < n;i++) - { - tmp.push_back(nums[i]); - dfs(ans,nums,tmp,i+1,n); - tmp.pop_back(); - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0078.Subsets/Solution.go b/leetcode/solution/0000-0099/0078.Subsets/Solution.go deleted file mode 100644 index fd7a9ac7..00000000 --- a/leetcode/solution/0000-0099/0078.Subsets/Solution.go +++ /dev/null @@ -1,21 +0,0 @@ -func subsets(nums []int) [][]int { - n := len(nums) - ans := make([][]int,0) - tmp := make([]int,0) - dfs(&ans,tmp,nums,0,n) - - return ans -} - - -func dfs(ans *[][]int,tmp []int,nums []int,k,n int) { - tmpVec := make([]int,len(tmp)) - copy(tmpVec,tmp) - *ans = append(*ans,tmpVec) - - for i:=k;i < n;i++{ - tmp = append(tmp,nums[i]) - dfs(ans,tmp,nums,i+1,n) - tmp = tmp[:len(tmp) - 1] - } -} diff --git a/leetcode/solution/0000-0099/0079.Word Search/README_EN.md b/leetcode/solution/0000-0099/0079.Word Search/README_EN.md deleted file mode 100644 index 96dcd516..00000000 --- a/leetcode/solution/0000-0099/0079.Word Search/README_EN.md +++ /dev/null @@ -1,117 +0,0 @@ -# [79. Word Search](https://leetcode.com/problems/word-search) - -[中文文档](/solution/0000-0099/0079.Word%20Search/README.md) - -## Description - -

Given a 2D board and a word, find if the word exists in the grid.

- -

The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

- -

Example:

- -
-
-board =
-
-[
-
-  ['A','B','C','E'],
-
-  ['S','F','C','S'],
-
-  ['A','D','E','E']
-
-]
-
-
-
-Given word = "ABCCED", return true.
-
-Given word = "SEE", return true.
-
-Given word = "ABCB", return false.
-
-
- -

 

-

Constraints:

- -
    -
  • board and word consists only of lowercase and uppercase English letters.
  • -
  • 1 <= board.length <= 200
  • -
  • 1 <= board[i].length <= 200
  • -
  • 1 <= word.length <= 10^3
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def exist(self, board: List[List[str]], word: str) -> bool: - def dfs(i, j, cur): - if cur == len(word): - return True - if i < 0 or i >= m or j < 0 or j >= n or visited[i][j] or word[cur] != board[i][j]: - return False - visited[i][j] = True - next = cur + 1 - res = dfs(i + 1, j, next) or dfs(i - 1, j, next) or dfs(i, j + 1, next) or dfs(i, j - 1, next) - visited[i][j] = False - return res - m, n = len(board), len(board[0]) - visited = [[False for _ in range(n)] for _ in range(m)] - for i in range(m): - for j in range(n): - res = dfs(i, j, 0) - if res: - return True - return False -``` - -### **Java** - -```java -class Solution { - private boolean[][] visited; - - public boolean exist(char[][] board, String word) { - int m = board.length, n = board[0].length; - visited = new boolean[m][n]; - char[] chars = word.toCharArray(); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - boolean res = dfs(board, i, j, chars, 0); - if (res) return true; - } - } - return false; - } - - private boolean dfs(char[][] board, int i, int j, char[] chars, int cur) { - if (cur == chars.length) return true; - if (i < 0 || i >= board.length || j < 0 || j >= board[0].length) return false; - if (visited[i][j] || board[i][j] != chars[cur]) return false; - visited[i][j] = true; - int next = cur + 1; - boolean res = dfs(board, i + 1, j, chars, next) - || dfs(board, i - 1, j, chars, next) - || dfs(board, i, j + 1, chars, next) - || dfs(board, i, j - 1, chars, next); - visited[i][j] = false; - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0079.Word Search/Solution.cs b/leetcode/solution/0000-0099/0079.Word Search/Solution.cs deleted file mode 100644 index e0843348..00000000 --- a/leetcode/solution/0000-0099/0079.Word Search/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -public class Solution { - public bool Exist(char[][] board, string word) { - var lenI = board.Length; - var lenJ = lenI == 0 ? 0 : board[0].Length; - var visited = new bool[lenI, lenJ]; - for (var i = 0; i < lenI; ++i) - { - for (var j = 0; j < lenJ; ++j) - { - if (Search(board, visited, word, lenI, lenJ, i, j, 0)) - { - return true; - } - } - } - return false; - } - - private int[,] paths = new int[4,2] { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; - - private bool Search(char[][] board, bool[,] visited, string word, int lenI, int lenJ, int i, int j, int p) - { - if (p == word.Length) - { - return true; - } - if (i < 0 || i >= lenI || j < 0 || j >= lenJ) return false; - if (visited[i, j] || word[p] != board[i][j]) return false; - visited[i, j] = true; - for (var k = 0; k < 4; ++k) - { - if (Search(board, visited, word, lenI, lenJ, i + paths[k, 0], j + paths[k, 1], p + 1)) return true; - } - visited[i, j] = false; - return false; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0079.Word Search/Solution.py b/leetcode/solution/0000-0099/0079.Word Search/Solution.py deleted file mode 100644 index 9056a640..00000000 --- a/leetcode/solution/0000-0099/0079.Word Search/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def exist(self, board: List[List[str]], word: str) -> bool: - def dfs(i, j, cur): - if cur == len(word): - return True - if i < 0 or i >= m or j < 0 or j >= n or visited[i][j] or word[cur] != board[i][j]: - return False - visited[i][j] = True - next = cur + 1 - res = dfs(i + 1, j, next) or dfs(i - 1, j, next) or dfs(i, j + 1, next) or dfs(i, j - 1, next) - visited[i][j] = False - return res - m, n = len(board), len(board[0]) - visited = [[False for _ in range(n)] for _ in range(m)] - for i in range(m): - for j in range(n): - res = dfs(i, j, 0) - if res: - return True - return False diff --git a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md b/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md deleted file mode 100644 index c88cd411..00000000 --- a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [80. Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) - -[中文文档](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md) - -## Description - -

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

- -

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

- -

Example 1:

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

Example 2:

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

Clarification:

- -

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

- -

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

- -

Internally you can think of this:

- -
-
-// nums is passed in by reference. (i.e., without making a copy)
-
-int len = removeDuplicates(nums);
-
-
-
-// any modification to nums in your function would be known by the caller.
-
-// using the length returned by your function, it prints the first len elements.
-
-for (int i = 0; i < len; i++) {
-
-    print(nums[i]);
-
-}
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cpp b/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cpp deleted file mode 100644 index 5246179a..00000000 --- a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -class Solution { -public: - int removeDuplicates(vector& nums) { - if(nums.empty())return 0; - size_t len = nums.size(); - if(len == 1)return 1; - - auto iter = nums.begin(); - iter++; - int k = 1; - while(iter != nums.end()){ - if(*iter == *(iter-1))k++; - else k = 1; - - if(k==3){ - nums.erase(iter); - k--; - } - else { - iter++; - } - } - - len = nums.size(); - return len; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cs b/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cs deleted file mode 100644 index dcd9e76d..00000000 --- a/leetcode/solution/0000-0099/0080.Remove Duplicates from Sorted Array II/Solution.cs +++ /dev/null @@ -1,16 +0,0 @@ -public class Solution { - public int RemoveDuplicates(int[] nums) { - if (nums.Length <= 2) return nums.Length; - var i = 0; - var j = 1; - while (j < nums.Length) - { - if (nums[i] != nums[j] || i == 0 || nums[i] == nums[j] && nums[i - 1] != nums[j]) - { - nums[++i] = nums[j]; - } - ++j; - } - return i + 1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md b/leetcode/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md deleted file mode 100644 index e1850b50..00000000 --- a/leetcode/solution/0000-0099/0081.Search in Rotated Sorted Array II/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [81. Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) - -[中文文档](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md) - -## Description - -

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

- -

(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).

- -

You are given a target value to search. If found in the array return true, otherwise return false.

- -

Example 1:

- -
-
-Input: nums = [2,5,6,0,0,1,2], target = 0
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: nums = [2,5,6,0,0,1,2], target = 3
-
-Output: false
- -

Follow up:

- -
    -
  • This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates.
  • -
  • Would this affect the run-time complexity? How and why?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md b/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md deleted file mode 100644 index 38464982..00000000 --- a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [82. Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) - -[中文文档](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md) - -## Description - -

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

- -

Return the linked list sorted as well.

- -

Example 1:

- -
-Input: 1->2->3->3->4->4->5
-Output: 1->2->5
-
- -

Example 2:

- -
-Input: 1->1->1->2->3
-Output: 2->3
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.cs b/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.cs deleted file mode 100644 index bb6fbe33..00000000 --- a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.cs +++ /dev/null @@ -1,43 +0,0 @@ -public class Solution { - private ListNode newHead; - private ListNode last; - private ListNode candidate; - private int count; - - public ListNode DeleteDuplicates(ListNode head) { - while (head != null) - { - if (candidate == null || candidate.val != head.val) - { - TryAppend(); - candidate = head; - count = 1; - } - else - { - ++count; - } - - head = head.next; - } - TryAppend(); - if (last != null) last.next = null; - return newHead; - } - - private void TryAppend() - { - if (count == 1) - { - if (newHead == null) - { - newHead = last = candidate; - } - else - { - last.next = candidate; - last = last.next; - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.py b/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.py deleted file mode 100644 index 4ecaf3d1..00000000 --- a/leetcode/solution/0000-0099/0082.Remove Duplicates from Sorted List II/Solution.py +++ /dev/null @@ -1,35 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def deleteDuplicates(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if head == None: - return None - list0=list() - i=head - while i: - list0.append(i.val) - i=i.next - list1=list0.copy() - for i in list0: - c=list0.count(i) - if c != 1: - while 1: - try: - list1.remove(i) - except: - break - - new_listnode=ListNode(0) - j=new_listnode - for v in list1: - new_listnode.next=ListNode(v) - new_listnode=new_listnode.next - return j.next \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md b/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md deleted file mode 100644 index 161032da..00000000 --- a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [83. Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list) - -[中文文档](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md) - -## Description - -

Given a sorted linked list, delete all duplicates such that each element appear only once.

- -

Example 1:

- -
-
-Input: 1->1->2
-
-Output: 1->2
-
-
- -

Example 2:

- -
-
-Input: 1->1->2->3->3
-
-Output: 1->2->3
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.cs b/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.cs deleted file mode 100644 index 5f9e8e23..00000000 --- a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.cs +++ /dev/null @@ -1,21 +0,0 @@ -public class Solution { - public ListNode DeleteDuplicates(ListNode head) { - if (head == null) return null; - var last = head; - var current = head.next; - while (current != null) - { - if (current.val != last.val) - { - last.next = current; - last = current; - } - else - { - last.next = null; - } - current = current.next; - } - return head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.go b/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.go deleted file mode 100644 index 711020d0..00000000 --- a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.go +++ /dev/null @@ -1,11 +0,0 @@ -func deleteDuplicates(head *ListNode) *ListNode { - current := head - for current != nil && current.Next != nil { - if current.Val == current.Next.Val { - current.Next = current.Next.Next - } else { - current = current.Next - } - } - return head -} diff --git a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js b/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js deleted file mode 100644 index 7078e3b5..00000000 --- a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @return {ListNode} - */ -var deleteDuplicates = function (head) { - var p = head; - while (p && p.next) { - if (p.val == p.next.val) { - p.next = p.next.next; - } else { - p = p.next; - } - } - return head; -}; diff --git a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.py b/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.py deleted file mode 100644 index 5a16f0de..00000000 --- a/leetcode/solution/0000-0099/0083.Remove Duplicates from Sorted List/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def deleteDuplicates(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if head == None: - return None - dict0=dict() - i=head - c=0 - while i: - if i.val not in dict0.values(): - dict0[c]=i.val - c+=1 - i=i.next - new_listnode=ListNode(0) - j=new_listnode - for v in dict0.values(): - new_listnode.next=ListNode(v) - new_listnode=new_listnode.next - return j.next - \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md b/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md deleted file mode 100644 index dbd46749..00000000 --- a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [84. Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram) - -[中文文档](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md) - -## Description - -

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

- -

 

- -![](./images/histogram.png) - -Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].

- -

 

- -![](./images/histogram_area.png) - -The largest rectangle is shown in the shaded area, which has area = 10 unit.

- -

 

- -

Example:

- -
-
-Input: [2,1,5,6,2,3]
-
-Output: 10
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cpp b/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cpp deleted file mode 100644 index 644437cd..00000000 --- a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cpp +++ /dev/null @@ -1,42 +0,0 @@ -class Solution { -public: - int largestRectangleArea(vector& heights) { - if(heights.empty())return 0; - int len = heights.size(); - - stack s_stack; - int ans = 0; - - for(int i = 0;i < len;i++){ - if(s_stack.empty() || heights[i] >= s_stack.top()) - {//满足升序条件 - s_stack.push(heights[i]); - } - else - {//不满足升序 - int count = 0; - while(!s_stack.empty() && s_stack.top() > heights[i]) - { - count++; - ans = max(ans,s_stack.top() * count); - s_stack.pop(); - } - while(count > 0) - { - s_stack.push(heights[i]); - count--; - } - s_stack.push(heights[i]); - } - } - - int count = 1; - while(!s_stack.empty()){ - ans = max(ans,s_stack.top() * count); - s_stack.pop(); - count++; - } - - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cs b/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cs deleted file mode 100644 index ba7d332e..00000000 --- a/leetcode/solution/0000-0099/0084.Largest Rectangle in Histogram/Solution.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public int LargestRectangleArea(int[] height) { - var stack = new Stack(); - var result = 0; - var i = 0; - while (i < height.Length || stack.Any()) - { - if (!stack.Any() || (i < height.Length && height[stack.Peek()] < height[i])) - { - stack.Push(i); - ++i; - } - else - { - var previousIndex = stack.Pop(); - var area = height[previousIndex] * (stack.Any() ? (i - stack.Peek() - 1) : i); - result = Math.Max(result, area); - } - } - - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0085.Maximal Rectangle/README_EN.md b/leetcode/solution/0000-0099/0085.Maximal Rectangle/README_EN.md deleted file mode 100644 index 652eaad1..00000000 --- a/leetcode/solution/0000-0099/0085.Maximal Rectangle/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [85. Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle) - -[中文文档](/solution/0000-0099/0085.Maximal%20Rectangle/README.md) - -## Description - -

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

- -

Example:

- -
-
-Input:
-
-[
-
-  ["1","0","1","0","0"],
-
-  ["1","0","1","1","1"],
-
-  ["1","1","1","1","1"],
-
-  ["1","0","0","1","0"]
-
-]
-
-Output: 6
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0085.Maximal Rectangle/Solution.cs b/leetcode/solution/0000-0099/0085.Maximal Rectangle/Solution.cs deleted file mode 100644 index de354ffd..00000000 --- a/leetcode/solution/0000-0099/0085.Maximal Rectangle/Solution.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Solution { - private int MaximalRectangleHistagram(int[] height) { - var stack = new Stack(); - var result = 0; - var i = 0; - while (i < height.Length || stack.Any()) - { - if (!stack.Any() || (i < height.Length && height[stack.Peek()] < height[i])) - { - stack.Push(i); - ++i; - } - else - { - var previousIndex = stack.Pop(); - var area = height[previousIndex] * (stack.Any() ? (i - stack.Peek() - 1) : i); - result = Math.Max(result, area); - } - } - - return result; - } - - public int MaximalRectangle(char[][] matrix) { - var lenI = matrix.Length; - var lenJ = lenI == 0 ? 0 : matrix[0].Length; - var height = new int[lenJ]; - var result = 0; - for (var i = 0; i < lenI; ++i) - { - for (var j = 0; j < lenJ; ++j) - { - if (matrix[i][j] == '1') - { - ++height[j]; - } - else - { - height[j] = 0; - } - } - result = Math.Max(result, MaximalRectangleHistagram(height)); - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0086.Partition List/README_EN.md b/leetcode/solution/0000-0099/0086.Partition List/README_EN.md deleted file mode 100644 index 81784efe..00000000 --- a/leetcode/solution/0000-0099/0086.Partition List/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -# [86. Partition List](https://leetcode.com/problems/partition-list) - -[中文文档](/solution/0000-0099/0086.Partition%20List/README.md) - -## Description - -

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

- -

You should preserve the original relative order of the nodes in each of the two partitions.

- -

Example:

- -
-
-Input: head = 1->4->3->2->5->2, x = 3
-
-Output: 1->2->2->4->3->5
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0086.Partition List/Solution.cpp b/leetcode/solution/0000-0099/0086.Partition List/Solution.cpp deleted file mode 100644 index 20aa01ca..00000000 --- a/leetcode/solution/0000-0099/0086.Partition List/Solution.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ -class Solution { -public: - ListNode* partition(ListNode* head, int x) { - ListNode headSmaller(0), headBigger(0) ; - ListNode *pSmaller = &headSmaller ; - ListNode *pBigger = &headBigger ; - ListNode *p = head ; - while (nullptr != p) - { - if (p->val < x) - { - pSmaller->next = p ; - pSmaller = p ; - } - else - { - pBigger->next = p ; - pBigger = p ; - } - p = p->next ; - } - pBigger->next = nullptr ; - pSmaller->next = headBigger.next ; - return headSmaller.next ; - } -}; diff --git a/leetcode/solution/0000-0099/0086.Partition List/Solution.py b/leetcode/solution/0000-0099/0086.Partition List/Solution.py deleted file mode 100644 index a76faa80..00000000 --- a/leetcode/solution/0000-0099/0086.Partition List/Solution.py +++ /dev/null @@ -1,30 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def partition(self, head, x): - """ - :type head: ListNode - :type x: int - :rtype: ListNode - """ - leftDummy=ListNode(-1) - rightDummy=ListNode(-1) - leftCur=leftDummy - rightCur=rightDummy - - while head: - if head.valGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.

- -

Below is one possible representation of s1 = "great":

- -
-
-    great
-
-   /    \
-
-  gr    eat
-
- / \    /  \
-
-g   r  e   at
-
-           / \
-
-          a   t
-
-
- -

To scramble the string, we may choose any non-leaf node and swap its two children.

- -

For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat".

- -
-
-    rgeat
-
-   /    \
-
-  rg    eat
-
- / \    /  \
-
-r   g  e   at
-
-           / \
-
-          a   t
-
-
- -

We say that "rgeat" is a scrambled string of "great".

- -

Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae".

- -
-
-    rgtae
-
-   /    \
-
-  rg    tae
-
- / \    /  \
-
-r   g  ta  e
-
-       / \
-
-      t   a
-
-
- -

We say that "rgtae" is a scrambled string of "great".

- -

Given two strings s1 and s2 of the same length, determine if s2 is a scrambled string of s1.

- -

Example 1:

- -
-
-Input: s1 = "great", s2 = "rgeat"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: s1 = "abcde", s2 = "caebd"
-
-Output: false
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0087.Scramble String/Solution.cs b/leetcode/solution/0000-0099/0087.Scramble String/Solution.cs deleted file mode 100644 index 5b944fda..00000000 --- a/leetcode/solution/0000-0099/0087.Scramble String/Solution.cs +++ /dev/null @@ -1,35 +0,0 @@ -public class Solution { - public bool IsScramble(string s1, string s2) { - if (s1.Length != s2.Length) return false; - var length = s1.Length; - if (length == 0) return true; - var f = new bool[length + 1, length, length]; - for (var i = 0; i < length; ++i) - { - for (var j = 0; j < length; ++j) - { - f[1, i, j] = s1[i] == s2[j]; - } - } - for (var i = 2; i <= length; ++i) - { - for (var j = 0; j <= length - i; ++j) - { - for (var k = 0; k <= length - i; ++k) - { - for (var l = 1; l < i; ++l) - { - if (f[l, j, k] && f[i - l, j + l, k + l] - || f[l, j, k + i - l] && f[i - l, j + l, k]) - { - f[i, j, k] = true; - break; - } - } - } - } - } - - return f[length, 0, 0]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0088.Merge Sorted Array/README_EN.md b/leetcode/solution/0000-0099/0088.Merge Sorted Array/README_EN.md deleted file mode 100644 index c52e86ba..00000000 --- a/leetcode/solution/0000-0099/0088.Merge Sorted Array/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) - -[中文文档](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md) - -## Description - -

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

- -

Note:

- -
    -
  • The number of elements initialized in nums1 and nums2 are m and n respectively.
  • -
  • You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
  • -
- -

Example:

- -
-
-Input:
-
-nums1 = [1,2,3,0,0,0], m = 3
-
-nums2 = [2,5,6],       n = 3
-
-
-
-Output: [1,2,2,3,5,6]
-
-
- -## Solutions - - - -### **Python3** - -```python -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. - """ - i, j = m - 1, n - 1 - k = m + n - 1 - while j >= 0: - if i >= 0 and nums1[i] > nums2[j]: - nums1[k] = nums1[i] - i -= 1 - else: - nums1[k] = nums2[j] - j -= 1 - k -= 1 -``` - -### **Java** - -```java -class Solution { - public void merge(int[] nums1, int m, int[] nums2, int n) { - int i = m - 1, j = n - 1; - int k = m + n - 1; - while (j >= 0) { - if (i >= 0 && nums1[i] >= nums2[j]) { - nums1[k--] = nums1[i--]; - } else { - nums1[k--] = nums2[j--]; - } - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.go b/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.go deleted file mode 100644 index 21864f1e..00000000 --- a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.go +++ /dev/null @@ -1,20 +0,0 @@ -func merge(nums1 []int, m int, nums2 []int, n int) { - ret := make([]int, m+n) - copy(ret, nums1[:m]) - p0, p1, p2 := 0, 0, 0 - for ; p1 < m && p2 < n; p0++ { - if nums1[p1] >= nums2[p2] { - ret[p0] = nums2[p2] - p2++ - } else if nums1[p1] < nums2[p2] { - ret[p0] = nums1[p1] - p1++ - } - } - if p1 < m { - copy(nums1, append(ret[:p0], nums1[p1:m]...)) - } - if p2 < n { - copy(nums1, append(ret[:p0], nums2[p2:]...)) - } -} diff --git a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.js b/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.js deleted file mode 100644 index c58e56f8..00000000 --- a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.js +++ /dev/null @@ -1,40 +0,0 @@ -//beat 88% -const merge1 = function (nums1, m, nums2, n) { - const arr = nums1.slice(0, m); - let i = 0, - j = 0; - let count = 0; - while (i < m && j < n) { - if (arr[i] <= nums2[j]) { - nums1[count++] = arr[i++]; - } else { - nums1[count++] = nums2[j++]; - } - } - while (i < m) { - nums1[count++] = arr[i++]; - } - while (j < n) { - nums1[count++] = nums2[j++]; - } -}; - -//beat 30%.... -const merge = function (nums1, m, nums2, n) { - let index = m + n - 1; - let aindex = m - 1; - let bindex = n - 1; - while (aindex >= 0 && bindex >= 0) { - if (nums1[aindex] > nums2[bindex]) { - nums1[index--] = nums1[aindex--]; - } else { - nums1[index--] = nums2[bindex--]; - } - } - while (aindex >= 0) { - nums1[index--] = nums1[aindex--]; - } - while (bindex >= 0) { - nums1[index--] = nums2[bindex--]; - } -}; diff --git a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.py b/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.py deleted file mode 100644 index 39959013..00000000 --- a/leetcode/solution/0000-0099/0088.Merge Sorted Array/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -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. - """ - i, j = m - 1, n - 1 - k = m + n - 1 - while j >= 0: - if i >= 0 and nums1[i] > nums2[j]: - nums1[k] = nums1[i] - i -= 1 - else: - nums1[k] = nums2[j] - j -= 1 - k -= 1 diff --git a/leetcode/solution/0000-0099/0089.Gray Code/README_EN.md b/leetcode/solution/0000-0099/0089.Gray Code/README_EN.md deleted file mode 100644 index 53f0f970..00000000 --- a/leetcode/solution/0000-0099/0089.Gray Code/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [89. Gray Code](https://leetcode.com/problems/gray-code) - -[中文文档](/solution/0000-0099/0089.Gray%20Code/README.md) - -## Description - -

The gray code is a binary numeral system where two successive values differ in only one bit.

- -

Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

- -

Example 1:

- -
-
-Input: 2
-
-Output: [0,1,3,2]
-
-Explanation:
-
-00 - 0
-
-01 - 1
-
-11 - 3
-
-10 - 2
-
-
-
-For a given n, a gray code sequence may not be uniquely defined.
-
-For example, [0,2,3,1] is also a valid gray code sequence.
-
-
-
-00 - 0
-
-10 - 2
-
-11 - 3
-
-01 - 1
-
-
- -

Example 2:

- -
-
-Input: 0
-
-Output: [0]
-
-Explanation: We define the gray code sequence to begin with 0.
-
-             A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
-
-             Therefore, for n = 0 the gray code sequence is [0].
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0089.Gray Code/Solution.cpp b/leetcode/solution/0000-0099/0089.Gray Code/Solution.cpp deleted file mode 100644 index e7d94ead..00000000 --- a/leetcode/solution/0000-0099/0089.Gray Code/Solution.cpp +++ /dev/null @@ -1,10 +0,0 @@ -class Solution { -public: - vector grayCode(int n) { - vector res; - for (int i = 0; i < (1 << n); ++i) { - res.push_back((i >> 1) ^ i); - } - return res; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0090.Subsets II/README_EN.md b/leetcode/solution/0000-0099/0090.Subsets II/README_EN.md deleted file mode 100644 index 062ab27f..00000000 --- a/leetcode/solution/0000-0099/0090.Subsets II/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [90. Subsets II](https://leetcode.com/problems/subsets-ii) - -[中文文档](/solution/0000-0099/0090.Subsets%20II/README.md) - -## Description - -

Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).

- -

Note: The solution set must not contain duplicate subsets.

- -

Example:

- -
-
-Input: [1,2,2]
-
-Output:
-
-[
-
-  [2],
-
-  [1],
-
-  [1,2,2],
-
-  [2,2],
-
-  [1,2],
-
-  []
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0090.Subsets II/Solution.cpp b/leetcode/solution/0000-0099/0090.Subsets II/Solution.cpp deleted file mode 100644 index d1c673c3..00000000 --- a/leetcode/solution/0000-0099/0090.Subsets II/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - vector> subsetsWithDup(vector& nums) { - vector tmp; - vector> ans; - int len = nums.size(); - if(len == 0)return ans; - dfs(nums,ans,tmp,len,0); - return ans; - } - - void dfs(vector &nums,vector> &ans,vector tmp,int len,int k){ - sort(tmp.begin(),tmp.end()); - auto iter = find(ans.begin(),ans.end(),tmp); - if(iter == ans.end())ans.push_back(tmp); - for(int i = k;iA message containing letters from A-Z is being encoded to numbers using the following mapping:

- -
-
-'A' -> 1
-
-'B' -> 2
-
-...
-
-'Z' -> 26
-
-
- -

Given a non-empty string containing only digits, determine the total number of ways to decode it.

- -

Example 1:

- -
-
-Input: "12"
-
-Output: 2
-
-Explanation: It could be decoded as "AB" (1 2) or "L" (12).
-
-
- -

Example 2:

- -
-
-Input: "226"
-
-Output: 3
-
-Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0091.Decode Ways/Solution.cs b/leetcode/solution/0000-0099/0091.Decode Ways/Solution.cs deleted file mode 100644 index 200f1016..00000000 --- a/leetcode/solution/0000-0099/0091.Decode Ways/Solution.cs +++ /dev/null @@ -1,25 +0,0 @@ -public class Solution { - public int NumDecodings(string s) { - if (s.Length == 0) return 0; - - var f0 = 1; - var f1 = 1; - var f2 = 1; - for (var i = 0; i < s.Length; ++i) - { - f0 = f1; - f1 = f2; - f2 = 0; - var two = i > 0 ? int.Parse(string.Format("{0}{1}", s[i - 1], s[i])) : 0; - if (two >= 10 && two <= 26) - { - f2 += f0; - } - if (s[i] != '0') - { - f2 += f1; - } - } - return f2; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0092.Reverse Linked List II/README_EN.md b/leetcode/solution/0000-0099/0092.Reverse Linked List II/README_EN.md deleted file mode 100644 index 3644fba7..00000000 --- a/leetcode/solution/0000-0099/0092.Reverse Linked List II/README_EN.md +++ /dev/null @@ -1,98 +0,0 @@ -# [92. Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii) - -[中文文档](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md) - -## Description - -

Reverse a linked list from position m to n. Do it in one-pass.

- -

Note: 1 ≤ mn ≤ length of list.

- -

Example:

- -
-
-Input: 1->2->3->4->5->NULL, m = 2, n = 4
-
-Output: 1->4->3->2->5->NULL
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def reverseBetween(self, head: ListNode, m: int, n: int) -> ListNode: - if head is None or head.next is None or m == n: - return head - dummy = ListNode(0) - dummy.next = head - pre, cur = dummy, head - for _ in range(m - 1): - pre = cur - cur = cur.next - p, q = pre, cur - for _ in range(n - m + 1): - t = cur.next - cur.next = pre - pre = cur - cur = t - p.next = pre - q.next = cur - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode reverseBetween(ListNode head, int m, int n) { - if (head == null || head.next == null || m == n) { - return head; - } - ListNode dummy = new ListNode(0); - dummy.next = head; - ListNode pre = dummy, cur = head; - for (int i = 0; i < m - 1; ++i) { - pre = cur; - cur = cur.next; - } - ListNode p = pre, q = cur; - for (int i = 0; i < n - m + 1; ++i) { - ListNode t = cur.next; - cur.next = pre; - pre = cur; - cur = t; - } - p.next = pre; - q.next = cur; - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cpp b/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cpp deleted file mode 100644 index 089c5bf8..00000000 --- a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ -class Solution { -public: - ListNode* reverseBetween(ListNode* head, int m, int n) { - ListNode headNode(0) ; - headNode.next = head ; - - n = n-m+1 ; - - ListNode *p = &headNode ; - while (--m) // 移动m-1次,故--m - p = p->next ; - - ListNode revNode(0) ; - ListNode *pRev = &revNode ; - pRev->next = nullptr ; - ListNode *pN = p->next ; - - ListNode *pTmp ; - while (n--) - { - pTmp = p->next ; - p->next = p->next->next ; - pTmp->next = pRev->next ; - pRev->next = pTmp ; - } - - pN->next = p->next ; - p->next = revNode.next ; - - return headNode.next ; - } -}; diff --git a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cs b/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cs deleted file mode 100644 index 783ce47b..00000000 --- a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.cs +++ /dev/null @@ -1,35 +0,0 @@ -public class Solution { - public ListNode ReverseBetween(ListNode head, int m, int n) { - ListNode part1Head = null; - ListNode part1Tail = null; - for (var i = 1; i < m; ++i) - { - if (part1Head == null) - { - part1Head = head; - } - part1Tail = head; - head = head.next; - } - if (part1Tail != null) part1Tail.next = null; - ListNode part2Head = null; - ListNode part2Tail = null; - for (var i = m; i <= n; ++i) - { - var next = head.next; - head.next = part2Head; - part2Head = head; - if (part2Tail == null) - { - part2Tail = head; - } - head = next; - } - if (part1Tail != null) - { - part1Tail.next = part2Head; - } - part2Tail.next = head; - return part1Head ?? part2Head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.py b/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.py deleted file mode 100644 index f065fc8f..00000000 --- a/leetcode/solution/0000-0099/0092.Reverse Linked List II/Solution.py +++ /dev/null @@ -1,25 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def reverseBetween(self, head: ListNode, m: int, n: int) -> ListNode: - if head is None or head.next is None or m == n: - return head - dummy = ListNode(0) - dummy.next = head - pre, cur = dummy, head - for _ in range(m - 1): - pre = cur - cur = cur.next - p, q = pre, cur - for _ in range(n - m + 1): - t = cur.next - cur.next = pre - pre = cur - cur = t - p.next = pre - q.next = cur - return dummy.next diff --git a/leetcode/solution/0000-0099/0093.Restore IP Addresses/README_EN.md b/leetcode/solution/0000-0099/0093.Restore IP Addresses/README_EN.md deleted file mode 100644 index d5da0b07..00000000 --- a/leetcode/solution/0000-0099/0093.Restore IP Addresses/README_EN.md +++ /dev/null @@ -1,41 +0,0 @@ -# [93. Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses) - -[中文文档](/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md) - -## Description - -

Given a string containing only digits, restore it by returning all possible valid IP address combinations.

- -

Example:

- -
-
-Input: "25525511135"
-
-Output: ["255.255.11.135", "255.255.111.35"]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cpp b/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cpp deleted file mode 100644 index 86376c5a..00000000 --- a/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cpp +++ /dev/null @@ -1,54 +0,0 @@ -class Solution { -private: - inline string Check(string &s, int widths[]) - { - widths[1] += widths[0] ; - widths[2] += widths[1] ; - widths[3] = s.length() - widths[2] ; - - if (widths[3] < 1 || widths[3] > 3 ) - return "" ; - - widths[3] = s.length() ; - - for (int seg = 0; seg < 4; ++seg) - { - int num = 0 ; - for (int i = (seg == 0? 0: widths[seg-1]); i < widths[seg]; ++i) - { - num *= 10 ; - num += s[i] - '0' ; - } - if (num > 255) - return "" ; - - int w = widths[seg] - (seg == 0? 0: widths[seg-1]) ; - if (w == 3 && num < 100) - return "" ; - if (w == 2 && num < 10) - return "" ; - } - string res = s ; - for (int i = 2; i >= 0; --i) - res.insert(widths[i], ".") ; - - return res ; - } -public: - vector restoreIpAddresses(string s) { - int widths[4] ; - vector res ; - for (int i = 0; i < 27; ++i) - { - widths[0] = 1 + i%3 ; - widths[1] = 1 + i/3%3 ; - widths[2] = 1 + i/9 ; - - string tmp = Check(s, widths) ; - if (tmp.size() != 0) - res.push_back(tmp) ; - } - - return res; - } -}; diff --git a/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cs b/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cs deleted file mode 100644 index 03055bfb..00000000 --- a/leetcode/solution/0000-0099/0093.Restore IP Addresses/Solution.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public IList RestoreIpAddresses(string s) { - if (s.Length > 12) return new List(); - var results = new HashSet(); - for (var i = 0; i < s.Length - 3; ++i) - { - for (var j = i + 1; j < s.Length - 2; ++j) - { - for (var k = j + 1; k < s.Length - 1; ++k) - { - var part1 = Normalize(s.Substring(0, i + 1)); - var part2 = Normalize(s.Substring(i + 1, j - i)); - var part3 = Normalize(s.Substring(j + 1, k - j)); - var part4 = Normalize(s.Substring(k + 1)); - - if (part1 != null && part2 != null && part3 != null && part4 != null) - { - results.Add(string.Format("{0}.{1}.{2}.{3}", part1, part2, part3, part4)); - } - } - } - } - - return results.ToList(); - } - - private string Normalize(string part) - { - if (part == "0") return part; - if (part[0] == '0') return null; - byte temp = 0; - if (byte.TryParse(part, out temp)) - { - return part; - } - else - { - return null; - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md b/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md deleted file mode 100644 index 7d32fece..00000000 --- a/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal) - -[中文文档](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md) - -## Description - -

Given a binary tree, return the inorder traversal of its nodes' values.

- -

Example:

- -
-
-Input: [1,null,2,3]
-
-   1
-
-    \
-
-     2
-
-    /
-
-   3
-
-
-
-Output: [1,3,2]
- -

Follow up: Recursive solution is trivial, could you do it iteratively?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.py b/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.py deleted file mode 100644 index de46ab53..00000000 --- a/leetcode/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.py +++ /dev/null @@ -1,44 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -# 递归版本 -""" -class Solution: - def inorderTraversal(self, root): - """ - : type root: TreeNode - : rtype: List[int] - """ - def dp(node): - if not node: - return - dp(node.left) - ls.append(node.val) - dp(node.right) - ls=[] - dp(root) - return ls -""" - -# 非递归版本 -class Solution: - def inorderTraversal(self, root): - """ - :type root: TreeNode - :rtype: List[int] - """ - ls = [] - stack = [] - while root or stack: - while root: - stack.append(root) - root = root.left - if stack: - root = stack.pop(-1) - ls.append(root.val) - root = root.right - return ls diff --git a/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md b/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md deleted file mode 100644 index 38d43303..00000000 --- a/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [95. Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii) - -[中文文档](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md) - -## Description - -

Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.

- -

Example:

- -
-
-Input: 3
-
-Output:
-
-[
-
-  [1,null,3,2],
-
-  [3,2,null,1],
-
-  [3,1,null,null,2],
-
-  [2,1,3],
-
-  [1,null,2,null,3]
-
-]
-
-Explanation:
-
-The above output corresponds to the 5 unique BST's shown below:
-
-
-
-   1         3     3      2      1
-
-    \       /     /      / \      \
-
-     3     2     1      1   3      2
-
-    /     /       \                 \
-
-   2     1         2                 3
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.go b/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.go deleted file mode 100644 index 61810569..00000000 --- a/leetcode/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.go +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @lc app=leetcode.cn id=95 lang=golang - * Accepted - * 9/9 cases passed (28 ms) - * Your runtime beats 94 % of golang submissions - * Your memory usage beats 100 % of golang submissions (8 MB) - */ - -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - -type Pair struct { - a, b interface{} -} - -func generateTrees(n int) []*TreeNode { - if n < 1 { - return []*TreeNode{} - } - cache := make(map[Pair][]*TreeNode) - return createTrees(1, n, cache) -} - -func createTrees(start, end int, cache map[Pair][]*TreeNode) []*TreeNode { - var ret []*TreeNode - p := Pair{start, end} - if ret, ok := cache[p]; ok { - return ret - } - if start > end { - ret = []*TreeNode{nil} - cache[p] = ret - return ret - } - if start == end { - node := &TreeNode{ - Val: start, - Left: nil, - Right: nil, - } - ret = []*TreeNode{node} - cache[p] = ret - return ret - } - ret = make([]*TreeNode, 0) - for i := start; i <= end; i++ { - lefts := createTrees(start, i-1, cache) - rights := createTrees(i+1, end, cache) - for _, left := range lefts { - for _, right := range rights { - node := &TreeNode{ - Val: i, - Left: left, - Right: right, - } - ret = append(ret, node) - } - } - } - cache[p] = ret - return ret -} diff --git a/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md b/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md deleted file mode 100644 index 3b1132b7..00000000 --- a/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [96. Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees) - -[中文文档](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md) - -## Description - -

Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?

- -

Example:

- -
-
-Input: 3
-
-Output: 5
-
-Explanation:
-
-Given n = 3, there are a total of 5 unique BST's:
-
-
-
-   1         3     3      2      1
-
-    \       /     /      / \      \
-
-     3     2     1      1   3      2
-
-    /     /       \                 \
-
-   2     1         2                 3
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/Solution.py b/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/Solution.py deleted file mode 100644 index 73a710b1..00000000 --- a/leetcode/solution/0000-0099/0096.Unique Binary Search Trees/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def numTrees(self, n): - """ - :type n: int - :rtype: int - """ - res = [0] * (n + 1) - res[0] = 1 - for i in range(1, n + 1): - for j in range(i): - res[i] += res[j] * res[i - j - 1] - return res[n] diff --git a/leetcode/solution/0000-0099/0097.Interleaving String/README_EN.md b/leetcode/solution/0000-0099/0097.Interleaving String/README_EN.md deleted file mode 100644 index 20799ce2..00000000 --- a/leetcode/solution/0000-0099/0097.Interleaving String/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [97. Interleaving String](https://leetcode.com/problems/interleaving-string) - -[中文文档](/solution/0000-0099/0097.Interleaving%20String/README.md) - -## Description - -

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.

- -

Example 1:

- -
-
-Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
-
-Output: false
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0097.Interleaving String/Solution.cs b/leetcode/solution/0000-0099/0097.Interleaving String/Solution.cs deleted file mode 100644 index b1167ef2..00000000 --- a/leetcode/solution/0000-0099/0097.Interleaving String/Solution.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; - -public class Solution { - public bool IsInterleave(string s1, string s2, string s3) { - if (s1.Length + s2.Length != s3.Length) return false; - var f = new bool[s3.Length + 1, s1.Length + 1]; - f[0, 0] = true; - for (var i = 1; i <= s3.Length; ++i) - { - var j = Math.Max(0, i - s2.Length); - var k = i - j; - while (j <= s1.Length) - { - if (j > 0 && s3[i - 1] == s1[j - 1] && f[i - 1, j - 1]) - { - f[i, j] = true; - } - else if (k > 0 && s3[i - 1] == s2[k - 1] && f[i - 1, j]) - { - f[i, j] = true; - } - ++j; - --k; - } - } - - for (var i = 0; i <= s1.Length; ++i) - { - if (f[s3.Length, i]) return true; - } - return false; - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0097.Interleaving String/Solution.go b/leetcode/solution/0000-0099/0097.Interleaving String/Solution.go deleted file mode 100644 index 39bb279b..00000000 --- a/leetcode/solution/0000-0099/0097.Interleaving String/Solution.go +++ /dev/null @@ -1,23 +0,0 @@ -func isInterleave(s1 string, s2 string, s3 string) bool { - if len(s1)+len(s2) != len(s3) { - return false - } - n,m := len(s1), len(s2) - dp := make([][]bool, n+1) - for i := 0; i < len(dp); i++ { - dp[i] = make([]bool, m+1) - } - dp[0][0] = true - for i := 1; i <= n; i++ { - dp[i][0] = dp[i-1][0] && (s1[i-1] == s3[i-1]) - } - for i := 1; i <= m ; i++ { - dp[0][i] = dp[0][i-1] && (s2[i-1] == s3[i-1]) - } - for i := 1; i <= n; i++ { - for j := 1; j <= m; j++ { - dp[i][j] = dp[i-1][j] && (s1[i-1] == s3[i-1+j]) || dp[i][j-1] && (s2[j-1] == s3[i+j-1]) - } - } - return dp[n][m] -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md b/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md deleted file mode 100644 index ba166544..00000000 --- a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [98. Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree) - -[中文文档](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md) - -## Description - -

Given a binary tree, determine if it is a valid binary search tree (BST).

- -

Assume a BST is defined as follows:

- -
    -
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • -
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • -
  • Both the left and right subtrees must also be binary search trees.
  • -
- -

 

- -

Example 1:

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

Example 2:

- -
-
-    5
-
-   / \
-
-  1   4
-
-     / \
-
-    3   6
-
-
-
-Input: [5,1,4,null,null,3,6]
-
-Output: false
-
-Explanation: The root node's value is 5 but its right child's value is 4.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cpp b/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cpp deleted file mode 100644 index 8fffd05a..00000000 --- a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - - void traverse(TreeNode* root, vector &elements){ - - if( root->left != NULL ) - traverse(root->left, elements); - - elements.push_back(root->val); - - if( root->right != NULL ) - traverse(root->right, elements); - } - - bool isValidBST(TreeNode* root) { - - if( root == NULL ) - return true; - - vector elements; - traverse(root, elements); - - for(int i = 0 ; i < elements.size() - 1 ; i++) - if( elements[i] >= elements[i + 1] ) - return false; - - return true; - } -}; diff --git a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cs b/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cs deleted file mode 100644 index e5af22a0..00000000 --- a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.cs +++ /dev/null @@ -1,13 +0,0 @@ -public class Solution { - public bool IsValidBST(TreeNode root) { - return IsValidBstInternal(root, int.MinValue, int.MaxValue); - } - - private bool IsValidBstInternal(TreeNode root, int min, int max) - { - if (root == null) return true; - if (root.val < min || root.val > max) return false; - return (root.val == int.MinValue ? root.left == null : IsValidBstInternal(root.left, min, root.val - 1)) - && (root.val == int.MaxValue ? root.right == null : IsValidBstInternal(root.right, root.val + 1, max)); - } -} \ No newline at end of file diff --git a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js b/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js deleted file mode 100644 index e67552a7..00000000 --- a/leetcode/solution/0000-0099/0098.Validate Binary Search Tree/Solution.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {boolean} - */ -var isValidBST = function (root) { - if (root == null) return true; - let arr = []; - inOrderTraverse(root, arr); - for (let i = 0; i < arr.length - 1; i++) { - if (arr[i] >= arr[i + 1]) return false; - } - return true; -}; - -var inOrderTraverse = function (node, arr) { - if (node !== null) { - inOrderTraverse(node.left, arr); - arr.push(node.val); - inOrderTraverse(node.right, arr); - } -}; diff --git a/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md b/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md deleted file mode 100644 index 765a37ce..00000000 --- a/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md +++ /dev/null @@ -1,112 +0,0 @@ -# [99. Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree) - -[中文文档](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md) - -## Description - -

Two elements of a binary search tree (BST) are swapped by mistake.

- -

Recover the tree without changing its structure.

- -

Example 1:

- -
-
-Input: [1,3,null,null,2]
-
-
-
-   1
-
-  /
-
- 3
-
-  \
-
-   2
-
-
-
-Output: [3,1,null,null,2]
-
-
-
-   3
-
-  /
-
- 1
-
-  \
-
-   2
-
-
- -

Example 2:

- -
-
-Input: [3,1,4,null,null,2]
-
-
-
-  3
-
- / \
-
-1   4
-
-   /
-
-  2
-
-
-
-Output: [2,1,4,null,null,3]
-
-
-
-  2
-
- / \
-
-1   4
-
-   /
-
-  3
-
-
- -

Follow up:

- -
    -
  • A solution using O(n) space is pretty straight forward.
  • -
  • Could you devise a constant space solution?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/Solution.cs b/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/Solution.cs deleted file mode 100644 index d869c8ad..00000000 --- a/leetcode/solution/0000-0099/0099.Recover Binary Search Tree/Solution.cs +++ /dev/null @@ -1,62 +0,0 @@ -public class Solution { - private TreeNode last, first, second; - - public void RecoverTree(TreeNode root) { - Traverse(root); - var temp = first.val; - first.val = second.val; - second.val = temp; - } - - private void Traverse(TreeNode root) - { - var current = root; - TreeNode temp; - while (current != null) - { - if (current.left == null) - { - Visit(current); - current = current.right; - } - else - { - temp = current.left; - while (temp.right != null && temp.right != current) - { - temp = temp.right; - } - if (temp.right == null) - { - temp.right = current; - current = current.left; - } - else - { - Visit(current); - temp.right = null; - current = current.right; - } - } - } - } - - private void Visit(TreeNode node) - { - if (last != null) - { - if (node.val < last.val) - { - if (first == null) - { - first = last; - } - } - if (first != null && node.val < first.val) - { - second = node; - } - } - last = node; - } -} diff --git a/leetcode/solution/0100-0199/0100.Same Tree/README_EN.md b/leetcode/solution/0100-0199/0100.Same Tree/README_EN.md deleted file mode 100644 index caa045dc..00000000 --- a/leetcode/solution/0100-0199/0100.Same Tree/README_EN.md +++ /dev/null @@ -1,172 +0,0 @@ -# [100. Same Tree](https://leetcode.com/problems/same-tree) - -[中文文档](/solution/0100-0199/0100.Same%20Tree/README.md) - -## Description - -

Given two binary trees, write a function to check if they are the same or not.

- -

Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

- -

Example 1:

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

Example 2:

- -
-
-Input:     1         1
-
-          /           \
-
-         2             2
-
-
-
-        [1,2],     [1,null,2]
-
-
-
-Output: false
-
-
- -

Example 3:

- -
-
-Input:     1         1
-
-          / \       / \
-
-         2   1     1   2
-
-
-
-        [1,2,1],   [1,1,2]
-
-
-
-Output: false
-
-
- -## Solutions - - - -### **Python3** - -```python -# 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 p == q: - return True - if p is None or q is None or p.val != q.val: - return False - return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode() {} - * TreeNode(int val) { this.val = val; } - * TreeNode(int val, TreeNode left, TreeNode right) { - * this.val = val; - * this.left = left; - * this.right = right; - * } - * } - */ -class Solution { - public boolean isSameTree(TreeNode p, TreeNode q) { - if (p == q) return true; - if (p == null || q == null || p.val != q.val) return false; - return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); - } -} -``` - -### **C++** - -```cpp -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode() : val(0), left(nullptr), right(nullptr) {} - * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} - * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} - * }; - */ -class Solution { -public: - bool isSameTree(TreeNode* p, TreeNode* q) { - if (p == q) return true; - if (!p || !q || p->val != q->val) return false; - return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); - } -}; -``` - -### **Go** - -```go -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ -func isSameTree(p *TreeNode, q *TreeNode) bool { - if p == q { - return true - } - if p == nil || q == nil || p.Val != q.Val { - return false - } - return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right) -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0100.Same Tree/Solution.cpp b/leetcode/solution/0100-0199/0100.Same Tree/Solution.cpp deleted file mode 100644 index 6531df6c..00000000 --- a/leetcode/solution/0100-0199/0100.Same Tree/Solution.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode() : val(0), left(nullptr), right(nullptr) {} - * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} - * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} - * }; - */ -class Solution { -public: - bool isSameTree(TreeNode* p, TreeNode* q) { - if (p == q) return true; - if (!p || !q || p->val != q->val) return false; - return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0100.Same Tree/Solution.go b/leetcode/solution/0100-0199/0100.Same Tree/Solution.go deleted file mode 100644 index 9cca4202..00000000 --- a/leetcode/solution/0100-0199/0100.Same Tree/Solution.go +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - func isSameTree(p *TreeNode, q *TreeNode) bool { - if p == q { - return true - } - if p == nil || q == nil || p.Val != q.Val { - return false - } - return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right) -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0100.Same Tree/Solution.py b/leetcode/solution/0100-0199/0100.Same Tree/Solution.py deleted file mode 100644 index 497b2139..00000000 --- a/leetcode/solution/0100-0199/0100.Same Tree/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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 p == q: - return True - if p is None or q is None or p.val != q.val: - return False - return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) diff --git a/leetcode/solution/0100-0199/0101.Symmetric Tree/README_EN.md b/leetcode/solution/0100-0199/0101.Symmetric Tree/README_EN.md deleted file mode 100644 index 7d1ab3ce..00000000 --- a/leetcode/solution/0100-0199/0101.Symmetric Tree/README_EN.md +++ /dev/null @@ -1,128 +0,0 @@ -# [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree) - -[中文文档](/solution/0100-0199/0101.Symmetric%20Tree/README.md) - -## Description - -

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

- -

For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

- -
-
-    1
-
-   / \
-
-  2   2
-
- / \ / \
-
-3  4 4  3
-
-
- -

 

- -

But the following [1,2,2,null,3,null,3] is not:

- -
-
-    1
-
-   / \
-
-  2   2
-
-   \   \
-
-   3    3
-
-
- -

 

- -

Note:
- -Bonus points if you could solve it both recursively and iteratively.

- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def isSymmetric(self, root: TreeNode) -> bool: - if root is None: - return True - return self.is_symmetric(root.left, root.right) - - def is_symmetric(self, left: TreeNode, right: TreeNode) -> bool: - if left is None and right is None: - return True - if left is None or right is None or left.val != right.val: - return False - return self.is_symmetric(left.left, right.right) and self.is_symmetric(left.right, right.left) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public boolean isSymmetric(TreeNode root) { - if (root == null) return true; - return isSymmetric(root.left, root.right); - } - - private boolean isSymmetric(TreeNode left, TreeNode right) { - if (left == null && right == null) return true; - if (left == null || right == null || left.val != right.val) return false; - return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left); - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - bool isSymmetric(TreeNode* root) { - if (!root) return true; - return isSymmetric(root->left, root->right); - } - -private: - bool isSymmetric(TreeNode* left, TreeNode* right) { - if (!left && !right) return true; - if (!left && right || left && !right || left->val != right->val) return false; - return isSymmetric(left->left, right->right) && isSymmetric(left->right, right->left); - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.cpp b/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.cpp deleted file mode 100644 index 6d577db1..00000000 --- a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - bool isSymmetric(TreeNode* root) { - if (!root) return true; - return isSymmetric(root->left, root->right); - } - -private: - bool isSymmetric(TreeNode* left, TreeNode* right) { - if (!left && !right) return true; - if (!left && right || left && !right || left->val != right->val) return false; - return isSymmetric(left->left, right->right) && isSymmetric(left->right, right->left); - } -}; diff --git a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.js b/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.js deleted file mode 100644 index e15f1cc0..00000000 --- a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {boolean} - */ -var isSymmetric = function (root) { - if (!root) return true; - return checkSymmetric(root.left, root.right); -}; - -const checkSymmetric = function (leftNode, rightNode) { - if (!leftNode && !rightNode) return true; - if (!leftNode || !rightNode) return false; - return ( - leftNode.val === rightNode.val && - checkSymmetric(leftNode.left, rightNode.right) && - checkSymmetric(rightNode.left, leftNode.right) - ); -}; diff --git a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.py b/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.py deleted file mode 100644 index 5105baf6..00000000 --- a/leetcode/solution/0100-0199/0101.Symmetric Tree/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def isSymmetric(self, root: TreeNode) -> bool: - if root is None: - return True - return self.is_symmetric(root.left, root.right) - - def is_symmetric(self, left: TreeNode, right: TreeNode) -> bool: - if left is None and right is None: - return True - if left is None or right is None or left.val != right.val: - return False - return self.is_symmetric(left.left, right.right) and self.is_symmetric(left.right, right.left) diff --git a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md b/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md deleted file mode 100644 index 255962a7..00000000 --- a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/README_EN.md +++ /dev/null @@ -1,160 +0,0 @@ -# [102. Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal) - -[中文文档](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md) - -## Description - -

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

- -

- -For example:
- -Given binary tree [3,9,20,null,null,15,7],
- -

-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
- -

- -

- -return its level order traversal as:
- -

-
-[
-
-  [3],
-
-  [9,20],
-
-  [15,7]
-
-]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrder(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - res = [] - q = [] - q.append(root) - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.pop(0) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - t.append(node.val) - res.append(t) - return res -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public List> levelOrder(TreeNode root) { - if (root == null) return Collections.emptyList(); - Deque q = new ArrayDeque<>(); - q.offer(root); - List> res = new ArrayList<>(); - while (!q.isEmpty()) { - int size = q.size(); - List t = new ArrayList<>(); - while (size-- > 0) { - TreeNode node = q.poll(); - t.add(node.val); - if (node.left != null) q.offer(node.left); - if (node.right != null) q.offer(node.right); - } - res.add(t); - } - return res; - } -} -``` - -### **C++** - -```cpp -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - vector> levelOrder(TreeNode* root) { - if (!root) return {}; - vector> res; - queue q{{root}}; - while (!q.empty()) { - vector oneLevel; - for (int i = q.size(); i > 0; --i) { - TreeNode* t = q.front(); - q.pop(); - oneLevel.push_back(t->val); - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - res.push_back(oneLevel); - } - return res; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.cpp b/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.cpp deleted file mode 100644 index df8b014c..00000000 --- a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - vector> levelOrder(TreeNode* root) { - if (!root) return {}; - vector> res; - queue q{{root}}; - while (!q.empty()) { - vector oneLevel; - for (int i = q.size(); i > 0; --i) { - TreeNode* t = q.front(); - q.pop(); - oneLevel.push_back(t->val); - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - res.push_back(oneLevel); - } - return res; - } -}; diff --git a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js b/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js deleted file mode 100644 index 9826cd6c..00000000 --- a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number[][]} - */ -var levelOrder = function (root) { - let result = []; - if (!root) return result; - - let queue = []; - queue.push(root); - while (queue.length) { - let size = queue.length; - let levelItems = []; - while (size--) { - let node = queue.shift(); - levelItems.push(node.val); - if (node.left) { - queue.push(node.left); - } - if (node.right) { - queue.push(node.right); - } - } - result.push(levelItems); - } - return result; -}; diff --git a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.py b/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.py deleted file mode 100644 index a446b8ba..00000000 --- a/leetcode/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.py +++ /dev/null @@ -1,26 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrder(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - res = [] - q = [] - q.append(root) - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.pop(0) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - t.append(node.val) - res.append(t) - return res diff --git a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md b/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md deleted file mode 100644 index 4e3f8261..00000000 --- a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [103. Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) - -[中文文档](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md) - -## Description - -

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).

- -

- -For example:
- -Given binary tree [3,9,20,null,null,15,7],
- -

-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
- -

- -

- -return its zigzag level order traversal as:
- -

-
-[
-
-  [3],
-
-  [20,9],
-
-  [15,7]
-
-]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.cpp b/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.cpp deleted file mode 100644 index a2c74e68..00000000 --- a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - vector> zigzagLevelOrder(TreeNode* root) { - if (!root) return {}; - vector> res; - queue q{{root}}; - bool leftToRight = true; - while (!q.empty()) { - int size = q.size(); - vector oneLevel(size); - for (int i = 0; i < size; ++i) { - TreeNode* t = q.front(); - q.pop(); - int idx = leftToRight ? i : (size - 1 - i); - oneLevel[idx] = t->val; - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - leftToRight = !leftToRight; - res.push_back(oneLevel); - } - return res; - } -}; diff --git a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.py b/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.py deleted file mode 100644 index a891f03d..00000000 --- a/leetcode/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.py +++ /dev/null @@ -1,41 +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 zigzagLevelOrder(self, root): - """ - :type root: TreeNode - :rtype: List[List[int]] - """ - zuo = [] - you = [] - if root is None: - return [] - zuo.append(root) - ans = [] - while zuo or you: - tmp = [] - while zuo: - if zuo[0].left is not None: - you.append(zuo[0].left) - if zuo[0].right is not None: - you.append(zuo[0].right) - tmp.append(zuo[0].val) - zuo.pop(0) - ans.append(tmp) - tmp = [] - while you: - if you[-1].right is not None: - zuo.insert(0, you[-1].right) - if you[-1].left is not None: - zuo.insert(0, you[-1].left) - tmp.append(you[-1].val) - you.pop(-1) - if tmp: - ans.append(tmp) - return ans diff --git a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md b/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md deleted file mode 100644 index d0b87566..00000000 --- a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/README_EN.md +++ /dev/null @@ -1,101 +0,0 @@ -# [104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) - -[中文文档](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md) - -## Description - -

Given a binary tree, find its maximum depth.

- -

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

- -

Note: A leaf is a node with no children.

- -

Example:

- -

Given binary tree [3,9,20,null,null,15,7],

- -
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
- -

return its depth = 3.

- -## Solutions - - - -### **Python3** - -```python -# 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: TreeNode) -> int: - if root is None: - return 0 - l = self.maxDepth(root.left) - r = self.maxDepth(root.right) - return 1 + max(l, r) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode() {} - * TreeNode(int val) { this.val = val; } - * TreeNode(int val, TreeNode left, TreeNode right) { - * this.val = val; - * this.left = left; - * this.right = right; - * } - * } - */ -class Solution { - public int maxDepth(TreeNode root) { - if (root == null) return 0; - int l = maxDepth(root.left); - int r = maxDepth(root.right); - return 1 + Math.max(l, r); - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - int maxDepth(TreeNode* root) { - if (!root) return 0; - int l = maxDepth(root->left); - int r = maxDepth(root->right); - return max(l, r) + 1; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.cpp b/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.cpp deleted file mode 100644 index 7776c044..00000000 --- a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.cpp +++ /dev/null @@ -1,9 +0,0 @@ -class Solution { -public: - int maxDepth(TreeNode* root) { - if (!root) return 0; - int l = maxDepth(root->left); - int r = maxDepth(root->right); - return max(l, r) + 1; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js b/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js deleted file mode 100644 index 36003284..00000000 --- a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {number} - */ -var maxDepth = function (root) { - if (!root) return 0; - let depth = 1; - return search(root, depth); -}; - -function search(root, depth) { - if (!root.left && !root.right) { - return depth; - } else if (root.left && !root.right) { - return search(root.left, depth + 1); - } else if (root.right && !root.left) { - return search(root.right, depth + 1); - } else if (root.left && root.right) { - return Math.max( - search(root.left, depth + 1), - search(root.right, depth + 1) - ); - } -} - -var maxDepth2 = function (root) { - if (!root) return 0; - return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; -}; diff --git a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.py b/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.py deleted file mode 100644 index 9fe63659..00000000 --- a/leetcode/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -# 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: TreeNode) -> int: - if root is None: - return 0 - l = self.maxDepth(root.left) - r = self.maxDepth(root.right) - return 1 + max(l, r) diff --git a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md b/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md deleted file mode 100644 index ca085c31..00000000 --- a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md +++ /dev/null @@ -1,108 +0,0 @@ -# [105. Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) - -[中文文档](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md) - -## Description - -

Given preorder and inorder traversal of a tree, construct the binary tree.

- -

Note:
- -You may assume that duplicates do not exist in the tree.

- -

For example, given

- -
-
-preorder = [3,9,20,15,7]
-
-inorder = [9,3,15,20,7]
- -

Return the following binary tree:

- -
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - indexes = {} - def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: - def build(preorder, inorder, p1, p2, i1, i2) -> TreeNode: - if p1 > p2 or i1 > i2: - return None - root_val = preorder[p1] - pos = self.indexes[root_val] - root = TreeNode(root_val) - root.left = None if pos == i1 else build(preorder, inorder, p1 + 1, p1 - i1 + pos, i1, pos - 1) - root.right = None if pos == i2 else build(preorder, inorder, p1 - i1 + pos + 1, p2, pos + 1, i2) - return root - n = len(inorder) - for i in range(n): - self.indexes[inorder[i]] = i - return build(preorder, inorder, 0, n - 1, 0, n - 1) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - private Map indexes = new HashMap<>(); - - public TreeNode buildTree(int[] preorder, int[] inorder) { - int n = inorder.length; - for (int i = 0; i < n; ++i) { - indexes.put(inorder[i], i); - } - return build(preorder, inorder, 0, n - 1, 0, n - 1); - } - - private TreeNode build(int[] preorder, int[] inorder, int p1, int p2, int i1, int i2) { - if (p1 > p2 || i1 > i2) return null; - int rootVal = preorder[p1]; - int pos = indexes.get(rootVal); - TreeNode node = new TreeNode(rootVal); - node.left = pos == i1 ? null : build(preorder, inorder, p1 + 1, pos - i1 + p1, i1, pos - 1); - node.right = pos == i2 ? null : build(preorder, inorder, pos - i1 + p1 + 1, p2, pos + 1, i2); - return node; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.cpp b/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.cpp deleted file mode 100644 index 49c605d2..00000000 --- a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - TreeNode* buildTree(vector& preorder, vector& inorder) { - int pRight = preorder.size()-1; - int iRight = inorder.size()-1; - return build(preorder,inorder,0,pRight,0,iRight); - } - - - TreeNode* build(vector& preorder,vector& inorder,int pLeft,int pRight,int iLeft,int iRight){ - if(pLeft > pRight)return NULL; - - TreeNode *node = new TreeNode(preorder[pLeft]); - int idx = iLeft; - - while(inorder[idx] != preorder[pLeft])idx++; - node->left = build(preorder,inorder,pLeft+1,pLeft+idx-iLeft,iLeft,idx-1); - node->right = build(preorder,inorder,pLeft+idx-iLeft+1,pRight,idx+1,iRight); - return node; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.py b/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.py deleted file mode 100644 index ede88e1a..00000000 --- a/leetcode/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - indexes = {} - def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: - def build(preorder, inorder, p1, p2, i1, i2) -> TreeNode: - if p1 > p2 or i1 > i2: - return None - root_val = preorder[p1] - pos = self.indexes[root_val] - root = TreeNode(root_val) - root.left = None if pos == i1 else build(preorder, inorder, p1 + 1, p1 - i1 + pos, i1, pos - 1) - root.right = None if pos == i2 else build(preorder, inorder, p1 - i1 + pos + 1, p2, pos + 1, i2) - return root - n = len(inorder) - for i in range(n): - self.indexes[inorder[i]] = i - return build(preorder, inorder, 0, n - 1, 0, n - 1) diff --git a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md b/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md deleted file mode 100644 index 42363f68..00000000 --- a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/README_EN.md +++ /dev/null @@ -1,133 +0,0 @@ -# [106. Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) - -[中文文档](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md) - -## Description - -

Given inorder and postorder traversal of a tree, construct the binary tree.

- -

Note:
- -You may assume that duplicates do not exist in the tree.

- -

For example, given

- -
-
-inorder = [9,3,15,20,7]
-
-postorder = [9,15,7,20,3]
- -

Return the following binary tree:

- -
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - indexes = {} - def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: - def build(inorder, postorder, i1, i2, p1, p2): - if i1 > i2 or p1 > p2: - return None - root_val = postorder[p2] - pos = self.indexes[root_val] - root = TreeNode(root_val) - root.left = None if pos == i1 else build(inorder, postorder, i1, pos - 1, p1, p1 - i1 + pos - 1) - root.right = None if pos == i2 else build(inorder, postorder, pos + 1, i2, p1 - i1 + pos, p2 - 1) - return root - n = len(inorder) - for i in range(n): - self.indexes[inorder[i]] = i - return build(inorder, postorder, 0, n - 1, 0, n - 1) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - private Map indexes = new HashMap<>(); - - public TreeNode buildTree(int[] inorder, int[] postorder) { - int n = inorder.length; - for (int i = 0; i < n; ++i) { - indexes.put(inorder[i], i); - } - return build(inorder, postorder, 0, inorder.length - 1, 0, postorder.length - 1); - } - - private TreeNode build(int[] inorder, int[] postorder, int i1, int i2, int p1, int p2) { - if (i1 > i2 || p1 > p2) return null; - int rootVal = postorder[p2]; - int pos = indexes.get(rootVal); - TreeNode root = new TreeNode(rootVal); - root.left = pos == i1 ? null : build(inorder, postorder, i1, pos - 1, p1, p1 - i1 + pos - 1); - root.right = pos == i2 ? null : build(inorder, postorder, pos + 1, i2, p1 - i1 + pos, p2 - 1); - return root; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - TreeNode *buildTree(vector &inorder, vector &postorder) { - return buildTree(inorder, 0, inorder.size() - 1, postorder, 0, postorder.size() - 1); - } - TreeNode *buildTree(vector &inorder, int iLeft, int iRight, vector &postorder, int pLeft, int pRight) { - if (iLeft > iRight || pLeft > pRight) return NULL; - TreeNode *cur = new TreeNode(postorder[pRight]); - int i = 0; - for (i = iLeft; i < inorder.size(); ++i) { - if (inorder[i] == cur->val) - break; - } - cur->left = buildTree(inorder, iLeft, i - 1, postorder, pLeft, pLeft + i - iLeft - 1); - cur->right = buildTree(inorder, i + 1, iRight, postorder, pLeft + i - iLeft, pRight - 1); - return cur; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.cpp b/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.cpp deleted file mode 100644 index 50119b1c..00000000 --- a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.cpp +++ /dev/null @@ -1,18 +0,0 @@ -class Solution { -public: - TreeNode *buildTree(vector &inorder, vector &postorder) { - return buildTree(inorder, 0, inorder.size() - 1, postorder, 0, postorder.size() - 1); - } - TreeNode *buildTree(vector &inorder, int iLeft, int iRight, vector &postorder, int pLeft, int pRight) { - if (iLeft > iRight || pLeft > pRight) return NULL; - TreeNode *cur = new TreeNode(postorder[pRight]); - int i = 0; - for (i = iLeft; i < inorder.size(); ++i) { - if (inorder[i] == cur->val) - break; - } - cur->left = buildTree(inorder, iLeft, i - 1, postorder, pLeft, pLeft + i - iLeft - 1); - cur->right = buildTree(inorder, i + 1, iRight, postorder, pLeft + i - iLeft, pRight - 1); - return cur; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.py b/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.py deleted file mode 100644 index 6aa6b84d..00000000 --- a/leetcode/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - indexes = {} - def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: - def build(inorder, postorder, i1, i2, p1, p2): - if i1 > i2 or p1 > p2: - return None - root_val = postorder[p2] - pos = self.indexes[root_val] - root = TreeNode(root_val) - root.left = None if pos == i1 else build(inorder, postorder, i1, pos - 1, p1, p1 - i1 + pos - 1) - root.right = None if pos == i2 else build(inorder, postorder, pos + 1, i2, p1 - i1 + pos, p2 - 1) - return root - n = len(inorder) - for i in range(n): - self.indexes[inorder[i]] = i - return build(inorder, postorder, 0, n - 1, 0, n - 1) diff --git a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md b/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md deleted file mode 100644 index 929d519a..00000000 --- a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/README_EN.md +++ /dev/null @@ -1,125 +0,0 @@ -# [107. Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) - -[中文文档](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md) - -## Description - -

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).

- -

- -For example:
- -Given binary tree [3,9,20,null,null,15,7],
- -

-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
- -

- -

- -return its bottom-up level order traversal as:
- -

-
-[
-
-  [15,7],
-
-  [9,20],
-
-  [3]
-
-]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrderBottom(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - q = [root] - res = [] - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.pop(0) - t.append(node.val) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - res.append(t) - return res[::-1] -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public List> levelOrderBottom(TreeNode root) { - if (root == null) return Collections.emptyList(); - Deque q = new ArrayDeque<>(); - List> res = new ArrayList<>(); - q.offer(root); - while (!q.isEmpty()) { - int size = q.size(); - List t = new ArrayList<>(); - while (size-- > 0) { - TreeNode node = q.poll(); - t.add(node.val); - if (node.left != null) q.offer(node.left); - if (node.right != null) q.offer(node.right); - } - res.add(0, t); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.cpp b/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.cpp deleted file mode 100644 index 199811f2..00000000 --- a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - vector > levelOrderBottom(TreeNode* root) { - if (!root) return {}; - vector> res; - queue q{{root}}; - while (!q.empty()) { - vector oneLevel; - for (int i = q.size(); i > 0; --i) { - TreeNode *t = q.front(); - q.pop(); - oneLevel.push_back(t->val); - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - res.insert(res.begin(), oneLevel); - } - return res; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.py b/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.py deleted file mode 100644 index 19127601..00000000 --- a/leetcode/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.py +++ /dev/null @@ -1,25 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def levelOrderBottom(self, root: TreeNode) -> List[List[int]]: - if root is None: - return [] - q = [root] - res = [] - while q: - size = len(q) - t = [] - for _ in range(size): - node = q.pop(0) - t.append(node.val) - if node.left is not None: - q.append(node.left) - if node.right is not None: - q.append(node.right) - res.append(t) - return res[::-1] diff --git a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md b/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md deleted file mode 100644 index 76cde842..00000000 --- a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) - -[中文文档](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md) - -## Description - -

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

- -

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

- -

Example:

- -
-
-Given the sorted array: [-10,-3,0,5,9],
-
-
-
-One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:
-
-
-
-      0
-
-     / \
-
-   -3   9
-
-   /   /
-
- -10  5
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.cpp b/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.cpp deleted file mode 100644 index b0330165..00000000 --- a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - TreeNode* sortedArrayToBST(vector& nums) { - return helper(nums, 0, nums.size() - 1); - } - -private: - TreeNode* helper(vector &nums, int left, int right) { - if (left > right) return nullptr; - int mid = left + (right - left) / 2; - TreeNode *cur = new TreeNode(nums[mid]); - cur->left = helper(nums, left, mid - 1); - cur->right = helper(nums, mid + 1, right); - return cur; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js b/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js deleted file mode 100644 index 6ef60dc3..00000000 --- a/leetcode/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {number[]} nums - * @return {TreeNode} - */ -var sortedArrayToBST = function (nums) { - return nums ? buildTree(nums, 0, nums.length - 1) : null; -}; - -const buildTree = function (nums, left, right) { - if (left > right) return null; - let mid = Math.floor((left + right) / 2); - let root = new TreeNode(nums[mid]); - root.left = buildTree(nums, left, mid - 1); - root.right = buildTree(nums, mid + 1, right); - return root; -}; diff --git a/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md b/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md deleted file mode 100644 index 20924e67..00000000 --- a/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [109. Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) - -[中文文档](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md) - -## Description - -

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

- -

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

- -

Example:

- -
-
-Given the sorted linked list: [-10,-3,0,5,9],
-
-
-
-One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:
-
-
-
-      0
-
-     / \
-
-   -3   9
-
-   /   /
-
- -10  5
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.cpp b/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.cpp deleted file mode 100644 index 96671a35..00000000 --- a/leetcode/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.cpp +++ /dev/null @@ -1,19 +0,0 @@ -class Solution { -public: - TreeNode* sortedListToBST(ListNode* head) { - if (!head) return nullptr; - if (!head->next) return new TreeNode(head->val); - ListNode *fast = head, *slow = head, *last = slow; - while (fast->next && fast->next->next) { - last = slow; - slow = slow->next; - fast = fast->next->next; - } - fast = slow->next; - last->next = nullptr; - TreeNode *cur = new TreeNode(slow->val); - if (head != slow) cur->left = sortedListToBST(head); - cur->right = sortedListToBST(fast); - return cur; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md b/leetcode/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md deleted file mode 100644 index 619c4ff0..00000000 --- a/leetcode/solution/0100-0199/0110.Balanced Binary Tree/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [110. Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) - -[中文文档](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md) - -## Description - -

Given a binary tree, determine if it is height-balanced.

- -

For this problem, a height-balanced binary tree is defined as:

- -
-

a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

-
- -

 

- -

Example 1:

- -

Given the following tree [3,9,20,null,null,15,7]:

- -
-    3
-   / \
-  9  20
-    /  \
-   15   7
- -

Return true.
-
-Example 2:

- -

Given the following tree [1,2,2,3,3,null,null,4,4]:

- -
-       1
-      / \
-     2   2
-    / \
-   3   3
-  / \
- 4   4
-
- -

Return false.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp b/leetcode/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp deleted file mode 100644 index 0578b11f..00000000 --- a/leetcode/solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - bool isBalanced(TreeNode* root) { - if (!root) return true; - if (abs(getDepth(root->left) - getDepth(root->right)) > 1) return false; - return isBalanced(root->left) && isBalanced(root->right); - } - -private: - int getDepth(TreeNode *root) { - if (!root) return 0; - return 1 + max(getDepth(root->left), getDepth(root->right)); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md b/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md deleted file mode 100644 index b86c9436..00000000 --- a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [111. Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree) - -[中文文档](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md) - -## Description - -

Given a binary tree, find its minimum depth.

- -

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

- -

Note: A leaf is a node with no children.

- -

Example:

- -

Given binary tree [3,9,20,null,null,15,7],

- -
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
- -

return its minimum depth = 2.

- -## Solutions - - - -### **Python3** - -```python -# 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: TreeNode) -> int: - if root is None: - return 0 - if root.left is None and root.right is None: - return 1 - l = self.minDepth(root.left) - r = self.minDepth(root.right) - # 如果左子树和右子树其中一个为空,那么需要返回比较大的那个子树的深度 - if root.left is None or root.right is None: - return l + r + 1 - # 左右子树都不为空,返回最小深度+1即可 - return min(l, r) + 1 -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode() {} - * TreeNode(int val) { this.val = val; } - * TreeNode(int val, TreeNode left, TreeNode right) { - * this.val = val; - * this.left = left; - * this.right = right; - * } - * } - */ -class Solution { - public int minDepth(TreeNode root) { - if (root == null) return 0; - if (root.left == null && root.right == null) return 1; - int l = minDepth(root.left); - int r = minDepth(root.right); - if (root.left == null || root.right == null) return l + r + 1; - return Math.min(l, r) + 1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp b/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp deleted file mode 100644 index 6dbe2254..00000000 --- a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.cpp +++ /dev/null @@ -1,9 +0,0 @@ -class Solution { -public: - int minDepth(TreeNode* root) { - if (!root) return 0; - if (!root->left) return 1 + minDepth(root->right); - if (!root->right) return 1 + minDepth(root->left); - return 1 + min(minDepth(root->left), minDepth(root->right)); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.py b/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.py deleted file mode 100644 index 20999090..00000000 --- a/leetcode/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -# 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: TreeNode) -> int: - if root is None: - return 0 - if root.left is None and root.right is None: - return 1 - l = self.minDepth(root.left) - r = self.minDepth(root.right) - # 如果左子树和右子树其中一个为空,那么需要返回比较大的那个子树的深度 - if root.left is None or root.right is None: - return l + r + 1 - # 左右子树都不为空,返回最小深度+1即可 - return min(l, r) + 1 diff --git a/leetcode/solution/0100-0199/0112.Path Sum/README_EN.md b/leetcode/solution/0100-0199/0112.Path Sum/README_EN.md deleted file mode 100644 index b8fb608e..00000000 --- a/leetcode/solution/0100-0199/0112.Path Sum/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [112. Path Sum](https://leetcode.com/problems/path-sum) - -[中文文档](/solution/0100-0199/0112.Path%20Sum/README.md) - -## Description - -

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

- -

Note: A leaf is a node with no children.

- -

Example:

- -

Given the below binary tree and sum = 22,

- -
-
-      5
-
-     / \
-
-    4   8
-
-   /   / \
-
-  11  13  4
-
- /  \      \
-
-7    2      1
-
-
- -

return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def hasPathSum(self, root: TreeNode, sum: int) -> bool: - def dfs(root, sum): - if root is None: - return False - if root.val == sum and root.left is None and root.right is None: - return True - return dfs(root.left, sum - root.val) or dfs(root.right, sum - root.val) - return dfs(root, sum) -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public boolean hasPathSum(TreeNode root, int sum) { - return dfs(root, sum); - } - - private boolean dfs(TreeNode root, int sum) { - if (root == null) return false; - if (root.val == sum && root.left == null && root.right == null) return true; - return dfs(root.left, sum - root.val) || dfs(root.right, sum - root.val); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0112.Path Sum/Solution.cpp b/leetcode/solution/0100-0199/0112.Path Sum/Solution.cpp deleted file mode 100644 index 642a3713..00000000 --- a/leetcode/solution/0100-0199/0112.Path Sum/Solution.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - bool hasPathSum(TreeNode* root, int sum) { - - if(root == NULL)return false; - if(root->right == NULL && root->left == NULL && sum == root->val)return true; - - bool leftTrue = hasPathSum(root->left,sum - root->val); - bool rightTrue = hasPathSum(root->right,sum - root->val); - - return (leftTrue || rightTrue); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0112.Path Sum/Solution.py b/leetcode/solution/0100-0199/0112.Path Sum/Solution.py deleted file mode 100644 index 5a32e066..00000000 --- a/leetcode/solution/0100-0199/0112.Path Sum/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def hasPathSum(self, root: TreeNode, sum: int) -> bool: - def dfs(root, sum): - if root is None: - return False - if root.val == sum and root.left is None and root.right is None: - return True - return dfs(root.left, sum - root.val) or dfs(root.right, sum - root.val) - return dfs(root, sum) diff --git a/leetcode/solution/0100-0199/0113.Path Sum II/README_EN.md b/leetcode/solution/0100-0199/0113.Path Sum II/README_EN.md deleted file mode 100644 index 870f7ff7..00000000 --- a/leetcode/solution/0100-0199/0113.Path Sum II/README_EN.md +++ /dev/null @@ -1,123 +0,0 @@ -# [113. Path Sum II](https://leetcode.com/problems/path-sum-ii) - -[中文文档](/solution/0100-0199/0113.Path%20Sum%20II/README.md) - -## Description - -

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.

- -

Note: A leaf is a node with no children.

- -

Example:

- -

Given the below binary tree and sum = 22,

- -
-
-      5
-
-     / \
-
-    4   8
-
-   /   / \
-
-  11  13  4
-
- /  \    / \
-
-7    2  5   1
-
-
- -

Return:

- -
-
-[
-
-   [5,4,11,2],
-
-   [5,8,4,5]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: - def dfs(root, sum): - if root is None: - return - path.append(root.val) - if root.val == sum and root.left is None and root.right is None: - res.append(path.copy()) - dfs(root.left, sum - root.val) - dfs(root.right, sum - root.val) - path.pop() - if not root: - return [] - res = [] - path = [] - dfs(root, sum) - return res -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - private List> res; - private List path; - - public List> pathSum(TreeNode root, int sum) { - if (root == null) return Collections.emptyList(); - res = new ArrayList<>(); - path = new ArrayList<>(); - dfs(root, sum); - return res; - } - - private void dfs(TreeNode root, int sum) { - if (root == null) return; - path.add(root.val); - if (root.val == sum && root.left == null && root.right == null) { - res.add(new ArrayList<>(path)); - } - dfs(root.left, sum - root.val); - dfs(root.right, sum - root.val); - path.remove(path.size() - 1); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0113.Path Sum II/Solution.cpp b/leetcode/solution/0100-0199/0113.Path Sum II/Solution.cpp deleted file mode 100644 index 402c7f26..00000000 --- a/leetcode/solution/0100-0199/0113.Path Sum II/Solution.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - vector> pathSum(TreeNode* root, int sum) { - vector> res; - vector out; - helper(root, sum, out, res); - return res; - } - -private: - void helper(TreeNode *node, int sum, vector &out, vector> &res) { - if (!node) return; - out.push_back(node->val); - if (sum == node->val && !node->left && !node->right) { - res.push_back(out); - } - helper(node->left, sum - node->val, out, res); - helper(node->right, sum - node->val, out, res); - out.pop_back(); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0113.Path Sum II/Solution.py b/leetcode/solution/0100-0199/0113.Path Sum II/Solution.py deleted file mode 100644 index 09d0a99f..00000000 --- a/leetcode/solution/0100-0199/0113.Path Sum II/Solution.py +++ /dev/null @@ -1,24 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: - def dfs(root, sum): - if root is None: - return - path.append(root.val) - if root.val == sum and root.left is None and root.right is None: - res.append(path.copy()) - dfs(root.left, sum - root.val) - dfs(root.right, sum - root.val) - path.pop() - if not root: - return [] - res = [] - path = [] - dfs(root, sum) - return res diff --git a/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md b/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md deleted file mode 100644 index 3ed856de..00000000 --- a/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [114. Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) - -[中文文档](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md) - -## Description - -

Given a binary tree, flatten it to a linked list in-place.

- -

For example, given the following tree:

- -
-
-    1
-
-   / \
-
-  2   5
-
- / \   \
-
-3   4   6
-
-
- -

The flattened tree should look like:

- -
-
-1
-
- \
-
-  2
-
-   \
-
-    3
-
-     \
-
-      4
-
-       \
-
-        5
-
-         \
-
-          6
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.cpp b/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.cpp deleted file mode 100644 index 0ba48e22..00000000 --- a/leetcode/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - void flatten(TreeNode* root) { - TreeNode* cur = root; - while (cur) { - if (cur->left) { - TreeNode* p = cur->left; - while (p->right) p = p->right; - p->right = cur->right; - cur->right = cur->left; - cur->left = nullptr; - } - cur = cur->right; - } - } -}; diff --git a/leetcode/solution/0100-0199/0115.Distinct Subsequences/README_EN.md b/leetcode/solution/0100-0199/0115.Distinct Subsequences/README_EN.md deleted file mode 100644 index 2203e083..00000000 --- a/leetcode/solution/0100-0199/0115.Distinct Subsequences/README_EN.md +++ /dev/null @@ -1,105 +0,0 @@ -# [115. Distinct Subsequences](https://leetcode.com/problems/distinct-subsequences) - -[中文文档](/solution/0100-0199/0115.Distinct%20Subsequences/README.md) - -## Description - -

Given a string S and a string T, count the number of distinct subsequences of S which equals T.

- -

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).

- -

Example 1:

- -
-
-Input: S = "rabbbit", T = "rabbit"
-
-Output: 3
-
-Explanation:
-
-
-
-As shown below, there are 3 ways you can generate "rabbit" from S.
-
-(The caret symbol ^ means the chosen letters)
-
-
-
-rabbbit
-
-^^^^ ^^
-
-rabbbit
-
-^^ ^^^^
-
-rabbbit
-
-^^^ ^^^
-
-
- -

Example 2:

- -
-
-Input: S = "babgbag", T = "bag"
-
-Output: 5
-
-Explanation:
-
-
-
-As shown below, there are 5 ways you can generate "bag" from S.
-
-(The caret symbol ^ means the chosen letters)
-
-
-
-babgbag
-
-^^ ^
-
-babgbag
-
-^^    ^
-
-babgbag
-
-^    ^^
-
-babgbag
-
-  ^  ^^
-
-babgbag
-
-    ^^^
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0115.Distinct Subsequences/Solution.cpp b/leetcode/solution/0100-0199/0115.Distinct Subsequences/Solution.cpp deleted file mode 100644 index a34e169b..00000000 --- a/leetcode/solution/0100-0199/0115.Distinct Subsequences/Solution.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int numDistinct(string s, string t) { - int m = s.size(), n = t.size(); - vector> dp(n + 1, vector(m + 1)); - for (int j = 0; j <= m; ++j) dp[0][j] = 1; - for (int i = 1; i <= n; ++i) { - for (int j = 1; j <= m; ++j) { - dp[i][j] = dp[i][j - 1] + (t[i - 1] == s[j - 1] ? dp[i - 1][j - 1] : 0); - } - } - return dp[n][m]; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md b/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md deleted file mode 100644 index c135cdc2..00000000 --- a/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [116. Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) - -[中文文档](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md) - -## Description - -

You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

- -
-struct Node {
-  int val;
-  Node *left;
-  Node *right;
-  Node *next;
-}
-
- -

Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

- -

Initially, all next pointers are set to NULL.

- -

 

- -

Follow up:

- -
    -
  • You may only use constant extra space.
  • -
  • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
  • -
- -

 

-

Example 1:

- -![](./images/116_sample.png) - -
-Input: root = [1,2,3,4,5,6,7]
-Output: [1,#,2,3,#,4,5,6,7,#]
-Explanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the given tree is less than 4096.
  • -
  • -1000 <= node.val <= 1000
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/Solution.cpp b/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/Solution.cpp deleted file mode 100644 index 97bed5f8..00000000 --- a/leetcode/solution/0100-0199/0116.Populating Next Right Pointers in Each Node/Solution.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - Node* connect(Node* root) { - if (!root) return nullptr; - queue q; - q.push(root); - while (!q.empty()) { - int size = q.size(); - for (int i = 0; i < size; ++i) { - Node* t = q.front(); - q.pop(); - if (i < size - 1) { - t->next = q.front(); - } - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - } - return root; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md b/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md deleted file mode 100644 index 7b866a40..00000000 --- a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [117. Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) - -[中文文档](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md) - -## Description - -

Given a binary tree

- -
-struct Node {
-  int val;
-  Node *left;
-  Node *right;
-  Node *next;
-}
-
- -

Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

- -

Initially, all next pointers are set to NULL.

- -

 

- -

Follow up:

- -
    -
  • You may only use constant extra space.
  • -
  • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
  • -
- -

 

-

Example 1:

- -![](./images/117_sample.png) - -
-Input: root = [1,2,3,4,5,null,7]
-Output: [1,#,2,3,#,4,5,7,#]
-Explanation: Given the above binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the given tree is less than 6000.
  • -
  • -100 <= node.val <= 100
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.cpp b/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.cpp deleted file mode 100644 index 89042ad8..00000000 --- a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - Node* connect(Node* root) { - if (!root) return nullptr; - queue q; - q.push(root); - while (!q.empty()) { - int size = q.size(); - for (int i = 0; i < size; ++i) { - Node* t = q.front(); - q.pop(); - if (i < size - 1) { - t->next = q.front(); - } - if (t->left) q.push(t->left); - if (t->right) q.push(t->right); - } - } - - return root; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.go b/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.go deleted file mode 100644 index 9750cd04..00000000 --- a/leetcode/solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.go +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Definition for a Node. - * type Node struct { - * Val int - * Left *Node - * Right *Node - * Next *Node - * } - */ - -func connect(root *Node) *Node { - if root == nil { - return nil - } - if root.Left != nil && root.Right != nil { - root.Left.Next = root.Right - } - if root.Left != nil && root.Right == nil { - root.Left.Next = getNext(root.Next) - } - if root.Right != nil { - root.Right.Next = getNext(root.Next) - } - //先连接右侧节点 - connect(root.Right) - connect(root.Left) - return root -} - -func getNext(node *Node) *Node { - for node != nil { - if node.Left != nil { - return node.Left - } - if node.Right != nil { - return node.Right - } - node = node.Next - } - return nil -} diff --git a/leetcode/solution/0100-0199/0118.Pascal's Triangle/README_EN.md b/leetcode/solution/0100-0199/0118.Pascal's Triangle/README_EN.md deleted file mode 100644 index 192cd93f..00000000 --- a/leetcode/solution/0100-0199/0118.Pascal's Triangle/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [118. Pascal's Triangle](https://leetcode.com/problems/pascals-triangle) - -[中文文档](/solution/0100-0199/0118.Pascal's%20Triangle/README.md) - -## Description - -

Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.

- -


- -In Pascal's triangle, each number is the sum of the two numbers directly above it.

- -

Example:

- -
-
-Input: 5
-
-Output:
-
-[
-
-     [1],
-
-    [1,1],
-
-   [1,2,1],
-
-  [1,3,3,1],
-
- [1,4,6,4,1]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def generate(self, numRows: int) -> List[List[int]]: - if numRows == 0: - return [] - res = [] - for i in range(numRows): - t = [1 if j == 0 or j == i else 0 for j in range(i + 1)] - for j in range(1, i): - t[j] = res[i - 1][j - 1] + res[i - 1][j] - res.append(t) - return res -``` - -### **Java** - -```java -class Solution { - public List> generate(int numRows) { - List> res = new ArrayList<>(); - if (numRows == 0) return res; - for (int i = 0; i < numRows; ++i) { - // 每一行 - List t = new ArrayList<>(); - for (int j = 0; j < i + 1; ++j) { - boolean firstOrLast = j == 0 || j == i; - // 设置每一行首尾元素为1,其它元素为0 - t.add(firstOrLast ? 1 : 0); - } - for (int j = 1; j < i; ++j) { - int val = res.get(i - 1).get(j - 1) + res.get(i - 1).get(j); - t.set(j, val); - } - res.add(t); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.cpp b/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.cpp deleted file mode 100644 index 9ac61e8a..00000000 --- a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.cpp +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - vector> generate(int numRows) { - vector> ans; - - for(int i = 0;i tmp(i+1); - tmp[0] = 1;//最左侧为1 - for(int j = 1;j<=i;j++){ - if(i == j)//最右侧为1 - { - tmp[j] = 1; - break; - } - tmp[j] = ans[i-1][j-1] + ans[i-1][j]; - } - ans.push_back(tmp); - } - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.js b/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.js deleted file mode 100644 index 1729352a..00000000 --- a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.js +++ /dev/null @@ -1,36 +0,0 @@ -const generate = function (numRows) { - let arr = []; - for (let i = 0; i < numRows; i++) { - let row = []; - row[0] = 1; - row[i] = 1; - for (let j = 1; j < row.length - 1; j++) { - row[j] = arr[i - 1][j - 1] + arr[i - 1][j]; - } - arr.push(row); - } - return arr; -}; - -/** - * Author: Mcnwork2018 - */ - -var generate = function (numRows) { - if (numRows === 0) return []; - if (numRows === 1) return [[1]]; - if (numRows === 2) return [[1], [1, 1]]; - let triangleArray = [[1], [1, 1]]; - for (let i = 2; i < numRows; ++i) { - triangleArray[i] = []; - for (let j = 0; j < i + 1; ++j) { - if (j === 0 || j === i) { - triangleArray[i][j] = 1; - } else { - triangleArray[i][j] = - triangleArray[i - 1][j - 1] + triangleArray[i - 1][j]; - } - } - } - return triangleArray; -}; diff --git a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.py b/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.py deleted file mode 100644 index f6d776c5..00000000 --- a/leetcode/solution/0100-0199/0118.Pascal's Triangle/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def generate(self, numRows: int) -> List[List[int]]: - if numRows == 0: - return [] - res = [] - for i in range(numRows): - t = [1 if j == 0 or j == i else 0 for j in range(i + 1)] - for j in range(1, i): - t[j] = res[i - 1][j - 1] + res[i - 1][j] - res.append(t) - return res diff --git a/leetcode/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md b/leetcode/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md deleted file mode 100644 index 80349d60..00000000 --- a/leetcode/solution/0100-0199/0119.Pascal's Triangle II/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [119. Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) - -[中文文档](/solution/0100-0199/0119.Pascal's%20Triangle%20II/README.md) - -## Description - -

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

- -

Note that the row index starts from 0.

- -


- -In Pascal's triangle, each number is the sum of the two numbers directly above it.

- -

Example:

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

Follow up:

- -

Could you optimize your algorithm to use only O(k) extra space?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0119.Pascal's Triangle II/Solution.cpp b/leetcode/solution/0100-0199/0119.Pascal's Triangle II/Solution.cpp deleted file mode 100644 index 55a99e5c..00000000 --- a/leetcode/solution/0100-0199/0119.Pascal's Triangle II/Solution.cpp +++ /dev/null @@ -1,15 +0,0 @@ -class Solution { -public: - vector getRow(int rowIndex) { - vector ans; - - for(int i = 0;i <= rowIndex;i++){ - for(int j = i-1;j > 0;j--){ - ans[j] = ans[j-1] + ans[j]; - } - ans.push_back(1); - } - return ans; - - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0120.Triangle/README_EN.md b/leetcode/solution/0100-0199/0120.Triangle/README_EN.md deleted file mode 100644 index 2dd78b26..00000000 --- a/leetcode/solution/0100-0199/0120.Triangle/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [120. Triangle](https://leetcode.com/problems/triangle) - -[中文文档](/solution/0100-0199/0120.Triangle/README.md) - -## Description - -

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

- -

For example, given the following triangle

- -
-
-[
-
-     [2],
-
-    [3,4],
-
-   [6,5,7],
-
-  [4,1,8,3]
-
-]
-
-
- -

The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

- -

Note:

- -

Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0120.Triangle/Solution.cpp b/leetcode/solution/0100-0199/0120.Triangle/Solution.cpp deleted file mode 100644 index c6e08678..00000000 --- a/leetcode/solution/0100-0199/0120.Triangle/Solution.cpp +++ /dev/null @@ -1,30 +0,0 @@ -class Solution { -public: - int minimumTotal(vector>& triangle) { - size_t rowNum = triangle.size(); - - //特殊值处理 - if(rowNum == 0)return 0; - if(rowNum == 1){ - if(triangle[0].empty())return 0; - else return triangle[0][0]; - } - - for(int i = 1;i=0;j--){ - //边界处理 - if(j == 0){triangle[i][j] = triangle[i][j] + triangle[i-1][j];continue;} - if(j == i){triangle[i][j] = triangle[i][j] + triangle[i-1][j-1];continue;} - - //一般处理 - triangle[i][j] = triangle[i][j] + min(triangle[i-1][j],triangle[i-1][j-1]); - } - } - - int ans = INT_MAX; - for(auto v : triangle[rowNum-1]){ - if(ans > v)ans = v; - } - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md b/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md deleted file mode 100644 index df2e5d31..00000000 --- a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) - -[中文文档](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md) - -## Description - -

Say you have an array for which the ith element is the price of a given stock on day i.

- -

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

- -

Note that you cannot sell a stock before you buy one.

- -

Example 1:

- -
-
-Input: [7,1,5,3,6,4]
-
-Output: 5
-
-Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
-
-             Not 7-1 = 6, as selling price needs to be larger than buying price.
-
-
- -

Example 2:

- -
-
-Input: [7,6,4,3,1]
-
-Output: 0
-
-Explanation: In this case, no transaction is done, i.e. max profit = 0.
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxProfit(self, prices: List[int]) -> int: - if not prices: - return 0 - res = 0 - min_price = prices[0] - for price in prices: - min_price = min(min_price, price) - res = max(res, price - min_price) - return res -``` - -### **Java** - -```java -class Solution { - public int maxProfit(int[] prices) { - if (prices == null) return 0; - int res = 0; - int min = Integer.MAX_VALUE; - for (int price : prices) { - min = Math.min(min, price); - res = Math.max(res, price - min); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cpp b/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cpp deleted file mode 100644 index 292ff9db..00000000 --- a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - const int n = prices.size(); - if (n < 1) return 0; - vector min_prices(n); - vector max_profit(n); - min_prices[0] = prices[0]; - max_profit[0] = 0; - for (int i = 1; i < n; ++i) { - min_prices[i] = min(min_prices[i - 1], prices[i]); - max_profit[i] = max(max_profit[i - 1], prices[i] - min_prices[i - 1]); - } - - return max_profit[n - 1]; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cs b/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cs deleted file mode 100644 index 12dfc5f3..00000000 --- a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.cs +++ /dev/null @@ -1,18 +0,0 @@ -public class Solution { - public int MaxProfit(int[] prices) { - var result = 0; - var minPrice = int.MaxValue; - foreach (var price in prices) - { - if (price > minPrice && result < price - minPrice) - { - result = price - minPrice; - } - if (price < minPrice) - { - minPrice = price; - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js b/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js deleted file mode 100644 index c3befd50..00000000 --- a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.js +++ /dev/null @@ -1,13 +0,0 @@ -const maxProfit1 = function (prices) { - let min = prices[0]; - let profit = 0; - for (let i = 0; i < prices.length; i++) { - if (prices[i] < min) { - min = prices[i]; - } - if (profit < prices[i] - min) { - profit = prices[i] - min; - } - } - return profit; -}; diff --git a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.py b/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.py deleted file mode 100644 index 900d5aed..00000000 --- a/leetcode/solution/0100-0199/0121.Best Time to Buy and Sell Stock/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def maxProfit(self, prices: List[int]) -> int: - if not prices: - return 0 - res = 0 - min_price = prices[0] - for price in prices: - min_price = min(min_price, price) - res = max(res, price - min_price) - return res \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md b/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md deleted file mode 100644 index b9b29c90..00000000 --- a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README_EN.md +++ /dev/null @@ -1,112 +0,0 @@ -# [122. Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) - -[中文文档](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md) - -## Description - -

Say you have an array for which the ith element is the price of a given stock on day i.

- -

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

- -

Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

- -

Example 1:

- -
-
-Input: [7,1,5,3,6,4]
-
-Output: 7
-
-Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
-
-             Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
-
-
- -

Example 2:

- -
-
-Input: [1,2,3,4,5]
-
-Output: 4
-
-Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
-
-             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
-
-             engaging multiple transactions at the same time. You must sell before buying again.
-
-
- -

Example 3:

- -
-
-Input: [7,6,4,3,1]
-
-Output: 0
-
-Explanation: In this case, no transaction is done, i.e. max profit = 0.
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxProfit(self, prices: List[int]) -> int: - if not prices: - return 0 - res = 0 - for i in range(1, len(prices)): - t = prices[i] - prices[i - 1] - res += max(t, 0) - return res -``` - -### **Java** - -```java -class Solution { - public int maxProfit(int[] prices) { - if (prices == null) return 0; - int res = 0; - for (int i = 1, n = prices.length; i < n; ++i) { - // 策略是所有上涨交易日都做买卖,所以下跌交易日都不做买卖 - int t = prices[i] - prices[i - 1]; - res += Math.max(t, 0); - } - return res; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - int maxProfit(vector& prices) { - int res = 0, n; - if ((n = prices.size()) == 0) return 0; - for (int i = 1; i < n; ++i) - { - int t = prices[i] - prices[i - 1]; - res += max(0, t); - } - return res; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cpp b/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cpp deleted file mode 100644 index 0a2d9e92..00000000 --- a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - int res = 0, n; - if ((n = prices.size()) == 0) return 0; - for (int i = 1; i < n; ++i) - { - int t = prices[i] - prices[i - 1]; - res += max(0, t); - } - return res; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cs b/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cs deleted file mode 100644 index 4f61a6c9..00000000 --- a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.cs +++ /dev/null @@ -1,20 +0,0 @@ -public class Solution { - public int MaxProfit(int[] prices) { - var result = 0; - var i = 0; - while (i + 1 < prices.Length) - { - while (i + 1 < prices.Length && prices[i] >= prices[i + 1]) - { - ++i; - } - result -= prices[i]; - while (i + 1 < prices.Length && prices[i] <= prices[i + 1]) - { - ++i; - } - result += prices[i]; - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js b/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js deleted file mode 100644 index d00f2b0b..00000000 --- a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.js +++ /dev/null @@ -1,9 +0,0 @@ -const maxProfit2 = function (prices) { - let profit = 0; - for (let i = 1; i < prices.length; i++) { - if (prices[i] - prices[i - 1] > 0) { - profit += prices[i] - prices[i - 1]; - } - } - return profit; -}; diff --git a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.py b/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.py deleted file mode 100644 index 509fdaa6..00000000 --- a/leetcode/solution/0100-0199/0122.Best Time to Buy and Sell Stock II/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def maxProfit(self, prices: List[int]) -> int: - if not prices: - return 0 - res = 0 - for i in range(1, len(prices)): - t = prices[i] - prices[i - 1] - res += max(t, 0) - return res diff --git a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md b/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md deleted file mode 100644 index 2853c6d7..00000000 --- a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [123. Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii) - -[中文文档](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md) - -## Description - -

Say you have an array for which the ith element is the price of a given stock on day i.

- -

Design an algorithm to find the maximum profit. You may complete at most two transactions.

- -

Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

- -

Example 1:

- -
-
-Input: [3,3,5,0,0,3,1,4]
-
-Output: 6
-
-Explanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
-
-             Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
- -

Example 2:

- -
-
-Input: [1,2,3,4,5]
-
-Output: 4
-
-Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
-
-             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
-
-             engaging multiple transactions at the same time. You must sell before buying again.
-
-
- -

Example 3:

- -
-
-Input: [7,6,4,3,1]
-
-Output: 0
-
-Explanation: In this case, no transaction is done, i.e. max profit = 0.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cpp b/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cpp deleted file mode 100644 index d05b484d..00000000 --- a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cpp +++ /dev/null @@ -1,44 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - int left = 0; - int len = prices.size(); - if(len == 0 || len == 1)return 0; - - vector leftArr(len, 0); - vector rightArr(len, 0); - - int diff, day = 1, minPrice, maxPrice, maxProfit; - - //计算某一天及之前的最大利益 - minPrice = prices[0]; - maxProfit = 0; - for (day = 1; day < len; day++) { - diff = prices[day] - minPrice; - if (diff < 0)minPrice = prices[day]; - else if (diff > maxProfit)maxProfit = diff; - - leftArr[day] = maxProfit; - } - - //计算某一天及之前的最大利益 - maxPrice = prices[len - 1]; - maxProfit = 0; - for (day = len - 2; day >= 0; day--) { - diff = maxPrice - prices[day]; - if (diff < 0)maxPrice = prices[day]; - else if (diff > maxProfit)maxProfit = diff; - - rightArr[day] = maxProfit; - } - - int sum = 0; - maxProfit = leftArr[0] + rightArr[0]; - for (int i = 1; i < len; i++) { - sum = leftArr[i] + rightArr[i]; - if (sum > maxProfit)maxProfit = sum; - } - - return maxProfit; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cs b/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cs deleted file mode 100644 index 6828bf21..00000000 --- a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; - -public class Solution { - public int MaxProfit(int[] prices) { - int[] leftProfit = new int[prices.Length]; - int[] rightProfit = new int[prices.Length]; - - // iterate from left to right - var minPrice = int.MaxValue; - var leftMaxProfit = 0; - for (var i = 0; i < prices.Length; ++i) - { - minPrice = Math.Min(minPrice, prices[i]); - leftMaxProfit = Math.Max(leftMaxProfit, prices[i] - minPrice); - leftProfit[i] = leftMaxProfit; - } - - // iterate from right to left - var maxPrice = int.MinValue; - var rightMaxProfit = 0; - for (var i = prices.Length - 1; i >= 0; --i) - { - maxPrice = Math.Max(maxPrice, prices[i]); - rightMaxProfit = Math.Max(rightMaxProfit, maxPrice - prices[i]); - rightProfit[i] = rightMaxProfit; - } - - // merge two profits - var maxProfit = 0; - for (var i = 0; i < prices.Length; ++i) - { - maxProfit = Math.Max(maxProfit, leftProfit[i] + rightProfit[i]); - } - - return maxProfit; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.py b/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.py deleted file mode 100644 index 4ca53726..00000000 --- a/leetcode/solution/0100-0199/0123.Best Time to Buy and Sell Stock III/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def maxProfit(self, prices: List[int]) -> int: - length = len(prices) - if 0 == length: - return 0 - dp = [([0] * length) for i in range(3)] - for i in range(1, 3, 1): - maxdiff = -((1 << 31) - 1) - for j in range(1, length, 1): - maxdiff = max(maxdiff, dp[i-1][j-1] - prices[j-1]) - dp[i][j] = max(dp[i][j - 1], maxdiff + prices[j]) - return dp[2][length - 1] \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md b/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md deleted file mode 100644 index 60ce04d9..00000000 --- a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [124. Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum) - -[中文文档](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md) - -## Description - -

Given a non-empty binary tree, find the maximum path sum.

- -

For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.

- -

Example 1:

- -
-
-Input: [1,2,3]
-
-
-
-       1
-
-      / \
-
-     2   3
-
-
-
-Output: 6
-
-
- -

Example 2:

- -
-
-Input: [-10,9,20,null,null,15,7]
-
-
-
-   -10
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
-
-Output: 42
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cpp b/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cpp deleted file mode 100644 index ef670e0e..00000000 --- a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - int maxPathSum(TreeNode* root) { - int maxInt = INT_MIN; - dfs(root,maxInt); - return maxInt; - } - - - int dfs(TreeNode *root,int &maxInt){ - if(root == nullptr)return 0; - - int left = max(dfs(root->left,maxInt),0); - int right = max(dfs(root->right,maxInt),0); - maxInt = max(maxInt,left + right + root->val); - return max(left,right) + root->val; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cs b/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cs deleted file mode 100644 index fbbf487f..00000000 --- a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -public class Solution { - private int _answer = int.MinValue; - public int MaxPathSum(TreeNode root) { - GetMaxSumOfOneSide(root); - return _answer; - } - - private int GetMaxSumOfOneSide(TreeNode root) - { - if (root == null) return 0; - var leftSum = GetMaxSumOfOneSide(root.left); - if (leftSum < 0) leftSum = 0; - var rightSum = GetMaxSumOfOneSide(root.right); - if (rightSum < 0) rightSum = 0; - var all = leftSum + rightSum + root.val; - _answer = Math.Max(_answer, all); - return Math.Max(root.val, root.val + Math.Max(leftSum, rightSum)); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.go b/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.go deleted file mode 100644 index 83623ea7..00000000 --- a/leetcode/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.go +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - - import( - "math" -) - -func maxPathSum(root *TreeNode) int { - maxInt := math.MinInt32 - dfs(root,&maxInt) - return maxInt -} - -func dfs(root *TreeNode,maxInt *int) int { - if root == nil{ - return 0 - } - - left := max(0,dfs(root.Left,maxInt)) - right := max(0,dfs(root.Right,maxInt)) - *maxInt = max(*maxInt,root.Val + left + right) - return max(left,right) + root.Val -} - - -func max(a,b int) int{ - if a > b{ - return a - } - return b -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0125.Valid Palindrome/README_EN.md b/leetcode/solution/0100-0199/0125.Valid Palindrome/README_EN.md deleted file mode 100644 index 568b1fb9..00000000 --- a/leetcode/solution/0100-0199/0125.Valid Palindrome/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [125. Valid Palindrome](https://leetcode.com/problems/valid-palindrome) - -[中文文档](/solution/0100-0199/0125.Valid%20Palindrome/README.md) - -## Description - -

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

- -

Note: For the purpose of this problem, we define empty string as valid palindrome.

- -

Example 1:

- -
-
-Input: "A man, a plan, a canal: Panama"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: "race a car"
-
-Output: false
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cpp b/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cpp deleted file mode 100644 index a4960cc4..00000000 --- a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - bool isPalindrome(string s) { - int left = 0, right = s.size() - 1; - while (left < right) { - if (!isAlphaNum(s[left])) ++left; - else if (!isAlphaNum(s[right])) --right; - else if ((s[left] + 32 - 'a') % 32 != (s[right] + 32 - 'a') % 32) return false; - else { - ++left; - --right; - } - } - return true; - } - -private: - bool isAlphaNum(char &ch) { - if (ch >= 'a' && ch <= 'z') return true; - if (ch >= 'A' && ch <= 'Z') return true; - if (ch >= '0' && ch <= '9') return true; - return false; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cs b/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cs deleted file mode 100644 index dc2c4e9a..00000000 --- a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Linq; - -public class Solution { - public bool IsPalindrome(string s) { - var chars = s.Where(ch => char.IsLetterOrDigit(ch)).Select(char.ToLower).ToList(); - var i = 0; - var j = chars.Count - 1; - for (; i < j; ++i, --j) - { - if (chars[i] != chars[j]) return false; - } - return true; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.js b/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.js deleted file mode 100644 index f31fb301..00000000 --- a/leetcode/solution/0100-0199/0125.Valid Palindrome/Solution.js +++ /dev/null @@ -1,50 +0,0 @@ -const isPalindrome1 = function (s) { - let arr1 = [], - arr2 = []; - for (let i = 0; i < s.length; i++) { - if (s[i] >= "A" && s[i] <= "Z") { - arr1.push(s[i].toLowerCase()); - } - if ((s[i] >= "0" && s[i] <= "9") || (s[i] >= "a" && s[i] <= "z")) { - arr1.push(s[i]); - } - } - arr2 = [...arr1]; - arr2.reverse(); - return arr1.join("") === arr2.join(""); -}; - -const isPalindrome = function (s) { - function isNumOrAl(a) { - if ( - (a >= "A" && a <= "Z") || - (a >= "0" && a <= "9") || - (a >= "a" && a <= "z") - ) { - return true; - } else { - return false; - } - } - - if (s.length === 0) { - return true; - } - let i = 0, - j = s.length - 1; - while (i < j) { - while (i < j && !isNumOrAl(s[i])) { - i++; - } - while (i < j && !isNumOrAl(s[j])) { - j--; - } - if (s[i].toLowerCase() !== s[j].toLowerCase()) { - return false; - } else { - i++; - j--; - } - } - return true; -}; diff --git a/leetcode/solution/0100-0199/0126.Word Ladder II/README_EN.md b/leetcode/solution/0100-0199/0126.Word Ladder II/README_EN.md deleted file mode 100644 index 045b7154..00000000 --- a/leetcode/solution/0100-0199/0126.Word Ladder II/README_EN.md +++ /dev/null @@ -1,98 +0,0 @@ -# [126. Word Ladder II](https://leetcode.com/problems/word-ladder-ii) - -[中文文档](/solution/0100-0199/0126.Word%20Ladder%20II/README.md) - -## Description - -

Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:

- -
    -
  1. Only one letter can be changed at a time
  2. -
  3. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
  4. -
- -

Note:

- -
    -
  • Return an empty list if there is no such transformation sequence.
  • -
  • All words have the same length.
  • -
  • All words contain only lowercase alphabetic characters.
  • -
  • You may assume no duplicates in the word list.
  • -
  • You may assume beginWord and endWord are non-empty and are not the same.
  • -
- -

Example 1:

- -
-
-Input:
-
-beginWord = "hit",
-
-endWord = "cog",
-
-wordList = ["hot","dot","dog","lot","log","cog"]
-
-
-
-Output:
-
-[
-
-  ["hit","hot","dot","dog","cog"],
-
-  ["hit","hot","lot","log","cog"]
-
-]
-
-
- -

Example 2:

- -
-
-Input:
-
-beginWord = "hit"
-
-endWord = "cog"
-
-wordList = ["hot","dot","dog","lot","log"]
-
-
-
-Output: []
-
-
-
-Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
-
-
- -
    - -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0127.Word Ladder/README_EN.md b/leetcode/solution/0100-0199/0127.Word Ladder/README_EN.md deleted file mode 100644 index 019417b5..00000000 --- a/leetcode/solution/0100-0199/0127.Word Ladder/README_EN.md +++ /dev/null @@ -1,96 +0,0 @@ -# [127. Word Ladder](https://leetcode.com/problems/word-ladder) - -[中文文档](/solution/0100-0199/0127.Word%20Ladder/README.md) - -## Description - -

Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:

- -
    -
  1. Only one letter can be changed at a time.
  2. -
  3. Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
  4. -
- -

Note:

- -
    -
  • Return 0 if there is no such transformation sequence.
  • -
  • All words have the same length.
  • -
  • All words contain only lowercase alphabetic characters.
  • -
  • You may assume no duplicates in the word list.
  • -
  • You may assume beginWord and endWord are non-empty and are not the same.
  • -
- -

Example 1:

- -
-
-Input:
-
-beginWord = "hit",
-
-endWord = "cog",
-
-wordList = ["hot","dot","dog","lot","log","cog"]
-
-
-
-Output: 5
-
-
-
-Explanation: As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
-
-return its length 5.
-
-
- -

Example 2:

- -
-
-Input:
-
-beginWord = "hit"
-
-endWord = "cog"
-
-wordList = ["hot","dot","dog","lot","log"]
-
-
-
-Output: 0
-
-
-
-Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
-
-
- -
    - -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cpp b/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cpp deleted file mode 100644 index e17a28b7..00000000 --- a/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cpp +++ /dev/null @@ -1,26 +0,0 @@ -class Solution { -public: - int ladderLength(string beginWord, string endWord, vector& wordList) { - unordered_set wordSet(wordList.begin(), wordList.end()); - if (!wordSet.count(endWord)) - return 0; - unordered_map pathCnt{{{beginWord, 1}}}; - queue q{{beginWord}}; - while (!q.empty()) { - string word = q.front(); - q.pop(); - for (int i = 0; i < word.size(); ++i) { - string newWord = word; - for (char ch = 'a'; ch <= 'z'; ++ch) { - newWord[i] = ch; - if (wordSet.count(newWord) && newWord == endWord) return pathCnt[word] + 1; - if (wordSet.count(newWord) && !pathCnt.count(newWord)) { - q.push(newWord); - pathCnt[newWord] = pathCnt[word] + 1; - } - } - } - } - return 0; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cs b/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cs deleted file mode 100644 index 7ca47c39..00000000 --- a/leetcode/solution/0100-0199/0127.Word Ladder/Solution.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public int LadderLength(string beginWord, string endWord, IList wordList) { - var words = Enumerable.Repeat(beginWord, 1).Concat(wordList).Select((word, i) => new { Word = word, Index = i }).ToList(); - var endWordIndex = words.Find(w => w.Word == endWord)?.Index; - if (endWordIndex == null) { - return 0; - } - - var paths = new List[words.Count]; - for (var i = 0; i < paths.Length; ++i) - { - paths[i] = new List(); - } - for (var i = 0; i < beginWord.Length; ++i) - { - var hashMap = new Hashtable(); - foreach (var item in words) - { - var newWord = string.Format("{0}_{1}", item.Word.Substring(0, i), item.Word.Substring(i + 1)); - List similars; - if (!hashMap.ContainsKey(newWord)) - { - similars = new List(); - hashMap.Add(newWord, similars); - } - else - { - similars = (List)hashMap[newWord]; - } - foreach (var similar in similars) - { - paths[similar].Add(item.Index); - paths[item.Index].Add(similar); - } - similars.Add(item.Index); - } - } - - var left = words.Count - 1; - var lastRound = new List { 0 }; - var visited = new bool[words.Count]; - visited[0] = true; - for (var result = 2; left > 0; ++result) - { - var thisRound = new List(); - foreach (var index in lastRound) - { - foreach (var next in paths[index]) - { - if (!visited[next]) - { - visited[next] = true; - if (next == endWordIndex) return result; - thisRound.Add(next); - } - } - } - if (thisRound.Count == 0) break; - lastRound = thisRound; - } - - return 0; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md b/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md deleted file mode 100644 index c00319c3..00000000 --- a/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/README_EN.md +++ /dev/null @@ -1,45 +0,0 @@ -# [128. Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence) - -[中文文档](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md) - -## Description - -

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

- -

Your algorithm should run in O(n) complexity.

- -

Example:

- -
-
-Input: [100, 4, 200, 1, 3, 2]
-
-Output: 4
-
-Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/Solution.cpp b/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/Solution.cpp deleted file mode 100644 index 8fd550c7..00000000 --- a/leetcode/solution/0100-0199/0128.Longest Consecutive Sequence/Solution.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - int longestConsecutive(vector& nums) { - int res = 0; - unordered_set set{nums.begin(), nums.end()}; - for (int num : nums) { - if (!set.count(num)) continue; - set.erase(num); - int pre = num - 1, next = num + 1; - while (set.count(pre)) set.erase(pre--); - while (set.count(next)) set.erase(next++); - res = max(res, next - pre - 1); - } - return res; - } -}; diff --git a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md b/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md deleted file mode 100644 index 6c3bce87..00000000 --- a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [129. Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers) - -[中文文档](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md) - -## Description - -

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

- -

An example is the root-to-leaf path 1->2->3 which represents the number 123.

- -

Find the total sum of all root-to-leaf numbers.

- -

Note: A leaf is a node with no children.

- -

Example:

- -
-
-Input: [1,2,3]
-
-    1
-
-   / \
-
-  2   3
-
-Output: 25
-
-Explanation:
-
-The root-to-leaf path 1->2 represents the number 12.
-
-The root-to-leaf path 1->3 represents the number 13.
-
-Therefore, sum = 12 + 13 = 25.
- -

Example 2:

- -
-
-Input: [4,9,0,5,1]
-
-    4
-
-   / \
-
-  9   0
-
- / \
-
-5   1
-
-Output: 1026
-
-Explanation:
-
-The root-to-leaf path 4->9->5 represents the number 495.
-
-The root-to-leaf path 4->9->1 represents the number 491.
-
-The root-to-leaf path 4->0 represents the number 40.
-
-Therefore, sum = 495 + 491 + 40 = 1026.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.cpp b/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.cpp deleted file mode 100644 index e61cc267..00000000 --- a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - int sumNumbers(TreeNode* root) { - if (!root) return 0; - int res = 0; - stack st{{root}}; - while (!st.empty()) { - TreeNode* t = st.top(); - st.pop(); - if (!t->left && !t->right) { - res += t->val; - } - if (t->right) { - t->right->val += t->val * 10; - st.push(t->right); - } - if (t->left) { - t->left->val += t->val * 10; - st.push(t->left); - } - } - return res; - } - -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.go b/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.go deleted file mode 100644 index 92b6a15a..00000000 --- a/leetcode/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.go +++ /dev/null @@ -1,16 +0,0 @@ -func sumNumbers(root *TreeNode) int { - if root == nil { - return 0 - } - return dfs(root, 0) -} - -func dfs(root *TreeNode, sum int) int { - if root == nil { - return 0 - } - if root.Left == nil && root.Right == nil { - return 10*sum + root.Val - } - return dfs(root.Left, 10*sum + root.Val) + dfs(root.Right, 10*sum + root.Val) -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0130.Surrounded Regions/README_EN.md b/leetcode/solution/0100-0199/0130.Surrounded Regions/README_EN.md deleted file mode 100644 index 454a9ce5..00000000 --- a/leetcode/solution/0100-0199/0130.Surrounded Regions/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [130. Surrounded Regions](https://leetcode.com/problems/surrounded-regions) - -[中文文档](/solution/0100-0199/0130.Surrounded%20Regions/README.md) - -## Description - -

Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.

- -

A region is captured by flipping all 'O's into 'X's in that surrounded region.

- -

Example:

- -
-
-X X X X
-
-X O O X
-
-X X O X
-
-X O X X
-
-
- -

After running your function, the board should be:

- -
-
-X X X X
-
-X X X X
-
-X X X X
-
-X O X X
-
-
- -

Explanation:

- -

Surrounded regions shouldn’t be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cpp b/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cpp deleted file mode 100644 index 1d475897..00000000 --- a/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cpp +++ /dev/null @@ -1,50 +0,0 @@ -class Solution { -private: - void dfs(vector>& b, - vector>& m, - int i, int j) - { - if (i < 0 || i >= b.size() - || j < 0 || j >= b[0].size()) - return ; - - if (b[i][j] != 'O' || m[i][j]) - return ; - - m[i][j] = true ; - dfs(b, m, i-1, j) ; - dfs(b, m, i+1, j) ; - dfs(b, m, i, j-1) ; - dfs(b, m, i, j+1) ; - } -public: - void solve(vector>& board) { - if (board.size() == 0 || board[0].size() == 0) - return ; - - vector> marks(board.size(), vector(board[0].size(), false)) ; - const int w_1 = board[0].size() - 1 ; - for (int i = 0; i < w_1; ++i) - { - if (board[0][i] == 'O') - dfs(board, marks, 0, i) ; - if (board[board.size()-1][i] == 'O') - dfs(board, marks, board.size()-1, i) ; - } - - const int h_1 = board.size() - 1 ; - for (int i = 1; i < h_1; ++i) - { - if (board[i][0] == 'O') - dfs(board, marks, i, 0) ; - if (board[i][board[0].size()-1] == 'O') - dfs(board, marks, i, board[0].size()-1) ; - } - - for (int i = 1; i < h_1; ++i) - for (int j = 1; j < w_1; ++j) - if (board[i][j] == 'O' && !marks[i][j]) - board[i][j] = 'X' ; - - } -}; diff --git a/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cs b/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cs deleted file mode 100644 index 9ddb0b2e..00000000 --- a/leetcode/solution/0100-0199/0130.Surrounded Regions/Solution.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - private static readonly int[,] directions = new int[4, 2] { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }}; - public void Solve(char[][] board) { - var lenI = board.Length; - var lenJ = lenI == 0 ? 0 : board[0].Length; - - for (var i = 0; i < lenI; ++i) - { - for (var j = 0; j < lenJ; ++j) - { - if (board[i][j] == 'O') - { - var marked = new List>(); - marked.Add(Tuple.Create(i, j)); - board[i][j] = 'M'; - bool escaped = false; - for (var m = 0; m < marked.Count; ++m) - { - for (var k = 0; k < 4; ++k) - { - var newI = marked[m].Item1 + directions[k, 0]; - var newJ = marked[m].Item2 + directions[k, 1]; - if (newI < 0 || newI >= lenI || newJ < 0 || newJ >= lenJ) - { - escaped = true; - } - else if (board[newI][newJ] == 'O') - { - board[newI][newJ] = 'M'; - marked.Add(Tuple.Create(newI, newJ)); - } - } - } - - if (!escaped) - { - foreach (var item in marked) - { - board[item.Item1][item.Item2] = 'X'; - } - } - } - } - } - - for (var i = 0; i < lenI; ++i) - { - for (var j = 0; j < lenJ; ++j) - { - if (board[i][j] == 'M') - { - board[i][j] = 'O'; - } - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md b/leetcode/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md deleted file mode 100644 index c3fbd5f8..00000000 --- a/leetcode/solution/0100-0199/0131.Palindrome Partitioning/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [131. Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning) - -[中文文档](/solution/0100-0199/0131.Palindrome%20Partitioning/README.md) - -## Description - -

Given a string s, partition s such that every substring of the partition is a palindrome.

- -

Return all possible palindrome partitioning of s.

- -

Example:

- -
-
-Input: "aab"
-
-Output:
-
-[
-
-  ["aa","b"],
-
-  ["a","a","b"]
-
-]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0131.Palindrome Partitioning/Solution.cs b/leetcode/solution/0100-0199/0131.Palindrome Partitioning/Solution.cs deleted file mode 100644 index fe3e2832..00000000 --- a/leetcode/solution/0100-0199/0131.Palindrome Partitioning/Solution.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public IList> Partition(string s) { - if (s.Length == 0) return new List>(); - - var paths = new List[s.Length]; - for (var i = 0; i < s.Length; ++i) - { - int j, k; - for (j = i, k = i + 1; j >= 0 && k < s.Length; --j, ++k) - { - if (s[j] == s[k]) - { - if (paths[k] == null) - { - paths[k] = new List(); - } - paths[k].Add(j - 1); - } - else - { - break; - } - } - for (j = i, k = i; j >= 0 && k < s.Length; --j, ++k) - { - if (s[j] == s[k]) - { - if (paths[k] == null) - { - paths[k] = new List(); - } - paths[k].Add(j - 1); - } - else - { - break; - } - } - } - - var prevs = new List[s.Length]; - for (var i = 0; i < s.Length; ++i) - { - if (paths[i] != null) - { - foreach (var path in paths[i]) - { - if (path < 0 || prevs[path] != null) - { - if (prevs[i] == null) - { - prevs[i] = new List(); - } - prevs[i].Add(path); - } - } - } - } - - var results = new List>(); - var temp = new List(); - GenerateResults(prevs, s, s.Length - 1, temp, results); - return results; - } - - private void GenerateResults(List[] prevs, string s, int i, IList temp, IList> results) - { - if (i < 0) - { - results.Add(temp.Reverse().ToList()); - } - else - { - foreach (var prev in prevs[i]) - { - temp.Add(s.Substring(prev + 1, i - prev)); - GenerateResults(prevs, s, prev, temp, results); - temp.RemoveAt(temp.Count - 1); - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md b/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md deleted file mode 100644 index 9a5e96d1..00000000 --- a/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/README_EN.md +++ /dev/null @@ -1,45 +0,0 @@ -# [132. Palindrome Partitioning II](https://leetcode.com/problems/palindrome-partitioning-ii) - -[中文文档](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md) - -## Description - -

Given a string s, partition s such that every substring of the partition is a palindrome.

- -

Return the minimum cuts needed for a palindrome partitioning of s.

- -

Example:

- -
-
-Input: "aab"
-
-Output: 1
-
-Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/Solution.cs b/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/Solution.cs deleted file mode 100644 index c1d1f3af..00000000 --- a/leetcode/solution/0100-0199/0132.Palindrome Partitioning II/Solution.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - public int MinCut(string s) { - if (s.Length == 0) return 0; - - var paths = new List[s.Length]; - for (var i = 0; i < s.Length; ++i) - { - int j, k; - for (j = i, k = i + 1; j >= 0 && k < s.Length; --j, ++k) - { - if (s[j] == s[k]) - { - if (paths[k] == null) - { - paths[k] = new List(); - } - paths[k].Add(j - 1); - } - else - { - break; - } - } - for (j = i, k = i; j >= 0 && k < s.Length; --j, ++k) - { - if (s[j] == s[k]) - { - if (paths[k] == null) - { - paths[k] = new List(); - } - paths[k].Add(j - 1); - } - else - { - break; - } - } - } - - var partCount = new int[s.Length]; - for (var i = 0; i < s.Length; ++i) - { - partCount[i] = int.MaxValue; - if (paths[i] != null) - { - foreach (var path in paths[i]) - { - if (path < 0) - { - partCount[i] = 0; - break; - } - else - { - partCount[i] = Math.Min(partCount[i], partCount[path]); - } - } - } - ++partCount[i]; - } - return partCount[s.Length - 1] - 1; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0133.Clone Graph/README_EN.md b/leetcode/solution/0100-0199/0133.Clone Graph/README_EN.md deleted file mode 100644 index 56e92130..00000000 --- a/leetcode/solution/0100-0199/0133.Clone Graph/README_EN.md +++ /dev/null @@ -1,105 +0,0 @@ -# [133. Clone Graph](https://leetcode.com/problems/clone-graph) - -[中文文档](/solution/0100-0199/0133.Clone%20Graph/README.md) - -## Description - -

Given a reference of a node in a connected undirected graph.

- -

Return a deep copy (clone) of the graph.

- -

Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.

- -
-class Node {
-    public int val;
-    public List<Node> neighbors;
-}
-
- -

 

- -

Test case format:

- -

For simplicity sake, each node's value is the same as the node's index (1-indexed). For example, the first node with val = 1, the second node with val = 2, and so on. The graph is represented in the test case using an adjacency list.

- -

Adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.

- -

The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.

- -

 

-

Example 1:

- -![](./images/133_clone_graph_question.png) - -
-Input: adjList = [[2,4],[1,3],[2,4],[1,3]]
-Output: [[2,4],[1,3],[2,4],[1,3]]
-Explanation: There are 4 nodes in the graph.
-1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
-2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
-3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
-4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
-
- -

Example 2:

- -![](./images/graph.png) - -
-Input: adjList = [[]]
-Output: [[]]
-Explanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.
-
- -

Example 3:

- -
-Input: adjList = []
-Output: []
-Explanation: This an empty graph, it does not have any nodes.
-
- -

Example 4:

- -![](./images/graph-1.png) - -
-Input: adjList = [[2],[1]]
-Output: [[2],[1]]
-
- -

 

-

Constraints:

- -
    -
  • 1 <= Node.val <= 100
  • -
  • Node.val is unique for each node.
  • -
  • Number of Nodes will not exceed 100.
  • -
  • There is no repeated edges and no self-loops in the graph.
  • -
  • The Graph is connected and all nodes can be visited starting from the given node.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0133.Clone Graph/Solution.cs b/leetcode/solution/0100-0199/0133.Clone Graph/Solution.cs deleted file mode 100644 index 9abef5a6..00000000 --- a/leetcode/solution/0100-0199/0133.Clone Graph/Solution.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public Node CloneGraph(Node node) { - if (node == null) return null; - var dict = new Dictionary(); - var queue = new Queue(); - queue.Enqueue(CloneVal(node)); - dict.Add(node.val, queue.Peek()); - while (queue.Count > 0) - { - var current = queue.Dequeue(); - var newNeighbors = new List(current.neighbors.Count); - foreach (var oldNeighbor in current.neighbors) - { - Node newNeighbor; - if (!dict.TryGetValue(oldNeighbor.val, out newNeighbor)) - { - newNeighbor = CloneVal(oldNeighbor); - queue.Enqueue(newNeighbor); - dict.Add(newNeighbor.val, newNeighbor); - } - newNeighbors.Add(newNeighbor); - } - current.neighbors = newNeighbors; - } - return dict[node.val]; - } - - private Node CloneVal(Node node) - { - return new Node(node.val, new List(node.neighbors)); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0134.Gas Station/README_EN.md b/leetcode/solution/0100-0199/0134.Gas Station/README_EN.md deleted file mode 100644 index 757f8804..00000000 --- a/leetcode/solution/0100-0199/0134.Gas Station/README_EN.md +++ /dev/null @@ -1,109 +0,0 @@ -# [134. Gas Station](https://leetcode.com/problems/gas-station) - -[中文文档](/solution/0100-0199/0134.Gas%20Station/README.md) - -## Description - -

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].

- -

You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.

- -

Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

- -

Note:

- -
    -
  • If there exists a solution, it is guaranteed to be unique.
  • -
  • Both input arrays are non-empty and have the same length.
  • -
  • Each element in the input arrays is a non-negative integer.
  • -
- -

Example 1:

- -
-
-Input: 
-
-gas  = [1,2,3,4,5]
-
-cost = [3,4,5,1,2]
-
-
-
-Output: 3
-
-
-
-Explanation:
-
-Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
-
-Travel to station 4. Your tank = 4 - 1 + 5 = 8
-
-Travel to station 0. Your tank = 8 - 2 + 1 = 7
-
-Travel to station 1. Your tank = 7 - 3 + 2 = 6
-
-Travel to station 2. Your tank = 6 - 4 + 3 = 5
-
-Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
-
-Therefore, return 3 as the starting index.
-
-
- -

Example 2:

- -
-
-Input: 
-
-gas  = [2,3,4]
-
-cost = [3,4,3]
-
-
-
-Output: -1
-
-
-
-Explanation:
-
-You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
-
-Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
-
-Travel to station 0. Your tank = 4 - 3 + 2 = 3
-
-Travel to station 1. Your tank = 3 - 3 + 3 = 3
-
-You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
-
-Therefore, you can't travel around the circuit once no matter where you start.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0134.Gas Station/Solution.cs b/leetcode/solution/0100-0199/0134.Gas Station/Solution.cs deleted file mode 100644 index 94621d70..00000000 --- a/leetcode/solution/0100-0199/0134.Gas Station/Solution.cs +++ /dev/null @@ -1,30 +0,0 @@ -public class Solution { - public int CanCompleteCircuit(int[] gas, int[] cost) { - if (gas.Length == 0) return -1; - var startIndex = 0; - var i = 0; - var gasLeft = 0; - while (true) - { - gasLeft += gas[i] - cost[i]; - ++i; - if (i >= gas.Length) i = 0; - if (gasLeft < 0) - { - if (startIndex >= i) - { - return -1; - } - startIndex = i; - gasLeft = 0; - } - else - { - if (startIndex == i) - { - return startIndex; - } - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0135.Candy/README_EN.md b/leetcode/solution/0100-0199/0135.Candy/README_EN.md deleted file mode 100644 index fae3128d..00000000 --- a/leetcode/solution/0100-0199/0135.Candy/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [135. Candy](https://leetcode.com/problems/candy) - -[中文文档](/solution/0100-0199/0135.Candy/README.md) - -## Description - -

There are N children standing in a line. Each child is assigned a rating value.

- -

You are giving candies to these children subjected to the following requirements:

- -
    -
  • Each child must have at least one candy.
  • -
  • Children with a higher rating get more candies than their neighbors.
  • -
- -

What is the minimum candies you must give?

- -

Example 1:

- -
-
-Input: [1,0,2]
-
-Output: 5
-
-Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
-
-
- -

Example 2:

- -
-
-Input: [1,2,2]
-
-Output: 4
-
-Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
-
-             The third child gets 1 candy because it satisfies the above two conditions.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0135.Candy/Solution.cs b/leetcode/solution/0100-0199/0135.Candy/Solution.cs deleted file mode 100644 index 811b114f..00000000 --- a/leetcode/solution/0100-0199/0135.Candy/Solution.cs +++ /dev/null @@ -1,40 +0,0 @@ -public class Solution { - public int Candy(int[] ratings) { - if (ratings.Length == 0) return 0; - var result = 0; - var previousRating = ratings[0]; - var previousCandy = 0; - var downCount = 0; - int? downCountThreshold = null; - foreach (var rating in ratings) - { - if (rating == previousRating) - { - result += 1; - previousCandy = 1; - downCount = 1; - downCountThreshold = null; - } - else if (rating > previousRating) - { - ++previousCandy; - result += previousCandy; - downCount = 1; - downCountThreshold = null; - } - else - { - if (downCountThreshold == null) - { - downCountThreshold = previousCandy - 1; - } - previousCandy = 1; - result += downCount + (downCount > downCountThreshold.Value ? 1 : 0); - ++downCount; - } - previousRating = rating; - //System.Console.WriteLine("{0} {1}", previousCandy, result); - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0136.Single Number/README_EN.md b/leetcode/solution/0100-0199/0136.Single Number/README_EN.md deleted file mode 100644 index e9a7f457..00000000 --- a/leetcode/solution/0100-0199/0136.Single Number/README_EN.md +++ /dev/null @@ -1,96 +0,0 @@ -# [136. Single Number](https://leetcode.com/problems/single-number) - -[中文文档](/solution/0100-0199/0136.Single%20Number/README.md) - -## Description - -

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

- -

Note:

- -

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

- -

Example 1:

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

Example 2:

- -
-
-Input: [4,1,2,1,2]
-
-Output: 4
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def singleNumber(self, nums: List[int]) -> int: - res = 0 - for num in nums: - res ^= num - return res -``` - -### **Java** - -```java -class Solution { - public int singleNumber(int[] nums) { - int res = 0; - for (int num : nums) { - res ^= num; - } - return res; - } -} -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @return {number} - */ -var singleNumber = function (nums) { - let res = 0; - for (let num of nums) { - res ^= num; - } - return res; -}; -``` - -### **Go** - -```go -func singleNumber(nums []int) int { - res := 0 - for _, v := range nums { - res ^= v - } - return res -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0136.Single Number/Solution.go b/leetcode/solution/0100-0199/0136.Single Number/Solution.go deleted file mode 100644 index 7fcc7659..00000000 --- a/leetcode/solution/0100-0199/0136.Single Number/Solution.go +++ /dev/null @@ -1,7 +0,0 @@ -func singleNumber(nums []int) int { - res := 0 - for _, v := range nums { - res ^= v - } - return res -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0136.Single Number/Solution.js b/leetcode/solution/0100-0199/0136.Single Number/Solution.js deleted file mode 100644 index f20862a0..00000000 --- a/leetcode/solution/0100-0199/0136.Single Number/Solution.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var singleNumber = function (nums) { - let res = 0; - for (let num of nums) { - res ^= num; - } - return res; -}; diff --git a/leetcode/solution/0100-0199/0136.Single Number/Solution.py b/leetcode/solution/0100-0199/0136.Single Number/Solution.py deleted file mode 100644 index d4103de7..00000000 --- a/leetcode/solution/0100-0199/0136.Single Number/Solution.py +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def singleNumber(self, nums: List[int]) -> int: - res = 0 - for num in nums: - res ^= num - return res diff --git a/leetcode/solution/0100-0199/0137.Single Number II/README_EN.md b/leetcode/solution/0100-0199/0137.Single Number II/README_EN.md deleted file mode 100644 index bb5146f5..00000000 --- a/leetcode/solution/0100-0199/0137.Single Number II/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [137. Single Number II](https://leetcode.com/problems/single-number-ii) - -[中文文档](/solution/0100-0199/0137.Single%20Number%20II/README.md) - -## Description - -

Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.

- -

Note:

- -

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

- -

Example 1:

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

Example 2:

- -
-
-Input: [0,1,0,1,0,1,99]
-
-Output: 99
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def singleNumber(self, nums: List[int]) -> int: - bits = [0] * 32 - for num in nums: - for i in range(32): - bits[i] += (num & 1) - num >>= 1 - res = 0 - for i in range(32): - if bits[i] % 3 != 0: - res += (1 << i) - return res if bits[31] % 3 == 0 else ~(res ^ 0xffffffff) -``` - -### **Java** - -```java -class Solution { - public int singleNumber(int[] nums) { - int[] bits = new int[32]; - for (int num : nums) { - for (int i = 0; i < 32; ++i) { - bits[i] += (num & 1); - num >>= 1; - } - } - - int res = 0; - for (int i = 0; i < 32; ++i) { - if (bits[i] % 3 == 1) { - res += (1 << i); - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0137.Single Number II/Solution.py b/leetcode/solution/0100-0199/0137.Single Number II/Solution.py deleted file mode 100644 index 2e7715a1..00000000 --- a/leetcode/solution/0100-0199/0137.Single Number II/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def singleNumber(self, nums: List[int]) -> int: - bits = [0] * 32 - for num in nums: - for i in range(32): - bits[i] += (num & 1) - num >>= 1 - res = 0 - for i in range(32): - if bits[i] % 3 != 0: - res += (1 << i) - return res if bits[31] % 3 == 0 else ~(res ^ 0xffffffff) diff --git a/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md b/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md deleted file mode 100644 index eafcb7bb..00000000 --- a/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [138. Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer) - -[中文文档](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md) - -## Description - -

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

- -

Return a deep copy of the list.

- -

The Linked List is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:

- -
    -
  • val: an integer representing Node.val
  • -
  • random_index: the index of the node (range from 0 to n-1) where random pointer points to, or null if it does not point to any node.
  • -
- -

 

-

Example 1:

- -![](./images/e1.png) - -
-Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
-Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
-
- -

Example 2:

- -![](./images/e2.png) - -
-Input: head = [[1,1],[2,1]]
-Output: [[1,1],[2,1]]
-
- -

Example 3:

- -![](./images/e3.png) - -
-Input: head = [[3,null],[3,0],[3,null]]
-Output: [[3,null],[3,0],[3,null]]
-
- -

Example 4:

- -
-Input: head = []
-Output: []
-Explanation: Given linked list is empty (null pointer), so return null.
-
- -

 

-

Constraints:

- -
    -
  • -10000 <= Node.val <= 10000
  • -
  • Node.random is null or pointing to a node in the linked list.
  • -
  • Number of Nodes will not exceed 1000.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/Solution.cs b/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/Solution.cs deleted file mode 100644 index 8a689696..00000000 --- a/leetcode/solution/0100-0199/0138.Copy List with Random Pointer/Solution.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Solution { - public Node CopyRandomList(Node head) { - if (head == null) { - return null; - } - - var map = new Dictionary(); - var current = head; - while (current != null) { - var newCurrent = new Node(current.val); - map.Add(current, newCurrent); - current = current.next; - } - - foreach (var entry in map) { - var oldNode = entry.Key; - var newNode = entry.Value; - if (oldNode.next != null) { - newNode.next = map[oldNode.next]; - } - if (oldNode.random != null) { - newNode.random = map[oldNode.random]; - } - } - - return map[head]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0139.Word Break/README_EN.md b/leetcode/solution/0100-0199/0139.Word Break/README_EN.md deleted file mode 100644 index 5c4ce14a..00000000 --- a/leetcode/solution/0100-0199/0139.Word Break/README_EN.md +++ /dev/null @@ -1,74 +0,0 @@ -# [139. Word Break](https://leetcode.com/problems/word-break) - -[中文文档](/solution/0100-0199/0139.Word%20Break/README.md) - -## Description - -

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

- -

Note:

- -
    -
  • The same word in the dictionary may be reused multiple times in the segmentation.
  • -
  • You may assume the dictionary does not contain duplicate words.
  • -
- -

Example 1:

- -
-
-Input: s = "leetcode", wordDict = ["leet", "code"]
-
-Output: true
-
-Explanation: Return true because "leetcode" can be segmented as "leet code".
-
-
- -

Example 2:

- -
-
-Input: s = "applepenapple", wordDict = ["apple", "pen"]
-
-Output: true
-
-Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
-
-             Note that you are allowed to reuse a dictionary word.
-
-
- -

Example 3:

- -
-
-Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
-
-Output: false
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0139.Word Break/Solution.cs b/leetcode/solution/0100-0199/0139.Word Break/Solution.cs deleted file mode 100644 index b9ec5f96..00000000 --- a/leetcode/solution/0100-0199/0139.Word Break/Solution.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public bool WordBreak(string s, IList wordDict) { - var f = new bool[s.Length + 1]; - f[0] = true; - var wordDictGroup = wordDict.GroupBy(word => word.Length); - for (var i = 1; i <= s.Length; ++i) - { - foreach (var wordGroup in wordDictGroup) - { - var wordLength = wordGroup.Key; - if (i >= wordLength && f[i - wordLength]) - { - foreach (var word in wordGroup) - { - if (s.Substring(i - wordLength, wordLength) == word) - { - f[i] = true; - break; - } - } - } - } - } - return f[s.Length]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0140.Word Break II/README_EN.md b/leetcode/solution/0100-0199/0140.Word Break II/README_EN.md deleted file mode 100644 index f96ae1e3..00000000 --- a/leetcode/solution/0100-0199/0140.Word Break II/README_EN.md +++ /dev/null @@ -1,100 +0,0 @@ -# [140. Word Break II](https://leetcode.com/problems/word-break-ii) - -[中文文档](/solution/0100-0199/0140.Word%20Break%20II/README.md) - -## Description - -

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.

- -

Note:

- -
    -
  • The same word in the dictionary may be reused multiple times in the segmentation.
  • -
  • You may assume the dictionary does not contain duplicate words.
  • -
- -

Example 1:

- -
-
-Input:
-
-s = "catsanddog"
-
-wordDict = ["cat", "cats", "and", "sand", "dog"]
-
-Output:
-
-[
-
-  "cats and dog",
-
-  "cat sand dog"
-
-]
-
-
- -

Example 2:

- -
-
-Input:
-
-s = "pineapplepenapple"
-
-wordDict = ["apple", "pen", "applepen", "pine", "pineapple"]
-
-Output:
-
-[
-
-  "pine apple pen apple",
-
-  "pineapple pen apple",
-
-  "pine applepen apple"
-
-]
-
-Explanation: Note that you are allowed to reuse a dictionary word.
-
-
- -

Example 3:

- -
-
-Input:
-
-s = "catsandog"
-
-wordDict = ["cats", "dog", "sand", "and", "cat"]
-
-Output:
-
-[]
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0140.Word Break II/Solution.cs b/leetcode/solution/0100-0199/0140.Word Break II/Solution.cs deleted file mode 100644 index b6f56226..00000000 --- a/leetcode/solution/0100-0199/0140.Word Break II/Solution.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -class Node -{ - public int Index1 { get; set; } - public int Index2 { get; set; } -} - -public class Solution { - public IList WordBreak(string s, IList wordDict) { - var paths = new List>[s.Length + 1]; - paths[s.Length] = new List> { Tuple.Create(-1, (string)null) }; - var wordDictGroup = wordDict.GroupBy(word => word.Length); - for (var i = s.Length - 1; i >= 0; --i) - { - paths[i] = new List>(); - foreach (var wordGroup in wordDictGroup) - { - var wordLength = wordGroup.Key; - if (i + wordLength <= s.Length && paths[i + wordLength].Count > 0) - { - foreach (var word in wordGroup) - { - if (s.Substring(i, wordLength) == word) - { - paths[i].Add(Tuple.Create(i + wordLength, word)); - } - } - } - } - } - - return GenerateResults(paths); - } - - private IList GenerateResults(List>[] paths) - { - var results = new List(); - var sb = new StringBuilder(); - var stack = new Stack(); - stack.Push(new Node()); - while (stack.Count > 0) - { - var node = stack.Peek(); - if (node.Index1 == paths.Length - 1 || node.Index2 == paths[node.Index1].Count) - { - if (node.Index1 == paths.Length - 1) - { - results.Add(sb.ToString()); - } - stack.Pop(); - if (stack.Count > 0) - { - var parent = stack.Peek(); - var length = paths[parent.Index1][parent.Index2 - 1].Item2.Length; - if (length < sb.Length) ++length; - sb.Remove(sb.Length - length, length); - } - } - else - { - var newNode = new Node { Index1 = paths[node.Index1][node.Index2].Item1, Index2 = 0 }; - if (sb.Length != 0) - { - sb.Append(' '); - } - sb.Append(paths[node.Index1][node.Index2].Item2); - stack.Push(newNode); - ++node.Index2; - } - } - return results; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0141.Linked List Cycle/README_EN.md b/leetcode/solution/0100-0199/0141.Linked List Cycle/README_EN.md deleted file mode 100644 index 71a9efcb..00000000 --- a/leetcode/solution/0100-0199/0141.Linked List Cycle/README_EN.md +++ /dev/null @@ -1,132 +0,0 @@ -# [141. Linked List Cycle](https://leetcode.com/problems/linked-list-cycle) - -[中文文档](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md) - -## Description - -

Given a linked list, determine if it has a cycle in it.

- -

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

- -

 

- -
- -

Example 1:

- -
-
-Input: head = [3,2,0,-4], pos = 1
-
-Output: true
-
-Explanation: There is a cycle in the linked list, where tail connects to the second node.
-
-
- -
- -
- -![](./images/circularlinkedlist.png) - -

Example 2:

- -
-
-Input: head = [1,2], pos = 0
-
-Output: true
-
-Explanation: There is a cycle in the linked list, where tail connects to the first node.
-
-
- -
- -
- -![](./images/circularlinkedlist_test2.png) - -

Example 3:

- -
-
-Input: head = [1], pos = -1
-
-Output: false
-
-Explanation: There is no cycle in the linked list.
-
-
- -
- -![](./images/circularlinkedlist_test3.png) - -

 

- -

Follow up:

- -

Can you solve it using O(1) (i.e. constant) memory?

- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def hasCycle(self, head: ListNode) -> bool: - slow = fast = head - while fast and fast.next: - slow, fast = slow.next, fast.next.next - if slow == fast: - return True - return False -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { - * val = x; - * next = null; - * } - * } - */ -public class Solution { - public boolean hasCycle(ListNode head) { - ListNode slow = head; - ListNode fast = head; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - if (slow == fast) { - return true; - } - } - return false; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.go b/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.go deleted file mode 100644 index 9ba0570f..00000000 --- a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.go +++ /dev/null @@ -1,20 +0,0 @@ -/* - * @lc app=leetcode.cn id=141 lang=golang - * 17/17 cases passed (12 ms), memory usage 4 MB - */ -func hasCycle(head *ListNode) bool { - if head == nil || head.Next == nil { - return false - } - slow, fast := head, head.Next - for { - if fast == nil || fast.Next == nil { - return false - } - if slow == fast { - return true - } - slow, fast = slow.Next, fast.Next.Next - } - return false -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.js b/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.js deleted file mode 100644 index e8d13b69..00000000 --- a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ - -/** - * @param {ListNode} head - * @return {boolean} - */ -var hasCycle = function (head) { - flag = false; - - dfs(head); - - return flag; -}; -function dfs(node) { - if (flag) return; - - if (node === null) return; - - if (node.flag) { - flag = true; - return; - } - - if (node.next === null) return; - - node.flag = true; - - dfs(node.next); -} diff --git a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.py b/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.py deleted file mode 100644 index 137c61e2..00000000 --- a/leetcode/solution/0100-0199/0141.Linked List Cycle/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def hasCycle(self, head: ListNode) -> bool: - slow = fast = head - while fast and fast.next: - slow, fast = slow.next, fast.next.next - if slow == fast: - return True - return False diff --git a/leetcode/solution/0100-0199/0142.Linked List Cycle II/README_EN.md b/leetcode/solution/0100-0199/0142.Linked List Cycle II/README_EN.md deleted file mode 100644 index 2e3d0169..00000000 --- a/leetcode/solution/0100-0199/0142.Linked List Cycle II/README_EN.md +++ /dev/null @@ -1,125 +0,0 @@ -# [142. Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii) - -[中文文档](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md) - -## Description - -

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

- -

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

- -

Note: Do not modify the linked list.

- -

 

- -

Example 1:

- -
-Input: head = [3,2,0,-4], pos = 1
-Output: tail connects to node index 1
-Explanation: There is a cycle in the linked list, where tail connects to the second node.
-
- -![](./images/circularlinkedlist.png) - -

Example 2:

- -
-Input: head = [1,2], pos = 0
-Output: tail connects to node index 0
-Explanation: There is a cycle in the linked list, where tail connects to the first node.
-
- -![](./images/circularlinkedlist_test2.png) - -

Example 3:

- -
-Input: head = [1], pos = -1
-Output: no cycle
-Explanation: There is no cycle in the linked list.
-
- -![](./images/circularlinkedlist_test3.png) - -

 

- -

Follow-up:
-Can you solve it without using extra space?

- -## Solutions - - - -### **Python3** - -```python -# 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: - slow = fast = head - has_cycle = False - while fast and fast.next: - slow, fast = slow.next, fast.next.next - if slow == fast: - has_cycle = True - break - if not has_cycle: - return None - p = head - while p != slow: - p, slow = p.next, slow.next - return p -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { - * val = x; - * next = null; - * } - * } - */ -public class Solution { - public ListNode detectCycle(ListNode head) { - ListNode slow = head, fast = head; - boolean hasCycle = false; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - if (slow == fast) { - hasCycle = true; - break; - } - } - if (!hasCycle) { - return null; - } - ListNode p = head; - while (p != slow) { - p = p.next; - slow = slow.next; - } - return p; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.cpp b/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.cpp deleted file mode 100644 index c64fa506..00000000 --- a/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - ListNode *detectCycle(ListNode *head) { - if(head == NULL)return NULL; - ListNode *fast = head; - ListNode *slow = head; - while(fast != NULL && fast->next != NULL){ - fast = fast->next->next; - slow = slow->next; - - if(fast == slow){ - slow = head; - while(slow != fast){ - fast = fast->next; - slow = slow->next; - } - return fast; - } - } - return NULL;//无环 - } -}; diff --git a/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.py b/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.py deleted file mode 100644 index 18a4124a..00000000 --- a/leetcode/solution/0100-0199/0142.Linked List Cycle II/Solution.py +++ /dev/null @@ -1,21 +0,0 @@ -# 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: - slow = fast = head - has_cycle = False - while fast and fast.next: - slow, fast = slow.next, fast.next.next - if slow == fast: - has_cycle = True - break - if not has_cycle: - return None - p = head - while p != slow: - p, slow = p.next, slow.next - return p diff --git a/leetcode/solution/0100-0199/0143.Reorder List/README_EN.md b/leetcode/solution/0100-0199/0143.Reorder List/README_EN.md deleted file mode 100644 index c3a1e613..00000000 --- a/leetcode/solution/0100-0199/0143.Reorder List/README_EN.md +++ /dev/null @@ -1,119 +0,0 @@ -# [143. Reorder List](https://leetcode.com/problems/reorder-list) - -[中文文档](/solution/0100-0199/0143.Reorder%20List/README.md) - -## Description - -

Given a singly linked list L: L0L1→…→Ln-1Ln,
- -reorder it to: L0LnL1Ln-1L2Ln-2→…

- -

You may not modify the values in the list's nodes, only nodes itself may be changed.

- -

Example 1:

- -
-
-Given 1->2->3->4, reorder it to 1->4->2->3.
- -

Example 2:

- -
-
-Given 1->2->3->4->5, reorder it to 1->5->2->4->3.
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def reorderList(self, head: ListNode) -> None: - """ - Do not return anything, modify head in-place instead. - """ - if head is None or head.next is None: - return - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - cur = slow.next - slow.next = None - pre = None - while cur: - t = cur.next - cur.next = pre - pre = cur - cur = t - cur = head - while pre: - t1 = cur.next - cur.next = pre - cur = t1 - t2 = pre.next - pre.next = t1 - pre = t2 -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public void reorderList(ListNode head) { - if (head == null || head.next == null) { - return; - } - ListNode slow = head; - ListNode fast = head.next; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - } - ListNode cur = slow.next; - slow.next = null; - ListNode pre = null; - while (cur != null) { - ListNode t = cur.next; - cur.next = pre; - pre = cur; - cur = t; - } - cur = head; - while (pre != null) { - ListNode t1 = cur.next; - cur.next = pre; - cur = t1; - ListNode t2 = pre.next; - pre.next = cur; - pre = t2; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0143.Reorder List/Solution.cs b/leetcode/solution/0100-0199/0143.Reorder List/Solution.cs deleted file mode 100644 index eb6c9589..00000000 --- a/leetcode/solution/0100-0199/0143.Reorder List/Solution.cs +++ /dev/null @@ -1,55 +0,0 @@ -public class Solution { - public void ReorderList(ListNode head) { - var mid = FindMiddleNode(head); - if (mid == null || mid.next == null) return; - var head2 = mid.next; - mid.next = null; - head2 = ReverseList(head2); - MergeList(head, head2); - } - - private ListNode FindMiddleNode(ListNode head) - { - var last = head; - var mid = head; - while (last != null) - { - last = last.next; - if (last != null) - { - last = last.next; - mid = mid.next; - } - } - return mid; - } - - private ListNode ReverseList(ListNode head) - { - var current = head; - head = null; - while (current != null) - { - var next = current.next; - current.next = head; - head = current; - current = next; - } - return head; - } - - private void MergeList(ListNode head1, ListNode head2) - { - var p1 = head1; - var p2 = head2; - while (p2 != null) - { - var p1Next = p1.next; - var p2Next = p2.next; - p1.next = p2; - p2.next = p1Next; - p1 = p1Next; - p2 = p2Next; - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0143.Reorder List/Solution.go b/leetcode/solution/0100-0199/0143.Reorder List/Solution.go deleted file mode 100644 index 9cc9fbab..00000000 --- a/leetcode/solution/0100-0199/0143.Reorder List/Solution.go +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Definition for singly-linked list. - * type ListNode struct { - * Val int - * Next *ListNode - * } - */ -func reorderList(head *ListNode) { - // 判空 - if head == nil { - return - } - //切片存放指针 - deq := []*ListNode{} - for head != nil { - deq = append(deq, head) - head = head.Next - } - - left, right := 0, len(deq) -1 - for left < right { - deq[left].Next = deq[right] - left++ - deq[right].Next = deq[left] - right-- - } - deq[left].Next = nil -} diff --git a/leetcode/solution/0100-0199/0143.Reorder List/Solution.py b/leetcode/solution/0100-0199/0143.Reorder List/Solution.py deleted file mode 100644 index a7fda2f4..00000000 --- a/leetcode/solution/0100-0199/0143.Reorder List/Solution.py +++ /dev/null @@ -1,31 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def reorderList(self, head: ListNode) -> None: - """ - Do not return anything, modify head in-place instead. - """ - if head is None or head.next is None: - return - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - cur = slow.next - slow.next = None - pre = None - while cur: - t = cur.next - cur.next = pre - pre = cur - cur = t - cur = head - while pre: - t1 = cur.next - cur.next = pre - cur = t1 - t2 = pre.next - pre.next = t1 - pre = t2 diff --git a/leetcode/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md b/leetcode/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md deleted file mode 100644 index 2cf76c19..00000000 --- a/leetcode/solution/0100-0199/0144.Binary Tree Preorder Traversal/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [144. Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal) - -[中文文档](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md) - -## Description - -

Given a binary tree, return the preorder traversal of its nodes' values.

- -

Example:

- -
-
-Input: [1,null,2,3]
-
-   1
-
-    \
-
-     2
-
-    /
-
-   3
-
-
-
-Output: [1,2,3]
-
-
- -

Follow up: Recursive solution is trivial, could you do it iteratively?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md b/leetcode/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md deleted file mode 100644 index 1aa49480..00000000 --- a/leetcode/solution/0100-0199/0145.Binary Tree Postorder Traversal/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [145. Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal) - -[中文文档](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md) - -## Description - -

Given a binary tree, return the postorder traversal of its nodes' values.

- -

Example:

- -
-
-Input: [1,null,2,3]
-
-   1
-
-    \
-
-     2
-
-    /
-
-   3
-
-
-
-Output: [3,2,1]
-
-
- -

Follow up: Recursive solution is trivial, could you do it iteratively?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0146.Lru Cache/README_EN.md b/leetcode/solution/0100-0199/0146.Lru Cache/README_EN.md deleted file mode 100644 index de96df3b..00000000 --- a/leetcode/solution/0100-0199/0146.Lru Cache/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [146. LRU Cache](https://leetcode.com/problems/lru-cache) - -[中文文档](/solution/0100-0199/0146.Lru%20Cache/README.md) - -## Description - -

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.

- -

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
- -put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

- -

The cache is initialized with a positive capacity.

- -

Follow up:
- -Could you do both operations in O(1) time complexity?

- -

Example:

- -
-
-LRUCache cache = new LRUCache( 2 /* capacity */ );
-
-
-
-cache.put(1, 1);
-
-cache.put(2, 2);
-
-cache.get(1);       // returns 1
-
-cache.put(3, 3);    // evicts key 2
-
-cache.get(2);       // returns -1 (not found)
-
-cache.put(4, 4);    // evicts key 1
-
-cache.get(1);       // returns -1 (not found)
-
-cache.get(3);       // returns 3
-
-cache.get(4);       // returns 4
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cpp b/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cpp deleted file mode 100644 index 7d2069c5..00000000 --- a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cpp +++ /dev/null @@ -1,57 +0,0 @@ -class LRUCache { - private: - int _cap; - // 双链表:装着 (key, value) 元组 - list> cache; - // 哈希表:key 映射到 (key, value) 在 cache 中的位置 - unordered_map>::iterator> umap; - public: - LRUCache(int capacity) { - _cap = capacity; - - } - - int get(int key) { - auto iter = umap.find(key); - if(iter == umap.end())return -1; - - pair kv = *umap[key]; - cache.erase(umap[key]);//改 - cache.push_front(kv); - umap[key] = cache.begin(); - - return kv.second; - } - - void put(int key, int value) { - auto iter = umap.find(key); - if(iter != umap.end()){ //存在于缓存 - - cache.erase(umap[key]); - cache.push_front(make_pair(key,value)); - umap[key] = cache.begin(); - - return; - } - - - //不在缓存中 - if(cache.size() == _cap) //满了 - { - - auto iter = cache.back(); - umap.erase(iter.first); - cache.pop_back(); - - cache.push_front(make_pair(key,value)); - umap[key] = cache.begin(); - - } - else //没满 - { - cache.push_front(make_pair(key,value)); - umap[key] = cache.begin(); - - } - } - }; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cs b/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cs deleted file mode 100644 index 1b25c661..00000000 --- a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.cs +++ /dev/null @@ -1,111 +0,0 @@ -// https://leetcode.com/problems/lru-cache/ - -using System.Collections.Generic; - -public class LRUCache -{ - class Node - { - public Node Prev; - public Node Next; - public int Key; - public int Value; - } - - private Node _head; - private Node _tail; - private Dictionary keyMap; - private readonly int _capacity; - - public LRUCache(int capacity) - { - _capacity = capacity; - keyMap = new Dictionary(); - } - - public int Get(int key) - { - Node node; - if (keyMap.TryGetValue(key, out node)) - { - MoveToHead(node); - return node.Value; - } - return -1; - } - - public void Put(int key, int value) - { - Node node; - if (keyMap.TryGetValue(key, out node)) - { - MoveToHead(node); - node.Value = value; - } - else - { - if (keyMap.Count == _capacity) - { - if (_capacity > 0) - { - keyMap.Remove(_tail.Key); - RemoveTail(); - } - else - { - return; - } - } - node = new Node() { Key = key, Value = value }; - keyMap.Add(key, node); - MoveToHead(node); - } - } - - private void MoveToHead(Node node) - { - if (_head != node) - { - if (_head == null) - { - _head = node; - _tail = node; - } - else - { - if (_tail == node) - { - _tail = node.Prev; - } - if (node.Next != null) - { - node.Next.Prev = node.Prev; - } - if (node.Prev != null) - { - node.Prev.Next = node.Next; - } - node.Next = _head; - _head.Prev = node; - _head = node; - } - } - } - - private void RemoveTail() - { - if (_tail != null) - { - if (_tail.Prev == null) - { - _head = null; - _tail = null; - } - else - { - _tail = _tail.Prev; - _tail.Next = null; - } - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.go b/leetcode/solution/0100-0199/0146.Lru Cache/Solution.go deleted file mode 100644 index 1b95e356..00000000 --- a/leetcode/solution/0100-0199/0146.Lru Cache/Solution.go +++ /dev/null @@ -1,105 +0,0 @@ -type list struct{ //双向链表,用于保存key:value - prev,next *list - key,val int -} - -type LRUCache struct { - _len,_cap int - front,back *list //头尾指针 - umap map[int]*list //hash表 -} - - -func Constructor(capacity int) LRUCache { - return LRUCache{ - _len : 0, - _cap : capacity, - front: nil, - back : nil, - umap : make(map[int]*list,capacity), - } -} - - -func (this *LRUCache) Get(key int) int { - if node,ok := this.umap[key];ok{ //存在 - - this.push_front(node) - return node.val - } - - return -1 -} - - -func (this *LRUCache) Put(key int, value int) { - if node,ok := this.umap[key];ok{ - node.val = value - this.push_front(node) - return - } - - //找不到 - if this._len == this._cap{ - delete(this.umap,this.back.key) - this.pop_back() - }else{ - this._len++ - } - - node := &list{ - prev:nil, - next:nil, - key:key, - val:value, - } - - this.umap[key] = node - this.insert_front(node) -} - - -func (this *LRUCache) push_front(node *list){ - switch node{ //先删除,再插入 - case this.front: - return - case this.back: - this.pop_back() - default: - node.prev.next = node.next - node.next.prev = node.prev - } - - this.insert_front(node) -} - -func (this *LRUCache) pop_back(){ - if this.back.prev != nil{ //链表长度大于1 - this.back.prev.next = nil - }else{ //链表长度小于等于1 - this.front = nil - } - - this.back = this.back.prev -} - - -func (this *LRUCache)insert_front(node *list){ - if this.back == nil{ - //空表 - this.back = node - }else{ //头插法 - node.next = this.front - this.front.prev = node - } - - this.front = node -} - - -/** - * Your LRUCache object will be instantiated and called as such: - * obj := Constructor(capacity); - * param_1 := obj.Get(key); - * obj.Put(key,value); - */ \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0147.Insertion Sort List/README_EN.md b/leetcode/solution/0100-0199/0147.Insertion Sort List/README_EN.md deleted file mode 100644 index 7e2222e5..00000000 --- a/leetcode/solution/0100-0199/0147.Insertion Sort List/README_EN.md +++ /dev/null @@ -1,136 +0,0 @@ -# [147. Insertion Sort List](https://leetcode.com/problems/insertion-sort-list) - -[中文文档](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md) - -## Description - -

Sort a linked list using insertion sort.

- -
    - -
- -


- -A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.
- -With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list

- - 

- -
    - -
- -

Algorithm of Insertion Sort:

- -
    -
  1. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
  2. -
  3. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
  4. -
  5. It repeats until no input elements remain.
  6. -
- -


- -Example 1:

- -
-
-Input: 4->2->1->3
-
-Output: 1->2->3->4
-
-
- -

Example 2:

- -
-
-Input: -1->5->3->4->0
-
-Output: -1->0->3->4->5
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def insertionSortList(self, head: ListNode) -> ListNode: - if head is None or head.next is None: - return head - dummy = ListNode(head.val) - dummy.next = head - pre, cur = dummy, head - while cur: - if pre.val <= cur.val: - pre, cur = cur, cur.next - continue - p = dummy - while p.next.val <= cur.val: - p = p.next - t = cur.next - cur.next = p.next - p.next = cur - pre.next = t - cur = t - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode insertionSortList(ListNode head) { - if (head == null || head.next == null) { - return head; - } - ListNode dummy = new ListNode(head.val); - dummy.next = head; - ListNode pre = dummy, cur = head; - while (cur != null) { - if (pre.val <= cur.val) { - pre = cur; - cur = cur.next; - continue; - } - ListNode p = dummy; - while (p.next.val <= cur.val) { - p = p.next; - } - ListNode t = cur.next; - cur.next = p.next; - p.next = cur; - pre.next = t; - cur = t; - } - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0147.Insertion Sort List/Solution.py b/leetcode/solution/0100-0199/0147.Insertion Sort List/Solution.py deleted file mode 100644 index aad7243f..00000000 --- a/leetcode/solution/0100-0199/0147.Insertion Sort List/Solution.py +++ /dev/null @@ -1,26 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def insertionSortList(self, head: ListNode) -> ListNode: - if head is None or head.next is None: - return head - dummy = ListNode(head.val) - dummy.next = head - pre, cur = dummy, head - while cur: - if pre.val <= cur.val: - pre, cur = cur, cur.next - continue - p = dummy - while p.next.val <= cur.val: - p = p.next - t = cur.next - cur.next = p.next - p.next = cur - pre.next = t - cur = t - return dummy.next diff --git a/leetcode/solution/0100-0199/0148.Sort List/README_EN.md b/leetcode/solution/0100-0199/0148.Sort List/README_EN.md deleted file mode 100644 index 0a68486c..00000000 --- a/leetcode/solution/0100-0199/0148.Sort List/README_EN.md +++ /dev/null @@ -1,114 +0,0 @@ -# [148. Sort List](https://leetcode.com/problems/sort-list) - -[中文文档](/solution/0100-0199/0148.Sort%20List/README.md) - -## Description - -

Sort a linked list in O(n log n) time using constant space complexity.

- -

Example 1:

- -
-
-Input: 4->2->1->3
-
-Output: 1->2->3->4
-
-
- -

Example 2:

- -
-
-Input: -1->5->3->4->0
-
-Output: -1->0->3->4->5
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def sortList(self, head: ListNode) -> ListNode: - if head is None or head.next is None: - return head - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - t = slow.next - slow.next = None - l1, l2 = self.sortList(head), self.sortList(t) - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode sortList(ListNode head) { - if (head == null || head.next == null) { - return head; - } - ListNode slow = head, fast = head.next; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - } - ListNode t = slow.next; - slow.next = null; - ListNode l1 = sortList(head); - ListNode l2 = sortList(t); - ListNode dummy = new ListNode(0); - ListNode cur = dummy; - while (l1 != null && l2 != null) { - if (l1.val <= l2.val) { - cur.next = l1; - l1 = l1.next; - } else { - cur.next = l2; - l2 = l2.next; - } - cur = cur.next; - } - cur.next = l1 == null ? l2 : l1; - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0148.Sort List/Solution.cs b/leetcode/solution/0100-0199/0148.Sort List/Solution.cs deleted file mode 100644 index 80df3820..00000000 --- a/leetcode/solution/0100-0199/0148.Sort List/Solution.cs +++ /dev/null @@ -1,50 +0,0 @@ -public class Solution { - public ListNode SortList(ListNode head) { - if (head == null || head.next == null) - { - return head; - } - - ListNode p1 = null; - var p2 = head; - while (p2 != null) - { - p2 = p2.next; - if (p2 != null) - { - p2 = p2.next; - p1 = p1 == null ? head : p1.next; - } - } - - p2 = p1.next; - p1.next = null; - p1 = head; - p1 = SortList(p1); - p2 = SortList(p2); - ListNode newHead = null; - ListNode newTail = null; - while (p1 != null || p2 != null) - { - if (p1 == null || (p2 != null && p1.val > p2.val)) - { - var temp = p1; - p1 = p2; - p2 = temp; - } - var next = p1; - p1 = p1.next; - next.next = null; - if (newTail == null) - { - newHead = newTail = next; - } - else - { - newTail.next = next; - newTail = next; - } - } - return newHead; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0148.Sort List/Solution.py b/leetcode/solution/0100-0199/0148.Sort List/Solution.py deleted file mode 100644 index ce9ef7b6..00000000 --- a/leetcode/solution/0100-0199/0148.Sort List/Solution.py +++ /dev/null @@ -1,27 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def sortList(self, head: ListNode) -> ListNode: - if head is None or head.next is None: - return head - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - t = slow.next - slow.next = None - l1, l2 = self.sortList(head), self.sortList(t) - dummy = ListNode() - cur = dummy - while l1 and l2: - if l1.val <= l2.val: - cur.next = l1 - l1 = l1.next - else: - cur.next = l2 - l2 = l2.next - cur = cur.next - cur.next = l1 or l2 - return dummy.next diff --git a/leetcode/solution/0100-0199/0149.Max Points on a Line/README_EN.md b/leetcode/solution/0100-0199/0149.Max Points on a Line/README_EN.md deleted file mode 100644 index 99ec4031..00000000 --- a/leetcode/solution/0100-0199/0149.Max Points on a Line/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [149. Max Points on a Line](https://leetcode.com/problems/max-points-on-a-line) - -[中文文档](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md) - -## Description - -

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

- -

Example 1:

- -
-
-Input: [[1,1],[2,2],[3,3]]
-
-Output: 3
-
-Explanation:
-
-^
-
-|
-
-|        o
-
-|     o
-
-|  o  
-
-+------------->
-
-0  1  2  3  4
-
-
- -

Example 2:

- -
-
-Input: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
-
-Output: 4
-
-Explanation:
-
-^
-
-|
-
-|  o
-
-|     o        o
-
-|        o
-
-|  o        o
-
-+------------------->
-
-0  1  2  3  4  5  6
-
-
- -

NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0149.Max Points on a Line/Solution.cs b/leetcode/solution/0100-0199/0149.Max Points on a Line/Solution.cs deleted file mode 100644 index 15d440fd..00000000 --- a/leetcode/solution/0100-0199/0149.Max Points on a Line/Solution.cs +++ /dev/null @@ -1,101 +0,0 @@ -// https://leetcode.com/problems/max-points-on-a-line/ - -using System.Collections.Generic; - -public class Solution -{ - class Slope { - private int _x; - private int _y; - - public Slope(int x, int y) { - if (x == 0 && y == 0) { - throw new ArgumentException("Invalid slope."); - } - if (x == 0) { - _x = 0; - _y = 1; - return; - } - if (y == 0) { - _x = 1; - _y = 0; - return; - } - - bool negative = x < 0 && y > 0 || x > 0 && y < 0; - x = Math.Abs(x); - y = Math.Abs(y); - int tx = x; - int ty = y; - int tz = tx % ty; - while (tz > 0) { - tx = ty; - ty = tz; - tz = tx % ty; - } - - _x = x / ty; - _y = (negative ? -1 : 1) * (y / ty); - } - - public override bool Equals(Object obj) - { - if (obj == null || !(obj is Slope)) { - return false; - } else { - return _x == ((Slope) obj)._x && _y == ((Slope) obj)._y; - } - } - - public override int GetHashCode() - { - return _x.GetHashCode() ^ _y.GetHashCode(); - } - } - - public int MaxPoints(int[][] points) - { - var answer = 0; - for (var i = 0; i < points.Length; ++i) - { - var slopes = new Dictionary(); - var samePoint = 0; - var max = 0; - for (var j = i + 1; j < points.Length; ++j) - { - if (points[i][0] == points[j][0] && points[i][1] == points[j][1]) - { - ++samePoint; - } - else - { - var slope = new Slope(points[j][0] - points[i][0], points[j][1] - points[i][1]); - if (slopes.ContainsKey(slope)) - { - ++slopes[slope]; - if (max < slopes[slope]) - { - max = slopes[slope]; - } - } - else - { - slopes[slope] = 1; - if (max < 1) - { - max = 1; - } - } - } - } - - if (1 + samePoint + max > answer) - { - answer = 1 + samePoint + max; - } - } - - return answer; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md b/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md deleted file mode 100644 index 1a338ce0..00000000 --- a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/README_EN.md +++ /dev/null @@ -1,138 +0,0 @@ -# [150. Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation) - -[中文文档](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md) - -## Description - -

Evaluate the value of an arithmetic expression in Reverse Polish Notation.

- -

Valid operators are +, -, *, /. Each operand may be an integer or another expression.

- -

Note:

- -
    -
  • Division between two integers should truncate toward zero.
  • -
  • The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
  • -
- -

Example 1:

- -
-
-Input: ["2", "1", "+", "3", "*"]
-
-Output: 9
-
-Explanation: ((2 + 1) * 3) = 9
-
-
- -

Example 2:

- -
-
-Input: ["4", "13", "5", "/", "+"]
-
-Output: 6
-
-Explanation: (4 + (13 / 5)) = 6
-
-
- -

Example 3:

- -
-
-Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
-
-Output: 22
-
-Explanation: 
-
-  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
-
-= ((10 * (6 / (12 * -11))) + 17) + 5
-
-= ((10 * (6 / -132)) + 17) + 5
-
-= ((10 * 0) + 17) + 5
-
-= (0 + 17) + 5
-
-= 17 + 5
-
-= 22
-
-
- -## Solutions - - - -### **Python3** - -```python -import operator - -class Solution: - def evalRPN(self, tokens: List[str]) -> int: - opt = { - "+": operator.add, - "-": operator.sub, - "*": operator.mul, - "/": operator.truediv - } - s = [] - for token in tokens: - if token in opt: - s.append(int(opt[token](s.pop(-2), s.pop(-1)))) - else: - s.append(int(token)) - return s[0] -``` - -### **Java** - -```java -class Solution { - public int evalRPN(String[] tokens) { - Deque s = new ArrayDeque<>(); - int left, right; - for (String token : tokens) { - switch(token) { - case "+": - right = s.pop(); - left = s.pop(); - s.push(left + right); - break; - case "-": - right = s.pop(); - left = s.pop(); - s.push(left - right); - break; - case "*": - right = s.pop(); - left = s.pop(); - s.push(left * right); - break; - case "/": - right = s.pop(); - left = s.pop(); - s.push(left / right); - break; - default: - s.push(Integer.valueOf(token)); - } - } - return s.pop(); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.cs b/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.cs deleted file mode 100644 index 242ee15e..00000000 --- a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int EvalRPN(string[] tokens) { - var stack = new Stack(); - foreach (var token in tokens) - { - switch (token) - { - case "+": - stack.Push(stack.Pop() + stack.Pop()); - break; - case "-": - stack.Push(-stack.Pop() + stack.Pop()); - break; - case "*": - stack.Push(stack.Pop() * stack.Pop()); - break; - case "/": - var right = stack.Pop(); - stack.Push(stack.Pop() / right); - break; - default: - stack.Push(int.Parse(token)); - break; - } - } - return stack.Pop(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.py b/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.py deleted file mode 100644 index bcc9565f..00000000 --- a/leetcode/solution/0100-0199/0150.Evaluate Reverse Polish Notation/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -import operator - -class Solution: - def evalRPN(self, tokens: List[str]) -> int: - opt = { - "+": operator.add, - "-": operator.sub, - "*": operator.mul, - "/": operator.truediv - } - s = [] - for token in tokens: - if token in opt: - s.append(int(opt[token](s.pop(-2), s.pop(-1)))) - else: - s.append(int(token)) - return s[0] \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0151.Reverse Words in a String/README_EN.md b/leetcode/solution/0100-0199/0151.Reverse Words in a String/README_EN.md deleted file mode 100644 index 6e2ec234..00000000 --- a/leetcode/solution/0100-0199/0151.Reverse Words in a String/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [151. Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) - -[中文文档](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md) - -## Description - -

Given an input string, reverse the string word by word.

- -

 

- -

Example 1:

- -
-
-Input: "the sky is blue"
-
-Output: "blue is sky the"
-
-
- -

Example 2:

- -
-
-Input: "  hello world!  "
-
-Output: "world! hello"
-
-Explanation: Your reversed string should not contain leading or trailing spaces.
-
-
- -

Example 3:

- -
-
-Input: "a good   example"
-
-Output: "example good a"
-
-Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.
-
-
- -

 

- -

Note:

- -
    -
  • A word is defined as a sequence of non-space characters.
  • -
  • Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
  • -
  • You need to reduce multiple spaces between two words to a single space in the reversed string.
  • -
- -

 

- -

Follow up:

- -

For C programmers, try to solve it in-place in O(1) extra space.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0151.Reverse Words in a String/Solution.cs b/leetcode/solution/0100-0199/0151.Reverse Words in a String/Solution.cs deleted file mode 100644 index de9f03ae..00000000 --- a/leetcode/solution/0100-0199/0151.Reverse Words in a String/Solution.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Text; -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public string ReverseWords(string s) { - var sb = new StringBuilder(); - var wordList = new List(); - foreach (var ch in s) - { - if (char.IsWhiteSpace(ch)) - { - if (sb.Length > 0) - { - wordList.Add(sb.ToString()); - sb.Clear(); - } - } - else - { - sb.Append(ch); - } - } - if (sb.Length > 0) - { - wordList.Add(sb.ToString()); - sb.Clear(); - } - - foreach (var word in ((IEnumerable)wordList).Reverse()) - { - if (sb.Length > 0) - { - sb.Append(' '); - } - sb.Append(word); - } - - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md b/leetcode/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md deleted file mode 100644 index 7ad2426b..00000000 --- a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/README_EN.md +++ /dev/null @@ -1,74 +0,0 @@ -# [152. Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray) - -[中文文档](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md) - -## Description - -

Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.

- -

Example 1:

- -
-
-Input: [2,3,-2,4]
-
-Output: 6
-
-Explanation: [2,3] has the largest product 6.
-
-
- -

Example 2:

- -
-
-Input: [-2,0,-1]
-
-Output: 0
-
-Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxProduct(self, nums: List[int]) -> int: - maxf = minf = nums[0] - res, n = nums[0], len(nums) - for i in range(1, n): - p, q = maxf, minf - maxf = max(nums[i], p * nums[i], q * nums[i]) - minf = min(nums[i], p * nums[i], q * nums[i]) - res = max(res, maxf) - return res -``` - -### **Java** - -```java -class Solution { - public int maxProduct(int[] nums) { - int maxf = nums[0], minf = nums[0]; - int res = nums[0], n = nums.length; - for (int i = 1; i < n; ++i) { - int p = maxf, q = minf; - maxf = Math.max(nums[i], Math.max(p * nums[i], q * nums[i])); - minf = Math.min(nums[i], Math.min(p * nums[i], q * nums[i])); - res = Math.max(res, maxf); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.cs b/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.cs deleted file mode 100644 index 86f921c1..00000000 --- a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -public class Solution { - public int MaxProduct(int[] nums) { - var prevMin = 1; - var prevMax = 1; - var result = int.MinValue; - for (var i = 0; i < nums.Length; ++i) - { - var max = Math.Max(nums[i], Math.Max(nums[i] * prevMin, nums[i] * prevMax)); - var min = Math.Min(nums[i], Math.Min(nums[i] * prevMin, nums[i] * prevMax)); - result = Math.Max(result, max); - prevMax = max; - prevMin = min; - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.py b/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.py deleted file mode 100644 index c4963513..00000000 --- a/leetcode/solution/0100-0199/0152.Maximum Product Subarray/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def maxProduct(self, nums: List[int]) -> int: - maxf = minf = nums[0] - res, n = nums[0], len(nums) - for i in range(1, n): - p, q = maxf, minf - maxf = max(nums[i], p * nums[i], q * nums[i]) - minf = min(nums[i], p * nums[i], q * nums[i]) - res = max(res, maxf) - return res diff --git a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md b/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md deleted file mode 100644 index f238a494..00000000 --- a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [153. Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) - -[中文文档](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md) - -## Description - -

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

- -

(i.e.,  [0,1,2,4,5,6,7] might become  [4,5,6,7,0,1,2]).

- -

Find the minimum element.

- -

You may assume no duplicate exists in the array.

- -

Example 1:

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

Example 2:

- -
-
-Input: [4,5,6,7,0,1,2]
-
-Output: 0
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findMin(self, nums: List[int]) -> int: - l, r = 0, len(nums) - 1 - while l < r: - m = l + ((r - l) >> 1) - if nums[m] > nums[r]: - l = m + 1 - else: - r = m - return nums[l] -``` - -### **Java** - -```java -class Solution { - public int findMin(int[] nums) { - int l = 0, r = nums.length - 1; - while (l < r) { - int m = l + ((r - l) >> 1); - if (nums[m] > nums[r]) { - l = m + 1; - } else { - r = m; - } - } - return nums[l]; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.cpp b/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.cpp deleted file mode 100644 index 7eb666d6..00000000 --- a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int findMin(vector& nums) { - if (nums[0] <= nums.back()) - return nums[0] ; - - int l = 0, r = nums.size() - 1 ; - - while (l+1 < r) - { - const int mid = l + ((r-l) >> 1) ; - if (nums[l] <= nums[mid]) - l = mid ; - else - r = mid ; - } - - return nums.at(r) ; - } -}; diff --git a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.go b/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.go deleted file mode 100644 index 66f89cbe..00000000 --- a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @lc app=leetcode.cn id=153 lang=golang - * Accepted - * 146/146 cases passed (4 ms) - * Your runtime beats 93 % of golang submissions - * Your memory usage beats 40.91 % of golang submissions (2.6 MB) - */ -func findMin(nums []int) int { - l, m, r := 0, 0, len(nums)-1 - for l < r { - if nums[l] <= nums[r] { - return nums[l] - } - m = (r + l) / 2 - if nums[l] <= nums[m] { - l = m + 1 - } else { - r = m - } - - } - return nums[l] -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.py b/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.py deleted file mode 100644 index 6f054030..00000000 --- a/leetcode/solution/0100-0199/0153.Find Minimum in Rotated Sorted Array/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def findMin(self, nums: List[int]) -> int: - l, r = 0, len(nums) - 1 - while l < r: - m = l + ((r - l) >> 1) - if nums[m] > nums[r]: - l = m + 1 - else: - r = m - return nums[l] diff --git a/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md b/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md deleted file mode 100644 index abe1b23d..00000000 --- a/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/README_EN.md +++ /dev/null @@ -1,86 +0,0 @@ -# [154. Find Minimum in Rotated Sorted Array II](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii) - -[中文文档](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md) - -## Description - -

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

- -

(i.e.,  [0,1,2,4,5,6,7] might become  [4,5,6,7,0,1,2]).

- -

Find the minimum element.

- -

The array may contain duplicates.

- -

Example 1:

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

Example 2:

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

Note:

- - - -## Solutions - - - -### **Python3** - -```python -class Solution: - def findMin(self, nums: List[int]) -> int: - l, r = 0, len(nums) - 1 - while l < r: - m = l + ((r - l) >> 1) - if nums[m] > nums[r]: - l = m + 1 - elif nums[m] < nums[r]: - r = m - else: - r -= 1 - return nums[l] -``` - -### **Java** - -```java -class Solution { - public int findMin(int[] nums) { - int l = 0, r = nums.length - 1; - while (l < r) { - int m = l + ((r - l) >> 1); - if (nums[m] > nums[r]) { - l = m + 1; - } else if (nums[m] < nums[r]) { - r = m; - } else { - --r; - } - } - return nums[l]; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/Solution.py b/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/Solution.py deleted file mode 100644 index 788292ef..00000000 --- a/leetcode/solution/0100-0199/0154.Find Minimum in Rotated Sorted Array II/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def findMin(self, nums: List[int]) -> int: - l, r = 0, len(nums) - 1 - while l < r: - m = l + ((r - l) >> 1) - if nums[m] > nums[r]: - l = m + 1 - elif nums[m] < nums[r]: - r = m - else: - r -= 1 - return nums[l] diff --git a/leetcode/solution/0100-0199/0155.Min Stack/README_EN.md b/leetcode/solution/0100-0199/0155.Min Stack/README_EN.md deleted file mode 100644 index 607dc083..00000000 --- a/leetcode/solution/0100-0199/0155.Min Stack/README_EN.md +++ /dev/null @@ -1,133 +0,0 @@ -# [155. Min Stack](https://leetcode.com/problems/min-stack) - -[中文文档](/solution/0100-0199/0155.Min%20Stack/README.md) - -## Description - -

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

- -
    -
  • push(x) -- Push element x onto stack.
  • -
  • pop() -- Removes the element on top of the stack.
  • -
  • top() -- Get the top element.
  • -
  • getMin() -- Retrieve the minimum element in the stack.
  • -
- -

 

- -

Example:

- -
-
-MinStack minStack = new MinStack();
-
-minStack.push(-2);
-
-minStack.push(0);
-
-minStack.push(-3);
-
-minStack.getMin();   --> Returns -3.
-
-minStack.pop();
-
-minStack.top();      --> Returns 0.
-
-minStack.getMin();   --> Returns -2.
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python -class MinStack: - - def __init__(self): - """ - initialize your data structure here. - """ - self.s = [] - self.helper = [] - - - def push(self, x: int) -> None: - self.s.append(x) - element = x if not self.helper or x < self.helper[-1] else self.helper[-1] - self.helper.append(element) - - def pop(self) -> None: - self.s.pop() - self.helper.pop() - - def top(self) -> int: - return self.s[-1] - - def getMin(self) -> int: - return self.helper[-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() -``` - -### **Java** - -```java -class MinStack { - - private Deque s; - private Deque helper; - - /** initialize your data structure here. */ - public MinStack() { - s = new ArrayDeque<>(); - helper = new ArrayDeque<>(); - } - - public void push(int x) { - s.push(x); - int element = helper.isEmpty() || x < helper.peek() ? x : helper.peek(); - helper.push(element); - } - - public void pop() { - s.pop(); - helper.pop(); - } - - public int top() { - return s.peek(); - } - - public int getMin() { - return helper.peek(); - } -} - -/** - * Your MinStack object will be instantiated and called as such: - * MinStack obj = new MinStack(); - * obj.push(x); - * obj.pop(); - * int param_3 = obj.top(); - * int param_4 = obj.getMin(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0155.Min Stack/Solution.cpp b/leetcode/solution/0100-0199/0155.Min Stack/Solution.cpp deleted file mode 100644 index 61d9f8c8..00000000 --- a/leetcode/solution/0100-0199/0155.Min Stack/Solution.cpp +++ /dev/null @@ -1,40 +0,0 @@ -class MinStack {//方法1 -public: - /** initialize your data structure here. */ - stack s; - MinStack() { - - } - - void push(int x) { - if(s.empty()) { - s.push(x); - s.push(x); - } else { - int temp = s.top(); - s.push(x); - if(x < temp) { - s.push(x); - } else { - s.push(temp); - } - } - } - - void pop() { - s.pop(); - s.pop(); - } - - int top() { - int temp = s.top(); - s.pop(); - int top = s.top(); - s.push(temp); - return top; - } - - int getMin() { - return s.top(); - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0155.Min Stack/Solution.cs b/leetcode/solution/0100-0199/0155.Min Stack/Solution.cs deleted file mode 100644 index fad32166..00000000 --- a/leetcode/solution/0100-0199/0155.Min Stack/Solution.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; - -public class MinStack { - private Stack _stack = new Stack(); - private Stack _minStack = new Stack(); - - public void Push(int x) { - _stack.Push(x); - if (GetMin() >= x) _minStack.Push(x); - } - - public void Pop() { - var x = _stack.Pop(); - if (GetMin() == x) _minStack.Pop(); - } - - public int Top() { - return _stack.Peek(); - } - - public int GetMin() { - if (_minStack.Count == 0) return int.MaxValue; - return _minStack.Peek(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0155.Min Stack/Solution.js b/leetcode/solution/0100-0199/0155.Min Stack/Solution.js deleted file mode 100644 index 4c285f51..00000000 --- a/leetcode/solution/0100-0199/0155.Min Stack/Solution.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * initialize your data structure here. - */ -const MinStack = function () { - this.arr = []; - this.help = []; -}; - -/** - * @param {number} x - * @return {void} - */ -MinStack.prototype.push = function (x) { - this.arr.push(x); - if (this.help.length === 0) { - this.help.push(0); - } else { - let min = this.getMin(); - if (x < min) { - this.help.push(this.arr.length - 1); - } - } -}; - -/** - * @return {void} - */ -MinStack.prototype.pop = function () { - if (this.arr.length === 0) { - throw new Error("???"); - } - if (this.arr.length - 1 === this.help[this.help.length - 1]) { - this.help.pop(); - } - this.arr.pop(); -}; - -/** - * @return {number} - */ -MinStack.prototype.top = function () { - return this.arr[this.arr.length - 1]; -}; - -/** - * @return {number} - */ -MinStack.prototype.getMin = function () { - if (this.arr.length === 0) { - throw new Error("???"); - } - return this.arr[this.help[this.help.length - 1]]; -}; - -/** - * Your MinStack object will be instantiated and called as such: - * var obj = Object.create(MinStack).createNew() - * obj.push(x) - * obj.pop() - * var param_3 = obj.top() - * var param_4 = obj.getMin() - */ diff --git a/leetcode/solution/0100-0199/0155.Min Stack/Solution.py b/leetcode/solution/0100-0199/0155.Min Stack/Solution.py deleted file mode 100644 index 038ba09d..00000000 --- a/leetcode/solution/0100-0199/0155.Min Stack/Solution.py +++ /dev/null @@ -1,32 +0,0 @@ -class MinStack: - - def __init__(self): - """ - initialize your data structure here. - """ - self.s = [] - self.helper = [] - - - def push(self, x: int) -> None: - self.s.append(x) - element = x if not self.helper or x < self.helper[-1] else self.helper[-1] - self.helper.append(element) - - def pop(self) -> None: - self.s.pop() - self.helper.pop() - - def top(self) -> int: - return self.s[-1] - - def getMin(self) -> int: - return self.helper[-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/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md b/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md deleted file mode 100644 index 4fe9a606..00000000 --- a/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/README_EN.md +++ /dev/null @@ -1,133 +0,0 @@ -# [160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) - -[中文文档](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md) - -## Description - -

Write a program to find the node at which the intersection of two singly linked lists begins.

- -

For example, the following two linked lists:

- -![](./images/160_statement.png) - -

begin to intersect at node c1.

- -

 

- -

Example 1:

- -![](./images/160_example_1.png) - -
-
-Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
-
-Output: Reference of the node with value = 8
-
-Input Explanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.
- -

 

- -

Example 2:

- -![](./images/160_example_2.png) - -
-
-Input: intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
-
-Output: Reference of the node with value = 2
-
-Input Explanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [0,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.
-
-
- -

 

- -

Example 3:

- -![](./images/160_example_3.png) - -
-
-Input: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
-
-Output: null
-
-Input Explanation: From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values.
-
-Explanation: The two lists do not intersect, so return null.
-
-
- -

 

- -

Notes:

- -
    -
  • If the two linked lists have no intersection at all, return null.
  • -
  • The linked lists must retain their original structure after the function returns.
  • -
  • You may assume there are no cycles anywhere in the entire linked structure.
  • -
  • Your code should preferably run in O(n) time and use only O(1) memory.
  • -
- -## Solutions - - - -### **Python3** - -```python -# 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 headA is None or headB is None: - return None - pA, pB = headA, headB - while pA != pB: - pA = pA.next if pA else headB - pB = pB.next if pB else headA - return pA -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { - * val = x; - * next = null; - * } - * } - */ -public class Solution { - public ListNode getIntersectionNode(ListNode headA, ListNode headB) { - if (headA == null || headB == null) { - return null; - } - ListNode pA = headA, pB = headB; - while (pA != pB) { - pA = pA != null ? pA.next : headB; - pB = pB != null ? pB.next : headA; - } - return pA; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js b/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js deleted file mode 100644 index fb3af0ee..00000000 --- a/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.js +++ /dev/null @@ -1,46 +0,0 @@ -var getIntersectionNode2 = function (headA, headB) { - if (!headA || !headB) { - return null; - } - let q = headA, - p = headB; - let lengthA = 1; - let lengthB = 1; - while (q.next) { - q = q.next; - lengthA++; - } - while (p.next) { - p = p.next; - lengthB++; - } - if (q !== p) { - return null; - } - - (q = headA), (p = headB); - if (lengthA > lengthB) { - for (let i = 0; i < lengthA - lengthB; i++) { - q = q.next; - } - } else { - for (let i = 0; i < lengthB - lengthA; i++) { - p = p.next; - } - } - while (q !== p && q !== null) { - q = q.next; - p = p.next; - } - return q; -}; - -var getIntersectionNode = function (headA, headB) { - let p1 = headA; - let p2 = headB; - while (p1 != p2) { - p1 = p1 ? p1.next : headB; - p2 = p2 ? p2.next : headA; - } - return p1; -}; diff --git a/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.py b/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.py deleted file mode 100644 index 5d03605a..00000000 --- a/leetcode/solution/0100-0199/0160.Intersection of Two Linked Lists/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -# 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 headA is None or headB is None: - return None - pA, pB = headA, headB - while pA != pB: - pA = pA.next if pA else headB - pB = pB.next if pB else headA - return pA diff --git a/leetcode/solution/0100-0199/0162.Find Peak Element/README_EN.md b/leetcode/solution/0100-0199/0162.Find Peak Element/README_EN.md deleted file mode 100644 index af3c34a0..00000000 --- a/leetcode/solution/0100-0199/0162.Find Peak Element/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [162. Find Peak Element](https://leetcode.com/problems/find-peak-element) - -[中文文档](/solution/0100-0199/0162.Find%20Peak%20Element/README.md) - -## Description - -

A peak element is an element that is greater than its neighbors.

- -

Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.

- -

The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

- -

You may imagine that nums[-1] = nums[n] = -∞.

- -

Example 1:

- -
-
-Input: nums = [1,2,3,1]
-
-Output: 2
-
-Explanation: 3 is a peak element and your function should return the index number 2.
- -

Example 2:

- -
-
-Input: nums = [1,2,1,3,5,6,4]
-
-Output: 1 or 5 
-
-Explanation: Your function can return either index number 1 where the peak element is 2, 
-
-             or index number 5 where the peak element is 6.
-
-
- -

Note:

- -

Your solution should be in logarithmic complexity.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0164.Maximum Gap/README_EN.md b/leetcode/solution/0100-0199/0164.Maximum Gap/README_EN.md deleted file mode 100644 index e1bc99f2..00000000 --- a/leetcode/solution/0100-0199/0164.Maximum Gap/README_EN.md +++ /dev/null @@ -1,62 +0,0 @@ -# [164. Maximum Gap](https://leetcode.com/problems/maximum-gap) - -[中文文档](/solution/0100-0199/0164.Maximum%20Gap/README.md) - -## Description - -

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

- -

Return 0 if the array contains less than 2 elements.

- -

Example 1:

- -
-
-Input: [3,6,9,1]
-
-Output: 3
-
-Explanation: The sorted form of the array is [1,3,6,9], either
-
-             (3,6) or (6,9) has the maximum difference 3.
- -

Example 2:

- -
-
-Input: [10]
-
-Output: 0
-
-Explanation: The array contains less than 2 elements, therefore return 0.
- -

Note:

- -
    -
  • You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
  • -
  • Try to solve it in linear time/space.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0164.Maximum Gap/Solution.cs b/leetcode/solution/0100-0199/0164.Maximum Gap/Solution.cs deleted file mode 100644 index 8f809f9c..00000000 --- a/leetcode/solution/0100-0199/0164.Maximum Gap/Solution.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Linq; - -public class Solution { - public int MaximumGap(int[] nums) { - if (nums.Length < 2) return 0; - var max = nums.Max(); - var min = nums.Min(); - var bucketSize = Math.Max(1, (max - min) / (nums.Length - 1)); - var buckets = new Tuple[(max - min) / bucketSize + 1]; - foreach (var num in nums) - { - var index = (num - min) / bucketSize; - if (buckets[index] == null) - { - buckets[index] = Tuple.Create(num, num); - } - else - { - buckets[index] = Tuple.Create(Math.Min(buckets[index].Item1, num), Math.Max(buckets[index].Item2, num)); - } - } - - var result = 0; - Tuple lastBucket = null; - for (var i = 0; i < buckets.Length; ++i) - { - if (buckets[i] != null) - { - if (lastBucket != null) - { - result = Math.Max(result, buckets[i].Item1 - lastBucket.Item2); - } - lastBucket = buckets[i]; - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0165.Compare Version Numbers/README_EN.md b/leetcode/solution/0100-0199/0165.Compare Version Numbers/README_EN.md deleted file mode 100644 index f7aba74e..00000000 --- a/leetcode/solution/0100-0199/0165.Compare Version Numbers/README_EN.md +++ /dev/null @@ -1,98 +0,0 @@ -# [165. Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers) - -[中文文档](/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md) - -## Description - -

Compare two version numbers version1 and version2.
- -If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.

- -

You may assume that the version strings are non-empty and contain only digits and the . character.

- -

The . character does not represent a decimal point and is used to separate number sequences.

- -

For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.

- -

You may assume the default revision number for each level of a version number to be 0. For example, version number 3.4 has a revision number of 3 and 4 for its first and second level revision number. Its third and fourth level revision number are both 0.

- -

 

- -

Example 1:

- -
-
-Input: version1 = "0.1", version2 = "1.1"
-
-Output: -1
- -

Example 2:

- -
-
-Input: version1 = "1.0.1", version2 = "1"
-
-Output: 1
- -

Example 3:

- -
-
-Input: version1 = "7.5.2.4", version2 = "7.5.3"
-
-Output: -1
- -

Example 4:

- -
-
-Input: version1 = "1.01", version2 = "1.001"
-
-Output: 0
-
-Explanation: Ignoring leading zeroes, both “01” and “001" represent the same number “1”
- -

Example 5:

- -
-
-Input: version1 = "1.0", version2 = "1.0.0"
-
-Output: 0
-
-Explanation: The first version number does not have a third level revision number, which means its third level revision number is default to "0"
- -

 

- -

Note:

- -
    - -
  1. Version strings are composed of numeric strings separated by dots . and this numeric strings may have leading zeroes.
  2. -
  3. Version strings do not start or end with dots, and they will not be two consecutive dots.
  4. - -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0165.Compare Version Numbers/Solution.cs b/leetcode/solution/0100-0199/0165.Compare Version Numbers/Solution.cs deleted file mode 100644 index d097238a..00000000 --- a/leetcode/solution/0100-0199/0165.Compare Version Numbers/Solution.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; - -public class Solution { - public int CompareVersion(string version1, string version2) { - var parts1 = version1.Split('.').Select(int.Parse).ToList(); - var parts2 = version2.Split('.').Select(int.Parse).ToList(); - var minLen = Math.Min(parts1.Count, parts2.Count); - for (var i = 0; i < minLen; ++i) - { - if (parts1[i] < parts2[i]) - { - return -1; - } - else if (parts1[i] > parts2[i]) - { - return 1; - } - } - if (parts1.Count > parts2.Count && parts1.Skip(minLen).Any(v => v != 0)) - { - return 1; - } - if (parts2.Count > parts1.Count && parts2.Skip(minLen).Any(v => v != 0)) - { - return -1; - } - return 0; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md b/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md deleted file mode 100644 index 89ea0c1f..00000000 --- a/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [166. Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal) - -[中文文档](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md) - -## Description - -

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

- -

If the fractional part is repeating, enclose the repeating part in parentheses.

- -

Example 1:

- -
-
-Input: numerator = 1, denominator = 2
-
-Output: "0.5"
-
-
- -

Example 2:

- -
-
-Input: numerator = 2, denominator = 1
-
-Output: "2"
- -

Example 3:

- -
-
-Input: numerator = 2, denominator = 3
-
-Output: "0.(6)"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/Solution.cs b/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/Solution.cs deleted file mode 100644 index b8cfcf8e..00000000 --- a/leetcode/solution/0100-0199/0166.Fraction to Recurring Decimal/Solution.cs +++ /dev/null @@ -1,57 +0,0 @@ -// https://leetcode.com/problems/fraction-to-recurring-decimal/ - -using System.Collections.Generic; -using System.Text; - -public partial class Solution -{ - public string FractionToDecimal(int numerator, int denominator) - { - var n = (long)numerator; - var d = (long)denominator; - var sb = new StringBuilder(); - if (n < 0) - { - n = -n; - if (d < 0) - { - d = -d; - } - else - { - sb.Append('-'); - } - } - else if (n > 0 && d < 0) - { - d = -d; - sb.Append('-'); - } - - sb.Append(n / d); - n = n % d; - if (n != 0) - { - sb.Append('.'); - var dict = new Dictionary(); - while (n != 0) - { - int index; - if (dict.TryGetValue(n, out index)) - { - sb.Insert(index, '('); - sb.Append(')'); - break; - } - else - { - dict.Add(n, sb.Length); - n *= 10; - sb.Append(n / d); - n %= d; - } - } - } - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md b/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md deleted file mode 100644 index 39fd0471..00000000 --- a/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/README_EN.md +++ /dev/null @@ -1,50 +0,0 @@ -# [167. Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) - -[中文文档](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md) - -## Description - -

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

- -

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

- -

Note:

- -
    -
  • Your returned answers (both index1 and index2) are not zero-based.
  • -
  • You may assume that each input would have exactly one solution and you may not use the same element twice.
  • -
- -

Example:

- -
-
-Input: numbers = [2,7,11,15], target = 9
-
-Output: [1,2]
-
-Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/Solution.cpp b/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/Solution.cpp deleted file mode 100644 index 0047bc1d..00000000 --- a/leetcode/solution/0100-0199/0167.Two Sum II - Input array is sorted/Solution.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// 先看target是否是偶数, -// 偶数的话先排除numbers[i] == numbers[i+1] == target/2 -// 然后set查找 -// 存在的话 再折半查找定位 -class Solution { -public: - vector twoSum(vector& numbers, int target) { - set s(numbers.begin(), numbers.end()) ; - - int t = target ; - if (!(target & 1)) - t /= 2 ; - - for (int i = 0; i < numbers.size()-1; ++i) - { - if (numbers[i] == t && numbers[i] == numbers[i+1]) - return {i+1, i+2} ; - - int tar = target - numbers[i] ; - if (s.find(tar) != s.end()) - { - int l = i+1, r = numbers.size(), mid ; - while (l < r) - { - mid = (l+r) >> 1 ; - if (numbers[mid] > tar) - r = mid ; - else if (numbers[mid] < tar) - l = mid+1 ; - else - break ; - } - return {i+1, mid+1} ; - } - } - - return {0, 0} ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md b/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md deleted file mode 100644 index 852b873e..00000000 --- a/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [168. Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) - -[中文文档](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md) - -## Description - -

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

- -

For example:

- -
-
-    1 -> A
-
-    2 -> B
-
-    3 -> C
-
-    ...
-
-    26 -> Z
-
-    27 -> AA
-
-    28 -> AB 
-
-    ...
-
-
- -

Example 1:

- -
-
-Input: 1
-
-Output: "A"
-
-
- -

Example 2:

- -
-
-Input: 28
-
-Output: "AB"
-
-
- -

Example 3:

- -
-
-Input: 701
-
-Output: "ZY"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/Solution.cs b/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/Solution.cs deleted file mode 100644 index 892ccc0b..00000000 --- a/leetcode/solution/0100-0199/0168.Excel Sheet Column Title/Solution.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; - -public class Solution { - public string ConvertToTitle(int n) { - var list = new List(); - while (n > 0) - { - var x = n % 26; - if (x == 0) x = 26; - list.Add((char)('A' + x - 1)); - n = (n - x) / 26; - } - var sb = new StringBuilder(); - for (var i = list.Count - 1; i >= 0; --i) - { - sb.Append(list[i]); - } - return sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0169.Majority Element/README_EN.md b/leetcode/solution/0100-0199/0169.Majority Element/README_EN.md deleted file mode 100644 index 9977fd08..00000000 --- a/leetcode/solution/0100-0199/0169.Majority Element/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [169. Majority Element](https://leetcode.com/problems/majority-element) - -[中文文档](/solution/0100-0199/0169.Majority%20Element/README.md) - -## Description - -

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

- -

You may assume that the array is non-empty and the majority element always exist in the array.

- -

Example 1:

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

Example 2:

- -
-
-Input: [2,2,1,1,1,2,2]
-
-Output: 2
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0169.Majority Element/Solution.cs b/leetcode/solution/0100-0199/0169.Majority Element/Solution.cs deleted file mode 100644 index 59948bdc..00000000 --- a/leetcode/solution/0100-0199/0169.Majority Element/Solution.cs +++ /dev/null @@ -1,30 +0,0 @@ -public class Solution { - public int MajorityElement(int[] nums) { - return Sort(nums, 0, nums.Length - 1); - } - - private int Sort(int[] nums, int left, int right) - { - if (left == right) return nums[left]; - var targetIndex = nums.Length / 2; - var mid = nums[(left + right) / 2]; - var i = left; - var j = right; - while (i <= j) - { - while (nums[i] < mid) ++i; - while (nums[j] > mid) --j; - if (i <= j) - { - var temp = nums[i]; - nums[i] = nums[j]; - nums[j] = temp; - ++i; - --j; - } - } - if (targetIndex <= j) return Sort(nums, left, j); - if (targetIndex >= i) return Sort(nums, i, right); - return mid; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md b/leetcode/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md deleted file mode 100644 index 4f0920b1..00000000 --- a/leetcode/solution/0100-0199/0171.Excel Sheet Column Number/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [171. Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number) - -[中文文档](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md) - -## Description - -

Given a column title as appear in an Excel sheet, return its corresponding column number.

- -

For example:

- -
-
-    A -> 1
-
-    B -> 2
-
-    C -> 3
-
-    ...
-
-    Z -> 26
-
-    AA -> 27
-
-    AB -> 28 
-
-    ...
-
-
- -

Example 1:

- -
-
-Input: "A"
-
-Output: 1
-
-
- -

Example 2:

- -
-
-Input: "AB"
-
-Output: 28
-
-
- -

Example 3:

- -
-
-Input: "ZY"
-
-Output: 701
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md b/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md deleted file mode 100644 index fd6ec1a2..00000000 --- a/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [172. Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) - -[中文文档](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md) - -## Description - -

Given an integer n, return the number of trailing zeroes in n!.

- -

Example 1:

- -
-
-Input: 3
-
-Output: 0
-
-Explanation: 3! = 6, no trailing zero.
- -

Example 2:

- -
-
-Input: 5
-
-Output: 1
-
-Explanation: 5! = 120, one trailing zero.
- -

Note: Your solution should be in logarithmic time complexity.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/Solution.cpp b/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/Solution.cpp deleted file mode 100644 index 37800f12..00000000 --- a/leetcode/solution/0100-0199/0172.Factorial Trailing Zeroes/Solution.cpp +++ /dev/null @@ -1,9 +0,0 @@ -class Solution { -public: - int trailingZeroes(int n) { - int cnt5 = 0 ; - for (long long i = 5; i <= n; i *= 5) - cnt5 += n/i ; - return cnt5 ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md b/leetcode/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md deleted file mode 100644 index 45e81067..00000000 --- a/leetcode/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [173. Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator) - -[中文文档](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md) - -## Description - -

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.

- -

Calling next() will return the next smallest number in the BST.

- -

 

- -
    - -
- -

Example:

- -![](./images/bst-tree.png) - -
-
-BSTIterator iterator = new BSTIterator(root);
-
-iterator.next();    // return 3
-
-iterator.next();    // return 7
-
-iterator.hasNext(); // return true
-
-iterator.next();    // return 9
-
-iterator.hasNext(); // return true
-
-iterator.next();    // return 15
-
-iterator.hasNext(); // return true
-
-iterator.next();    // return 20
-
-iterator.hasNext(); // return false
-
-
- -

 

- -

Note:

- -
    -
  • next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tree.
  • -
  • You may assume that next() call will always be valid, that is, there will be at least a next smallest number in the BST when next() is called.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0174.Dungeon Game/README_EN.md b/leetcode/solution/0100-0199/0174.Dungeon Game/README_EN.md deleted file mode 100644 index c4fd8655..00000000 --- a/leetcode/solution/0100-0199/0174.Dungeon Game/README_EN.md +++ /dev/null @@ -1,110 +0,0 @@ -# [174. Dungeon Game](https://leetcode.com/problems/dungeon-game) - -[中文文档](/solution/0100-0199/0174.Dungeon%20Game/README.md) - -## Description - - - -

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.

- -

The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.

- -

Some of the rooms are guarded by demons, so the knight loses health (negative integers) upon entering these rooms; other rooms are either empty (0's) or contain magic orbs that increase the knight's health (positive integers).

- -

In order to reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.

- -

 

- -

Write a function to determine the knight's minimum initial health so that he is able to rescue the princess.

- -

For example, given the dungeon below, the initial health of the knight must be at least 7 if he follows the optimal path RIGHT-> RIGHT -> DOWN -> DOWN.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-2 (K)-33
-5-101
1030-5 (P)
- -

 

- -

Note:

- -
    -
  • The knight's health has no upper bound.
  • -
  • Any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0174.Dungeon Game/Solution.cs b/leetcode/solution/0100-0199/0174.Dungeon Game/Solution.cs deleted file mode 100644 index ca03cbb3..00000000 --- a/leetcode/solution/0100-0199/0174.Dungeon Game/Solution.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -public class Solution { - public int CalculateMinimumHP(int[][] dungeon) { - var len1 = dungeon.Length; - var len2 = len1 == 0 ? 0 : dungeon[0].Length; - var f = new long[len1, len2]; - for (var i = len1 - 1; i >= 0; --i) - { - for (var j = len2 - 1; j >= 0; --j) - { - var down = (i == len1 - 1) ? long.MaxValue : f[i + 1, j]; - var right = (j == len2 - 1) ? long.MaxValue : f[i, j + 1]; - f[i, j] = Math.Min(down, right); - if (f[i, j] == long.MaxValue) f[i, j] = 1; - f[i, j] -= dungeon[i][j]; - if (f[i, j] < 1) f[i, j] = 1; - } - } - return (int) f[0, 0]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0179.Largest Number/README_EN.md b/leetcode/solution/0100-0199/0179.Largest Number/README_EN.md deleted file mode 100644 index 1c9cc7ab..00000000 --- a/leetcode/solution/0100-0199/0179.Largest Number/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [179. Largest Number](https://leetcode.com/problems/largest-number) - -[中文文档](/solution/0100-0199/0179.Largest%20Number/README.md) - -## Description - -

Given a list of non negative integers, arrange them such that they form the largest number.

- -

Example 1:

- -
-
-Input: [10,2]
-
-Output: "210"
- -

Example 2:

- -
-
-Input: [3,30,34,5,9]
-
-Output: "9534330"
-
-
- -

Note: The result may be very large, so you need to return a string instead of an integer.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0179.Largest Number/Solution.cs b/leetcode/solution/0100-0199/0179.Largest Number/Solution.cs deleted file mode 100644 index 2b5248ed..00000000 --- a/leetcode/solution/0100-0199/0179.Largest Number/Solution.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Globalization; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -public class Comparer: IComparer -{ - public int Compare(string left, string right) - { - return Compare(left, right, 0, 0); - } - - private int Compare(string left, string right, int lBegin, int rBegin) - { - var len = Math.Min(left.Length - lBegin, right.Length - rBegin); - for (var i = 0; i < len; ++i) - { - if (left[lBegin + i] != right[rBegin + i]) - { - return left[lBegin + i] < right[rBegin + i] ? -1 : 1; - } - } - - if (left.Length - lBegin == right.Length - rBegin) - { - return 0; - } - if (left.Length - lBegin > right.Length - rBegin) - { - return Compare(left, right, lBegin + len, rBegin); - } - else - { - return Compare(left, right, lBegin, rBegin + len); - } - } -} - -public class Solution { - public string LargestNumber(int[] nums) { - var sb = new StringBuilder(); - var strs = nums.Select(n => n.ToString(CultureInfo.InvariantCulture)).OrderByDescending(s => s, new Comparer()); - - var nonZeroOccurred = false; - foreach (var str in strs) - { - if (!nonZeroOccurred && str == "0") continue; - sb.Append(str); - nonZeroOccurred = true; - } - return sb.Length == 0 ? "0" : sb.ToString(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md b/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md deleted file mode 100644 index 7671603f..00000000 --- a/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/README_EN.md +++ /dev/null @@ -1,45 +0,0 @@ -# [187. Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences) - -[中文文档](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README.md) - -## Description - -

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

- -

Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

- -

Example:

- -
-
-Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
-
-
-
-Output: ["AAAAACCCCC", "CCCCCAAAAA"]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/Solution.cs b/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/Solution.cs deleted file mode 100644 index a25a95f7..00000000 --- a/leetcode/solution/0100-0199/0187.Repeated DNA Sequences/Solution.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public IList FindRepeatedDnaSequences(string s) { - var once = new HashSet(); - var moreThanOnce = new HashSet(); - int bits = 0; - for (var i = 0; i < s.Length; ++i) - { - bits <<= 2; - switch (s[i]) - { - case 'A': - break; - case 'C': - bits |= 1; - break; - case 'G': - bits |= 2; - break; - case 'T': - bits |= 3; - break; - } - if (i >= 10) - { - bits &= 0xFFFFF; - } - if (i >= 9 && !once.Add(bits)) - { - moreThanOnce.Add(bits); - } - } - - var results = new List(); - foreach (var item in moreThanOnce) - { - var itemCopy = item; - var charArray = new char[10]; - for (var i = 9; i >= 0; --i) - { - switch (itemCopy & 3) - { - case 0: - charArray[i] = 'A'; - break; - case 1: - charArray[i] = 'C'; - break; - case 2: - charArray[i] = 'G'; - break; - case 3: - charArray[i] = 'T'; - break; - } - itemCopy >>= 2; - } - results.Add(new string(charArray)); - } - return results; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md b/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md deleted file mode 100644 index 2b986fa7..00000000 --- a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [188. Best Time to Buy and Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv) - -[中文文档](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README.md) - -## Description - -

Say you have an array for which the i-th element is the price of a given stock on day i.

- -

Design an algorithm to find the maximum profit. You may complete at most k transactions.

- -

Note:
-You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

- -

Example 1:

- -
-Input: [2,4,1], k = 2
-Output: 2
-Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
-
- -

Example 2:

- -
-Input: [3,2,6,5,0,3], k = 2
-Output: 7
-Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4.
-             Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.cs b/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.cs deleted file mode 100644 index 8c32573c..00000000 --- a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Comparer : IComparer>> -{ - public int Compare(LinkedListNode> left, LinkedListNode> right) - { - var result = left.Value.Item1.CompareTo(right.Value.Item1); - if (result == 0 && left != right) - { - return left.Value.Item2.CompareTo(right.Value.Item2); - } - return result; - } -} - -public class Solution { - private SortedSet>> heap = new SortedSet>>(new Comparer()); - private LinkedList> list = new LinkedList>(); - - private int lable = 0; - private Tuple CreateNodeValue(int value) - { - return Tuple.Create(value, lable++); - } - - public int MaxProfitStupid(int k, int[] prices) - { - var f = new int[prices.Length + 1, k + 1]; - for (var i = 2; i <= prices.Length; ++i) - { - for (var kk = 1; kk <= k; ++kk) - { - for (var j = 0; j + 1 < i; ++j) - { - f[i, kk] = Math.Max(f[i, kk], Math.Max(Math.Max(f[i, kk - 1], f[i - 1, kk]), f[j, kk - 1] + prices[i - 1] - prices[j])); - } - } - } - return f[prices.Length, k]; - } - - public int MaxProfit(int k, int[] prices) { - var result = 0; - var i = 0; - var profitCount = 0; - var tempList = new List>(); - while (i + 1 < prices.Length) - { - var highIndex = i; - while (i + 1 < prices.Length && prices[i] >= prices[i + 1]) - { - ++i; - } - var lowIndex = i; - while (i + 1 < prices.Length && prices[i] <= prices[i + 1]) - { - ++i; - } - var highIndex2 = i; - - if (highIndex != lowIndex) - { - tempList.Add(Tuple.Create(prices[highIndex] - prices[lowIndex], false)); - } - if (lowIndex != highIndex2) - { - tempList.Add(Tuple.Create(prices[highIndex2] - prices[lowIndex], true)); - result += prices[highIndex2] - prices[lowIndex]; - ++profitCount; - } - } - - // Trim gaps - if (tempList.Any() && tempList.First().Item2 == false) - { - tempList.RemoveAt(0); - } - if (tempList.Any() && tempList.Last().Item2 == false) - { - tempList.RemoveAt(tempList.Count - 1); - } - - foreach (var temp in tempList) - { - var node = list.AddLast(CreateNodeValue(temp.Item1)); - heap.Add(node); - } - //Console.WriteLine("profitCount: {0}. tempList size: {1}. Heap size: {2}.", profitCount, tempList.Count, heap.Sum(item =>item.Value.Count)); - - for (var j = 0; j < profitCount - k; ++j) - { - var node = heap.Min; - result -= node.Value.Item1; - //Console.WriteLine(node.Value); - var previous = node.Previous; - var next = node.Next; - var newValue = (previous == null ? 0 : previous.Value.Item1) + (next == null ? 0 : next.Value.Item1) - node.Value.Item1; - if (previous != null) - { - heap.Remove(previous); - list.Remove(previous); - } - if (next != null) - { - heap.Remove(next); - list.Remove(next); - } - if (previous != null && next != null) - { - var newNode = list.AddBefore(node, CreateNodeValue(newValue)); - heap.Add(newNode); - } - heap.Remove(node); - list.Remove(node); - } - - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.py b/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.py deleted file mode 100644 index ca7f54f4..00000000 --- a/leetcode/solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/Solution.py +++ /dev/null @@ -1,28 +0,0 @@ -class Solution: - def maxProfit(self, k: int, prices: List[int]) -> int: - length = len(prices) - if 0 == length: - return 0 - if k > (length / 2): - maxprofit = 0 - for i in range(0, len(prices) - 1, 1): - if prices[i + 1] > prices[i]: - maxprofit += prices[i + 1] - prices[i] - return maxprofit - m = k - n = length - dp = [[([0] * (2)) for i in range(m + 1)] for i in range(n + 1)] - minNumber = -((1 << 31) - 1) - for x in range(0, n + 1, 1): - dp[x][0][0] = 0 - dp[x][0][1] = minNumber - for y in range(1, m + 1, 1): - dp[0][y][0] = 0 - dp[0][y][1] = minNumber - for i in range(1, m + 1, 1): - for j in range(1, length + 1, 1): - dp[j][i][0] = max(dp[j - 1][i][0], dp[j - 1] - [i][1] + prices[j - 1]) - dp[j][i][1] = max(dp[j - 1][i][1], dp[j - 1] - [i - 1][0] - prices[j - 1]) - return dp[n][m][0] diff --git a/leetcode/solution/0100-0199/0189.Rotate Array/README_EN.md b/leetcode/solution/0100-0199/0189.Rotate Array/README_EN.md deleted file mode 100644 index bbff651a..00000000 --- a/leetcode/solution/0100-0199/0189.Rotate Array/README_EN.md +++ /dev/null @@ -1,108 +0,0 @@ -# [189. Rotate Array](https://leetcode.com/problems/rotate-array) - -[中文文档](/solution/0100-0199/0189.Rotate%20Array/README.md) - -## Description - -

Given an array, rotate the array to the right by k steps, where k is non-negative.

- -

Example 1:

- -
-
-Input: [1,2,3,4,5,6,7] and k = 3
-
-Output: [5,6,7,1,2,3,4]
-
-Explanation:
-
-rotate 1 steps to the right: [7,1,2,3,4,5,6]
-
-rotate 2 steps to the right: [6,7,1,2,3,4,5]
-
-rotate 3 steps to the right: [5,6,7,1,2,3,4]
-
-
- -

Example 2:

- -
-
-Input: [-1,-100,3,99] and k = 2
-
-Output: [3,99,-1,-100]
-
-Explanation: 
-
-rotate 1 steps to the right: [99,-1,-100,3]
-
-rotate 2 steps to the right: [3,99,-1,-100]
-
-
- -

Note:

- -
    -
  • Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
  • -
  • Could you do it in-place with O(1) extra space?
  • -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def rotate(self, nums: List[int], k: int) -> None: - """ - Do not return anything, modify nums in-place instead. - """ - n = len(nums) - k %= n - if n < 2 or k == 0: - return - nums[:] = nums[::-1] - nums[:k] = nums[:k][::-1] - nums[k:] = nums[k:][::-1] -``` - -### **Java** - -```java -class Solution { - public void rotate(int[] nums, int k) { - if (nums == null) { - return; - } - int n = nums.length; - k %= n; - if (n < 2 || k == 0) { - return; - } - - rotate(nums, 0, n - 1); - rotate(nums, 0, k - 1); - rotate(nums, k, n - 1); - } - - private void rotate(int[] nums, int i, int j) { - while (i < j) { - int t = nums[i]; - nums[i] = nums[j]; - nums[j] = t; - ++i; - --j; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0189.Rotate Array/Solution.cs b/leetcode/solution/0100-0199/0189.Rotate Array/Solution.cs deleted file mode 100644 index 65b98661..00000000 --- a/leetcode/solution/0100-0199/0189.Rotate Array/Solution.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; - -public class Solution { - public void Rotate(int[] nums, int k) { - if (nums.Length == 0 || k % nums.Length == 0) return; - k = k % nums.Length; - Algo2(nums, k); - } - - private void Algo1(int[] nums, int k) - { - var copy = new int[nums.Length]; - Array.Copy(nums, copy, nums.Length); - var j = nums.Length - k; - for (var i = 0; i < nums.Length; ++i) - { - if (j == nums.Length) j = 0; - nums[i] = copy[j]; - ++j; - } - } - - private void Algo2(int[] nums, int k) - { - var gcd = Gcd(nums.Length, k); - var count = nums.Length / gcd; - for (var i = 0; i < gcd; ++i) - { - var p = i; - var first = nums[p]; - for (var j = 0; j + 1 < count; ++j) - { - var q = p - k; - if (q < 0) q += nums.Length; - nums[p] = nums[q]; - p = q; - } - nums[i + k] = first; - } - } - - private int Gcd(int m, int n) - { - while (n > 0) - { - var x = m % n; - m = n; - n = x; - } - return m; - } -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0189.Rotate Array/Solution.py b/leetcode/solution/0100-0199/0189.Rotate Array/Solution.py deleted file mode 100644 index 4ac42c78..00000000 --- a/leetcode/solution/0100-0199/0189.Rotate Array/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def rotate(self, nums: List[int], k: int) -> None: - """ - Do not return anything, modify nums in-place instead. - """ - n = len(nums) - k %= n - if n < 2 or k == 0: - return - nums[:] = nums[::-1] - nums[:k] = nums[:k][::-1] - nums[k:] = nums[k:][::-1] diff --git a/leetcode/solution/0100-0199/0190.Reverse Bits/README_EN.md b/leetcode/solution/0100-0199/0190.Reverse Bits/README_EN.md deleted file mode 100644 index 076edf27..00000000 --- a/leetcode/solution/0100-0199/0190.Reverse Bits/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [190. Reverse Bits](https://leetcode.com/problems/reverse-bits) - -[中文文档](/solution/0100-0199/0190.Reverse%20Bits/README.md) - -## Description - -

Reverse bits of a given 32 bits unsigned integer.

- -

 

- -

Example 1:

- -
-Input: 00000010100101000001111010011100
-Output: 00111001011110000010100101000000
-Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
-
- -

Example 2:

- -
-Input: 11111111111111111111111111111101
-Output: 10111111111111111111111111111111
-Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
- -

 

- -

Note:

- -
    -
  • Note that in some languages such as Java, there is no unsigned integer type. In this case, both input and output will be given as signed integer type and should not affect your implementation, as the internal binary representation of the integer is the same whether it is signed or unsigned.
  • -
  • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 2 above the input represents the signed integer -3 and the output represents the signed integer -1073741825.
  • -
- -

 

- -

Follow up:

- -

If this function is called many times, how would you optimize it?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.cpp b/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.cpp deleted file mode 100644 index 4d5eceaf..00000000 --- a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.cpp +++ /dev/null @@ -1,16 +0,0 @@ -class Solution { -public: - uint32_t reverseBits(uint32_t n) { - uint32_t res = 0 ; - uint32_t tmp = 1 << 31 ; - while (n) - { - if (n&1) - res |= tmp ; - tmp >>= 1 ; - n >>= 1 ; - } - - return res ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.js b/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.js deleted file mode 100644 index f52bb815..00000000 --- a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.js +++ /dev/null @@ -1,6 +0,0 @@ -const reverseBits = function (n) { - return parseInt( - n.toString(2).split("").reverse().join("").padEnd(32, "0"), - 2 - ); -}; diff --git a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.py b/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.py deleted file mode 100644 index afd6baa5..00000000 --- a/leetcode/solution/0100-0199/0190.Reverse Bits/Solution.py +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - # @param n, an integer - # @return an integer - def reverseBits(self, n): - B = bin(n) - B = (B[2:].rjust(32, "0"))[::-1] - return int(B, 2) diff --git a/leetcode/solution/0100-0199/0191.Number of 1 Bits/README_EN.md b/leetcode/solution/0100-0199/0191.Number of 1 Bits/README_EN.md deleted file mode 100644 index 9b2bf8d1..00000000 --- a/leetcode/solution/0100-0199/0191.Number of 1 Bits/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [191. Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits) - -[中文文档](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md) - -## Description - -

Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight).

- -

 

- -

Example 1:

- -
-
-Input: 00000000000000000000000000001011
-
-Output: 3
-
-Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.
-
-
- -

Example 2:

- -
-
-Input: 00000000000000000000000010000000
-
-Output: 1
-
-Explanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.
-
-
- -

Example 3:

- -
-
-Input: 11111111111111111111111111111101
-
-Output: 31
-
-Explanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.
- -

 

- -

Note:

- -
    -
  • Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as signed integer type and should not affect your implementation, as the internal binary representation of the integer is the same whether it is signed or unsigned.
  • -
  • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3 above the input represents the signed integer -3.
  • -
- -

 

- -

Follow up:

- -

If this function is called many times, how would you optimize it?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.js b/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.js deleted file mode 100644 index 09a3d891..00000000 --- a/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.js +++ /dev/null @@ -1,8 +0,0 @@ -const hammingWeight = function (n) { - let result = 0; - while (n) { - result += n & 1; - n = n >>> 1; - } - return result; -}; diff --git a/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.py b/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.py deleted file mode 100644 index 3bb613b0..00000000 --- a/leetcode/solution/0100-0199/0191.Number of 1 Bits/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution(object): - def hammingWeight(self, n): - """ - :type n: int - :rtype: int - """ - - return bin(n).count("1") diff --git a/leetcode/solution/0100-0199/0198.House Robber/README_EN.md b/leetcode/solution/0100-0199/0198.House Robber/README_EN.md deleted file mode 100644 index 5e757837..00000000 --- a/leetcode/solution/0100-0199/0198.House Robber/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [198. House Robber](https://leetcode.com/problems/house-robber) - -[中文文档](/solution/0100-0199/0198.House%20Robber/README.md) - -## Description - -

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

- -

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

- -

Example 1:

- -
-
-Input: [1,2,3,1]
-
-Output: 4
-
-Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
-
-             Total amount you can rob = 1 + 3 = 4.
- -

Example 2:

- -
-
-Input: [2,7,9,3,1]
-
-Output: 12
-
-Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
-
-             Total amount you can rob = 2 + 9 + 1 = 12.
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def rob(self, nums: List[int]) -> int: - if not nums: - return 0 - n = len(nums) - if n == 1: - return nums[0] - pre, cur = nums[0], max(nums[0], nums[1]) - for i in range(2, n): - t = max(pre + nums[i], cur) - pre, cur = cur, t - return cur -``` - -### **Java** - -```java -class Solution { - public int rob(int[] nums) { - int n; - if (nums == null || (n = nums.length) == 0) { - return 0; - } - if (n == 1) { - return nums[0]; - } - int pre = nums[0]; - int cur = Math.max(nums[0], nums[1]); - for (int i = 2; i < n; ++i) { - int t = Math.max(pre + nums[i], cur); - pre = cur; - cur = t; - } - return cur; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0100-0199/0198.House Robber/Solution.cpp b/leetcode/solution/0100-0199/0198.House Robber/Solution.cpp deleted file mode 100644 index 22e5b737..00000000 --- a/leetcode/solution/0100-0199/0198.House Robber/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - int rob(vector& nums) { - if (nums.size() == 0) - return 0 ; - if (nums.size() == 1) - return nums[0] ; - vector dp(nums.size(), -1) ; - dp[0] = nums[0] ; - dp[1] = max(nums[0], nums[1]) ; - for (int i = 2; i < nums.size(); ++i) - { - dp[i] = max( - dp[i-2] + nums[i], - dp[i-1] - ) ; - } - return dp[dp.size()-1] ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0198.House Robber/Solution.go b/leetcode/solution/0100-0199/0198.House Robber/Solution.go deleted file mode 100644 index 5a89d864..00000000 --- a/leetcode/solution/0100-0199/0198.House Robber/Solution.go +++ /dev/null @@ -1,15 +0,0 @@ -/* -198.House Robber -动态规划的思路,找到状态转移方程 `f(n) = max(f(n-2)+nums[n], f(n-1))` ,初始值为 `f(0)=0, f(1)=nums[1]` -*/ - -func rob(nums []int) int { - x, y := 0, 0 - for _, n := range nums { - x, y = y, x+n - if x > y { - y = x - } - } - return y -} \ No newline at end of file diff --git a/leetcode/solution/0100-0199/0198.House Robber/Solution.py b/leetcode/solution/0100-0199/0198.House Robber/Solution.py deleted file mode 100644 index ce17d905..00000000 --- a/leetcode/solution/0100-0199/0198.House Robber/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def rob(self, nums: List[int]) -> int: - if not nums: - return 0 - n = len(nums) - if n == 1: - return nums[0] - pre, cur = nums[0], max(nums[0], nums[1]) - for i in range(2, n): - t = max(pre + nums[i], cur) - pre, cur = cur, t - return cur diff --git a/leetcode/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md b/leetcode/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md deleted file mode 100644 index 06faf6fb..00000000 --- a/leetcode/solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [199. Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view) - -[中文文档](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md) - -## Description - -

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

- -

Example:

- -
-
-Input: [1,2,3,null,5,null,4]
-
-Output: [1, 3, 4]
-
-Explanation:
-
-
-
-   1            <---
-
- /   \
-
-2     3         <---
-
- \     \
-
-  5     4       <---
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public List rightSideView(TreeNode root) { - List ans = new ArrayList<>(); - robot(root, ans, 0); - return ans; - } - - private void robot(TreeNode root, List ans, int level) { - if (root == null) { - return; - } - if (ans.size() <= level) { - ans.add(root.val); - } - ans.set(level, root.val); - robot(root.left, ans, level + 1); - robot(root.right, ans, level + 1); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0200.Number of Islands/README_EN.md b/leetcode/solution/0200-0299/0200.Number of Islands/README_EN.md deleted file mode 100644 index f5c6eecd..00000000 --- a/leetcode/solution/0200-0299/0200.Number of Islands/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [200. Number of Islands](https://leetcode.com/problems/number-of-islands) - -[中文文档](/solution/0200-0299/0200.Number%20of%20Islands/README.md) - -## Description - -

Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

- -

Example 1:

- -
-
-Input:
-
-11110
-
-11010
-
-11000
-
-00000
-
-
-
-Output: 1
-
-
- -

Example 2:

- -
-
-Input:
-
-11000
-
-11000
-
-00100
-
-00011
-
-
-
-Output: 3
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0200.Number of Islands/Solution.cs b/leetcode/solution/0200-0299/0200.Number of Islands/Solution.cs deleted file mode 100644 index c6ecd934..00000000 --- a/leetcode/solution/0200-0299/0200.Number of Islands/Solution.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public int NumIslands(char[][] grid) - { - var queue = new Queue>(); - var lenI = grid.Length; - var lenJ = lenI == 0 ? 0 : grid[0].Length; - var paths = new int[,] { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; - var result = 0; - for (var i = 0; i < lenI; ++i) - { - for (var j = 0; j < lenJ; ++j) - { - if (grid[i][j] == '1') - { - ++result; - grid[i][j] = '0'; - queue.Enqueue(Tuple.Create(i, j)); - while (queue.Any()) - { - var position = queue.Dequeue(); - for (var k = 0; k < 4; ++k) - { - var next = Tuple.Create(position.Item1 + paths[k, 0], position.Item2 + paths[k, 1]); - if (next.Item1 >= 0 && next.Item1 < lenI && next.Item2 >= 0 && next.Item2 < lenJ && grid[next.Item1][next.Item2] == '1') - { - grid[next.Item1][next.Item2] = '0'; - queue.Enqueue(next); - } - } - } - } - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0200.Number of Islands/Solution.py b/leetcode/solution/0200-0299/0200.Number of Islands/Solution.py deleted file mode 100644 index c50f3d4a..00000000 --- a/leetcode/solution/0200-0299/0200.Number of Islands/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def numIslands(self, grid): - """ - :type grid: List[List[str]] - :rtype: int - """ - def dp(x, y): - if x >= 0 and x < len(grid) and y >= 0 and y < len(grid[x]) and grid[x][y] == '1': - grid[x][y] = '0' - dp(x-1, y) - dp(x+1, y) - dp(x, y-1) - dp(x, y+1) - ans = 0 - for i in range(len(grid)): - for j in range(len(grid[i])): - if grid[i][j] == '1': - ans += 1 - dp(i, j) - return ans diff --git a/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md b/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md deleted file mode 100644 index f41cd45b..00000000 --- a/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [201. Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range) - -[中文文档](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README.md) - -## Description - -

Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.

- -

Example 1:

- -
-
-Input: [5,7]
-
-Output: 4
-
-
- -

Example 2:

- -
-
-Input: [0,1]
-
-Output: 0
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.cs b/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.cs deleted file mode 100644 index 040e5ac5..00000000 --- a/leetcode/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.cs +++ /dev/null @@ -1,13 +0,0 @@ -public class Solution { - public int RangeBitwiseAnd(int m, int n) { - var and = m & n; - var xor = m ^ n; - var temp = 0; - while (xor > 0) - { - temp = (temp << 1) + 1; - xor >>= 1; - } - return and & (~temp); - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0202.Happy Number/README_EN.md b/leetcode/solution/0200-0299/0202.Happy Number/README_EN.md deleted file mode 100644 index a8fa3b86..00000000 --- a/leetcode/solution/0200-0299/0202.Happy Number/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [202. Happy Number](https://leetcode.com/problems/happy-number) - -[中文文档](/solution/0200-0299/0202.Happy%20Number/README.md) - -## Description - -

Write an algorithm to determine if a number is "happy".

- -

A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.

- -

Example: 

- -
-
-Input: 19
-
-Output: true
-
-Explanation: 
-
-12 + 92 = 82
-
-82 + 22 = 68
-
-62 + 82 = 100
-
-12 + 02 + 02 = 1
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isHappy(self, n: int) -> bool: - def get_next(n): - s = 0 - while n > 0: - n, digit = divmod(n, 10) - s += digit ** 2 - return s - - visited = set() - while n != 1 and n not in visited: - visited.add(n) - n = get_next(n) - return n == 1 -``` - -### **Java** - -```java -class Solution { - public boolean isHappy(int n) { - Set visited = new HashSet<>(); - while (n != 1 && !visited.contains(n)) { - visited.add(n); - n = getNext(n); - } - return n == 1; - } - - private int getNext(int n) { - int s = 0; - while (n > 0) { - int digit = n % 10; - s += digit * digit; - n /= 10; - } - return s; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0202.Happy Number/Solution.py b/leetcode/solution/0200-0299/0202.Happy Number/Solution.py deleted file mode 100644 index 577b9a94..00000000 --- a/leetcode/solution/0200-0299/0202.Happy Number/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def isHappy(self, n: int) -> bool: - def get_next(n): - s = 0 - while n > 0: - n, digit = divmod(n, 10) - s += digit ** 2 - return s - - visited = set() - while n != 1 and n not in visited: - visited.add(n) - n = get_next(n) - return n == 1 diff --git a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md b/leetcode/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md deleted file mode 100644 index b0e3702d..00000000 --- a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [203. Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) - -[中文文档](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md) - -## Description - -

Remove all elements from a linked list of integers that have value val.

- -

Example:

- -
-
-Input:  1->2->6->3->4->5->6, val = 6
-
-Output: 1->2->3->4->5
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def removeElements(self, head: ListNode, val: int) -> ListNode: - dummy = ListNode(-1, head) - pre = dummy - while pre and pre.next: - if pre.next.val != val: - pre = pre.next - else: - pre.next = pre.next.next - return dummy.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode removeElements(ListNode head, int val) { - ListNode dummy = new ListNode(-1, head); - ListNode pre = dummy; - while (pre != null && pre.next != null) { - if (pre.next.val != val) pre = pre.next; - else pre.next = pre.next.next; - } - return dummy.next; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.cs b/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.cs deleted file mode 100644 index 9c0afd3f..00000000 --- a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.cs +++ /dev/null @@ -1,25 +0,0 @@ -public class Solution { - public ListNode RemoveElements(ListNode head, int val) { - ListNode newHead = null; - ListNode newTail = null; - var current = head; - while (current != null) - { - if (current.val != val) - { - if (newHead == null) - { - newHead = newTail = current; - } - else - { - newTail.next = current; - newTail = current; - } - } - current = current.next; - } - if (newTail != null) newTail.next = null; - return newHead; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.py b/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.py deleted file mode 100644 index 72e0384c..00000000 --- a/leetcode/solution/0200-0299/0203.Remove Linked List Elements/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def removeElements(self, head: ListNode, val: int) -> ListNode: - dummy = ListNode(-1, head) - pre = dummy - while pre and pre.next: - if pre.next.val != val: - pre = pre.next - else: - pre.next = pre.next.next - return dummy.next \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0204.Count Primes/README_EN.md b/leetcode/solution/0200-0299/0204.Count Primes/README_EN.md deleted file mode 100644 index 28f430a7..00000000 --- a/leetcode/solution/0200-0299/0204.Count Primes/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [204. Count Primes](https://leetcode.com/problems/count-primes) - -[中文文档](/solution/0200-0299/0204.Count%20Primes/README.md) - -## Description - -

Count the number of prime numbers less than a non-negative number, n.

- -

Example:

- -
-
-Input: 10
-
-Output: 4
-
-Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def countPrimes(self, n: int) -> int: - if n < 2: - return 0 - res = 0 - primes = [True for _ in range(n)] - for i in range(2, n): - if primes[i]: - res += 1 - for j in range(i * i, n, i): - primes[j] = False - return res -``` - -### **Java** - -```java -class Solution { - public int countPrimes(int n) { - if (n < 2) return 0; - boolean[] primes = new boolean[n]; - Arrays.fill(primes, true); - int res = 0; - for (int i = 2; i < n; ++i) { - if (primes[i]) { - ++res; - if ((long) i * i < n) { - for (int j = i * i; j < n; j += i) { - primes[j] = false; - } - } - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0204.Count Primes/Solution.cpp b/leetcode/solution/0200-0299/0204.Count Primes/Solution.cpp deleted file mode 100644 index 2ecb07bd..00000000 --- a/leetcode/solution/0200-0299/0204.Count Primes/Solution.cpp +++ /dev/null @@ -1,29 +0,0 @@ -class Solution { - public: - - vector primes; - - int isPrime(int num){ - - int i = 1; - while( i < primes.size() && sqrt(num) >= primes[i] ){ - if( num % primes[i] == 0 ) return 0; - i++; - } - return 1; - } - - int countPrimes(int n) { - - if( n <= 2 ) return 0; - - primes.push_back(2); - - for(int i = 3; i < n; i += 2){ - if( isPrime(i) ) - primes.push_back(i); - } - - return primes.size(); - } -}; diff --git a/leetcode/solution/0200-0299/0204.Count Primes/Solution.cs b/leetcode/solution/0200-0299/0204.Count Primes/Solution.cs deleted file mode 100644 index f8be821a..00000000 --- a/leetcode/solution/0200-0299/0204.Count Primes/Solution.cs +++ /dev/null @@ -1,18 +0,0 @@ -public class Solution { - public int CountPrimes(int n) { - var count = 0; - var notPrime = new bool[n]; - for (var i = 2; i < n; ++i) - { - if (!notPrime[i]) - { - ++count; - for (var j = i + i; j < n; j += i) - { - notPrime[j] = true; - } - } - } - return count; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0204.Count Primes/Solution.js b/leetcode/solution/0200-0299/0204.Count Primes/Solution.js deleted file mode 100644 index 11e0c780..00000000 --- a/leetcode/solution/0200-0299/0204.Count Primes/Solution.js +++ /dev/null @@ -1,31 +0,0 @@ -// 600ms多 -const countPrimes2 = function (n) { - let arr = []; - let res = 0; - for (let i = 2; i < n; i++) { - if (arr[i] === undefined) { - arr[i] = 1; - res++; - for (let j = 2; i * j < n; j++) { - arr[i * j] = 0; - } - } - } - return res; -}; - -//200ms多 -const countPrimes = function (n) { - let arr = []; - let res = 0; - for (let i = 2; i < n; i++) { - if (arr[i] === undefined) { - arr[i] = 1; - res++; - for (let j = i; i * j < n; j++) { - arr[i * j] = 0; - } - } - } - return res; -}; diff --git a/leetcode/solution/0200-0299/0204.Count Primes/Solution.py b/leetcode/solution/0200-0299/0204.Count Primes/Solution.py deleted file mode 100644 index 55cfcb91..00000000 --- a/leetcode/solution/0200-0299/0204.Count Primes/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def countPrimes(self, n: int) -> int: - if n < 2: - return 0 - res = 0 - primes = [True for _ in range(n)] - for i in range(2, n): - if primes[i]: - res += 1 - for j in range(i * i, n, i): - primes[j] = False - return res diff --git a/leetcode/solution/0200-0299/0205.Isomorphic Strings/README_EN.md b/leetcode/solution/0200-0299/0205.Isomorphic Strings/README_EN.md deleted file mode 100644 index 8232d16c..00000000 --- a/leetcode/solution/0200-0299/0205.Isomorphic Strings/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [205. Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) - -[中文文档](/solution/0200-0299/0205.Isomorphic%20Strings/README.md) - -## Description - -

Given two strings s and t, determine if they are isomorphic.

- -

Two strings are isomorphic if the characters in s can be replaced to get t.

- -

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.

- -

Example 1:

- -
-
-Input: s = "egg", t = "add"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: s = "foo", t = "bar"
-
-Output: false
- -

Example 3:

- -
-
-Input: s = "paper", t = "title"
-
-Output: true
- -

Note:
- -You may assume both and have the same length.

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isIsomorphic(self, s: str, t: str) -> bool: - a2b, b2a = {}, {} - n = len(s) - for i in range(n): - a, b = s[i], t[i] - if (a in a2b and a2b[a] != b) or (b in b2a and b2a[b] != a): - return False - a2b[a] = b - b2a[b] = a - return True -``` - -### **Java** - -```java -class Solution { - public boolean isIsomorphic(String s, String t) { - int n = s.length(); - Map a2b = new HashMap<>(); - Map b2a = new HashMap<>(); - for (int i = 0; i < n; ++i) { - char a = s.charAt(i), b = t.charAt(i); - if ((a2b.containsKey(a) && a2b.get(a) != b) || (b2a.containsKey(b) && b2a.get(b) != a)) return false; - a2b.put(a, b); - b2a.put(b, a); - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.cs b/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.cs deleted file mode 100644 index 79a7524f..00000000 --- a/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public bool IsIsomorphic(string s, string t) { - if (s.Length != t.Length) return false; - var dict1 = new Dictionary(); - var dict2 = new Dictionary(); - for (var i = 0; i < s.Length; ++i) - { - char mapping1; - char mapping2; - var found1 = dict1.TryGetValue(s[i], out mapping1); - var found2 = dict2.TryGetValue(t[i], out mapping2); - if (found1 ^ found2) return false; - if (!found1) - { - dict1.Add(s[i], t[i]); - dict2.Add(t[i], s[i]); - } - else if (mapping1 != t[i] || mapping2 != s[i]) - { - return false; - } - } - return true; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.py b/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.py deleted file mode 100644 index 2950ad0b..00000000 --- a/leetcode/solution/0200-0299/0205.Isomorphic Strings/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def isIsomorphic(self, s: str, t: str) -> bool: - a2b, b2a = {}, {} - n = len(s) - for i in range(n): - a, b = s[i], t[i] - if (a in a2b and a2b[a] != b) or (b in b2a and b2a[b] != a): - return False - a2b[a] = b - b2a[b] = a - return True diff --git a/leetcode/solution/0200-0299/0206.Reverse Linked List/README_EN.md b/leetcode/solution/0200-0299/0206.Reverse Linked List/README_EN.md deleted file mode 100644 index 83cb2914..00000000 --- a/leetcode/solution/0200-0299/0206.Reverse Linked List/README_EN.md +++ /dev/null @@ -1,150 +0,0 @@ -# [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list) - -[中文文档](/solution/0200-0299/0206.Reverse%20Linked%20List/README.md) - -## Description - -

Reverse a singly linked list.

- -

Example:

- -
-
-Input: 1->2->3->4->5->NULL
-
-Output: 5->4->3->2->1->NULL
-
-
- -

Follow up:

- -

A linked list can be reversed either iteratively or recursively. Could you implement both?

- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def reverseList(self, head: ListNode) -> ListNode: - pre, p = None, head - while p: - q = p.next - p.next = pre - pre = p - p = q - return pre -``` - -### **Java** - -Iterative version: - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode reverseList(ListNode head) { - ListNode pre = null, p = head; - while (p != null) { - ListNode q = p.next; - p.next = pre; - pre = p; - p = q; - } - return pre; - } -} -``` - -Recursive version: - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public ListNode reverseList(ListNode head) { - if (head == null || head.next == null) { - return head; - } - ListNode res = reverseList(head.next); - head.next.next = head; - head.next = null; - return res; - } -} -``` - -### **JavaScript** - -```js -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @return {ListNode} - */ -var reverseList = function (head) { - let node = head; - let pre = null; - while (node) { - let cur = node; - node = cur.next; - cur.next = pre; - pre = cur; - } - return pre; -}; -``` - -### **Go** - -```go -func reverseList(head *ListNode) *ListNode { - if head == nil ||head.Next == nil { - return head - } - dummyHead := &ListNode{} - cur := head - for cur != nil { - tmp := cur.Next - cur.Next = dummyHead.Next - dummyHead.Next = cur - cur = tmp - } - return dummyHead.Next -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.cs b/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.cs deleted file mode 100644 index 65f169c9..00000000 --- a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.cs +++ /dev/null @@ -1,13 +0,0 @@ -public class Solution { - public ListNode ReverseList(ListNode head) { - ListNode newHead = null; - while (head != null) - { - var next = head.next; - head.next = newHead; - newHead = head; - head = next; - } - return newHead; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.go b/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.go deleted file mode 100644 index 5e20ffe0..00000000 --- a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.go +++ /dev/null @@ -1,14 +0,0 @@ -func reverseList(head *ListNode) *ListNode { - if head == nil ||head.Next == nil { - return head - } - dummyHead := &ListNode{} - cur := head - for cur != nil { - tmp := cur.Next - cur.Next = dummyHead.Next - dummyHead.Next = cur - cur = tmp - } - return dummyHead.Next -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.js b/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.js deleted file mode 100644 index 19d396c3..00000000 --- a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} head - * @return {ListNode} - */ -var reverseList = function (head) { - let node = head; - let pre = null; - while (node) { - let cur = node; - node = cur.next; - cur.next = pre; - pre = cur; - } - return pre; -}; diff --git a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.py b/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.py deleted file mode 100644 index fb8aabb5..00000000 --- a/leetcode/solution/0200-0299/0206.Reverse Linked List/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def reverseList(self, head: ListNode) -> ListNode: - pre, p = None, head - while p: - q = p.next - p.next = pre - pre = p - p = q - return pre diff --git a/leetcode/solution/0200-0299/0207.Course Schedule/README_EN.md b/leetcode/solution/0200-0299/0207.Course Schedule/README_EN.md deleted file mode 100644 index c91e8429..00000000 --- a/leetcode/solution/0200-0299/0207.Course Schedule/README_EN.md +++ /dev/null @@ -1,64 +0,0 @@ -# [207. Course Schedule](https://leetcode.com/problems/course-schedule) - -[中文文档](/solution/0200-0299/0207.Course%20Schedule/README.md) - -## Description - -

There are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.

- -

Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]

- -

Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses?

- -

 

-

Example 1:

- -
-Input: numCourses = 2, prerequisites = [[1,0]]
-Output: true
-Explanation: There are a total of 2 courses to take. 
-             To take course 1 you should have finished course 0. So it is possible.
-
- -

Example 2:

- -
-Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
-Output: false
-Explanation: There are a total of 2 courses to take. 
-             To take course 1 you should have finished course 0, and to take course 0 you should
-             also have finished course 1. So it is impossible.
-
- -

 

-

Constraints:

- -
    -
  • The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read more about how a graph is represented.
  • -
  • You may assume that there are no duplicate edges in the input prerequisites.
  • -
  • 1 <= numCourses <= 10^5
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0207.Course Schedule/Solution.cs b/leetcode/solution/0200-0299/0207.Course Schedule/Solution.cs deleted file mode 100644 index 3532d64d..00000000 --- a/leetcode/solution/0200-0299/0207.Course Schedule/Solution.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public bool CanFinish(int numCourses, int[][] prerequisites) { - var indegree = new int[numCourses]; - var edgeCount = prerequisites.Length; - var edge = new List[numCourses]; - for (var i = 0; i < edgeCount; ++i) - { - var child = prerequisites[i][0]; - var parent = prerequisites[i][1]; - if (edge[parent] == null) - { - edge[parent] = new List(); - } - edge[parent].Add(child); - ++indegree[child]; - } - - var queue = new Queue(); - for (var i = 0; i < numCourses; ++i) - { - if (indegree[i] == 0) queue.Enqueue(i); - } - - var count = 0; - while (queue.Count > 0) - { - var node = queue.Dequeue(); - ++count; - if (edge[node] != null) - { - foreach (var next in edge[node]) - { - if (--indegree[next] == 0) - { - queue.Enqueue(next); - } - } - } - } - return count == numCourses; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md b/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md deleted file mode 100644 index f3e8fe1a..00000000 --- a/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [208. Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree) - -[中文文档]() - -## Description - -

Implement a trie with insert, search, and startsWith methods.

- -

Example:

- -
-
-Trie trie = new Trie();
-
-
-
-trie.insert("apple");
-
-trie.search("apple");   // returns true
-
-trie.search("app");     // returns false
-
-trie.startsWith("app"); // returns true
-
-trie.insert("app");   
-
-trie.search("app");     // returns true
-
-
- -

Note:

- -
    -
  • You may assume that all inputs are consist of lowercase letters a-z.
  • -
  • All inputs are guaranteed to be non-empty strings.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.cs b/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.cs deleted file mode 100644 index 4856875e..00000000 --- a/leetcode/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -class TrieNode { - public bool IsEnd { get; set; } - public TrieNode[] Children { get; set; } - public TrieNode() { - Children = new TrieNode[26]; - } -} - -public class Trie { - private TrieNode root; - - public Trie() { - root = new TrieNode(); - } - - public void Insert(string word) { - var node = root; - for (var i = 0; i < word.Length; ++i) - { - TrieNode nextNode; - var index = word[i] - 'a'; - nextNode = node.Children[index]; - if (nextNode == null) - { - nextNode = new TrieNode(); - node.Children[index] = nextNode; - } - node = nextNode; - } - node.IsEnd = true; - } - - public bool Search(string word) { - var node = root; - for (var i = 0; i < word.Length; ++i) - { - var nextNode = node.Children[word[i] - 'a']; - if (nextNode == null) - { - return false; - } - node = nextNode; - } - return node.IsEnd; - } - - public bool StartsWith(string word) { - var node = root; - for (var i = 0; i < word.Length; ++i) - { - var nextNode = node.Children[word[i] - 'a']; - if (nextNode == null) - { - return false; - } - node = nextNode; - } - return node.IsEnd || node.Children.Any(c => c != null); - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md b/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md deleted file mode 100644 index a2994221..00000000 --- a/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/README_EN.md +++ /dev/null @@ -1,45 +0,0 @@ -# [209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum) - -[中文文档](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README.md) - -## Description - -

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.

- -

Example: 

- -
-
-Input: s = 7, nums = [2,3,1,2,4,3]
-
-Output: 2
-
-Explanation: the subarray [4,3] has the minimal length under the problem constraint.
- -
Follow up:
- -
If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n). 
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/Solution.cs b/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/Solution.cs deleted file mode 100644 index e88bb30f..00000000 --- a/leetcode/solution/0200-0299/0209.Minimum Size Subarray Sum/Solution.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -public class Solution { - public int MinSubArrayLen(int s, int[] nums) { - var result = int.MaxValue; - var l = 0; - var r = -1; - var sum = 0; - while (r + 1 < nums.Length) - { - sum += nums[++r]; - while (sum - nums[l] >= s) - { - sum -= nums[l++]; - } - if (sum >= s) - { - result = Math.Min(result, r - l + 1); - sum -= nums[l++]; - } - } - - if (result == int.MaxValue) result = 0; - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0210.Course Schedule II/README_EN.md b/leetcode/solution/0200-0299/0210.Course Schedule II/README_EN.md deleted file mode 100644 index 70657226..00000000 --- a/leetcode/solution/0200-0299/0210.Course Schedule II/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [210. Course Schedule II](https://leetcode.com/problems/course-schedule-ii) - -[中文文档](/solution/0200-0299/0210.Course%20Schedule%20II/README.md) - -## Description - -

There are a total of n courses you have to take, labeled from 0 to n-1.

- -

Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]

- -

Given the total number of courses and a list of prerequisite pairs, return the ordering of courses you should take to finish all courses.

- -

There may be multiple correct orders, you just need to return one of them. If it is impossible to finish all courses, return an empty array.

- -

Example 1:

- -
-
-Input: 2, [[1,0]] 
-
-Output: [0,1]
-
-Explanation: There are a total of 2 courses to take. To take course 1 you should have finished   
-
-             course 0. So the correct course order is [0,1] .
- -

Example 2:

- -
-
-Input: 4, [[1,0],[2,0],[3,1],[3,2]]
-
-Output: [0,1,2,3] or [0,2,1,3]
-
-Explanation: There are a total of 4 courses to take. To take course 3 you should have finished both     
-
-             courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0. 
-
-             So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3] .
- -

Note:

- -
    -
  1. The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read more about how a graph is represented.
  2. -
  3. You may assume that there are no duplicate edges in the input prerequisites.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0210.Course Schedule II/Solution.cs b/leetcode/solution/0200-0299/0210.Course Schedule II/Solution.cs deleted file mode 100644 index dc598f0d..00000000 --- a/leetcode/solution/0200-0299/0210.Course Schedule II/Solution.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int[] FindOrder(int numCourses, int[][] prerequisites) { - var indegree = new int[numCourses]; - var edgeCount = prerequisites.Length; - var edge = new List[numCourses]; - for (var i = 0; i < edgeCount; ++i) - { - var child = prerequisites[i][0]; - var parent = prerequisites[i][1]; - if (edge[parent] == null) - { - edge[parent] = new List(); - } - edge[parent].Add(child); - ++indegree[child]; - } - - var queue = new Queue(); - for (var i = 0; i < numCourses; ++i) - { - if (indegree[i] == 0) queue.Enqueue(i); - } - - var result = new int[numCourses]; - var count = 0; - while (queue.Count > 0) - { - var node = queue.Dequeue(); - result[count++] = node; - if (edge[node] != null) - { - foreach (var next in edge[node]) - { - if (--indegree[next] == 0) - { - queue.Enqueue(next); - } - } - } - } - return count == numCourses ? result : new int[0]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md b/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md deleted file mode 100644 index d4da969a..00000000 --- a/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [211. Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure) - -[中文文档](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README.md) - -## Description - -

You should design a data structure that supports adding new words and finding if a string matches any previously added string.

- -

Implement the WordDictionary class:

- -
    -
  • WordDictionary() Initializes the object.
  • -
  • void addWord(word) adds word to the data structure, it can be matched later.
  • -
  • bool search(word) returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.
  • -
- -

 

-

Example:

- -
-Input
-["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
-[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
-Output
-[null,null,null,null,false,true,true,true]
-
-Explanation
-WordDictionary wordDictionary = new WordDictionary();
-wordDictionary.addWord("bad");
-wordDictionary.addWord("dad");
-wordDictionary.addWord("mad");
-wordDictionary.search("pad"); // return False
-wordDictionary.search("bad"); // return True
-wordDictionary.search(".ad"); // return True
-wordDictionary.search("b.."); // return True
-
- -

 

-

Constraints:

- -
    -
  • 1 <= word.length <= 500
  • -
  • word in addWord consists lower-case English letters.
  • -
  • word in search consist of  '.' or lower-case English letters.
  • -
  • At most 50000 calls will be made to addWord and search .
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/Solution.cs b/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/Solution.cs deleted file mode 100644 index d0d04495..00000000 --- a/leetcode/solution/0200-0299/0211.Design Add and Search Words Data Structure/Solution.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -class TrieNode { - public bool IsEnd { get; set; } - public TrieNode[] Children { get; set; } - public TrieNode() { - Children = new TrieNode[26]; - } -} - -public class WordDictionary { - private TrieNode root; - - public WordDictionary() { - root = new TrieNode(); - } - - public void AddWord(string word) { - var node = root; - for (var i = 0; i < word.Length; ++i) - { - TrieNode nextNode; - var index = word[i] - 'a'; - nextNode = node.Children[index]; - if (nextNode == null) - { - nextNode = new TrieNode(); - node.Children[index] = nextNode; - } - node = nextNode; - } - node.IsEnd = true; - } - - public bool Search(string word) { - var queue = new Queue(); - queue.Enqueue(root); - for (var i = 0; i < word.Length; ++i) - { - var count = queue.Count; - while (count-- > 0) - { - var node = queue.Dequeue(); - if (word[i] == '.') - { - foreach (var nextNode in node.Children) - { - if (nextNode != null) - { - queue.Enqueue(nextNode); - } - } - } - else - { - var nextNode = node.Children[word[i] - 'a']; - if (nextNode != null) - { - queue.Enqueue(nextNode); - } - } - } - } - return queue.Any(n => n.IsEnd); - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0213.House Robber II/README_EN.md b/leetcode/solution/0200-0299/0213.House Robber II/README_EN.md deleted file mode 100644 index aee70db7..00000000 --- a/leetcode/solution/0200-0299/0213.House Robber II/README_EN.md +++ /dev/null @@ -1,104 +0,0 @@ -# [213. House Robber II](https://leetcode.com/problems/house-robber-ii) - -[中文文档](/solution/0200-0299/0213.House%20Robber%20II/README.md) - -## Description - -

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

- -

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

- -

Example 1:

- -
-
-Input: [2,3,2]
-
-Output: 3
-
-Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2),
-
-             because they are adjacent houses.
-
-
- -

Example 2:

- -
-
-Input: [1,2,3,1]
-
-Output: 4
-
-Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
-
-             Total amount you can rob = 1 + 3 = 4.
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def rob(self, nums: List[int]) -> int: - def _rob(nums): - n = len(nums) - if n == 0: - return 0 - if n == 1: - return nums[0] - pre, cur = nums[0], max(nums[0], nums[1]) - for i in range(2, n): - t = max(pre + nums[i], cur) - pre, cur = cur, t - return cur - - n = len(nums) - if n == 1: - return nums[0] - return max(_rob(nums[1:]), _rob(nums[:-1])) -``` - -### **Java** - -```java -class Solution { - public int rob(int[] nums) { - int n = nums.length; - if (n == 1) { - return nums[0]; - } - int sub1 = robInternal(Arrays.copyOfRange(nums, 0, n - 1)); - int sub2 = robInternal(Arrays.copyOfRange(nums, 1, n)); - return Math.max(sub1, sub2); - } - - private int robInternal(int[] nums) { - int n; - if ((n = nums.length) == 0) { - return 0; - } - if (n == 1) { - return nums[0]; - } - int pre = nums[0]; - int cur = Math.max(nums[0], nums[1]); - for (int i = 2; i < n; ++i) { - int t = Math.max(pre + nums[i], cur); - pre = cur; - cur = t; - } - return cur; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0213.House Robber II/Solution.go b/leetcode/solution/0200-0299/0213.House Robber II/Solution.go deleted file mode 100644 index ebcda584..00000000 --- a/leetcode/solution/0200-0299/0213.House Robber II/Solution.go +++ /dev/null @@ -1,26 +0,0 @@ -func rob(nums []int) int { - l := len(nums) - if l == 0 { - return 0 - } - if l == 1 { - return nums[0] - } - res1 := _rob(nums[:l-1]) - res2 := _rob(nums[1:]) - if res1 < res2 { - return res2 - } - return res1 -} - -func _rob(nums []int) int { - x, y := 0, 0 - for _, n := range nums { - x, y = y, x+n - if x > y { - y = x - } - } - return y -} diff --git a/leetcode/solution/0200-0299/0213.House Robber II/Solution.py b/leetcode/solution/0200-0299/0213.House Robber II/Solution.py deleted file mode 100644 index 8bd11953..00000000 --- a/leetcode/solution/0200-0299/0213.House Robber II/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution: - def rob(self, nums: List[int]) -> int: - def _rob(nums): - n = len(nums) - if n == 0: - return 0 - if n == 1: - return nums[0] - pre, cur = nums[0], max(nums[0], nums[1]) - for i in range(2, n): - t = max(pre + nums[i], cur) - pre, cur = cur, t - return cur - - n = len(nums) - if n == 1: - return nums[0] - return max(_rob(nums[1:]), _rob(nums[:-1])) diff --git a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md b/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md deleted file mode 100644 index b94b2a9b..00000000 --- a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [215. Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array) - -[中文文档](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README.md) - -## Description - -

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

- -

Example 1:

- -
-
-Input: [3,2,1,5,6,4] and k = 2
-
-Output: 5
-
-
- -

Example 2:

- -
-
-Input: [3,2,3,1,2,4,5,5,6] and k = 4
-
-Output: 4
- -

Note:
- -You may assume k is always valid, 1 ≤ k ≤ array's length.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.cpp b/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.cpp deleted file mode 100644 index 849874c9..00000000 --- a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.cpp +++ /dev/null @@ -1,44 +0,0 @@ -class Solution { -public: - int findKthLargest(vector& nums, int k) { - --k ; - int ii = 0, jj = nums.size()-1 ; - int i, j ; - while (true) - { - i = ii, j = jj ; - if (i + 63 < j) - { - const int mid = i + (j-i)/2 ; - if (nums[j] >= nums[mid] && nums[j] <= nums[i] - || nums[j] <= nums[mid] && nums[j] >= nums[i]) - { - swap(nums[i], nums[j]) ; - } - else if (nums[mid] >= nums[i] && nums[mid] <= nums[j] - || nums[mid] <= nums[i] && nums[mid] >= nums[j]) - { - swap(nums[i], nums[mid]) ; - } - } - while (i < j) - { - while (i < j && nums.at(i) >= nums.at(j)) - --j ; - swap(nums[i], nums[j]) ; - while (i < j && nums.at(i) >= nums.at(j)) - ++i ; - swap(nums[i], nums[j]) ; - } - - if (i > k) - jj = i-1 ; - else if (i < k) - ii = i+1 ; - else - return nums[k] ; - } - - return nums.at(k) ; - } -}; diff --git a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.go b/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.go deleted file mode 100644 index 7f1c8f74..00000000 --- a/leetcode/solution/0200-0299/0215.Kth Largest Element in an Array/Solution.go +++ /dev/null @@ -1,35 +0,0 @@ -func adjustHeap(heap []int,i,k int){ - child := i*2+1 - for child < k{ - if child + 1 < k && heap[child] > heap[child+1]{ - child++ - } - if heap[child] > heap[i]{ - break - } - - heap[child],heap[i] = heap[i],heap[child] - i = child - child = i * 2 + 1 - } -} - - -func findKthLargest(nums []int, k int) int { - - minHeap := make([]int,k) - copy(minHeap,nums) - - for i := k/2-1;i>=0;i--{ - adjustHeap(minHeap,i,k) - } - - for i := k;i < len(nums);i++{ - if nums[i] > minHeap[0]{ - minHeap[0] = nums[i] - adjustHeap(minHeap,0,k) - } - } - - return minHeap[0] -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0216.Combination Sum III/README_EN.md b/leetcode/solution/0200-0299/0216.Combination Sum III/README_EN.md deleted file mode 100644 index 644ea329..00000000 --- a/leetcode/solution/0200-0299/0216.Combination Sum III/README_EN.md +++ /dev/null @@ -1,62 +0,0 @@ -# [216. Combination Sum III](https://leetcode.com/problems/combination-sum-iii) - -[中文文档](/solution/0200-0299/0216.Combination%20Sum%20III/README.md) - -## Description - -
- -

Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.

- -

Note:

- -
    -
  • All numbers will be positive integers.
  • -
  • The solution set must not contain duplicate combinations.
  • -
- -

Example 1:

- -
-
-Input: k = 3, n = 7
-
-Output: [[1,2,4]]
-
-
- -

Example 2:

- -
-
-Input: k = 3, n = 9
-
-Output: [[1,2,6], [1,3,5], [2,3,4]]
-
-
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0216.Combination Sum III/Solution.cs b/leetcode/solution/0200-0299/0216.Combination Sum III/Solution.cs deleted file mode 100644 index 4c8778e4..00000000 --- a/leetcode/solution/0200-0299/0216.Combination Sum III/Solution.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Collections.Generic; - -public class Solution -{ - public IList> CombinationSum3(int k, int n) - { - if (n == 0 || k == 0) return new IList[0]; - - var paths = new List[n + 1, k + 1]; - paths[0, 0] = new List(); - for (var c = 1; c <= 9; ++c) - { - for (var j = n; j >= c; --j) - { - for (var kk = 1; kk <= k; ++kk) - { - if (paths[j - c, kk - 1] != null) - { - if (paths[j, kk] == null) - { - paths[j, kk] = new List(); - } - paths[j, kk].Add(c); - } - } - } - } - - var results = new List>(); - if (paths[n, k] != null && paths[n, k].Count > 0) GenerateResults(results, new Stack(), paths, k, n, paths[n, k].Count - 1); - return results; - } - - private void GenerateResults(IList> results, Stack result, List[,] paths, int k, int n, - int maxIndex) - { - if (n == 0) - { - results.Add(new List(result)); - return; - } - for (var i = maxIndex; i >= 0; --i) - { - var value = paths[n, k][i]; - result.Push(value); - var nextMaxIndex = paths[n - value, k - 1].BinarySearch(value); - if (nextMaxIndex >= 0) - { - --nextMaxIndex; - } - else if (nextMaxIndex < 0) - { - nextMaxIndex = ~nextMaxIndex - 1; - } - GenerateResults(results, result, paths, k - 1, n - value, nextMaxIndex); - result.Pop(); - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0217.Contains Duplicate/README_EN.md b/leetcode/solution/0200-0299/0217.Contains Duplicate/README_EN.md deleted file mode 100644 index 78e7bbbb..00000000 --- a/leetcode/solution/0200-0299/0217.Contains Duplicate/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [217. Contains Duplicate](https://leetcode.com/problems/contains-duplicate) - -[中文文档](/solution/0200-0299/0217.Contains%20Duplicate/README.md) - -## Description - -

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

- -

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

- -

Example 1:

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

Example 2:

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

Example 3:

- -
-
-Input: [1,1,1,3,3,4,3,2,4,2]
-
-Output: true
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def containsDuplicate(self, nums: List[int]) -> bool: - return len(nums) != len(set(nums)) -``` - -### **Java** - -```java -class Solution { - public boolean containsDuplicate(int[] nums) { - Set set = new HashSet<>(); - for (int e : nums) { - if (set.contains(e)) return true; - set.add(e); - } - return false; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.cs b/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.cs deleted file mode 100644 index fddf9b35..00000000 --- a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.cs +++ /dev/null @@ -1,11 +0,0 @@ -// https://leetcode.com/problems/contains-duplicate/ - -using System.Linq; - -public partial class Solution -{ - public bool ContainsDuplicate(int[] nums) - { - return nums.Distinct().Count() < nums.Length; - } -} diff --git a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.js b/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.js deleted file mode 100644 index bbafc8e4..00000000 --- a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.js +++ /dev/null @@ -1,23 +0,0 @@ -const containsDuplicate = function (nums) { - let set = new Set(); - nums.forEach((e) => { - set.add(e); - }); - return set.size !== nums.length; -}; -var containsDuplicate2 = function (nums) { - return new Set(nums).size !== nums.length; -}; -var containsDuplicate3 = function (nums) { - const map = {}; // key => number, value => count - - for (let i = 0; i < nums.length; i++) { - if (map[nums[i]] !== undefined) { - return true; - } else { - map[nums[i]] = 1; - } - } - - return false; -}; diff --git a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.py b/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.py deleted file mode 100644 index 0648d87c..00000000 --- a/leetcode/solution/0200-0299/0217.Contains Duplicate/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def containsDuplicate(self, nums: List[int]) -> bool: - return len(nums) != len(set(nums)) diff --git a/leetcode/solution/0200-0299/0219.Contains Duplicate II/README_EN.md b/leetcode/solution/0200-0299/0219.Contains Duplicate II/README_EN.md deleted file mode 100644 index 1538e827..00000000 --- a/leetcode/solution/0200-0299/0219.Contains Duplicate II/README_EN.md +++ /dev/null @@ -1,94 +0,0 @@ -# [219. Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii) - -[中文文档](/solution/0200-0299/0219.Contains%20Duplicate%20II/README.md) - -## Description - -

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

- -
- -

Example 1:

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

Example 2:

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

Example 3:

- -
-
-Input: nums = [1,2,3,1,2,3], k = 2
-
-Output: false
-
-
- -
- -
- -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: - helper = {} - for i, v in enumerate(nums): - if v in helper and i - helper[v] <= k: - return True - helper[v] = i - return False -``` - -### **Java** - -```java -class Solution { - public boolean containsNearbyDuplicate(int[] nums, int k) { - Map helper = new HashMap<>(); - for (int i = 0, n = nums.length; i < n; ++i) { - if (helper.containsKey(nums[i])) { - int j = helper.get(nums[i]); - if (i - j <= k) { - return true; - } - } - helper.put(nums[i], i); - } - return false; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.cs b/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.cs deleted file mode 100644 index 8bc22ff4..00000000 --- a/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.cs +++ /dev/null @@ -1,37 +0,0 @@ -// https://leetcode.com/problems/contains-duplicate-ii/ - -using System; -using System.Collections.Generic; -using System.Linq; - -public partial class Solution -{ - public bool ContainsNearbyDuplicate(int[] nums, int k) - { - //var sorted = nums.Select((n, i) => Tuple.Create(n, i)).OrderBy(t => t.Item1).ThenBy(t => t.Item2).ToList(); - //for (var i = 1; i < sorted.Count; ++i) - //{ - // if (sorted[i - 1].Item1 == sorted[i].Item1 && sorted[i].Item2 - sorted[i - 1].Item2 <= k) - // { - // return true; - // } - //} - //return false; - - if (k <= 0) return false; - var index = new HashSet(); - for (int i = 0; i < nums.Length; ++i) - { - if (index.Contains(nums[i])) - { - return true; - } - if (index.Count == k) - { - index.Remove(nums[i - k]); - } - index.Add(nums[i]); - } - return false; - } -} diff --git a/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.py b/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.py deleted file mode 100644 index 2497f324..00000000 --- a/leetcode/solution/0200-0299/0219.Contains Duplicate II/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: - helper = {} - for i, v in enumerate(nums): - if v in helper and i - helper[v] <= k: - return True - helper[v] = i - return False diff --git a/leetcode/solution/0200-0299/0220.Contains Duplicate III/README_EN.md b/leetcode/solution/0200-0299/0220.Contains Duplicate III/README_EN.md deleted file mode 100644 index 706e57ec..00000000 --- a/leetcode/solution/0200-0299/0220.Contains Duplicate III/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [220. Contains Duplicate III](https://leetcode.com/problems/contains-duplicate-iii) - -[中文文档](/solution/0200-0299/0220.Contains%20Duplicate%20III/README.md) - -## Description - -

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

- -
- -

Example 1:

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

Example 2:

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

Example 3:

- -
-
-Input: nums = [1,5,9,1,5,9], k = 2, t = 3
-
-Output: false
-
-
- -
- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0220.Contains Duplicate III/Solution.cs b/leetcode/solution/0200-0299/0220.Contains Duplicate III/Solution.cs deleted file mode 100644 index 80e68063..00000000 --- a/leetcode/solution/0200-0299/0220.Contains Duplicate III/Solution.cs +++ /dev/null @@ -1,35 +0,0 @@ -// https://leetcode.com/problems/contains-duplicate-iii/ - -using System.Collections.Generic; - -public partial class Solution -{ - public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) - { - - if (k <= 0 || t < 0) return false; - var index = new SortedList(); - for (int i = 0; i < nums.Length; ++i) - { - if (index.ContainsKey(nums[i])) - { - return true; - } - index.Add(nums[i], null); - var j = index.IndexOfKey(nums[i]); - if (j > 0 && (long)nums[i] - index.Keys[j - 1] <= t) - { - return true; - } - if (j < index.Count - 1 && (long)index.Keys[j + 1] - nums[i] <= t) - { - return true; - } - if (index.Count > k) - { - index.Remove(nums[i - k]); - } - } - return false; - } -} diff --git a/leetcode/solution/0200-0299/0221.Maximal Square/README_EN.md b/leetcode/solution/0200-0299/0221.Maximal Square/README_EN.md deleted file mode 100644 index 55bf8ffe..00000000 --- a/leetcode/solution/0200-0299/0221.Maximal Square/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [221. Maximal Square](https://leetcode.com/problems/maximal-square) - -[中文文档](/solution/0200-0299/0221.Maximal%20Square/README.md) - -## Description - -

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

- -

Example:

- -
-
-Input: 
-
-
-
-1 0 1 0 0
-
-1 0 1 1 1
-
-1 1 1 1 1
-
-1 0 0 1 0
-
-
-
-Output: 4
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0221.Maximal Square/Solution.cs b/leetcode/solution/0200-0299/0221.Maximal Square/Solution.cs deleted file mode 100644 index 997688aa..00000000 --- a/leetcode/solution/0200-0299/0221.Maximal Square/Solution.cs +++ /dev/null @@ -1,40 +0,0 @@ -// https://leetcode.com/problems/maximal-square/ - -using System; - -public partial class Solution -{ - public int MaximalSquare(char[][] matrix) - { - var lengthI = matrix.Length; - var lengthJ = lengthI == 0 ? 0 : matrix[0].Length; - if (lengthI == 0 || lengthJ == 0) return 0; - - var lenI = new int[lengthI, lengthJ]; - var lenJ = new int[lengthI, lengthJ]; - var f = new int[lengthI, lengthJ]; - var maxSideLength = 0; - for (var i = 0; i < lengthI; ++i) - { - for (var j = 0; j < lengthJ ; ++j) - { - if (matrix[i][j] == '1') - { - lenI[i, j] = i == 0 ? 1 : lenI[i - 1, j] + 1; - lenJ[i, j] = j == 0 ? 1 : lenJ[i, j - 1] + 1; - if (i == 0 || j == 0) - { - f[i, j] = 1; - } - else - { - f[i, j] = Math.Min(Math.Min(f[i - 1, j - 1] + 1, lenI[i, j]), lenJ[i, j]); - } - if (f[i, j] > maxSideLength) maxSideLength = f[i, j]; - } - } - } - - return maxSideLength * maxSideLength; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md b/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md deleted file mode 100644 index 2e949d17..00000000 --- a/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [222. Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes) - -[中文文档](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README.md) - -## Description - -

Given a complete binary tree, count the number of nodes.

- -

Note:

- -

Definition of a complete binary tree from Wikipedia:
- -In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

- -

Example:

- -
-
-Input: 
-
-    1
-
-   / \
-
-  2   3
-
- / \  /
-
-4  5 6
-
-
-
-Output: 6
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.cs b/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.cs deleted file mode 100644 index 9c828210..00000000 --- a/leetcode/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.cs +++ /dev/null @@ -1,38 +0,0 @@ -// https://leetcode.com/problems/count-complete-tree-nodes/ - -using System; - -public class Solution -{ - public int CountNodes(TreeNode root) - { - if (root == null) return 0; - var lastNodeOffset = CountNodes_GetLastNodeOffset(root, 0); - var totalDepth = CountNodes_GetDeepth(root); - return (int)Math.Pow(2, totalDepth - 1) - 1 + lastNodeOffset; - } - - private int CountNodes_GetLastNodeOffset(TreeNode node, int offset) - { - if (node == null) return offset; - if (node.left == null) return offset + 1; - var leftDepth = CountNodes_GetDeepth(node.left); - var rightDepth = CountNodes_GetDeepth(node.right); - if (leftDepth > rightDepth) - { - return CountNodes_GetLastNodeOffset(node.left, offset); - } - return CountNodes_GetLastNodeOffset(node.right, offset + (int)Math.Pow(2, leftDepth - 1)); - } - - private int CountNodes_GetDeepth(TreeNode node) - { - var depth = 0; - while (node != null) - { - ++depth; - node = node.left; - } - return depth; - } -} diff --git a/leetcode/solution/0200-0299/0223.Rectangle Area/README_EN.md b/leetcode/solution/0200-0299/0223.Rectangle Area/README_EN.md deleted file mode 100644 index 13d0f05d..00000000 --- a/leetcode/solution/0200-0299/0223.Rectangle Area/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [223. Rectangle Area](https://leetcode.com/problems/rectangle-area) - -[中文文档](/solution/0200-0299/0223.Rectangle%20Area/README.md) - -## Description - -

Find the total area covered by two rectilinear rectangles in a 2D plane.

- -

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

- -![](./images/rectangle_area.png) - -

Example:

- -
-
-Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2
-
-Output: 45
- -

Note:

- -

Assume that the total area is never beyond the maximum possible value of int.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0223.Rectangle Area/Solution.cs b/leetcode/solution/0200-0299/0223.Rectangle Area/Solution.cs deleted file mode 100644 index 73410231..00000000 --- a/leetcode/solution/0200-0299/0223.Rectangle Area/Solution.cs +++ /dev/null @@ -1,20 +0,0 @@ -// https://leetcode.com/problems/rectangle-area/ - -using System; - -public partial class Solution -{ - public int ComputeArea(int A, int B, int C, int D, int E, int F, int G, int H) - { - var area = (long)(C - A) * (D - B) + (G - E) * (H - F); - var overlapA = Math.Max(A, E); - var overlapB = Math.Max(B, F); - var overlapC = Math.Min(C, G); - var overlapD = Math.Min(D, H); - if (overlapA < overlapC && overlapB < overlapD) - { - area -= (overlapC - overlapA) * (overlapD - overlapB); - } - return (int)area; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0224.Basic Calculator/README_EN.md b/leetcode/solution/0200-0299/0224.Basic Calculator/README_EN.md deleted file mode 100644 index ffd7d569..00000000 --- a/leetcode/solution/0200-0299/0224.Basic Calculator/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [224. Basic Calculator](https://leetcode.com/problems/basic-calculator) - -[中文文档](/solution/0200-0299/0224.Basic%20Calculator/README.md) - -## Description - -

Implement a basic calculator to evaluate a simple expression string.

- -

The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .

- -

Example 1:

- -
-
-Input: "1 + 1"
-
-Output: 2
-
-
- -

Example 2:

- -
-
-Input: " 2-1 + 2 "
-
-Output: 3
- -

Example 3:

- -
-
-Input: "(1+(4+5+2)-3)+(6+8)"
-
-Output: 23
- -Note: - -
    -
  • You may assume that the given expression is always valid.
  • -
  • Do not use the eval built-in library function.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0224.Basic Calculator/Solution.cs b/leetcode/solution/0200-0299/0224.Basic Calculator/Solution.cs deleted file mode 100644 index 62b4cc68..00000000 --- a/leetcode/solution/0200-0299/0224.Basic Calculator/Solution.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int Calculate(string s) { - var numbers = new Stack(); - var symbols = new Stack(); - int number = -1; - for (var i = 0; i <= s.Length; ++i) - { - var ch = i < s.Length ? s[i] : ' '; - if (char.IsDigit(ch)) - { - if (number == -1) number = 0; - number = number * 10 + ch - '0'; - } - else - { - if (number != -1) - { - numbers.Push(number); - while (symbols.Count > 0 && symbols.Peek() != '(') - { - var symbol = symbols.Pop(); - if (symbol == '+') - { - numbers.Push(numbers.Pop() + numbers.Pop()); - } - else - { - numbers.Push(-(numbers.Pop() - numbers.Pop())); - } - } - number = -1; - } - if (char.IsWhiteSpace(ch)) continue; - - if (ch == ')') - { - symbols.Pop(); - while (symbols.Count > 0 && symbols.Peek() != '(') - { - var symbol = symbols.Pop(); - if (symbol == '+') - { - numbers.Push(numbers.Pop() + numbers.Pop()); - } - else - { - numbers.Push(-(numbers.Pop() - numbers.Pop())); - } - } - } - else - { - symbols.Push(ch); - } - } - } - - return numbers.Pop(); - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md b/leetcode/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md deleted file mode 100644 index 8aaf74ee..00000000 --- a/leetcode/solution/0200-0299/0225.Implement Stack using Queues/README_EN.md +++ /dev/null @@ -1,151 +0,0 @@ -# [225. Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues) - -[中文文档](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md) - -## Description - -

Implement the following operations of a stack using queues.

- -
    -
  • push(x) -- Push element x onto stack.
  • -
  • pop() -- Removes the element on top of the stack.
  • -
  • top() -- Get the top element.
  • -
  • empty() -- Return whether the stack is empty.
  • -
- -

Example:

- -
-
-MyStack stack = new MyStack();
-
-
-
-stack.push(1);
-
-stack.push(2);  
-
-stack.top();   // returns 2
-
-stack.pop();   // returns 2
-
-stack.empty(); // returns false
- -

Notes:

- -
    -
  • You must use only standard operations of a queue -- which means only push to back, peek/pop from front, size, and is empty operations are valid.
  • -
  • Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
  • -
  • You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).
  • -
- -## Solutions - - - -### **Python3** - -```python -class MyStack: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.q = [] - - - def push(self, x: int) -> None: - """ - Push element x onto stack. - """ - self.q.append(x) - n = len(self.q) - for i in range(1, n): - self.q.append(self.q.pop(0)) - - - def pop(self) -> int: - """ - Removes the element on top of the stack and returns that element. - """ - return self.q.pop(0) - - - def top(self) -> int: - """ - Get the top element. - """ - return self.q[0] - - - def empty(self) -> bool: - """ - Returns whether the stack is empty. - """ - return len(self.q) == 0 - - - -# 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() -``` - -### **Java** - -```java -class MyStack { - - private Deque q; - - /** Initialize your data structure here. */ - public MyStack() { - q = new ArrayDeque<>(); - } - - /** Push element x onto stack. */ - public void push(int x) { - q.offerLast(x); - int n = q.size(); - while (n-- > 1) { - q.offerLast(q.pollFirst()); - } - } - - /** Removes the element on top of the stack and returns that element. */ - public int pop() { - return q.pollFirst(); - } - - /** Get the top element. */ - public int top() { - return q.peekFirst(); - } - - /** Returns whether the stack is empty. */ - public boolean empty() { - return q.isEmpty(); - } -} - -/** - * Your MyStack object will be instantiated and called as such: - * MyStack obj = new MyStack(); - * obj.push(x); - * int param_2 = obj.pop(); - * int param_3 = obj.top(); - * boolean param_4 = obj.empty(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0225.Implement Stack using Queues/Solution.py b/leetcode/solution/0200-0299/0225.Implement Stack using Queues/Solution.py deleted file mode 100644 index 26cfe8d9..00000000 --- a/leetcode/solution/0200-0299/0225.Implement Stack using Queues/Solution.py +++ /dev/null @@ -1,47 +0,0 @@ -class MyStack: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.q = [] - - - def push(self, x: int) -> None: - """ - Push element x onto stack. - """ - self.q.append(x) - n = len(self.q) - for i in range(1, n): - self.q.append(self.q.pop(0)) - - - def pop(self) -> int: - """ - Removes the element on top of the stack and returns that element. - """ - return self.q.pop(0) - - - def top(self) -> int: - """ - Get the top element. - """ - return self.q[0] - - - def empty(self) -> bool: - """ - Returns whether the stack is empty. - """ - return len(self.q) == 0 - - - -# 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/leetcode/solution/0200-0299/0226.Invert Binary Tree/README_EN.md b/leetcode/solution/0200-0299/0226.Invert Binary Tree/README_EN.md deleted file mode 100644 index 44c87ba7..00000000 --- a/leetcode/solution/0200-0299/0226.Invert Binary Tree/README_EN.md +++ /dev/null @@ -1,145 +0,0 @@ -# [226. Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree) - -[中文文档](/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md) - -## Description - -

Invert a binary tree.

- -

Example:

- -

Input:

- -
-
-     4
-
-   /   \
-
-  2     7
-
- / \   / \
-
-1   3 6   9
- -

Output:

- -
-
-     4
-
-   /   \
-
-  7     2
-
- / \   / \
-
-9   6 3   1
- -

Trivia:
- -This problem was inspired by this original tweet by Max Howell:

- -
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so f*** off.
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def invertTree(self, root: TreeNode) -> TreeNode: - if root is None: - return None - root.left, root.right = root.right, root.left - self.invertTree(root.left) - self.invertTree(root.right) - return root -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public TreeNode invertTree(TreeNode root) { - if (root == null) return null; - TreeNode t = root.left; - root.left = root.right; - root.right = t; - invertTree(root.left); - invertTree(root.right); - return root; - } -} -``` - -### **JavaScript** - -```js -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {TreeNode} - */ -var invertTree = function (root) { - if (!root) return null; - [root.left, root.right] = [root.right, root.left]; - invertTree(root.left); - invertTree(root.right); - return root; -}; -``` - -### **Go** - -```go -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ -func invertTree(root *TreeNode) *TreeNode { - if (root == nil) { - return nil - } - root.Left, root.Right = root.Right, root.Left - invertTree(root.Left) - invertTree(root.Right) - return root -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.go b/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.go deleted file mode 100644 index 226ae6e4..00000000 --- a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.go +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - func invertTree(root *TreeNode) *TreeNode { - if (root == nil) { - return nil - } - root.Left, root.Right = root.Right, root.Left - invertTree(root.Left) - invertTree(root.Right) - return root -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.js b/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.js deleted file mode 100644 index bc5637bb..00000000 --- a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @return {TreeNode} - */ -var invertTree = function (root) { - if (!root) return null; - [root.left, root.right] = [root.right, root.left]; - invertTree(root.left); - invertTree(root.right); - return root; -}; diff --git a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.py b/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.py deleted file mode 100644 index dee27d84..00000000 --- a/leetcode/solution/0200-0299/0226.Invert Binary Tree/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def invertTree(self, root: TreeNode) -> TreeNode: - if root is None: - return None - root.left, root.right = root.right, root.left - self.invertTree(root.left) - self.invertTree(root.right) - return root diff --git a/leetcode/solution/0200-0299/0227.Basic Calculator II/README_EN.md b/leetcode/solution/0200-0299/0227.Basic Calculator II/README_EN.md deleted file mode 100644 index 5148af72..00000000 --- a/leetcode/solution/0200-0299/0227.Basic Calculator II/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [227. Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii) - -[中文文档](/solution/0200-0299/0227.Basic%20Calculator%20II/README.md) - -## Description - -

Implement a basic calculator to evaluate a simple expression string.

- -

The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.

- -

Example 1:

- -
-
-Input: "3+2*2"
-
-Output: 7
-
-
- -

Example 2:

- -
-
-Input: " 3/2 "
-
-Output: 1
- -

Example 3:

- -
-
-Input: " 3+5 / 2 "
-
-Output: 5
-
-
- -

Note:

- -
    -
  • You may assume that the given expression is always valid.
  • -
  • Do not use the eval built-in library function.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0227.Basic Calculator II/Solution.cs b/leetcode/solution/0200-0299/0227.Basic Calculator II/Solution.cs deleted file mode 100644 index 52259f17..00000000 --- a/leetcode/solution/0200-0299/0227.Basic Calculator II/Solution.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -struct Element -{ - public char Op; - public int Number; - public Element(char op, int number) - { - Op = op; - Number = number; - } -} - -public class Solution { - public int Calculate(string s) { - var stack = new Stack(); - var readingNumber = false; - var number = 0; - var op = '+'; - foreach (var ch in ((IEnumerable)s).Concat(Enumerable.Repeat('+', 1))) - { - if (ch >= '0' && ch <= '9') - { - if (!readingNumber) - { - readingNumber = true; - number = 0; - } - number = (number * 10) + (ch - '0'); - } - else if (ch != ' ') - { - readingNumber = false; - if (op == '+' || op == '-') - { - if (stack.Count == 2) - { - var prev = stack.Pop(); - var first = stack.Pop(); - if (prev.Op == '+') - { - stack.Push(new Element(first.Op, first.Number + prev.Number)); - } - else // '-' - { - stack.Push(new Element(first.Op, first.Number - prev.Number)); - } - } - stack.Push(new Element(op, number)); - } - else - { - var prev = stack.Pop(); - if (op == '*') - { - stack.Push(new Element(prev.Op, prev.Number * number)); - } - else // '/' - { - stack.Push(new Element(prev.Op, prev.Number / number)); - } - } - op = ch; - } - } - - if (stack.Count == 2) - { - var second = stack.Pop(); - var first = stack.Pop(); - if (second.Op == '+') - { - stack.Push(new Element(first.Op, first.Number + second.Number)); - } - else // '-' - { - stack.Push(new Element(first.Op, first.Number - second.Number)); - } - } - - return stack.Peek().Number; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0228.Summary Ranges/README_EN.md b/leetcode/solution/0200-0299/0228.Summary Ranges/README_EN.md deleted file mode 100644 index 061c8e04..00000000 --- a/leetcode/solution/0200-0299/0228.Summary Ranges/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [228. Summary Ranges](https://leetcode.com/problems/summary-ranges) - -[中文文档](/solution/0200-0299/0228.Summary%20Ranges/README.md) - -## Description - -

Given a sorted integer array without duplicates, return the summary of its ranges.

- -

Example 1:

- -
-
-Input:  [0,1,2,4,5,7]
-
-Output: ["0->2","4->5","7"]
-
-Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range.
-
-
- -

Example 2:

- -
-
-Input:  [0,2,3,4,6,8,9]
-
-Output: ["0","2->4","6","8->9"]
-
-Explanation: 2,3,4 form a continuous range; 8,9 form a continuous range.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cpp b/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cpp deleted file mode 100644 index e199f53e..00000000 --- a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -class Solution { -public: - vector summaryRanges(vector& nums) { - int len = nums.size(); - if(len == 0)return {}; - vector ans; - int count = 0; - int idx = 0; - while((idx + count) < len-1){ - if(nums[idx+count] == nums[idx+count+1]-1)count++; - else{ - string str; - if(count == 0){ - str = to_string(nums[idx]); - } - else{ - str = to_string(nums[idx])+"->"+to_string(nums[idx+count]); - } - ans.push_back(str); - idx += (count+1); - count = 0; - } - } - - //末尾处理 - string str; - if(count > 0) - str = to_string(nums[idx])+"->"+to_string(nums[idx+count]); - else - str = to_string(nums[idx]); - - ans.push_back(str); - - return ans; - - } -}; \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cs b/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cs deleted file mode 100644 index 3e0230ac..00000000 --- a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public IList SummaryRanges(int[] nums) { - var result = new List(); - int? start = null; - for (var i = 0; i < nums.Length; ++i) - { - if (start == null) start = nums[i]; - if (i == nums.Length - 1 || nums[i] + 1 < nums[i + 1]) - { - result.Add(start == nums[i] ? start.ToString() : string.Format("{0}->{1}", start, nums[i])); - start = null; - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.py b/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.py deleted file mode 100644 index 0d88188a..00000000 --- a/leetcode/solution/0200-0299/0228.Summary Ranges/Solution.py +++ /dev/null @@ -1,32 +0,0 @@ -class Solution(object): - def summaryRanges(self, nums): - """ - :type nums: List[int] - :rtype: List[str] - """ - length = len(nums) - if length == 0: - return [] - ans = [] - count = 0 - idx = 0 - while idx + count < length - 1: - if nums[idx + count] == nums[idx + count + 1] - 1: - count += 1 - else: - string = '' - if count == 0: - string = str(nums[idx]) - else: - string = str(nums[idx]) + "->" + str(nums[idx + count]) - ans.append(string) - idx += count + 1 - count = 0 - # 末尾处理 - string = '' - if count > 0: - string = str(nums[idx]) + "->" + str(nums[idx + count]) - else: - string = str(nums[idx]) - ans.append(string) - return ans diff --git a/leetcode/solution/0200-0299/0229.Majority Element II/README_EN.md b/leetcode/solution/0200-0299/0229.Majority Element II/README_EN.md deleted file mode 100644 index 1add1ffb..00000000 --- a/leetcode/solution/0200-0299/0229.Majority Element II/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [229. Majority Element II](https://leetcode.com/problems/majority-element-ii) - -[中文文档](/solution/0200-0299/0229.Majority%20Element%20II/README.md) - -## Description - -

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

- -

Note: The algorithm should run in linear time and in O(1) space.

- -

Example 1:

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

Example 2:

- -
-
-Input: [1,1,1,3,3,2,2,2]
-
-Output: [1,2]
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0229.Majority Element II/Solution.cs b/leetcode/solution/0200-0299/0229.Majority Element II/Solution.cs deleted file mode 100644 index 9b75786b..00000000 --- a/leetcode/solution/0200-0299/0229.Majority Element II/Solution.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - public IList MajorityElement(int[] nums) { - if (nums.Length == 0) return new int[0]; - var targetIndices = new [] { nums.Length / 3, nums.Length - nums.Length / 3 - 1 }.Distinct().ToList(); - var candidates = Sort(nums, 0, nums.Length - 1, targetIndices).Distinct(); - return candidates.Where(c => nums.Count(n => n == c) > nums.Length / 3).ToList(); - } - - private IList Sort(int[] nums, int left, int right, IList targetIndices) - { - if (left == right) return new [] { nums[left] }; - var mid = nums[(left + right) / 2]; - var i = left; - var j = right; - while (i <= j) - { - while (nums[i] < mid) ++i; - while (nums[j] > mid) --j; - if (i <= j) - { - var temp = nums[i]; - nums[i] = nums[j]; - nums[j] = temp; - ++i; - --j; - } - } - var result = new List(); - var leftTargetIndices = new List(); - var rightTargetIndecies = new List(); - foreach (var targetIndex in targetIndices) - { - if (targetIndex <= j) leftTargetIndices.Add(targetIndex); - else if (targetIndex >= i) rightTargetIndecies.Add(targetIndex); - else result.Add(mid); - } - if (leftTargetIndices.Count > 0) result.AddRange(Sort(nums, left, j, leftTargetIndices)); - if (rightTargetIndecies.Count > 0) result.AddRange(Sort(nums, i, right, rightTargetIndecies)); - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md b/leetcode/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md deleted file mode 100644 index 79ce410c..00000000 --- a/leetcode/solution/0200-0299/0230.Kth Smallest Element in a BST/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [230. Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst) - -[中文文档](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README.md) - -## Description - -

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

- -

Note:
- -You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

- -

Example 1:

- -
-
-Input: root = [3,1,4,null,2], k = 1
-
-   3
-
-  / \
-
- 1   4
-
-  \
-
-   2
-
-Output: 1
- -

Example 2:

- -
-
-Input: root = [5,3,6,2,4,null,null,1], k = 3
-
-       5
-
-      / \
-
-     3   6
-
-    / \
-
-   2   4
-
-  /
-
- 1
-
-Output: 3
-
-
- -

Follow up:
- -What if the BST is modified (insert/delete operations) often and you need to find the kth smallest frequently? How would you optimize the kthSmallest routine?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0231.Power of Two/README_EN.md b/leetcode/solution/0200-0299/0231.Power of Two/README_EN.md deleted file mode 100644 index 6e19db41..00000000 --- a/leetcode/solution/0200-0299/0231.Power of Two/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [231. Power of Two](https://leetcode.com/problems/power-of-two) - -[中文文档](/solution/0200-0299/0231.Power%20of%20Two/README.md) - -## Description - -

Given an integer, write a function to determine if it is a power of two.

- -

Example 1:

- -
-
-Input: 1
-
-Output: true 
-
-Explanation: 20 = 1
-
-
- -

Example 2:

- -
-
-Input: 16
-
-Output: true
-
-Explanation: 24 = 16
- -

Example 3:

- -
-
-Input: 218
-
-Output: false
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0231.Power of Two/Solution.py b/leetcode/solution/0200-0299/0231.Power of Two/Solution.py deleted file mode 100644 index 0673bf88..00000000 --- a/leetcode/solution/0200-0299/0231.Power of Two/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def isPowerOfTwo(self, n): - """ - :type n: int - :rtype: bool - """ - if n<=0: - return False - m=2**32 - if m%n: - return False - else: - return True \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md b/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md deleted file mode 100644 index 4073726a..00000000 --- a/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md +++ /dev/null @@ -1,167 +0,0 @@ -# [232. Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks) - -[中文文档](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md) - -## Description - -

Implement the following operations of a queue using stacks.

- -
    -
  • push(x) -- Push element x to the back of queue.
  • -
  • pop() -- Removes the element from in front of queue.
  • -
  • peek() -- Get the front element.
  • -
  • empty() -- Return whether the queue is empty.
  • -
- -

Example:

- -
-
-MyQueue queue = new MyQueue();
-
-
-
-queue.push(1);
-
-queue.push(2);  
-
-queue.peek();  // returns 1
-
-queue.pop();   // returns 1
-
-queue.empty(); // returns false
- -

Notes:

- -
    -
  • You must use only standard operations of a stack -- which means only push to top, peek/pop from top, size, and is empty operations are valid.
  • -
  • Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.
  • -
  • You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).
  • -
- -## Solutions - - - -### **Python3** - -```python -class MyQueue: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.s1 = [] - self.s2 = [] - - - def push(self, x: int) -> None: - """ - Push element x to the back of queue. - """ - self.s1.append(x) - - - def pop(self) -> int: - """ - Removes the element from in front of queue and returns that element. - """ - self._move() - return self.s2.pop() - - def peek(self) -> int: - """ - Get the front element. - """ - self._move() - return self.s2[-1] - - - def empty(self) -> bool: - """ - Returns whether the queue is empty. - """ - return len(self.s1) + len(self.s2) == 0 - - - def _move(self): - """ - Move elements from s1 to s2. - """ - if len(self.s2) == 0: - while len(self.s1) > 0: - self.s2.append(self.s1.pop()) - - -# Your MyQueue object will be instantiated and called as such: -# obj = MyQueue() -# obj.push(x) -# param_2 = obj.pop() -# param_3 = obj.peek() -# param_4 = obj.empty() -``` - -### **Java** - -```java -class MyQueue { - - private Deque s1; - private Deque s2; - - /** Initialize your data structure here. */ - public MyQueue() { - s1 = new ArrayDeque<>(); - s2 = new ArrayDeque<>(); - } - - /** Push element x to the back of queue. */ - public void push(int x) { - s1.push(x); - } - - /** Removes the element from in front of queue and returns that element. */ - public int pop() { - move(); - return s2.pop(); - } - - /** Get the front element. */ - public int peek() { - move(); - return s2.peek(); - } - - /** Returns whether the queue is empty. */ - public boolean empty() { - return s1.isEmpty() && s2.isEmpty(); - } - - /** Move elements from s1 to s2. */ - private void move() { - if (s2.isEmpty()) { - while (!s1.isEmpty()) { - s2.push(s1.pop()); - } - } - } -} - -/** - * Your MyQueue object will be instantiated and called as such: - * MyQueue obj = new MyQueue(); - * obj.push(x); - * int param_2 = obj.pop(); - * int param_3 = obj.peek(); - * boolean param_4 = obj.empty(); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/Solution.py b/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/Solution.py deleted file mode 100644 index 6029f85e..00000000 --- a/leetcode/solution/0200-0299/0232.Implement Queue using Stacks/Solution.py +++ /dev/null @@ -1,54 +0,0 @@ -class MyQueue: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.s1 = [] - self.s2 = [] - - - def push(self, x: int) -> None: - """ - Push element x to the back of queue. - """ - self.s1.append(x) - - - def pop(self) -> int: - """ - Removes the element from in front of queue and returns that element. - """ - self._move() - return self.s2.pop() - - def peek(self) -> int: - """ - Get the front element. - """ - self._move() - return self.s2[-1] - - - def empty(self) -> bool: - """ - Returns whether the queue is empty. - """ - return len(self.s1) + len(self.s2) == 0 - - - def _move(self): - """ - Move elements from s1 to s2. - """ - if len(self.s2) == 0: - while len(self.s1) > 0: - self.s2.append(self.s1.pop()) - - -# Your MyQueue object will be instantiated and called as such: -# obj = MyQueue() -# obj.push(x) -# param_2 = obj.pop() -# param_3 = obj.peek() -# param_4 = obj.empty() \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0233.Number of Digit One/README_EN.md b/leetcode/solution/0200-0299/0233.Number of Digit One/README_EN.md deleted file mode 100644 index c84831a5..00000000 --- a/leetcode/solution/0200-0299/0233.Number of Digit One/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -# [233. Number of Digit One](https://leetcode.com/problems/number-of-digit-one) - -[中文文档](/solution/0200-0299/0233.Number%20of%20Digit%20One/README.md) - -## Description - -

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

- -

Example:

- -
-
-Input: 13
-
-Output: 6 
-
-Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0233.Number of Digit One/Solution.cs b/leetcode/solution/0200-0299/0233.Number of Digit One/Solution.cs deleted file mode 100644 index 92638269..00000000 --- a/leetcode/solution/0200-0299/0233.Number of Digit One/Solution.cs +++ /dev/null @@ -1,17 +0,0 @@ -public class Solution { - public int CountDigitOne(int n) { - if (n <= 0) return 0; - if (n < 10) return 1; - return CountDigitOne(n / 10 - 1) * 10 + n / 10 + CountDigitOneOfN(n / 10) * (n % 10 + 1) + (n % 10 >= 1 ? 1 : 0); - } - - private int CountDigitOneOfN(int n) { - var count = 0; - while (n > 0) - { - if (n % 10 == 1) ++count; - n /= 10; - } - return count; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0234.Palindrome Linked List/README_EN.md b/leetcode/solution/0200-0299/0234.Palindrome Linked List/README_EN.md deleted file mode 100644 index 7b787599..00000000 --- a/leetcode/solution/0200-0299/0234.Palindrome Linked List/README_EN.md +++ /dev/null @@ -1,109 +0,0 @@ -# [234. Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list) - -[中文文档](/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md) - -## Description - -

Given a singly linked list, determine if it is a palindrome.

- -

Example 1:

- -
-
-Input: 1->2
-
-Output: false
- -

Example 2:

- -
-
-Input: 1->2->2->1
-
-Output: true
- -

Follow up:
- -Could you do it in O(n) time and O(1) space?

- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None -class Solution: - def isPalindrome(self, head: ListNode) -> bool: - if head is None or head.next is None: - return True - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - pre, cur = None, slow.next - while cur: - t = cur.next - cur.next = pre - pre, cur = cur, t - while pre: - if pre.val != head.val: - return False - pre, head = pre.next, head.next - return True -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public boolean isPalindrome(ListNode head) { - if (head == null || head.next == null) { - return true; - } - ListNode slow = head; - ListNode fast = head.next; - while (fast != null && fast.next != null) { - slow = slow.next; - fast = fast.next.next; - } - ListNode cur = slow.next; - slow.next = null; - ListNode pre = null; - while (cur != null) { - ListNode t = cur.next; - cur.next = pre; - pre = cur; - cur = t; - } - while (pre != null) { - if (pre.val != head.val) { - return false; - } - pre = pre.next; - head = head.next; - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.cs b/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.cs deleted file mode 100644 index fc06343d..00000000 --- a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.cs +++ /dev/null @@ -1,48 +0,0 @@ -public class Solution { - public bool IsPalindrome(ListNode head) { - if (head == null) return true; - var count = Count(head); - var temp = head; - var c = 1; - while (c < count / 2) - { - ++c; - temp = temp.next; - } - var head2 = Reverse(temp.next); - temp.next = null; - - while (head != null && head2 != null) - { - if (head.val != head2.val) return false; - head = head.next; - head2 = head2.next; - } - return true; - } - - private int Count(ListNode head) - { - var count = 0; - while (head != null) - { - ++count; - head = head.next; - } - return count; - } - - private ListNode Reverse(ListNode head) - { - var temp = head; - head = null; - while (temp != null) - { - var temp2 = temp.next; - temp.next = head; - head = temp; - temp = temp2; - } - return head; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.js b/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.js deleted file mode 100644 index 65dd9b72..00000000 --- a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.js +++ /dev/null @@ -1,58 +0,0 @@ -var isPalindrome2 = function (head) { - if (!head || !head.next) { - return true; - } - let slow = head; - let fast = head; - while (fast !== null && fast.next !== null) { - slow = slow.next; - fast = fast.next.next; - } - if (fast !== null) { - slow = slow.next; - } - - let p = new ListNode(0); - while (slow !== null) { - let t = slow.next; - slow.next = p.next; - p.next = slow; - slow = t; - } - - let left = head; - let right = p.next; - while (right !== null) { - if (left.val !== right.val) { - return false; - } - left = left.next; - right = right.next; - } - return true; -}; - -var isPalindrom3 = function (head) { - let arr = []; - let next = head; - while (next) { - arr.push(next.val); - next = next.next; - } - let len = Math.trunc(arr.length / 2); - for (let i = 0; i < len; i++) { - if (arr[i] !== arr[arr.length - 1 - i]) { - return false; - } - } - return true; -}; - -var isPalindrome = function (head) { - let arr = []; - while (head) { - arr.push(head.val); - head = head.next; - } - return arr.join("") === arr.reverse().join(""); -}; diff --git a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.py b/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.py deleted file mode 100644 index aa44a45f..00000000 --- a/leetcode/solution/0200-0299/0234.Palindrome Linked List/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None -class Solution: - def isPalindrome(self, head: ListNode) -> bool: - if head is None or head.next is None: - return True - slow, fast = head, head.next - while fast and fast.next: - slow, fast = slow.next, fast.next.next - pre, cur = None, slow.next - while cur: - t = cur.next - cur.next = pre - pre, cur = cur, t - while pre: - if pre.val != head.val: - return False - pre, head = pre.next, head.next - return True diff --git a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md b/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md deleted file mode 100644 index b7512430..00000000 --- a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/README_EN.md +++ /dev/null @@ -1,206 +0,0 @@ -# [235. Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) - -[中文文档](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md) - -## Description - -

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

- -

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

- -

Given binary search tree:  root = [6,2,8,0,4,7,9,null,null,3,5]

- -![](./images/binarysearchtree_improved.png) - -

Example 1:

- -
-
-Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
-
-Output: 6
-
-Explanation: The LCA of nodes 2 and 8 is 6.
-
-
- -

Example 2:

- -
-
-Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
-
-Output: 2
-
-Explanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.
-
-
- -

 

- -

Note:

- -
    -
  • All of the nodes' values will be unique.
  • -
  • p and q are different and both values will exist in the BST.
  • -
- -## Solutions - - - -### **Python3** - -Iterative: - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': - while root: - if root.val < p.val and root.val < q.val: - root = root.right - elif root.val > p.val and root.val > q.val: - root = root.left - else: - return root -``` - -Recursive: - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': - if root is None: - return None - if root.val < p.val and root.val < q.val: - return self.lowestCommonAncestor(root.right, p, q) - if root.val > p.val and root.val > q.val: - return self.lowestCommonAncestor(root.left, p, q) - return root -``` - -### **Java** - -Iterative: - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ - -class Solution { - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - while (root != null) { - if (root.val < p.val && root.val < q.val) root = root.right; - else if (root.val > p.val && root.val > q.val) root = root.left; - else return root; - } - return root; - } -} -``` - -Recursive: - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ - -class Solution { - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - if (root == null) return null; - if (root.val < p.val && root.val < q.val) return lowestCommonAncestor(root.right, p, q); - if (root.val > p.val && root.val > q.val) return lowestCommonAncestor(root.left, p, q); - return root; - } -} -``` - -### **Go** - -Iterative: - -```go -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - -func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { - for root != nil { - if root.Val > p.Val && root.Val > q.Val { - root = root.Left - } else if root.Val < p.Val && root.Val < q.Val { - root = root.Right - } else { - return root - } - } - return nil -} -``` - -Recursive: - -```go -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - -func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { - if root == nil { - return root - } - if root.Val < p.Val && root.Val < q.Val { - return lowestCommonAncestor(root.Right, p, q) - } - if root.Val > p.Val && root.Val > q.Val { - return lowestCommonAncestor(root.Left, p, q) - } - return root -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.go b/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.go deleted file mode 100644 index 17f787b9..00000000 --- a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.go +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - -func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { - for root != nil { - // 如果 p、q 的值都小于 root,说明 p、q 肯定在 root 的左子树中; - // 如果 p、q 都大于 root,说明肯定在 root 的右子树中; - // 如果一个在左一个在右,则说明此时的 root 记为对应的最近公共祖先。 - if root.Val > p.Val && root.Val > q.Val { - root = root.Left - } else if root.Val < p.Val && root.Val < q.Val { - root = root.Right - } else { - return root - } - } - return nil -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.py b/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.py deleted file mode 100644 index ed74aa9a..00000000 --- a/leetcode/solution/0200-0299/0235.Lowest Common Ancestor of a Binary Search Tree/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': - while root: - if root.val < p.val and root.val < q.val: - root = root.right - elif root.val > p.val and root.val > q.val: - root = root.left - else: - return root diff --git a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md b/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md deleted file mode 100644 index ccf459ef..00000000 --- a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/README_EN.md +++ /dev/null @@ -1,131 +0,0 @@ -# [236. Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) - -[中文文档](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md) - -## Description - -

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

- -

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

- -

Given the following binary tree:  root = [3,5,1,6,2,0,8,null,null,7,4]

- -![](./images/binarytree.png) - -

Example 1:

- -
-
-Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
-
-Output: 3
-
-Explanation: The LCA of nodes 5 and 1 is 3.
-
-
- -

Example 2:

- -
-
-Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
-
-Output: 5
-
-Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
-
-
- -

 

- -

Note:

- -
    -
  • All of the nodes' values will be unique.
  • -
  • p and q are different and both values will exist in the binary tree.
  • -
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': - if root is None or root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - if left is None: - return right - if right is None: - return left - return root -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { - if (root == null || root == p || root == q) return root; - TreeNode left = lowestCommonAncestor(root.left, p, q); - TreeNode right = lowestCommonAncestor(root.right, p, q); - if (left == null) return right; - if (right == null) return left; - return root; - } -} -``` - -### **JavaScript** - -```js -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {TreeNode} p - * @param {TreeNode} q - * @return {TreeNode} - */ -var lowestCommonAncestor = function (root, p, q) { - if (!root || root == p || root == q) return root; - const left = lowestCommonAncestor(root.left, p, q); - const right = lowestCommonAncestor(root.right, p, q); - if (!left) return right; - if (!right) return left; - return root; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.js b/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.js deleted file mode 100644 index 9eb1249f..00000000 --- a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Definition for a binary tree node. - * function TreeNode(val) { - * this.val = val; - * this.left = this.right = null; - * } - */ -/** - * @param {TreeNode} root - * @param {TreeNode} p - * @param {TreeNode} q - * @return {TreeNode} - */ -var lowestCommonAncestor = function (root, p, q) { - if (!root || root == p || root == q) return root; - const left = lowestCommonAncestor(root.left, p, q); - const right = lowestCommonAncestor(root.right, p, q); - if (!left) return right; - if (!right) return left; - return root; -}; diff --git a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.py b/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.py deleted file mode 100644 index e3817df9..00000000 --- a/leetcode/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': - if root is None or root == p or root == q: - return root - left = self.lowestCommonAncestor(root.left, p, q) - right = self.lowestCommonAncestor(root.right, p, q) - if left is None: - return right - if right is None: - return left - return root diff --git a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md b/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md deleted file mode 100644 index c7d769c8..00000000 --- a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md +++ /dev/null @@ -1,112 +0,0 @@ -# [237. Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) - -[中文文档](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md) - -## Description - -

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

- -

Given linked list -- head = [4,5,1,9], which looks like following:

- -![](./images/237_example.png) - -

 

- -

Example 1:

- -
-
-Input: head = [4,5,1,9], node = 5
-
-Output: [4,1,9]
-
-Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
-
-
- -

Example 2:

- -
-
-Input: head = [4,5,1,9], node = 1
-
-Output: [4,5,9]
-
-Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
-
-
- -

 

- -

Note:

- -
    -
  • The linked list will have at least two elements.
  • -
  • All of the nodes' values will be unique.
  • -
  • The given node will not be the tail and it will always be a valid node of the linked list.
  • -
  • Do not return anything from your function.
  • -
- -## Solutions - - - -### **Python3** - -```python -# 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. - """ - node.val = node.next.val - node.next = node.next.next -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode(int x) { val = x; } - * } - */ -class Solution { - public void deleteNode(ListNode node) { - node.val = node.next.val; - node.next = node.next.next; - } -} -``` - -### **JavaScript** - -```javascript -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} node - * @return {void} Do not return anything, modify node in-place instead. - */ -var deleteNode = function (node) { - node.val = node.next.val; - node.next = node.next.next; -}; -``` - - diff --git a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.js b/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.js deleted file mode 100644 index 0c0dfa5d..00000000 --- a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Definition for singly-linked list. - * function ListNode(val) { - * this.val = val; - * this.next = null; - * } - */ -/** - * @param {ListNode} node - * @return {void} Do not return anything, modify node in-place instead. - */ -var deleteNode = function (node) { - node.val = node.next.val; - node.next = node.next.next; -}; diff --git a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.py b/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.py deleted file mode 100644 index 201e675b..00000000 --- a/leetcode/solution/0200-0299/0237.Delete Node in a Linked List/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - """ - node.val = node.next.val - node.next = node.next.next \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0238.Product of Array Except Self/README_EN.md b/leetcode/solution/0200-0299/0238.Product of Array Except Self/README_EN.md deleted file mode 100644 index 03c43637..00000000 --- a/leetcode/solution/0200-0299/0238.Product of Array Except Self/README_EN.md +++ /dev/null @@ -1,92 +0,0 @@ -# [238. Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self) - -[中文文档](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md) - -## Description - -

Given an array nums of n integers where n > 1,  return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

- -

Example:

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

Constraint: It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32 bit integer.

- -

Note: Please solve it without division and in O(n).

- -

Follow up:
-Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.)

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def productExceptSelf(self, nums: List[int]) -> List[int]: - n = len(nums) - output = [1 for _ in nums] - left = right = 1 - for i in range(n): - output[i] = left - left *= nums[i] - for i in range(n - 1, -1, -1): - output[i] *= right - right *= nums[i] - return output -``` - -### **Java** - -```java -class Solution { - public int[] productExceptSelf(int[] nums) { - int n = nums.length; - int[] output = new int[n]; - for (int i = 0, left = 1; i < n; ++i) { - output[i] = left; - left *= nums[i]; - } - for (int i = n - 1, right = 1; i >= 0; --i) { - output[i] *= right; - right *= nums[i]; - } - return output; - } -} -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @return {number[]} - */ -var productExceptSelf = function (nums) { - const n = nums.length; - let output = new Array(n); - for (let i = 0, left = 1; i < n; ++i) { - output[i] = left; - left *= nums[i]; - } - for (let i = n - 1, right = 1; i >= 0; --i) { - output[i] *= right; - right *= nums[i]; - } - return output; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.cpp b/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.cpp deleted file mode 100644 index a772b2c0..00000000 --- a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution -{ -public: - vector productExceptSelf(vector &nums) - { - vector dpLeft(nums.size(), 1); - vector dpRight(nums.size(), 1); - for (int i = 1; i < nums.size(); i++) - { - dpLeft[i] = dpLeft[i - 1] * nums[i - 1]; - } - for (int i = nums.size() - 2; i >= 0; i--) - { - dpRight[i] = dpRight[i + 1] * nums[i + 1]; - } - vector result; - for (int i = 0; i < nums.size(); i++) - { - result.push_back(dpLeft[i] * dpRight[i]); - } - return result; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.js b/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.js deleted file mode 100644 index 9904bcb8..00000000 --- a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @param {number[]} nums - * @return {number[]} - */ -var productExceptSelf = function (nums) { - const n = nums.length; - let output = new Array(n); - for (let i = 0, left = 1; i < n; ++i) { - output[i] = left; - left *= nums[i]; - } - for (let i = n - 1, right = 1; i >= 0; --i) { - output[i] *= right; - right *= nums[i]; - } - return output; -}; diff --git a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.py b/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.py deleted file mode 100644 index 133cc931..00000000 --- a/leetcode/solution/0200-0299/0238.Product of Array Except Self/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def productExceptSelf(self, nums: List[int]) -> List[int]: - n = len(nums) - output = [1 for _ in nums] - left = right = 1 - for i in range(n): - output[i] = left - left *= nums[i] - for i in range(n - 1, -1, -1): - output[i] *= right - right *= nums[i] - return output diff --git a/leetcode/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md b/leetcode/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md deleted file mode 100644 index a24ca127..00000000 --- a/leetcode/solution/0200-0299/0239.Sliding Window Maximum/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [239. Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum) - -[中文文档](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README.md) - -## Description - -

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.

- -

Example:

- -
-
-Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3
-
-Output: [3,3,5,5,6,7] 
-
-Explanation: 
-
-
-
-Window position                Max
-
----------------               -----
-
-[1  3  -1] -3  5  3  6  7       3
-
- 1 [3  -1  -3] 5  3  6  7       3
-
- 1  3 [-1  -3  5] 3  6  7       5
-
- 1  3  -1 [-3  5  3] 6  7       5
-
- 1  3  -1  -3 [5  3  6] 7       6
-
- 1  3  -1  -3  5 [3  6  7]      7
-
-
- -

Note:
- -You may assume k is always valid, 1 ≤ k ≤ input array's size for non-empty array.

- -

Follow up:
- -Could you solve it in linear time?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0239.Sliding Window Maximum/Solution.cs b/leetcode/solution/0200-0299/0239.Sliding Window Maximum/Solution.cs deleted file mode 100644 index 15052452..00000000 --- a/leetcode/solution/0200-0299/0239.Sliding Window Maximum/Solution.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public int[] MaxSlidingWindow(int[] nums, int k) { - if (nums.Length == 0) return new int[0]; - var result = new int[nums.Length - k + 1]; - var descOrderNums = new LinkedList(); - for (var i = 0; i < nums.Length; ++i) - { - if (i >= k && nums[i - k] == descOrderNums.First.Value) - { - descOrderNums.RemoveFirst(); - } - while (descOrderNums.Count > 0 && nums[i] > descOrderNums.Last.Value) - { - descOrderNums.RemoveLast(); - } - descOrderNums.AddLast(nums[i]); - if (i >= k - 1) - { - result[i - k + 1] = descOrderNums.First.Value; - } - } - return result; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md b/leetcode/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md deleted file mode 100644 index e118932f..00000000 --- a/leetcode/solution/0200-0299/0240.Search a 2D Matrix II/README_EN.md +++ /dev/null @@ -1,62 +0,0 @@ -# [240. Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii) - -[中文文档](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README.md) - -## Description - -

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

- -
    -
  • Integers in each row are sorted in ascending from left to right.
  • -
  • Integers in each column are sorted in ascending from top to bottom.
  • -
- -

Example:

- -

Consider the following matrix:

- -
-
-[
-
-  [1,   4,  7, 11, 15],
-
-  [2,   5,  8, 12, 19],
-
-  [3,   6,  9, 16, 22],
-
-  [10, 13, 14, 17, 24],
-
-  [18, 21, 23, 26, 30]
-
-]
-
-
- -

Given target = 5, return true.

- -

Given target = 20, return false.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md b/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md deleted file mode 100644 index 1e87718c..00000000 --- a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [241. Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses) - -[中文文档](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README.md) - -## Description - -

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.

- -

Example 1:

- -
-
-Input: "2-1-1"
-
-Output: [0, 2]
-
-Explanation: 
-
-((2-1)-1) = 0 
-
-(2-(1-1)) = 2
- -

Example 2:

- -
-
-Input: "2*3-4*5"
-
-Output: [-34, -14, -10, -10, 10]
-
-Explanation: 
-
-(2*(3-(4*5))) = -34 
-
-((2*3)-(4*5)) = -14 
-
-((2*(3-4))*5) = -10 
-
-(2*((3-4)*5)) = -10 
-
-(((2*3)-4)*5) = 10
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.cs b/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.cs deleted file mode 100644 index c09ba31b..00000000 --- a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections.Generic; - -public class Solution { - public IList DiffWaysToCompute(string input) { - var values = new List(); - var operators = new List(); - var sum = 0; - foreach (var ch in input) - { - if (ch == '+' || ch == '-' || ch == '*') - { - values.Add(sum); - operators.Add(ch); - sum = 0; - } - else - { - sum = sum * 10 + ch - '0'; - } - } - values.Add(sum); - - var f = new List[values.Count, values.Count]; - for (var i = 0; i < values.Count; ++i) - { - f[i, i] = new List { values[i] }; - } - - for (var diff = 1; diff < values.Count; ++diff) - { - for (var left = 0; left + diff < values.Count; ++left) - { - var right = left + diff; - f[left, right] = new List(); - for (var i = left; i < right; ++i) - { - foreach (var leftValue in f[left, i]) - { - foreach (var rightValue in f[i + 1, right]) - { - switch (operators[i]) - { - case '+': - f[left, right].Add(leftValue + rightValue); - break; - case '-': - f[left, right].Add(leftValue - rightValue); - break; - case '*': - f[left, right].Add(leftValue * rightValue); - break; - } - } - } - } - } - } - - return f[0, values.Count - 1]; - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.go b/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.go deleted file mode 100644 index ad9cb2ad..00000000 --- a/leetcode/solution/0200-0299/0241.Different Ways to Add Parentheses/Solution.go +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @lc app=leetcode.cn id=241 lang=golang - * Accepted - * 25/25 cases passed (4 ms) - * Your runtime beats 52.94 % of golang submissions - * Your memory usage beats 100 % of golang submissions (6.5 MB) - * time complex O(n^2) - */ - -import "strconv" - -func diffWaysToCompute(input string) []int { - ret := []int{} - for i, c := range input { - if c == '+' || c == '-' || c == '*' { - left_ret := diffWaysToCompute(input[0:i]) - right_ret := diffWaysToCompute(input[i+1:]) - for _, l_ret := range left_ret { - for _, r_ret := range right_ret { - if c == '+' { - ret = append(ret, l_ret+r_ret) - } else if c == '-' { - ret = append(ret, l_ret-r_ret) - } else { - ret = append(ret, l_ret*r_ret) - } - } - } - } - } - if len(ret) == 0 { - num, _ := strconv.Atoi(input) - ret = append(ret, num) - } - return ret -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0242.Valid Anagram/README_EN.md b/leetcode/solution/0200-0299/0242.Valid Anagram/README_EN.md deleted file mode 100644 index 6c823348..00000000 --- a/leetcode/solution/0200-0299/0242.Valid Anagram/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [242. Valid Anagram](https://leetcode.com/problems/valid-anagram) - -[中文文档](/solution/0200-0299/0242.Valid%20Anagram/README.md) - -## Description - -

Given two strings s and , write a function to determine if t is an anagram of s.

- -

Example 1:

- -
-
-Input: s = "anagram", t = "nagaram"
-
-Output: true
-
-
- -

Example 2:

- -
-
-Input: s = "rat", t = "car"
-
-Output: false
-
-
- -

Note:
- -You may assume the string contains only lowercase alphabets.

- -

Follow up:
- -What if the inputs contain unicode characters? How would you adapt your solution to such case?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0242.Valid Anagram/Solution.js b/leetcode/solution/0200-0299/0242.Valid Anagram/Solution.js deleted file mode 100644 index b9100d16..00000000 --- a/leetcode/solution/0200-0299/0242.Valid Anagram/Solution.js +++ /dev/null @@ -1,27 +0,0 @@ -const isAnagram = function (s, t) { - let a = {}, - b = {}; - for (let i = 0; i < s.length; i++) { - if (a.hasOwnProperty(s[i])) { - a[s[i]]++; - } else { - a[s[i]] = 1; - } - } - for (let i = 0; i < t.length; i++) { - if (b.hasOwnProperty(t[i])) { - b[t[i]]++; - } else { - b[t[i]] = 1; - } - } - let keyA = Object.keys(a); - let keyB = Object.keys(b); - if (keyA.length !== keyB.length) { - return false; - } - for (let i = 0; i < keyA.length; i++) { - if (a[keyA[i]] !== b[keyA[i]]) return false; - } - return true; -}; diff --git a/leetcode/solution/0200-0299/0243.Shortest Word Distance/README_EN.md b/leetcode/solution/0200-0299/0243.Shortest Word Distance/README_EN.md deleted file mode 100644 index 65e00e4c..00000000 --- a/leetcode/solution/0200-0299/0243.Shortest Word Distance/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [243. Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) - -[中文文档](/solution/0200-0299/0243.Shortest%20Word%20Distance/README.md) - -## Description - -

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.

- -

Example:
-Assume that words = ["practice", "makes", "perfect", "coding", "makes"].

- -
-Input: word1 = “coding”, word2 = “practice”
-Output: 3
-
- -
-Input: word1 = "makes", word2 = "coding"
-Output: 1
-
- -

Note:
-You may assume that word1 does not equal to word2, and word1 and word2 are both in the list.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md b/leetcode/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md deleted file mode 100644 index 8fe6735b..00000000 --- a/leetcode/solution/0200-0299/0244.Shortest Word Distance II/README_EN.md +++ /dev/null @@ -1,46 +0,0 @@ -# [244. Shortest Word Distance II](https://leetcode.com/problems/shortest-word-distance-ii) - -[中文文档](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README.md) - -## Description - -

Design a class which receives a list of words in the constructor, and implements a method that takes two words word1 and word2 and return the shortest distance between these two words in the list. Your method will be called repeatedly many times with different parameters. 

- -

Example:
-Assume that words = ["practice", "makes", "perfect", "coding", "makes"].

- -
-Input: word1 = “coding”, word2 = “practice”
-Output: 3
-
- -
-Input: word1 = "makes", word2 = "coding"
-Output: 1
- -

Note:
-You may assume that word1 does not equal to word2, and word1 and word2 are both in the list.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md b/leetcode/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md deleted file mode 100644 index 6f61b320..00000000 --- a/leetcode/solution/0200-0299/0245.Shortest Word Distance III/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [245. Shortest Word Distance III](https://leetcode.com/problems/shortest-word-distance-iii) - -[中文文档](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README.md) - -## Description - -

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.

- -

word1 and word2 may be the same and they represent two individual words in the list.

- -

Example:
-Assume that words = ["practice", "makes", "perfect", "coding", "makes"].

- -
-Input: word1 = “makes”, word2 = “coding”
-Output: 1
-
- -
-Input: word1 = "makes", word2 = "makes"
-Output: 3
-
- -

Note:
-You may assume word1 and word2 are both in the list.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md b/leetcode/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md deleted file mode 100644 index 5abe64c2..00000000 --- a/leetcode/solution/0200-0299/0246.Strobogrammatic Number/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [246. Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number) - -[中文文档](/solution/0200-0299/0246.Strobogrammatic%20Number/README.md) - -## Description - -

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

- -

Write a function to determine if a number is strobogrammatic. The number is represented as a string.

- -

 

-

Example 1:

-
Input: num = "69"
-Output: true
-

Example 2:

-
Input: num = "88"
-Output: true
-

Example 3:

-
Input: num = "962"
-Output: false
-

Example 4:

-
Input: num = "1"
-Output: true
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isStrobogrammatic(self, num: str) -> bool: - def match(a, b): - if a in {'0', '1', '8'}: - return a == b - if a == '6': - return b == '9' - if a == '9': - return b == '6' - return False - n = len(num) - i, j = 0, n - 1 - while i <= j: - if not match(num[i], num[j]): - return False - i += 1 - j -= 1 - return True -``` - -### **Java** - -```java -class Solution { - public boolean isStrobogrammatic(String num) { - int n = num.length(); - for (int i = 0, j = n - 1; i <= j; ++i, --j) { - if (!match(num.charAt(i), num.charAt(j))) return false; - } - return true; - } - - private boolean match(char a, char b) { - switch (a) { - case '0': - case '1': - case '8': - return a == b; - case '6': - return b == '9'; - case '9': - return b == '6'; - default: - return false; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0246.Strobogrammatic Number/Solution.py b/leetcode/solution/0200-0299/0246.Strobogrammatic Number/Solution.py deleted file mode 100644 index ffa16c76..00000000 --- a/leetcode/solution/0200-0299/0246.Strobogrammatic Number/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -class Solution: - def isStrobogrammatic(self, num: str) -> bool: - def match(a, b): - if a in {'0', '1', '8'}: - return a == b - if a == '6': - return b == '9' - if a == '9': - return b == '6' - return False - n = len(num) - i, j = 0, n - 1 - while i <= j: - if not match(num[i], num[j]): - return False - i += 1 - j -= 1 - return True diff --git a/leetcode/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md b/leetcode/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md deleted file mode 100644 index 1e427e4c..00000000 --- a/leetcode/solution/0200-0299/0247.Strobogrammatic Number II/README_EN.md +++ /dev/null @@ -1,39 +0,0 @@ -# [247. Strobogrammatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii) - -[中文文档](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README.md) - -## Description - -

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

- -

Find all strobogrammatic numbers that are of length = n.

- -

Example:

- -
Input:  n = 2
-Output: ["11","69","88","96"]
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0252.Meeting Rooms/README_EN.md b/leetcode/solution/0200-0299/0252.Meeting Rooms/README_EN.md deleted file mode 100644 index 54afca57..00000000 --- a/leetcode/solution/0200-0299/0252.Meeting Rooms/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [252. Meeting Rooms](https://leetcode.com/problems/meeting-rooms) - -[中文文档](/solution/0200-0299/0252.Meeting%20Rooms/README.md) - -## Description - -

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.

- -

Example 1:

- -
-Input: [[0,30],[5,10],[15,20]]
-Output: false
-
- -

Example 2:

- -
-Input: [[7,10],[2,4]]
-Output: true
-
- -

NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def canAttendMeetings(self, intervals: List[List[int]]) -> bool: - intervals.sort(key=lambda x: x[0]) - for i in range(len(intervals) - 1): - if intervals[i][1] > intervals[i + 1][0]: - return False - return True -``` - -### **Java** - -```java -class Solution { - public boolean canAttendMeetings(int[][] intervals) { - Arrays.sort(intervals, Comparator.comparingInt(a -> a[0])); - for (int i = 0, n = intervals.length; i < n - 1; ++i) { - if (intervals[i][1] > intervals[i + 1][0]) return false; - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0252.Meeting Rooms/Solution.py b/leetcode/solution/0200-0299/0252.Meeting Rooms/Solution.py deleted file mode 100644 index fca30d77..00000000 --- a/leetcode/solution/0200-0299/0252.Meeting Rooms/Solution.py +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - def canAttendMeetings(self, intervals: List[List[int]]) -> bool: - intervals.sort(key=lambda x: x[0]) - for i in range(len(intervals) - 1): - if intervals[i][1] > intervals[i + 1][0]: - return False - return True diff --git a/leetcode/solution/0200-0299/0257.Binary Tree Paths/README_EN.md b/leetcode/solution/0200-0299/0257.Binary Tree Paths/README_EN.md deleted file mode 100644 index 8286ddab..00000000 --- a/leetcode/solution/0200-0299/0257.Binary Tree Paths/README_EN.md +++ /dev/null @@ -1,113 +0,0 @@ -# [257. Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths) - -[中文文档](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md) - -## Description - -

Given a binary tree, return all root-to-leaf paths.

- -

Note: A leaf is a node with no children.

- -

Example:

- -
-
-Input:
-
-
-
-   1
-
- /   \
-
-2     3
-
- \
-
-  5
-
-
-
-Output: ["1->2->5", "1->3"]
-
-
-
-Explanation: All root-to-leaf paths are: 1->2->5, 1->3
-
-
- -## Solutions - - - -### **Python3** - -```python -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def binaryTreePaths(self, root: TreeNode) -> List[str]: - def dfs(root): - if root is None: - return - path.append(str(root.val)) - if root.left is None and root.right is None: - res.append("->".join(path)) - dfs(root.left) - dfs(root.right) - path.pop() - res = [] - path = [] - dfs(root) - return res -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode(int x) { val = x; } - * } - */ -class Solution { - private List res; - private List path; - - public List binaryTreePaths(TreeNode root) { - if (root == null) return Collections.emptyList(); - res = new ArrayList<>(); - path = new ArrayList<>(); - dfs(root); - return res; - } - - private void dfs(TreeNode root) { - if (root == null) return; - path.add(String.valueOf(root.val)); - if (root.left == null && root.right == null) { - res.add(String.join("->", path)); - } - dfs(root.left); - dfs(root.right); - path.remove(path.size() - 1); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0257.Binary Tree Paths/Solution.py b/leetcode/solution/0200-0299/0257.Binary Tree Paths/Solution.py deleted file mode 100644 index 403b8f31..00000000 --- a/leetcode/solution/0200-0299/0257.Binary Tree Paths/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def binaryTreePaths(self, root: TreeNode) -> List[str]: - def dfs(root): - if root is None: - return - path.append(str(root.val)) - if root.left is None and root.right is None: - res.append("->".join(path)) - dfs(root.left) - dfs(root.right) - path.pop() - res = [] - path = [] - dfs(root) - return res diff --git a/leetcode/solution/0200-0299/0258.Add Digits/README_EN.md b/leetcode/solution/0200-0299/0258.Add Digits/README_EN.md deleted file mode 100644 index ba942e4b..00000000 --- a/leetcode/solution/0200-0299/0258.Add Digits/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [258. Add Digits](https://leetcode.com/problems/add-digits) - -[中文文档](/solution/0200-0299/0258.Add%20Digits/README.md) - -## Description - -

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

- -

Example:

- -
-
-Input: 38
-
-Output: 2 
-
-Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. 
-
-             Since 2 has only one digit, return it.
-
-
- -

Follow up:
- -Could you do it without any loop/recursion in O(1) runtime?

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def addDigits(self, num: int) -> int: - return 0 if num == 0 else (num - 1) % 9 + 1 -``` - -### **Java** - -```java -class Solution { - public int addDigits(int num) { - return (num - 1) % 9 + 1; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - int addDigits(int num) { - return (num - 1) % 9 + 1; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0258.Add Digits/Solution.cpp b/leetcode/solution/0200-0299/0258.Add Digits/Solution.cpp deleted file mode 100644 index 67ddad7d..00000000 --- a/leetcode/solution/0200-0299/0258.Add Digits/Solution.cpp +++ /dev/null @@ -1,6 +0,0 @@ -class Solution { -public: - int addDigits(int num) { - return (num - 1) % 9 + 1; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0258.Add Digits/Solution.py b/leetcode/solution/0200-0299/0258.Add Digits/Solution.py deleted file mode 100644 index 45dead4b..00000000 --- a/leetcode/solution/0200-0299/0258.Add Digits/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def addDigits(self, num: int) -> int: - return 0 if num == 0 else (num - 1) % 9 + 1 diff --git a/leetcode/solution/0200-0299/0260.Single Number III/README_EN.md b/leetcode/solution/0200-0299/0260.Single Number III/README_EN.md deleted file mode 100644 index 507d6d8c..00000000 --- a/leetcode/solution/0200-0299/0260.Single Number III/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [260. Single Number III](https://leetcode.com/problems/single-number-iii) - -[中文文档](/solution/0200-0299/0260.Single%20Number%20III/README.md) - -## Description - -

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.

- -

Example:

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

Note:

- -
    -
  1. The order of the result is not important. So in the above example, [5, 3] is also correct.
  2. -
  3. Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
  4. -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def singleNumber(self, nums: List[int]) -> List[int]: - xor = 0 - for num in nums: - xor ^= num - diff = xor & (-xor) - a = b = 0 - for num in nums: - if (num & diff) == 0: - a ^= num - else: - b ^= num - return [a, b] - -``` - -### **Java** - -```java -class Solution { - public int[] singleNumber(int[] nums) { - int xor = 0; - for (int num : nums) { - xor ^= num; - } - int diff = xor & (-xor); - int a = 0, b = 0; - for (int num : nums) { - if ((num & diff) == 0) a ^= num; - else b ^= num; - } - return new int[]{a, b}; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0260.Single Number III/Solution.py b/leetcode/solution/0200-0299/0260.Single Number III/Solution.py deleted file mode 100644 index 19ae6538..00000000 --- a/leetcode/solution/0200-0299/0260.Single Number III/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def singleNumber(self, nums: List[int]) -> List[int]: - xor = 0 - for num in nums: - xor ^= num - diff = xor & (-xor) - a = b = 0 - for num in nums: - if (num & diff) == 0: - a ^= num - else: - b ^= num - return [a, b] diff --git a/leetcode/solution/0200-0299/0263.Ugly Number/README_EN.md b/leetcode/solution/0200-0299/0263.Ugly Number/README_EN.md deleted file mode 100644 index 35ae6b04..00000000 --- a/leetcode/solution/0200-0299/0263.Ugly Number/README_EN.md +++ /dev/null @@ -1,74 +0,0 @@ -# [263. Ugly Number](https://leetcode.com/problems/ugly-number) - -[中文文档](/solution/0200-0299/0263.Ugly%20Number/README.md) - -## Description - -

Write a program to check whether a given number is an ugly number.

- -

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.

- -

Example 1:

- -
-
-Input: 6
-
-Output: true
-
-Explanation: 6 = 2 × 3
- -

Example 2:

- -
-
-Input: 8
-
-Output: true
-
-Explanation: 8 = 2 × 2 × 2
-
-
- -

Example 3:

- -
-
-Input: 14
-
-Output: false 
-
-Explanation: 14 is not ugly since it includes another prime factor 7.
-
-
- -

Note:

- -
    -
  1. 1 is typically treated as an ugly number.
  2. -
  3. Input is within the 32-bit signed integer range: [−231,  231 − 1].
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0264.Ugly Number II/README_EN.md b/leetcode/solution/0200-0299/0264.Ugly Number II/README_EN.md deleted file mode 100644 index badb4244..00000000 --- a/leetcode/solution/0200-0299/0264.Ugly Number II/README_EN.md +++ /dev/null @@ -1,50 +0,0 @@ -# [264. Ugly Number II](https://leetcode.com/problems/ugly-number-ii) - -[中文文档](/solution/0200-0299/0264.Ugly%20Number%20II/README.md) - -## Description - -

Write a program to find the n-th ugly number.

- -

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5

- -

Example:

- -
-
-Input: n = 10
-
-Output: 12
-
-Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
- -

Note:  

- -
    -
  1. 1 is typically treated as an ugly number.
  2. -
  3. n does not exceed 1690.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0266.Palindrome Permutation/README_EN.md b/leetcode/solution/0200-0299/0266.Palindrome Permutation/README_EN.md deleted file mode 100644 index a04c9ecc..00000000 --- a/leetcode/solution/0200-0299/0266.Palindrome Permutation/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [266. Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation) - -[中文文档](/solution/0200-0299/0266.Palindrome%20Permutation/README.md) - -## Description - -

Given a string, determine if a permutation of the string could form a palindrome.

- -

Example 1:

- -
-Input: "code"
-Output: false
- -

Example 2:

- -
-Input: "aab"
-Output: true
- -

Example 3:

- -
-Input: "carerac"
-Output: true
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def canPermutePalindrome(self, s: str) -> bool: - mapper = {} - for ch in s: - mapper[ch] = mapper.get(ch, 0) + 1 - cnt = 0 - for _, v in mapper.items(): - if v % 2 != 0: - cnt += 1 - return cnt <= 1 -``` - -### **Java** - -```java -class Solution { - public boolean canPermutePalindrome(String s) { - Map map = new HashMap<>(); - for (int i = 0, n = s.length(); i < n; ++i) { - char ch = s.charAt(i); - map.put(ch, map.getOrDefault(ch, 0) + 1); - } - int cnt = 0; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() % 2 != 0) { - ++cnt; - } - } - return cnt <= 1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0266.Palindrome Permutation/Solution.py b/leetcode/solution/0200-0299/0266.Palindrome Permutation/Solution.py deleted file mode 100644 index cf237614..00000000 --- a/leetcode/solution/0200-0299/0266.Palindrome Permutation/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def canPermutePalindrome(self, s: str) -> bool: - mapper = {} - for ch in s: - mapper[ch] = mapper.get(ch, 0) + 1 - cnt = 0 - for _, v in mapper.items(): - if v % 2 != 0: - cnt += 1 - return cnt <= 1 diff --git a/leetcode/solution/0200-0299/0268.Missing Number/README_EN.md b/leetcode/solution/0200-0299/0268.Missing Number/README_EN.md deleted file mode 100644 index 08dca80d..00000000 --- a/leetcode/solution/0200-0299/0268.Missing Number/README_EN.md +++ /dev/null @@ -1,84 +0,0 @@ -# [268. Missing Number](https://leetcode.com/problems/missing-number) - -[中文文档](/solution/0200-0299/0268.Missing%20Number/README.md) - -## Description - -

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

- -

Example 1:

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

Example 2:

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

Note:
- -Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def missingNumber(self, nums: List[int]) -> int: - res = len(nums) - for i, v in enumerate(nums): - res ^= (i ^ v) - return res -``` - -### **Java** - -- XOR - -```java -class Solution { - public int missingNumber(int[] nums) { - int res = nums.length; - for (int i = 0, n = res; i < n; ++i) { - res ^= (i ^ nums[i]); - } - return res; - } -} -``` - -- Math - -```java -class Solution { - public int missingNumber(int[] nums) { - int res = nums.length; - for (int i = 0, n = res; i < n; ++i) { - res += (i - nums[i]); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0268.Missing Number/Solution.js b/leetcode/solution/0200-0299/0268.Missing Number/Solution.js deleted file mode 100644 index c7c1fca0..00000000 --- a/leetcode/solution/0200-0299/0268.Missing Number/Solution.js +++ /dev/null @@ -1,6 +0,0 @@ -const missingNumber = function (nums) { - return ( - ((1 + nums.length) * nums.length) / 2 - - nums.reduce((prev, cur) => (prev += cur), 0) - ); -}; diff --git a/leetcode/solution/0200-0299/0273.Integer to English Words/README_EN.md b/leetcode/solution/0200-0299/0273.Integer to English Words/README_EN.md deleted file mode 100644 index f9e6c24c..00000000 --- a/leetcode/solution/0200-0299/0273.Integer to English Words/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [273. Integer to English Words](https://leetcode.com/problems/integer-to-english-words) - -[中文文档](/solution/0200-0299/0273.Integer%20to%20English%20Words/README.md) - -## Description - -

Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.

- -

Example 1:

- -
-
-Input: 123
-
-Output: "One Hundred Twenty Three"
-
-
- -

Example 2:

- -
-
-Input: 12345
-
-Output: "Twelve Thousand Three Hundred Forty Five"
- -

Example 3:

- -
-
-Input: 1234567
-
-Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
-
-
- -

Example 4:

- -
-
-Input: 1234567891
-
-Output: "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0273.Integer to English Words/Solution.cs b/leetcode/solution/0200-0299/0273.Integer to English Words/Solution.cs deleted file mode 100644 index e52511dc..00000000 --- a/leetcode/solution/0200-0299/0273.Integer to English Words/Solution.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -public class Solution { - private string[] bases = { "Thousand", "Million", "Billion" }; - public string NumberToWords(int num) { - if (num == 0) - { - return "Zero"; - } - var baseIndex = -1; - var parts = new List(); - while (num > 0) - { - var part = NumberToWordsInternal(num % 1000); - if (part.Length > 0 && baseIndex >= 0) - { - part = JoinParts(part, bases[baseIndex]); - } - parts.Add(part); - baseIndex++; - num /= 1000; - } - parts.Reverse(); - return JoinParts(parts); - } - - private string JoinParts(IEnumerable parts) - { - return string.Join(" ", parts.Where(p => p.Length > 0)); - } - - private string JoinParts(params string[] parts) - { - return JoinParts((IEnumerable)parts); - } - - private string NumberToWordsInternal(int num) - { - switch(num) - { - case 0: return ""; - case 1: return "One"; - case 2: return "Two"; - case 3: return "Three"; - case 4: return "Four"; - case 5: return "Five"; - case 6: return "Six"; - case 7: return "Seven"; - case 8: return "Eight"; - case 9: return "Nine"; - case 10: return "Ten"; - case 11: return "Eleven"; - case 12: return "Twelve"; - case 13: return "Thirteen"; - case 14: return "Fourteen"; - case 15: return "Fifteen"; - case 16: return "Sixteen"; - case 17: return "Seventeen"; - case 18: return "Eighteen"; - case 19: return "Nineteen"; - } - - if (num < 100) - { - string part1; - switch (num/10) - { - case 2: part1 = "Twenty"; break; - case 3: part1 = "Thirty"; break; - case 4: part1 = "Forty"; break; - case 5: part1 = "Fifty"; break; - case 6: part1 = "Sixty"; break; - case 7: part1 = "Seventy"; break; - case 8: part1 = "Eighty"; break; - case 9: default: part1 = "Ninety"; break; - } - var part2 = NumberToWordsInternal(num % 10); - return JoinParts(part1, part2); - } - - { - var part1 = NumberToWordsInternal(num / 100); - var part2 = NumberToWordsInternal(num % 100); - return JoinParts(part1, "Hundred", part2); - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0274.H-Index/README_EN.md b/leetcode/solution/0200-0299/0274.H-Index/README_EN.md deleted file mode 100644 index f3249d3b..00000000 --- a/leetcode/solution/0200-0299/0274.H-Index/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [274. H-Index](https://leetcode.com/problems/h-index) - -[中文文档](/solution/0200-0299/0274.H-Index/README.md) - -## Description - -

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

- -

According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."

- -

Example:

- -
-
-Input: citations = [3,0,6,1,5]
-
-Output: 3 
-
-Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had 
-
-             received 3, 0, 6, 1, 5 citations respectively. 
-
-             Since the researcher has 3 papers with at least 3 citations each and the remaining 
-
-             two with no more than 3 citations each, her h-index is 3.
- -

Note: If there are several possible values for h, the maximum one is taken as the h-index.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0275.H-Index II/README_EN.md b/leetcode/solution/0200-0299/0275.H-Index II/README_EN.md deleted file mode 100644 index 73023406..00000000 --- a/leetcode/solution/0200-0299/0275.H-Index II/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [275. H-Index II](https://leetcode.com/problems/h-index-ii) - -[中文文档](/solution/0200-0299/0275.H-Index%20II/README.md) - -## Description - -

Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

- -

According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than citations each."

- -

Example:

- -
-
-Input: citations = [0,1,3,5,6]
-
-Output: 3 
-
-Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had 
-
-             received 0, 1, 3, 5, 6 citations respectively. 
-
-             Since the researcher has 3 papers with at least 3 citations each and the remaining 
-
-             two with no more than 3 citations each, her h-index is 3.
- -

Note:

- -

If there are several possible values for h, the maximum one is taken as the h-index.

- -

Follow up:

- -
    -
  • This is a follow up problem to H-Index, where citations is now guaranteed to be sorted in ascending order.
  • -
  • Could you solve it in logarithmic time complexity?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0278.First Bad Version/README_EN.md b/leetcode/solution/0200-0299/0278.First Bad Version/README_EN.md deleted file mode 100644 index 85ee85ca..00000000 --- a/leetcode/solution/0200-0299/0278.First Bad Version/README_EN.md +++ /dev/null @@ -1,124 +0,0 @@ -# [278. First Bad Version](https://leetcode.com/problems/first-bad-version) - -[中文文档](/solution/0200-0299/0278.First%20Bad%20Version/README.md) - -## Description - -

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

- -

Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

- -

You are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

- -

Example:

- -
-
-Given n = 5, and version = 4 is the first bad version.
-
-
-
-call isBadVersion(3) -> false
-
-call isBadVersion(5) -> true
-
-call isBadVersion(4) -> true
-
-
-
-Then 4 is the first bad version. 
-
-
- -## Solutions - - - -### **Python3** - -```python -# The isBadVersion API is already defined for you. -# @param version, an integer -# @return an integer -# def isBadVersion(version): - -class Solution: - def firstBadVersion(self, n): - """ - :type n: int - :rtype: int - """ - low, high = 1, n - while low < high: - mid = low + ((high - low) >> 1) - if isBadVersion(mid): - high = mid - else: - low = mid + 1 - return low -``` - -### **Java** - -```java -/* The isBadVersion API is defined in the parent class VersionControl. - boolean isBadVersion(int version); */ - -public class Solution extends VersionControl { - public int firstBadVersion(int n) { - int low = 1, high = n; - while (low < high) { - int mid = low + ((high - low) >> 1); - if (isBadVersion(mid)) high = mid; - else low = mid + 1; - } - return low; - } -} -``` - -### **JavaScript** - -```js -/** - * Definition for isBadVersion() - * - * @param {integer} version number - * @return {boolean} whether the version is bad - * isBadVersion = function(version) { - * ... - * }; - */ - -/** - * @param {function} isBadVersion() - * @return {function} - */ -var solution = function (isBadVersion) { - /** - * @param {integer} n Total versions - * @return {integer} The first bad version - */ - return function (n) { - let low = 1, - high = n; - while (low < high) { - const mid = low + ((high - low) >> 1); - if (isBadVersion(mid)) { - high = mid; - } else { - low = mid + 1; - } - } - return low; - }; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0278.First Bad Version/Solution.js b/leetcode/solution/0200-0299/0278.First Bad Version/Solution.js deleted file mode 100644 index 7db3fc31..00000000 --- a/leetcode/solution/0200-0299/0278.First Bad Version/Solution.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Definition for isBadVersion() - * - * @param {integer} version number - * @return {boolean} whether the version is bad - * isBadVersion = function(version) { - * ... - * }; - */ - -/** - * @param {function} isBadVersion() - * @return {function} - */ -var solution = function (isBadVersion) { - /** - * @param {integer} n Total versions - * @return {integer} The first bad version - */ - return function (n) { - let low = 1, - high = n; - while (low < high) { - const mid = low + ((high - low) >> 1); - if (isBadVersion(mid)) { - high = mid; - } else { - low = mid + 1; - } - } - return low; - }; -}; diff --git a/leetcode/solution/0200-0299/0278.First Bad Version/Solution.py b/leetcode/solution/0200-0299/0278.First Bad Version/Solution.py deleted file mode 100644 index 084147c8..00000000 --- a/leetcode/solution/0200-0299/0278.First Bad Version/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -# The isBadVersion API is already defined for you. -# @param version, an integer -# @return an integer -# def isBadVersion(version): - -class Solution: - def firstBadVersion(self, n): - """ - :type n: int - :rtype: int - """ - low, high = 1, n - while low < high: - mid = low + ((high - low) >> 1) - if isBadVersion(mid): - high = mid - else: - low = mid + 1 - return low \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0279.Perfect Squares/README_EN.md b/leetcode/solution/0200-0299/0279.Perfect Squares/README_EN.md deleted file mode 100644 index 8afa9882..00000000 --- a/leetcode/solution/0200-0299/0279.Perfect Squares/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [279. Perfect Squares](https://leetcode.com/problems/perfect-squares) - -[中文文档](/solution/0200-0299/0279.Perfect%20Squares/README.md) - -## Description - -

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

- -

Example 1:

- -
-
-Input: n = 12
-
-Output: 3 
-
-Explanation: 12 = 4 + 4 + 4.
- -

Example 2:

- -
-
-Input: n = 13
-
-Output: 2
-
-Explanation: 13 = 4 + 9.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0279.Perfect Squares/Solution.go b/leetcode/solution/0200-0299/0279.Perfect Squares/Solution.go deleted file mode 100644 index d21d2b9a..00000000 --- a/leetcode/solution/0200-0299/0279.Perfect Squares/Solution.go +++ /dev/null @@ -1,24 +0,0 @@ -/* - * @lc app=leetcode.cn id=279 lang=golang - * 动态规划的思路,状态转移方程:dp[n] = min(dp[n-1*1]+1, dp[n-2*2]+1, ..., dp[n-k*k]+1), ( 0< k*k <=n ) - */ -func numSquares(n int) int { - if n <= 0 { - return 0 - } - dp := make([]int, n+1) // 多申请了一份整形,使代码更容易理解, dp[n] 就是 n 的完全平方数的求解 - for i := 1; i <= n; i++ { - dp[i] = i // 初始值 dp[n] 的最大值的解,也是最容易求的解 - for j := 0; j*j <= i; j++ { - dp[i] = minInt(dp[i-j*j]+1, dp[i]) - } - } - return dp[n] -} - -func minInt(x, y int) int { - if x < y { - return x - } - return y -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0283.Move Zeroes/README_EN.md b/leetcode/solution/0200-0299/0283.Move Zeroes/README_EN.md deleted file mode 100644 index 3a178490..00000000 --- a/leetcode/solution/0200-0299/0283.Move Zeroes/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [283. Move Zeroes](https://leetcode.com/problems/move-zeroes) - -[中文文档](/solution/0200-0299/0283.Move%20Zeroes/README.md) - -## Description - -

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

- -

Example:

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

Note:

- -
    -
  1. You must do this in-place without making a copy of the array.
  2. -
  3. Minimize the total number of operations.
  4. -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def moveZeroes(self, nums: List[int]) -> None: - """ - Do not return anything, modify nums in-place instead. - """ - if not nums: - return - n = len(nums) - zero_count = 0 - for i in range(n): - if nums[i] == 0: - zero_count += 1 - else: - nums[i - zero_count] = nums[i] - while zero_count > 0: - nums[n - zero_count] = 0 - zero_count -= 1 -``` - -### **Java** - -```java -class Solution { - public void moveZeroes(int[] nums) { - int n; - if (nums == null || (n = nums.length) < 1) { - return; - } - int zeroCount = 0; - for (int i = 0; i < n; ++i) { - if (nums[i] == 0) { - ++zeroCount; - } else { - nums[i - zeroCount] = nums[i]; - } - } - while (zeroCount > 0) { - nums[n - zeroCount--] = 0; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0283.Move Zeroes/Solution.cpp b/leetcode/solution/0200-0299/0283.Move Zeroes/Solution.cpp deleted file mode 100644 index 24d148e9..00000000 --- a/leetcode/solution/0200-0299/0283.Move Zeroes/Solution.cpp +++ /dev/null @@ -1,48 +0,0 @@ -class Solution { -public: - void moveZeroes(vector& nums) { - int len = nums.size(); - if(len == 0)return; - - int slow = 0; - int fast; - - while(slow < len){ - if(nums[slow] == 0){ - fast = slow+1; - while(fast < len){ - if(nums[fast] == 0)fast++; - else break; - } - - if(fast == len)return; - - swap(nums[slow],nums[fast]); - } - slow++; - } - - } -}; - -//--------------------------------------------- - -class Solution { -public: - void moveZeroes(vector& nums) { - int len = nums.size(); - if(len == 0)return; - - int idx = 0; - for(int i = 0;i None: - """ - Do not return anything, modify nums in-place instead. - """ - if not nums: - return - n = len(nums) - zero_count = 0 - for i in range(n): - if nums[i] == 0: - zero_count += 1 - else: - nums[i - zero_count] = nums[i] - while zero_count > 0: - nums[n - zero_count] = 0 - zero_count -= 1 diff --git a/leetcode/solution/0200-0299/0284.Peeking Iterator/README_EN.md b/leetcode/solution/0200-0299/0284.Peeking Iterator/README_EN.md deleted file mode 100644 index 09242408..00000000 --- a/leetcode/solution/0200-0299/0284.Peeking Iterator/README_EN.md +++ /dev/null @@ -1,51 +0,0 @@ -# [284. Peeking Iterator](https://leetcode.com/problems/peeking-iterator) - -[中文文档](/solution/0200-0299/0284.Peeking%20Iterator/README.md) - -## Description - -

Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be returned by the next call to next().

- -

Example:

- -
-
-Assume that the iterator is initialized to the beginning of the list: [1,2,3].
-
-
-
-Call next() gets you 1, the first element in the list.
-
-Now you call peek() and it returns 2, the next element. Calling next() after that still return 2. 
-
-You call next() the final time and it returns 3, the last element. 
-
-Calling hasNext() after that should return false.
-
-
- -

Follow up: How would you extend your design to be generic and work with all types, not just integer?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md b/leetcode/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md deleted file mode 100644 index e665e958..00000000 --- a/leetcode/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [287. Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number) - -[中文文档](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README.md) - -## Description - -

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.

- -

Example 1:

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

Example 2:

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

Note:

- -
    -
  1. You must not modify the array (assume the array is read only).
  2. -
  3. You must use only constant, O(1) extra space.
  4. -
  5. Your runtime complexity should be less than O(n2).
  6. -
  7. There is only one duplicate number in the array, but it could be repeated more than once.
  8. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0289.Game of Life/README_EN.md b/leetcode/solution/0200-0299/0289.Game of Life/README_EN.md deleted file mode 100644 index 7d180af1..00000000 --- a/leetcode/solution/0200-0299/0289.Game of Life/README_EN.md +++ /dev/null @@ -1,86 +0,0 @@ -# [289. Game of Life](https://leetcode.com/problems/game-of-life) - -[中文文档](/solution/0200-0299/0289.Game%20of%20Life/README.md) - -## Description - -

According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."

- -

Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

- -
    -
  1. Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  2. -
  3. Any live cell with two or three live neighbors lives on to the next generation.
  4. -
  5. Any live cell with more than three live neighbors dies, as if by over-population..
  6. -
  7. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
  8. -
- -

Write a function to compute the next state (after one update) of the board given its current state. The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously.

- -

Example:

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

Follow up:

- -
    - -
  1. Could you solve it in-place? Remember that the board needs to be updated at the same time: You cannot update some cells first and then use their updated values to update other cells.
  2. - -
  3. In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches the border of the array. How would you address these problems?
  4. - -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0290.Word Pattern/README_EN.md b/leetcode/solution/0200-0299/0290.Word Pattern/README_EN.md deleted file mode 100644 index fa32b94b..00000000 --- a/leetcode/solution/0200-0299/0290.Word Pattern/README_EN.md +++ /dev/null @@ -1,105 +0,0 @@ -# [290. Word Pattern](https://leetcode.com/problems/word-pattern) - -[中文文档](/solution/0200-0299/0290.Word%20Pattern/README.md) - -## Description - -

Given a pattern and a string str, find if str follows the same pattern.

- -

Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

- -

Example 1:

- -
-
-Input: pattern = "abba", str = "dog cat cat dog"
-
-Output: true
- -

Example 2:

- -
-
-Input:pattern = "abba", str = "dog cat cat fish"
-
-Output: false
- -

Example 3:

- -
-
-Input: pattern = "aaaa", str = "dog cat cat dog"
-
-Output: false
- -

Example 4:

- -
-
-Input: pattern = "abba", str = "dog dog dog dog"
-
-Output: false
- -

Notes:
- -You may assume pattern contains only lowercase letters, and str contains lowercase letters that may be separated by a single space.

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def wordPattern(self, pattern: str, s: str) -> bool: - ch2str, str2ch = {}, {} - ss = s.split(' ') - n = len(pattern) - if n != len(ss): - return False - for i in range(n): - if ch2str.get(pattern[i]) is not None and ch2str.get(pattern[i]) != ss[i]: - return False - if str2ch.get(ss[i]) is not None and str2ch.get(ss[i]) != pattern[i]: - return False - ch2str[pattern[i]] = ss[i] - str2ch[ss[i]] = pattern[i] - return True -``` - -### **Java** - -```java -class Solution { - public boolean wordPattern(String pattern, String s) { - Map ch2str = new HashMap<>(); - Map str2ch = new HashMap<>(); - String[] ss = s.split(" "); - int n = pattern.length(); - if (n != ss.length) { - return false; - } - for (int i = 0; i < n; ++i) { - char ch = pattern.charAt(i); - if (ch2str.containsKey(ch) && !ch2str.get(ch).equals(ss[i])) { - return false; - } - if (str2ch.containsKey(ss[i]) && !str2ch.get(ss[i]).equals(ch)) { - return false; - } - ch2str.put(ch, ss[i]); - str2ch.put(ss[i], ch); - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0290.Word Pattern/Solution.py b/leetcode/solution/0200-0299/0290.Word Pattern/Solution.py deleted file mode 100644 index 3e7b098b..00000000 --- a/leetcode/solution/0200-0299/0290.Word Pattern/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def wordPattern(self, pattern: str, s: str) -> bool: - ch2str, str2ch = {}, {} - ss = s.split(' ') - n = len(pattern) - if n != len(ss): - return False - for i in range(n): - if ch2str.get(pattern[i]) is not None and ch2str.get(pattern[i]) != ss[i]: - return False - if str2ch.get(ss[i]) is not None and str2ch.get(ss[i]) != pattern[i]: - return False - ch2str[pattern[i]] = ss[i] - str2ch[ss[i]] = pattern[i] - return True diff --git a/leetcode/solution/0200-0299/0292.Nim Game/README_EN.md b/leetcode/solution/0200-0299/0292.Nim Game/README_EN.md deleted file mode 100644 index a2bb5160..00000000 --- a/leetcode/solution/0200-0299/0292.Nim Game/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [292. Nim Game](https://leetcode.com/problems/nim-game) - -[中文文档](/solution/0200-0299/0292.Nim%20Game/README.md) - -## Description - -

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

- -

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

- -

Example:

- -
-
-Input: 4
-
-Output: false 
-
-Explanation: If there are 4 stones in the heap, then you will never win the game;
-
-             No matter 1, 2, or 3 stones you remove, the last stone will always be 
-
-             removed by your friend.
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0293.Flip Game/README_EN.md b/leetcode/solution/0200-0299/0293.Flip Game/README_EN.md deleted file mode 100644 index a07290ed..00000000 --- a/leetcode/solution/0200-0299/0293.Flip Game/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [293. Flip Game](https://leetcode.com/problems/flip-game) - -[中文文档](/solution/0200-0299/0293.Flip%20Game/README.md) - -## Description - -

You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move and therefore the other person will be the winner.

- -

Write a function to compute all possible states of the string after one valid move.

- -

Example:

- -
-Input: s = "++++"
-Output: 
-[
-  "--++",
-  "+--+",
-  "++--"
-]
-
- -

Note: If there is no valid move, return an empty list [].

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def generatePossibleNextMoves(self, s: str) -> List[str]: - if not s or len(s) < 2: - return [] - n = len(s) - res = [] - for i in range(n - 1): - if s[i] == '+' and s[i + 1] == '+': - res.append(s[:i] + "--" + s[i + 2:]) - return res -``` - -### **Java** - -```java -class Solution { - public List generatePossibleNextMoves(String s) { - int n; - if (s == null || (n = s.length()) < 2) return Collections.emptyList(); - List res = new ArrayList<>(); - for (int i = 0; i < n - 1; ++i) { - if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') { - StringBuilder sb = new StringBuilder(s); - sb.replace(i, i + 2, "--"); - res.add(sb.toString()); - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0293.Flip Game/Solution.py b/leetcode/solution/0200-0299/0293.Flip Game/Solution.py deleted file mode 100644 index 00a39299..00000000 --- a/leetcode/solution/0200-0299/0293.Flip Game/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def generatePossibleNextMoves(self, s: str) -> List[str]: - if not s or len(s) < 2: - return [] - n = len(s) - res = [] - for i in range(n - 1): - if s[i] == '+' and s[i + 1] == '+': - res.append(s[:i] + "--" + s[i + 2:]) - return res diff --git a/leetcode/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md b/leetcode/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md deleted file mode 100644 index 27699aa5..00000000 --- a/leetcode/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [295. Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream) - -[中文文档](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README.md) - -## Description - -

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

- -For example, - -

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

- -

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

- -

Design a data structure that supports the following two operations:

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

 

- -

Example:

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

 

- -

Follow up:

- -
    -
  1. If all integer numbers from the stream are between 0 and 100, how would you optimize it?
  2. -
  3. If 99% of all integer numbers from the stream are between 0 and 100, how would you optimize it?
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0295.Find Median from Data Stream/Solution.cs b/leetcode/solution/0200-0299/0295.Find Median from Data Stream/Solution.cs deleted file mode 100644 index 357b1dbd..00000000 --- a/leetcode/solution/0200-0299/0295.Find Median from Data Stream/Solution.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; - -public class Comparer : IComparer> -{ - public int Compare(Tuple x, Tuple y) - { - var result = x.Item1.CompareTo(y.Item1); - if (result != 0) - { - return result; - } - return x.Item2.CompareTo(y.Item2); - } -} - -public class MedianFinder { - - private SortedSet> smallerHeap = new SortedSet>(); - private SortedSet> biggerHeap = new SortedSet>(); - - private int index; - - public void AddNum(double num) { - if (smallerHeap.Count == 0 || smallerHeap.Max.Item1 >= num) - { - smallerHeap.Add(Tuple.Create(num, index++)); - } - else - { - biggerHeap.Add(Tuple.Create(num, index++)); - } - - if (smallerHeap.Count == biggerHeap.Count + 2) - { - biggerHeap.Add(smallerHeap.Max); - smallerHeap.Remove(smallerHeap.Max); - } - else if (biggerHeap.Count == smallerHeap.Count + 2) - { - smallerHeap.Add(biggerHeap.Min); - biggerHeap.Remove(biggerHeap.Min); - } - } - - public double FindMedian() { - if (smallerHeap.Count == biggerHeap.Count) - { - return (smallerHeap.Max.Item1 + biggerHeap.Min.Item1) / 2; - } - else if (smallerHeap.Count < biggerHeap.Count) - { - return biggerHeap.Min.Item1; - } - else - { - return smallerHeap.Max.Item1; - } - } -} \ No newline at end of file diff --git a/leetcode/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md b/leetcode/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md deleted file mode 100644 index efa607b5..00000000 --- a/leetcode/solution/0200-0299/0297.Serialize and Deserialize Binary Tree/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [297. Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) - -[中文文档](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README.md) - -## Description - -

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

- -

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

- -

Example: 

- -
-
-You may serialize the following tree:
-
-
-
-    1
-
-   / \
-
-  2   3
-
-     / \
-
-    4   5
-
-
-
-as "[1,2,3,null,null,4,5]"
-
-
- -

Clarification: The above format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

- -

Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0200-0299/0299.Bulls and Cows/README_EN.md b/leetcode/solution/0200-0299/0299.Bulls and Cows/README_EN.md deleted file mode 100644 index 51e880bb..00000000 --- a/leetcode/solution/0200-0299/0299.Bulls and Cows/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [299. Bulls and Cows](https://leetcode.com/problems/bulls-and-cows) - -[中文文档](/solution/0200-0299/0299.Bulls%20and%20Cows/README.md) - -## Description - -

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called "bulls") and how many digits match the secret number but locate in the wrong position (called "cows"). Your friend will use successive guesses and hints to eventually derive the secret number.

- -

Write a function to return a hint according to the secret number and friend's guess, use A to indicate the bulls and B to indicate the cows. 

- -

Please note that both secret number and friend's guess may contain duplicate digits.

- -

Example 1:

- -
-
-Input: secret = "1807", guess = "7810"
-
-
-
-Output: "1A3B"
-
-
-
-Explanation: 1 bull and 3 cows. The bull is 8, the cows are 0, 1 and 7.
- -

Example 2:

- -
-
-Input: secret = "1123", guess = "0111"
-
-
-
-Output: "1A1B"
-
-
-
-Explanation: The 1st 1 in friend's guess is a bull, the 2nd or 3rd 1 is a cow.
- -

Note: You may assume that the secret number and your friend's guess only contain digits, and their lengths are always equal.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md b/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md deleted file mode 100644 index 2186bd82..00000000 --- a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [300. Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence) - -[中文文档](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md) - -## Description - -

Given an unsorted array of integers, find the length of longest increasing subsequence.

- -

Example:

- -
-
-Input: [10,9,2,5,3,7,101,18]
-
-Output: 4 
-
-Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. 
- -

Note:

- -
    -
  • There may be more than one LIS combination, it is only necessary for you to return the length.
  • -
  • Your algorithm should run in O(n2) complexity.
  • -
- -

Follow up: Could you improve it to O(n log n) time complexity?

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def lengthOfLIS(self, nums: List[int]) -> int: - n = len(nums) - if n < 2: - return n - dp = [1] * n - res = 1 - for i in range(1, n): - for j in range(i): - if nums[j] < nums[i]: - dp[i] = max(dp[i], dp[j] + 1) - res = max(res, dp[i]) - return res -``` - -### **Java** - -```java -class Solution { - public int lengthOfLIS(int[] nums) { - int n = nums.length; - int[] dp = new int[n]; - Arrays.fill(dp, 1); - int res = 1; - for (int i = 1; i < n; ++i) { - for (int j = 0; j < i; ++j) { - if (nums[j] < nums[i]) { - dp[i] = Math.max(dp[i], dp[j] + 1); - } - } - res = Math.max(res, dp[i]); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.cpp b/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.cpp deleted file mode 100644 index 4daa0895..00000000 --- a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.cpp +++ /dev/null @@ -1,17 +0,0 @@ -class Solution { -public: - int lengthOfLIS(vector& nums) { - if (nums.size() == 0) - return 0 ; - int M[nums.size()] = {0, } ; - int MM = -1 ; - for (int i = nums.size()-1; i >= 0; --i) - { - for (int j = i+1; j < nums.size(); ++j) - if (nums[i] < nums[j]) - M[i] = max(M[i], M[j]) ; - MM = max(++M[i], MM) ; - } - return MM ; - } -}; diff --git a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.py b/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.py deleted file mode 100644 index 3a97a9fe..00000000 --- a/leetcode/solution/0300-0399/0300.Longest Increasing Subsequence/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def lengthOfLIS(self, nums: List[int]) -> int: - n = len(nums) - if n < 2: - return n - dp = [1] * n - res = 1 - for i in range(1, n): - for j in range(i): - if nums[j] < nums[i]: - dp[i] = max(dp[i], dp[j] + 1) - res = max(res, dp[i]) - return res diff --git a/leetcode/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md b/leetcode/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md deleted file mode 100644 index eda6a8f7..00000000 --- a/leetcode/solution/0300-0399/0301.Remove Invalid Parentheses/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [301. Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses) - -[中文文档](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README.md) - -## Description - -

Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.

- -

Note: The input string may contain letters other than the parentheses ( and ).

- -

Example 1:

- -
-
-Input: "()())()"
-
-Output: ["()()()", "(())()"]
-
-
- -

Example 2:

- -
-
-Input: "(a)())()"
-
-Output: ["(a)()()", "(a())()"]
-
-
- -

Example 3:

- -
-
-Input: ")("
-
-Output: [""]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md b/leetcode/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md deleted file mode 100644 index df206661..00000000 --- a/leetcode/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [303. Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable) - -[中文文档](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README.md) - -## Description - -

Given an integer array nums, find the sum of the elements between indices i and j (ij), inclusive.

- -

Example:
- -

-
-Given nums = [-2, 0, 3, -5, 2, -1]
-
-
-
-sumRange(0, 2) -> 1
-
-sumRange(2, 5) -> -1
-
-sumRange(0, 5) -> -3
-
-
- -

- -

Note:
- -

    - -
  1. You may assume that the array does not change.
  2. - -
  3. There are many calls to sumRange function.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md b/leetcode/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md deleted file mode 100644 index b739cbf9..00000000 --- a/leetcode/solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [304. Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable) - -[中文文档](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md) - -## Description - -

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).

- -

- -![](./images/304.png) - -The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and (row2, col2) = (4, 3), which contains sum = 8. - -

- -

Example:
- -

-
-Given matrix = [
-
-  [3, 0, 1, 4, 2],
-
-  [5, 6, 3, 2, 1],
-
-  [1, 2, 0, 1, 5],
-
-  [4, 1, 0, 1, 7],
-
-  [1, 0, 3, 0, 5]
-
-]
-
-
-
-sumRegion(2, 1, 4, 3) -> 8
-
-sumRegion(1, 1, 2, 2) -> 11
-
-sumRegion(1, 2, 2, 4) -> 12
-
-
- -

- -

Note:
- -

    - -
  1. You may assume that the matrix does not change.
  2. - -
  3. There are many calls to sumRegion function.
  4. - -
  5. You may assume that row1 ≤ row2 and col1 ≤ col2.
  6. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0306.Additive Number/README_EN.md b/leetcode/solution/0300-0399/0306.Additive Number/README_EN.md deleted file mode 100644 index 7d528ac0..00000000 --- a/leetcode/solution/0300-0399/0306.Additive Number/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [306. Additive Number](https://leetcode.com/problems/additive-number) - -[中文文档](/solution/0300-0399/0306.Additive%20Number/README.md) - -## Description - -

Additive number is a string whose digits can form additive sequence.

- -

A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.

- -

Given a string containing only digits '0'-'9', write a function to determine if it's an additive number.

- -

Note: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.

- -

 

-

Example 1:

- -
-Input: "112358"
-Output: true
-Explanation: The digits can form an additive sequence: 1, 1, 2, 3, 5, 8. 
-             1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8
-
- -

Example 2:

- -
-Input: "199100199"
-Output: true
-Explanation: The additive sequence is: 1, 99, 100, 199. 
-             1 + 99 = 100, 99 + 100 = 199
-
- -

 

-

Constraints:

- -
    -
  • num consists only of digits '0'-'9'.
  • -
  • 1 <= num.length <= 35
  • -
- -

Follow up:
-How would you handle overflow for very large input integers?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md b/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md deleted file mode 100644 index 8d6ef9c0..00000000 --- a/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/README_EN.md +++ /dev/null @@ -1,56 +0,0 @@ -# [307. Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable) - -[中文文档](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README.md) - -## Description - -

Given an integer array nums, find the sum of the elements between indices i and j (ij), inclusive.

- -

The update(i, val) function modifies nums by updating the element at index i to val.

- -

Example:

- -
-
-Given nums = [1, 3, 5]
-
-
-
-sumRange(0, 2) -> 9
-
-update(1, 2)
-
-sumRange(0, 2) -> 8
-
-
- -

Note:

- -
    -
  1. The array is only modifiable by the update function.
  2. -
  3. You may assume the number of calls to update and sumRange function is distributed evenly.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/Solution.cs b/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/Solution.cs deleted file mode 100644 index b15a1c93..00000000 --- a/leetcode/solution/0300-0399/0307.Range Sum Query - Mutable/Solution.cs +++ /dev/null @@ -1,75 +0,0 @@ -public class NumArray { - private int[] sums; - private int numsCount; - private int sumsCount; - - public NumArray(int[] nums) { - numsCount = nums.Length; - sumsCount = 1; - var x = numsCount; - while (x > 1) - { - x /= 2; - sumsCount *= 2; - } - sumsCount = sumsCount * 2 - 1 + numsCount; - sums = new int[sumsCount + 1]; - - for (var i = sumsCount; i > 0; --i) - { - if (i - sumsCount + numsCount - 1 >= 0) - { - sums[i] = nums[i - sumsCount + numsCount - 1]; - } - else - { - var l = i * 2; - var r = l + 1; - if (l <= sumsCount) - { - sums[i] += sums[l]; - if (r <= sumsCount) - { - sums[i] += sums[r]; - } - } - } - } - //System.Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(sums)); - } - - public void Update(int i, int val) { - var j = sumsCount - numsCount + i + 1; - sums[j] = val; - for (j /= 2; j > 0; j /= 2) - { - var l = j * 2; - var r = l + 1; - sums[j] = sums[l]; - if (r <= sumsCount) - { - sums[j] += sums[r]; - } - } - //System.Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(sums)); - } - - public int SumRange(int i, int j) { - return SumFromStart(j) - SumFromStart(i - 1); - } - - private int SumFromStart(int i) - { - if (i < 0) return 0; - var j = sumsCount - numsCount + i + 1; - var sum = sums[j]; - for (; j / 2 > 0; j /= 2) - { - if (j % 2 != 0) - { - sum += sums[j - 1]; - } - } - return sum; - } -} \ No newline at end of file diff --git a/leetcode/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md b/leetcode/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md deleted file mode 100644 index e4728413..00000000 --- a/leetcode/solution/0300-0399/0309.Best Time to Buy and Sell Stock with Cooldown/README_EN.md +++ /dev/null @@ -1,50 +0,0 @@ -# [309. Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) - -[中文文档](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md) - -## Description - -

Say you have an array for which the ith element is the price of a given stock on day i.

- -

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:

- -
    -
  • You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
  • -
  • After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day)
  • -
- -

Example:

- -
-
-Input: [1,2,3,0,2]
-
-Output: 3 
-
-Explanation: transactions = [buy, sell, cooldown, buy, sell]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0312.Burst Balloons/README_EN.md b/leetcode/solution/0300-0399/0312.Burst Balloons/README_EN.md deleted file mode 100644 index e864bed6..00000000 --- a/leetcode/solution/0300-0399/0312.Burst Balloons/README_EN.md +++ /dev/null @@ -1,54 +0,0 @@ -# [312. Burst Balloons](https://leetcode.com/problems/burst-balloons) - -[中文文档](/solution/0300-0399/0312.Burst%20Balloons/README.md) - -## Description - -

Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.

- -

Find the maximum coins you can collect by bursting the balloons wisely.

- -

Note:

- -
    -
  • You may imagine nums[-1] = nums[n] = 1. They are not real therefore you can not burst them.
  • -
  • 0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100
  • -
- -

Example:

- -
-
-Input: [3,1,5,8]
-
-Output: 167 
-
-Explanation: nums = [3,1,5,8] --> [3,5,8] -->   [3,8]   -->  [8]  --> []
-
-             coins =  3*1*5      +  3*5*8    +  1*3*8      + 1*8*1   = 167
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0319.Bulb Switcher/README_EN.md b/leetcode/solution/0300-0399/0319.Bulb Switcher/README_EN.md deleted file mode 100644 index 9c038cf6..00000000 --- a/leetcode/solution/0300-0399/0319.Bulb Switcher/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [319. Bulb Switcher](https://leetcode.com/problems/bulb-switcher) - -[中文文档](/solution/0300-0399/0319.Bulb%20Switcher/README.md) - -## Description - -

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the i-th round, you toggle every i bulb. For the n-th round, you only toggle the last bulb. Find how many bulbs are on after n rounds.

- -

Example:

- -
-
-Input: 3
-
-Output: 1 
-
-Explanation: 
-
-At first, the three bulbs are [off, off, off].
-
-After first round, the three bulbs are [on, on, on].
-
-After second round, the three bulbs are [on, off, on].
-
-After third round, the three bulbs are [on, off, off]. 
-
-
-
-So you should return 1, because there is only one bulb is on.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0322.Coin Change/README_EN.md b/leetcode/solution/0300-0399/0322.Coin Change/README_EN.md deleted file mode 100644 index 8e514844..00000000 --- a/leetcode/solution/0300-0399/0322.Coin Change/README_EN.md +++ /dev/null @@ -1,74 +0,0 @@ -# [322. Coin Change](https://leetcode.com/problems/coin-change) - -[中文文档](/solution/0300-0399/0322.Coin%20Change/README.md) - -## Description - -

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

- -

Example 1:

- -
-
-Input: coins = [1, 2, 5], amount = 11
-
-Output: 3 
-
-Explanation: 11 = 5 + 5 + 1
- -

Example 2:

- -
-
-Input: coins = [2], amount = 3
-
-Output: -1
-
-
- -

Note:
- -You may assume that you have an infinite number of each kind of coin.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **JavaScript** - -Dynamic programming. - -```javascript -/** - * @param {number[]} coins - * @param {number} amount - * @return {number} - */ -var coinChange = function (coins, amount) { - var dp = Array(amount + 1).fill(amount + 1); - dp[0] = 0; - for (var i = 1; i <= amount; i++) { - for (var j = 0; j < coins.length; j++) { - if (coins[j] <= i) { - dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1); - } - } - } - - return dp[amount] > amount ? -1 : dp[amount]; -}; - - -``` diff --git a/leetcode/solution/0300-0399/0322.Coin Change/Solution.js b/leetcode/solution/0300-0399/0322.Coin Change/Solution.js deleted file mode 100644 index 598268be..00000000 --- a/leetcode/solution/0300-0399/0322.Coin Change/Solution.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @param {number[]} coins - * @param {number} amount - * @return {number} - */ -var coinChange = function (coins, amount) { - var dp = Array(amount + 1).fill(amount + 1); - dp[0] = 0; - for (var i = 1; i <= amount; i++) { - for (var j = 0; j < coins.length; j++) { - if (coins[j] <= i) { - dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1); - } - } - } - - return dp[amount] > amount ? -1 : dp[amount]; -}; diff --git a/leetcode/solution/0300-0399/0328.Odd Even Linked List/README_EN.md b/leetcode/solution/0300-0399/0328.Odd Even Linked List/README_EN.md deleted file mode 100644 index 223f207f..00000000 --- a/leetcode/solution/0300-0399/0328.Odd Even Linked List/README_EN.md +++ /dev/null @@ -1,103 +0,0 @@ -# [328. Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list) - -[中文文档](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md) - -## Description - -

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

- -

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

- -

Example 1:

- -
-
-Input: 1->2->3->4->5->NULL
-
-Output: 1->3->5->2->4->NULL
-
-
- -

Example 2:

- -
-
-Input: 2->1->3->5->6->4->7->NULL
-
-Output: 2->3->6->7->1->5->4->NULL
-
-
- -

Note:

- -
    -
  • The relative order inside both the even and odd groups should remain as it was in the input.
  • -
  • The first node is considered odd, the second node even and so on ...
  • -
- -## Solutions - - - -### **Python3** - -```python -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def oddEvenList(self, head: ListNode) -> ListNode: - if head is None: - return head - evenHead = head.next - odd, even = head, evenHead - while even and even.next: - odd.next = even.next - odd = odd.next - even.next = odd.next - even = even.next - odd.next = evenHead - return head -``` - -### **Java** - -```java -/** - * Definition for singly-linked list. - * public class ListNode { - * int val; - * ListNode next; - * ListNode() {} - * ListNode(int val) { this.val = val; } - * ListNode(int val, ListNode next) { this.val = val; this.next = next; } - * } - */ -class Solution { - public ListNode oddEvenList(ListNode head) { - if (head == null) { - return head; - } - ListNode evenHead = head.next; - ListNode odd = head, even = evenHead; - while (even != null && even.next != null) { - odd.next = even.next; - odd = odd.next; - even.next = odd.next; - even = even.next; - } - odd.next = evenHead; - return head; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0328.Odd Even Linked List/Solution.py b/leetcode/solution/0300-0399/0328.Odd Even Linked List/Solution.py deleted file mode 100644 index dc0295c4..00000000 --- a/leetcode/solution/0300-0399/0328.Odd Even Linked List/Solution.py +++ /dev/null @@ -1,18 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, val=0, next=None): -# self.val = val -# self.next = next -class Solution: - def oddEvenList(self, head: ListNode) -> ListNode: - if head is None: - return head - evenHead = head.next - odd, even = head, evenHead - while even and even.next: - odd.next = even.next - odd = odd.next - even.next = odd.next - even = even.next - odd.next = evenHead - return head diff --git a/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md b/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md deleted file mode 100644 index 09f0e985..00000000 --- a/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [329. Longest Increasing Path in a Matrix](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) - -[中文文档](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README.md) - -## Description - -

Given an integer matrix, find the length of the longest increasing path.

- -

From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).

- -

Example 1:

- -
-
-Input: nums = 
-
-[
-
-  [9,9,4],
-
-  [6,6,8],
-
-  [2,1,1]
-
-] 
-
-Output: 4 
-
-Explanation: The longest increasing path is [1, 2, 6, 9].
-
-
- -

Example 2:

- -
-
-Input: nums = 
-
-[
-
-  [3,4,5],
-
-  [3,2,6],
-
-  [2,2,1]
-
-] 
-
-Output: 4 
-
-Explanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/Solution.cpp b/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/Solution.cpp deleted file mode 100644 index 99dc31c7..00000000 --- a/leetcode/solution/0300-0399/0329.Longest Increasing Path in a Matrix/Solution.cpp +++ /dev/null @@ -1,54 +0,0 @@ -class Solution { -private: - int Dfs(vector> &m, vector> &v, - int i, int j, - bool first, int lastNum) - { - if (i < 0 || i >= m.size() - || j < 0 || j >= m[0].size()) - return 0 ; - - if (!first && lastNum >= m[i][j]) - return 0 ; - - if (v[i][j] >= 0) - return v[i][j] ; - - int d1 = Dfs(m, v, i-1, j, false, m[i][j]) ; - int d2 = Dfs(m, v, i+1, j, false, m[i][j]) ; - int d3 = Dfs(m, v, i, j-1, false, m[i][j]) ; - int d4 = Dfs(m, v, i, j+1, false, m[i][j]) ; - v[i][j] = 1 + max(max(d1, d2), max(d3, d4)) ; - - return v[i][j] ; - } -public: - int longestIncreasingPath(vector>& matrix) { - if (matrix.size() == 0) - return 0 ; - const int h = matrix.size(), w = matrix[0].size() ; - vector> visited(h, vector(w, -1)) ; - - int M = 0 ; - for (int i = 0; i < h; ++i) - for (int j = 0; j < w; ++j) - { - if (j + 1 < w && matrix[i][j] > matrix[i][j+1] - || i + 1 < h && matrix[i][j] > matrix[i+1][j]) - { - continue ; - } - else - { - M = max(M, Dfs(matrix, visited, i, j, true, 0)) ; - } - } - return M ; - } -}; - -static const auto __ = []() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - return nullptr; -}(); \ No newline at end of file diff --git a/leetcode/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md b/leetcode/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md deleted file mode 100644 index 8173065c..00000000 --- a/leetcode/solution/0300-0399/0331.Verify Preorder Serialization of a Binary Tree/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [331. Verify Preorder Serialization of a Binary Tree](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) - -[中文文档](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README.md) - -## Description - -

One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.

- -
-
-     _9_
-
-    /   \
-
-   3     2
-
-  / \   / \
-
- 4   1  #  6
-
-/ \ / \   / \
-
-# # # #   # #
-
-
- -

For example, the above binary tree can be serialized to the string "9,3,4,#,#,1,#,#,2,#,6,#,#", where # represents a null node.

- -

Given a string of comma separated values, verify whether it is a correct preorder traversal serialization of a binary tree. Find an algorithm without reconstructing the tree.

- -

Each comma separated value in the string must be either an integer or a character '#' representing null pointer.

- -

You may assume that the input format is always valid, for example it could never contain two consecutive commas such as "1,,3".

- -

Example 1:

- -
-
-Input: "9,3,4,#,#,1,#,#,2,#,6,#,#"
-
-Output: true
- -

Example 2:

- -
-
-Input: "1,#"
-
-Output: false
-
-
- -

Example 3:

- -
-
-Input: "9,#,#,1"
-
-Output: false
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0337.House Robber III/README_EN.md b/leetcode/solution/0300-0399/0337.House Robber III/README_EN.md deleted file mode 100644 index 8ab538c3..00000000 --- a/leetcode/solution/0300-0399/0337.House Robber III/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [337. House Robber III](https://leetcode.com/problems/house-robber-iii) - -[中文文档](/solution/0300-0399/0337.House%20Robber%20III/README.md) - -## Description - -

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.

- -

Determine the maximum amount of money the thief can rob tonight without alerting the police.

- -

Example 1:

- -
-
-Input: [3,2,3,null,3,null,1]
-
-
-
-     3
-
-    / \
-
-   2   3
-
-    \   \ 
-
-     3   1
-
-
-
-Output: 7 
-
-Explanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.
- -

Example 2:

- -
-
-Input: [3,4,5,1,3,null,1]
-
-
-
-     3
-
-    / \
-
-   4   5
-
-  / \   \ 
-
- 1   3   1
-
-
-
-Output: 9
-
-Explanation: Maximum amount of money the thief can rob = 4 + 5 = 9.
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0342.Power of Four/README_EN.md b/leetcode/solution/0300-0399/0342.Power of Four/README_EN.md deleted file mode 100644 index aebb3499..00000000 --- a/leetcode/solution/0300-0399/0342.Power of Four/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [342. Power of Four](https://leetcode.com/problems/power-of-four) - -[中文文档](/solution/0300-0399/0342.Power%20of%20Four/README.md) - -## Description - -

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

- -

Example 1:

- -
-
-Input: 16
-
-Output: true
-
-
- -
- -

Example 2:

- -
-
-Input: 5
-
-Output: false
- -
- -

Follow up: Could you solve it without loops/recursion?

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0342.Power of Four/Solution.js b/leetcode/solution/0300-0399/0342.Power of Four/Solution.js deleted file mode 100644 index 86c7872a..00000000 --- a/leetcode/solution/0300-0399/0342.Power of Four/Solution.js +++ /dev/null @@ -1,3 +0,0 @@ -const isPowerOfFour = function (num) { - return (Math.log(num) / Math.log(4)) % 1.0 == 0.0; -}; diff --git a/leetcode/solution/0300-0399/0343.Integer Break/README_EN.md b/leetcode/solution/0300-0399/0343.Integer Break/README_EN.md deleted file mode 100644 index 051a132e..00000000 --- a/leetcode/solution/0300-0399/0343.Integer Break/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [343. Integer Break](https://leetcode.com/problems/integer-break) - -[中文文档](/solution/0300-0399/0343.Integer%20Break/README.md) - -## Description - -

Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.

- -

Example 1:

- -
- -
-
-Input: 2
-
-Output: 1
-
-Explanation: 2 = 1 + 1, 1 × 1 = 1.
- -
- -

Example 2:

- -
-
-Input: 10
-
-Output: 36
-
-Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
- -

Note: You may assume that n is not less than 2 and not larger than 58.

- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0344.Reverse String/README_EN.md b/leetcode/solution/0300-0399/0344.Reverse String/README_EN.md deleted file mode 100644 index 9647bc31..00000000 --- a/leetcode/solution/0300-0399/0344.Reverse String/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [344. Reverse String](https://leetcode.com/problems/reverse-string) - -[中文文档](/solution/0300-0399/0344.Reverse%20String/README.md) - -## Description - -

Write a function that reverses a string. The input string is given as an array of characters char[].

- -

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

- -

You may assume all the characters consist of printable ascii characters.

- -

 

- -
- -

Example 1:

- -
-
-Input: ["h","e","l","l","o"]
-
-Output: ["o","l","l","e","h"]
-
-
- -
- -

Example 2:

- -
-
-Input: ["H","a","n","n","a","h"]
-
-Output: ["h","a","n","n","a","H"]
-
-
- -
- -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def reverseString(self, s: List[str]) -> None: - """ - Do not return anything, modify s in-place instead. - """ - s[:] = s[::-1] -``` - -### **Java** - -```java -class Solution { - public void reverseString(char[] s) { - int n; - if (s == null || (n = s.length) < 2) return; - int i = 0, j = n - 1; - while (i < j) { - char t = s[i]; - s[i] = s[j]; - s[j] = t; - ++i; - --j; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0344.Reverse String/Solution.js b/leetcode/solution/0300-0399/0344.Reverse String/Solution.js deleted file mode 100644 index f56459a7..00000000 --- a/leetcode/solution/0300-0399/0344.Reverse String/Solution.js +++ /dev/null @@ -1,3 +0,0 @@ -const reverseString = function (s) { - return s.split("").reverse().join(""); -}; diff --git a/leetcode/solution/0300-0399/0344.Reverse String/Solution.py b/leetcode/solution/0300-0399/0344.Reverse String/Solution.py deleted file mode 100644 index 00a39299..00000000 --- a/leetcode/solution/0300-0399/0344.Reverse String/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def generatePossibleNextMoves(self, s: str) -> List[str]: - if not s or len(s) < 2: - return [] - n = len(s) - res = [] - for i in range(n - 1): - if s[i] == '+' and s[i + 1] == '+': - res.append(s[:i] + "--" + s[i + 2:]) - return res diff --git a/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md b/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md deleted file mode 100644 index cbfddde7..00000000 --- a/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/README_EN.md +++ /dev/null @@ -1,119 +0,0 @@ -# [345. Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string) - -[中文文档](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md) - -## Description - -

Write a function that takes a string as input and reverse only the vowels of a string.

- -

Example 1:

- -
-
-Input: "hello"
-
-Output: "holle"
-
-
- -
- -

Example 2:

- -
-
-Input: "leetcode"
-
-Output: "leotcede"
- -
- -

Note:
- -The vowels does not include the letter "y".

- -

 

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def reverseVowels(self, s: str) -> str: - if s is None: - return s - chars = list(s) - p, q = 0, len(chars) - 1 - while p < q: - if chars[p] not in 'aeiouAEIOU': - p += 1 - continue - if chars[q] not in 'aeiouAEIOU': - q -= 1 - continue - chars[p], chars[q] = chars[q], chars[p] - p += 1 - q -= 1 - return ''.join(chars) -``` - -### **Java** - -```java -class Solution { - public String reverseVowels(String s) { - if (s == null) { - return s; - } - char[] chars = s.toCharArray(); - int p = 0, q = chars.length - 1; - while (p < q) { - if (!isVowel(chars[p])) { - ++p; - continue; - } - if (!isVowel(chars[q])) { - --q; - continue; - } - swap(chars, p++, q--); - } - return String.valueOf(chars); - } - - private void swap(char[] chars, int i, int j) { - char t = chars[i]; - chars[i] = chars[j]; - chars[j] = t; - } - - private boolean isVowel(char c) { - switch(c) { - case 'a': - case 'e': - case 'i': - case 'o': - case 'u': - case 'A': - case 'E': - case 'I': - case 'O': - case 'U': - return true; - default: - return false; - } - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/Solution.py b/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/Solution.py deleted file mode 100644 index a58b4af1..00000000 --- a/leetcode/solution/0300-0399/0345.Reverse Vowels of a String/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def reverseVowels(self, s: str) -> str: - if s is None: - return s - chars = list(s) - p, q = 0, len(chars) - 1 - while p < q: - if chars[p] not in 'aeiouAEIOU': - p += 1 - continue - if chars[q] not in 'aeiouAEIOU': - q -= 1 - continue - chars[p], chars[q] = chars[q], chars[p] - p += 1 - q -= 1 - return ''.join(chars) diff --git a/leetcode/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md b/leetcode/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md deleted file mode 100644 index a6376090..00000000 --- a/leetcode/solution/0300-0399/0347.Top K Frequent Elements/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [347. Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements) - -[中文文档](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README.md) - -## Description - -

Given a non-empty array of integers, return the k most frequent elements.

- -

Example 1:

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

Example 2:

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

Note:

- -
    -
  • You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
  • -
  • Your algorithm's time complexity must be better than O(n log n), where n is the array's size.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md b/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md deleted file mode 100644 index b280a01d..00000000 --- a/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [349. Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays) - -[中文文档](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README.md) - -## Description - -

Given two arrays, write a function to compute their intersection.

- -

Example 1:

- -
-
-Input: nums1 = [1,2,2,1], nums2 = [2,2]
-
-Output: [2]
-
-
- -
- -

Example 2:

- -
-
-Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
-
-Output: [9,4]
- -
- -

Note:

- -
    -
  • Each element in the result must be unique.
  • -
  • The result can be in any order.
  • -
- -

 

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: - s1, s2 = set(nums1), set(nums2) - return list(s1 & s2) -``` - -### **Java** - -```java -class Solution { - public int[] intersection(int[] nums1, int[] nums2) { - Set s1 = transfer(nums1); - Set s2 = transfer(nums2); - s1.retainAll(s2); - int[] output = new int[s1.size()]; - int i = 0; - for (Integer e : s1) { - output[i++] = e; - } - return output; - } - - private Set transfer(int[] nums) { - Set s = new HashSet<>(); - for (int e : nums) { - s.add(e); - } - return s; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/Solution.py b/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/Solution.py deleted file mode 100644 index d4f458a4..00000000 --- a/leetcode/solution/0300-0399/0349.Intersection of Two Arrays/Solution.py +++ /dev/null @@ -1,4 +0,0 @@ -class Solution: - def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: - s1, s2 = set(nums1), set(nums2) - return list(s1 & s2) diff --git a/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md b/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md deleted file mode 100644 index fb49c1ff..00000000 --- a/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [350. Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii) - -[中文文档](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README.md) - -## Description - -

Given two arrays, write a function to compute their intersection.

- -

Example 1:

- -
-
-Input: nums1 = [1,2,2,1], nums2 = [2,2]
-
-Output: [2,2]
-
-
- -
- -

Example 2:

- -
-
-Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
-
-Output: [4,9]
- -
- -

Note:

- -
    -
  • Each element in the result should appear as many times as it shows in both arrays.
  • -
  • The result can be in any order.
  • -
- -

Follow up:

- -
    -
  • What if the given array is already sorted? How would you optimize your algorithm?
  • -
  • What if nums1's size is small compared to nums2's size? Which algorithm is better?
  • -
  • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/Solution.js b/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/Solution.js deleted file mode 100644 index ba798e4e..00000000 --- a/leetcode/solution/0300-0399/0350.Intersection of Two Arrays II/Solution.js +++ /dev/null @@ -1,12 +0,0 @@ -const intersect = function (nums1, nums2) { - let arr = []; - while (nums2.length > 0) { - let tmp = nums2.pop(); - if (nums1.indexOf(tmp) > -1) { - let indexTmp = nums1.indexOf(tmp); - nums1.splice(indexTmp, 1); - arr.push(tmp); - } - } - return arr; -}; diff --git a/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md b/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md deleted file mode 100644 index ac02747b..00000000 --- a/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [354. Russian Doll Envelopes](https://leetcode.com/problems/russian-doll-envelopes) - -[中文文档](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md) - -## Description - -

You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope.

- -

What is the maximum number of envelopes can you Russian doll? (put one inside other)

- -

Note:
- -Rotation is not allowed.

- -

Example:

- -
- -
-
-Input: [[5,4],[6,4],[6,7],[2,3]]
-
-Output: 3 
-
-Explanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).
-
-
- -
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxEnvelopes(self, envelopes: List[List[int]]) -> int: - if not envelopes: - return 0 - envelopes.sort(key=lambda x: (x[0], -x[1])) - nums = [x[1] for x in envelopes] - n = len(nums) - dp = [1] * n - res = 1 - for i in range(1, n): - for j in range(i): - if nums[j] < nums[i]: - dp[i] = max(dp[i], dp[j] + 1) - res = max(res, dp[i]) - return res -``` - -### **Java** - -```java -class Solution { - public int maxEnvelopes(int[][] envelopes) { - int n; - if (envelopes == null || (n = envelopes.length) == 0) return 0; - Arrays.sort(envelopes, (a, b) -> { - return a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]; - }); - int[] dp = new int[n]; - Arrays.fill(dp, 1); - int res = 1; - for (int i = 1; i < n; ++i) { - for (int j = 0; j < i; ++j) { - if (envelopes[j][1] < envelopes[i][1]) { - dp[i] = Math.max(dp[i], dp[j] + 1); - } - } - res = Math.max(res, dp[i]); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/Solution.py b/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/Solution.py deleted file mode 100644 index 64d5f159..00000000 --- a/leetcode/solution/0300-0399/0354.Russian Doll Envelopes/Solution.py +++ /dev/null @@ -1,15 +0,0 @@ -class Solution: - def maxEnvelopes(self, envelopes: List[List[int]]) -> int: - if not envelopes: - return 0 - envelopes.sort(key=lambda x: (x[0], -x[1])) - nums = [x[1] for x in envelopes] - n = len(nums) - dp = [1] * n - res = 1 - for i in range(1, n): - for j in range(i): - if nums[j] < nums[i]: - dp[i] = max(dp[i], dp[j] + 1) - res = max(res, dp[i]) - return res diff --git a/leetcode/solution/0300-0399/0355.Design Twitter/README_EN.md b/leetcode/solution/0300-0399/0355.Design Twitter/README_EN.md deleted file mode 100644 index 0677dacc..00000000 --- a/leetcode/solution/0300-0399/0355.Design Twitter/README_EN.md +++ /dev/null @@ -1,103 +0,0 @@ -# [355. Design Twitter](https://leetcode.com/problems/design-twitter) - -[中文文档](/solution/0300-0399/0355.Design%20Twitter/README.md) - -## Description - -

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the following methods:

- -

- -

    - -
  1. postTweet(userId, tweetId): Compose a new tweet.
  2. - -
  3. getNewsFeed(userId): 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.
  4. - -
  5. follow(followerId, followeeId): Follower follows a followee.
  6. - -
  7. unfollow(followerId, followeeId): Follower unfollows a followee.
  8. - -
- -

- -

Example: - -

-
-Twitter twitter = new Twitter();
-
-
-
-// User 1 posts a new tweet (id = 5).
-
-twitter.postTweet(1, 5);
-
-
-
-// User 1's news feed should return a list with 1 tweet id -> [5].
-
-twitter.getNewsFeed(1);
-
-
-
-// User 1 follows user 2.
-
-twitter.follow(1, 2);
-
-
-
-// User 2 posts a new tweet (id = 6).
-
-twitter.postTweet(2, 6);
-
-
-
-// User 1's news feed should return a list with 2 tweet ids -> [6, 5].
-
-// Tweet id 6 should precede tweet id 5 because it is posted after tweet id 5.
-
-twitter.getNewsFeed(1);
-
-
-
-// User 1 unfollows user 2.
-
-twitter.unfollow(1, 2);
-
-
-
-// User 1's news feed should return a list with 1 tweet id -> [5],
-
-// since user 1 is no longer following user 2.
-
-twitter.getNewsFeed(1);
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0367.Valid Perfect Square/README_EN.md b/leetcode/solution/0300-0399/0367.Valid Perfect Square/README_EN.md deleted file mode 100644 index 2a8340d0..00000000 --- a/leetcode/solution/0300-0399/0367.Valid Perfect Square/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [367. Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square) - -[中文文档](/solution/0300-0399/0367.Valid%20Perfect%20Square/README.md) - -## Description - -

Given a positive integer num, write a function which returns True if num is a perfect square else False.

- -

Note: Do not use any built-in library function such as sqrt.

- -

Example 1:

- -
- -
-
-Input: 16
-
-Output: true
-
-
- -
- -

Example 2:

- -
-
-Input: 14
-
-Output: false
-
-
- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0371.Sum of Two Integers/README_EN.md b/leetcode/solution/0300-0399/0371.Sum of Two Integers/README_EN.md deleted file mode 100644 index eb2d1008..00000000 --- a/leetcode/solution/0300-0399/0371.Sum of Two Integers/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [371. Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers) - -[中文文档](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README.md) - -## Description - -

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

- -
- -

Example 1:

- -
-
-Input: a = 1, b = 2
-
-Output: 3
-
-
- -
- -

Example 2:

- -
-
-Input: a = -2, b = 3
-
-Output: 1
-
-
- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md b/leetcode/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md deleted file mode 100644 index 2915a019..00000000 --- a/leetcode/solution/0300-0399/0374.Guess Number Higher or Lower/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [374. Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower) - -[中文文档](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README.md) - -## Description - -

We are playing the Guess Game. The game is as follows:

- -

I pick a number from 1 to n. You have to guess which number I picked.

- -

Every time you guess wrong, I'll tell you whether the number is higher or lower.

- -

You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):

- -
-
--1 : My number is lower
-
- 1 : My number is higher
-
- 0 : Congrats! You got it!
-
-
- -

Example :

- -
- -
-
-Input: n = 10, pick = 6
-
-Output: 6
-
-
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md b/leetcode/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md deleted file mode 100644 index 4b81c82e..00000000 --- a/leetcode/solution/0300-0399/0376.Wiggle Subsequence/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [376. Wiggle Subsequence](https://leetcode.com/problems/wiggle-subsequence) - -[中文文档](/solution/0300-0399/0376.Wiggle%20Subsequence/README.md) - -## Description - -

A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a wiggle sequence.

- -

For example, [1,7,4,9,2,5] is a wiggle sequence because the differences (6,-3,5,-7,3) are alternately positive and negative. In contrast, [1,4,7,2,5] and [1,7,4,5,5] are not wiggle sequences, the first because its first two differences are positive and the second because its last difference is zero.

- -

Given a sequence of integers, return the length of the longest subsequence that is a wiggle sequence. A subsequence is obtained by deleting some number of elements (eventually, also zero) from the original sequence, leaving the remaining elements in their original order.

- -

Example 1:

- -
-
-Input: [1,7,4,9,2,5]
-
-Output: 6
-
-Explanation: The entire sequence is a wiggle sequence.
- -
- -

Example 2:

- -
-
-Input: [1,17,5,10,13,15,10,5,16,8]
-
-Output: 7
-
-Explanation: There are several subsequences that achieve this length. One is [1,17,10,13,10,16,8].
- -
- -

Example 3:

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

Follow up:
- -Can you do it in O(n) time?

- -
- -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0377.Combination Sum IV/README_EN.md b/leetcode/solution/0300-0399/0377.Combination Sum IV/README_EN.md deleted file mode 100644 index 8b409c52..00000000 --- a/leetcode/solution/0300-0399/0377.Combination Sum IV/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [377. Combination Sum IV](https://leetcode.com/problems/combination-sum-iv) - -[中文文档](/solution/0300-0399/0377.Combination%20Sum%20IV/README.md) - -## Description - -

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

- -

Example:

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

 

- -

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

- -

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

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md b/leetcode/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md deleted file mode 100644 index e6b12046..00000000 --- a/leetcode/solution/0300-0399/0378.Kth Smallest Element in a Sorted Matrix/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [378. Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix) - -[中文文档](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README.md) - -## Description - -

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.

- -

- -Note that it is the kth smallest element in the sorted order, not the kth distinct element. - -

- -

Example: - -

-
-matrix = [
-
-   [ 1,  5,  9],
-
-   [10, 11, 13],
-
-   [12, 13, 15]
-
-],
-
-k = 8,
-
-
-
-return 13.
-
-
- -

- -

Note:
- -You may assume k is always valid, 1 ≤ k ≤ n2.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md b/leetcode/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md deleted file mode 100644 index 24c0af97..00000000 --- a/leetcode/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [380. Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1) - -[中文文档]() - -## Description - -

Design a data structure that supports all following operations in average O(1) time.

- -

- -

    - -
  1. insert(val): Inserts an item val to the set if not already present.
  2. - -
  3. remove(val): Removes an item val from the set if present.
  4. - -
  5. getRandom: Returns a random element from current set of elements. Each element must have the same probability of being returned.
  6. - -
- -

- -

Example: - -

-
-// Init an empty set.
-
-RandomizedSet randomSet = new RandomizedSet();
-
-
-
-// Inserts 1 to the set. Returns true as 1 was inserted successfully.
-
-randomSet.insert(1);
-
-
-
-// Returns false as 2 does not exist in the set.
-
-randomSet.remove(2);
-
-
-
-// Inserts 2 to the set, returns true. Set now contains [1,2].
-
-randomSet.insert(2);
-
-
-
-// getRandom should return either 1 or 2 randomly.
-
-randomSet.getRandom();
-
-
-
-// Removes 1 from the set, returns true. Set now contains [2].
-
-randomSet.remove(1);
-
-
-
-// 2 was already in the set, so return false.
-
-randomSet.insert(2);
-
-
-
-// Since 2 is the only number in the set, getRandom always return 2.
-
-randomSet.getRandom();
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md b/leetcode/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md deleted file mode 100644 index 3c135eab..00000000 --- a/leetcode/solution/0300-0399/0381.Insert Delete GetRandom O(1) - Duplicates allowed/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [381. Insert Delete GetRandom O(1) - Duplicates allowed](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed) - -[中文文档]() - -## Description - -

Design a data structure that supports all following operations in average O(1) time.

- -Note: Duplicate elements are allowed. - -

- -

    - -
  1. insert(val): Inserts an item val to the collection.
  2. - -
  3. remove(val): Removes an item val from the collection if present.
  4. - -
  5. getRandom: Returns a random element from current collection of elements. The probability of each element being returned is linearly related to the number of same value the collection contains.
  6. - -
- -

- -

Example: - -

-
-// Init an empty collection.
-
-RandomizedCollection collection = new RandomizedCollection();
-
-
-
-// Inserts 1 to the collection. Returns true as the collection did not contain 1.
-
-collection.insert(1);
-
-
-
-// Inserts another 1 to the collection. Returns false as the collection contained 1. Collection now contains [1,1].
-
-collection.insert(1);
-
-
-
-// Inserts 2 to the collection, returns true. Collection now contains [1,1,2].
-
-collection.insert(2);
-
-
-
-// getRandom should return 1 with the probability 2/3, and returns 2 with the probability 1/3.
-
-collection.getRandom();
-
-
-
-// Removes 1 from the collection, returns true. Collection now contains [1,2].
-
-collection.remove(1);
-
-
-
-// getRandom should return 1 and 2 both equally likely.
-
-collection.getRandom();
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0383.Ransom Note/README_EN.md b/leetcode/solution/0300-0399/0383.Ransom Note/README_EN.md deleted file mode 100644 index 3114a511..00000000 --- a/leetcode/solution/0300-0399/0383.Ransom Note/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [383. Ransom Note](https://leetcode.com/problems/ransom-note) - -[中文文档](/solution/0300-0399/0383.Ransom%20Note/README.md) - -## Description - -

- -Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom - -note can be constructed from the magazines ; otherwise, it will return false. - -

- -

- -Each letter in the magazine string can only be used once in your ransom note. - -

- -

Note:
- -You may assume that both strings contain only lowercase letters. - -

- -
-
-canConstruct("a", "b") -> false
-
-canConstruct("aa", "ab") -> false
-
-canConstruct("aa", "aab") -> true
-
-
- -## Solutions - - - -### **Python3** - -```python -class Solution: - def canConstruct(self, ransomNote: str, magazine: str) -> bool: - chars = {} - for i in magazine: - chars[i] = chars.get(i, 0) + 1 - for i in ransomNote: - if not chars.get(i): - return False - chars[i] -= 1 - return True -``` - -### **Java** - -```java -class Solution { - public boolean canConstruct(String ransomNote, String magazine) { - int[] chars = new int[26]; - for (int i = 0, n = magazine.length(); i < n; ++i) { - int idx = magazine.charAt(i) - 'a'; - ++chars[idx]; - } - for (int i = 0, n = ransomNote.length(); i < n; ++i) { - int idx = ransomNote.charAt(i) - 'a'; - if (chars[idx] == 0) return false; - --chars[idx]; - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0383.Ransom Note/Solution.py b/leetcode/solution/0300-0399/0383.Ransom Note/Solution.py deleted file mode 100644 index 98fc3644..00000000 --- a/leetcode/solution/0300-0399/0383.Ransom Note/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def canConstruct(self, ransomNote: str, magazine: str) -> bool: - chars = {} - for i in magazine: - chars[i] = chars.get(i, 0) + 1 - for i in ransomNote: - if not chars.get(i): - return False - chars[i] -= 1 - return True diff --git a/leetcode/solution/0300-0399/0384.Shuffle an Array/README_EN.md b/leetcode/solution/0300-0399/0384.Shuffle an Array/README_EN.md deleted file mode 100644 index da4ce943..00000000 --- a/leetcode/solution/0300-0399/0384.Shuffle an Array/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [384. Shuffle an Array](https://leetcode.com/problems/shuffle-an-array) - -[中文文档](/solution/0300-0399/0384.Shuffle%20an%20Array/README.md) - -## Description - -

Shuffle a set of numbers without duplicates. - -

- -

Example: - -

-
-// Init an array with set 1, 2, and 3.
-
-int[] nums = {1,2,3};
-
-Solution solution = new Solution(nums);
-
-
-
-// Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally likely to be returned.
-
-solution.shuffle();
-
-
-
-// Resets the array back to its original configuration [1,2,3].
-
-solution.reset();
-
-
-
-// Returns the random shuffling of array [1,2,3].
-
-solution.shuffle();
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0384.Shuffle an Array/Solution.js b/leetcode/solution/0300-0399/0384.Shuffle an Array/Solution.js deleted file mode 100644 index 75184bbf..00000000 --- a/leetcode/solution/0300-0399/0384.Shuffle an Array/Solution.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @param {number[]} nums - */ -const Solution = function (nums) { - this.nums = nums || []; -}; - -/** - * Resets the array to its original configuration and return it. - * @return {number[]} - */ -Solution.prototype.reset = function () { - return this.nums; -}; - -/** - * Returns a random shuffling of the array. - * @return {number[]} - */ -Solution.prototype.shuffle = function () { - let a = this.nums.slice(); - for (let i = 0; i < a.length; i++) { - let rand = Math.floor(Math.random() * (a.length - i)) + i; - let tmp = a[i]; - a[i] = a[rand]; - a[rand] = tmp; - } - return a; -}; - -/** - * Your Solution object will be instantiated and called as such: - * var obj = Object.create(Solution).createNew(nums) - * var param_1 = obj.reset() - * var param_2 = obj.shuffle() - */ diff --git a/leetcode/solution/0300-0399/0387.First Unique Character in a String/README_EN.md b/leetcode/solution/0300-0399/0387.First Unique Character in a String/README_EN.md deleted file mode 100644 index 068f841d..00000000 --- a/leetcode/solution/0300-0399/0387.First Unique Character in a String/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [387. First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string) - -[中文文档](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md) - -## Description - -

- -Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. - -

- -

Examples: - -

-
-s = "leetcode"
-
-return 0.
-
-
-
-s = "loveleetcode",
-
-return 2.
-
-
- -

- -

- -Note: You may assume the string contain only lowercase letters. - -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def firstUniqChar(self, s: str) -> int: - chars = {} - for ch in s: - ch = ord(ch) - chars[ch] = chars.get(ch, 0) + 1 - for i, ch in enumerate(s): - ch = ord(ch) - if chars[ch] == 1: - return i - return -1 -``` - -### **Java** - -```java -class Solution { - public int firstUniqChar(String s) { - Map chars = new HashMap<>(26); - int n = s.length(); - for (int i = 0; i < n; ++i) { - char ch = s.charAt(i); - chars.put(ch, chars.getOrDefault(ch, 0) + 1); - } - for (int i = 0; i < n; ++i) { - char ch = s.charAt(i); - if (chars.get(ch) == 1) return i; - } - return -1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.cpp b/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.cpp deleted file mode 100644 index fc930c5a..00000000 --- a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.cpp +++ /dev/null @@ -1,23 +0,0 @@ -class Solution { -public: - int firstUniqChar(string s) { - vector cnts(26, 0), pos(26, s.size()) ; - - - for (int i = s.size()-1; i >= 0; --i) - { - int index = s[i] - 'a' ; - cnts[index]++ ; - pos[index] = i ; - } - - int p = s.size() ; - for (int i = 0; i < 26; ++i) - { - if (cnts[i] == 1 && pos[i] < p) - p = pos[i] ; - } - - return p != s.size()? p: -1 ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.js b/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.js deleted file mode 100644 index 3af11946..00000000 --- a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.js +++ /dev/null @@ -1,48 +0,0 @@ -const firstUniqChar2 = function (s) { - let arr = {}; - for (let i = 0; i < s.length; i++) { - // console.log(arr[s[i]]); - if (arr[s[i]]) { - arr[s[i]]++; - } else { - arr[s[i]] = 1; - } - } - let keys = Object.keys(arr); - for (let i = 0; i < keys.length; i++) { - if (arr[keys[i]] !== 1) { - keys.splice(i, 1); - i--; - } - } - for (let i = 0; i < s.length; i++) { - for (let j = 0; j < keys.length; j++) { - if (s[i] === keys[j]) { - return i; - } - } - } - return -1; -}; - -const firstUniqChar = function (s) { - let hashTable = {}; - let arr = []; - - for (let i = 0; i < s.length; i++) { - let c = s.charAt(i); - if (!hashTable.hasOwnProperty(c)) { - hashTable[c] = i; - arr.push(i); - } else { - if (hashTable[c] !== null) { - let val = hashTable[c]; - let index = arr.indexOf(val); - arr.splice(index, 1); - hashTable[c] = null; - } - } - } - - return arr.length ? arr[0] : -1; -}; diff --git a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.py b/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.py deleted file mode 100644 index d1b411ab..00000000 --- a/leetcode/solution/0300-0399/0387.First Unique Character in a String/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def firstUniqChar(self, s: str) -> int: - chars = {} - for ch in s: - ch = ord(ch) - chars[ch] = chars.get(ch, 0) + 1 - for i, ch in enumerate(s): - ch = ord(ch) - if chars[ch] == 1: - return i - return -1 diff --git a/leetcode/solution/0300-0399/0392.Is Subsequence/README_EN.md b/leetcode/solution/0300-0399/0392.Is Subsequence/README_EN.md deleted file mode 100644 index a00a45e1..00000000 --- a/leetcode/solution/0300-0399/0392.Is Subsequence/README_EN.md +++ /dev/null @@ -1,97 +0,0 @@ -# [392. Is Subsequence](https://leetcode.com/problems/is-subsequence) - -[中文文档](/solution/0300-0399/0392.Is%20Subsequence/README.md) - -## Description - -

- -Given a string s and a string t, check if s is subsequence of t. - -

- -

- -You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (<=100). - -

- -

- -A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not). - -

- -

Example 1:
- -s = "abc", t = "ahbgdc" - -

- -

- -Return true. - -

- -

Example 2:
- -s = "axc", t = "ahbgdc" - -

- -

- -Return false. - -

- -

Follow up:
- -If there are lots of incoming S, say S1, S2, ... , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?

- -

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

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def isSubsequence(self, s: str, t: str) -> bool: - m, n = len(s), len(t) - i = j = 0 - while i < m and j < n: - if s[i] == t[j]: - i += 1 - j += 1 - return i == m -``` - -### **Java** - -```java -class Solution { - public boolean isSubsequence(String s, String t) { - int m = s.length(), n = t.length(); - int i = 0, j = 0; - while (i < m && j < n) { - if (s.charAt(i) == t.charAt(j)) { - ++i; - } - ++j; - } - return i == m; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0392.Is Subsequence/Solution.py b/leetcode/solution/0300-0399/0392.Is Subsequence/Solution.py deleted file mode 100644 index 6c7bbb68..00000000 --- a/leetcode/solution/0300-0399/0392.Is Subsequence/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def isSubsequence(self, s: str, t: str) -> bool: - m, n = len(s), len(t) - i = j = 0 - while i < m and j < n: - if s[i] == t[j]: - i += 1 - j += 1 - return i == m diff --git a/leetcode/solution/0300-0399/0394.Decode String/README_EN.md b/leetcode/solution/0300-0399/0394.Decode String/README_EN.md deleted file mode 100644 index 785472f9..00000000 --- a/leetcode/solution/0300-0399/0394.Decode String/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [394. Decode String](https://leetcode.com/problems/decode-string) - -[中文文档](/solution/0300-0399/0394.Decode%20String/README.md) - -## Description - -

Given an encoded string, return its decoded string.

- -

The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.

- -

You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.

- -

Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won't be input like 3a or 2[4].

- -

Examples:

- -
-s = "3[a]2[bc]", return "aaabcbc".
-s = "3[a2[c]]", return "accaccacc".
-s = "2[abc]3[cd]ef", return "abcabccdcdcdef".
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0300-0399/0394.Decode String/Solution.py b/leetcode/solution/0300-0399/0394.Decode String/Solution.py deleted file mode 100644 index 9f6f7e26..00000000 --- a/leetcode/solution/0300-0399/0394.Decode String/Solution.py +++ /dev/null @@ -1,42 +0,0 @@ -class Solution(object): - def decodeString(self, s): - """ - :type s: str - :rtype: str - """ - def deco(s): - if '[' not in s and ']' not in s: - return s - i = j = 0 - ans = '' - count = '' - while i < len(s): - if s[i].isdigit(): - count += s[i] - i += 1 - elif s[i].isalpha(): - ans += s[i] - i += 1 - elif s[i] == '[': - j = i + 1 - zuo = 0 - while j < len(s): - if s[j] == '[': - zuo += 1 - j += 1 - elif s[j] == ']': - if zuo != 0: - zuo -= 1 - j += 1 - else: - if not count: - ans += deco(s[i + 1:j]) - else: - ans += int(count) * deco(s[i + 1:j]) - count = '' - i = j + 1 - break - else: - j += 1 - return ans - return deco(s) diff --git a/leetcode/solution/0300-0399/0397.Integer Replacement/README_EN.md b/leetcode/solution/0300-0399/0397.Integer Replacement/README_EN.md deleted file mode 100644 index de7b028e..00000000 --- a/leetcode/solution/0300-0399/0397.Integer Replacement/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [397. Integer Replacement](https://leetcode.com/problems/integer-replacement) - -[中文文档](/solution/0300-0399/0397.Integer%20Replacement/README.md) - -## Description - -

- -Given a positive integer n and you can do operations as follow: - -

- -

- -

    - -
  1. If n is even, replace n with n/2.
  2. - -
  3. If n is odd, you can replace n with either n + 1 or n - 1.
  4. - -
- -

- -

- -What is the minimum number of replacements needed for n to become 1? - -

- -

- -

Example 1: - -

-
-Input:
-
-8
-
-
-
-Output:
-
-3
-
-
-
-Explanation:
-
-8 -> 4 -> 2 -> 1
-
-
- -

- -

Example 2: - -

-
-Input:
-
-7
-
-
-
-Output:
-
-4
-
-
-
-Explanation:
-
-7 -> 8 -> 4 -> 2 -> 1
-
-or
-
-7 -> 6 -> 3 -> 2 -> 1
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0400.Nth Digit/README_EN.md b/leetcode/solution/0400-0499/0400.Nth Digit/README_EN.md deleted file mode 100644 index 7182ab80..00000000 --- a/leetcode/solution/0400-0499/0400.Nth Digit/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [400. Nth Digit](https://leetcode.com/problems/nth-digit) - -[中文文档](/solution/0400-0499/0400.Nth%20Digit/README.md) - -## Description - -

Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...

- -

Note:
- -n is positive and will fit within the range of a 32-bit signed integer (n < 231). - -

- -

Example 1: - -

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

- -

Example 2: - -

-
-Input:
-
-11
-
-
-
-Output:
-
-0
-
-
-
-Explanation:
-
-The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0401.Binary Watch/README_EN.md b/leetcode/solution/0400-0499/0401.Binary Watch/README_EN.md deleted file mode 100644 index f8aaf151..00000000 --- a/leetcode/solution/0400-0499/0401.Binary Watch/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [401. Binary Watch](https://leetcode.com/problems/binary-watch) - -[中文文档](/solution/0400-0499/0401.Binary%20Watch/README.md) - -## Description - -

A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).

- -

Each LED represents a zero or one, with the least significant bit on the right.

- - - -

For example, the above binary watch reads "3:25".

- -

Given a non-negative integer n which represents the number of LEDs that are currently on, return all possible times the watch could represent.

- -

Example: - -

Input: n = 1
Return: ["1:00", "2:00", "4:00", "8:00", "0:01", "0:02", "0:04", "0:08", "0:16", "0:32"]
- -

- -

Note:
- -

    - -
  • The order of output does not matter.
  • - -
  • The hour must not contain a leading zero, for example "01:00" is not valid, it should be "1:00".
  • - -
  • The minute must be consist of two digits and may contain a leading zero, for example "10:2" is not valid, it should be "10:02".
  • - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0402.Remove K Digits/README_EN.md b/leetcode/solution/0400-0499/0402.Remove K Digits/README_EN.md deleted file mode 100644 index 5970e31d..00000000 --- a/leetcode/solution/0400-0499/0402.Remove K Digits/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [402. Remove K Digits](https://leetcode.com/problems/remove-k-digits) - -[中文文档](/solution/0400-0499/0402.Remove%20K%20Digits/README.md) - -## Description - -

Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. - -

- -

Note:
- -

    - -
  • The length of num is less than 10002 and will be ≥ k.
  • - -
  • The given num does not contain any leading zero.
  • - -
- - - -

- -

Example 1: - -

-
-Input: num = "1432219", k = 3
-
-Output: "1219"
-
-Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
-
-
- -

- -

Example 2: - -

-
-Input: num = "10200", k = 1
-
-Output: "200"
-
-Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
-
-
- -

- -

Example 3: - -

-
-Input: num = "10", k = 2
-
-Output: "0"
-
-Explanation: Remove all the digits from the number and it is left with nothing which is 0.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md b/leetcode/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md deleted file mode 100644 index 9e169155..00000000 --- a/leetcode/solution/0400-0499/0404.Sum of Left Leaves/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [404. Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) - -[中文文档](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README.md) - -## Description - -

Find the sum of all left leaves in a given binary tree.

- -

Example: - -

-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-
-
-There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md b/leetcode/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md deleted file mode 100644 index c10915a9..00000000 --- a/leetcode/solution/0400-0499/0405.Convert a Number to Hexadecimal/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [405. Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) - -[中文文档](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README.md) - -## Description - -

- -Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. - -

- -

Note: - -

    - -
  1. All letters in hexadecimal (a-f) must be in lowercase.
  2. - -
  3. The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character '0'; otherwise, the first character in the hexadecimal string will not be the zero character.
  4. - -
  5. The given number is guaranteed to fit within the range of a 32-bit signed integer.
  6. - -
  7. You must not use any method provided by the library which converts/formats the number to hex directly.
  8. - -
- -

- -

Example 1: - -

-
-Input:
-
-26
-
-
-
-Output:
-
-"1a"
-
-
- -

- -

Example 2: - -

-
-Input:
-
--1
-
-
-
-Output:
-
-"ffffffff"
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md b/leetcode/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md deleted file mode 100644 index 9286d74c..00000000 --- a/leetcode/solution/0400-0499/0406.Queue Reconstruction by Height/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [406. Queue Reconstruction by Height](https://leetcode.com/problems/queue-reconstruction-by-height) - -[中文文档](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README.md) - -## Description - -

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue.

- -

Note:
- -The number of people is less than 1,100.

- -  - -

Example

- -
-
-Input:
-
-[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
-
-
-
-Output:
-
-[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0409.Longest Palindrome/README_EN.md b/leetcode/solution/0400-0499/0409.Longest Palindrome/README_EN.md deleted file mode 100644 index 77c4bf0b..00000000 --- a/leetcode/solution/0400-0499/0409.Longest Palindrome/README_EN.md +++ /dev/null @@ -1,84 +0,0 @@ -# [409. Longest Palindrome](https://leetcode.com/problems/longest-palindrome) - -[中文文档](/solution/0400-0499/0409.Longest%20Palindrome/README.md) - -## Description - -

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.

- -

This is case sensitive, for example "Aa" is not considered a palindrome here.

- -

Note:
- -Assume the length of given string will not exceed 1,010. - -

- -

Example: - -

-
-Input:
-
-"abccccdd"
-
-
-
-Output:
-
-7
-
-
-
-Explanation:
-
-One longest palindrome that can be built is "dccaccd", whose length is 7.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def longestPalindrome(self, s: str) -> int: - res = [0] * 128 - for ch in s: - res[ord(ch)] += 1 - odd_cnt, n = 0, len(s) - for e in res: - odd_cnt += (e % 2) - return n if odd_cnt == 0 else n - odd_cnt + 1 -``` - -### **Java** - -```java -class Solution { - public int longestPalindrome(String s) { - int[] res = new int[128]; - int n = s.length(); - for (int i = 0; i < n; ++i) { - res[s.charAt(i)]++; - } - int oddCnt = 0; - for (int e : res) { - oddCnt += (e % 2); - } - return oddCnt == 0 ? n : n - oddCnt + 1; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0409.Longest Palindrome/Solution.py b/leetcode/solution/0400-0499/0409.Longest Palindrome/Solution.py deleted file mode 100644 index 518c1d59..00000000 --- a/leetcode/solution/0400-0499/0409.Longest Palindrome/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def longestPalindrome(self, s: str) -> int: - res = [0] * 128 - for ch in s: - res[ord(ch)] += 1 - odd_cnt, n = 0, len(s) - for e in res: - odd_cnt += (e % 2) - return n if odd_cnt == 0 else n - odd_cnt + 1 diff --git a/leetcode/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md b/leetcode/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md deleted file mode 100644 index 7538954e..00000000 --- a/leetcode/solution/0400-0499/0410.Split Array Largest Sum/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [410. Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum) - -[中文文档](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README.md) - -## Description - -

Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays. - -

- -

Note:
- -If n is the length of array, assume the following constraints are satisfied: - -

    - -
  • 1 ≤ n ≤ 1000
  • - -
  • 1 ≤ m ≤ min(50, n)
  • - -
- -

- -

Examples: - -

-
-Input:
-
-nums = [7,2,5,10,8]
-
-m = 2
-
-
-
-Output:
-
-18
-
-
-
-Explanation:
-
-There are four ways to split nums into two subarrays.
-
-The best way is to split it into [7,2,5] and [10,8],
-
-where the largest sum among the two subarrays is only 18.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0414.Third Maximum Number/README_EN.md b/leetcode/solution/0400-0499/0414.Third Maximum Number/README_EN.md deleted file mode 100644 index 3c247e4a..00000000 --- a/leetcode/solution/0400-0499/0414.Third Maximum Number/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [414. Third Maximum Number](https://leetcode.com/problems/third-maximum-number) - -[中文文档](/solution/0400-0499/0414.Third%20Maximum%20Number/README.md) - -## Description - -

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).

- -

Example 1:
- -

-
-Input: [3, 2, 1]
-
-
-
-Output: 1
-
-
-
-Explanation: The third maximum is 1.
-
-
- -

- -

Example 2:
- -

-
-Input: [1, 2]
-
-
-
-Output: 2
-
-
-
-Explanation: The third maximum does not exist, so the maximum (2) is returned instead.
-
-
- -

- -

Example 3:
- -

-
-Input: [2, 2, 3, 1]
-
-
-
-Output: 1
-
-
-
-Explanation: Note that the third maximum here means the third maximum distinct number.
-
-Both numbers with value 2 are both considered as second maximum.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0415.Add Strings/README_EN.md b/leetcode/solution/0400-0499/0415.Add Strings/README_EN.md deleted file mode 100644 index e5ca4572..00000000 --- a/leetcode/solution/0400-0499/0415.Add Strings/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [415. Add Strings](https://leetcode.com/problems/add-strings) - -[中文文档](/solution/0400-0499/0415.Add%20Strings/README.md) - -## Description - -

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.

- -

Note: - -

    - -
  1. The length of both num1 and num2 is < 5100.
  2. - -
  3. Both num1 and num2 contains only digits 0-9.
  4. - -
  5. Both num1 and num2 does not contain any leading zero.
  6. - -
  7. You must not use any built-in BigInteger library or convert the inputs to integer directly.
  8. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md b/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md deleted file mode 100644 index 41293026..00000000 --- a/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [421. Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array) - -[中文文档](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README.md) - -## Description - -

Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.

- -

Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.

- -

Could you do this in O(n) runtime?

- -

Example:

- -
-
-Input: [3, 10, 5, 25, 2, 8]
-
-
-
-Output: 28
-
-
-
-Explanation: The maximum result is 5 ^ 25 = 28.
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/Solution.py b/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/Solution.py deleted file mode 100644 index be25295a..00000000 --- a/leetcode/solution/0400-0499/0421.Maximum XOR of Two Numbers in an Array/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -class Solution: - def findMaximumXOR(self, nums: List[int]) -> int: - max = 0 - mask = 0 - for i in range(30, -1, -1): - current = 1 << i - # 期望的二进制前缀 - mask = mask ^ current - # 在当前前缀下, 数组内的前缀位数所有情况集合 - _set = set() - for num in nums: - _set.add(num & mask) - # 期望最终异或值的从右数第i位为1, 再根据异或运算的特性推算假设是否成立 - flag = max | current - for prefix in _set: - if prefix ^ flag in _set: - max = flag - break - return max \ No newline at end of file diff --git a/leetcode/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md b/leetcode/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md deleted file mode 100644 index a95f7c82..00000000 --- a/leetcode/solution/0400-0499/0424.Longest Repeating Character Replacement/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [424. Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement) - -[中文文档](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README.md) - -## Description - -

Given a string s that consists of only uppercase English letters, you can perform at most k operations on that string.

- -

In one operation, you can choose any character of the string and change it to any other uppercase English character.

- -

Find the length of the longest sub-string containing all repeating letters you can get after performing the above operations.

- -

Note:
- -Both the string's length and k will not exceed 104.

- -

Example 1:

- -
-
-Input:
-
-s = "ABAB", k = 2
-
-
-
-Output:
-
-4
-
-
-
-Explanation:
-
-Replace the two 'A's with two 'B's or vice versa.
-
-
- -

 

- -

Example 2:

- -
-
-Input:
-
-s = "AABABBA", k = 1
-
-
-
-Output:
-
-4
-
-
-
-Explanation:
-
-Replace the one 'A' in the middle with 'B' and form "AABBBBA".
-
-The substring "BBBB" has the longest repeating letters, which is 4.
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md b/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md deleted file mode 100644 index 5f064fbd..00000000 --- a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/README_EN.md +++ /dev/null @@ -1,190 +0,0 @@ -# [426. Convert Binary Search Tree to Sorted Doubly Linked List](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) - -[中文文档](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md) - -## Description - -

Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place.

- -

You can think of the left and right pointers as synonymous to the predecessor and successor pointers in a doubly-linked list. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element.

- -

We want to do the transformation in place. After the transformation, the left pointer of the tree node should point to its predecessor, and the right pointer should point to its successor. You should return the pointer to the smallest element of the linked list.

- -

 

-

Example 1:

- -![](./images/bstdlloriginalbst.png) - -
-Input: root = [4,2,5,1,3]
-
- -![](./images/bstdllreturndll.png) - -
-Output: [1,2,3,4,5]
-
-Explanation: The figure below shows the transformed BST. The solid line indicates the successor relationship, while the dashed line means the predecessor relationship.
-
-
- -![](./images/bstdllreturnbst.png) - -

Example 2:

- -
-Input: root = [2,1,3]
-Output: [1,2,3]
-
- -

Example 3:

- -
-Input: root = []
-Output: []
-Explanation: Input is an empty tree. Output is also an empty Linked List.
-
- -

Example 4:

- -
-Input: root = [1]
-Output: [1]
-
- -

 

-

Constraints:

- -
    -
  • -1000 <= Node.val <= 1000
  • -
  • Node.left.val < Node.val < Node.right.val
  • -
  • All values of Node.val are unique.
  • -
  • 0 <= Number of Nodes <= 2000
  • -
- -## Solutions - - - -### **Python3** - -```python -""" -# Definition for a Node. -class Node: - def __init__(self, val, left=None, right=None): - self.val = val - self.left = left - self.right = right -""" -class Solution: - def treeToDoublyList(self, root: 'Node') -> 'Node': - def dfs(cur): - if cur is None: - return - dfs(cur.left) - if self.pre is None: - self.head = cur - else: - self.pre.right = cur - cur.left = self.pre - self.pre = cur - dfs(cur.right) - if root is None: - return None - self.head = self.pre = None - dfs(root) - self.head.left = self.pre - self.pre.right = self.head - return self.head -``` - -### **Java** - -```java -/* -// Definition for a Node. -class Node { - public int val; - public Node left; - public Node right; - - public Node() {} - - public Node(int _val) { - val = _val; - } - - public Node(int _val,Node _left,Node _right) { - val = _val; - left = _left; - right = _right; - } -}; -*/ - -class Solution { - private Node head; - private Node pre; - - public Node treeToDoublyList(Node root) { - if (root == null) return null; - dfs(root); - head.left = pre; - pre.right = head; - return head; - } - - private void dfs(Node cur) { - if (cur == null) return; - dfs(cur.left); - if (pre == null) head = cur; - else pre.right = cur; - cur.left = pre; - pre = cur; - dfs(cur.right); - } -} -``` - -### **JavaScript** - -```js -/** - * // Definition for a Node. - * function Node(val,left,right) { - * this.val = val; - * this.left = left; - * this.right = right; - * }; - */ -/** - * @param {Node} root - * @return {Node} - */ -var treeToDoublyList = function (root) { - function dfs(cur) { - if (!cur) return; - dfs(cur.left); - if (!pre) head = cur; - else pre.right = cur; - cur.left = pre; - pre = cur; - dfs(cur.right); - } - if (!root) return null; - let head, pre; - dfs(root); - head.left = pre; - pre.right = head; - return head; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.js b/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.js deleted file mode 100644 index 8edd9c4f..00000000 --- a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * // Definition for a Node. - * function Node(val,left,right) { - * this.val = val; - * this.left = left; - * this.right = right; - * }; - */ -/** - * @param {Node} root - * @return {Node} - */ -var treeToDoublyList = function (root) { - function dfs(cur) { - if (!cur) return; - dfs(cur.left); - if (!pre) head = cur; - else pre.right = cur; - cur.left = pre; - pre = cur; - dfs(cur.right); - } - if (!root) return null; - let head, pre; - dfs(root); - head.left = pre; - pre.right = head; - return head; -}; diff --git a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.py b/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.py deleted file mode 100644 index 3b425cca..00000000 --- a/leetcode/solution/0400-0499/0426.Convert Binary Search Tree to Sorted Doubly Linked List/Solution.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -# Definition for a Node. -class Node: - def __init__(self, val, left=None, right=None): - self.val = val - self.left = left - self.right = right -""" -class Solution: - def treeToDoublyList(self, root: 'Node') -> 'Node': - def dfs(cur): - if cur is None: - return - dfs(cur.left) - if self.pre is None: - self.head = cur - else: - self.pre.right = cur - cur.left = self.pre - self.pre = cur - dfs(cur.right) - if root is None: - return None - self.head = self.pre = None - dfs(root) - self.head.left = self.pre - self.pre.right = self.head - return self.head diff --git a/leetcode/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md b/leetcode/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md deleted file mode 100644 index bf91bb43..00000000 --- a/leetcode/solution/0400-0499/0429.N-ary Tree Level Order Traversal/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [429. N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal) - -[中文文档](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README.md) - -## Description - -

Given an n-ary tree, return the level order traversal of its nodes' values.

- -

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

- -

 

-

Example 1:

- -![](./images/narytreeexample.png) - -
-Input: root = [1,null,3,2,4,null,5,6]
-Output: [[1],[3,2,4],[5,6]]
-
- -

Example 2:

- -![](./images/sample_4_964.png) - -
-Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
-Output: [[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]
-
- -

 

-

Constraints:

- -
    -
  • The height of the n-ary tree is less than or equal to 1000
  • -
  • The total number of nodes is between [0, 10^4]
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md b/leetcode/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md deleted file mode 100644 index 7c89a2cc..00000000 --- a/leetcode/solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md +++ /dev/null @@ -1,113 +0,0 @@ -# [430. Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) - -[中文文档](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README.md) - -## Description - -

You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example below.

- -

Flatten the list so that all the nodes appear in a single-level, doubly linked list. You are given the head of the first level of the list.

- -

 

-

Example 1:

- -
-Input: head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
-Output: [1,2,3,7,8,11,12,9,10,4,5,6]
-Explanation:
-
-The multilevel linked list in the input is as follows:
- -![](./images/multilevellinkedlist.png) - -
-After flattening the multilevel linked list it becomes:
- -![](./images/multilevellinkedlistflattened.png) - -

Example 2:

- -
-Input: head = [1,2,null,3]
-Output: [1,3,2]
-Explanation:
-
-The input multilevel linked list is as follows:
-
-  1---2---NULL
-  |
-  3---NULL
-
- -

Example 3:

- -
-Input: head = []
-Output: []
-
- -

 

- -

How multilevel linked list is represented in test case:

- -

We use the multilevel linked list from Example 1 above:

- -
- 1---2---3---4---5---6--NULL
-         |
-         7---8---9---10--NULL
-             |
-             11--12--NULL
- -

The serialization of each level is as follows:

- -
-[1,2,3,4,5,6,null]
-[7,8,9,10,null]
-[11,12,null]
-
- -

To serialize all levels together we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:

- -
-[1,2,3,4,5,6,null]
-[null,null,7,8,9,10,null]
-[null,11,12,null]
-
- -

Merging the serialization of each level and removing trailing nulls we obtain:

- -
-[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
- -

 

-

Constraints:

- -
    -
  • Number of Nodes will not exceed 1000.
  • -
  • 1 <= Node.val <= 10^5
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0437.Path Sum III/README_EN.md b/leetcode/solution/0400-0499/0437.Path Sum III/README_EN.md deleted file mode 100644 index 9c0e5f2c..00000000 --- a/leetcode/solution/0400-0499/0437.Path Sum III/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [437. Path Sum III](https://leetcode.com/problems/path-sum-iii) - -[中文文档](/solution/0400-0499/0437.Path%20Sum%20III/README.md) - -## Description - -

You are given a binary tree in which each node contains an integer value.

- -

Find the number of paths that sum to a given value.

- -

The path does not need to start or end at the root or a leaf, but it must go downwards - -(traveling only from parent nodes to child nodes).

- -

The tree has no more than 1,000 nodes and the values are in the range -1,000,000 to 1,000,000. - -

Example: - -

-
-root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8
-
-
-
-      10
-
-     /  \
-
-    5   -3
-
-   / \    \
-
-  3   2   11
-
- / \   \
-
-3  -2   1
-
-
-
-Return 3. The paths that sum to 8 are:
-
-
-
-1.  5 -> 3
-
-2.  5 -> 2 -> 1
-
-3. -3 -> 11
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0441.Arranging Coins/README_EN.md b/leetcode/solution/0400-0499/0441.Arranging Coins/README_EN.md deleted file mode 100644 index 50361277..00000000 --- a/leetcode/solution/0400-0499/0441.Arranging Coins/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [441. Arranging Coins](https://leetcode.com/problems/arranging-coins) - -[中文文档](/solution/0400-0499/0441.Arranging%20Coins/README.md) - -## Description - -

You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.

- -

Given n, find the total number of full staircase rows that can be formed.

- -

n is a non-negative integer and fits within the range of a 32-bit signed integer.

- -

Example 1: - -

-
-n = 5
-
-
-
-The coins can form the following rows:
-
-¤
-
-¤ ¤
-
-¤ ¤
-
-
-
-Because the 3rd row is incomplete, we return 2.
-
-
- -

- -

Example 2: - -

-
-n = 8
-
-
-
-The coins can form the following rows:
-
-¤
-
-¤ ¤
-
-¤ ¤ ¤
-
-¤ ¤
-
-
-
-Because the 4th row is incomplete, we return 3.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def arrangeCoins(self, n: int) -> int: - return int(math.sqrt(2) * math.sqrt(n + 0.125) - 0.5) -``` - -### **Java** - -```java -class Solution { - public int arrangeCoins(int n) { - return (int) (Math.sqrt(2) * Math.sqrt(n + 0.125) - 0.5); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0441.Arranging Coins/Solution.py b/leetcode/solution/0400-0499/0441.Arranging Coins/Solution.py deleted file mode 100644 index d2eadf93..00000000 --- a/leetcode/solution/0400-0499/0441.Arranging Coins/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def arrangeCoins(self, n: int) -> int: - return int(math.sqrt(2) * math.sqrt(n + 0.125) - 0.5) diff --git a/leetcode/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md b/leetcode/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md deleted file mode 100644 index d29fa529..00000000 --- a/leetcode/solution/0400-0499/0442.Find All Duplicates in an Array/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [442. Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array) - -[中文文档](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README.md) - -## Description - -

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

- -

Find all the elements that appear twice in this array.

- -

Could you do it without extra space and in O(n) runtime?

- -

- -

Example:
- -

-
-Input:
-
-[4,3,2,7,8,2,3,1]
-
-
-
-Output:
-
-[2,3]
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0445.Add Two Numbers II/README_EN.md b/leetcode/solution/0400-0499/0445.Add Two Numbers II/README_EN.md deleted file mode 100644 index e25a6313..00000000 --- a/leetcode/solution/0400-0499/0445.Add Two Numbers II/README_EN.md +++ /dev/null @@ -1,53 +0,0 @@ -# [445. Add Two Numbers II](https://leetcode.com/problems/add-two-numbers-ii) - -[中文文档](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md) - -## Description - -

You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

- -

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

- -

Follow up:
- -What if you cannot modify the input lists? In other words, reversing the lists is not allowed. - -

- -

- -Example: - -

-
-Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)
-
-Output: 7 -> 8 -> 0 -> 7
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md b/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md deleted file mode 100644 index 5d13b8c7..00000000 --- a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [448. Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) - -[中文文档](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README.md) - -## Description - -

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

- -

Find all the elements of [1, n] inclusive that do not appear in this array.

- -

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

- -

Example: - -

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

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findDisappearedNumbers(self, nums: List[int]) -> List[int]: - for num in nums: - index = abs(num) - 1 - if nums[index] > 0: - nums[index] *= -1 - res = [] - for i, v in enumerate(nums): - if v > 0: - res.append(i + 1) - return res -``` - -### **Java** - -```java -class Solution { - public List findDisappearedNumbers(int[] nums) { - int n = nums.length; - for (int i = 0; i < n; ++i) { - int index = Math.abs(nums[i]) - 1; - if (nums[index] > 0) { - nums[index] *= -1; - } - } - List res = new ArrayList<>(); - for (int i = 0; i < n; ++i) { - if (nums[i] > 0) { - res.add(i + 1); - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.cpp b/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.cpp deleted file mode 100644 index 244bc4d4..00000000 --- a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.cpp +++ /dev/null @@ -1,24 +0,0 @@ -class Solution { -public: - vector findDisappearedNumbers(vector& nums) { - int len = nums.size(); - vector ans; - if(len == 0)return ans; - - int index; - for(int i = 0;i 0) - nums[index] = -nums[index]; - } - - - for(int i = 0;i 0) - ans.push_back(i+1); - } - - return ans; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.py b/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.py deleted file mode 100644 index 9aa66d92..00000000 --- a/leetcode/solution/0400-0499/0448.Find All Numbers Disappeared in an Array/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def findDisappearedNumbers(self, nums: List[int]) -> List[int]: - for num in nums: - index = abs(num) - 1 - if nums[index] > 0: - nums[index] *= -1 - res = [] - for i, v in enumerate(nums): - if v > 0: - res.append(i + 1) - return res diff --git a/leetcode/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md b/leetcode/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md deleted file mode 100644 index 22833e5c..00000000 --- a/leetcode/solution/0400-0499/0449.Serialize and Deserialize BST/README_EN.md +++ /dev/null @@ -1,37 +0,0 @@ -# [449. Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst) - -[中文文档](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README.md) - -## Description - -

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

- -

Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary search tree can be serialized to a string and this string can be deserialized to the original tree structure.

- -

The encoded string should be as compact as possible.

- -

Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0450.Delete Node in a BST/README_EN.md b/leetcode/solution/0400-0499/0450.Delete Node in a BST/README_EN.md deleted file mode 100644 index aa7448db..00000000 --- a/leetcode/solution/0400-0499/0450.Delete Node in a BST/README_EN.md +++ /dev/null @@ -1,105 +0,0 @@ -# [450. Delete Node in a BST](https://leetcode.com/problems/delete-node-in-a-bst) - -[中文文档](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README.md) - -## Description - -

Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.

- -

Basically, the deletion can be divided into two stages: - -

    - -
  1. Search for a node to remove.
  2. - -
  3. If the node is found, delete the node.
  4. - -
- -

- -

Note: Time complexity should be O(height of tree).

- -

Example: - -

-
-root = [5,3,6,2,4,null,7]
-
-key = 3
-
-
-
-    5
-
-   / \
-
-  3   6
-
- / \   \
-
-2   4   7
-
-
-
-Given key to delete is 3. So we find the node with value 3 and delete it.
-
-
-
-One valid answer is [5,4,6,2,null,null,7], shown in the following BST.
-
-
-
-    5
-
-   / \
-
-  4   6
-
- /     \
-
-2       7
-
-
-
-Another valid answer is [5,2,6,null,4,null,7].
-
-
-
-    5
-
-   / \
-
-  2   6
-
-   \   \
-
-    4   7
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md b/leetcode/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md deleted file mode 100644 index 425b78a1..00000000 --- a/leetcode/solution/0400-0499/0452.Minimum Number of Arrows to Burst Balloons/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [452. Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons) - -[中文文档](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README.md) - -## Description - -

There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104 balloons.

- -

An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.

- -

Example:

- -
-
-Input:
-
-[[10,16], [2,8], [1,6], [7,12]]
-
-
-
-Output:
-
-2
-
-
-
-Explanation:
-
-One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md b/leetcode/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md deleted file mode 100644 index b299d747..00000000 --- a/leetcode/solution/0400-0499/0453.Minimum Moves to Equal Array Elements/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [453. Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) - -[中文文档](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README.md) - -## Description - -

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.

- -

Example: - -

-
-Input:
-
-[1,2,3]
-
-
-
-Output:
-
-3
-
-
-
-Explanation:
-
-Only three moves are needed (remember each move increments two elements):
-
-
-
-[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0454.4Sum II/README_EN.md b/leetcode/solution/0400-0499/0454.4Sum II/README_EN.md deleted file mode 100644 index 482c7718..00000000 --- a/leetcode/solution/0400-0499/0454.4Sum II/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [454. 4Sum II](https://leetcode.com/problems/4sum-ii) - -[中文文档](/solution/0400-0499/0454.4Sum%20II/README.md) - -## Description - -

Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.

- -

To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the range of -228 to 228 - 1 and the result is guaranteed to be at most 231 - 1.

- -

Example:

- -
-
-Input:
-
-A = [ 1, 2]
-
-B = [-2,-1]
-
-C = [-1, 2]
-
-D = [ 0, 2]
-
-
-
-Output:
-
-2
-
-
-
-Explanation:
-
-The two tuples are:
-
-1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0
-
-2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0456.132 Pattern/README_EN.md b/leetcode/solution/0400-0499/0456.132 Pattern/README_EN.md deleted file mode 100644 index 9ca02501..00000000 --- a/leetcode/solution/0400-0499/0456.132 Pattern/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [456. 132 Pattern](https://leetcode.com/problems/132-pattern) - -[中文文档](/solution/0400-0499/0456.132%20Pattern/README.md) - -## Description - -

- -Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such - -that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a 132 pattern in the list.

- -

Note: n will be less than 15,000.

- -

Example 1:
- -

-
-Input: [1, 2, 3, 4]
-
-
-
-Output: False
-
-
-
-Explanation: There is no 132 pattern in the sequence.
-
-
- -

- -

Example 2:
- -

-
-Input: [3, 1, 4, 2]
-
-
-
-Output: True
-
-
-
-Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
-
-
- -

- -

Example 3:
- -

-
-Input: [-1, 3, 2, 0]
-
-
-
-Output: True
-
-
-
-Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0458.Poor Pigs/README_EN.md b/leetcode/solution/0400-0499/0458.Poor Pigs/README_EN.md deleted file mode 100644 index a43205ba..00000000 --- a/leetcode/solution/0400-0499/0458.Poor Pigs/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [458. Poor Pigs](https://leetcode.com/problems/poor-pigs) - -[中文文档](/solution/0400-0499/0458.Poor%20Pigs/README.md) - -## Description - -

There are 1000 buckets, one and only one of them is poisonous, while the rest are filled with water. They all look identical. If a pig drinks the poison it will die within 15 minutes. What is the minimum amount of pigs you need to figure out which bucket is poisonous within one hour?

- -

Answer this question, and write an algorithm for the general case.

- -

 

- -

General case:

- -

If there are n buckets and a pig drinking poison will die within m minutes, how many pigs (x) you need to figure out the poisonous bucket within p minutes? There is exactly one bucket with poison.

- -

 

- -

Note:

- -
    -
  1. A pig can be allowed to drink simultaneously on as many buckets as one would like, and the feeding takes no time.
  2. -
  3. After a pig has instantly finished drinking buckets, there has to be a cool down time of minutes. During this time, only observation is allowed and no feedings at all.
  4. -
  5. Any given bucket can be sampled an infinite number of times (by an unlimited number of pigs).
  6. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md b/leetcode/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md deleted file mode 100644 index 541887c3..00000000 --- a/leetcode/solution/0400-0499/0459.Repeated Substring Pattern/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [459. Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) - -[中文文档](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README.md) - -## Description - -

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.

- -

 

- -

Example 1:

- -
-
-Input: "abab"
-
-Output: True
-
-Explanation: It's the substring "ab" twice.
-
-
- -

Example 2:

- -
-
-Input: "aba"
-
-Output: False
-
-
- -

Example 3:

- -
-
-Input: "abcabcabcabc"
-
-Output: True
-
-Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)
-
-
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0461.Hamming Distance/README_EN.md b/leetcode/solution/0400-0499/0461.Hamming Distance/README_EN.md deleted file mode 100644 index fa299c2b..00000000 --- a/leetcode/solution/0400-0499/0461.Hamming Distance/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [461. Hamming Distance](https://leetcode.com/problems/hamming-distance) - -[中文文档](/solution/0400-0499/0461.Hamming%20Distance/README.md) - -## Description - -

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

- -

Given two integers x and y, calculate the Hamming distance.

- -

Note:
- -0 ≤ x, y < 231. - -

- -

Example: - -

-
-Input: x = 1, y = 4
-
-
-
-Output: 2
-
-
-
-Explanation:
-
-1   (0 0 0 1)
-
-4   (0 1 0 0)
-
-       ↑   ↑
-
-
-
-The above arrows point to positions where the corresponding bits are different.
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0461.Hamming Distance/Solution.js b/leetcode/solution/0400-0499/0461.Hamming Distance/Solution.js deleted file mode 100644 index 1caec84a..00000000 --- a/leetcode/solution/0400-0499/0461.Hamming Distance/Solution.js +++ /dev/null @@ -1,9 +0,0 @@ -const hammingDistance = function (x, y) { - let a = x ^ y; - a = a.toString(2); - let res = 0; - for (let i = 0; i < a.length; i++) { - res += a[i] === "1"; - } - return res; -}; diff --git a/leetcode/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md b/leetcode/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md deleted file mode 100644 index 0a4f2c8a..00000000 --- a/leetcode/solution/0400-0499/0462.Minimum Moves to Equal Array Elements II/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [462. Minimum Moves to Equal Array Elements II](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii) - -[中文文档](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README.md) - -## Description - -

Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1.

- -

You may assume the array's length is at most 10,000.

- -

Example: - -

-
-Input:
-
-[1,2,3]
-
-
-
-Output:
-
-2
-
-
-
-Explanation:
-
-Only two moves are needed (remember each move increments or decrements one element):
-
-
-
-[1,2,3]  =>  [2,2,3]  =>  [2,2,2]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0473.Matchsticks to Square/README_EN.md b/leetcode/solution/0400-0499/0473.Matchsticks to Square/README_EN.md deleted file mode 100644 index 45659406..00000000 --- a/leetcode/solution/0400-0499/0473.Matchsticks to Square/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [473. Matchsticks to Square](https://leetcode.com/problems/matchsticks-to-square) - -[中文文档](/solution/0400-0499/0473.Matchsticks%20to%20Square/README.md) - -## Description - -

Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.

- -

Your input will be several matchsticks the girl has, represented with their stick length. Your output will either be true or false, to represent whether you could make one square using all the matchsticks the little match girl has.

- -

Example 1:
- -

-
-Input: [1,1,2,2,2]
-
-Output: true
-
-
-
-Explanation: You can form a square with length 2, one side of the square came two sticks with length 1.
-
-
- -

- -

Example 2:
- -

-
-Input: [3,3,3,3,4]
-
-Output: false
-
-
-
-Explanation: You cannot find a way to form a square with all the matchsticks.
-
-
- -

- -

Note:
- -

    - -
  1. The length sum of the given matchsticks is in the range of 0 to 10^9. - -
  2. The length of the given matchstick array will not exceed 15.
  3. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0475.Heaters/README_EN.md b/leetcode/solution/0400-0499/0475.Heaters/README_EN.md deleted file mode 100644 index c529056c..00000000 --- a/leetcode/solution/0400-0499/0475.Heaters/README_EN.md +++ /dev/null @@ -1,74 +0,0 @@ -# [475. Heaters](https://leetcode.com/problems/heaters) - -[中文文档](/solution/0400-0499/0475.Heaters/README.md) - -## Description - -

Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.

- -

Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all houses could be covered by those heaters.

- -

So, your input will be the positions of houses and heaters seperately, and your expected output will be the minimum radius standard of heaters.

- -

Note:

- -
    -
  1. Numbers of houses and heaters you are given are non-negative and will not exceed 25000.
  2. -
  3. Positions of houses and heaters you are given are non-negative and will not exceed 10^9.
  4. -
  5. As long as a house is in the heaters' warm radius range, it can be warmed.
  6. -
  7. All the heaters follow your radius standard and the warm radius will the same.
  8. -
- -

 

- -

Example 1:

- -
-
-Input: [1,2,3],[2]
-
-Output: 1
-
-Explanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.
-
-
- -

 

- -

Example 2:

- -
-
-Input: [1,2,3,4],[1,4]
-
-Output: 1
-
-Explanation: The two heater was placed in the position 1 and 4. We need to use radius 1 standard, then all the houses can be warmed.
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0477.Total Hamming Distance/README_EN.md b/leetcode/solution/0400-0499/0477.Total Hamming Distance/README_EN.md deleted file mode 100644 index b7e81427..00000000 --- a/leetcode/solution/0400-0499/0477.Total Hamming Distance/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [477. Total Hamming Distance](https://leetcode.com/problems/total-hamming-distance) - -[中文文档](/solution/0400-0499/0477.Total%20Hamming%20Distance/README.md) - -## Description - -

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

- -

Now your job is to find the total Hamming distance between all pairs of the given numbers. - -

Example:
- -

-
-Input: 4, 14, 2
-
-
-
-Output: 6
-
-
-
-Explanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just
-
-showing the four bits relevant in this case). So the answer will be:
-
-HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.
-
-
- -

- -

Note:
- -

    - -
  1. Elements of the given array are in the range of 0 to 10^9 - -
  2. Length of the array will not exceed 10^4.
  3. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0483.Smallest Good Base/README_EN.md b/leetcode/solution/0400-0499/0483.Smallest Good Base/README_EN.md deleted file mode 100644 index 584f21aa..00000000 --- a/leetcode/solution/0400-0499/0483.Smallest Good Base/README_EN.md +++ /dev/null @@ -1,84 +0,0 @@ -# [483. Smallest Good Base](https://leetcode.com/problems/smallest-good-base) - -[中文文档](/solution/0400-0499/0483.Smallest%20Good%20Base/README.md) - -## Description - -

For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1.

- -

Now given a string representing n, you should return the smallest good base of n in string format.

- -

Example 1:

- -
-
-Input: "13"
-
-Output: "3"
-
-Explanation: 13 base 3 is 111.
-
-
- -

 

- -

Example 2:

- -
-
-Input: "4681"
-
-Output: "8"
-
-Explanation: 4681 base 8 is 11111.
-
-
- -

 

- -

Example 3:

- -
-
-Input: "1000000000000000000"
-
-Output: "999999999999999999"
-
-Explanation: 1000000000000000000 base 999999999999999999 is 11.
-
-
- -

 

- -

Note:

- -
    -
  1. The range of n is [3, 10^18].
  2. -
  3. The string representing n is always valid and will not have leading zeros.
  4. -
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md b/leetcode/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md deleted file mode 100644 index dee8df10..00000000 --- a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/README_EN.md +++ /dev/null @@ -1,103 +0,0 @@ -# [485. Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones) - -[中文文档](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README.md) - -## Description - -

Given a binary array, find the maximum number of consecutive 1s in this array.

- -

Example 1:
- -

-
-Input: [1,1,0,1,1,1]
-
-Output: 3
-
-Explanation: The first two digits or the last three digits are consecutive 1s.
-
-    The maximum number of consecutive 1s is 3.
-
-
- -

- -

Note: - -

    - -
  • The input array will only contain 0 and 1.
  • - -
  • The length of input array is a positive integer and will not exceed 10,000
  • - -
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findMaxConsecutiveOnes(self, nums: List[int]) -> int: - res = t = 0 - for num in nums: - if num == 1: - t += 1 - else: - res = max(res, t) - t = 0 - return max(res, t) -``` - -### **Java** - -```java -class Solution { - public int findMaxConsecutiveOnes(int[] nums) { - int res = 0, t = 0; - for (int num : nums) { - if (num == 1) { - ++t; - } else { - res = Math.max(res, t); - t = 0; - } - } - return Math.max(res, t); - } -} -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @return {number} - */ -var findMaxConsecutiveOnes = function (nums) { - let res = 0, - t = 0; - for (let num of nums) { - if (num == 1) { - ++t; - } else { - res = Math.max(res, t); - t = 0; - } - } - return Math.max(res, t); -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.js b/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.js deleted file mode 100644 index e5ac66d8..00000000 --- a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var findMaxConsecutiveOnes = function (nums) { - let res = 0, - t = 0; - for (let num of nums) { - if (num == 1) { - ++t; - } else { - res = Math.max(res, t); - t = 0; - } - } - return Math.max(res, t); -}; diff --git a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.py b/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.py deleted file mode 100644 index 8ee6ada1..00000000 --- a/leetcode/solution/0400-0499/0485.Max Consecutive Ones/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def findMaxConsecutiveOnes(self, nums: List[int]) -> int: - res = t = 0 - for num in nums: - if num == 1: - t += 1 - else: - res = max(res, t) - t = 0 - return max(res, t) diff --git a/leetcode/solution/0400-0499/0486.Predict the Winner/README_EN.md b/leetcode/solution/0400-0499/0486.Predict the Winner/README_EN.md deleted file mode 100644 index 6de3ac0a..00000000 --- a/leetcode/solution/0400-0499/0486.Predict the Winner/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [486. Predict the Winner](https://leetcode.com/problems/predict-the-winner) - -[中文文档](/solution/0400-0499/0486.Predict%20the%20Winner/README.md) - -## Description - -

Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all the scores have been chosen. The player with the maximum score wins.

- -

Given an array of scores, predict whether player 1 is the winner. You can assume each player plays to maximize his score.

- -

Example 1:
- -

-
-Input: [1, 5, 2]
-
-Output: False
-
-Explanation: Initially, player 1 can choose between 1 and 2. 
If he chooses 2 (or 1), then player 2 can choose from 1 (or 2) and 5. If player 2 chooses 5, then player 1 will be left with 1 (or 2).
So, final score of player 1 is 1 + 2 = 3, and player 2 is 5.
Hence, player 1 will never be the winner and you need to return False. - -
- -

- -

Example 2:
- -

-
-Input: [1, 5, 233, 7]
-
-Output: True
-
-Explanation: Player 1 first chooses 1. Then player 2 have to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.
Finally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win. - -
- -

- -

Note:
- -

    - -
  1. 1 <= length of the array <= 20.
  2. - -
  3. Any scores in the given array are non-negative integers and will not exceed 10,000,000.
  4. - -
  5. If the scores of both players are equal, then player 1 is still the winner.
  6. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md b/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md deleted file mode 100644 index 2550a69e..00000000 --- a/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/README_EN.md +++ /dev/null @@ -1,132 +0,0 @@ -# [487. Max Consecutive Ones II](https://leetcode.com/problems/max-consecutive-ones-ii) - -[中文文档](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README.md) - -## Description - -

-Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0. -

- -

Example 1:
-

-Input: [1,0,1,1,0]
-Output: 4
-Explanation: Flip the first zero will get the the maximum number of consecutive 1s.
-    After flipping, the maximum number of consecutive 1s is 4.
-
-

- -

Note: -

    -
  • The input array will only contain 0 and 1.
  • -
  • The length of input array is a positive integer and will not exceed 10,000
  • -
-

- -

Follow up:
-What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently? -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findMaxConsecutiveOnes(self, nums: List[int]) -> int: - n = len(nums) - prefix = [0] * n - suffix = [0] * n - res = 0 - for i in range(n): - if i == 0: - prefix[i] = nums[i] - else: - prefix[i] = 0 if nums[i] == 0 else prefix[i - 1] + 1 - res = max(res, prefix[i]) - - for i in range(n - 1, -1, -1): - if i == n - 1: - suffix[i] = nums[i] - else: - suffix[i] = 0 if nums[i] == 0 else suffix[i + 1] + 1 - - for i in range(n): - if nums[i] == 0: - t = 1 - if i > 0: - t += prefix[i - 1] - if i < n - 1: - t += suffix[i + 1] - res = max(res, t) - return res -``` - -### **Java** - -- Two Pointers, time complexity: O(n²), memory complexity: O(1) - -```java -class Solution { - public int findMaxConsecutiveOnes(int[] nums) { - int n = nums.length; - int res = 0; - for (int i = 0; i < n; ++i) { - int cnt = 1; - int j = i; - while (j < n && (cnt > 0 || nums[j] == 1)) { - if (nums[j] == 0) --cnt; - ++j; - } - res = Math.max(res, j - i); - } - return res; - } -} -``` - -- Prefix Array & Suffix Array, time complexity: O(n), memory complexity: O(n) - -```java -class Solution { - public int findMaxConsecutiveOnes(int[] nums) { - int n = nums.length; - - int[] prefix = new int[n]; - int[] suffix = new int[n]; - - int res = 0; - for (int i = 0; i < n; ++i) { - if (i == 0) prefix[0] = nums[0]; - else prefix[i] = nums[i] == 0 ? 0 : prefix[i - 1] + 1; - res = Math.max(res, prefix[i]); - } - - for (int i = n - 1; i >= 0; --i) { - if (i == n - 1) suffix[n - 1] = nums[n - 1]; - else suffix[i] = nums[i] == 0 ? 0 : suffix[i + 1] + 1; - } - - for (int i = 0; i < n; ++i) { - if (nums[i] == 0) { - int t = 1; - if (i > 0) t += prefix[i - 1]; - if (i < n - 1) t += suffix[i + 1]; - res = Math.max(res, t); - } - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/Solution.py b/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/Solution.py deleted file mode 100644 index 8871954c..00000000 --- a/leetcode/solution/0400-0499/0487.Max Consecutive Ones II/Solution.py +++ /dev/null @@ -1,28 +0,0 @@ -class Solution: - def findMaxConsecutiveOnes(self, nums: List[int]) -> int: - n = len(nums) - prefix = [0] * n - suffix = [0] * n - res = 0 - for i in range(n): - if i == 0: - prefix[i] = nums[i] - else: - prefix[i] = 0 if nums[i] == 0 else prefix[i - 1] + 1 - res = max(res, prefix[i]) - - for i in range(n - 1, -1, -1): - if i == n - 1: - suffix[i] = nums[i] - else: - suffix[i] = 0 if nums[i] == 0 else suffix[i + 1] + 1 - - for i in range(n): - if nums[i] == 0: - t = 1 - if i > 0: - t += prefix[i - 1] - if i < n - 1: - t += suffix[i + 1] - res = max(res, t) - return res diff --git a/leetcode/solution/0400-0499/0490.The Maze/README_EN.md b/leetcode/solution/0400-0499/0490.The Maze/README_EN.md deleted file mode 100644 index 403edd20..00000000 --- a/leetcode/solution/0400-0499/0490.The Maze/README_EN.md +++ /dev/null @@ -1,150 +0,0 @@ -# [490. The Maze](https://leetcode.com/problems/the-maze) - -[中文文档](/solution/0400-0499/0490.The%20Maze/README.md) - -## Description - -

There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

- -

Given the ball's start position, the destination and the maze, determine whether the ball could stop at the destination.

- -

The maze is represented by a binary 2D array. 1 means the wall and 0 means the empty space. You may assume that the borders of the maze are all walls. The start and destination coordinates are represented by row and column indexes.

- -

 

- -

Example 1:

- -
-Input 1: a maze represented by a 2D array
-
-0 0 1 0 0
-0 0 0 0 0
-0 0 0 1 0
-1 1 0 1 1
-0 0 0 0 0
-
-Input 2: start coordinate (rowStart, colStart) = (0, 4)
-Input 3: destination coordinate (rowDest, colDest) = (4, 4)
-
-Output: true
-
-Explanation: One possible way is : left -> down -> left -> down -> right -> down -> right.
-
- -![](./images/maze_1_example_1.png) - -

Example 2:

- -
-Input 1: a maze represented by a 2D array
-
-0 0 1 0 0
-0 0 0 0 0
-0 0 0 1 0
-1 1 0 1 1
-0 0 0 0 0
-
-Input 2: start coordinate (rowStart, colStart) = (0, 4)
-Input 3: destination coordinate (rowDest, colDest) = (3, 2)
-
-Output: false
-
-Explanation: There is no way for the ball to stop at the destination.
-
- -![](./images/maze_1_example_2.png) - -

 

- -

Note:

- -
    -
  1. There is only one ball and one destination in the maze.
  2. -
  3. Both the ball and the destination exist on an empty space, and they will not be at the same position initially.
  4. -
  5. The given maze does not contain border (like the red rectangle in the example pictures), but you could assume the border of the maze are all walls.
  6. -
  7. The maze contains at least 2 empty spaces, and both the width and height of the maze won't exceed 100.
  8. -
- -## Solutions - - - -### **Python3** - -DFS. - -```python -class Solution: - def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool: - def dfs(maze, start, destination): - if visited[start[0]][start[1]]: - return False - if start[0] == destination[0] and start[1] == destination[1]: - return True - visited[start[0]][start[1]] = True - l, r, u, d = start[1] - 1, start[1] + 1, start[0] - 1, start[0] + 1 - while l >= 0 and maze[start[0]][l] == 0: - l -= 1 - if dfs(maze, [start[0], l + 1], destination): - return True - while r < len(maze[0]) and maze[start[0]][r] == 0: - r += 1 - if dfs(maze, [start[0], r - 1], destination): - return True - while u >= 0 and maze[u][start[1]] == 0: - u -= 1 - if dfs(maze, [u + 1, start[1]], destination): - return True - while d < len(maze) and maze[d][start[1]] == 0: - d += 1 - if dfs(maze, [d - 1, start[1]], destination): - return True - return False - - visited = [[False for _ in maze[0]] for _ in maze] - return dfs(maze, start, destination) -``` - -### **Java** - -```java -class Solution { - private boolean[][] visited; - - public boolean hasPath(int[][] maze, int[] start, int[] destination) { - int m = maze.length, n = maze[0].length; - visited = new boolean[m][n]; - return dfs(maze, start, destination); - } - - private boolean dfs(int[][] maze, int[] start, int[] destination) { - if (visited[start[0]][start[1]]) return false; - if (start[0] == destination[0] && start[1] == destination[1]) return true; - visited[start[0]][start[1]] = true; - - int l = start[1] - 1, r = start[1] + 1, u = start[0] - 1, d = start[0] + 1; - - while (l >= 0 && maze[start[0]][l] == 0) --l; - if (dfs(maze, new int[]{start[0], l + 1}, destination)) return true; - - while (r < maze[0].length && maze[start[0]][r] == 0) ++r; - if (dfs(maze, new int[]{start[0], r - 1}, destination)) return true; - - while (u >= 0 && maze[u][start[1]] == 0) --u; - if (dfs(maze, new int[]{u + 1, start[1]}, destination)) return true; - - while (d < maze.length && maze[d][start[1]] == 0) ++d; - if (dfs(maze, new int[]{d - 1, start[1]}, destination)) return true; - - return false; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0490.The Maze/Solution.py b/leetcode/solution/0400-0499/0490.The Maze/Solution.py deleted file mode 100644 index b93dda9b..00000000 --- a/leetcode/solution/0400-0499/0490.The Maze/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -class Solution: - def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool: - def dfs(maze, start, destination): - if visited[start[0]][start[1]]: - return False - if start[0] == destination[0] and start[1] == destination[1]: - return True - visited[start[0]][start[1]] = True - l, r, u, d = start[1] - 1, start[1] + 1, start[0] - 1, start[0] + 1 - while l >= 0 and maze[start[0]][l] == 0: - l -= 1 - if dfs(maze, [start[0], l + 1], destination): - return True - while r < len(maze[0]) and maze[start[0]][r] == 0: - r += 1 - if dfs(maze, [start[0], r - 1], destination): - return True - while u >= 0 and maze[u][start[1]] == 0: - u -= 1 - if dfs(maze, [u + 1, start[1]], destination): - return True - while d < len(maze) and maze[d][start[1]] == 0: - d += 1 - if dfs(maze, [d - 1, start[1]], destination): - return True - return False - - visited = [[False for _ in maze[0]] for _ in maze] - return dfs(maze, start, destination) diff --git a/leetcode/solution/0400-0499/0492.Construct the Rectangle/README_EN.md b/leetcode/solution/0400-0499/0492.Construct the Rectangle/README_EN.md deleted file mode 100644 index 86d9f023..00000000 --- a/leetcode/solution/0400-0499/0492.Construct the Rectangle/README_EN.md +++ /dev/null @@ -1,97 +0,0 @@ -# [492. Construct the Rectangle](https://leetcode.com/problems/construct-the-rectangle) - -[中文文档](/solution/0400-0499/0492.Construct%20the%20Rectangle/README.md) - -## Description - -

- -For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

-
-1. The area of the rectangular web page you designed must equal to the given target area.
-
-
2. The width W should not be larger than the length L, which means L >= W. - -
3. The difference between length L and width W should be as small as possible. - -
- -You need to output the length L and the width W of the web page you designed in sequence. - -

- -

Example:
- -

-
-Input: 4
-
-Output: [2, 2]
-
-Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. 
-
-But according to requirement 2, [1,4] is illegal; according to requirement 3,  [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.
-
-
- -

- -

Note:
- -

    - -
  1. The given area won't exceed 10,000,000 and is a positive integer
  2. - -
  3. The web page's width and length you designed must be positive integers.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def constructRectangle(self, area: int) -> List[int]: - sr = int(math.sqrt(area)) - l = w = sr - while l <= area and w >= 1: - s = l * w - if s == area: - break - if s > area: - w -= 1 - else: - l += 1 - return [l, w] -``` - -### **Java** - -```java -class Solution { - public int[] constructRectangle(int area) { - int sr = (int) Math.sqrt(area); - int l = sr, w = sr; - while (l <= area && w >= 1) { - int s = l * w; - if (s == area) break; - if (s > area) --w; - else ++l; - } - return new int[]{l, w}; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0492.Construct the Rectangle/Solution.py b/leetcode/solution/0400-0499/0492.Construct the Rectangle/Solution.py deleted file mode 100644 index 9ab073aa..00000000 --- a/leetcode/solution/0400-0499/0492.Construct the Rectangle/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def constructRectangle(self, area: int) -> List[int]: - sr = int(math.sqrt(area)) - l = w = sr - while l <= area and w >= 1: - s = l * w - if s == area: - break - if s > area: - w -= 1 - else: - l += 1 - return [l, w] \ No newline at end of file diff --git a/leetcode/solution/0400-0499/0494.Target Sum/README_EN.md b/leetcode/solution/0400-0499/0494.Target Sum/README_EN.md deleted file mode 100644 index a3f349b6..00000000 --- a/leetcode/solution/0400-0499/0494.Target Sum/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [494. Target Sum](https://leetcode.com/problems/target-sum) - -[中文文档](/solution/0400-0499/0494.Target%20Sum/README.md) - -## Description - -

- -You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol. - -

- -

Find out how many ways to assign symbols to make sum of integers equal to target S. - -

- -

Example 1:
- -

-
-Input: nums is [1, 1, 1, 1, 1], S is 3. 
-
-Output: 5
-
-Explanation: 
-
-
-
--1+1+1+1+1 = 3
-
-+1-1+1+1+1 = 3
-
-+1+1-1+1+1 = 3
-
-+1+1+1-1+1 = 3
-
-+1+1+1+1-1 = 3
-
-
-
-There are 5 ways to assign symbols to make the sum of nums be target 3.
-
-
- -

- -

Note:
- -

    - -
  1. The length of the given array is positive and will not exceed 20.
  2. - -
  3. The sum of elements in the given array will not exceed 1000.
  4. - -
  5. Your output answer is guaranteed to be fitted in a 32-bit integer.
  6. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0400-0499/0496.Next Greater Element I/README_EN.md b/leetcode/solution/0400-0499/0496.Next Greater Element I/README_EN.md deleted file mode 100644 index e8775007..00000000 --- a/leetcode/solution/0400-0499/0496.Next Greater Element I/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [496. Next Greater Element I](https://leetcode.com/problems/next-greater-element-i) - -[中文文档](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md) - -## Description - -

- -You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. - -

- -

- -The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number. - -

- -

Example 1:
- -

-
-Input: nums1 = [4,1,2], nums2 = [1,3,4,2].
-
-Output: [-1,3,-1]
-
-Explanation:
-
-    For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.
-
-    For number 1 in the first array, the next greater number for it in the second array is 3.
-
-    For number 2 in the first array, there is no next greater number for it in the second array, so output -1.
-
-
- -

- -

Example 2:
- -

-
-Input: nums1 = [2,4], nums2 = [1,2,3,4].
-
-Output: [3,-1]
-
-Explanation:
-
-    For number 2 in the first array, the next greater number for it in the second array is 3.
-
-    For number 4 in the first array, there is no next greater number for it in the second array, so output -1.
-
-
- -

- -

Note:
- -

    - -
  1. All elements in nums1 and nums2 are unique.
  2. - -
  3. The length of both nums1 and nums2 would not exceed 1000.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0500.Keyboard Row/README_EN.md b/leetcode/solution/0500-0599/0500.Keyboard Row/README_EN.md deleted file mode 100644 index f4443892..00000000 --- a/leetcode/solution/0500-0599/0500.Keyboard Row/README_EN.md +++ /dev/null @@ -1,56 +0,0 @@ -# [500. Keyboard Row](https://leetcode.com/problems/keyboard-row) - -[中文文档](/solution/0500-0599/0500.Keyboard%20Row/README.md) - -## Description - -

Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

- -

 

- -![](./images/keyboard.png) - -  - -

Example:

- -
-
-Input: ["Hello", "Alaska", "Dad", "Peace"]
-
-Output: ["Alaska", "Dad"]
-
-
- -

 

- -

Note:

- -
    -
  1. You may use one character in the keyboard more than once.
  2. -
  3. You may assume the input string will only contain letters of alphabet.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0500.Keyboard Row/Solution.py b/leetcode/solution/0500-0599/0500.Keyboard Row/Solution.py deleted file mode 100644 index dcc86221..00000000 --- a/leetcode/solution/0500-0599/0500.Keyboard Row/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -class Solution: - def findWords(self, words): - """ - :type words: List[str] - :rtype: List[str] - """ - - Rows={"q":0, "w":0, "e":0, "r":0, "t":0, "y":0, "u":0, "i":0, "o":0, "p":0, "a":1, "s":1, "d":1, "f":1, "g":1, "h":1, "j":1, "k":1, "l":1, "z":2, "x":2, "c":2, "v":2, "b":2, "n":2, "m":2} - - Final = [] - for each in words : - - if all([Rows[each[0].lower()]==Rows[ch] for ch in each.lower()]) : - Final.append(each) - - return Final diff --git a/leetcode/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md b/leetcode/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md deleted file mode 100644 index 7a59ce7e..00000000 --- a/leetcode/solution/0500-0599/0501.Find Mode in Binary Search Tree/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [501. Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree) - -[中文文档](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README.md) - -## Description - -

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.

- -

Assume a BST is defined as follows:

- -
    -
  • The left subtree of a node contains only nodes with keys less than or equal to the node's key.
  • -
  • The right subtree of a node contains only nodes with keys greater than or equal to the node's key.
  • -
  • Both the left and right subtrees must also be binary search trees.
  • -
- -

 

- -

For example:
- -Given BST [1,null,2,2],

- -
-
-   1
-
-    \
-
-     2
-
-    /
-
-   2
-
-
- -

 

- -

return [2].

- -

Note: If a tree has more than one mode, you can return them in any order.

- -

Follow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0502.IPO/README_EN.md b/leetcode/solution/0500-0599/0502.IPO/README_EN.md deleted file mode 100644 index bf801719..00000000 --- a/leetcode/solution/0500-0599/0502.IPO/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [502. IPO](https://leetcode.com/problems/ipo) - -[中文文档](/solution/0500-0599/0502.IPO/README.md) - -## Description - -

- -Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects. - -

- -

- -You are given several projects. For each project i, it has a pure profit Pi and a minimum capital of Ci is needed to start the corresponding project. Initially, you have W capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital. - -

- -

- -To sum up, pick a list of at most k distinct projects from given projects to maximize your final capital, and output your final maximized capital. - -

- -

Example 1:
- -

-
-Input: k=2, W=0, Profits=[1,2,3], Capital=[0,1,1].
-
-
-
-Output: 4
-
-
-
-Explanation: Since your initial capital is 0, you can only start the project indexed 0.
-
-             After finishing it you will obtain profit 1 and your capital becomes 1.
-
-             With capital 1, you can either start the project indexed 1 or the project indexed 2.
-
-             Since you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.
-
-             Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4.
-
-
- -

- -

Note:
- -

    - -
  1. You may assume all numbers in the input are non-negative integers.
  2. - -
  3. The length of Profits array and Capital array will not exceed 50,000.
  4. - -
  5. The answer is guaranteed to fit in a 32-bit signed integer.
  6. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0503.Next Greater Element II/README_EN.md b/leetcode/solution/0500-0599/0503.Next Greater Element II/README_EN.md deleted file mode 100644 index ce7de57e..00000000 --- a/leetcode/solution/0500-0599/0503.Next Greater Element II/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [503. Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii) - -[中文文档](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md) - -## Description - -

- -Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, output -1 for this number. - -

- -

Example 1:
- -

-
-Input: [1,2,1]
-
-Output: [2,-1,2]
-
-Explanation: The first 1's next greater number is 2; 
The number 2 can't find next greater number;
The second 1's next greater number needs to search circularly, which is also 2. - -
- -

- -

Note: - -The length of given array won't exceed 10000. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0504.Base 7/README_EN.md b/leetcode/solution/0500-0599/0504.Base 7/README_EN.md deleted file mode 100644 index 4c4e82c7..00000000 --- a/leetcode/solution/0500-0599/0504.Base 7/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [504. Base 7](https://leetcode.com/problems/base-7) - -[中文文档](/solution/0500-0599/0504.Base%207/README.md) - -## Description - -

Given an integer, return its base 7 string representation.

- -

Example 1:
- -

-
-Input: 100
-
-Output: "202"
-
-
- -

- -

Example 2:
- -

-
-Input: -7
-
-Output: "-10"
-
-
- -

- -

Note: - -The input will be in range of [-1e7, 1e7]. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0506.Relative Ranks/README_EN.md b/leetcode/solution/0500-0599/0506.Relative Ranks/README_EN.md deleted file mode 100644 index e08255af..00000000 --- a/leetcode/solution/0500-0599/0506.Relative Ranks/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [506. Relative Ranks](https://leetcode.com/problems/relative-ranks) - -[中文文档](/solution/0500-0599/0506.Relative%20Ranks/README.md) - -## Description - -

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

- -

Example 1:
- -

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

- -

Note:
- -

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

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0507.Perfect Number/README_EN.md b/leetcode/solution/0500-0599/0507.Perfect Number/README_EN.md deleted file mode 100644 index 50878cdf..00000000 --- a/leetcode/solution/0500-0599/0507.Perfect Number/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [507. Perfect Number](https://leetcode.com/problems/perfect-number) - -[中文文档](/solution/0500-0599/0507.Perfect%20Number/README.md) - -## Description - -

We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. - -

- -Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not. - -

- -

Example:
- -

-
-Input: 28
-
-Output: True
-
-Explanation: 28 = 1 + 2 + 4 + 7 + 14
-
-
- -

- -

Note: - -The input number n will not exceed 100,000,000. (1e8) - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md b/leetcode/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md deleted file mode 100644 index 772fbbcf..00000000 --- a/leetcode/solution/0500-0599/0508.Most Frequent Subtree Sum/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [508. Most Frequent Subtree Sum](https://leetcode.com/problems/most-frequent-subtree-sum) - -[中文文档](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README.md) - -## Description - -

- -Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). So what is the most frequent subtree sum value? If there is a tie, return all the values with the highest frequency in any order. - -

- -

Examples 1
- -Input: - -

-
-  5
-
- /  \
-
-2   -3
-
-
- -return [2, -3, 4], since all the values happen only once, return all of them in any order. - -

- -

Examples 2
- -Input: - -

-
-  5
-
- /  \
-
-2   -5
-
-
- -return [2], since 2 happens twice, however -5 only occur once. - -

- -

Note: - -You may assume the sum of values in any subtree is in the range of 32-bit signed integer. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0509.Fibonacci Number/README_EN.md b/leetcode/solution/0500-0599/0509.Fibonacci Number/README_EN.md deleted file mode 100644 index 0349a48c..00000000 --- a/leetcode/solution/0500-0599/0509.Fibonacci Number/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number) - -[中文文档](/solution/0500-0599/0509.Fibonacci%20Number/README.md) - -## Description - -

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

- -
-
-F(0) = 0,   F(1) = 1
-
-F(N) = F(N - 1) + F(N - 2), for N > 1.
-
-
- -

Given N, calculate F(N).

- -

 

- -

Example 1:

- -
-
-Input: 2
-
-Output: 1
-
-Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
-
-
- -

Example 2:

- -
-
-Input: 3
-
-Output: 2
-
-Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
-
-
- -

Example 3:

- -
-
-Input: 4
-
-Output: 3
-
-Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
-
-
- -

 

- -

Note:

- -

0 ≤ N ≤ 30.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.cpp b/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.cpp deleted file mode 100644 index 1ee39425..00000000 --- a/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.cpp +++ /dev/null @@ -1,9 +0,0 @@ -class Solution { -public: - int fib(int N) { - int a[2] = {0, 1} ; - for (int i = 2; i <= N; ++i) - a[i&1] += a[i&1^1] ; - return a[N&1] ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.js b/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.js deleted file mode 100644 index 6c8a55dd..00000000 --- a/leetcode/solution/0500-0599/0509.Fibonacci Number/Solution.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @param {number} N - * @return {number} - */ - -/** - * Author: Mcnwork2018 - */ - -let preResult = {}; -var fib = function (N) { - if (N === 0) return 0; - if (N === 1) return 1; - if (preResult[N]) { - return preResult[N]; - } else { - preResult[N] = fib(N - 1) + fib(N - 2); - } - return fib(N - 1) + fib(N - 2); -}; diff --git a/leetcode/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md b/leetcode/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md deleted file mode 100644 index 2294ded6..00000000 --- a/leetcode/solution/0500-0599/0513.Find Bottom Left Tree Value/README_EN.md +++ /dev/null @@ -1,97 +0,0 @@ -# [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value) - -[中文文档](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README.md) - -## Description - -

- -Given a binary tree, find the leftmost value in the last row of the tree. - -

- -

Example 1:
- -

-
-Input:
-
-
-
-    2
-
-   / \
-
-  1   3
-
-
-
-Output:
-
-1
-
-
- -

- -

Example 2:
- -

-
-Input:
-
-
-
-        1
-
-       / \
-
-      2   3
-
-     /   / \
-
-    4   5   6
-
-       /
-
-      7
-
-
-
-Output:
-
-7
-
-
- -

- -

Note: - -You may assume the tree (i.e., the given root node) is not NULL. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md b/leetcode/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md deleted file mode 100644 index fc3a3e3d..00000000 --- a/leetcode/solution/0500-0599/0515.Find Largest Value in Each Tree Row/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [515. Find Largest Value in Each Tree Row](https://leetcode.com/problems/find-largest-value-in-each-tree-row) - -[中文文档](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README.md) - -## Description - -

You need to find the largest value in each row of a binary tree.

- -

Example:
- -

-
-Input: 
-
-
-
-          1
-
-         / \
-
-        3   2
-
-       / \   \  
-
-      5   3   9 
-
-
-
-Output: [1, 3, 9]
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0518.Coin Change 2/README_EN.md b/leetcode/solution/0500-0599/0518.Coin Change 2/README_EN.md deleted file mode 100644 index 859233df..00000000 --- a/leetcode/solution/0500-0599/0518.Coin Change 2/README_EN.md +++ /dev/null @@ -1,92 +0,0 @@ -# [518. Coin Change 2](https://leetcode.com/problems/coin-change-2) - -[中文文档](/solution/0500-0599/0518.Coin%20Change%202/README.md) - -## Description - -

You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin.

- -
    - -
- -

 

- -

Example 1:

- -
-
-Input: amount = 5, coins = [1, 2, 5]
-
-Output: 4
-
-Explanation: there are four ways to make up the amount:
-
-5=5
-
-5=2+2+1
-
-5=2+1+1+1
-
-5=1+1+1+1+1
-
-
- -

Example 2:

- -
-
-Input: amount = 3, coins = [2]
-
-Output: 0
-
-Explanation: the amount of 3 cannot be made up just with coins of 2.
-
-
- -

Example 3:

- -
-
-Input: amount = 10, coins = [10] 
-
-Output: 1
-
-
- -

 

- -

Note:

- -

You can assume that

- -
    -
  • 0 <= amount <= 5000
  • -
  • 1 <= coin <= 5000
  • -
  • the number of coins is less than 500
  • -
  • the answer is guaranteed to fit into signed 32-bit integer
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0520.Detect Capital/README_EN.md b/leetcode/solution/0500-0599/0520.Detect Capital/README_EN.md deleted file mode 100644 index 8e658000..00000000 --- a/leetcode/solution/0500-0599/0520.Detect Capital/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [520. Detect Capital](https://leetcode.com/problems/detect-capital) - -[中文文档](/solution/0500-0599/0520.Detect%20Capital/README.md) - -## Description - -

Given a word, you need to judge whether the usage of capitals in it is right or not.

- -

We define the usage of capitals in a word to be right when one of the following cases holds:

- -
    -
  1. All letters in this word are capitals, like "USA".
  2. -
  3. All letters in this word are not capitals, like "leetcode".
  4. -
  5. Only the first letter in this word is capital, like "Google".
  6. -
- -Otherwise, we define that this word doesn't use capitals in a right way. - -

 

- -

Example 1:

- -
-
-Input: "USA"
-
-Output: True
-
-
- -

 

- -

Example 2:

- -
-
-Input: "FlaG"
-
-Output: False
-
-
- -

 

- -

Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md b/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md deleted file mode 100644 index e55a4d3f..00000000 --- a/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [521. Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i) - -[中文文档](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README.md) - -## Description - -

- -Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. - -The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. - -

- -

- -A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string. - -

- -

- -The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1. - -

- -

Example 1:
- -

-
-Input: "aba", "cdc"
-
-Output: 3
-
-Explanation: The longest uncommon subsequence is "aba" (or "cdc"), 
because "aba" is a subsequence of "aba",
but not a subsequence of any other strings in the group of two strings. - -
- -

- -

Note: - -

    - -
  1. Both strings' lengths will not exceed 100.
  2. - -
  3. Only letters from a ~ z will appear in input strings.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/Solution.py b/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/Solution.py deleted file mode 100644 index 6769f7a0..00000000 --- a/leetcode/solution/0500-0599/0521.Longest Uncommon Subsequence I/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def findLUSlength(self, a, b): - """ - :type a: str - :type b: str - :rtype: int - """ - return -1 if a == b else max(len(a), len(b)) diff --git a/leetcode/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md b/leetcode/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md deleted file mode 100644 index b3af5711..00000000 --- a/leetcode/solution/0500-0599/0522.Longest Uncommon Subsequence II/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [522. Longest Uncommon Subsequence II](https://leetcode.com/problems/longest-uncommon-subsequence-ii) - -[中文文档](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README.md) - -## Description - -

- -Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. - -

- -

- -A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string. - -

- -

- -The input will be a list of strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1. - -

- -

Example 1:
- -

-
-Input: "aba", "cdc", "eae"
-
-Output: 3
-
-
- -

- -

Note: - -

    - -
  1. All the given strings' lengths will not exceed 10.
  2. - -
  3. The length of the given list will be in the range of [2, 50].
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md b/leetcode/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md deleted file mode 100644 index 2c7c94c5..00000000 --- a/leetcode/solution/0500-0599/0523.Continuous Subarray Sum/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [523. Continuous Subarray Sum](https://leetcode.com/problems/continuous-subarray-sum) - -[中文文档](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README.md) - -## Description - -

Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k, that is, sums up to n*k where n is also an integer.

- -

 

- -

Example 1:

- -
-
-Input: [23, 2, 4, 6, 7],  k=6
-
-Output: True
-
-Explanation: Because [2, 4] is a continuous subarray of size 2 and sums up to 6.
-
-
- -

Example 2:

- -
-
-Input: [23, 2, 6, 4, 7],  k=6
-
-Output: True
-
-Explanation: Because [23, 2, 6, 4, 7] is an continuous subarray of size 5 and sums up to 42.
-
-
- -

 

- -

Note:

- -
    -
  1. The length of the array won't exceed 10,000.
  2. -
  3. You may assume the sum of all the numbers is in the range of a signed 32-bit integer.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0525.Contiguous Array/README_EN.md b/leetcode/solution/0500-0599/0525.Contiguous Array/README_EN.md deleted file mode 100644 index fed3c6d2..00000000 --- a/leetcode/solution/0500-0599/0525.Contiguous Array/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [525. Contiguous Array](https://leetcode.com/problems/contiguous-array) - -[中文文档](/solution/0500-0599/0525.Contiguous%20Array/README.md) - -## Description - -

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.

- -

Example 1:
- -

-
-Input: [0,1]
-
-Output: 2
-
-Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1.
-
-
- -

- -

Example 2:
- -

-
-Input: [0,1,0]
-
-Output: 2
-
-Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
-
-
- -

- -

Note: - -The length of the given binary array will not exceed 50,000. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md b/leetcode/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md deleted file mode 100644 index 7be86fb0..00000000 --- a/leetcode/solution/0500-0599/0526.Beautiful Arrangement/README_EN.md +++ /dev/null @@ -1,86 +0,0 @@ -# [526. Beautiful Arrangement](https://leetcode.com/problems/beautiful-arrangement) - -[中文文档](/solution/0500-0599/0526.Beautiful%20Arrangement/README.md) - -## Description - -

Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <= N) in this array:

- -
    -
  1. The number at the ith position is divisible by i.
  2. -
  3. i is divisible by the number at the ith position.
  4. -
- -

 

- -

Now given N, how many beautiful arrangements can you construct?

- -

Example 1:

- -
-
-Input: 2
-
-Output: 2
-
-Explanation: 
-
-
-
-The first beautiful arrangement is [1, 2]:
-
-
-
-Number at the 1st position (i=1) is 1, and 1 is divisible by i (i=1).
-
-
-
-Number at the 2nd position (i=2) is 2, and 2 is divisible by i (i=2).
-
-
-
-The second beautiful arrangement is [2, 1]:
-
-
-
-Number at the 1st position (i=1) is 2, and 2 is divisible by i (i=1).
-
-
-
-Number at the 2nd position (i=2) is 1, and i (i=2) is divisible by 1.
-
-
- -

 

- -

Note:

- -
    -
  1. N is a positive integer and will not exceed 15.
  2. -
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md b/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md deleted file mode 100644 index 687cbc10..00000000 --- a/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [530. Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst) - -[中文文档](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README.md) - -## Description - -

Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.

- -

Example:

- -
-Input:
-
-   1
-    \
-     3
-    /
-   2
-
-Output:
-1
-
-Explanation:
-The minimum absolute difference is 1, which is the difference between 2 and 1 (or between 2 and 3).
-
- -

 

- -

Note:

- - - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.go b/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.go deleted file mode 100644 index 7e9805ed..00000000 --- a/leetcode/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.go +++ /dev/null @@ -1,27 +0,0 @@ -var res int -var preNode *TreeNode -func getMinimumDifference(root *TreeNode) int { - res = int(^uint(0) >> 1) - preNode = nil - helper(root) - return res -} - -func helper(root *TreeNode) { - if root == nil { - return - } - helper(root.Left) - if preNode != nil { - res = getMinInt(res, root.Val - preNode.Val) - } - preNode = root - helper(root.Right) -} - -func getMinInt(a,b int) int { - if a < b { - return a - } - return b -} \ No newline at end of file diff --git a/leetcode/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md b/leetcode/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md deleted file mode 100644 index 2bb77238..00000000 --- a/leetcode/solution/0500-0599/0538.Convert BST to Greater Tree/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [538. Convert BST to Greater Tree](https://leetcode.com/problems/convert-bst-to-greater-tree) - -[中文文档](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README.md) - -## Description - -

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

- -

Example:

- -
-Input: The root of a Binary Search Tree like this:
-              5
-            /   \
-           2     13
-
-Output: The root of a Greater Tree like this:
-             18
-            /   \
-          20     13
-
- -

Note: This question is the same as 1038: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0541.Reverse String II/README_EN.md b/leetcode/solution/0500-0599/0541.Reverse String II/README_EN.md deleted file mode 100644 index d5d7d42e..00000000 --- a/leetcode/solution/0500-0599/0541.Reverse String II/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [541. Reverse String II](https://leetcode.com/problems/reverse-string-ii) - -[中文文档](/solution/0500-0599/0541.Reverse%20String%20II/README.md) - -## Description - -

- -Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original. - -

- -

Example:
- -

-
-Input: s = "abcdefg", k = 2
-
-Output: "bacdfeg"
-
-
- -

- -Restrictions: - -
    - -
  1. The string consists of lower English letters only.
  2. - -
  3. Length of the given string and k will in the range [1, 10000]
  4. - -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0542.01 Matrix/README_EN.md b/leetcode/solution/0500-0599/0542.01 Matrix/README_EN.md deleted file mode 100644 index 400a39fe..00000000 --- a/leetcode/solution/0500-0599/0542.01 Matrix/README_EN.md +++ /dev/null @@ -1,93 +0,0 @@ -# [542. 01 Matrix](https://leetcode.com/problems/01-matrix) - -[中文文档](/solution/0500-0599/0542.01%20Matrix/README.md) - -## Description - -

Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.

- -

The distance between two adjacent cells is 1.

- -

 

- -

Example 1:

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

Example 2:

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

 

- -

Note:

- -
    -
  1. The number of elements of the given matrix will not exceed 10,000.
  2. -
  3. There are at least one 0 in the given matrix.
  4. -
  5. The cells are adjacent in only four directions: up, down, left and right.
  6. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md b/leetcode/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md deleted file mode 100644 index 1cf20942..00000000 --- a/leetcode/solution/0500-0599/0543.Diameter of Binary Tree/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree) - -[中文文档](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README.md) - -## Description - -

- -Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. - -

- -

- -Example:
- -Given a binary tree
- -

-
-          1
-
-         / \
-
-        2   3
-
-       / \     
-
-      4   5    
-
-
- -

- -

- -Return 3, which is the length of the path [4,2,1,3] or [5,2,1,3]. - -

- -

Note: - -The length of path between two nodes is represented by the number of edges between them. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0554.Brick Wall/README_EN.md b/leetcode/solution/0500-0599/0554.Brick Wall/README_EN.md deleted file mode 100644 index 85f61c94..00000000 --- a/leetcode/solution/0500-0599/0554.Brick Wall/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [554. Brick Wall](https://leetcode.com/problems/brick-wall) - -[中文文档](/solution/0500-0599/0554.Brick%20Wall/README.md) - -## Description - -

There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the top to the bottom and cross the least bricks.

- -

The brick wall is represented by a list of rows. Each row is a list of integers representing the width of each brick in this row from left to right.

- -

If your line go through the edge of a brick, then the brick is not considered as crossed. You need to find out how to draw the line to cross the least bricks and return the number of crossed bricks.

- -

You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks.

- -

 

- -

Example:

- -
-
-Input: [[1,2,2,1],
-
-        [3,1,2],
-
-        [1,3,2],
-
-        [2,4],
-
-        [3,1,2],
-
-        [1,3,1,1]]
-
-
-
-Output: 2
-
-
-
-Explanation: 
-
-
- -![](./images/brick_wall.png) - -

 

- -

Note:

- -
    -
  1. The width sum of bricks in different rows are the same and won't exceed INT_MAX.
  2. -
  3. The number of bricks in each row is in range [1,10,000]. The height of wall is in range [1,10,000]. Total number of bricks of the wall won't exceed 20,000.
  4. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0554.Brick Wall/Solution.py b/leetcode/solution/0500-0599/0554.Brick Wall/Solution.py deleted file mode 100644 index 788d9e75..00000000 --- a/leetcode/solution/0500-0599/0554.Brick Wall/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -class Solution: - def leastBricks(self, wall): - """ - :type wall: List[List[int]] - :rtype: int - """ - dic = {} - count = 0 - for hang in wall: - count = 0 - for j, ele in enumerate(hang): - if j == len(hang) - 1: - break - count += ele - if count not in dic: - dic[count] = 1 - else: - dic[count] += 1 - - if not dic: - return len(wall) - return len(wall) - dic[max(dic, key=dic.get)] diff --git a/leetcode/solution/0500-0599/0556.Next Greater Element III/README_EN.md b/leetcode/solution/0500-0599/0556.Next Greater Element III/README_EN.md deleted file mode 100644 index 962184e1..00000000 --- a/leetcode/solution/0500-0599/0556.Next Greater Element III/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [556. Next Greater Element III](https://leetcode.com/problems/next-greater-element-iii) - -[中文文档](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README.md) - -## Description - -

Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1.

- -

Example 1:

- -
-
-Input: 12
-
-Output: 21
-
-
- -

 

- -

Example 2:

- -
-
-Input: 21
-
-Output: -1
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md b/leetcode/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md deleted file mode 100644 index 417ef788..00000000 --- a/leetcode/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md +++ /dev/null @@ -1,49 +0,0 @@ -# [557. Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii) - -[中文文档](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README.md) - -## Description - -

Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

- -

Example 1:
- -

-
-Input: "Let's take LeetCode contest"
-
-Output: "s'teL ekat edoCteeL tsetnoc"
-
-
- -

- -

Note: - -In the string, each word is separated by single space and there will not be any extra space in the string. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md b/leetcode/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md deleted file mode 100644 index c838b74c..00000000 --- a/leetcode/solution/0500-0599/0560.Subarray Sum Equals K/README_EN.md +++ /dev/null @@ -1,55 +0,0 @@ -# [560. Subarray Sum Equals K](https://leetcode.com/problems/subarray-sum-equals-k) - -[中文文档](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README.md) - -## Description - -

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

- -

Example 1:
- -

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

- -

Note:
- -

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

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0561.Array Partition I/README_EN.md b/leetcode/solution/0500-0599/0561.Array Partition I/README_EN.md deleted file mode 100644 index c6e94fba..00000000 --- a/leetcode/solution/0500-0599/0561.Array Partition I/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [561. Array Partition I](https://leetcode.com/problems/array-partition-i) - -[中文文档](/solution/0500-0599/0561.Array%20Partition%20I/README.md) - -## Description - -

- -Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. - -

- -

Example 1:
- -

-
-Input: [1,4,3,2]
-
-
-
-Output: 4
-
-Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
-
-
- -

- -

Note:
- -

    - -
  1. n is a positive integer, which is in the range of [1, 10000].
  2. - -
  3. All the integers in the array will be in the range of [-10000, 10000].
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def arrayPairSum(self, nums: List[int]) -> int: - return sum(sorted(nums)[::2]) -``` - -### **Java** - -```java -class Solution { - public int arrayPairSum(int[] nums) { - Arrays.sort(nums); - int res = 0; - for (int i = 0, n = nums.length; i < n; i += 2) { - res += nums[i]; - } - return res; - } -} -``` - -### **JavaScript** - -```js -/** - * @param {number[]} nums - * @return {number} - */ -var arrayPairSum = function (nums) { - nums.sort((a, b) => a - b); - let res = 0; - for (let i = 0, n = nums.length; i < n; i += 2) { - res += nums[i]; - } - return res; -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0561.Array Partition I/Solution.js b/leetcode/solution/0500-0599/0561.Array Partition I/Solution.js deleted file mode 100644 index 5cb1e52f..00000000 --- a/leetcode/solution/0500-0599/0561.Array Partition I/Solution.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @param {number[]} nums - * @return {number} - */ -var arrayPairSum = function (nums) { - nums.sort((a, b) => a - b); - let res = 0; - for (let i = 0, n = nums.length; i < n; i += 2) { - res += nums[i]; - } - return res; -}; diff --git a/leetcode/solution/0500-0599/0561.Array Partition I/Solution.py b/leetcode/solution/0500-0599/0561.Array Partition I/Solution.py deleted file mode 100644 index 5e879579..00000000 --- a/leetcode/solution/0500-0599/0561.Array Partition I/Solution.py +++ /dev/null @@ -1,3 +0,0 @@ -class Solution: - def arrayPairSum(self, nums: List[int]) -> int: - return sum(sorted(nums)[::2]) diff --git a/leetcode/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md b/leetcode/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md deleted file mode 100644 index 47b3eaf9..00000000 --- a/leetcode/solution/0500-0599/0563.Binary Tree Tilt/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [563. Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt) - -[中文文档](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README.md) - -## Description - -

Given a binary tree, return the tilt of the whole tree.

- -

The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0.

- -

The tilt of the whole tree is defined as the sum of all nodes' tilt.

- -

Example:
- -

-
-Input: 
-
-         1
-
-       /   \
-
-      2     3
-
-Output: 1
-
-Explanation: 
-
-Tilt of node 2 : 0
-
-Tilt of node 3 : 0
-
-Tilt of node 1 : |2-3| = 1
-
-Tilt of binary tree : 0 + 0 + 1 = 1
-
-
- -

- -

Note: - -

    - -
  1. The sum of node values in any subtree won't exceed the range of 32-bit integer.
  2. - -
  3. All the tilt values won't exceed the range of 32-bit integer.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0566.Reshape the Matrix/README_EN.md b/leetcode/solution/0500-0599/0566.Reshape the Matrix/README_EN.md deleted file mode 100644 index 05348e48..00000000 --- a/leetcode/solution/0500-0599/0566.Reshape the Matrix/README_EN.md +++ /dev/null @@ -1,127 +0,0 @@ -# [566. Reshape the Matrix](https://leetcode.com/problems/reshape-the-matrix) - -[中文文档](/solution/0500-0599/0566.Reshape%20the%20Matrix/README.md) - -## Description - -

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. - -

- -

- -You're given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively.

- -

The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing order as they were. - -

- -

- -If the 'reshape' operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix. - -

- -

Example 1:
- -

-
-Input: 
-
-nums = 
-
-[[1,2],
-
- [3,4]]
-
-r = 1, c = 4
-
-Output: 
-
-[[1,2,3,4]]
-
-Explanation:
The row-traversing of nums is [1,2,3,4]. The new reshaped matrix is a 1 * 4 matrix, fill it row by row by using the previous list. - -
- -

- -

Example 2:
- -

-
-Input: 
-
-nums = 
-
-[[1,2],
-
- [3,4]]
-
-r = 2, c = 4
-
-Output: 
-
-[[1,2],
-
- [3,4]]
-
-Explanation:
There is no way to reshape a 2 * 2 matrix to a 2 * 4 matrix. So output the original matrix. - -
- -

- -

Note:
- -

    - -
  1. The height and width of the given matrix is in range [1, 100].
  2. - -
  3. The given r and c are all positive.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]: - m, n = len(nums), len(nums[0]) - if m * n != r * c: - return nums - res = [[0] * c for _ in range(r)] - for x in range(m * n): - res[x // c][x % c] = nums[x // n][x % n] - return res -``` - -### **Java** - -```java -class Solution { - public int[][] matrixReshape(int[][] nums, int r, int c) { - int m = nums.length, n = nums[0].length; - if (m * n != r * c) return nums; - int[][] res = new int[r][c]; - for (int i = 0; i < m * n; ++i) { - res[i / c][i % c] = nums[i / n][i % n]; - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0566.Reshape the Matrix/Solution.py b/leetcode/solution/0500-0599/0566.Reshape the Matrix/Solution.py deleted file mode 100644 index a5168a72..00000000 --- a/leetcode/solution/0500-0599/0566.Reshape the Matrix/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]: - m, n = len(nums), len(nums[0]) - if m * n != r * c: - return nums - res = [[0] * c for _ in range(r)] - for x in range(m * n): - res[x // c][x % c] = nums[x // n][x % n] - return res diff --git a/leetcode/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md b/leetcode/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md deleted file mode 100644 index 2e5cf634..00000000 --- a/leetcode/solution/0500-0599/0572.Subtree of Another Tree/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [572. Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree) - -[中文文档](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README.md) - -## Description - -

- -Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself. - -

- -

Example 1:
- -Given tree s: - -

-
-     3
-
-    / \
-
-   4   5
-
-  / \
-
- 1   2
-
-
- -Given tree t: - -
-
-   4 
-
-  / \
-
- 1   2
-
-
- -Return true, because t has the same structure and node values with a subtree of s. - -

- -

Example 2:
- -Given tree s: - -

-
-     3
-
-    / \
-
-   4   5
-
-  / \
-
- 1   2
-
-    /
-
-   0
-
-
- -Given tree t: - -
-
-   4
-
-  / \
-
- 1   2
-
-
- -Return false. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0572.Subtree of Another Tree/Solution.cpp b/leetcode/solution/0500-0599/0572.Subtree of Another Tree/Solution.cpp deleted file mode 100644 index fae148dc..00000000 --- a/leetcode/solution/0500-0599/0572.Subtree of Another Tree/Solution.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -private: - bool IsSameTree(TreeNode *s, TreeNode *t) - { - if (nullptr == s && nullptr == t) - return true ; - if (nullptr == s || nullptr == t - || s->val != t->val) - return false ; - - return IsSameTree(s->left, t->left) - && IsSameTree(s->right, t->right) ; - } -public: - bool isSubtree(TreeNode* s, TreeNode* t) { - if (nullptr == s) - return false ; - - if (s->val == t->val && IsSameTree(s, t)) - return true ; - - if (!isSubtree(s->left, t) - && !isSubtree(s->right, t)) - return false ; - - return true ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md b/leetcode/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md deleted file mode 100644 index eb04a390..00000000 --- a/leetcode/solution/0500-0599/0576.Out of Boundary Paths/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [576. Out of Boundary Paths](https://leetcode.com/problems/out-of-boundary-paths) - -[中文文档](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README.md) - -## Description - -

There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most move N times. Find out the number of paths to move the ball out of grid boundary. The answer may be very large, return it after mod 109 + 7.

- -

 

- -

Example 1:

- -
-
-Input: m = 2, n = 2, N = 2, i = 0, j = 0
-
-Output: 6
-
-Explanation:
-
-
- -![](./images/out_of_boundary_paths_1.png) - -

Example 2:

- -
-
-Input: m = 1, n = 3, N = 3, i = 0, j = 1
-
-Output: 12
-
-Explanation:
-
-
- -![](./images/out_of_boundary_paths_2.png) - -

 

- -

Note:

- -
    -
  1. Once you move the ball out of boundary, you cannot move it back.
  2. -
  3. The length and height of the grid is in range [1,50].
  4. -
  5. N is in range [0,50].
  6. -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md b/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md deleted file mode 100644 index f0d9b752..00000000 --- a/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [581. Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) - -[中文文档](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README.md) - -## Description - -

Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.

- -

You need to find the shortest such subarray and output its length.

- -

Example 1:
- -

-
-Input: [2, 6, 4, 8, 10, 9, 15]
-
-Output: 5
-
-Explanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.
-
-
- -

- -

Note:
- -

    - -
  1. Then length of the input array is in range [1, 10,000].
  2. - -
  3. The input array may contain duplicates, so ascending order here means <=.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/Solution.cpp b/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/Solution.cpp deleted file mode 100644 index 763c69d2..00000000 --- a/leetcode/solution/0500-0599/0581.Shortest Unsorted Continuous Subarray/Solution.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// i自左向右找到第一个逆序, -// j自右向左找到第一个逆序 -// 找到nums[i, j]的上下界 -// ij向外扩展找到满足上下界的最小[i, j] -class Solution { -public: - int findUnsortedSubarray(vector& nums) { - if (1 == nums.size()) - return 0 ; - - int i = 0, j = nums.size()-1 ; - while (i < j && nums[i] <= nums[i+1]) - ++i ; - if (i >= j) - return 0 ; - - while (nums[j-1] <= nums[j]) - --j ; - - //cout << i << ' ' << j << endl ; - int m = nums[i] ; - int M = m ; - for (int k = i; k <= j; ++k) - { - if (m > nums[k]) - m = nums[k] ; - if (M < nums[k]) - M = nums[k] ; - } - //cout << m << ' ' << M << endl ; - - while (i >= 0 && m < nums[i]) - --i ; - while (j < nums.size() && M > nums[j]) - ++j ; - - //cout << i << ' ' << j << endl ; - return j-i-1 ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md b/leetcode/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md deleted file mode 100644 index 79e1dc33..00000000 --- a/leetcode/solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [589. N-ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal) - -[中文文档](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README.md) - -## Description - -

Given an n-ary tree, return the preorder traversal of its nodes' values.

- -

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

- -

 

- -

Follow up:

- -

Recursive solution is trivial, could you do it iteratively?

- -

 

-

Example 1:

- -![](./images/narytreeexample.png) - -
-Input: root = [1,null,3,2,4,null,5,6]
-Output: [1,3,5,6,2,4]
-
- -

Example 2:

- -![](./images/sample_4_964.png) - -
-Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
-Output: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]
-
- -

 

-

Constraints:

- -
    -
  • The height of the n-ary tree is less than or equal to 1000
  • -
  • The total number of nodes is between [0, 10^4]
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md b/leetcode/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md deleted file mode 100644 index 65523edd..00000000 --- a/leetcode/solution/0500-0599/0590.N-ary Tree Postorder Traversal/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [590. N-ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal) - -[中文文档](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README.md) - -## Description - -

Given an n-ary tree, return the postorder traversal of its nodes' values.

- -

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

- -

 

- -

Follow up:

- -

Recursive solution is trivial, could you do it iteratively?

- -

 

-

Example 1:

- -![](./images/narytreeexample.png) - -
-Input: root = [1,null,3,2,4,null,5,6]
-Output: [5,6,3,2,4,1]
-
- -

Example 2:

- -![](./images/sample_4_964.png) - -
-Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
-Output: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]
-
- -

 

-

Constraints:

- -
    -
  • The height of the n-ary tree is less than or equal to 1000
  • -
  • The total number of nodes is between [0, 10^4]
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0605.Can Place Flowers/README_EN.md b/leetcode/solution/0600-0699/0605.Can Place Flowers/README_EN.md deleted file mode 100644 index eb2da998..00000000 --- a/leetcode/solution/0600-0699/0605.Can Place Flowers/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [605. Can Place Flowers](https://leetcode.com/problems/can-place-flowers) - -[中文文档](/solution/0600-0699/0605.Can%20Place%20Flowers/README.md) - -## Description - -

Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.

- -

Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empty), and a number n, return if n new flowers can be planted in it without violating the no-adjacent-flowers rule.

- -

Example 1:
- -

-
-Input: flowerbed = [1,0,0,0,1], n = 1
-
-Output: True
-
-
- -

- -

Example 2:
- -

-
-Input: flowerbed = [1,0,0,0,1], n = 2
-
-Output: False
-
-
- -

- -

Note:
- -

    - -
  1. The input array won't violate no-adjacent-flowers rule.
  2. - -
  3. The input array size is in the range of [1, 20000].
  4. - -
  5. n is a non-negative integer which won't exceed the input array size.
  6. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.cpp b/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.cpp deleted file mode 100644 index 99e5d988..00000000 --- a/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.cpp +++ /dev/null @@ -1,33 +0,0 @@ -class Solution { -public: - bool canPlaceFlowers(vector& flowerbed, int n) { - int i = 0, j = flowerbed.size()-1 ; - int cnt=0 ; - int num ; - while (i <= j && !flowerbed[i]) - ++i ; - if (i > j) - return n <= 1 + (j>>1) ; - num = i>>1 ; - while (!flowerbed[j]) - --j ; - num += (flowerbed.size()-1-j)>>1 ; - //cout << i << ' ' << j << endl ; - while (i <= j) - { - - //cout << "num = " << num << ", cnt = " << cnt << endl ; - if (flowerbed[i]) - { - if (cnt > 0) - num += (cnt-1) >> 1 ; - cnt = 0 ; - } - else - cnt++ ; - ++i ; - } - //cout << num << endl ; - return num >= n ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.py b/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.py deleted file mode 100644 index 44462eb8..00000000 --- a/leetcode/solution/0600-0699/0605.Can Place Flowers/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -class Solution: - def canPlaceFlowers(self, flowerBed, n): - """ - type flowerBed : List[int], n : int - rtype : bool - """ - - i = 0 - while n > 0 and i < len(flowerBed): - if i == 0 and flowerBed[0] == 0: # for 1st Element - if len(flowerBed) == 1 or (len(flowerBed) > 1 and flowerBed[1] == 0): - n -= 1 - flowerBed[0] = 1 - elif i == len(flowerBed)-1 and flowerBed[i] == 0 and flowerBed[i-1] == 0: # for last element - n -= 1 - flowerBed[i] = 1 - elif flowerBed[i] == 0 and flowerBed[i-1] == 0 and flowerBed[i+1] == 0: - n -= 1 - flowerBed[i] = 1 - i += 1 - - return n==0 diff --git a/leetcode/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md b/leetcode/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md deleted file mode 100644 index e1a705c9..00000000 --- a/leetcode/solution/0600-0699/0606.Construct String from Binary Tree/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [606. Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree) - -[中文文档](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README.md) - -## Description - -

You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.

- -

The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relationship between the string and the original binary tree.

- -

Example 1:
- -

-
-Input: Binary tree: [1,2,3,4]
-
-       1
-
-     /   \
-
-    2     3
-
-   /    
-
-  4     
-
-
-
-Output: "1(2(4))(3)"
-
-
Explanation: Originallay it needs to be "1(2(4)())(3()())",
but you need to omit all the unnecessary empty parenthesis pairs.
And it will be "1(2(4))(3)". - -
- -

- -

Example 2:
- -

-
-Input: Binary tree: [1,2,3,null,4]
-
-       1
-
-     /   \
-
-    2     3
-
-     \  
-
-      4 
-
-
-
-Output: "1(2()(4))(3)"
-
-
Explanation: Almost the same as the first example,
except we can't omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0611.Valid Triangle Number/README_EN.md b/leetcode/solution/0600-0699/0611.Valid Triangle Number/README_EN.md deleted file mode 100644 index d67b2c38..00000000 --- a/leetcode/solution/0600-0699/0611.Valid Triangle Number/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [611. Valid Triangle Number](https://leetcode.com/problems/valid-triangle-number) - -[中文文档](/solution/0600-0699/0611.Valid%20Triangle%20Number/README.md) - -## Description - -Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. - -

Example 1:
- -

-
-Input: [2,2,3,4]
-
-Output: 3
-
-Explanation:
-
-Valid combinations are: 
-
-2,3,4 (using the first 2)
-
-2,3,4 (using the second 2)
-
-2,2,3
-
-
- -

- -

Note:
- -

    - -
  1. The length of the given array won't exceed 1000.
  2. - -
  3. The integers in the given array are in the range of [0, 1000].
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md b/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md deleted file mode 100644 index d405bc91..00000000 --- a/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [617. Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees) - -[中文文档](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README.md) - -## Description - -

Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.

- -

You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.

- -

Example 1:

- -
-
-Input: 
-
-	Tree 1                     Tree 2                  
-
-          1                         2                             
-
-         / \                       / \                            
-
-        3   2                     1   3                        
-
-       /                           \   \                      
-
-      5                             4   7                  
-
-Output: 
-
-Merged tree:
-
-	     3
-
-	    / \
-
-	   4   5
-
-	  / \   \ 
-
-	 5   4   7
-
-
- -

 

- -

Note: The merging process must start from the root nodes of both trees.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/Solution.go b/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/Solution.go deleted file mode 100644 index c9548d33..00000000 --- a/leetcode/solution/0600-0699/0617.Merge Two Binary Trees/Solution.go +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ -func mergeTrees(t1 *TreeNode, t2 *TreeNode) *TreeNode { - if t1 == nil { - return t2 - } - if t2 == nil { - return t1 - } - t1.Val += t2.Val - t1.Left = mergeTrees(t1.Left, t2.Left) - t1.Right = mergeTrees(t1.Right, t2.Right) - return t1 -} diff --git a/leetcode/solution/0600-0699/0622.Design Circular Queue/README_EN.md b/leetcode/solution/0600-0699/0622.Design Circular Queue/README_EN.md deleted file mode 100644 index dae6671c..00000000 --- a/leetcode/solution/0600-0699/0622.Design Circular Queue/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [622. Design Circular Queue](https://leetcode.com/problems/design-circular-queue) - -[中文文档](/solution/0600-0699/0622.Design%20Circular%20Queue/README.md) - -## Description - -

Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer".

- -

One of the benefits of the circular queue is that we can make use of the spaces in front of the queue. In a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values.

- -

Your implementation should support following operations:

- -
    -
  • MyCircularQueue(k): Constructor, set the size of the queue to be k.
  • -
  • Front: Get the front item from the queue. If the queue is empty, return -1.
  • -
  • Rear: Get the last item from the queue. If the queue is empty, return -1.
  • -
  • enQueue(value): Insert an element into the circular queue. Return true if the operation is successful.
  • -
  • deQueue(): Delete an element from the circular queue. Return true if the operation is successful.
  • -
  • isEmpty(): Checks whether the circular queue is empty or not.
  • -
  • isFull(): Checks whether the circular queue is full or not.
  • -
- -

 

- -

Example:

- -
-
-MyCircularQueue circularQueue = new MyCircularQueue(3); // set the size to be 3
-
-circularQueue.enQueue(1);  // return true
-
-circularQueue.enQueue(2);  // return true
-
-circularQueue.enQueue(3);  // return true
-
-circularQueue.enQueue(4);  // return false, the queue is full
-
-circularQueue.Rear();  // return 3
-
-circularQueue.isFull();  // return true
-
-circularQueue.deQueue();  // return true
-
-circularQueue.enQueue(4);  // return true
-
-circularQueue.Rear();  // return 4
-
-
- -  - -

Note:

- -
    -
  • All values will be in the range of [0, 1000].
  • -
  • The number of operations will be in the range of [1, 1000].
  • -
  • Please do not use the built-in Queue library.
  • -
- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md b/leetcode/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md deleted file mode 100644 index b0ce18b4..00000000 --- a/leetcode/solution/0600-0699/0633.Sum of Square Numbers/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [633. Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers) - -[中文文档](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README.md) - -## Description - -

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

- -

Example 1:

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

 

- -

Example 2:

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

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md b/leetcode/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md deleted file mode 100644 index 7229362b..00000000 --- a/leetcode/solution/0600-0699/0637.Average of Levels in Binary Tree/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [637. Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree) - -[中文文档](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README.md) - -## Description - -Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. - -

Example 1:
- -

-
-Input:
-
-    3
-
-   / \
-
-  9  20
-
-    /  \
-
-   15   7
-
-Output: [3, 14.5, 11]
-
-Explanation:
-
-The average value of nodes on level 0 is 3,  on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].
-
-
- -

- -

Note:
- -

    - -
  1. The range of node's value is in the range of 32-bit signed integer.
  2. - -
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0645.Set Mismatch/README_EN.md b/leetcode/solution/0600-0699/0645.Set Mismatch/README_EN.md deleted file mode 100644 index abc28338..00000000 --- a/leetcode/solution/0600-0699/0645.Set Mismatch/README_EN.md +++ /dev/null @@ -1,126 +0,0 @@ -# [645. Set Mismatch](https://leetcode.com/problems/set-mismatch) - -[中文文档](/solution/0600-0699/0645.Set%20Mismatch/README.md) - -## Description - -

- -The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number. - -

- -

- -Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array. - -

- -

Example 1:
- -

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

- -

Note:
- -

    - -
  1. The given array size will in the range [2, 10000].
  2. - -
  3. The given array's numbers won't have any order.
  4. - -
- -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findErrorNums(self, nums: List[int]) -> List[int]: - res = 0 - for num in nums: - res ^= num - for i in range(1, len(nums) + 1): - res ^= i - pos = 0 - while (res & 1) == 0: - res >>= 1 - pos += 1 - a = b = 0 - for num in nums: - if ((num >> pos) & 1) == 0: - a ^= num - else: - b ^= num - for i in range(1, len(nums) + 1): - if ((i >> pos) & 1) == 0: - a ^= i - else: - b ^= i - for num in nums: - if num == a: - return [a, b] - return [b, a] -``` - -### **Java** - -```java -class Solution { - public int[] findErrorNums(int[] nums) { - int res = 0; - for (int num : nums) { - res ^= num; - } - for (int i = 1, n = nums.length; i < n + 1; ++i) { - res ^= i; - } - int pos = 0; - while ((res & 1) == 0) { - res >>= 1; - ++pos; - } - int a = 0, b = 0; - for (int num : nums) { - if (((num >> pos) & 1) == 0) { - a ^= num; - } else { - b ^= num; - } - } - for (int i = 1, n = nums.length; i < n + 1; ++i) { - if (((i >> pos) & 1) == 0) { - a ^= i; - } else { - b ^= i; - } - } - for (int num : nums) { - if (num == a) { - return new int[]{a, b}; - } - } - return new int[]{b, a}; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0645.Set Mismatch/Solution.py b/leetcode/solution/0600-0699/0645.Set Mismatch/Solution.py deleted file mode 100644 index 5628345b..00000000 --- a/leetcode/solution/0600-0699/0645.Set Mismatch/Solution.py +++ /dev/null @@ -1,26 +0,0 @@ -class Solution: - def findErrorNums(self, nums: List[int]) -> List[int]: - res = 0 - for num in nums: - res ^= num - for i in range(1, len(nums) + 1): - res ^= i - pos = 0 - while (res & 1) == 0: - res >>= 1 - pos += 1 - a = b = 0 - for num in nums: - if ((num >> pos) & 1) == 0: - a ^= num - else: - b ^= num - for i in range(1, len(nums) + 1): - if ((i >> pos) & 1) == 0: - a ^= i - else: - b ^= i - for num in nums: - if num == a: - return [a, b] - return [b, a] diff --git a/leetcode/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md b/leetcode/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md deleted file mode 100644 index 6b191554..00000000 --- a/leetcode/solution/0600-0699/0650.2 Keys Keyboard/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [650. 2 Keys Keyboard](https://leetcode.com/problems/2-keys-keyboard) - -[中文文档](/solution/0600-0699/0650.2%20Keys%20Keyboard/README.md) - -## Description - -

Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:

- -
    -
  1. Copy All: You can copy all the characters present on the notepad (partial copy is not allowed).
  2. -
  3. Paste: You can paste the characters which are copied last time.
  4. -
- -

 

- -

Given a number n. You have to get exactly n 'A' on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get n 'A'.

- -

Example 1:

- -
-
-Input: 3
-
-Output: 3
-
-Explanation:
-
-Intitally, we have one character 'A'.
-
-In step 1, we use Copy All operation.
-
-In step 2, we use Paste operation to get 'AA'.
-
-In step 3, we use Paste operation to get 'AAA'.
-
-
- -

 

- -

Note:

- -
    -
  1. The n will be in the range [1, 1000].
  2. -
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md b/leetcode/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md deleted file mode 100644 index f131da5f..00000000 --- a/leetcode/solution/0600-0699/0652.Find Duplicate Subtrees/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [652. Find Duplicate Subtrees](https://leetcode.com/problems/find-duplicate-subtrees) - -[中文文档](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README.md) - -## Description - -

Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.

- -

Two trees are duplicate if they have the same structure with same node values.

- -

Example 1:

- -
-
-        1
-
-       / \
-
-      2   3
-
-     /   / \
-
-    4   2   4
-
-       /
-
-      4
-
-
- -

The following are two duplicate subtrees:

- -
-
-      2
-
-     /
-
-    4
-
-
- -

and

- -
-
-    4
-
-
- -Therefore, you need to return above trees' root in the form of a list. - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0664.Strange Printer/README_EN.md b/leetcode/solution/0600-0699/0664.Strange Printer/README_EN.md deleted file mode 100644 index 7bde7bd1..00000000 --- a/leetcode/solution/0600-0699/0664.Strange Printer/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [664. Strange Printer](https://leetcode.com/problems/strange-printer) - -[中文文档](/solution/0600-0699/0664.Strange%20Printer/README.md) - -## Description - -

- -There is a strange printer with the following two special requirements: - -

    - -
  1. The printer can only print a sequence of the same character each time.
  2. - -
  3. At each turn, the printer can print new characters starting from and ending at any places, and will cover the original existing characters.
  4. - -
- -

- -

- -Given a string consists of lower English letters only, your job is to count the minimum number of turns the printer needed in order to print it. - -

- -

Example 1:
- -

-
-Input: "aaabbb"
-
-Output: 2
-
-Explanation: Print "aaa" first and then print "bbb".
-
-
- -

- -

Example 2:
- -

-
-Input: "aba"
-
-Output: 2
-
-Explanation: Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character 'a'.
-
-
- -

- -

Hint: Length of the given string will not exceed 100.

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md b/leetcode/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md deleted file mode 100644 index dd9b2a29..00000000 --- a/leetcode/solution/0600-0699/0669.Trim a Binary Search Tree/README_EN.md +++ /dev/null @@ -1,111 +0,0 @@ -# [669. Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree) - -[中文文档](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README.md) - -## Description - -

- -Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree. - -

- -

Example 1:
- -

-
-Input: 
-
-    1
-
-   / \
-
-  0   2
-
-
-
-  L = 1
-
-  R = 2
-
-
-
-Output: 
-
-    1
-
-      \
-
-       2
-
-
- -

- -

Example 2:
- -

-
-Input: 
-
-    3
-
-   / \
-
-  0   4
-
-   \
-
-    2
-
-   /
-
-  1
-
-
-
-  L = 1
-
-  R = 3
-
-
-
-Output: 
-
-      3
-
-     / 
-
-   2   
-
-  /
-
- 1
-
-
- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md b/leetcode/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md deleted file mode 100644 index 880c0899..00000000 --- a/leetcode/solution/0600-0699/0671.Second Minimum Node In a Binary Tree/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [671. Second Minimum Node In a Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) - -[中文文档](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README.md) - -## Description - -

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root.left.val, root.right.val) always holds.

- -

Given such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.

- -

If no such second minimum value exists, output -1 instead.

- -

Example 1:

- -
-
-Input: 
-
-    2
-
-   / \
-
-  2   5
-
-     / \
-
-    5   7
-
-
-
-Output: 5
-
-Explanation: The smallest value is 2, the second smallest value is 5.
-
-
- -

 

- -

Example 2:

- -
-
-Input: 
-
-    2
-
-   / \
-
-  2   2
-
-
-
-Output: -1
-
-Explanation: The smallest value is 2, but there isn't any second smallest value.
-
-
- -

 

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md b/leetcode/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md deleted file mode 100644 index ae7155ec..00000000 --- a/leetcode/solution/0600-0699/0673.Number of Longest Increasing Subsequence/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [673. Number of Longest Increasing Subsequence](https://leetcode.com/problems/number-of-longest-increasing-subsequence) - -[中文文档](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README.md) - -## Description - -

- -Given an unsorted array of integers, find the number of longest increasing subsequence. - -

- -

Example 1:
- -

-
-Input: [1,3,5,4,7]
-
-Output: 2
-
-Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3, 5, 7].
-
-
- -

- -

Example 2:
- -

-
-Input: [2,2,2,2,2]
-
-Output: 5
-
-Explanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5.
-
-
- -

- -

Note: - -Length of the given array will be not exceed 2000 and the answer is guaranteed to be fit in 32-bit signed int. - -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md b/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md deleted file mode 100644 index 6828f4ba..00000000 --- a/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [674. Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence) - -[中文文档](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README.md) - -## Description - -

- -Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). - -

- -

Example 1:
- -

-
-Input: [1,3,5,4,7]
-
-Output: 3
-
-Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. 
-
-Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4. 
-
-
- -

- -

Example 2:
- -

-
-Input: [2,2,2,2,2]
-
-Output: 1
-
-Explanation: The longest continuous increasing subsequence is [2], its length is 1. 
-
-
- -

- -

Note: - -Length of the array will not exceed 10,000. - -

- -## Solutions - - - -### **Python3** - -```python -class Solution: - def findLengthOfLCIS(self, nums: List[int]) -> int: - n = len(nums) - if n < 2: - return n - res = f = 1 - for i in range(1, n): - f = 1 + (f if nums[i - 1] < nums[i] else 0) - res = max(res, f) - return res -``` - -### **Java** - -```java -class Solution { - public int findLengthOfLCIS(int[] nums) { - int n; - if ((n = nums.length) < 2) return n; - int res = 1, f = 1; - for (int i = 1; i < n; ++i) { - f = 1 + (nums[i - 1] < nums[i] ? f : 0); - res = Math.max(res, f); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.py b/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.py deleted file mode 100644 index ff0a8cd8..00000000 --- a/leetcode/solution/0600-0699/0674.Longest Continuous Increasing Subsequence/Solution.py +++ /dev/null @@ -1,10 +0,0 @@ -class Solution: - def findLengthOfLCIS(self, nums: List[int]) -> int: - n = len(nums) - if n < 2: - return n - res = f = 1 - for i in range(1, n): - f = 1 + (f if nums[i - 1] < nums[i] else 0) - res = max(res, f) - return res diff --git a/leetcode/solution/0600-0699/0679.24 Game/README_EN.md b/leetcode/solution/0600-0699/0679.24 Game/README_EN.md deleted file mode 100644 index 3515da13..00000000 --- a/leetcode/solution/0600-0699/0679.24 Game/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [679. 24 Game](https://leetcode.com/problems/24-game) - -[中文文档](/solution/0600-0699/0679.24%20Game/README.md) - -## Description - -

- -You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through \*, /, +, -, (, ) to get the value of 24. - -

- -

Example 1:
- -

-
-Input: [4, 1, 8, 7]
-
-Output: True
-
-Explanation: (8-4) * (7-1) = 24
-
-
- -

- -

Example 2:
- -

-
-Input: [1, 2, 1, 2]
-
-Output: False
-
-
- -

- -

Note:
- -

    - -
  1. The division operator / represents real division, not integer division. For example, 4 / (1 - 2/3) = 12.
  2. - -
  3. Every operation done is between two numbers. In particular, we cannot use - as a unary operator. For example, with [1, 1, 1, 1] as input, the expression -1 - 1 - 1 - 1 is not allowed.
  4. - -
  5. You cannot concatenate numbers together. For example, if the input is [1, 2, 1, 2], we cannot write this as 12 + 12.
  6. - -
- -

- -

- -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0682.Baseball Game/README_EN.md b/leetcode/solution/0600-0699/0682.Baseball Game/README_EN.md deleted file mode 100644 index 89d91c1d..00000000 --- a/leetcode/solution/0600-0699/0682.Baseball Game/README_EN.md +++ /dev/null @@ -1,162 +0,0 @@ -# [682. Baseball Game](https://leetcode.com/problems/baseball-game) - -[中文文档](/solution/0600-0699/0682.Baseball%20Game/README.md) - -## Description - -

- -You're now a baseball game point recorder. - -

- -

- -Given a list of strings, each string can be one of the 4 following types: - -

    - -
  1. Integer (one round's score): Directly represents the number of points you get in this round.
  2. - -
  3. "+" (one round's score): Represents that the points you get in this round are the sum of the last two valid round's points.
  4. - -
  5. "D" (one round's score): Represents that the points you get in this round are the doubled data of the last valid round's points.
  6. - -
  7. "C" (an operation, which isn't a round's score): Represents the last valid round's points you get were invalid and should be removed.
  8. - -
- -

- -

- -Each round's operation is permanent and could have an impact on the round before and the round after. - -

- -

- -You need to return the sum of the points you could get in all the rounds. - -

- -

Example 1:
- -

-
-Input: ["5","2","C","D","+"]
-
-Output: 30
-
-Explanation: 
-
-Round 1: You could get 5 points. The sum is: 5.
-
-Round 2: You could get 2 points. The sum is: 7.
-
-Operation 1: The round 2's data was invalid. The sum is: 5.  
-
-Round 3: You could get 10 points (the round 2's data has been removed). The sum is: 15.
-
-Round 4: You could get 5 + 10 = 15 points. The sum is: 30.
-
-
- -

- -

Example 2:
- -

-
-Input: ["5","-2","4","C","D","9","+","+"]
-
-Output: 27
-
-Explanation: 
-
-Round 1: You could get 5 points. The sum is: 5.
-
-Round 2: You could get -2 points. The sum is: 3.
-
-Round 3: You could get 4 points. The sum is: 7.
-
-Operation 1: The round 3's data is invalid. The sum is: 3.  
-
-Round 4: You could get -4 points (the round 3's data has been removed). The sum is: -1.
-
-Round 5: You could get 9 points. The sum is: 8.
-
-Round 6: You could get -4 + 9 = 5 points. The sum is 13.
-
-Round 7: You could get 9 + 5 = 14 points. The sum is 27.
-
-
- -

- -

Note:
- -

  • The size of the input list will be between 1 and 1000.
  • - -
  • Every integer represented in the list will be between -30000 and 30000.
  • - -

    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def calPoints(self, ops: List[str]) -> int: - stack = [] - for op in ops: - if op == 'C': - stack.pop() - elif op == 'D': - stack.append(stack[-1] << 1) - elif op == '+': - stack.append(stack[-1] + stack[-2]) - else: - stack.append(int(op)) - return sum(stack) -``` - -### **Java** - -```java -class Solution { - public int calPoints(String[] ops) { - Deque stack = new ArrayDeque<>(); - for (String op : ops) { - if ("C".equals(op)) { - stack.pop(); - } else if ("D".equals(op)) { - stack.push(stack.peek() << 1); - } else if ("+".equals(op)) { - Integer a = stack.pop(); - Integer b = stack.peek(); - stack.push(a); - stack.push(a + b); - } else { - stack.push(Integer.valueOf(op)); - } - } - int res = 0; - for (Integer score : stack) { - res += score; - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0682.Baseball Game/Solution.py b/leetcode/solution/0600-0699/0682.Baseball Game/Solution.py deleted file mode 100644 index d9430899..00000000 --- a/leetcode/solution/0600-0699/0682.Baseball Game/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def calPoints(self, ops: List[str]) -> int: - stack = [] - for op in ops: - if op == 'C': - stack.pop() - elif op == 'D': - stack.append(stack[-1] << 1) - elif op == '+': - stack.append(stack[-1] + stack[-2]) - else: - stack.append(int(op)) - return sum(stack) \ No newline at end of file diff --git a/leetcode/solution/0600-0699/0684.Redundant Connection/README_EN.md b/leetcode/solution/0600-0699/0684.Redundant Connection/README_EN.md deleted file mode 100644 index 9ba6402c..00000000 --- a/leetcode/solution/0600-0699/0684.Redundant Connection/README_EN.md +++ /dev/null @@ -1,103 +0,0 @@ -# [684. Redundant Connection](https://leetcode.com/problems/redundant-connection) - -[中文文档](/solution/0600-0699/0684.Redundant%20Connection/README.md) - -## Description - -

    - -In this problem, a tree is an undirected graph that is connected and has no cycles. - -

    - -The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, ..., N), with one additional edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed. - -

    - -The resulting graph is given as a 2D-array of edges. Each element of edges is a pair [u, v] with u < v, that represents an undirected edge connecting nodes u and v. - -

    - -Return an edge that can be removed so that the resulting graph is a tree of N nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array. The answer edge [u, v] should be in the same format, with u < v. - -

    Example 1:
    - -

    -
    -Input: [[1,2], [1,3], [2,3]]
    -
    -Output: [2,3]
    -
    -Explanation: The given undirected graph will be like this:
    -
    -  1
    -
    - / \
    -
    -2 - 3
    -
    -
    - -

    - -

    Example 2:
    - -

    -
    -Input: [[1,2], [2,3], [3,4], [1,4], [1,5]]
    -
    -Output: [1,4]
    -
    -Explanation: The given undirected graph will be like this:
    -
    -5 - 1 - 2
    -
    -    |   |
    -
    -    4 - 3
    -
    -
    - -

    - -

    Note:
    - -

  • The size of the input 2D-array will be between 3 and 1000.
  • - -
  • Every integer represented in the 2D-array will be between 1 and N, where N is the size of the input array.
  • - -

    - -
    - -

    - -Update (2017-09-26):
    - -We have overhauled the problem description + test cases and specified clearly the graph is an undirected graph. For the directed graph follow up please see Redundant Connection II). We apologize for any inconvenience caused. - -

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0687.Longest Univalue Path/README_EN.md b/leetcode/solution/0600-0699/0687.Longest Univalue Path/README_EN.md deleted file mode 100644 index bbd74ce5..00000000 --- a/leetcode/solution/0600-0699/0687.Longest Univalue Path/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [687. Longest Univalue Path](https://leetcode.com/problems/longest-univalue-path) - -[中文文档](/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md) - -## Description - -

    Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.

    - -

    The length of path between two nodes is represented by the number of edges between them.

    - -

     

    - -

    Example 1:

    - -

    Input:

    - -
    -
    -              5
    -
    -             / \
    -
    -            4   5
    -
    -           / \   \
    -
    -          1   1   5
    -
    -
    - -

    Output: 2

    - -

     

    - -

    Example 2:

    - -

    Input:

    - -
    -
    -              1
    -
    -             / \
    -
    -            4   5
    -
    -           / \   \
    -
    -          4   4   5
    -
    -
    - -

    Output: 2

    - -

     

    - -

    Note: The given binary tree has not more than 10000 nodes. The height of the tree is not more than 1000.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0690.Employee Importance/README_EN.md b/leetcode/solution/0600-0699/0690.Employee Importance/README_EN.md deleted file mode 100644 index d4887ff3..00000000 --- a/leetcode/solution/0600-0699/0690.Employee Importance/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [690. Employee Importance](https://leetcode.com/problems/employee-importance) - -[中文文档](/solution/0600-0699/0690.Employee%20Importance/README.md) - -## Description - -

    You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id.

    - -

    For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. They have importance value 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []]. Note that although employee 3 is also a subordinate of employee 1, the relationship is not direct.

    - -

    Now given the employee information of a company, and an employee id, you need to return the total importance value of this employee and all his subordinates.

    - -

    Example 1:

    - -
    -
    -Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1
    -
    -Output: 11
    -
    -Explanation:
    -
    -Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. One employee has at most one direct leader and may have several subordinates.
    2. -
    3. The maximum number of employees won't exceed 2000.
    4. -
    - -

     

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0695.Max Area of Island/README_EN.md b/leetcode/solution/0600-0699/0695.Max Area of Island/README_EN.md deleted file mode 100644 index 51399fe7..00000000 --- a/leetcode/solution/0600-0699/0695.Max Area of Island/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [695. Max Area of Island](https://leetcode.com/problems/max-area-of-island) - -[中文文档](/solution/0600-0699/0695.Max%20Area%20of%20Island/README.md) - -## Description - -

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    - -

    Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.)

    - -

    Example 1:

    - -
    -
    -[[0,0,1,0,0,0,0,1,0,0,0,0,0],
    -
    - [0,0,0,0,0,0,0,1,1,1,0,0,0],
    -
    - [0,1,1,0,1,0,0,0,0,0,0,0,0],
    -
    - [0,1,0,0,1,1,0,0,1,0,1,0,0],
    -
    - [0,1,0,0,1,1,0,0,1,1,1,0,0],
    -
    - [0,0,0,0,0,0,0,0,0,0,1,0,0],
    -
    - [0,0,0,0,0,0,0,1,1,1,0,0,0],
    -
    - [0,0,0,0,0,0,0,1,1,0,0,0,0]]
    -
    -
    - -Given the above grid, return 6. Note the answer is not 11, because the island must be connected 4-directionally. - -

    Example 2:

    - -
    -
    -[[0,0,0,0,0,0,0,0]]
    - -Given the above grid, return 0. - -

    Note: The length of each dimension in the given grid does not exceed 50.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0695.Max Area of Island/Solution.cpp b/leetcode/solution/0600-0699/0695.Max Area of Island/Solution.cpp deleted file mode 100644 index 6cc0a68f..00000000 --- a/leetcode/solution/0600-0699/0695.Max Area of Island/Solution.cpp +++ /dev/null @@ -1,51 +0,0 @@ -class Solution { -public: - bool v[55][55] = {0, } ; // ʱ - int maxAreaOfIsland(vector>& grid) - { - int maxAera = 0 ; - for (int i = 0; i < grid.size(); ++i) - { - if (0 == grid.size()) - { - return 0 ; - } - - for (int j = 0; j < grid[0].size(); ++j) - { - if (1 == grid[i][j] && !v[i][j]) - { - int cnt = calcAera(grid, i, j) ; - if (cnt > maxAera) - maxAera = cnt ; - } - } - } - return maxAera ; - } - - int calcAera(vector>& grid, int i, int j) - { - if (i < 0 || i >= grid.size()) - return 0 ; - if (j < 0 || j >= grid[0].size()) - return 0 ; - - if (v[i][j]) - return 0 ; - - v[i][j] = true ; - - - if (grid[i][j]) - { - return 1 - + calcAera(grid, i-1, j) - + calcAera(grid, i+1, j) - + calcAera(grid, i, j-1) - + calcAera(grid, i, j+1) ; - } - else - return 0 ; - } -} ; \ No newline at end of file diff --git a/leetcode/solution/0600-0699/0696.Count Binary Substrings/README_EN.md b/leetcode/solution/0600-0699/0696.Count Binary Substrings/README_EN.md deleted file mode 100644 index 9066db3e..00000000 --- a/leetcode/solution/0600-0699/0696.Count Binary Substrings/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [696. Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings) - -[中文文档](/solution/0600-0699/0696.Count%20Binary%20Substrings/README.md) - -## Description - -

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. - -

    - -

    Substrings that occur multiple times are counted the number of times they occur.

    - -

    Example 1:
    - -

    -
    -Input: "00110011"
    -
    -Output: 6
    -
    -Explanation: There are 6 substrings that have equal number of consecutive 1's and 0's: "0011", "01", "1100", "10", "0011", and "01".
    -
    -
    Notice that some of these substrings repeat and are counted the number of times they occur. - -
    Also, "00110011" is not a valid substring because all the 0's (and 1's) are not grouped together. - -
    - -

    - -

    Example 2:
    - -

    -
    -Input: "10101"
    -
    -Output: 4
    -
    -Explanation: There are 4 substrings: "10", "01", "10", "01" that have equal number of consecutive 1's and 0's.
    -
    -
    - -

    - -

    Note: - -

  • s.length will be between 1 and 50,000.
  • - -
  • s will only consist of "0" or "1" characters.
  • - -

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0697.Degree of an Array/README_EN.md b/leetcode/solution/0600-0699/0697.Degree of an Array/README_EN.md deleted file mode 100644 index dc639fea..00000000 --- a/leetcode/solution/0600-0699/0697.Degree of an Array/README_EN.md +++ /dev/null @@ -1,119 +0,0 @@ -# [697. Degree of an Array](https://leetcode.com/problems/degree-of-an-array) - -[中文文档](/solution/0600-0699/0697.Degree%20of%20an%20Array/README.md) - -## Description - -

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

    - -

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

    - -

    Example 1:
    - -

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

    - -

    Example 2:
    - -

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

    - -

    Note: - -

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

    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def findShortestSubArray(self, nums: List[int]) -> int: - mapper = {} - for i, v in enumerate(nums): - if v in mapper: - arr = mapper[v] - arr[0] += 1 - arr[2] = i - else: - arr = [1, i, i] - mapper[v] = arr - max_degree = min_len = 0 - for arr in mapper.values(): - if max_degree < arr[0]: - max_degree = arr[0] - min_len = arr[2] - arr[1] + 1 - elif max_degree == arr[0]: - min_len = min(min_len, arr[2] - arr[1] + 1) - return min_len -``` - -### **Java** - -```java -class Solution { - public int findShortestSubArray(int[] nums) { - Map mapper = new HashMap<>(); - for (int i = 0, n = nums.length; i < n; ++i) { - if (mapper.containsKey(nums[i])) { - int[] arr = mapper.get(nums[i]); - ++arr[0]; - arr[2] = i; - } else { - int[] arr = new int[]{1, i, i}; - mapper.put(nums[i], arr); - } - } - - int maxDegree = 0, minLen = 0; - for (Map.Entry entry : mapper.entrySet()) { - int[] arr = entry.getValue(); - if (maxDegree < arr[0]) { - maxDegree = arr[0]; - minLen = arr[2] - arr[1] + 1; - } else if (maxDegree == arr[0]) { - minLen = Math.min(minLen, arr[2] - arr[1] + 1); - } - } - return minLen; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0600-0699/0697.Degree of an Array/Solution.py b/leetcode/solution/0600-0699/0697.Degree of an Array/Solution.py deleted file mode 100644 index 29218856..00000000 --- a/leetcode/solution/0600-0699/0697.Degree of an Array/Solution.py +++ /dev/null @@ -1,19 +0,0 @@ -class Solution: - def findShortestSubArray(self, nums: List[int]) -> int: - mapper = {} - for i, v in enumerate(nums): - if v in mapper: - arr = mapper[v] - arr[0] += 1 - arr[2] = i - else: - arr = [1, i, i] - mapper[v] = arr - max_degree = min_len = 0 - for arr in mapper.values(): - if max_degree < arr[0]: - max_degree = arr[0] - min_len = arr[2] - arr[1] + 1 - elif max_degree == arr[0]: - min_len = min(min_len, arr[2] - arr[1] + 1) - return min_len diff --git a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md b/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md deleted file mode 100644 index 22dd978a..00000000 --- a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [700. Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree) - -[中文文档](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README.md) - -## Description - -

    Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL.

    - -

    For example, 

    - -
    -
    -Given the tree:
    -
    -        4
    -
    -       / \
    -
    -      2   7
    -
    -     / \
    -
    -    1   3
    -
    -
    -
    -And the value to search: 2
    -
    -
    - -

    You should return this subtree:

    - -
    -
    -      2     
    -
    -     / \   
    -
    -    1   3
    -
    -
    - -

    In the example above, if we want to search the value 5, since there is no node with value 5, we should return NULL.

    - -

    Note that an empty tree is represented by NULL, therefore you would see the expected output (serialized tree format) as [], not null.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.cpp b/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.cpp deleted file mode 100644 index 54619019..00000000 --- a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { - public: - TreeNode* searchBST(TreeNode* root, int val) { - - TreeNode* temp = root; - - while( temp != NULL ){ - if( temp->val == val ){ - return temp; - } - else if( val < temp->val ){ - temp = temp->left; - } - else{ - temp = temp->right; - } - } - - return NULL; - } -}; diff --git a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.py b/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.py deleted file mode 100644 index 9dae3630..00000000 --- a/leetcode/solution/0700-0799/0700.Search in a Binary Search Tree/Solution.py +++ /dev/null @@ -1,27 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -class Solution: - def searchBST(self, root, val): - """ - :type root: TreeNode - :type val: int - :rtype: TreeNode - """ - - temp = root - - while temp != None : - - if temp.val == val : - return temp - elif val < temp.val : - temp = temp.left - else: - temp = temp.right - - return None diff --git a/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md b/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md deleted file mode 100644 index f942d80e..00000000 --- a/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [701. Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree) - -[中文文档](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README.md) - -## Description - -

    Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

    - -

    Note that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

    - -

    For example, 

    - -
    -
    -Given the tree:
    -
    -        4
    -
    -       / \
    -
    -      2   7
    -
    -     / \
    -
    -    1   3
    -
    -And the value to insert: 5
    -
    -
    - -

    You can return this binary search tree:

    - -
    -
    -         4
    -
    -       /   \
    -
    -      2     7
    -
    -     / \   /
    -
    -    1   3 5
    -
    -
    - -

    This tree is also valid:

    - -
    -
    -         5
    -
    -       /   \
    -
    -      2     7
    -
    -     / \   
    -
    -    1   3
    -
    -         \
    -
    -          4
    -
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/Solution.py b/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/Solution.py deleted file mode 100644 index 118eaff9..00000000 --- a/leetcode/solution/0700-0799/0701.Insert into a Binary Search Tree/Solution.py +++ /dev/null @@ -1,51 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - -# 解法一 -class Solution: - def insertIntoBST(self, root, val): - """ - :type root: TreeNode - :type val: int - :rtype: TreeNode - """ - if not root: - return TreeNode(val) - if root.val < val: - if root.right: - self.insertIntoBST(root.right, val) - else: - root.right = TreeNode(val) - if root.val > val: - if root.left: - self.insertIntoBST(root.left, val) - else: - root.left = TreeNode(val) - return root - - -""" -# 解法二 -class Solution: - def insertIntoBST(self, root, val): - """ - : type root: TreeNode - : type val: int - : rtype: TreeNode - """ - if not root: - return TreeNode(val) - elif root.left is None: - root.left = TreeNode(root.val) - root.val = val - root.val, val = val, root.val - node = root.left - while node.right: - node = node.right - node.right = TreeNode(val) - return root -""" diff --git a/leetcode/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md b/leetcode/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md deleted file mode 100644 index e22a5200..00000000 --- a/leetcode/solution/0700-0799/0703.Kth Largest Element in a Stream/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [703. Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream) - -[中文文档](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README.md) - -## Description - -

    Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

    - -

    Your KthLargest class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method KthLargest.add, return the element representing the kth largest element in the stream.

    - -

    Example:

    - -
    -
    -int k = 3;
    -
    -int[] arr = [4,5,8,2];
    -
    -KthLargest kthLargest = new KthLargest(3, arr);
    -
    -kthLargest.add(3);   // returns 4
    -
    -kthLargest.add(5);   // returns 5
    -
    -kthLargest.add(10);  // returns 5
    -
    -kthLargest.add(9);   // returns 8
    -
    -kthLargest.add(4);   // returns 8
    -
    -
    - -

    Note:
    - -You may assume that nums' length ≥ k-1 and k ≥ 1.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0704.Binary Search/README_EN.md b/leetcode/solution/0700-0799/0704.Binary Search/README_EN.md deleted file mode 100644 index 4991553b..00000000 --- a/leetcode/solution/0700-0799/0704.Binary Search/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [704. Binary Search](https://leetcode.com/problems/binary-search) - -[中文文档](/solution/0700-0799/0704.Binary%20Search/README.md) - -## Description - -

    Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1.

    - -


    - -Example 1:

    - -
    -
    -Input: nums = [-1,0,3,5,9,12], target = 9
    -
    -Output: 4
    -
    -Explanation: 9 exists in nums and its index is 4
    -
    -
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: nums = [-1,0,3,5,9,12], target = 2
    -
    -Output: -1
    -
    -Explanation: 2 does not exist in nums so return -1
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. You may assume that all elements in nums are unique.
    2. -
    3. n will be in the range [1, 10000].
    4. -
    5. The value of each element in nums will be in the range [-9999, 9999].
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0704.Binary Search/Solution.py b/leetcode/solution/0700-0799/0704.Binary Search/Solution.py deleted file mode 100644 index 59040990..00000000 --- a/leetcode/solution/0700-0799/0704.Binary Search/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -''' -Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1. -''' - -# Perfomance -''' -Runtime: 268 ms, faster than 84.25% of Python3 online submissions for Binary Search. -Memory Usage: 14 MB, less than 100.00% of Python3 online submissions for Binary Search. -''' - - -class Solution: - def search(self, nums: List[int], target: int) -> int: - low, high = 0, len(nums) - 1 - while low <= high: - mid = low + (high - low) // 2 - if nums[mid] == target: - return mid - elif nums[mid] < target: - low = mid + 1 - else: - high = mid - 1 - return -1 diff --git a/leetcode/solution/0700-0799/0707.Design Linked List/README_EN.md b/leetcode/solution/0700-0799/0707.Design Linked List/README_EN.md deleted file mode 100644 index b24032ea..00000000 --- a/leetcode/solution/0700-0799/0707.Design Linked List/README_EN.md +++ /dev/null @@ -1,231 +0,0 @@ -# [707. Design Linked List](https://leetcode.com/problems/design-linked-list) - -[中文文档](/solution/0700-0799/0707.Design%20Linked%20List/README.md) - -## Description - -

    Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node. If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.

    - -

    Implement these functions in your linked list class:

    - -
      -
    • get(index) : Get the value of the index-th node in the linked list. If the index is invalid, return -1.
    • -
    • addAtHead(val) : Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
    • -
    • addAtTail(val) : Append a node of value val to the last element of the linked list.
    • -
    • addAtIndex(index, val) : Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.
    • -
    • deleteAtIndex(index) : Delete the index-th node in the linked list, if the index is valid.
    • -
    - -

     

    - -

    Example:

    - -
    -Input: 
    -["MyLinkedList","addAtHead","addAtTail","addAtIndex","get","deleteAtIndex","get"]
    -[[],[1],[3],[1,2],[1],[1],[1]]
    -Output:  
    -[null,null,null,null,2,null,3]
    -
    -Explanation:
    -MyLinkedList linkedList = new MyLinkedList(); // Initialize empty LinkedList
    -linkedList.addAtHead(1);
    -linkedList.addAtTail(3);
    -linkedList.addAtIndex(1, 2);  // linked list becomes 1->2->3
    -linkedList.get(1);            // returns 2
    -linkedList.deleteAtIndex(1);  // now the linked list is 1->3
    -linkedList.get(1);            // returns 3
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 0 <= index,val <= 1000
    • -
    • Please do not use the built-in LinkedList library.
    • -
    • At most 2000 calls will be made to getaddAtHeadaddAtTailaddAtIndex and deleteAtIndex.
    • -
    - -## Solutions - - - -### **Python3** - -```python -class ListNode: - - def __init__(self, val=0, next=None): - self.val = val - self.next = next - - -class MyLinkedList: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.dummy = ListNode() - self.count = 0 - - - def get(self, index: int) -> int: - """ - Get the value of the index-th node in the linked list. If the index is invalid, return -1. - """ - if index < 0 or index >= self.count: - return -1 - cur = self.dummy.next - for _ in range(index): - cur = cur.next - return cur.val - - - def addAtHead(self, val: int) -> None: - """ - Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. - """ - self.addAtIndex(0, val) - - - def addAtTail(self, val: int) -> None: - """ - Append a node of value val to the last element of the linked list. - """ - self.addAtIndex(self.count, val) - - - def addAtIndex(self, index: int, val: int) -> None: - """ - Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. - """ - if index > self.count: - return - pre = self.dummy - for _ in range(index): - pre = pre.next - pre.next = ListNode(val, pre.next) - self.count += 1 - - - def deleteAtIndex(self, index: int) -> None: - """ - Delete the index-th node in the linked list, if the index is valid. - """ - if index < 0 or index >= self.count: - return - pre = self.dummy - for _ in range(index): - pre = pre.next - t = pre.next - pre.next = t.next - t.next = None - self.count -= 1 - - - -# Your MyLinkedList object will be instantiated and called as such: -# obj = MyLinkedList() -# param_1 = obj.get(index) -# obj.addAtHead(val) -# obj.addAtTail(val) -# obj.addAtIndex(index,val) -# obj.deleteAtIndex(index) -``` - -### **Java** - -```java -class MyLinkedList { - - private class ListNode { - int val; - ListNode next; - ListNode(int val) { - this(val, null); - } - ListNode(int val, ListNode next) { - this.val = val; - this.next = next; - } - } - - private ListNode dummy; - private int count; - - /** Initialize your data structure here. */ - public MyLinkedList() { - dummy = new ListNode(0); - count = 0; - } - - /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */ - public int get(int index) { - if (index < 0 || index >= count) { - return -1; - } - ListNode cur = dummy.next; - while (index-- > 0) { - cur = cur.next; - } - return cur.val; - } - - /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */ - public void addAtHead(int val) { - addAtIndex(0, val); - } - - /** Append a node of value val to the last element of the linked list. */ - public void addAtTail(int val) { - addAtIndex(count, val); - } - - /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */ - public void addAtIndex(int index, int val) { - if (index > count) { - return; - } - ListNode pre = dummy; - while (index-- > 0) { - pre = pre.next; - } - pre.next = new ListNode(val, pre.next); - ++count; - } - - /** Delete the index-th node in the linked list, if the index is valid. */ - public void deleteAtIndex(int index) { - if (index < 0 || index >= count) { - return; - } - ListNode pre = dummy; - while (index-- > 0) { - pre = pre.next; - } - ListNode t = pre.next; - pre.next = t.next; - t.next = null; - --count; - } -} - -/** - * Your MyLinkedList object will be instantiated and called as such: - * MyLinkedList obj = new MyLinkedList(); - * int param_1 = obj.get(index); - * obj.addAtHead(val); - * obj.addAtTail(val); - * obj.addAtIndex(index,val); - * obj.deleteAtIndex(index); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0707.Design Linked List/Solution.py b/leetcode/solution/0700-0799/0707.Design Linked List/Solution.py deleted file mode 100644 index 13f27206..00000000 --- a/leetcode/solution/0700-0799/0707.Design Linked List/Solution.py +++ /dev/null @@ -1,79 +0,0 @@ -class ListNode: - - def __init__(self, val=0, next=None): - self.val = val - self.next = next - - -class MyLinkedList: - - def __init__(self): - """ - Initialize your data structure here. - """ - self.dummy = ListNode() - self.count = 0 - - - def get(self, index: int) -> int: - """ - Get the value of the index-th node in the linked list. If the index is invalid, return -1. - """ - if index < 0 or index >= self.count: - return -1 - cur = self.dummy.next - for _ in range(index): - cur = cur.next - return cur.val - - - def addAtHead(self, val: int) -> None: - """ - Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. - """ - self.addAtIndex(0, val) - - - def addAtTail(self, val: int) -> None: - """ - Append a node of value val to the last element of the linked list. - """ - self.addAtIndex(self.count, val) - - - def addAtIndex(self, index: int, val: int) -> None: - """ - Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. - """ - if index > self.count: - return - pre = self.dummy - for _ in range(index): - pre = pre.next - pre.next = ListNode(val, pre.next) - self.count += 1 - - - def deleteAtIndex(self, index: int) -> None: - """ - Delete the index-th node in the linked list, if the index is valid. - """ - if index < 0 or index >= self.count: - return - pre = self.dummy - for _ in range(index): - pre = pre.next - t = pre.next - pre.next = t.next - t.next = None - self.count -= 1 - - - -# Your MyLinkedList object will be instantiated and called as such: -# obj = MyLinkedList() -# param_1 = obj.get(index) -# obj.addAtHead(val) -# obj.addAtTail(val) -# obj.addAtIndex(index,val) -# obj.deleteAtIndex(index) \ No newline at end of file diff --git a/leetcode/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md b/leetcode/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md deleted file mode 100644 index 4b2cb733..00000000 --- a/leetcode/solution/0700-0799/0718.Maximum Length of Repeated Subarray/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [718. Maximum Length of Repeated Subarray](https://leetcode.com/problems/maximum-length-of-repeated-subarray) - -[中文文档](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README.md) - -## Description - -

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.

    - -

    Example 1:

    - -
    -
    -Input:
    -
    -A: [1,2,3,2,1]
    -
    -B: [3,2,1,4,7]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -The repeated subarray with maximum length is [3, 2, 1].
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= len(A), len(B) <= 1000
    2. -
    3. 0 <= A[i], B[i] < 100
    4. -
    - -

     

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0724.Find Pivot Index/README_EN.md b/leetcode/solution/0700-0799/0724.Find Pivot Index/README_EN.md deleted file mode 100644 index ce0166a8..00000000 --- a/leetcode/solution/0700-0799/0724.Find Pivot Index/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [724. Find Pivot Index](https://leetcode.com/problems/find-pivot-index) - -[中文文档](/solution/0700-0799/0724.Find%20Pivot%20Index/README.md) - -## Description - -

    Given an array of integers nums, write a method that returns the "pivot" index of this array.

    - -

    We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.

    - -

    If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.

    - -

    Example 1:

    - -
    -
    -Input: 
    -
    -nums = [1, 7, 3, 6, 5, 6]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -The sum of the numbers to the left of index 3 (nums[3] = 6) is equal to the sum of numbers to the right of index 3.
    -
    -Also, 3 is the first index where this occurs.
    -
    -
    - -

     

    - -

    Example 2:

    - -
    -
    -Input: 
    -
    -nums = [1, 2, 3]
    -
    -Output: -1
    -
    -Explanation: 
    -
    -There is no index that satisfies the conditions in the problem statement.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • The length of nums will be in the range [0, 10000].
    • -
    • Each element nums[i] will be an integer in the range [-1000, 1000].
    • -
    - -

     

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md b/leetcode/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md deleted file mode 100644 index 7920e1cd..00000000 --- a/leetcode/solution/0700-0799/0725.Split Linked List in Parts/README_EN.md +++ /dev/null @@ -1,111 +0,0 @@ -# [725. Split Linked List in Parts](https://leetcode.com/problems/split-linked-list-in-parts) - -[中文文档](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README.md) - -## Description - -

    Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts". - -

    - -The length of each part should be as equal as possible: no two parts should have a size differing by more than 1. This may lead to some parts being null. - -

    - -The parts should be in order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal parts occurring later. - -

    - -Return a List of ListNode's representing the linked list parts that are formed. - -

    - -Examples - -1->2->3->4, k = 5 // 5 equal parts - -[ [1], - -[2], - -[3], - -[4], - -null ] - -

    Example 1:
    - -

    -
    -Input: 
    -
    -root = [1, 2, 3], k = 5
    -
    -Output: [[1],[2],[3],[],[]]
    -
    -Explanation:
    -
    -The input and each element of the output are ListNodes, not arrays.
    -
    -For example, the input root has root.val = 1, root.next.val = 2, \root.next.next.val = 3, and root.next.next.next = null.
    -
    -The first element output[0] has output[0].val = 1, output[0].next = null.
    -
    -The last element output[4] is null, but it's string representation as a ListNode is [].
    -
    -
    - -

    - -

    Example 2:
    - -

    -
    -Input: 
    -
    -root = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3
    -
    -Output: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
    -
    -Explanation:
    -
    -The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.
    -
    -
    - -

    - -

    Note: - -

  • The length of root will be in the range [0, 1000].
  • - -
  • Each value of a node in the input will be an integer in the range [0, 999].
  • - -
  • k will be an integer in the range [1, 50].
  • - -

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0739.Daily Temperatures/README_EN.md b/leetcode/solution/0700-0799/0739.Daily Temperatures/README_EN.md deleted file mode 100644 index 0a5b6a24..00000000 --- a/leetcode/solution/0700-0799/0739.Daily Temperatures/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [739. Daily Temperatures](https://leetcode.com/problems/daily-temperatures) - -[中文文档](/solution/0700-0799/0739.Daily%20Temperatures/README.md) - -## Description - -

    - -Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead. - -

    - -For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0]. - -

    - -

    Note: - -The length of temperatures will be in the range [1, 30000]. - -Each temperature will be an integer in the range [30, 100]. - -

    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def dailyTemperatures(self, T: List[int]) -> List[int]: - n = len(T) - res = [0 for _ in range(n)] - s = [] - for i in range(n): - while s and T[s[-1]] < T[i]: - j = s.pop() - res[j] = i - j - s.append(i) - return res -``` - -### **Java** - -```java -class Solution { - public int[] dailyTemperatures(int[] T) { - int n = T.length; - int[] res = new int[n]; - Deque s = new ArrayDeque<>(); - for (int i = 0; i < n; ++i) { - while (!s.isEmpty() && T[s.peek()] < T[i]) { - int j = s.pop(); - res[j] = i - j; - } - s.push(i); - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0739.Daily Temperatures/Solution.py b/leetcode/solution/0700-0799/0739.Daily Temperatures/Solution.py deleted file mode 100644 index 1d2ba55e..00000000 --- a/leetcode/solution/0700-0799/0739.Daily Temperatures/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def dailyTemperatures(self, T: List[int]) -> List[int]: - n = len(T) - res = [0 for _ in range(n)] - s = [] - for i in range(n): - while s and T[s[-1]] < T[i]: - j = s.pop() - res[j] = i - j - s.append(i) - return res diff --git a/leetcode/solution/0700-0799/0740.Delete and Earn/README_EN.md b/leetcode/solution/0700-0799/0740.Delete and Earn/README_EN.md deleted file mode 100644 index 5e0ff491..00000000 --- a/leetcode/solution/0700-0799/0740.Delete and Earn/README_EN.md +++ /dev/null @@ -1,122 +0,0 @@ -# [740. Delete and Earn](https://leetcode.com/problems/delete-and-earn) - -[中文文档](/solution/0700-0799/0740.Delete%20and%20Earn/README.md) - -## Description - -

    Given an array nums of integers, you can perform operations on the array.

    - -

    In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to nums[i] - 1 or nums[i] + 1.

    - -

    You start with 0 points. Return the maximum number of points you can earn by applying such operations.

    - -

    Example 1:

    - -
    -
    -Input: nums = [3, 4, 2]
    -
    -Output: 6
    -
    -Explanation: 
    -
    -Delete 4 to earn 4 points, consequently 3 is also deleted.
    -
    -Then, delete 2 to earn 2 points. 6 total points are earned.
    -
    -
    - -

     

    - -

    Example 2:

    - -
    -
    -Input: nums = [2, 2, 3, 3, 3, 4]
    -
    -Output: 9
    -
    -Explanation: 
    -
    -Delete 3 to earn 3 points, deleting both 2's and the 4.
    -
    -Then, delete 3 again to earn 3 points, and 3 again to earn 3 points.
    -
    -9 total points are earned.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • The length of nums is at most 20000.
    • -
    • Each element nums[i] is an integer in the range [1, 10000].
    • -
    - -

     

    - -## Solutions - - - -Intuition: **If we take a number, we will take all of the copies of it**. - -First calculate the sum of each number as **sums**, and keep updating two dp arrays: **select** and **nonSelect** - -- sums[i] represents the sum of elements whose value is i; -- select[i] represents the maximum sum of processing from 0 to i if the number i is selected; -- nonSelect[i] represents the maximum sum of processing from 0 to i if the number i is not selected; - -Then we have the following conclusions: - -- If i is selected, then i-1 must not be selected; -- If you do not choose i, then i-1 can choose or not, so we choose the larger one; - -```java -select[i] = nonSelect[i-1] + sums[i]; -nonSelect[i] = Math.max(select[i-1], nonSelect[i-1]); -``` - -### **Python3** - -```python - -``` - -### **Java** - -```java -class Solution { - public int deleteAndEarn(int[] nums) { - if (nums.length == 0) { - return 0; - } - - int[] sums = new int[10010]; - int[] select = new int[10010]; - int[] nonSelect = new int[10010]; - - int maxV = 0; - for (int x : nums) { - sums[x] += x; - maxV = Math.max(maxV, x); - } - - for (int i = 1; i <= maxV; i++) { - select[i] = nonSelect[i - 1] + sums[i]; - nonSelect[i] = Math.max(select[i - 1], nonSelect[i - 1]); - } - return Math.max(select[maxV], nonSelect[maxV]); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md b/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md deleted file mode 100644 index 30ff39ad..00000000 --- a/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md +++ /dev/null @@ -1,96 +0,0 @@ -# [746. Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs) - -[中文文档](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md) - -## Description - -

    - -On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). - -

    - -Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1. - -

    - -

    Example 1:
    - -

    -
    -Input: cost = [10, 15, 20]
    -
    -Output: 15
    -
    -Explanation: Cheapest is start on cost[1], pay that cost and go to the top.
    -
    -
    - -

    - -

    Example 2:
    - -

    -
    -Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
    -
    -Output: 6
    -
    -Explanation: Cheapest is start on cost[0], and only step on 1s, skipping cost[3].
    -
    -
    - -

    - -

    Note:
    - -

      - -
    1. cost will have a length in the range [2, 1000].
    2. - -
    3. Every cost[i] will be an integer in the range [0, 999].
    4. - -
    - -

    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def minCostClimbingStairs(self, cost: List[int]) -> int: - pre = cur = 0 - n = len(cost) - for i in range(1, n): - t = min(cost[i] + cur, cost[i - 1] + pre) - pre, cur = cur, t - return cur -``` - -### **Java** - -```java -class Solution { - public int minCostClimbingStairs(int[] cost) { - int pre = 0, cur = 0; - for (int i = 1, n = cost.length; i < n; ++i) { - int t = Math.min(cost[i] + cur, cost[i - 1] + pre); - pre = cur; - cur = t; - } - return cur; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.py b/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.py deleted file mode 100644 index a3786603..00000000 --- a/leetcode/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def minCostClimbingStairs(self, cost: List[int]) -> int: - pre = cur = 0 - n = len(cost) - for i in range(1, n): - t = min(cost[i] + cur, cost[i - 1] + pre) - pre, cur = cur, t - return cur diff --git a/leetcode/solution/0700-0799/0752.Open the Lock/README_EN.md b/leetcode/solution/0700-0799/0752.Open the Lock/README_EN.md deleted file mode 100644 index 4b8d8369..00000000 --- a/leetcode/solution/0700-0799/0752.Open the Lock/README_EN.md +++ /dev/null @@ -1,125 +0,0 @@ -# [752. Open the Lock](https://leetcode.com/problems/open-the-lock) - -[中文文档](/solution/0700-0799/0752.Open%20the%20Lock/README.md) - -## Description - -

    - -You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot. - -

    - -The lock initially starts at '0000', a string representing the state of the 4 wheels. - -

    - -You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it. - -

    - -Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible. - -

    - -

    Example 1:
    - -

    -
    -Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
    -
    -Output: 6
    -
    -Explanation:
    -
    -A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
    -
    -Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
    -
    -because the wheels of the lock become stuck after the display becomes the dead end "0102".
    -
    -
    - -

    - -

    Example 2:
    - -

    -
    -Input: deadends = ["8888"], target = "0009"
    -
    -Output: 1
    -
    -Explanation:
    -
    -We can turn the last wheel in reverse to move from "0000" -> "0009".
    -
    -
    - -

    - -

    Example 3:
    - -

    -
    -Input: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"
    -
    -Output: -1
    -
    -Explanation:
    -
    -We can't reach the target without getting stuck.
    -
    -
    - -

    - -

    Example 4:
    - -

    -
    -Input: deadends = ["0000"], target = "8888"
    -
    -Output: -1
    -
    -
    - -

    - -

    Note:
    - -

      - -
    1. The length of deadends will be in the range [1, 500].
    2. - -
    3. target will not be in the list deadends.
    4. - -
    5. Every string in deadends and the string target will be a string of 4 digits from the 10,000 possibilities '0000' to '9999'.
    6. - -
    - -

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md b/leetcode/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md deleted file mode 100644 index 984b979c..00000000 --- a/leetcode/solution/0700-0799/0760.Find Anagram Mappings/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [760. Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings) - -[中文文档](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README.md) - -## Description - -

    -Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing the order of the elements in A. -

    -We want to find an index mapping P, from A to B. A mapping P[i] = j means the ith element in A appears in B at index j. -

    -These lists A and B may contain duplicates. If there are multiple answers, output any of them. -

    - -

    -For example, given -

    -A = [12, 28, 46, 32, 50]
    -B = [50, 12, 32, 46, 28]
    -
    -

    -We should return -
    -[1, 4, 3, 2, 0]
    -
    -as P[0] = 1 because the 0th element of A appears at B[1], -and P[1] = 4 because the 1st element of A appears at B[4], -and so on. -

    - -

    Note:

      -
    1. A, B have equal lengths in range [1, 100].
    2. -
    3. A[i], B[i] are integers in range [0, 10^5].
    4. -

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0760.Find Anagram Mappings/Solution.py b/leetcode/solution/0700-0799/0760.Find Anagram Mappings/Solution.py deleted file mode 100644 index 076e9a6a..00000000 --- a/leetcode/solution/0700-0799/0760.Find Anagram Mappings/Solution.py +++ /dev/null @@ -1,9 +0,0 @@ -class Solution: - def anagramMappings(self, A, B): - """ - :type A: List[int] - :type B: List[int] - :rtype: List[int] - """ - record = {val: i for i, val in enumerate(B)} - return [record[val] for val in A] \ No newline at end of file diff --git a/leetcode/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md b/leetcode/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md deleted file mode 100644 index 348c081b..00000000 --- a/leetcode/solution/0700-0799/0766.Toeplitz Matrix/README_EN.md +++ /dev/null @@ -1,123 +0,0 @@ -# [766. Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix) - -[中文文档](/solution/0700-0799/0766.Toeplitz%20Matrix/README.md) - -## Description - -

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.

    - -

    Now given an M x N matrix, return True if and only if the matrix is Toeplitz.
    - - 

    - -

    Example 1:

    - -
    -
    -Input:
    -
    -matrix = [
    -
    -  [1,2,3,4],
    -
    -  [5,1,2,3],
    -
    -  [9,5,1,2]
    -
    -]
    -
    -Output: True
    -
    -Explanation:
    -
    -In the above grid, the diagonals are:
    -
    -"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
    -
    -In each diagonal all elements are the same, so the answer is True.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input:
    -
    -matrix = [
    -
    -  [1,2],
    -
    -  [2,2]
    -
    -]
    -
    -Output: False
    -
    -Explanation:
    -
    -The diagonal "[1, 2]" has different elements.
    -
    -
    - -


    - -Note:

    - -
      -
    1. matrix will be a 2D array of integers.
    2. -
    3. matrix will have a number of rows and columns in range [1, 20].
    4. -
    5. matrix[i][j] will be integers in range [0, 99].
    6. -
    - -


    - -Follow up:

    - -
      -
    1. What if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?
    2. -
    3. What if the matrix is so large that you can only load up a partial row into the memory at once?
    4. -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: - m, n = len(matrix), len(matrix[0]) - for i in range(1, m): - for j in range(1, n): - if matrix[i][j] != matrix[i - 1][j - 1]: - return False - return True -``` - -### **Java** - -```java -class Solution { - public boolean isToeplitzMatrix(int[][] matrix) { - int m = matrix.length, n = matrix[0].length; - for (int i = 1; i < m; ++i) { - for (int j = 1; j < n; ++j) { - if (matrix[i][j] != matrix[i - 1][j - 1]) { - return false; - } - } - } - return true; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0766.Toeplitz Matrix/Solution.py b/leetcode/solution/0700-0799/0766.Toeplitz Matrix/Solution.py deleted file mode 100644 index 4f5f378d..00000000 --- a/leetcode/solution/0700-0799/0766.Toeplitz Matrix/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: - m, n = len(matrix), len(matrix[0]) - for i in range(1, m): - for j in range(1, n): - if matrix[i][j] != matrix[i - 1][j - 1]: - return False - return True diff --git a/leetcode/solution/0700-0799/0771.Jewels and Stones/README_EN.md b/leetcode/solution/0700-0799/0771.Jewels and Stones/README_EN.md deleted file mode 100644 index cf5a8e3f..00000000 --- a/leetcode/solution/0700-0799/0771.Jewels and Stones/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [771. Jewels and Stones](https://leetcode.com/problems/jewels-and-stones) - -[中文文档](/solution/0700-0799/0771.Jewels%20and%20Stones/README.md) - -## Description - -

    You're given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in S is a type of stone you have.  You want to know how many of the stones you have are also jewels.

    - -

    The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

    - -

    Example 1:

    - -
    -
    -Input: J = "aA", S = "aAAbbbb"
    -
    -Output: 3
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: J = "z", S = "ZZ"
    -
    -Output: 0
    -
    -
    - -

    Note:

    - -
      -
    • S and J will consist of letters and have length at most 50.
    • -
    • The characters in J are distinct.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.cpp b/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.cpp deleted file mode 100644 index 030ad28f..00000000 --- a/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - int numJewelsInStones(string J, string S) { - std::unordered_map count; - int number = 0; - for(char c: J) count[c]++; - for(char c: S){ - if(count.find(c)!=count.end()) - number++; - } - return number; - } -}; diff --git a/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.py b/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.py deleted file mode 100644 index abf69946..00000000 --- a/leetcode/solution/0700-0799/0771.Jewels and Stones/Solution.py +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - def numJewelsInStones(self, J: str, S: str) -> int: - record = {ch for ch in J} - sum = 0 - for ch in S: - sum += 1 if ch in record else 0 - return sum \ No newline at end of file diff --git a/leetcode/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md b/leetcode/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md deleted file mode 100644 index 50188bac..00000000 --- a/leetcode/solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md +++ /dev/null @@ -1,62 +0,0 @@ -# [777. Swap Adjacent in LR String](https://leetcode.com/problems/swap-adjacent-in-lr-string) - -[中文文档](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md) - -## Description - -

    In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

    - -

    Example:

    - -
    -
    -Input: start = "RXXLRXRXL", end = "XRLXXRRLX"
    -
    -Output: True
    -
    -Explanation:
    -
    -We can transform start to end following these steps:
    -
    -RXXLRXRXL ->
    -
    -XRXLRXRXL ->
    -
    -XRLXRXRXL ->
    -
    -XRLXXRRXL ->
    -
    -XRLXXRRLX
    -
    -
    - -

    Note:

    - -
      -
    1. 1 <= len(start) = len(end) <= 10000.
    2. -
    3. Both start and end will only consist of characters in {'L', 'R', 'X'}.
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md b/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md deleted file mode 100644 index ea46f0c9..00000000 --- a/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [783. Minimum Distance Between BST Nodes](https://leetcode.com/problems/minimum-distance-between-bst-nodes) - -[中文文档](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README.md) - -## Description - -

    Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree.

    - -

    Example :

    - -
    -Input: root = [4,2,6,1,3,null,null]
    -Output: 1
    -Explanation:
    -Note that root is a TreeNode object, not an array.
    -
    -The given tree [4,2,6,1,3,null,null] is represented by the following diagram:
    -
    -          4
    -        /   \
    -      2      6
    -     / \    
    -    1   3  
    -
    -while the minimum difference in this tree is 1, it occurs between node 1 and node 2, also between node 3 and node 2.
    -
    - -

    Note:

    - -
      -
    1. The size of the BST will be between 2 and 100.
    2. -
    3. The BST is always valid, each node's value is an integer, and each node's value is different.
    4. -
    5. This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.go b/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.go deleted file mode 100644 index a270c12d..00000000 --- a/leetcode/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.go +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Definition for a binary tree node. - * type TreeNode struct { - * Val int - * Left *TreeNode - * Right *TreeNode - * } - */ - -var res int -var preNode *TreeNode -func minDiffInBST(root *TreeNode) int { - res = int(^uint(0) >> 1) - preNode = nil - helper(root) - return res -} - -func helper(root *TreeNode) { - if root == nil { - return - } - helper(root.Left) - if preNode != nil { - res = getMinInt(res, root.Val - preNode.Val) - } - preNode = root - helper(root.Right) -} - -func getMinInt(a,b int) int { - if a < b { - return a - } - return b -} \ No newline at end of file diff --git a/leetcode/solution/0700-0799/0784.Letter Case Permutation/README_EN.md b/leetcode/solution/0700-0799/0784.Letter Case Permutation/README_EN.md deleted file mode 100644 index ce21d64c..00000000 --- a/leetcode/solution/0700-0799/0784.Letter Case Permutation/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [784. Letter Case Permutation](https://leetcode.com/problems/letter-case-permutation) - -[中文文档](/solution/0700-0799/0784.Letter%20Case%20Permutation/README.md) - -## Description - -

    Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.  Return a list of all possible strings we could create.

    - -
    -
    -Examples:
    -
    -Input: S = "a1b2"
    -
    -Output: ["a1b2", "a1B2", "A1b2", "A1B2"]
    -
    -
    -
    -Input: S = "3z4"
    -
    -Output: ["3z4", "3Z4"]
    -
    -
    -
    -Input: S = "12345"
    -
    -Output: ["12345"]
    -
    -
    - -

    Note:

    - -
      -
    • S will be a string with length between 1 and 12.
    • -
    • S will consist only of letters or digits.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md b/leetcode/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md deleted file mode 100644 index 962649bd..00000000 --- a/leetcode/solution/0800-0899/0814.Binary Tree Pruning/README_EN.md +++ /dev/null @@ -1,86 +0,0 @@ -# [814. Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning) - -[中文文档](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README.md) - -## Description - -

    We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.

    - -

    Return the same tree where every subtree (of the given tree) not containing a 1 has been removed.

    - -

    (Recall that the subtree of a node X is X, plus every node that is a descendant of X.)

    - -
    -
    -Example 1:
    -
    -Input: [1,null,0,0,1]
    -
    -Output: [1,null,0,null,1]
    -
    - 
    -
    -Explanation: 
    -
    -Only the red nodes satisfy the property "every subtree not containing a 1".
    -
    -The diagram on the right represents the answer.
    -
    -
    - -![](./images/1028_2.png) - -
    -
    -Example 2:
    -
    -Input: [1,0,1,0,0,0,1]
    -
    -Output: [1,null,1,null,1]
    -
    -
    - -![](./images/1028_1.png) - -
    -
    -Example 3:
    -
    -Input: [1,1,0,1,1,0,1,0]
    -
    -Output: [1,1,0,1,1,null,1]
    -
    -
    - -![](./images/1028.png) - -

    Note:

    - -
      -
    • The binary tree will have at most 100 nodes.
    • -
    • The value of each node will only be 0 or 1.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0817.Linked List Components/README_EN.md b/leetcode/solution/0800-0899/0817.Linked List Components/README_EN.md deleted file mode 100644 index 39dac477..00000000 --- a/leetcode/solution/0800-0899/0817.Linked List Components/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [817. Linked List Components](https://leetcode.com/problems/linked-list-components) - -[中文文档](/solution/0800-0899/0817.Linked%20List%20Components/README.md) - -## Description - -

    We are given head, the head node of a linked list containing unique integer values.

    - -

    We are also given the list G, a subset of the values in the linked list.

    - -

    Return the number of connected components in G, where two values are connected if they appear consecutively in the linked list.

    - -

    Example 1:

    - -
    -
    -Input: 
    -
    -head: 0->1->2->3
    -
    -G = [0, 1, 3]
    -
    -Output: 2
    -
    -Explanation: 
    -
    -0 and 1 are connected, so [0, 1] and [3] are the two connected components.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: 
    -
    -head: 0->1->2->3->4
    -
    -G = [0, 3, 1, 4]
    -
    -Output: 2
    -
    -Explanation: 
    -
    -0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components.
    -
    -
    - -

    Note:

    - -
      -
    • If N is the length of the linked list given by head1 <= N <= 10000.
    • -
    • The value of each node in the linked list will be in the range [0, N - 1].
    • -
    • 1 <= G.length <= 10000.
    • -
    • G is a subset of all values in the linked list.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0817.Linked List Components/Solution.py b/leetcode/solution/0800-0899/0817.Linked List Components/Solution.py deleted file mode 100644 index 5ba61691..00000000 --- a/leetcode/solution/0800-0899/0817.Linked List Components/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - - -class Solution: - def numComponents(self, head, G): - """ - :type head: ListNode - :type G: List[int] - :rtype: int - """ - dic = set(G) - ans = 0 - flag = 0 - while head: - if head.val not in dic: - if flag == 1: - ans += 1 - flag = 0 - else: - flag = 1 - head = head.next - else: - if flag == 1: - ans += 1 - return ans diff --git a/leetcode/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md b/leetcode/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md deleted file mode 100644 index cf835507..00000000 --- a/leetcode/solution/0800-0899/0829.Consecutive Numbers Sum/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [829. Consecutive Numbers Sum](https://leetcode.com/problems/consecutive-numbers-sum) - -[中文文档](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README.md) - -## Description - -

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers?

    - -

    Example 1:

    - -
    -
    -Input: 5
    -
    -Output: 2
    -
    -Explanation: 5 = 5 = 2 + 3
    - -

    Example 2:

    - -
    -
    -Input: 9
    -
    -Output: 3
    -
    -Explanation: 9 = 9 = 4 + 5 = 2 + 3 + 4
    - -

    Example 3:

    - -
    -
    -Input: 15
    -
    -Output: 4
    -
    -Explanation: 15 = 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5
    - -

    Note: 1 <= N <= 10 ^ 9.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0832.Flipping an Image/README_EN.md b/leetcode/solution/0800-0899/0832.Flipping an Image/README_EN.md deleted file mode 100644 index 836e633d..00000000 --- a/leetcode/solution/0800-0899/0832.Flipping an Image/README_EN.md +++ /dev/null @@ -1,126 +0,0 @@ -# [832. Flipping an Image](https://leetcode.com/problems/flipping-an-image) - -[中文文档](/solution/0800-0899/0832.Flipping%20an%20Image/README.md) - -## Description - -

    Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.

    - -

    To flip an image horizontally means that each row of the image is reversed.  For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].

    - -

    To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0, 1, 1] results in [1, 0, 0].

    - -

    Example 1:

    - -
    -
    -Input: [[1,1,0],[1,0,1],[0,0,0]]
    -
    -Output: [[1,0,0],[0,1,0],[1,1,1]]
    -
    -Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
    -
    -Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
    -
    -Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
    -
    -Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
    -
    -Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
    -
    -
    - -

    Notes:

    - -
      -
    • 1 <= A.length = A[0].length <= 20
    • -
    • 0 <= A[i][j] <= 1
    • -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]: - m, n = len(A), len(A[0]) - for i in range(m): - p, q = 0, n - 1 - while p < q: - t = A[i][p] ^ 1 - A[i][p] = A[i][q] ^ 1 - A[i][q] = t - p += 1 - q -= 1 - if p == q: - A[i][p] ^= 1 - return A -``` - -### **Java** - -```java -class Solution { - public int[][] flipAndInvertImage(int[][] A) { - int m = A.length, n = A[0].length; - for (int i = 0; i < m; ++i) { - int p = 0, q = n - 1; - while (p < q) { - int t = A[i][p] ^ 1; - A[i][p] = A[i][q] ^ 1; - A[i][q] = t; - ++p; - --q; - } - if (p == q) { - A[i][p] ^= 1; - } - } - return A; - } -} -``` - -### **C++** - -```cpp -class Solution { -public: - vector> flipAndInvertImage(vector>& A) { - int m = A.size(), n = A[0].size(); - for (int i = 0; i < m; ++i) { - int p = 0, q = n - 1; - while (p < q) { - int t = A[i][p] ^ 1; - A[i][p] = A[i][q] ^ 1; - A[i][q] = t; - ++p; - --q; - } - if (p == q) { - A[i][p] ^= 1; - } - } - return A; - } -}; -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.cpp b/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.cpp deleted file mode 100644 index f4f26ced..00000000 --- a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - vector> flipAndInvertImage(vector>& A) { - int m = A.size(), n = A[0].size(); - for (int i = 0; i < m; ++i) { - int p = 0, q = n - 1; - while (p < q) { - int t = A[i][p] ^ 1; - A[i][p] = A[i][q] ^ 1; - A[i][q] = t; - ++p; - --q; - } - if (p == q) { - A[i][p] ^= 1; - } - } - return A; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.js b/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.js deleted file mode 100644 index 6c56bf76..00000000 --- a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @param {number[][]} A - * @return {number[][]} - */ - -/** - * Author: Mcnwork2018 - */ - -// 第一种思路,碰到相等的情况才进行取反 -var flipAndInvertImage = function (A) { - const len = A.length; - for (let k = 0; k < len; k++) { - let j = len - 1; - for (let i = 0; i <= ~~(j / 2); i++) { - if (A[k][i] === A[k][j - i]) { - A[k][i] === 1 - ? (A[k][i] = A[k][j - i] = 0) - : (A[k][i] = A[k][j - i] = 1); - } - } - } - return A; -}; -// 第二种思路,无论是否相等,对每个值都进行交换并取反 -var flipAndInvertImage2 = function (A) { - for (let i = 0; i < A.length; ++i) { - let last = A[i].length - 1; - for (let j = 0; j <= ~~(last / 2); ++j) { - [A[i][j], A[i][last - j]] = [A[i][last - j] ^ 1, A[i][j] ^ 1]; - } - } - return A; -}; diff --git a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.py b/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.py deleted file mode 100644 index 181b61aa..00000000 --- a/leetcode/solution/0800-0899/0832.Flipping an Image/Solution.py +++ /dev/null @@ -1,14 +0,0 @@ -class Solution: - def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]: - m, n = len(A), len(A[0]) - for i in range(m): - p, q = 0, n - 1 - while p < q: - t = A[i][p] ^ 1 - A[i][p] = A[i][q] ^ 1 - A[i][q] = t - p += 1 - q -= 1 - if p == q: - A[i][p] ^= 1 - return A diff --git a/leetcode/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md b/leetcode/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md deleted file mode 100644 index 0713f5ea..00000000 --- a/leetcode/solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [852. Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) - -[中文文档](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README.md) - -## Description - -

    Let's call an array A a mountain if the following properties hold:

    - -
      -
    • A.length >= 3
    • -
    • There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
    • -
    - -

    Given an array that is definitely a mountain, return any i such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1].

    - -

    Example 1:

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

    Example 2:

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

    Note:

    - -
      -
    1. 3 <= A.length <= 10000
    2. -
    3. 0 <= A[i] <= 10^6
    4. -
    5. A is a mountain, as defined above.
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0856.Score of Parentheses/README_EN.md b/leetcode/solution/0800-0899/0856.Score of Parentheses/README_EN.md deleted file mode 100644 index d0a095ad..00000000 --- a/leetcode/solution/0800-0899/0856.Score of Parentheses/README_EN.md +++ /dev/null @@ -1,104 +0,0 @@ -# [856. Score of Parentheses](https://leetcode.com/problems/score-of-parentheses) - -[中文文档](/solution/0800-0899/0856.Score%20of%20Parentheses/README.md) - -## Description - -

    Given a balanced parentheses string S, compute the score of the string based on the following rule:

    - -
      -
    • () has score 1
    • -
    • AB has score A + B, where A and B are balanced parentheses strings.
    • -
    • (A) has score 2 * A, where A is a balanced parentheses string.
    • -
    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: "()"
    -
    -Output: 1
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: "(())"
    -
    -Output: 2
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: "()()"
    -
    -Output: 2
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: "(()(()))"
    -
    -Output: 6
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. S is a balanced parentheses string, containing only ( and ).
    2. -
    3. 2 <= S.length <= 50
    4. -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md b/leetcode/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md deleted file mode 100644 index 857ded32..00000000 --- a/leetcode/solution/0800-0899/0857.Minimum Cost to Hire K Workers/README_EN.md +++ /dev/null @@ -1,89 +0,0 @@ -# [857. Minimum Cost to Hire K Workers](https://leetcode.com/problems/minimum-cost-to-hire-k-workers) - -[中文文档](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README.md) - -## Description - -

    There are N workers.  The i-th worker has a quality[i] and a minimum wage expectation wage[i].

    - -

    Now we want to hire exactly K workers to form a paid group.  When hiring a group of K workers, we must pay them according to the following rules:

    - -
      -
    1. Every worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.
    2. -
    3. Every worker in the paid group must be paid at least their minimum wage expectation.
    4. -
    - -

    Return the least amount of money needed to form a paid group satisfying the above conditions.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: quality = [10,20,5], wage = [70,50,30], K = 2
    -
    -Output: 105.00000
    -
    -Explanation: We pay 70 to 0-th worker and 35 to 2-th worker.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], K = 3
    -
    -Output: 30.66667
    -
    -Explanation: We pay 4 to 0-th worker, 13.33333 to 2-th and 3-th workers seperately. 
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= K <= N <= 10000, where N = quality.length = wage.length
    2. -
    3. 1 <= quality[i] <= 10000
    4. -
    5. 1 <= wage[i] <= 10000
    6. -
    7. Answers within 10^-5 of the correct answer will be considered correct.
    8. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0860.Lemonade Change/README_EN.md b/leetcode/solution/0800-0899/0860.Lemonade Change/README_EN.md deleted file mode 100644 index 912c8b1b..00000000 --- a/leetcode/solution/0800-0899/0860.Lemonade Change/README_EN.md +++ /dev/null @@ -1,126 +0,0 @@ -# [860. Lemonade Change](https://leetcode.com/problems/lemonade-change) - -[中文文档](/solution/0800-0899/0860.Lemonade%20Change/README.md) - -## Description - -

    At a lemonade stand, each lemonade costs $5

    - -

    Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).

    - -

    Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.  You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.

    - -

    Note that you don't have any change in hand at first.

    - -

    Return true if and only if you can provide every customer with correct change.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [5,5,5,10,20]
    -
    -Output: true
    -
    -Explanation: 
    -
    -From the first 3 customers, we collect three $5 bills in order.
    -
    -From the fourth customer, we collect a $10 bill and give back a $5.
    -
    -From the fifth customer, we give a $10 bill and a $5 bill.
    -
    -Since all customers got correct change, we output true.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [5,5,10]
    -
    -Output: true
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: [10,10]
    -
    -Output: false
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: [5,5,10,10,20]
    -
    -Output: false
    -
    -Explanation: 
    -
    -From the first two customers in order, we collect two $5 bills.
    -
    -For the next two customers in order, we collect a $10 bill and give back a $5 bill.
    -
    -For the last customer, we can't give change of $15 back because we only have two $10 bills.
    -
    -Since not every customer received correct change, the answer is false.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 0 <= bills.length <= 10000
    • -
    • bills[i] will be either 5, 10, or 20.
    • -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md b/leetcode/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md deleted file mode 100644 index 6b341e0b..00000000 --- a/leetcode/solution/0800-0899/0862.Shortest Subarray with Sum at Least K/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [862. Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k) - -[中文文档](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README.md) - -## Description - -

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.

    - -

    If there is no non-empty subarray with sum at least K, return -1.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: A = [1], K = 1
    -
    -Output: 1
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: A = [1,2], K = 4
    -
    -Output: -1
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: A = [2,-1,2], K = 3
    -
    -Output: 3
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 50000
    2. -
    3. -10 ^ 5 <= A[i] <= 10 ^ 5
    4. -
    5. 1 <= K <= 10 ^ 9
    6. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md b/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md deleted file mode 100644 index aba2f7a1..00000000 --- a/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [872. Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) - -[中文文档](/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md) - -## Description - -

    Consider all the leaves of a binary tree.  From left to right order, the values of those leaves form a leaf value sequence.

    - -![](./images/tree.png) - -

    For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).

    - -

    Two binary trees are considered leaf-similar if their leaf value sequence is the same.

    - -

    Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.

    - -

     

    - -

    Note:

    - -
      -
    • Both of the given trees will have between 1 and 100 nodes.
    • -
    - -## Solutions - - - -### **Python3** - -```python -# 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 leafSimilar(self, root1: TreeNode, root2: TreeNode) -> bool: - def dfs(root, leaves): - if root is None: - return - if root.left is None and root.right is None: - leaves.append(root.val) - return - dfs(root.left, leaves) - dfs(root.right, leaves) - l1, l2 = [], [] - dfs(root1, l1) - dfs(root2, l2) - return l1 == l2 -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode() {} - * TreeNode(int val) { this.val = val; } - * TreeNode(int val, TreeNode left, TreeNode right) { - * this.val = val; - * this.left = left; - * this.right = right; - * } - * } - */ -class Solution { - public boolean leafSimilar(TreeNode root1, TreeNode root2) { - List l1 = new ArrayList<>(); - List l2 = new ArrayList<>(); - dfs(root1, l1); - dfs(root2, l2); - return l1.equals(l2); - } - - private void dfs(TreeNode root, List leaves) { - if (root == null) return; - if (root.left == null && root.right == null) { - leaves.add(root.val); - return; - } - dfs(root.left, leaves); - dfs(root.right, leaves); - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/Solution.py b/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/Solution.py deleted file mode 100644 index de3602c2..00000000 --- a/leetcode/solution/0800-0899/0872.Leaf-Similar Trees/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -# 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 leafSimilar(self, root1: TreeNode, root2: TreeNode) -> bool: - def dfs(root, leaves): - if root is None: - return - if root.left is None and root.right is None: - leaves.append(root.val) - return - dfs(root.left, leaves) - dfs(root.right, leaves) - l1, l2 = [], [] - dfs(root1, l1) - dfs(root2, l2) - return l1 == l2 diff --git a/leetcode/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md b/leetcode/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md deleted file mode 100644 index ea704101..00000000 --- a/leetcode/solution/0800-0899/0875.Koko Eating Bananas/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas) - -[中文文档](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md) - -## Description - -

    Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours.

    - -

    Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, and eats K bananas from that pile.  If the pile has less than K bananas, she eats all of them instead, and won't eat any more bananas during this hour.

    - -

    Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back.

    - -

    Return the minimum integer K such that she can eat all the bananas within H hours.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: piles = [3,6,7,11], H = 8
    -
    -Output: 4
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: piles = [30,11,23,4,20], H = 5
    -
    -Output: 30
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: piles = [30,11,23,4,20], H = 6
    -
    -Output: 23
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 1 <= piles.length <= 10^4
    • -
    • piles.length <= H <= 10^9
    • -
    • 1 <= piles[i] <= 10^9
    • -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0876.Middle of the Linked List/README_EN.md b/leetcode/solution/0800-0899/0876.Middle of the Linked List/README_EN.md deleted file mode 100644 index 961cebe2..00000000 --- a/leetcode/solution/0800-0899/0876.Middle of the Linked List/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list) - -[中文文档](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md) - -## Description - -

    Given a non-empty, singly linked list with head node head, return a middle node of linked list.

    - -

    If there are two middle nodes, return the second middle node.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [1,2,3,4,5]
    -
    -Output: Node 3 from this list (Serialization: [3,4,5])
    -
    -The returned node has value 3.  (The judge's serialization of this node is [3,4,5]).
    -
    -Note that we returned a ListNode object ans, such that:
    -
    -ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [1,2,3,4,5,6]
    -
    -Output: Node 4 from this list (Serialization: [4,5,6])
    -
    -Since the list has two middle nodes with values 3 and 4, we return the second one.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • The number of nodes in the given list will be between 1 and 100.
    • -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0876.Middle of the Linked List/Solution.py b/leetcode/solution/0800-0899/0876.Middle of the Linked List/Solution.py deleted file mode 100644 index facf3eb3..00000000 --- a/leetcode/solution/0800-0899/0876.Middle of the Linked List/Solution.py +++ /dev/null @@ -1,23 +0,0 @@ -# Definition for singly-linked list. -# class ListNode: -# def __init__(self, x): -# self.val = x -# self.next = None - -class Solution: - def middleNode(self, head): - """ - :type head: ListNode - :rtype: ListNode - """ - if not head: - return None - if not head.next: - return head - fast=head - slow=head - while fast.next: - fast=fast.next.next - slow=slow.next - if not fast or not fast.next: - return slow \ No newline at end of file diff --git a/leetcode/solution/0800-0899/0878.Nth Magical Number/README_EN.md b/leetcode/solution/0800-0899/0878.Nth Magical Number/README_EN.md deleted file mode 100644 index 90761c59..00000000 --- a/leetcode/solution/0800-0899/0878.Nth Magical Number/README_EN.md +++ /dev/null @@ -1,105 +0,0 @@ -# [878. Nth Magical Number](https://leetcode.com/problems/nth-magical-number) - -[中文文档](/solution/0800-0899/0878.Nth%20Magical%20Number/README.md) - -## Description - -

    A positive integer is magical if it is divisible by either A or B.

    - -

    Return the N-th magical number.  Since the answer may be very large, return it modulo 10^9 + 7.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: N = 1, A = 2, B = 3
    -
    -Output: 2
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: N = 4, A = 2, B = 3
    -
    -Output: 6
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: N = 5, A = 2, B = 4
    -
    -Output: 10
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: N = 3, A = 6, B = 4
    -
    -Output: 8
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= N <= 10^9
    2. -
    3. 2 <= A <= 40000
    4. -
    5. 2 <= B <= 40000
    6. -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md b/leetcode/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md deleted file mode 100644 index 2a775ece..00000000 --- a/leetcode/solution/0800-0899/0883.Projection Area of 3D Shapes/README_EN.md +++ /dev/null @@ -1,216 +0,0 @@ -# [883. Projection Area of 3D Shapes](https://leetcode.com/problems/projection-area-of-3d-shapes) - -[中文文档](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README.md) - -## Description - -

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes.

    - -

    Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).

    - -

    Now we view the projection of these cubes onto the xy, yz, and zx planes.

    - -

    A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane. 

    - -

    Here, we are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

    - -

    Return the total area of all three projections.

    - -

     

    - -
    - -
      - -
    - -
    - -
    - -
    - -
      - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
      - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
      - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: [[2]]
    -
    -Output: 5
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [[1,2],[3,4]]
    -
    -Output: 17
    -
    -Explanation: 
    -
    -Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
    -
    -
    - -![](./images/shadow.png) - -
    - -

    Example 3:

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

    Example 4:

    - -
    -
    -Input: [[1,1,1],[1,0,1],[1,1,1]]
    -
    -Output: 14
    -
    -
    - -
    - -

    Example 5:

    - -
    -
    -Input: [[2,2,2],[2,1,2],[2,2,2]]
    -
    -Output: 21
    -
    -
    - -

     

    - -
    - -
    - -
    - -

    Note:

    - -
      -
    • 1 <= grid.length = grid[0].length <= 50
    • -
    • 0 <= grid[i][j] <= 50
    • -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0887.Super Egg Drop/README_EN.md b/leetcode/solution/0800-0899/0887.Super Egg Drop/README_EN.md deleted file mode 100644 index 01057cb9..00000000 --- a/leetcode/solution/0800-0899/0887.Super Egg Drop/README_EN.md +++ /dev/null @@ -1,108 +0,0 @@ -# [887. Super Egg Drop](https://leetcode.com/problems/super-egg-drop) - -[中文文档](/solution/0800-0899/0887.Super%20Egg%20Drop/README.md) - -## Description - -

    You are given K eggs, and you have access to a building with N floors from 1 to N

    - -

    Each egg is identical in function, and if an egg breaks, you cannot drop it again.

    - -

    You know that there exists a floor F with 0 <= F <= N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break.

    - -

    Each move, you may take an egg (if you have an unbroken one) and drop it from any floor X (with 1 <= X <= N). 

    - -

    Your goal is to know with certainty what the value of F is.

    - -

    What is the minimum number of moves that you need to know with certainty what F is, regardless of the initial value of F?

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: K = 1, N = 2
    -
    -Output: 2
    -
    -Explanation: 
    -
    -Drop the egg from floor 1.  If it breaks, we know with certainty that F = 0.
    -
    -Otherwise, drop the egg from floor 2.  If it breaks, we know with certainty that F = 1.
    -
    -If it didn't break, then we know with certainty F = 2.
    -
    -Hence, we needed 2 moves in the worst case to know what F is with certainty.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: K = 2, N = 6
    -
    -Output: 3
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: K = 3, N = 14
    -
    -Output: 4
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= K <= 100
    2. -
    3. 1 <= N <= 10000
    4. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0887.Super Egg Drop/Solution.py b/leetcode/solution/0800-0899/0887.Super Egg Drop/Solution.py deleted file mode 100644 index 9de58c9b..00000000 --- a/leetcode/solution/0800-0899/0887.Super Egg Drop/Solution.py +++ /dev/null @@ -1,8 +0,0 @@ -class Solution: - def superEggDrop(self, K: int, N: int) -> int: - dp = [1] * (K) - while dp[K - 1] < N: - for i in range(K - 1, 0, -1): - dp[i] = dp[i] + dp[i - 1] + 1 - dp[0] = dp[0] + 1 - return dp[0] diff --git a/leetcode/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md b/leetcode/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md deleted file mode 100644 index 830738a5..00000000 --- a/leetcode/solution/0800-0899/0891.Sum of Subsequence Widths/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [891. Sum of Subsequence Widths](https://leetcode.com/problems/sum-of-subsequence-widths) - -[中文文档](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README.md) - -## Description - -

    Given an array of integers A, consider all non-empty subsequences of A.

    - -

    For any sequence S, let the width of S be the difference between the maximum and minimum element of S.

    - -

    Return the sum of the widths of all subsequences of A. 

    - -

    As the answer may be very large, return the answer modulo 10^9 + 7.

    - -
    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [2,1,3]
    -
    -Output: 6
    -
    -Explanation:
    -
    -Subsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].
    -
    -The corresponding widths are 0, 0, 0, 1, 1, 2, 2.
    -
    -The sum of these widths is 6.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 1 <= A.length <= 20000
    • -
    • 1 <= A[i] <= 20000
    • -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md b/leetcode/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md deleted file mode 100644 index 1238bcd3..00000000 --- a/leetcode/solution/0800-0899/0892.Surface Area of 3D Shapes/README_EN.md +++ /dev/null @@ -1,132 +0,0 @@ -# [892. Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) - -[中文文档](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README.md) - -## Description - -

    On a N * N grid, we place some 1 * 1 * 1 cubes.

    - -

    Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).

    - -

    Return the total surface area of the resulting shapes.

    - -

     

    - -
    - -
    - -
    - -
      - -
    - -
    - -
    - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: [[2]]
    -
    -Output: 10
    -
    -
    - -
    - -

    Example 2:

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

    Example 3:

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

    Example 4:

    - -
    -
    -Input: [[1,1,1],[1,0,1],[1,1,1]]
    -
    -Output: 32
    -
    -
    - -
    - -

    Example 5:

    - -
    -
    -Input: [[2,2,2],[2,1,2],[2,2,2]]
    -
    -Output: 46
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 1 <= N <= 50
    • -
    • 0 <= grid[i][j] <= 50
    • -
    - -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md b/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md deleted file mode 100644 index c409714a..00000000 --- a/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/README_EN.md +++ /dev/null @@ -1,124 +0,0 @@ -# [897. Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) - -[中文文档](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md) - -## Description - -

    Given a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.

    - -
    -Example 1:
    -Input: [5,3,6,2,4,null,8,1,null,null,null,7,9]
    -
    -       5
    -      / \
    -    3    6
    -   / \    \
    -  2   4    8
    - /        / \ 
    -1        7   9
    -
    -Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]
    -
    - 1
    -  \
    -   2
    -    \
    -     3
    -      \
    -       4
    -        \
    -         5
    -          \
    -           6
    -            \
    -             7
    -              \
    -               8
    -                \
    -                 9  
    -

     

    -

    Constraints:

    - -
      -
    • The number of nodes in the given tree will be between 1 and 100.
    • -
    • Each node will have a unique integer value from 0 to 1000.
    • -
    - -## Solutions - -See [17.12. BiNode](/lcci/17.12.BiNode/README_EN.md). - - - -### **Python3** - -```python -# 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: - if root is None: - return None - left = self.increasingBST(root.left) - right = self.increasingBST(root.right) - if left is None: - root.right = right - return root - res = left - while left and left.right: - left = left.right - left.right = root - root.right = right - root.left = None - return res -``` - -### **Java** - -```java -/** - * Definition for a binary tree node. - * public class TreeNode { - * int val; - * TreeNode left; - * TreeNode right; - * TreeNode() {} - * TreeNode(int val) { this.val = val; } - * TreeNode(int val, TreeNode left, TreeNode right) { - * this.val = val; - * this.left = left; - * this.right = right; - * } - * } - */ -class Solution { - public TreeNode increasingBST(TreeNode root) { - if (root == null) return null; - TreeNode left = increasingBST(root.left); - TreeNode right = increasingBST(root.right); - if (left == null) { - root.right = right; - return root; - } - TreeNode res = left; - while (left != null && left.right != null) left = left.right; - left.right = root; - root.right = right; - root.left = null; - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/Solution.py b/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/Solution.py deleted file mode 100644 index 56a13943..00000000 --- a/leetcode/solution/0800-0899/0897.Increasing Order Search Tree/Solution.py +++ /dev/null @@ -1,22 +0,0 @@ -# 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: - if root is None: - return None - left = self.increasingBST(root.left) - right = self.increasingBST(root.right) - if left is None: - root.right = right - return root - res = left - while left and left.right: - left = left.right - left.right = root - root.right = right - root.left = None - return res diff --git a/leetcode/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md b/leetcode/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md deleted file mode 100644 index 483b9f7d..00000000 --- a/leetcode/solution/0800-0899/0898.Bitwise ORs of Subarrays/README_EN.md +++ /dev/null @@ -1,104 +0,0 @@ -# [898. Bitwise ORs of Subarrays](https://leetcode.com/problems/bitwise-ors-of-subarrays) - -[中文文档](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README.md) - -## Description - -

    We have an array A of non-negative integers.

    - -

    For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].

    - -

    Return the number of possible results.  (Results that occur more than once are only counted once in the final answer.)

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [0]
    -
    -Output: 1
    -
    -Explanation: 
    -
    -There is only one possible result: 0.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [1,1,2]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].
    -
    -These yield the results 1, 1, 2, 1, 3, 3.
    -
    -There are 3 unique values, so the answer is 3.
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: [1,2,4]
    -
    -Output: 6
    -
    -Explanation: 
    -
    -The possible results are 1, 2, 3, 4, 6, and 7.
    -
    -
    - -
    - -
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 50000
    2. -
    3. 0 <= A[i] <= 10^9
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0912.Sort an Array/README_EN.md b/leetcode/solution/0900-0999/0912.Sort an Array/README_EN.md deleted file mode 100644 index debf05e2..00000000 --- a/leetcode/solution/0900-0999/0912.Sort an Array/README_EN.md +++ /dev/null @@ -1,47 +0,0 @@ -# [912. Sort an Array](https://leetcode.com/problems/sort-an-array) - -[中文文档](/solution/0900-0999/0912.Sort%20an%20Array/README.md) - -## Description - -

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

    - -

     

    -

    Example 1:

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

    Example 2:

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

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 50000
    • -
    • -50000 <= nums[i] <= 50000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md b/leetcode/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md deleted file mode 100644 index d94d2072..00000000 --- a/leetcode/solution/0900-0999/0918.Maximum Sum Circular Subarray/README_EN.md +++ /dev/null @@ -1,122 +0,0 @@ -# [918. Maximum Sum Circular Subarray](https://leetcode.com/problems/maximum-sum-circular-subarray) - -[中文文档](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md) - -## Description - -

    Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C.

    - -

    Here, a circular array means the end of the array connects to the beginning of the array.  (Formally, C[i] = A[i] when 0 <= i < A.length, and C[i+A.length] = C[i] when i >= 0.)

    - -

    Also, a subarray may only include each element of the fixed buffer A at most once.  (Formally, for a subarray C[i], C[i+1], ..., C[j], there does not exist i <= k1, k2 <= j with k1 % A.length = k2 % A.length.)

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [1,-2,3,-2]
    -
    -Output: 3
    -
    -Explanation: Subarray [3] has maximum sum 3
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [5,-3,5]
    -
    -Output: 10
    -
    -Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: [3,-1,2,-1]
    -
    -Output: 4
    -
    -Explanation: Subarray [2,-1,3] has maximum sum 2 + (-1) + 3 = 4
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: [3,-2,2,-3]
    -
    -Output: 3
    -
    -Explanation: Subarray [3] and [3,-2,2] both have maximum sum 3
    -
    -
    - -

    Example 5:

    - -
    -
    -Input: [-2,-3,-1]
    -
    -Output: -1
    -
    -Explanation: Subarray [-1] has maximum sum -1
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. -30000 <= A[i] <= 30000
    2. -
    3. 1 <= A.length <= 30000
    4. -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md b/leetcode/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md deleted file mode 100644 index e4c9cdbc..00000000 --- a/leetcode/solution/0900-0999/0922.Sort Array By Parity II/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [922. Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) - -[中文文档](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README.md) - -## Description - -

    Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.

    - -

    Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even.

    - -

    You may return any answer array that satisfies this condition.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [4,2,5,7]
    -
    -Output: [4,5,2,7]
    -
    -Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 2 <= A.length <= 20000
    2. -
    3. A.length % 2 == 0
    4. -
    5. 0 <= A[i] <= 1000
    6. -
    - -
    - -

     

    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0922.Sort Array By Parity II/Solution.js b/leetcode/solution/0900-0999/0922.Sort Array By Parity II/Solution.js deleted file mode 100644 index 8b6e6c63..00000000 --- a/leetcode/solution/0900-0999/0922.Sort Array By Parity II/Solution.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @param {number[]} A - * @return {number[]} - */ - -/** - * Author: Mcnwork2018 - */ - -var sortArrayByParityII = function (A) { - let index = A.length - 1, - i = 0, - j = 1; // index A的索引, i偶数位, j奇数位。 - for (; i < index; i += 2) { - if ((A[i] & 1) != 0) { - // 寻找A[i]是奇数的情况。 - while ((A[j] & 1) != 0) { - // 寻找A[j]是偶数的情况。 - j += 2; - } - let temp = A[j]; - A[j] = A[i]; - A[i] = temp; - } - } - return A; -}; diff --git a/leetcode/solution/0900-0999/0929.Unique Email Addresses/README_EN.md b/leetcode/solution/0900-0999/0929.Unique Email Addresses/README_EN.md deleted file mode 100644 index 4c8127a2..00000000 --- a/leetcode/solution/0900-0999/0929.Unique Email Addresses/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [929. Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) - -[中文文档](/solution/0900-0999/0929.Unique%20Email%20Addresses/README.md) - -## Description - -

    Every email consists of a local name and a domain name, separated by the @ sign.

    - -

    For example, in alice@leetcode.comalice is the local name, and leetcode.com is the domain name.

    - -

    Besides lowercase letters, these emails may contain '.'s or '+'s.

    - -

    If you add periods ('.') between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name.  For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.  (Note that this rule does not apply for domain names.)

    - -

    If you add a plus ('+') in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com.  (Again, this rule does not apply for domain names.)

    - -

    It is possible to use both of these rules at the same time.

    - -

    Given a list of emails, we send one email to each address in the list.  How many different addresses actually receive mails? 

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
    -
    -Output: 2
    -
    -Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 1 <= emails[i].length <= 100
    • -
    • 1 <= emails.length <= 100
    • -
    • Each emails[i] contains exactly one '@' character.
    • -
    • All local and domain names are non-empty.
    • -
    • Local names do not start with a '+' character.
    • -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.js b/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.js deleted file mode 100644 index cb7aeb5c..00000000 --- a/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.js +++ /dev/null @@ -1,40 +0,0 @@ -const numUniqueEmails2 = function (emails) { - const emailFilter = function (str) { - let index = str.search(/@/); - let s = str.substring(0, index); - let s2 = str.substring(index + 1, str.length); - let res = ""; - for (let i = 0; i < s.length; i++) { - if (s[i] === "+") break; - if (s[i] === ".") continue; - res = res + s[i]; - } - return res + s2; - }; - - let arr = []; - for (let i = 0; i < emails.length; i++) { - let t = emailFilter(emails[i]); - if (arr.indexOf(t) === -1) { - arr.push(t); - } - } - return arr.length; -}; - -const numUniqueEmails = function (emails) { - let arr = emails.map((str) => { - let index = str.search(/@/); - let s = str.substring(0, index); - let s2 = str.substring(index + 1, str.length); - let res = ""; - for (let i = 0; i < s.length; i++) { - if (s[i] === "+") break; - if (s[i] === ".") continue; - res = res + s[i]; - } - return res + s2; - }); - let set = new Set(arr); - return set.size; -}; diff --git a/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.py b/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.py deleted file mode 100644 index 0452142e..00000000 --- a/leetcode/solution/0900-0999/0929.Unique Email Addresses/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def numUniqueEmails(self, emails): - """ - :type emails: List[str] - :rtype: int - """ - E = {} - for each in emails: - local_name, domain = each.split('@') - local_name = local_name.split('+')[0].replace('.', '') - E[local_name + '@' + domain] = 0 - - return len(E) diff --git a/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md b/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md deleted file mode 100644 index ee54e7d4..00000000 --- a/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum) - -[中文文档](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README.md) - -## Description - -

    In an array A of 0s and 1s, how many non-empty subarrays have sum S?

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: A = [1,0,1,0,1], S = 2
    -
    -Output: 4
    -
    -Explanation: 
    -
    -The 4 subarrays are bolded below:
    -
    -[1,0,1,0,1]
    -
    -[1,0,1,0,1]
    -
    -[1,0,1,0,1]
    -
    -[1,0,1,0,1]
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. A.length <= 30000
    2. -
    3. 0 <= S <= A.length
    4. -
    5. A[i] is either 0 or 1.
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/Solution.js b/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/Solution.js deleted file mode 100644 index 6d619a5f..00000000 --- a/leetcode/solution/0900-0999/0930.Binary Subarrays With Sum/Solution.js +++ /dev/null @@ -1,26 +0,0 @@ -const numSubarrayWithSum = function (A, S) { - let count = 0; - for (let i = 0; i < A.length; i++) { - if (A[i] === 1) count++; - } - if (S > count) return 0; - let count2 = 0; - let res = 0; - for (let i = 0; i < A.length; i++) { - if (S > count - count2) break; - let t = 0; - for (let j = i; j < A.length; j++) { - t += A[j]; - if (t === S) { - res++; - for (let k = j + 1; k < A.length; k++) { - if (A[k] === 0) res++; - else break; - } - break; - } - } - if (A[i] === 1) count2++; - } - return res; -}; diff --git a/leetcode/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md b/leetcode/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md deleted file mode 100644 index 0321e9b5..00000000 --- a/leetcode/solution/0900-0999/0931.Minimum Falling Path Sum/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [931. Minimum Falling Path Sum](https://leetcode.com/problems/minimum-falling-path-sum) - -[中文文档](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md) - -## Description - -

    Given a square array of integers A, we want the minimum sum of a falling path through A.

    - -

    A falling path starts at any element in the first row, and chooses one element from each row.  The next row's choice must be in a column that is different from the previous row's column by at most one.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [[1,2,3],[4,5,6],[7,8,9]]
    -
    -Output: 12
    -
    -Explanation: 
    -
    -The possible falling paths are:
    -
    -
    - -
      -
    • [1,4,7], [1,4,8], [1,5,7], [1,5,8], [1,5,9]
    • -
    • [2,4,7], [2,4,8], [2,5,7], [2,5,8], [2,5,9], [2,6,8], [2,6,9]
    • -
    • [3,5,7], [3,5,8], [3,5,9], [3,6,8], [3,6,9]
    • -
    - -

    The falling path with the smallest sum is [1,4,7], so the answer is 12.

    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length == A[0].length <= 100
    2. -
    3. -100 <= A[i][j] <= 100
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0933.Number of Recent Calls/README_EN.md b/leetcode/solution/0900-0999/0933.Number of Recent Calls/README_EN.md deleted file mode 100644 index 6101d4a1..00000000 --- a/leetcode/solution/0900-0999/0933.Number of Recent Calls/README_EN.md +++ /dev/null @@ -1,101 +0,0 @@ -# [933. Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) - -[中文文档](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md) - -## Description - -

    Write a class RecentCounter to count recent requests.

    - -

    It has only one method: ping(int t), where t represents some time in milliseconds.

    - -

    Return the number of pings that have been made from 3000 milliseconds ago until now.

    - -

    Any ping with time in [t - 3000, t] will count, including the current ping.

    - -

    It is guaranteed that every call to ping uses a strictly larger value of t than before.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: inputs = ["RecentCounter","ping","ping","ping","ping"], inputs = [[],[1],[100],[3001],[3002]]
    -
    -Output: [null,1,2,3,3]
    - -

     

    - -

    Note:

    - -
      -
    1. Each test case will have at most 10000 calls to ping.
    2. -
    3. Each test case will call ping with strictly increasing values of t.
    4. -
    5. Each call to ping will have 1 <= t <= 10^9.
    6. -
    - -
    - -

     

    - -
    - -## Solutions - - - -### **Python3** - -```python -class RecentCounter: - - def __init__(self): - self.q = [] - - - def ping(self, t: int) -> int: - self.q.append(t) - while self.q[0] < t - 3000: - self.q.pop(0) - return len(self.q) - - -# Your RecentCounter object will be instantiated and called as such: -# obj = RecentCounter() -# param_1 = obj.ping(t) -``` - -### **Java** - -```java -class RecentCounter { - - private Deque q; - - public RecentCounter() { - q = new ArrayDeque<>(); - } - - public int ping(int t) { - q.offerLast(t); - while (q.peekFirst() < t - 3000) { - q.pollFirst(); - } - return q.size(); - } -} - -/** - * Your RecentCounter object will be instantiated and called as such: - * RecentCounter obj = new RecentCounter(); - * int param_1 = obj.ping(t); - */ -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0933.Number of Recent Calls/Solution.py b/leetcode/solution/0900-0999/0933.Number of Recent Calls/Solution.py deleted file mode 100644 index eee073e6..00000000 --- a/leetcode/solution/0900-0999/0933.Number of Recent Calls/Solution.py +++ /dev/null @@ -1,16 +0,0 @@ -class RecentCounter: - - def __init__(self): - self.q = [] - - - def ping(self, t: int) -> int: - self.q.append(t) - while self.q[0] < t - 3000: - self.q.pop(0) - return len(self.q) - - -# Your RecentCounter object will be instantiated and called as such: -# obj = RecentCounter() -# param_1 = obj.ping(t) \ No newline at end of file diff --git a/leetcode/solution/0900-0999/0938.Range Sum of BST/README_EN.md b/leetcode/solution/0900-0999/0938.Range Sum of BST/README_EN.md deleted file mode 100644 index 329b683a..00000000 --- a/leetcode/solution/0900-0999/0938.Range Sum of BST/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [938. Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) - -[中文文档](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README.md) - -## Description - -

    Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).

    - -

    The binary search tree is guaranteed to have unique values.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: root = [10,5,15,3,7,null,18], L = 7, R = 15
    -
    -Output: 32
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: root = [10,5,15,3,7,13,18,1,null,6], L = 6, R = 10
    -
    -Output: 23
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. The number of nodes in the tree is at most 10000.
    2. -
    3. The final answer is guaranteed to be less than 2^31.
    4. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.cpp b/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.cpp deleted file mode 100644 index d0ae1884..00000000 --- a/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { -public: - int rangeSumBST(TreeNode* root, int L, int R) { - if (nullptr == root) - return 0 ; - stack s ; - s.push(root) ; - int sum = 0 ; - while (!s.empty()) - { - TreeNode *node = s.top() ; - s.pop() ; - - if (nullptr == node) - continue ; - - if (node->val > R) - s.push(node->left) ; - else if (node->val < L) - s.push(node->right) ; - else - { - sum += node->val ; - s.push(node->left) ; - s.push(node->right) ; - } - } - - return sum ; - } -}; - -static int x = []() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - return 0; -}() ; diff --git a/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.py b/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.py deleted file mode 100644 index 980074a1..00000000 --- a/leetcode/solution/0900-0999/0938.Range Sum of BST/Solution.py +++ /dev/null @@ -1,30 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - - -class Solution: - def rangeSumBST(self, root, L, R): - """ - :type root: TreeNode - :type L: int - :type R: int - :rtype: int - """ - def searchBST(node): - if not node: - return - if L <= node.val <= R: - self.ans += node.val - searchBST(node.right) - searchBST(node.left) - elif node.val < L: - searchBST(node.right) - elif node.val > R: - searchBST(node.left) - self.ans = 0 - searchBST(root) - return self.ans diff --git a/leetcode/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md b/leetcode/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md deleted file mode 100644 index ca29a282..00000000 --- a/leetcode/solution/0900-0999/0946.Validate Stack Sequences/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [946. Validate Stack Sequences](https://leetcode.com/problems/validate-stack-sequences) - -[中文文档](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README.md) - -## Description - -

    Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
    -
    -Output: true
    -
    -Explanation: We might do the following sequence:
    -
    -push(1), push(2), push(3), push(4), pop() -> 4,
    -
    -push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
    -
    -Output: false
    -
    -Explanation: 1 cannot be popped before 2.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 0 <= pushed.length == popped.length <= 1000
    2. -
    3. 0 <= pushed[i], popped[i] < 1000
    4. -
    5. pushed is a permutation of popped.
    6. -
    7. pushed and popped have distinct values.
    8. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md b/leetcode/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md deleted file mode 100644 index e7b74bfd..00000000 --- a/leetcode/solution/0900-0999/0952.Largest Component Size by Common Factor/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [952. Largest Component Size by Common Factor](https://leetcode.com/problems/largest-component-size-by-common-factor) - -[中文文档](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README.md) - -## Description - -

    Given a non-empty array of unique positive integers A, consider the following graph:

    - -
      -
    • There are A.length nodes, labelled A[0] to A[A.length - 1];
    • -
    • There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
    • -
    - -

    Return the size of the largest connected component in the graph.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: [4,6,15,35]
    -
    -Output: 4
    -
    -
    - -![](./images/ex1.png) - -
    - -

    Example 2:

    - -
    -
    -Input: [20,50,9,63]
    -
    -Output: 2
    -
    -
    - -![](./images/ex2.png) - -
    - -

    Example 3:

    - -
    -
    -Input: [2,3,6,7,4,12,21,39]
    -
    -Output: 8
    -
    -
    - -![](./images/ex3.png) - -

    Note:

    - -
      -
    1. 1 <= A.length <= 20000
    2. -
    3. 1 <= A[i] <= 100000
    4. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md b/leetcode/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md deleted file mode 100644 index 1b847731..00000000 --- a/leetcode/solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md +++ /dev/null @@ -1,132 +0,0 @@ -# [955. Delete Columns to Make Sorted II](https://leetcode.com/problems/delete-columns-to-make-sorted-ii) - -[中文文档](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README.md) - -## Description - -

    We are given an array A of N lowercase letter strings, all of the same length.

    - -

    Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.

    - -

    For example, if we have an array A = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef","vyz"].

    - -

    Suppose we chose a set of deletion indices D such that after deletions, the final array has its elements in lexicographic order (A[0] <= A[1] <= A[2] ... <= A[A.length - 1]).

    - -

    Return the minimum possible value of D.length.

    - -

     

    - -
    - -
    - -
      - -
    - -
    - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: ["ca","bb","ac"]
    -
    -Output: 1
    -
    -Explanation: 
    -
    -After deleting the first column, A = ["a", "b", "c"].
    -
    -Now A is in lexicographic order (ie. A[0] <= A[1] <= A[2]).
    -
    -We require at least 1 deletion since initially A was not in lexicographic order, so the answer is 1.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: ["xc","yb","za"]
    -
    -Output: 0
    -
    -Explanation: 
    -
    -A is already in lexicographic order, so we don't need to delete anything.
    -
    -Note that the rows of A are not necessarily in lexicographic order:
    -
    -ie. it is NOT necessarily true that (A[0][0] <= A[0][1] <= ...)
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: ["zyx","wvu","tsr"]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -We have to delete every column.
    -
    -
    - -

     

    - -
    - -
    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 100
    2. -
    3. 1 <= A[i].length <= 100
    4. -
    - -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md b/leetcode/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md deleted file mode 100644 index d5f525e6..00000000 --- a/leetcode/solution/0900-0999/0958.Check Completeness of a Binary Tree/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [958. Check Completeness of a Binary Tree](https://leetcode.com/problems/check-completeness-of-a-binary-tree) - -[中文文档](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README.md) - -## Description - -

    Given a binary tree, determine if it is a complete binary tree.

    - -

    Definition of a complete binary tree from Wikipedia:
    - -In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    - -

     

    - -

    Example 1:

    - -![](./images/complete-binary-tree-1.png) - -
    -
    -Input: [1,2,3,4,5,6]
    -
    -Output: true
    -
    -Explanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.
    -
    -
    - -
    - -

    Example 2:

    - -![](./images/complete-binary-tree-2.png) - -
    -
    -Input: [1,2,3,4,5,null,7]
    -
    -Output: false
    -
    -Explanation: The node with value 7 isn't as far left as possible.
    -
    -
    - -
     
    - -
    - -

    Note:

    - -
      -
    1. The tree will have between 1 and 100 nodes.
    2. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md b/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md deleted file mode 100644 index be75b326..00000000 --- a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [961. N-Repeated Element in Size 2N Array](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) - -[中文文档](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README.md) - -## Description - -

    In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times.

    - -

    Return the element repeated N times.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

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

    Example 2:

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

    Example 3:

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

     

    - -

    Note:

    - -
      -
    1. 4 <= A.length <= 10000
    2. -
    3. 0 <= A[i] < 10000
    4. -
    5. A.length is even
    6. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.cpp b/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.cpp deleted file mode 100644 index ac692420..00000000 --- a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.cpp +++ /dev/null @@ -1,12 +0,0 @@ -class Solution { -public: - int repeatedNTimes(vector& A) { - unordered_set us(A[0]) ; - for(int i = (A.size() >> 1) - 1; i < A.size(); ++i) - if(us.find(A[i]) != us.end()) - return A[i] ; - else - us.insert(A[i]) ; - return A[0] ; - } -}; \ No newline at end of file diff --git a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.js b/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.js deleted file mode 100644 index 5b3fb4ff..00000000 --- a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.js +++ /dev/null @@ -1,10 +0,0 @@ -const repeatedNTimes = function (A) { - let ss = new Set(); - for (let i = 0; i < A.length; i++) { - if (ss.has(A[i])) { - return A[i]; - } - ss.add(A[i]); - } - return null; -}; diff --git a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.py b/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.py deleted file mode 100644 index 6b6f8ac8..00000000 --- a/leetcode/solution/0900-0999/0961.N-Repeated Element in Size 2N Array/Solution.py +++ /dev/null @@ -1,17 +0,0 @@ -class Solution: - def repeatedNTimes(self, A): - """ - :type A: List[int] - :rtype: int - """ - if A[0] == A[1] or A[0] == A[2] or A[0] == A[3]: - return A[0] - elif A[1] == A[2] or A[1] == A[3]: - return A[1] - elif A[2] == A[3]: - return A[2] - i = 4 - while i < len(A): - if A[i] == A[i + 1]: - return A[i] - i += 2 diff --git a/leetcode/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md b/leetcode/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md deleted file mode 100644 index 8776df50..00000000 --- a/leetcode/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md +++ /dev/null @@ -1,87 +0,0 @@ -# [973. K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin) - -[中文文档](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md) - -## Description - -

    We have a list of points on the plane.  Find the K closest points to the origin (0, 0).

    - -

    (Here, the distance between two points on a plane is the Euclidean distance.)

    - -

    You may return the answer in any order.  The answer is guaranteed to be unique (except for the order that it is in.)

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: points = [[1,3],[-2,2]], K = 1
    -
    -Output: [[-2,2]]
    -
    -Explanation: 
    -
    -The distance between (1, 3) and the origin is sqrt(10).
    -
    -The distance between (-2, 2) and the origin is sqrt(8).
    -
    -Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
    -
    -We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]].
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: points = [[3,3],[5,-1],[-2,4]], K = 2
    -
    -Output: [[3,3],[-2,4]]
    -
    -(The answer [[-2,4],[3,3]] would also be accepted.)
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= K <= points.length <= 10000
    2. -
    3. -10000 < points[i][0] < 10000
    4. -
    5. -10000 < points[i][1] < 10000
    6. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md b/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md deleted file mode 100644 index 0544ce8d..00000000 --- a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array) - -[中文文档](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README.md) - -## Description - -

    Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [-4,-1,0,3,10]
    -
    -Output: [0,1,9,16,100]
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [-7,-3,2,3,11]
    -
    -Output: [4,9,9,49,121]
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 10000
    2. -
    3. -10000 <= A[i] <= 10000
    4. -
    5. A is sorted in non-decreasing order.
    6. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.cpp b/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.cpp deleted file mode 100644 index 03431b84..00000000 --- a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.cpp +++ /dev/null @@ -1,17 +0,0 @@ -bool check(int x, int y){ - return abs(x) < abs(y); -} - -class Solution { -public: - - vector sortedSquares(vector& A) { - - sort(A.begin(), A.end(), check); - - for(int i = 0; i < A.size(); i++) - A[i] = pow(A[i], 2); - - return A; - } -}; diff --git a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.js b/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.js deleted file mode 100644 index 3779dbf9..00000000 --- a/leetcode/solution/0900-0999/0977.Squares of a Sorted Array/Solution.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @param {number[]} A - * @return {number[]} - */ -/** - * Author: Mcnwork2018 - */ -// 第一种解法 -var sortedSquares = function (A) { - let results = A.map((item, index, array) => { - return (item *= item); - }); - results.sort((v1, v2) => { - return v1 - v2; - }); - return results; -}; -// 第二种解法 -var sortedSquares = function (A) { - let len = A.length; // 数组长度 - let j = 0; // j 正数开始 - while (j < len && A[j] < 0) { - j++; - } - let i = j - 1; // i 负数开始 - let results = []; // 存放最终结果 - let t = 0; // results下标 - while (i >= 0 && j < len) { - if (A[i] * A[i] < A[j] * A[j]) { - results[t++] = A[i] * A[i]; - i--; - } else { - results[t++] = A[j] * A[j]; - j++; - } - } - while (i >= 0) { - results[t++] = A[i] * A[i]; - i--; - } - while (j < len) { - results[t++] = A[j] * A[j]; - j++; - } - return results; -}; diff --git a/leetcode/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md b/leetcode/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md deleted file mode 100644 index 69b3b7ca..00000000 --- a/leetcode/solution/0900-0999/0978.Longest Turbulent Subarray/README_EN.md +++ /dev/null @@ -1,95 +0,0 @@ -# [978. Longest Turbulent Subarray](https://leetcode.com/problems/longest-turbulent-subarray) - -[中文文档](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README.md) - -## Description - -

    A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if:

    - -
      -
    • For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even;
    • -
    • OR, for i <= k < j, A[k] > A[k+1] when k is even, and A[k] < A[k+1] when k is odd.
    • -
    - -

    That is, the subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.

    - -

    Return the length of a maximum size turbulent subarray of A.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: [9,4,2,10,7,8,8,1,9]
    -
    -Output: 5
    -
    -Explanation: (A[1] > A[2] < A[3] > A[4] < A[5])
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [4,8,12,16]
    -
    -Output: 2
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: [100]
    -
    -Output: 1
    -
    -
    - -
    - -
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 40000
    2. -
    3. 0 <= A[i] <= 10^9
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md b/leetcode/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md deleted file mode 100644 index 925c250c..00000000 --- a/leetcode/solution/0900-0999/0987.Vertical Order Traversal of a Binary Tree/README_EN.md +++ /dev/null @@ -1,106 +0,0 @@ -# [987. Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree) - -[中文文档](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README.md) - -## Description - -

    Given a binary tree, return the vertical order traversal of its nodes values.

    - -

    For each node at position (X, Y), its left and right children respectively will be at positions (X-1, Y-1) and (X+1, Y-1).

    - -

    Running a vertical line from X = -infinity to X = +infinity, whenever the vertical line touches some nodes, we report the values of the nodes in order from top to bottom (decreasing Y coordinates).

    - -

    If two nodes have the same position, then the value of the node that is reported first is the value that is smaller.

    - -

    Return an list of non-empty reports in order of X coordinate.  Every report will have a list of values of nodes.

    - -

     

    - -

    Example 1:

    - -![](./images/1236_example_1.png) - -
    - -
    -
    -Input: [3,9,20,null,null,15,7]
    -
    -Output: [[9],[3,15],[20],[7]]
    -
    -Explanation: 
    -
    -Without loss of generality, we can assume the root node is at position (0, 0):
    -
    -Then, the node with value 9 occurs at position (-1, -1);
    -
    -The nodes with values 3 and 15 occur at positions (0, 0) and (0, -2);
    -
    -The node with value 20 occurs at position (1, -1);
    -
    -The node with value 7 occurs at position (2, -2).
    -
    -
    - -
    - -

    Example 2:

    - -![](./images/tree2.png) - -
    -
    -Input: [1,2,3,4,5,6,7]
    -
    -Output: [[4],[2],[1,5,6],[3],[7]]
    -
    -Explanation: 
    -
    -The node with value 5 and the node with value 6 have the same position according to the given scheme.
    -
    -However, in the report "[1,5,6]", the node value of 5 comes first since 5 is smaller than 6.
    -
    -
    - -

     

    - -
    - -

    Note:

    - -
      -
    1. The tree will have between 1 and 1000 nodes.
    2. -
    3. Each node's value will be between 0 and 1000.
    4. -
    - -
    - -
    - -
     
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md b/leetcode/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md deleted file mode 100644 index 1054a750..00000000 --- a/leetcode/solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md +++ /dev/null @@ -1,114 +0,0 @@ -# [989. Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer) - -[中文文档](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README.md) - -## Description - -

    For a non-negative integer X, the array-form of X is an array of its digits in left to right order.  For example, if X = 1231, then the array form is [1,2,3,1].

    - -

    Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: A = [1,2,0,0], K = 34
    -
    -Output: [1,2,3,4]
    -
    -Explanation: 1200 + 34 = 1234
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: A = [2,7,4], K = 181
    -
    -Output: [4,5,5]
    -
    -Explanation: 274 + 181 = 455
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: A = [2,1,5], K = 806
    -
    -Output: [1,0,2,1]
    -
    -Explanation: 215 + 806 = 1021
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: A = [9,9,9,9,9,9,9,9,9,9], K = 1
    -
    -Output: [1,0,0,0,0,0,0,0,0,0,0]
    -
    -Explanation: 9999999999 + 1 = 10000000000
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 10000
    2. -
    3. 0 <= A[i] <= 9
    4. -
    5. 0 <= K <= 10000
    6. -
    7. If A.length > 1, then A[0] != 0
    8. -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0999.Available Captures for Rook/README_EN.md b/leetcode/solution/0900-0999/0999.Available Captures for Rook/README_EN.md deleted file mode 100644 index 06e8da8c..00000000 --- a/leetcode/solution/0900-0999/0999.Available Captures for Rook/README_EN.md +++ /dev/null @@ -1,136 +0,0 @@ -# [999. Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook) - -[中文文档](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README.md) - -## Description - -

    On an 8 x 8 chessboard, there is one white rook.  There also may be empty squares, white bishops, and black pawns.  These are given as characters 'R', '.', 'B', and 'p' respectively. Uppercase characters represent white pieces, and lowercase characters represent black pieces.

    - -

    The rook moves as in the rules of Chess: it chooses one of four cardinal directions (north, east, west, and south), then moves in that direction until it chooses to stop, reaches the edge of the board, or captures an opposite colored pawn by moving to the same square it occupies.  Also, rooks cannot move into the same square as other friendly bishops.

    - -

    Return the number of pawns the rook can capture in one move.

    - -

     

    - -

    Example 1:

    - -![](./images/1253_example_1_improved.png) - -
    -
    -Input: [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -In this example the rook is able to capture all the pawns.
    -
    -
    - -

    Example 2:

    - -![](./images/1253_example_2_improved.png) - -
    -
    -Input: [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
    -
    -Output: 0
    -
    -Explanation: 
    -
    -Bishops are blocking the rook to capture any pawn.
    -
    -
    - -

    Example 3:

    - -![](./images/1253_example_3_improved.png) - -
    -
    -Input: [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
    -
    -Output: 3
    -
    -Explanation: 
    -
    -The rook can capture the pawns at positions b5, d6 and f5.
    -
    -
    - -

     

    - -

    Note:

    - -1. `board.length == board[i].length == 8` -2. `board[i][j]` is either `'R'`, `'.'`, `'B'` or `'p'` -3. There is exactly one cell with `board[i][j] == 'R'` - -## Solutions - - - -### **Python3** - -```python -class Solution: - def numRookCaptures(self, board: List[List[str]]) -> int: - - def search(board, i, j, direction): - while i >= 0 and i < 8 and j >= 0 and j < 8: - if board[i][j] == 'B': return 0 - if board[i][j] == 'p': return 1 - i += direction[0] - j += direction[1] - return 0 - directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] - res = 0; - for i in range(8): - for j in range(8): - if board[i][j] == 'R': - for direction in directions: - res += search(board, i, j, direction) - return res -``` - -### **Java** - -```java -class Solution { - public int numRookCaptures(char[][] board) { - int[][] directions = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; - int res = 0; - for (int i = 0; i < 8; ++i) { - for (int j = 0; j < 8; ++j) { - if (board[i][j] == 'R') { - for (int[] direction : directions) { - res += search(board, i, j, direction); - } - return res; - } - } - } - return res; - } - - private int search(char[][] board, int i, int j, int[] direction) { - while (i >= 0 && i < 8 && j >= 0 && j < 8) { - if (board[i][j] == 'B') return 0; - if (board[i][j] == 'p') return 1; - i += direction[0]; - j += direction[1]; - } - return 0; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/0900-0999/0999.Available Captures for Rook/Solution.py b/leetcode/solution/0900-0999/0999.Available Captures for Rook/Solution.py deleted file mode 100644 index 97b5f5d2..00000000 --- a/leetcode/solution/0900-0999/0999.Available Captures for Rook/Solution.py +++ /dev/null @@ -1,20 +0,0 @@ -class Solution: - def numRookCaptures(self, board: List[List[str]]) -> int: - - def search(board, i, j, direction): - while i >= 0 and i < 8 and j >= 0 and j < 8: - if board[i][j] == 'B': - return 0 - if board[i][j] == 'p': - return 1 - i += direction[0] - j += direction[1] - return 0 - directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] - res = 0 - for i in range(8): - for j in range(8): - if board[i][j] == 'R': - for direction in directions: - res += search(board, i, j, direction) - return res diff --git a/leetcode/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md b/leetcode/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md deleted file mode 100644 index 802e32ce..00000000 --- a/leetcode/solution/1000-1099/1004.Max Consecutive Ones III/README_EN.md +++ /dev/null @@ -1,84 +0,0 @@ -# [1004. Max Consecutive Ones III](https://leetcode.com/problems/max-consecutive-ones-iii) - -[中文文档](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md) - -## Description - -

    Given an array A of 0s and 1s, we may change up to K values from 0 to 1.

    - -

    Return the length of the longest (contiguous) subarray that contains only 1s. 

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2
    -
    -Output: 6
    -
    -Explanation: 
    -
    -[1,1,1,0,0,1,1,1,1,1,1]
    -
    -Bolded numbers were flipped from 0 to 1.  The longest subarray is underlined.
    - -
    - -

    Example 2:

    - -
    -
    -Input: A = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3
    -
    -Output: 10
    -
    -Explanation: 
    -
    -[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
    -
    -Bolded numbers were flipped from 0 to 1.  The longest subarray is underlined.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 20000
    2. -
    3. 0 <= K <= A.length
    4. -
    5. A[i] is 0 or 1 
    6. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - - diff --git a/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md b/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md deleted file mode 100644 index c1d507bd..00000000 --- a/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [1008. Construct Binary Search Tree from Preorder Traversal](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal) - -[中文文档](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README.md) - -## Description - -

    Return the root node of a binary search tree that matches the given preorder traversal.

    - -

    (Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val.  Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [8,5,1,7,10,12]
    -
    -Output: [8,5,10,1,7,null,12]
    -
    -
    - -![](./images/1266.png) - -

     

    - -

    Note: 

    - -
      -
    1. 1 <= preorder.length <= 100
    2. -
    3. The values of preorder are distinct.
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - - diff --git a/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.py b/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.py deleted file mode 100644 index f2d28f64..00000000 --- a/leetcode/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.py +++ /dev/null @@ -1,29 +0,0 @@ -# Definition for a binary tree node. -# class TreeNode: -# def __init__(self, x): -# self.val = x -# self.left = None -# self.right = None - - -class Solution: - - def bstFromPreorder(self, preorder: List[int]) -> TreeNode: - def buildtree(li): - if not li: - return - val = li[0] - if len(li) == 1: - root = TreeNode(val) - else: - l, r = [], [] - for item in li[1:]: - if item > val: - r.append(item) - else: - l.append(item) - root = TreeNode(val) - root.left = buildtree(l) - root.right = buildtree(r) - return root - return buildtree(preorder) diff --git a/leetcode/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md b/leetcode/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md deleted file mode 100644 index 8368569d..00000000 --- a/leetcode/solution/1000-1099/1009.Complement of Base 10 Integer/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [1009. Complement of Base 10 Integer](https://leetcode.com/problems/complement-of-base-10-integer) - -[中文文档](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README.md) - -## Description - -

    Every non-negative integer N has a binary representation.  For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on.  Note that except for N = 0, there are no leading zeroes in any binary representation.

    - -

    The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to a 1.  For example, the complement of "101" in binary is "010" in binary.

    - -

    For a given number N in base-10, return the complement of it's binary representation as a base-10 integer.

    - -

     

    - -
      -
    - -
    -

    Example 1:

    - -
    -Input: 5
    -Output: 2
    -Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.
    -
    - -
    -

    Example 2:

    - -
    -Input: 7
    -Output: 0
    -Explanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.
    -
    - -
    -

    Example 3:

    - -
    -Input: 10
    -Output: 5
    -Explanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 0 <= N < 10^9
    2. -
    3. This question is the same as 476: https://leetcode.com/problems/number-complement/
    4. -
    -
    -
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - - diff --git a/leetcode/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md b/leetcode/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md deleted file mode 100644 index 3d1b7c17..00000000 --- a/leetcode/solution/1000-1099/1010.Pairs of Songs With Total Durations Divisible by 60/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [1010. Pairs of Songs With Total Durations Divisible by 60](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) - -[中文文档](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README.md) - -## Description - -

    In a list of songs, the i-th song has a duration of time[i] seconds. 

    - -

    Return the number of pairs of songs for which their total duration in seconds is divisible by 60.  Formally, we want the number of indices i < j with (time[i] + time[j]) % 60 == 0.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [30,20,150,100,40]
    -
    -Output: 3
    -
    -Explanation: Three pairs have a total duration divisible by 60:
    -
    -(time[0] = 30, time[2] = 150): total duration 180
    -
    -(time[1] = 20, time[3] = 100): total duration 120
    -
    -(time[1] = 20, time[4] = 40): total duration 60
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [60,60,60]
    -
    -Output: 3
    -
    -Explanation: All three pairs have a total duration of 120, which is divisible by 60.
    -
    -
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= time.length <= 60000
    2. -
    3. 1 <= time[i] <= 500
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - - diff --git a/leetcode/solution/1000-1099/1012.Complement of Base 10 Integer/Solution.py b/leetcode/solution/1000-1099/1012.Complement of Base 10 Integer/Solution.py deleted file mode 100644 index 0f4c4d59..00000000 --- a/leetcode/solution/1000-1099/1012.Complement of Base 10 Integer/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - - def bitwiseComplement(self, N: int) -> int: - if N == 0: - return 1 - ans = 0 - index = 0 - while N > 1: - if N % 2 == 0: - ans += 2**index - index += 1 - N = N // 2 - return ans diff --git a/leetcode/solution/1000-1099/1017.Convert to Base -2/README_EN.md b/leetcode/solution/1000-1099/1017.Convert to Base -2/README_EN.md deleted file mode 100644 index 7cc96f74..00000000 --- a/leetcode/solution/1000-1099/1017.Convert to Base -2/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [1017. Convert to Base -2](https://leetcode.com/problems/convert-to-base-2) - -[中文文档](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README.md) - -## Description - -

    Given a number N, return a string consisting of "0"s and "1"s that represents its value in base -2 (negative two).

    - -

    The returned string must have no leading zeroes, unless the string is "0".

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: 2
    -
    -Output: "110"
    -
    -Explantion: (-2) ^ 2 + (-2) ^ 1 = 2
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: 3
    -
    -Output: "111"
    -
    -Explantion: (-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: 4
    -
    -Output: "100"
    -
    -Explantion: (-2) ^ 2 = 4
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 0 <= N <= 10^9
    2. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md b/leetcode/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md deleted file mode 100644 index 8a67b700..00000000 --- a/leetcode/solution/1000-1099/1019.Next Greater Node In Linked List/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [1019. Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list) - -[中文文档](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README.md) - -## Description - -

    We are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc.

    - -

    Each node may have a next larger value: for node_inext_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val, and j is the smallest possible choice.  If such a j does not exist, the next larger value is 0.

    - -

    Return an array of integers answer, where answer[i] = next_larger(node_{i+1}).

    - -

    Note that in the example inputs (not outputs) below, arrays such as [2,1,5] represent the serialization of a linked list with a head node value of 2, second node value of 1, and third node value of 5.

    - -

     

    - -
    - -

    Example 1:

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

    Example 2:

    - -
    -
    -Input: [2,7,4,3,5]
    -
    -Output: [7,0,5,5,0]
    -
    -
    - -
    - -

    Example 3:

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

     

    - -

    Note:

    - -
      -
    1. 1 <= node.val <= 10^9 for each node in the linked list.
    2. -
    3. The given list has length in the range [0, 10000].
    4. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md b/leetcode/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md deleted file mode 100644 index 49fc5a67..00000000 --- a/leetcode/solution/1000-1099/1021.Remove Outermost Parentheses/README_EN.md +++ /dev/null @@ -1,115 +0,0 @@ -# [1021. Remove Outermost Parentheses](https://leetcode.com/problems/remove-outermost-parentheses) - -[中文文档](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md) - -## Description - -

    A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.  For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.

    - -

    A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings.

    - -

    Given a valid parentheses string S, consider its primitive decomposition: S = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings.

    - -

    Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: "(()())(())"
    -
    -Output: "()()()"
    -
    -Explanation: 
    -
    -The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
    -
    -After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: "(()())(())(()(()))"
    -
    -Output: "()()()()(())"
    -
    -Explanation: 
    -
    -The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
    -
    -After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: "()()"
    -
    -Output: ""
    -
    -Explanation: 
    -
    -The input string is "()()", with primitive decomposition "()" + "()".
    -
    -After removing outer parentheses of each part, this is "" + "" = "".
    -
    -
    - -

     

    - -
    - -
    - -

    Note:

    - -
      -
    1. S.length <= 10000
    2. -
    3. S[i] is "(" or ")"
    4. -
    5. S is a valid parentheses string
    6. -
    - -
    - -
    - -
     
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md b/leetcode/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md deleted file mode 100644 index 710dac68..00000000 --- a/leetcode/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/README_EN.md +++ /dev/null @@ -1,61 +0,0 @@ -# [1022. Sum of Root To Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) - -[中文文档](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README.md) - -## Description - -

    Given a binary tree, each node has value 0 or 1.  Each root-to-leaf path represents a binary number starting with the most significant bit.  For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.

    - -

    For all leaves in the tree, consider the numbers represented by the path from the root to that leaf.

    - -

    Return the sum of these numbers.

    - -

     

    - -

    Example 1:

    - -![](./images/sum-of-root-to-leaf-binary-numbers.png) - -
    -
    -Input: [1,0,1,0,1,0,1]
    -
    -Output: 22
    -
    -Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. The number of nodes in the tree is between 1 and 1000.
    2. -
    3. node.val is 0 or 1.
    4. -
    5. The answer will not exceed 2^31 - 1.
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1025.Divisor Game/README_EN.md b/leetcode/solution/1000-1099/1025.Divisor Game/README_EN.md deleted file mode 100644 index 93f4acd4..00000000 --- a/leetcode/solution/1000-1099/1025.Divisor Game/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [1025. Divisor Game](https://leetcode.com/problems/divisor-game) - -[中文文档](/solution/1000-1099/1025.Divisor%20Game/README.md) - -## Description - -

    Alice and Bob take turns playing a game, with Alice starting first.

    - -

    Initially, there is a number N on the chalkboard.  On each player's turn, that player makes a move consisting of:

    - -
      -
    • Choosing any x with 0 < x < N and N % x == 0.
    • -
    • Replacing the number N on the chalkboard with N - x.
    • -
    - -

    Also, if a player cannot make a move, they lose the game.

    - -

    Return True if and only if Alice wins the game, assuming both players play optimally.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: 2
    -
    -Output: true
    -
    -Explanation: Alice chooses 1, and Bob has no more moves.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: 3
    -
    -Output: false
    -
    -Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= N <= 1000
    2. -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1025.Divisor Game/Solution.cpp b/leetcode/solution/1000-1099/1025.Divisor Game/Solution.cpp deleted file mode 100644 index 70b75cf9..00000000 --- a/leetcode/solution/1000-1099/1025.Divisor Game/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { - unordered_map mem; -public: - bool divisorGame(int N) { - if (N == 1) return false; - if (mem.count(N)) { - return mem[N]; - } - for (int i = 1; i < N; ++i) { - if (N % i == 0) { - if (divisorGame(N-i) == false) { - mem[N] = true; - return true; - } - } - } - mem[N] = false; - return false; - } -}; \ No newline at end of file diff --git a/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md b/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md deleted file mode 100644 index 1207f285..00000000 --- a/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [1026. Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor) - -[中文文档](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README.md) - -## Description - -

    Given the root of a binary tree, find the maximum value V for which there exists different nodes A and B where V = |A.val - B.val| and A is an ancestor of B.

    - -

    (A node A is an ancestor of B if either: any child of A is equal to B, or any child of A is an ancestor of B.)

    - -

     

    - -

    Example 1:

    - -![](./images/2whqcep.jpg) - -
    -Input: [8,3,10,1,6,null,14,null,null,4,7,13]
    -Output: 7
    -Explanation: 
    -We have various ancestor-node differences, some of which are given below :
    -|8 - 3| = 5
    -|3 - 7| = 4
    -|8 - 1| = 7
    -|10 - 13| = 3
    -Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
    -
    - -

     

    - -

    Note:

    - -
      -
    1. The number of nodes in the tree is between 2 and 5000.
    2. -
    3. Each node will have value between 0 and 100000.
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/Solution.cpp b/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/Solution.cpp deleted file mode 100644 index b6045968..00000000 --- a/leetcode/solution/1000-1099/1026.Maximum Difference Between Node and Ancestor/Solution.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Definition for a binary tree node. - * struct TreeNode { - * int val; - * TreeNode *left; - * TreeNode *right; - * TreeNode(int x) : val(x), left(NULL), right(NULL) {} - * }; - */ -class Solution { - int helper(TreeNode* node, int& left, int & right) { - left = INT_MAX; - right = INT_MIN; - if (node == nullptr) { - return 0; - } - left = node->val; - right = node->val; - - int tmpLeft, tmpRight; - int res = 0; - - res = max(res, helper(node->left, tmpLeft, tmpRight)); - left = min(left, tmpLeft); - right = max(right, tmpRight); - - res = max(res, helper(node->right, tmpLeft, tmpRight)); - left = min(left, tmpLeft); - right = max(right, tmpRight); - - res = max(res, abs(node->val - left)); - res = max(res, abs(node->val - right)); - - return res; - } -public: - int maxAncestorDiff(TreeNode* root) { - int left = 0, right = 0; - return helper(root, left, right); - } -}; \ No newline at end of file diff --git a/leetcode/solution/1000-1099/1029.Two City Scheduling/README_EN.md b/leetcode/solution/1000-1099/1029.Two City Scheduling/README_EN.md deleted file mode 100644 index 35e05cd3..00000000 --- a/leetcode/solution/1000-1099/1029.Two City Scheduling/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [1029. Two City Scheduling](https://leetcode.com/problems/two-city-scheduling) - -[中文文档](/solution/1000-1099/1029.Two%20City%20Scheduling/README.md) - -## Description - -

    There are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1].

    - -

    Return the minimum cost to fly every person to a city such that exactly N people arrive in each city.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [[10,20],[30,200],[400,50],[30,20]]
    -
    -Output: 110
    -
    -Explanation: 
    -
    -The first person goes to city A for a cost of 10.
    -
    -The second person goes to city A for a cost of 30.
    -
    -The third person goes to city B for a cost of 50.
    -
    -The fourth person goes to city B for a cost of 20.
    -
    -
    -
    -The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= costs.length <= 100
    2. -
    3. It is guaranteed that costs.length is even.
    4. -
    5. 1 <= costs[i][0], costs[i][1] <= 1000
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md b/leetcode/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md deleted file mode 100644 index 11a61f43..00000000 --- a/leetcode/solution/1000-1099/1030.Matrix Cells in Distance Order/README_EN.md +++ /dev/null @@ -1,100 +0,0 @@ -# [1030. Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order) - -[中文文档](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README.md) - -## Description - -

    We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), where 0 <= r < R and 0 <= c < C.

    - -

    Additionally, we are given a cell in that matrix with coordinates (r0, c0).

    - -

    Return the coordinates of all cells in the matrix, sorted by their distance from (r0, c0) from smallest distance to largest distance.  Here, the distance between two cells (r1, c1) and (r2, c2) is the Manhattan distance, |r1 - r2| + |c1 - c2|.  (You may return the answer in any order that satisfies this condition.)

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: R = 1, C = 2, r0 = 0, c0 = 0
    -
    -Output: [[0,0],[0,1]]
    -
    -Explanation: The distances from (r0, c0) to other cells are: [0,1]
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: R = 2, C = 2, r0 = 0, c0 = 1
    -
    -Output: [[0,1],[0,0],[1,1],[1,0]]
    -
    -Explanation: The distances from (r0, c0) to other cells are: [0,1,1,2]
    -
    -The answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: R = 2, C = 3, r0 = 1, c0 = 2
    -
    -Output: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]
    -
    -Explanation: The distances from (r0, c0) to other cells are: [0,1,1,2,2,3]
    -
    -There are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= R <= 100
    2. -
    3. 1 <= C <= 100
    4. -
    5. 0 <= r0 < R
    6. -
    7. 0 <= c0 < C
    8. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md b/leetcode/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md deleted file mode 100644 index 4f98ff5b..00000000 --- a/leetcode/solution/1000-1099/1033.Moving Stones Until Consecutive/README_EN.md +++ /dev/null @@ -1,106 +0,0 @@ -# [1033. Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive) - -[中文文档](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README.md) - -## Description - -

    Three stones are on a number line at positions a, b, and c.

    - -

    Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints.  Formally, let's say the stones are currently at positions x, y, z with x < y < z.  You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.

    - -

    The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

    - -

    When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: a = 1, b = 2, c = 5
    -
    -Output: [1,2]
    -
    -Explanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: a = 4, b = 3, c = 2
    -
    -Output: [0,0]
    -
    -Explanation: We cannot make any moves.
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: a = 3, b = 5, c = 1
    -
    -Output: [1,2]
    -
    -Explanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.
    -
    -
    - -

     

    - -
    - -
    - -

    Note:

    - -
      -
    1. 1 <= a <= 100
    2. -
    3. 1 <= b <= 100
    4. -
    5. 1 <= c <= 100
    6. -
    7. a != b, b != c, c != a
    8. -
    - -
    - -

     

    - -
    - -
     
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1034.Coloring A Border/README_EN.md b/leetcode/solution/1000-1099/1034.Coloring A Border/README_EN.md deleted file mode 100644 index 3d913942..00000000 --- a/leetcode/solution/1000-1099/1034.Coloring A Border/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [1034. Coloring A Border](https://leetcode.com/problems/coloring-a-border) - -[中文文档](/solution/1000-1099/1034.Coloring%20A%20Border/README.md) - -## Description - -

    Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location.

    - -

    Two squares belong to the same connected component if and only if they have the same color and are next to each other in any of the 4 directions.

    - -

    The border of a connected component is all the squares in the connected component that are either 4-directionally adjacent to a square not in the component, or on the boundary of the grid (the first or last row or column).

    - -

    Given a square at location (r0, c0) in the grid and a color, color the border of the connected component of that square with the given color, and return the final grid.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: grid = [[1,1],[1,2]], r0 = 0, c0 = 0, color = 3
    -
    -Output: [[3, 3], [3, 2]]
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: grid = [[1,2,2],[2,3,2]], r0 = 0, c0 = 1, color = 3
    -
    -Output: [[1, 3, 3], [2, 3, 3]]
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: grid = [[1,1,1],[1,1,1],[1,1,1]], r0 = 1, c0 = 1, color = 2
    -
    -Output: [[2, 2, 2], [2, 1, 2], [2, 2, 2]]
    - -
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= grid.length <= 50
    2. -
    3. 1 <= grid[0].length <= 50
    4. -
    5. 1 <= grid[i][j] <= 1000
    6. -
    7. 0 <= r0 < grid.length
    8. -
    9. 0 <= c0 < grid[0].length
    10. -
    11. 1 <= color <= 1000
    12. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1036.Escape a Large Maze/README_EN.md b/leetcode/solution/1000-1099/1036.Escape a Large Maze/README_EN.md deleted file mode 100644 index 9dc1c603..00000000 --- a/leetcode/solution/1000-1099/1036.Escape a Large Maze/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [1036. Escape a Large Maze](https://leetcode.com/problems/escape-a-large-maze) - -[中文文档](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README.md) - -## Description - -

    In a 1 million by 1 million grid, the coordinates of each grid square are (x, y) with 0 <= x, y < 10^6.

    - -

    We start at the source square and want to reach the target square.  Each move, we can walk to a 4-directionally adjacent square in the grid that isn't in the given list of blocked squares.

    - -

    Return true if and only if it is possible to reach the target square through a sequence of moves.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: blocked = [[0,1],[1,0]], source = [0,0], target = [0,2]
    -
    -Output: false
    -
    -Explanation: 
    -
    -The target square is inaccessible starting from the source square, because we can't walk outside the grid.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: blocked = [], source = [0,0], target = [999999,999999]
    -
    -Output: true
    -
    -Explanation: 
    -
    -Because there are no blocked cells, it's possible to reach the target square.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 0 <= blocked.length <= 200
    2. -
    3. blocked[i].length == 2
    4. -
    5. 0 <= blocked[i][j] < 10^6
    6. -
    7. source.length == target.length == 2
    8. -
    9. 0 <= source[i][j], target[i][j] < 10^6
    10. -
    11. source != target
    12. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1037.Valid Boomerang/README_EN.md b/leetcode/solution/1000-1099/1037.Valid Boomerang/README_EN.md deleted file mode 100644 index 17f17c38..00000000 --- a/leetcode/solution/1000-1099/1037.Valid Boomerang/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [1037. Valid Boomerang](https://leetcode.com/problems/valid-boomerang) - -[中文文档](/solution/1000-1099/1037.Valid%20Boomerang/README.md) - -## Description - -

    A boomerang is a set of 3 points that are all distinct and not in a straight line.

    - -

    Given a list of three points in the plane, return whether these points are a boomerang.

    - -

     

    - -

    Example 1:

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

    Example 2:

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

     

    - -

    Note:

    - -
      -
    1. points.length == 3
    2. -
    3. points[i].length == 2
    4. -
    5. 0 <= points[i][j] <= 100
    6. -
    - -
    - -
     
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md b/leetcode/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md deleted file mode 100644 index 9808c0c0..00000000 --- a/leetcode/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [1038. Binary Search Tree to Greater Sum Tree](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree) - -[中文文档](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README.md) - -## Description - -

    Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val.

    - -

    As a reminder, a binary search tree is a tree that satisfies these constraints:

    - -
      -
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • -
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • -
    • Both the left and right subtrees must also be binary search trees.
    • -
    - -

     

    - -

    Example 1:

    - -![](./images/tree.png) - -
    -Input: [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]
    -Output: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]
    -
    - -
    -

     

    -
    - -

    Constraints:

    - -
      -
    1. The number of nodes in the tree is between 1 and 100.
    2. -
    3. Each node will have value between 0 and 100.
    4. -
    5. The given tree is a binary search tree.
    6. -
    - -
    -
    -
    Note: This question is the same as 538: https://leetcode.com/problems/convert-bst-to-greater-tree/
    -
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md b/leetcode/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md deleted file mode 100644 index e4b53be9..00000000 --- a/leetcode/solution/1000-1099/1041.Robot Bounded In Circle/README_EN.md +++ /dev/null @@ -1,80 +0,0 @@ -# [1041. Robot Bounded In Circle](https://leetcode.com/problems/robot-bounded-in-circle) - -[中文文档](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README.md) - -## Description - -

    On an infinite plane, a robot initially stands at (0, 0) and faces north.  The robot can receive one of three instructions:

    - -
      -
    • "G": go straight 1 unit;
    • -
    • "L": turn 90 degrees to the left;
    • -
    • "R": turn 90 degress to the right.
    • -
    - -

    The robot performs the instructions given in order, and repeats them forever.

    - -

    Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.

    - -

     

    - -

    Example 1:

    - -
    -Input: "GGLLGG"
    -Output: true
    -Explanation: 
    -The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).
    -When repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
    -
    - -

    Example 2:

    - -
    -Input: "GG"
    -Output: false
    -Explanation: 
    -The robot moves north indefinitely.
    -
    - -

    Example 3:

    - -
    -Input: "GL"
    -Output: true
    -Explanation: 
    -The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= instructions.length <= 100
    2. -
    3. instructions[i] is in {'G', 'L', 'R'}
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md b/leetcode/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md deleted file mode 100644 index 014eeb8c..00000000 --- a/leetcode/solution/1000-1099/1043.Partition Array for Maximum Sum/README_EN.md +++ /dev/null @@ -1,54 +0,0 @@ -# [1043. Partition Array for Maximum Sum](https://leetcode.com/problems/partition-array-for-maximum-sum) - -[中文文档](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README.md) - -## Description - -

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

    - -

    Return the largest sum of the given array after partitioning.

    - -

     

    - -

    Example 1:

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

     

    - -

    Note:

    - -
      -
    1. 1 <= K <= A.length <= 500
    2. -
    3. 0 <= A[i] <= 10^6
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1046.Last Stone Weight/README_EN.md b/leetcode/solution/1000-1099/1046.Last Stone Weight/README_EN.md deleted file mode 100644 index 5e5d2737..00000000 --- a/leetcode/solution/1000-1099/1046.Last Stone Weight/README_EN.md +++ /dev/null @@ -1,69 +0,0 @@ -# [1046. Last Stone Weight](https://leetcode.com/problems/last-stone-weight) - -[中文文档](/solution/1000-1099/1046.Last%20Stone%20Weight/README.md) - -## Description - -

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

    - -

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

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

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

    - -

     

    - -

    Example 1:

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

     

    - -

    Note:

    - -
      -
    1. 1 <= stones.length <= 30
    2. -
    3. 1 <= stones[i] <= 1000
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md b/leetcode/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md deleted file mode 100644 index d3f025f4..00000000 --- a/leetcode/solution/1000-1099/1047.Remove All Adjacent Duplicates In String/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [1047. Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) - -[中文文档](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README.md) - -## Description - -

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

    - -

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

    - -

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

    - -

     

    - -

    Example 1:

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

     

    - -

    Note:

    - -
      -
    1. 1 <= S.length <= 20000
    2. -
    3. S consists only of English lowercase letters.
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1048.Longest String Chain/README_EN.md b/leetcode/solution/1000-1099/1048.Longest String Chain/README_EN.md deleted file mode 100644 index 40f0fe70..00000000 --- a/leetcode/solution/1000-1099/1048.Longest String Chain/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [1048. Longest String Chain](https://leetcode.com/problems/longest-string-chain) - -[中文文档](/solution/1000-1099/1048.Longest%20String%20Chain/README.md) - -## Description - -

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

    - -

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

    - -

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

    - -

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

    - -

     

    - -

    Example 1:

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

     

    - -

    Note:

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

     

    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1051.Height Checker/README_EN.md b/leetcode/solution/1000-1099/1051.Height Checker/README_EN.md deleted file mode 100644 index 74bf5320..00000000 --- a/leetcode/solution/1000-1099/1051.Height Checker/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [1051. Height Checker](https://leetcode.com/problems/height-checker) - -[中文文档](/solution/1000-1099/1051.Height%20Checker/README.md) - -## Description - -

    Students are asked to stand in non-decreasing order of heights for an annual photo.

    - -

    Return the minimum number of students that must move in order for all students to be standing in non-decreasing order of height.

    - -

    Notice that when a group of students is selected they can reorder in any possible way between themselves and the non selected students remain on their seats.

    - -

     

    -

    Example 1:

    - -
    -Input: heights = [1,1,4,2,1,3]
    -Output: 3
    -Explanation: 
    -Current array : [1,1,4,2,1,3]
    -Target array  : [1,1,1,2,3,4]
    -On index 2 (0-based) we have 4 vs 1 so we have to move this student.
    -On index 4 (0-based) we have 1 vs 3 so we have to move this student.
    -On index 5 (0-based) we have 3 vs 4 so we have to move this student.
    -
    - -

    Example 2:

    - -
    -Input: heights = [5,1,2,3,4]
    -Output: 5
    -
    - -

    Example 3:

    - -
    -Input: heights = [1,2,3,4,5]
    -Output: 0
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= heights.length <= 100
    • -
    • 1 <= heights[i] <= 100
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md b/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md deleted file mode 100644 index bb3142ca..00000000 --- a/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md +++ /dev/null @@ -1,91 +0,0 @@ -# [1052. Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner) - -[中文文档](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README.md) - -## Description - -

    Today, the bookstore owner has a store open for customers.length minutes.  Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.

    - -

    On some minutes, the bookstore owner is grumpy.  If the bookstore owner is grumpy on the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0.  When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.

    - -

    The bookstore owner knows a secret technique to keep themselves not grumpy for X minutes straight, but can only use it once.

    - -

    Return the maximum number of customers that can be satisfied throughout the day.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3
    -
    -Output: 16
    -
    -Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. 
    -
    -The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    • 1 <= X <= customers.length == grumpy.length <= 20000
    • -
    • 0 <= customers[i] <= 1000
    • -
    • 0 <= grumpy[i] <= 1
    • -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int: - s = t = 0 - win, n = 0, len(customers) - for i in range(n): - if grumpy[i] == 0: - s += customers[i] - else: - win += customers[i] - if i >= X and grumpy[i - X] == 1: - win -= customers[i - X] - t = max(t, win) - return s + t -``` - -### **Java** - -```java -class Solution { - public int maxSatisfied(int[] customers, int[] grumpy, int X) { - int s = 0, t = 0; - for (int i = 0, win = 0, n = customers.length; i < n; ++i) { - if (grumpy[i] == 0) { - s += customers[i]; - } else { - win += customers[i]; - } - if (i >= X && grumpy[i - X] == 1) { - win -= customers[i - X]; - } - t = Math.max(t, win); - } - return s + t; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/Solution.py b/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/Solution.py deleted file mode 100644 index a3bae02c..00000000 --- a/leetcode/solution/1000-1099/1052.Grumpy Bookstore Owner/Solution.py +++ /dev/null @@ -1,13 +0,0 @@ -class Solution: - def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int: - s = t = 0 - win, n = 0, len(customers) - for i in range(n): - if grumpy[i] == 0: - s += customers[i] - else: - win += customers[i] - if i >= X and grumpy[i - X] == 1: - win -= customers[i - X] - t = max(t, win) - return s + t diff --git a/leetcode/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md b/leetcode/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md deleted file mode 100644 index 6f8eb0a3..00000000 --- a/leetcode/solution/1000-1099/1053.Previous Permutation With One Swap/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [1053. Previous Permutation With One Swap](https://leetcode.com/problems/previous-permutation-with-one-swap) - -[中文文档](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README.md) - -## Description - -

    Given an array A of positive integers (not necessarily distinct), return the lexicographically largest permutation that is smaller than A, that can be made with one swap (A swap exchanges the positions of two numbers A[i] and A[j]).  If it cannot be done, then return the same array.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [3,2,1]
    -
    -Output: [3,1,2]
    -
    -Explanation: Swapping 2 and 1.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: [1,1,5]
    -
    -Output: [1,1,5]
    -
    -Explanation: This is already the smallest permutation.
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: [1,9,4,6,7]
    -
    -Output: [1,7,4,6,9]
    -
    -Explanation: Swapping 9 and 7.
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: [3,1,1,3]
    -
    -Output: [1,3,1,3]
    -
    -Explanation: Swapping 1 and 3.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 10000
    2. -
    3. 1 <= A[i] <= 10000
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1054.Distant Barcodes/README_EN.md b/leetcode/solution/1000-1099/1054.Distant Barcodes/README_EN.md deleted file mode 100644 index 3c932c5e..00000000 --- a/leetcode/solution/1000-1099/1054.Distant Barcodes/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [1054. Distant Barcodes](https://leetcode.com/problems/distant-barcodes) - -[中文文档](/solution/1000-1099/1054.Distant%20Barcodes/README.md) - -## Description - -

    In a warehouse, there is a row of barcodes, where the i-th barcode is barcodes[i].

    - -

    Rearrange the barcodes so that no two adjacent barcodes are equal.  You may return any answer, and it is guaranteed an answer exists.

    - -

     

    - -

    Example 1:

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

    Example 2:

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

     

    - -

    Note:

    - -
      -
    1. 1 <= barcodes.length <= 10000
    2. -
    3. 1 <= barcodes[i] <= 10000
    4. -
    - -
    - -
     
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md b/leetcode/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md deleted file mode 100644 index 4e1f48ff..00000000 --- a/leetcode/solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [1071. Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings) - -[中文文档](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README.md) - -## Description - -

    For strings S and T, we say "T divides S" if and only if S = T + ... + T  (T concatenated with itself 1 or more times)

    - -

    Return the largest string X such that X divides str1 and X divides str2.

    - -

     

    - -

    Example 1:

    - -
    -Input: str1 = "ABCABC", str2 = "ABC"
    -Output: "ABC"
    -
    - -

    Example 2:

    - -
    -Input: str1 = "ABABAB", str2 = "ABAB"
    -Output: "AB"
    -
    - -

    Example 3:

    - -
    -Input: str1 = "LEET", str2 = "CODE"
    -Output: ""
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= str1.length <= 1000
    2. -
    3. 1 <= str2.length <= 1000
    4. -
    5. str1[i] and str2[i] are English uppercase letters.
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md b/leetcode/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md deleted file mode 100644 index e6cf36dc..00000000 --- a/leetcode/solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md +++ /dev/null @@ -1,98 +0,0 @@ -# [1072. Flip Columns For Maximum Number of Equal Rows](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows) - -[中文文档](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README.md) - -## Description - -

    Given a matrix consisting of 0s and 1s, we may choose any number of columns in the matrix and flip every cell in that column.  Flipping a cell changes the value of that cell from 0 to 1 or from 1 to 0.

    - -

    Return the maximum number of rows that have all values equal after some number of flips.

    - -

     

    - -
      - -
    - -
    - -

    Example 1:

    - -
    -
    -Input: [[0,1],[1,1]]
    -
    -Output: 1
    -
    -Explanation: After flipping no values, 1 row has all values equal.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: [[0,1],[1,0]]
    -
    -Output: 2
    -
    -Explanation: After flipping values in the first column, both rows have equal values.
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: [[0,0,0],[0,0,1],[1,1,0]]
    -
    -Output: 2
    -
    -Explanation: After flipping values in the first two columns, the last two rows have equal values.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= matrix.length <= 300
    2. -
    3. 1 <= matrix[i].length <= 300
    4. -
    5. All matrix[i].length's are equal
    6. -
    7. matrix[i][j] is 0 or 1
    8. -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md b/leetcode/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md deleted file mode 100644 index 7393cb28..00000000 --- a/leetcode/solution/1000-1099/1073.Adding Two Negabinary Numbers/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [1073. Adding Two Negabinary Numbers](https://leetcode.com/problems/adding-two-negabinary-numbers) - -[中文文档](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README.md) - -## Description - -

    Given two numbers arr1 and arr2 in base -2, return the result of adding them together.

    - -

    Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.  A number arr in array format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.

    - -

    Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.

    - -

     

    - -

    Example 1:

    - -
    -Input: arr1 = [1,1,1,1,1], arr2 = [1,0,1]
    -Output: [1,0,0,0,0]
    -Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= arr1.length <= 1000
    2. -
    3. 1 <= arr2.length <= 1000
    4. -
    5. arr1 and arr2 have no leading zeros
    6. -
    7. arr1[i] is 0 or 1
    8. -
    9. arr2[i] is 0 or 1
    10. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md b/leetcode/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md deleted file mode 100644 index 96104539..00000000 --- a/leetcode/solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [1074. Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target) - -[中文文档](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README.md) - -## Description - -

    Given a matrix, and a target, return the number of non-empty submatrices that sum to target.

    - -

    A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.

    - -

    Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0
    -
    -Output: 4
    -
    -Explanation: The four 1x1 submatrices that only contain 0.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: matrix = [[1,-1],[-1,1]], target = 0
    -
    -Output: 5
    -
    -Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.
    -
    -
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= matrix.length <= 300
    2. -
    3. 1 <= matrix[0].length <= 300
    4. -
    5. -1000 <= matrix[i] <= 1000
    6. -
    7. -10^8 <= target <= 10^8
    8. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md b/leetcode/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md deleted file mode 100644 index 39955198..00000000 --- a/leetcode/solution/1000-1099/1079.Letter Tile Possibilities/README_EN.md +++ /dev/null @@ -1,68 +0,0 @@ -# [1079. Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities) - -[中文文档](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README.md) - -## Description - -

    You have a set of tiles, where each tile has one letter tiles[i] printed on it.  Return the number of possible non-empty sequences of letters you can make.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: "AAB"
    -
    -Output: 8
    -
    -Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: "AAABBC"
    -
    -Output: 188
    -
    -
    - -

     

    - -
    - -

    Note:

    - -
      -
    1. 1 <= tiles.length <= 7
    2. -
    3. tiles consists of uppercase English letters.
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md b/leetcode/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md deleted file mode 100644 index 12e30632..00000000 --- a/leetcode/solution/1000-1099/1080.Insufficient Nodes in Root to Leaf Paths/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [1080. Insufficient Nodes in Root to Leaf Paths](https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths) - -[中文文档](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README.md) - -## Description - -

    Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf.  (A leaf is a node with no children.)

    - -

    A node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.

    - -

    Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.

    - -

     

    - -

    Example 1:

    - -![](./images/insufficient-11.png) - -
    -
    -
    -
    -Input: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1
    - -![](./images/insufficient-2.png) - -
    -
    -Output: [1,2,3,4,null,null,7,8,9,null,14]
    -
    -
    - -
    - -

    Example 2:

    - -![](./images/insufficient-3.png) - -
    -Input: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22
    - -![](./images/insufficient-4.png) - -
    -
    -Output: [5,4,8,11,null,17,4,7,null,null,null,5]
    - -

     

    - -

    Example 3:

    - -![](./images/screen-shot-2019-06-11-at-83301-pm.png) - -
    -
    -
    -
    -Input: root = [1,2,-3,-5,null,4,null], limit = -1
    - -![](./images/screen-shot-2019-06-11-at-83517-pm.png) - -
    -
    -
    -Output: [1,null,-3,4]
    - -
    - -

     

    - -

    Note:

    - -
      -
    1. The given tree will have between 1 and 5000 nodes.
    2. -
    3. -10^5 <= node.val <= 10^5
    4. -
    5. -10^9 <= limit <= 10^9
    6. -
    - -
    - -
     
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md b/leetcode/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md deleted file mode 100644 index e077273b..00000000 --- a/leetcode/solution/1000-1099/1081.Smallest Subsequence of Distinct Characters/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [1081. Smallest Subsequence of Distinct Characters](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters) - -[中文文档](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README.md) - -## Description - -

    Return the lexicographically smallest subsequence of text that contains all the distinct characters of text exactly once.

    - -

    Example 1:

    - -
    -Input: "cdadabcc"
    -Output: "adbc"
    -
    - -
    -

    Example 2:

    - -
    -Input: "abcd"
    -Output: "abcd"
    -
    - -
    -

    Example 3:

    - -
    -Input: "ecbacba"
    -Output: "eacb"
    -
    - -
    -

    Example 4:

    - -
    -Input: "leetcode"
    -Output: "letcod"
    -
    - -

     

    - -

    Constraints:

    - -
      -
    1. 1 <= text.length <= 1000
    2. -
    3. text consists of lowercase English letters.
    4. -
    - -

    Note: This question is the same as 316: https://leetcode.com/problems/remove-duplicate-letters/

    -
    -
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1089.Duplicate Zeros/README_EN.md b/leetcode/solution/1000-1099/1089.Duplicate Zeros/README_EN.md deleted file mode 100644 index 5343d9d8..00000000 --- a/leetcode/solution/1000-1099/1089.Duplicate Zeros/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [1089. Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros) - -[中文文档](/solution/1000-1099/1089.Duplicate%20Zeros/README.md) - -## Description - -

    Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.

    - -

    Note that elements beyond the length of the original array are not written.

    - -

    Do the above modifications to the input array in place, do not return anything from your function.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: [1,0,2,3,0,4,5,0]
    -
    -Output: null
    -
    -Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: [1,2,3]
    -
    -Output: null
    -
    -Explanation: After calling your function, the input array is modified to: [1,2,3]
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= arr.length <= 10000
    2. -
    3. 0 <= arr[i] <= 9
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1090.Largest Values From Labels/README_EN.md b/leetcode/solution/1000-1099/1090.Largest Values From Labels/README_EN.md deleted file mode 100644 index 749d325e..00000000 --- a/leetcode/solution/1000-1099/1090.Largest Values From Labels/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [1090. Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels) - -[中文文档](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README.md) - -## Description - -

    We have a set of items: the i-th item has value values[i] and label labels[i].

    - -

    Then, we choose a subset S of these items, such that:

    - -
      -
    • |S| <= num_wanted
    • -
    • For every label L, the number of items in S with label L is <= use_limit.
    • -
    - -

    Return the largest possible sum of the subset S.

    - -

     

    - -
    - -

    Example 1:

    - -
    -
    -Input: values = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1
    -
    -Output: 9
    -
    -Explanation: The subset chosen is the first, third, and fifth item.
    -
    -
    - -
    - -

    Example 2:

    - -
    -
    -Input: values = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2
    -
    -Output: 12
    -
    -Explanation: The subset chosen is the first, second, and third item.
    -
    -
    - -
    - -

    Example 3:

    - -
    -
    -Input: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1
    -
    -Output: 16
    -
    -Explanation: The subset chosen is the first and fourth item.
    -
    -
    - -
    - -

    Example 4:

    - -
    -
    -Input: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2
    -
    -Output: 24
    -
    -Explanation: The subset chosen is the first, second, and fourth item.
    -
    -
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= values.length == labels.length <= 20000
    2. -
    3. 0 <= values[i], labels[i] <= 20000
    4. -
    5. 1 <= num_wanted, use_limit <= values.length
    6. -
    - -
    - -
    - -
    - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md b/leetcode/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md deleted file mode 100644 index a40d17db..00000000 --- a/leetcode/solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md +++ /dev/null @@ -1,79 +0,0 @@ -# [1091. Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix) - -[中文文档](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README.md) - -## Description - -

    In an N by N square grid, each cell is either empty (0) or blocked (1).

    - -

    clear path from top-left to bottom-right has length k if and only if it is composed of cells C_1, C_2, ..., C_k such that:

    - -
      -
    • Adjacent cells C_i and C_{i+1} are connected 8-directionally (ie., they are different and share an edge or corner)
    • -
    • C_1 is at location (0, 0) (ie. has value grid[0][0])
    • -
    • C_k is at location (N-1, N-1) (ie. has value grid[N-1][N-1])
    • -
    • If C_i is located at (r, c), then grid[r][c] is empty (ie. grid[r][c] == 0).
    • -
    - -

    Return the length of the shortest such clear path from top-left to bottom-right.  If such a path does not exist, return -1.

    - -

     

    - -

    Example 1:

    - -
    -Input: [[0,1],[1,0]]
    - -![](./images/example1_1.png) - -
    Output: 2
    - -![](./images/example1_2.png) - -
    -

    Example 2:

    - -
    -Input: [[0,0,0],[1,1,0],[1,1,0]]
    -
    - -![](./images/example2_1.png) - -
    Output: 4
    -
    - -![](./images/example2_2.png) - -

     

    -
    - -

    Note:

    - -
      -
    1. 1 <= grid.length == grid[0].length <= 100
    2. -
    3. grid[r][c] is 0 or 1
    4. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md b/leetcode/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md deleted file mode 100644 index e1e16138..00000000 --- a/leetcode/solution/1000-1099/1093.Statistics from a Large Sample/README_EN.md +++ /dev/null @@ -1,58 +0,0 @@ -# [1093. Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample) - -[中文文档](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README.md) - -## Description - -

    We sampled integers between 0 and 255, and stored the results in an array countcount[k] is the number of integers we sampled equal to k.

    - -

    Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of floating point numbers.  The mode is guaranteed to be unique.

    - -

    (Recall that the median of a sample is:

    - -
      -
    • The middle element, if the elements of the sample were sorted and the number of elements is odd;
    • -
    • The average of the middle two elements, if the elements of the sample were sorted and the number of elements is even.)
    • -
    - -

     

    -

    Example 1:

    -
    Input: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    -Output: [1.00000,3.00000,2.37500,2.50000,3.00000]
    -

    Example 2:

    -
    Input: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    -Output: [1.00000,4.00000,2.18182,2.00000,1.00000]
    -
    -

     

    -

    Constraints:

    - -
      -
    1. count.length == 256
    2. -
    3. 1 <= sum(count) <= 10^9
    4. -
    5. The mode of the sample that count represents is unique.
    6. -
    7. Answers within 10^-5 of the true value will be accepted as correct.
    8. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1094.Car Pooling/README_EN.md b/leetcode/solution/1000-1099/1094.Car Pooling/README_EN.md deleted file mode 100644 index a8aaeb82..00000000 --- a/leetcode/solution/1000-1099/1094.Car Pooling/README_EN.md +++ /dev/null @@ -1,90 +0,0 @@ -# [1094. Car Pooling](https://leetcode.com/problems/car-pooling) - -[中文文档](/solution/1000-1099/1094.Car%20Pooling/README.md) - -## Description - -

    You are driving a vehicle that has capacity empty seats initially available for passengers.  The vehicle only drives east (ie. it cannot turn around and drive west.)

    - -

    Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.  The locations are given as the number of kilometers due east from your vehicle's initial location.

    - -

    Return true if and only if it is possible to pick up and drop off all passengers for all the given trips. 

    - -

     

    - -

    Example 1:

    - -
    -Input: trips = [[2,1,5],[3,3,7]], capacity = 4
    -Output: false
    -
    - -
    -

    Example 2:

    - -
    -Input: trips = [[2,1,5],[3,3,7]], capacity = 5
    -Output: true
    -
    - -
    -

    Example 3:

    - -
    -Input: trips = [[2,1,5],[3,5,7]], capacity = 3
    -Output: true
    -
    - -
    -

    Example 4:

    - -
    -Input: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11
    -Output: true
    -
    -
    -
    -
    - -
    -
    -
    -
     
    -
    -
    -
    - -

     

    -

    Constraints:

    - -
      -
    1. trips.length <= 1000
    2. -
    3. trips[i].length == 3
    4. -
    5. 1 <= trips[i][0] <= 100
    6. -
    7. 0 <= trips[i][1] < trips[i][2] <= 1000
    8. -
    9. 1 <= capacity <= 100000
    10. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1000-1099/1095.Find in Mountain Array/README_EN.md b/leetcode/solution/1000-1099/1095.Find in Mountain Array/README_EN.md deleted file mode 100644 index 463d9a18..00000000 --- a/leetcode/solution/1000-1099/1095.Find in Mountain Array/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [1095. Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array) - -[中文文档](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README.md) - -## Description - -

    (This problem is an interactive problem.)

    - -

    You may recall that an array A is a mountain array if and only if:

    - -
      -
    • A.length >= 3
    • -
    • There exists some i with 0 < i < A.length - 1 such that: -
        -
      • A[0] < A[1] < ... A[i-1] < A[i]
      • -
      • A[i] > A[i+1] > ... > A[A.length - 1]
      • -
      -
    • -
    - -

    Given a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target.  If such an index doesn't exist, return -1.

    - -

    You can't access the mountain array directly.  You may only access the array using a MountainArray interface:

    - -
      -
    • MountainArray.get(k) returns the element of the array at index k (0-indexed).
    • -
    • MountainArray.length() returns the length of the array.
    • -
    - -

    Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer.  Also, any solutions that attempt to circumvent the judge will result in disqualification.

    - -
      -
    - -

     

    -

    Example 1:

    - -
    -Input: array = [1,2,3,4,5,3,1], target = 3
    -Output: 2
    -Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.
    - -

    Example 2:

    - -
    -Input: array = [0,1,2,4,2,1], target = 3
    -Output: -1
    -Explanation: 3 does not exist in the array, so we return -1.
    -
    - -

     

    -

    Constraints:

    - -
      -
    1. 3 <= mountain_arr.length() <= 10000
    2. -
    3. 0 <= target <= 10^9
    4. -
    5. 0 <= mountain_arr.get(index) <= 10^9
    6. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1103.Distribute Candies to People/README_EN.md b/leetcode/solution/1100-1199/1103.Distribute Candies to People/README_EN.md deleted file mode 100644 index 5451232a..00000000 --- a/leetcode/solution/1100-1199/1103.Distribute Candies to People/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [1103. Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people) - -[中文文档](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README.md) - -## Description - -

    We distribute some number of candies, to a row of n = num_people people in the following way:

    - -

    We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.

    - -

    Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person.

    - -

    This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift).

    - -

    Return an array (of length num_people and sum candies) that represents the final distribution of candies.

    - -

     

    -

    Example 1:

    - -
    -Input: candies = 7, num_people = 4
    -Output: [1,2,3,1]
    -Explanation:
    -On the first turn, ans[0] += 1, and the array is [1,0,0,0].
    -On the second turn, ans[1] += 2, and the array is [1,2,0,0].
    -On the third turn, ans[2] += 3, and the array is [1,2,3,0].
    -On the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].
    -
    - -

    Example 2:

    - -
    -Input: candies = 10, num_people = 3
    -Output: [5,2,3]
    -Explanation: 
    -On the first turn, ans[0] += 1, and the array is [1,0,0].
    -On the second turn, ans[1] += 2, and the array is [1,2,0].
    -On the third turn, ans[2] += 3, and the array is [1,2,3].
    -On the fourth turn, ans[0] += 4, and the final array is [5,2,3].
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= candies <= 10^9
    • -
    • 1 <= num_people <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md b/leetcode/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md deleted file mode 100644 index 7089b401..00000000 --- a/leetcode/solution/1100-1199/1104.Path In Zigzag Labelled Binary Tree/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [1104. Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree) - -[中文文档](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README.md) - -## Description - -

    In an infinite binary tree where every node has two children, the nodes are labelled in row order.

    - -

    In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

    - -![](./images/tree.png) - -

    Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.

    - -

     

    -

    Example 1:

    - -
    -Input: label = 14
    -Output: [1,3,4,14]
    -
    - -

    Example 2:

    - -
    -Input: label = 26
    -Output: [1,2,6,10,26]
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= label <= 10^6
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1108.Defanging an IP Address/README_EN.md b/leetcode/solution/1100-1199/1108.Defanging an IP Address/README_EN.md deleted file mode 100644 index 6e9206fd..00000000 --- a/leetcode/solution/1100-1199/1108.Defanging an IP Address/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [1108. Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address) - -[中文文档](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README.md) - -## Description - -

    Given a valid (IPv4) IP address, return a defanged version of that IP address.

    - -

    A defanged IP address replaces every period "." with "[.]".

    - -

     

    - -

    Example 1:

    - -
    Input: address = "1.1.1.1"
    -
    -Output: "1[.]1[.]1[.]1"
    -
    -

    Example 2:

    - -
    Input: address = "255.100.50.0"
    -
    -Output: "255[.]100[.]50[.]0"
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • The given address is a valid IPv4 address.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md b/leetcode/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md deleted file mode 100644 index 260ddf7a..00000000 --- a/leetcode/solution/1100-1199/1109.Corporate Flight Bookings/README_EN.md +++ /dev/null @@ -1,57 +0,0 @@ -# [1109. Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings) - -[中文文档](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README.md) - -## Description - -

    There are n flights, and they are labeled from 1 to n.

    - -

    We have a list of flight bookings.  The i-th booking bookings[i] = [i, j, k] means that we booked k seats from flights labeled i to j inclusive.

    - -

    Return an array answer of length n, representing the number of seats booked on each flight in order of their label.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
    -
    -Output: [10,55,45,25,25]
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= bookings.length <= 20000
    • -
    • 1 <= bookings[i][0] <= bookings[i][1] <= n <= 20000
    • -
    • 1 <= bookings[i][2] <= 10000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md b/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md deleted file mode 100644 index 6e94317f..00000000 --- a/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/README_EN.md +++ /dev/null @@ -1,60 +0,0 @@ -# [1110. Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest) - -[中文文档](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README.md) - -## Description - -

    Given the root of a binary tree, each node in the tree has a distinct value.

    - -

    After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).

    - -

    Return the roots of the trees in the remaining forest.  You may return the result in any order.

    - -

     

    - -

    Example 1:

    - -![](./images/screen-shot-2019-07-01-at-53836-pm.png) - -
    -
    -Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]
    -
    -Output: [[1,2,null,4],[6],[7]]
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • The number of nodes in the given tree is at most 1000.
    • -
    • Each node has a distinct value between 1 and 1000.
    • -
    • to_delete.length <= 1000
    • -
    • to_delete contains distinct values between 1 and 1000.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/Solution.py b/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/Solution.py deleted file mode 100644 index bacbb7d7..00000000 --- a/leetcode/solution/1100-1199/1110.Delete Nodes And Return Forest/Solution.py +++ /dev/null @@ -1,55 +0,0 @@ -''' -https://leetcode.com/problems/delete-nodes-and-return-forest/ -Given the root of a binary tree, each node in the tree has a distinct value. - -After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees). - -Return the roots of the trees in the remaining forest. You may return the result in any order. - -''' -# Performance -''' -Runtime: 52 ms, faster than 99.34% of Python3 online submissions for Delete Nodes And Return Forest. -Memory Usage: 12.8 MB, less than 100.00% of Python3 online submissions for Delete Nodes And Return Forest. -''' -''' -n: number of node -m: number of to_delete -Runtime: O(n) -Space: O(log n) or O(m) -''' - - -class Solution: - def delNodes(self, root, to_delete): - # Change to set to for better check runtime - set_delete = set(to_delete) - forests = [] - # Only add a node in the forest when - # 1) Its parent is in set_delete - # 2) It's not in set_delete - # dfs return False when 1) Node is none and 2) node is in set_delete - # When that happen, set the parent link to that node to None - - def dfs(node, is_parent_in_delete): - nonlocal set_delete, forests - if not node: - return False - # Still traverse subsequent node but return False - if node.val in set_delete: - if node.left: - dfs(node.left, True) - if node.right: - dfs(node.right, True) - return False - # Add the current node to the forest - if is_parent_in_delete: - forests.append(node) - # Set the child to none when the child is in set_delete - if node.left and not dfs(node.left, False): - node.left = None - if node.right and not dfs(node.right, False): - node.right = None - return True - dfs(root, True) - return forests diff --git a/leetcode/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md b/leetcode/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md deleted file mode 100644 index db49b01a..00000000 --- a/leetcode/solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md +++ /dev/null @@ -1,77 +0,0 @@ -# [1111. Maximum Nesting Depth of Two Valid Parentheses Strings](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings) - -[中文文档](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README.md) - -## Description - -

    A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and:

    - -
      -
    • It is the empty string, or
    • -
    • It can be written as AB (A concatenated with B), where A and B are VPS's, or
    • -
    • It can be written as (A), where A is a VPS.
    • -
    - -

    We can similarly define the nesting depth depth(S) of any VPS S as follows:

    - -
      -
    • depth("") = 0
    • -
    • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
    • -
    • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
    • -
    - -

    For example,  """()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

    - -

     

    - -

    Given a VPS seq, split it into two disjoint subsequences A and B, such that A and B are VPS's (and A.length + B.length = seq.length).

    - -

    Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value.

    - -

    Return an answer array (of length seq.length) that encodes such a choice of A and Banswer[i] = 0 if seq[i] is part of A, else answer[i] = 1.  Note that even though multiple answers may exist, you may return any of them.

    - -

     

    -

    Example 1:

    - -
    -Input: seq = "(()())"
    -Output: [0,1,1,1,1,0]
    -
    - -

    Example 2:

    - -
    -Input: seq = "()(())()"
    -Output: [0,0,0,1,1,0,1,1]
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= seq.size <= 10000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1114.Print in Order/README_EN.md b/leetcode/solution/1100-1199/1114.Print in Order/README_EN.md deleted file mode 100644 index 1c8f9bd6..00000000 --- a/leetcode/solution/1100-1199/1114.Print in Order/README_EN.md +++ /dev/null @@ -1,64 +0,0 @@ -# [1114. Print in Order](https://leetcode.com/problems/print-in-order) - -[中文文档](/solution/1100-1199/1114.Print%20in%20Order/README.md) - -## Description - -

    Suppose we have a class:

    - -
    -public class Foo {
    -  public void first() { print("first"); }
    -  public void second() { print("second"); }
    -  public void third() { print("third"); }
    -}
    -
    - -

    The same instance of Foo will be passed to three different threads. Thread A will call first(), thread B will call second(), and thread C will call third(). Design a mechanism and modify the program to ensure that second() is executed after first(), and third() is executed after second().

    - -

     

    - -

    Example 1:

    - -
    -Input: [1,2,3]
    -Output: "firstsecondthird"
    -Explanation: There are three threads being fired asynchronously. The input [1,2,3] means thread A calls first(), thread B calls second(), and thread C calls third(). "firstsecondthird" is the correct output.
    -
    - -

    Example 2:

    - -
    -Input: [1,3,2]
    -Output: "firstsecondthird"
    -Explanation: The input [1,3,2] means thread A calls first(), thread B calls third(), and thread C calls second(). "firstsecondthird" is the correct output.
    - -

     

    - -

    Note:

    - -

    We do not know how the threads will be scheduled in the operating system, even though the numbers in the input seems to imply the ordering. The input format you see is mainly to ensure our tests' comprehensiveness.

    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1114.Print in Order/Solution.cpp b/leetcode/solution/1100-1199/1114.Print in Order/Solution.cpp deleted file mode 100644 index 86bcc6ce..00000000 --- a/leetcode/solution/1100-1199/1114.Print in Order/Solution.cpp +++ /dev/null @@ -1,34 +0,0 @@ -class Foo { -public: - Foo() { - _mutex1.lock(); - _mutex2.lock(); - } - - void first(function printFirst) { - - printFirst(); - _mutex1.unlock(); - } - - void second(function printSecond) { - - _mutex1.lock(); - printSecond(); - _mutex1.unlock(); - _mutex2.unlock(); - } - - void third(function printThird) { - - _mutex2.lock(); - printThird(); - _mutex2.unlock(); - } - - -private: - std::mutex _mutex1; - std::mutex _mutex2; - -}; diff --git a/leetcode/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md b/leetcode/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md deleted file mode 100644 index 6bad2d4f..00000000 --- a/leetcode/solution/1100-1199/1115.Print FooBar Alternately/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [1115. Print FooBar Alternately](https://leetcode.com/problems/print-foobar-alternately) - -[中文文档](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README.md) - -## Description - -

    Suppose you are given the following code:

    - -
    -class FooBar {
    -  public void foo() {
    -    for (int i = 0; i < n; i++) {
    -      print("foo");
    -    }
    -  }
    -
    -  public void bar() {
    -    for (int i = 0; i < n; i++) {
    -      print("bar");
    -    }
    -  }
    -}
    -
    - -

    The same instance of FooBar will be passed to two different threads. Thread A will call foo() while thread B will call bar(). Modify the given program to output "foobar" n times.

    - -

     

    - -

    Example 1:

    - -
    -Input: n = 1
    -Output: "foobar"
    -Explanation: There are two threads being fired asynchronously. One of them calls foo(), while the other calls bar(). "foobar" is being output 1 time.
    -
    - -

    Example 2:

    - -
    -Input: n = 2
    -Output: "foobarfoobar"
    -Explanation: "foobar" is being output 2 times.
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1115.Print FooBar Alternately/Solution.cpp b/leetcode/solution/1100-1199/1115.Print FooBar Alternately/Solution.cpp deleted file mode 100644 index fef97d0d..00000000 --- a/leetcode/solution/1100-1199/1115.Print FooBar Alternately/Solution.cpp +++ /dev/null @@ -1,30 +0,0 @@ -class FooBar { -private: - int n; - std::mutex _mutex1; - std::mutex _mutex2; - -public: - FooBar(int n) { - this->n = n; - _mutex2.lock(); - } - - void foo(function printFoo) { - - for (int i = 0; i < n; i++) { - _mutex1.lock(); - printFoo(); - _mutex2.unlock(); - } - } - - void bar(function printBar) { - - for (int i = 0; i < n; i++) { - _mutex2.lock(); - printBar(); - _mutex1.unlock(); - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md b/leetcode/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md deleted file mode 100644 index 41ff99fc..00000000 --- a/leetcode/solution/1100-1199/1116.Print Zero Even Odd/README_EN.md +++ /dev/null @@ -1,67 +0,0 @@ -# [1116. Print Zero Even Odd](https://leetcode.com/problems/print-zero-even-odd) - -[中文文档](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README.md) - -## Description - -

    Suppose you are given the following code:

    - -
    -class ZeroEvenOdd {
    -  public ZeroEvenOdd(int n) { ... }      // constructor
    -  public void zero(printNumber) { ... }  // only output 0's
    -  public void even(printNumber) { ... }  // only output even numbers
    -  public void odd(printNumber) { ... }   // only output odd numbers
    -}
    -
    - -

    The same instance of ZeroEvenOdd will be passed to three different threads:

    - -
      -
    1. Thread A will call zero() which should only output 0's.
    2. -
    3. Thread B will call even() which should only ouput even numbers.
    4. -
    5. Thread C will call odd() which should only output odd numbers.
    6. -
    - -

    Each of the threads is given a printNumber method to output an integer. Modify the given program to output the series 010203040506... where the length of the series must be 2n.

    - -

     

    - -

    Example 1:

    - -
    -Input: n = 2
    -Output: "0102"
    -Explanation: There are three threads being fired asynchronously. One of them calls zero(), the other calls even(), and the last one calls odd(). "0102" is the correct output.
    -
    - -

    Example 2:

    - -
    -Input: n = 5
    -Output: "0102030405"
    -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1116.Print Zero Even Odd/Solution.cpp b/leetcode/solution/1100-1199/1116.Print Zero Even Odd/Solution.cpp deleted file mode 100644 index 72e48792..00000000 --- a/leetcode/solution/1100-1199/1116.Print Zero Even Odd/Solution.cpp +++ /dev/null @@ -1,43 +0,0 @@ -class ZeroEvenOdd { -private: - int n; - int flag; - mutex m1,m2,m3; - -public: - ZeroEvenOdd(int n) { - this->n = n; - flag = 1; //奇偶判断 - m1.lock(); - m2.lock(); - m3.lock(); - } - - // printNumber(x) outputs "x", where x is an integer. - void zero(function printNumber) { - m3.unlock(); - for(int i = 0; i < n ;i++){ - m3.lock(); - printNumber(0); - if(flag == 1)flag = 0,m2.unlock(); - else flag = 1,m1.unlock(); - } - } - - - void odd(function printNumber) { //输出奇数 - for(int i = 1;i <= n; i+=2){ - m2.lock(); - printNumber(i); - m3.unlock(); - } - } - - void even(function printNumber) { //输出偶数 - for(int i = 2;i <= n; i+=2){ - m1.lock(); - printNumber(i); - m3.unlock(); - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/1100-1199/1117.Building H2O/README_EN.md b/leetcode/solution/1100-1199/1117.Building H2O/README_EN.md deleted file mode 100644 index a7bc17b8..00000000 --- a/leetcode/solution/1100-1199/1117.Building H2O/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [1117. Building H2O](https://leetcode.com/problems/building-h2o) - -[中文文档](/solution/1100-1199/1117.Building%20H2O/README.md) - -## Description - -

    There are two kinds of threads, oxygen and hydrogen. Your goal is to group these threads to form water molecules. There is a barrier where each thread has to wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given releaseHydrogen and releaseOxygen methods respectively, which will allow them to pass the barrier. These threads should pass the barrier in groups of three, and they must be able to immediately bond with each other to form a water molecule. You must guarantee that all the threads from one molecule bond before any other threads from the next molecule do.

    - -

    In other words:

    - -
      -
    • If an oxygen thread arrives at the barrier when no hydrogen threads are present, it has to wait for two hydrogen threads.
    • -
    • If a hydrogen thread arrives at the barrier when no other threads are present, it has to wait for an oxygen thread and another hydrogen thread.
    • -
    - -

    We don’t have to worry about matching the threads up explicitly; that is, the threads do not necessarily know which other threads they are paired up with. The key is just that threads pass the barrier in complete sets; thus, if we examine the sequence of threads that bond and divide them into groups of three, each group should contain one oxygen and two hydrogen threads.

    - -

    Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

    - -
    -

     

    -
    - -
    -

    Example 1:

    - -
    -Input: "HOH"
    -Output: "HHO"
    -Explanation: "HOH" and "OHH" are also valid answers.
    -
    - -
    -

    Example 2:

    - -
    -Input: "OOHHHH"
    -Output: "HHOHHO"
    -Explanation: "HOHHHO", "OHHHHO", "HHOHOH", "HOHHOH", "OHHHOH", "HHOOHH", "HOHOHH" and "OHHOHH" are also valid answers.
    -
    -
    -
    - -

     

    -

    Constraints:

    - -
      -
    • Total length of input string will be 3n, where 1 ≤ n ≤ 20.
    • -
    • Total number of H will be 2n in the input string.
    • -
    • Total number of O will be n in the input string.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1117.Building H2O/Solution.cpp b/leetcode/solution/1100-1199/1117.Building H2O/Solution.cpp deleted file mode 100644 index 27fd4ace..00000000 --- a/leetcode/solution/1100-1199/1117.Building H2O/Solution.cpp +++ /dev/null @@ -1,25 +0,0 @@ -class H2O { -private: - int n_h; - mutex m_h,m_o; -public: - H2O() { - m_o.lock(); - n_h = 2; - } - - void hydrogen(function releaseHydrogen) { - m_h.lock(); - releaseHydrogen(); - n_h--; - if(n_h > 0)m_h.unlock(); - else m_o.unlock(); - } - - void oxygen(function releaseOxygen) { - m_o.lock(); - releaseOxygen(); - n_h = 2; - m_h.unlock(); - } -}; \ No newline at end of file diff --git a/leetcode/solution/1100-1199/1122.Relative Sort Array/README_EN.md b/leetcode/solution/1100-1199/1122.Relative Sort Array/README_EN.md deleted file mode 100644 index 198f629b..00000000 --- a/leetcode/solution/1100-1199/1122.Relative Sort Array/README_EN.md +++ /dev/null @@ -1,48 +0,0 @@ -# [1122. Relative Sort Array](https://leetcode.com/problems/relative-sort-array) - -[中文文档](/solution/1100-1199/1122.Relative%20Sort%20Array/README.md) - -## Description - -

    Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.

    - -

    Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2.  Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.

    - -

     

    -

    Example 1:

    -
    Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
    -Output: [2,2,2,1,4,3,3,9,6,7,19]
    -
    -

     

    -

    Constraints:

    - -
      -
    • arr1.length, arr2.length <= 1000
    • -
    • 0 <= arr1[i], arr2[i] <= 1000
    • -
    • Each arr2[i] is distinct.
    • -
    • Each arr2[i] is in arr1.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md b/leetcode/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md deleted file mode 100644 index b3e8e2a5..00000000 --- a/leetcode/solution/1100-1199/1123.Lowest Common Ancestor of Deepest Leaves/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [1123. Lowest Common Ancestor of Deepest Leaves](https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves) - -[中文文档](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README.md) - -## Description - -

    Given a rooted binary tree, return the lowest common ancestor of its deepest leaves.

    - -

    Recall that:

    - -
      -
    • The node of a binary tree is a leaf if and only if it has no children
    • -
    • The depth of the root of the tree is 0, and if the depth of a node is d, the depth of each of its children is d+1.
    • -
    • The lowest common ancestor of a set S of nodes is the node A with the largest depth such that every node in S is in the subtree with root A.
    • -
    - -

     

    -

    Example 1:

    - -
    -Input: root = [1,2,3]
    -Output: [1,2,3]
    -Explanation: 
    -The deepest leaves are the nodes with values 2 and 3.
    -The lowest common ancestor of these leaves is the node with value 1.
    -The answer returned is a TreeNode object (not an array) with serialization "[1,2,3]".
    -
    - -

    Example 2:

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

    Example 3:

    - -
    -Input: root = [1,2,3,4,5]
    -Output: [2,4,5]
    -
    - -

     

    -

    Constraints:

    - -
      -
    • The given tree will have between 1 and 1000 nodes.
    • -
    • Each node of the tree will have a distinct value between 1 and 1000.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md b/leetcode/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md deleted file mode 100644 index 1d2c1bca..00000000 --- a/leetcode/solution/1100-1199/1124.Longest Well-Performing Interval/README_EN.md +++ /dev/null @@ -1,54 +0,0 @@ -# [1124. Longest Well-Performing Interval](https://leetcode.com/problems/longest-well-performing-interval) - -[中文文档](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README.md) - -## Description - -

    We are given hours, a list of the number of hours worked per day for a given employee.

    - -

    A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.

    - -

    A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.

    - -

    Return the length of the longest well-performing interval.

    - -

     

    -

    Example 1:

    - -
    -Input: hours = [9,9,6,0,6,6,9]
    -Output: 3
    -Explanation: The longest well-performing interval is [9,9,6].
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= hours.length <= 10000
    • -
    • 0 <= hours[i] <= 16
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md b/leetcode/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md deleted file mode 100644 index 38fee516..00000000 --- a/leetcode/solution/1100-1199/1128.Number of Equivalent Domino Pairs/README_EN.md +++ /dev/null @@ -1,52 +0,0 @@ -# [1128. Number of Equivalent Domino Pairs](https://leetcode.com/problems/number-of-equivalent-domino-pairs) - -[中文文档](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README.md) - -## Description - -

    Given a list of dominoesdominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a==c and b==d), or (a==d and b==c) - that is, one domino can be rotated to be equal to another domino.

    - -

    Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].

    - -

     

    - -

    Example 1:

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

     

    - -

    Constraints:

    - -
      -
    • 1 <= dominoes.length <= 40000
    • -
    • 1 <= dominoes[i][j] <= 9
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md b/leetcode/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md deleted file mode 100644 index a597ef0a..00000000 --- a/leetcode/solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [1137. N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number) - -[中文文档](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md) - -## Description - -

    The Tribonacci sequence Tn is defined as follows: 

    - -

    T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

    - -

    Given n, return the value of Tn.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: n = 4
    -
    -Output: 4
    -
    -Explanation:
    -
    -T_3 = 0 + 1 + 1 = 2
    -
    -T_4 = 1 + 1 + 2 = 4
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: n = 25
    -
    -Output: 1389537
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 0 <= n <= 37
    • -
    • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1138.Alphabet Board Path/README_EN.md b/leetcode/solution/1100-1199/1138.Alphabet Board Path/README_EN.md deleted file mode 100644 index 08088385..00000000 --- a/leetcode/solution/1100-1199/1138.Alphabet Board Path/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [1138. Alphabet Board Path](https://leetcode.com/problems/alphabet-board-path) - -[中文文档](/solution/1100-1199/1138.Alphabet%20Board%20Path/README.md) - -## Description - -

    On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].

    - -

    Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.

    - -![](./images/azboard.png) - -

    We may make the following moves:

    - -
      -
    • 'U' moves our position up one row, if the position exists on the board;
    • -
    • 'D' moves our position down one row, if the position exists on the board;
    • -
    • 'L' moves our position left one column, if the position exists on the board;
    • -
    • 'R' moves our position right one column, if the position exists on the board;
    • -
    • '!' adds the character board[r][c] at our current position (r, c) to the answer.
    • - -
    - -

    (Here, the only positions that exist on the board are positions with letters on them.)

    - -

    Return a sequence of moves that makes our answer equal to target in the minimum number of moves.  You may return any path that does so.

    - -

     

    - -

    Example 1:

    - -
    Input: target = "leet"
    -
    -Output: "DDR!UURRR!!DDD!"
    -
    -

    Example 2:

    - -
    Input: target = "code"
    -
    -Output: "RR!DDRR!UUL!R!"
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= target.length <= 100
    • -
    • target consists only of English lowercase letters.
    • - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md b/leetcode/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md deleted file mode 100644 index 60cf71ce..00000000 --- a/leetcode/solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md +++ /dev/null @@ -1,63 +0,0 @@ -# [1139. Largest 1-Bordered Square](https://leetcode.com/problems/largest-1-bordered-square) - -[中文文档](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README.md) - -## Description - -

    Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: grid = [[1,1,1],[1,0,1],[1,1,1]]
    -
    -Output: 9
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: grid = [[1,1,0,0]]
    -
    -Output: 1
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= grid.length <= 100
    • -
    • 1 <= grid[0].length <= 100
    • -
    • grid[i][j] is 0 or 1
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1140.Stone Game II/README_EN.md b/leetcode/solution/1100-1199/1140.Stone Game II/README_EN.md deleted file mode 100644 index 4e66ca20..00000000 --- a/leetcode/solution/1100-1199/1140.Stone Game II/README_EN.md +++ /dev/null @@ -1,62 +0,0 @@ -# [1140. Stone Game II](https://leetcode.com/problems/stone-game-ii) - -[中文文档](/solution/1100-1199/1140.Stone%20Game%20II/README.md) - -## Description - -

    Alex and Lee continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones. 

    - -

    Alex and Lee take turns, with Alex starting first.  Initially, M = 1.

    - -

    On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M.  Then, we set M = max(M, X).

    - -

    The game continues until all the stones have been taken.

    - -

    Assuming Alex and Lee play optimally, return the maximum number of stones Alex can get.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: piles = [2,7,9,4,4]
    -
    -Output: 10
    -
    -Explanation:  If Alex takes one pile at the beginning, Lee takes two piles, then Alex takes 2 piles again. Alex can get 2 + 4 + 4 = 10 piles in total. If Alex takes two piles at the beginning, then Lee can take all three piles left. In this case, Alex get 2 + 7 = 9 piles in total. So we return 10 since it's larger. 
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= piles.length <= 100
    • -
    • 1 <= piles[i] <= 10 ^ 4
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md b/leetcode/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md deleted file mode 100644 index 80792e4c..00000000 --- a/leetcode/solution/1100-1199/1144.Decrease Elements To Make Array Zigzag/README_EN.md +++ /dev/null @@ -1,64 +0,0 @@ -# [1144. Decrease Elements To Make Array Zigzag](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag) - -[中文文档](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README.md) - -## Description - -

    Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.

    - -

    An array A is a zigzag array if either:

    - -
      -
    • Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
    • -
    • OR, every odd-indexed element is greater than adjacent elements, ie. A[0] < A[1] > A[2] < A[3] > A[4] < ...
    • -
    - -

    Return the minimum number of moves to transform the given array nums into a zigzag array.

    - -

     

    -

    Example 1:

    - -
    -Input: nums = [1,2,3]
    -Output: 2
    -Explanation: We can decrease 2 to 0 or 3 to 1.
    -
    - -

    Example 2:

    - -
    -Input: nums = [9,6,1,6,2]
    -Output: 4
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 1000
    • -
    • 1 <= nums[i] <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md b/leetcode/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md deleted file mode 100644 index 846a9b33..00000000 --- a/leetcode/solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md +++ /dev/null @@ -1,96 +0,0 @@ -# [1147. Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition) - -[中文文档](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README.md) - -## Description - -

    Return the largest possible k such that there exists a_1, a_2, ..., a_k such that:

    - -
      -
    • Each a_i is a non-empty string;
    • -
    • Their concatenation a_1 + a_2 + ... + a_k is equal to text;
    • -
    • For all 1 <= i <= k,  a_i = a_{k+1 - i}.
    • -
    - -

     

    - -

    Example 1:

    - -
    -
    -Input: text = "ghiabcdefhelloadamhelloabcdefghi"
    -
    -Output: 7
    -
    -Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: text = "merchant"
    -
    -Output: 1
    -
    -Explanation: We can split the string on "(merchant)".
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: text = "antaprezatepzapreanta"
    -
    -Output: 11
    -
    -Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: text = "aaa"
    -
    -Output: 3
    -
    -Explanation: We can split the string on "(a)(a)(a)".
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • text consists only of lowercase English characters.
    • -
    • 1 <= text.length <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md b/leetcode/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md deleted file mode 100644 index 6097aa86..00000000 --- a/leetcode/solution/1100-1199/1155.Number of Dice Rolls With Target Sum/README_EN.md +++ /dev/null @@ -1,116 +0,0 @@ -# [1155. Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum) - -[中文文档](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README.md) - -## Description - -

    You have d dice, and each die has f faces numbered 1, 2, ..., f.

    - -

    Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the face up numbers equals target.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: d = 1, f = 6, target = 3
    -
    -Output: 1
    -
    -Explanation: 
    -
    -You throw one die with 6 faces.  There is only one way to get a sum of 3.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: d = 2, f = 6, target = 7
    -
    -Output: 6
    -
    -Explanation: 
    -
    -You throw two dice, each with 6 faces.  There are 6 ways to get a sum of 7:
    -
    -1+6, 2+5, 3+4, 4+3, 5+2, 6+1.
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: d = 2, f = 5, target = 10
    -
    -Output: 1
    -
    -Explanation: 
    -
    -You throw two dice, each with 5 faces.  There is only one way to get a sum of 10: 5+5.
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: d = 1, f = 2, target = 3
    -
    -Output: 0
    -
    -Explanation: 
    -
    -You throw one die with 2 faces.  There is no way to get a sum of 3.
    -
    -
    - -

    Example 5:

    - -
    -
    -Input: d = 30, f = 30, target = 500
    -
    -Output: 222616187
    -
    -Explanation: 
    -
    -The answer must be returned modulo 10^9 + 7.
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= d, f <= 30
    • -
    • 1 <= target <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md b/leetcode/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md deleted file mode 100644 index 65d4a17f..00000000 --- a/leetcode/solution/1100-1199/1171.Remove Zero Sum Consecutive Nodes from Linked List/README_EN.md +++ /dev/null @@ -1,66 +0,0 @@ -# [1171. Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list) - -[中文文档](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md) - -## Description - -

    Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.

    - -

    After doing so, return the head of the final linked list.  You may return any such answer.

    - -

     

    -

    (Note that in the examples below, all sequences are serializations of ListNode objects.)

    - -

    Example 1:

    - -
    -Input: head = [1,2,-3,3,1]
    -Output: [3,1]
    -Note: The answer [1,2,1] would also be accepted.
    -
    - -

    Example 2:

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

    Example 3:

    - -
    -Input: head = [1,2,3,-3,-2]
    -Output: [1]
    -
    - -

     

    -

    Constraints:

    - -
      -
    • The given linked list will contain between 1 and 1000 nodes.
    • -
    • Each node in the linked list has -1000 <= node.val <= 1000.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md b/leetcode/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md deleted file mode 100644 index 17b0ae2c..00000000 --- a/leetcode/solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md +++ /dev/null @@ -1,92 +0,0 @@ -# [1184. Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops) - -[中文文档](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README.md) - -## Description - -

    A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.

    - -

    The bus goes along both directions i.e. clockwise and counterclockwise.

    - -

    Return the shortest distance between the given start and destination stops.

    - -

     

    - -

    Example 1:

    - -![](./images/untitled-diagram-1.jpg) - -
    -
    -Input: distance = [1,2,3,4], start = 0, destination = 1
    -
    -Output: 1
    -
    -Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
    - -

     

    - -

    Example 2:

    - -![](./images/untitled-diagram-1-1.jpg) - -
    -
    -Input: distance = [1,2,3,4], start = 0, destination = 2
    -
    -Output: 3
    -
    -Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.
    -
    -
    - -

     

    - -

    Example 3:

    - -![](./images/untitled-diagram-1-2.jpg) - -
    -
    -Input: distance = [1,2,3,4], start = 0, destination = 3
    -
    -Output: 4
    -
    -Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= n <= 10^4
    • -
    • distance.length == n
    • -
    • 0 <= start, destination < n
    • -
    • 0 <= distance[i] <= 10^4
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1185.Day of the Week/README_EN.md b/leetcode/solution/1100-1199/1185.Day of the Week/README_EN.md deleted file mode 100644 index 88f9b057..00000000 --- a/leetcode/solution/1100-1199/1185.Day of the Week/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [1185. Day of the Week](https://leetcode.com/problems/day-of-the-week) - -[中文文档](/solution/1100-1199/1185.Day%20of%20the%20Week/README.md) - -## Description - -

    Given a date, return the corresponding day of the week for that date.

    - -

    The input is given as three integers representing the day, month and year respectively.

    - -

    Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: day = 31, month = 8, year = 2019
    -
    -Output: "Saturday"
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: day = 18, month = 7, year = 1999
    -
    -Output: "Sunday"
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: day = 15, month = 8, year = 1993
    -
    -Output: "Sunday"
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • The given dates are valid dates between the years 1971 and 2100.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md b/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md deleted file mode 100644 index 3bb1ce19..00000000 --- a/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/README_EN.md +++ /dev/null @@ -1,59 +0,0 @@ -# [1195. Fizz Buzz Multithreaded](https://leetcode.com/problems/fizz-buzz-multithreaded) - -[中文文档](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README.md) - -## Description - -

    Write a program that outputs the string representation of numbers from 1 to n, however:

    - -
      -
    • If the number is divisible by 3, output "fizz".
    • -
    • If the number is divisible by 5, output "buzz".
    • -
    • If the number is divisible by both 3 and 5, output "fizzbuzz".
    • -
    - -

    For example, for n = 15, we output: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz.

    - -

    Suppose you are given the following code:

    - -
    -class FizzBuzz {
    -  public FizzBuzz(int n) { ... }               // constructor
    -  public void fizz(printFizz) { ... }          // only output "fizz"
    -  public void buzz(printBuzz) { ... }          // only output "buzz"
    -  public void fizzbuzz(printFizzBuzz) { ... }  // only output "fizzbuzz"
    -  public void number(printNumber) { ... }      // only output the numbers
    -}
    - -

    Implement a multithreaded version of FizzBuzz with four threads. The same instance of FizzBuzz will be passed to four different threads:

    - -
      -
    1. Thread A will call fizz() to check for divisibility of 3 and outputs fizz.
    2. -
    3. Thread B will call buzz() to check for divisibility of 5 and outputs buzz.
    4. -
    5. Thread C will call fizzbuzz() to check for divisibility of 3 and 5 and outputs fizzbuzz.
    6. -
    7. Thread D will call number() which should only output the numbers.
    8. -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/Solution.cpp b/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/Solution.cpp deleted file mode 100644 index 59141210..00000000 --- a/leetcode/solution/1100-1199/1195.Fizz Buzz Multithreaded/Solution.cpp +++ /dev/null @@ -1,56 +0,0 @@ -class FizzBuzz { -private: - std::mutex mtx; - atomic index; - int n; - -public: - FizzBuzz(int n) { - this->n = n; - index = 1; - } - - // printFizz() outputs "fizz". - void fizz(function printFizz) { - while (index <= n) { - std::lock_guard lk(mtx); - if (0 == index % 3 && 0 != index % 5 && index <= n) { - printFizz(); - index++; - } - } - } - - // printBuzz() outputs "buzz". - void buzz(function printBuzz) { - while (index <= n) { - std::lock_guard lk(mtx); - if (0 == index % 5 && 0 != index % 3 && index <= n){ - printBuzz(); - index++; - } - } - } - - // printFizzBuzz() outputs "fizzbuzz". - void fizzbuzz(function printFizzBuzz) { - while (index <= n) { - std::lock_guard lk(mtx); - if (0 == index % 15 && index <= n) { - printFizzBuzz(); - index++; - } - } - } - - // printNumber(x) outputs "x", where x is an integer. - void number(function printNumber) { - while (index <= n) { - std::lock_guard lk(mtx); - if (0 != index % 3 && 0 != index % 5 && index <= n) { - printNumber(index); - index++; - } - } - } -}; \ No newline at end of file diff --git a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md b/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md deleted file mode 100644 index 71fafa11..00000000 --- a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md +++ /dev/null @@ -1,52 +0,0 @@ -# [1287. Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) - -[中文文档](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%%20In%20Sorted%20Array/README.md) - -## Description - -

    Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.

    - -

    Return that integer.

    - -

     

    - -

    Example 1:

    - -
    Input: arr = [1,2,2,6,6,6,6,7,10]
    -
    -Output: 6
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= arr.length <= 10^4
    • -
    • 0 <= arr[i] <= 10^5
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.js b/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.js deleted file mode 100644 index 6be3f6af..00000000 --- a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.js +++ /dev/null @@ -1,16 +0,0 @@ -const findSpecialInteger = function (arr) { - let count = 0; - let item = -1; - for (var i = 0; i < arr.length; i++) { - if (item == arr[i]) { - count++; - } else { - item = arr[i]; - count = 1; - } - if (count > arr.length * 0.25) { - return item; - } - } - return item; -}; diff --git a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.py b/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.py deleted file mode 100644 index fa6c0672..00000000 --- a/leetcode/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.py +++ /dev/null @@ -1,7 +0,0 @@ -class Solution: - def findSpecialInteger(self, arr: List[int]) -> int: - total = len(arr) - for i, val in enumerate(arr): - if val == arr[i + (total >> 2)]: - return val - return 0 \ No newline at end of file diff --git a/leetcode/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md b/leetcode/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md deleted file mode 100644 index 6252969d..00000000 --- a/leetcode/solution/1200-1299/1290.Convert Binary Number in a Linked List to Integer/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [1290. Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) - -[中文文档](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README.md) - -## Description - -

    Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.

    - -

    Return the decimal value of the number in the linked list.

    - -

     

    - -

    Example 1:

    - -![](./images/graph-1.png) - -
    -
    -Input: head = [1,0,1]
    -
    -Output: 5
    -
    -Explanation: (101) in base 2 = (5) in base 10
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: head = [0]
    -
    -Output: 0
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: head = [1]
    -
    -Output: 1
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]
    -
    -Output: 18880
    -
    -
    - -

    Example 5:

    - -
    -
    -Input: head = [0,0]
    -
    -Output: 0
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • The Linked List is not empty.
    • -
    • Number of nodes will not exceed 30.
    • -
    • Each node's value is either 0 or 1.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md b/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md deleted file mode 100644 index 16f5f7fe..00000000 --- a/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/README_EN.md +++ /dev/null @@ -1,76 +0,0 @@ -# [1295. Find Numbers with Even Number of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) - -[中文文档](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README.md) - -## Description - -Given an array nums of integers, return how many of them contain an even number of digits. - -

     

    -

    Example 1:

    - -
    -Input: nums = [12,345,2,6,7896]
    -Output: 2
    -Explanation: 
    -12 contains 2 digits (even number of digits). 
    -345 contains 3 digits (odd number of digits). 
    -2 contains 1 digit (odd number of digits). 
    -6 contains 1 digit (odd number of digits). 
    -7896 contains 4 digits (even number of digits). 
    -Therefore only 12 and 7896 contain an even number of digits.
    -
    - -

    Example 2:

    - -
    -Input: nums = [555,901,482,1771]
    -Output: 1 
    -Explanation: 
    -Only 1771 contains an even number of digits.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 500
    • -
    • 1 <= nums[i] <= 10^5
    • -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def findNumbers(self, nums: List[int]) -> int: - res = 0 - for num in nums: - res += (len(str(num)) & 1) == 0 - return res -``` - -### **Java** - -```java -class Solution { - public int findNumbers(int[] nums) { - int res = 0; - for (int num : nums) { - res += (String.valueOf(num).length() & 1) == 0 ? 1 : 0; - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/Solution.py b/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/Solution.py deleted file mode 100644 index 3bf16410..00000000 --- a/leetcode/solution/1200-1299/1295.Find Numbers with Even Number of Digits/Solution.py +++ /dev/null @@ -1,6 +0,0 @@ -class Solution: - def findNumbers(self, nums: List[int]) -> int: - res = 0 - for num in nums: - res += (len(str(num)) & 1) == 0 - return res diff --git a/leetcode/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md b/leetcode/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md deleted file mode 100644 index 5b4927c4..00000000 --- a/leetcode/solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [1346. Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist) - -[中文文档](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README.md) - -## Description - -

    Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).

    - -

    More formally check if there exists two indices i and j such that :

    - -
      -
    • i != j
    • -
    • 0 <= i, j < arr.length
    • -
    • arr[i] == 2 * arr[j]
    • -
    - -

     

    -

    Example 1:

    - -
    -Input: arr = [10,2,5,3]
    -Output: true
    -Explanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.
    -
    - -

    Example 2:

    - -
    -Input: arr = [7,1,14,11]
    -Output: true
    -Explanation: N = 14 is the double of M = 7,that is, 14 = 2 * 7.
    -
    - -

    Example 3:

    - -
    -Input: arr = [3,1,7,11]
    -Output: false
    -Explanation: In this case does not exist N and M, such that N = 2 * M.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 2 <= arr.length <= 500
    • -
    • -10^3 <= arr[i] <= 10^3
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md b/leetcode/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md deleted file mode 100644 index 025709e7..00000000 --- a/leetcode/solution/1300-1399/1347.Minimum Number of Steps to Make Two Strings Anagram/README_EN.md +++ /dev/null @@ -1,83 +0,0 @@ -# [1347. Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram) - -[中文文档](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README.md) - -## Description - -

    Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.

    - -

    Return the minimum number of steps to make t an anagram of s.

    - -

    An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

    - -

     

    -

    Example 1:

    - -
    -Input: s = "bab", t = "aba"
    -Output: 1
    -Explanation: Replace the first 'a' in t with b, t = "bba" which is anagram of s.
    -
    - -

    Example 2:

    - -
    -Input: s = "leetcode", t = "practice"
    -Output: 5
    -Explanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.
    -
    - -

    Example 3:

    - -
    -Input: s = "anagram", t = "mangaar"
    -Output: 0
    -Explanation: "anagram" and "mangaar" are anagrams. 
    -
    - -

    Example 4:

    - -
    -Input: s = "xxyyzz", t = "xxyyzz"
    -Output: 0
    -
    - -

    Example 5:

    - -
    -Input: s = "friend", t = "family"
    -Output: 4
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= s.length <= 50000
    • -
    • s.length == t.length
    • -
    • s and t contain lower-case English letters only.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md b/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md deleted file mode 100644 index 288667be..00000000 --- a/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md +++ /dev/null @@ -1,110 +0,0 @@ -# [1380. Lucky Numbers in a Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix) - -[中文文档](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README.md) - -## Description - -

    Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

    - -

    A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
    -
    -Output: [15]
    -
    -Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
    -
    -Output: [12]
    -
    -Explanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: matrix = [[7,8],[1,2]]
    -
    -Output: [7]
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • m == mat.length
    • -
    • n == mat[i].length
    • -
    • 1 <= n, m <= 50
    • -
    • 1 <= matrix[i][j] <= 10^5.
    • -
    • All elements in the matrix are distinct.
    • -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def luckyNumbers (self, matrix: List[List[int]]) -> List[int]: - row_min = {min(rows) for rows in matrix} - col_max = {max(cols) for cols in zip(*matrix)} - return [e for e in row_min if e in col_max] -``` - -### **Java** - -```java -class Solution { - public List luckyNumbers (int[][] matrix) { - int m = matrix.length, n = matrix[0].length; - Set rowMin = new HashSet<>(); - List res = new ArrayList<>(); - for (int i = 0; i < m; ++i) { - int min = Integer.MAX_VALUE; - for (int j = 0; j < n; ++j) { - min = Math.min(min, matrix[i][j]); - } - rowMin.add(min); - } - - for (int j = 0; j < n; ++j) { - int max = Integer.MIN_VALUE; - for (int i = 0; i < m; ++i) { - max = Math.max(max, matrix[i][j]); - } - if (rowMin.contains(max)) { - res.add(max); - } - - } - return res; - } -} -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/Solution.py b/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/Solution.py deleted file mode 100644 index c12eff06..00000000 --- a/leetcode/solution/1300-1399/1380.Lucky Numbers in a Matrix/Solution.py +++ /dev/null @@ -1,5 +0,0 @@ -class Solution: - def luckyNumbers (self, matrix: List[List[int]]) -> List[int]: - row_min = {min(rows) for rows in matrix} - col_max = {max(cols) for cols in zip(*matrix)} - return [e for e in row_min if e in col_max] diff --git a/leetcode/solution/1400-1499/1476.Subrectangle Queries/README_EN.md b/leetcode/solution/1400-1499/1476.Subrectangle Queries/README_EN.md deleted file mode 100644 index 61ea9a8f..00000000 --- a/leetcode/solution/1400-1499/1476.Subrectangle Queries/README_EN.md +++ /dev/null @@ -1,157 +0,0 @@ -# [1476. Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries) - -[中文文档](/solution/1400-1499/1476.Subrectangle%20Queries/README.md) - -## Description - -

    Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods:

    - -

    1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)

    - -
      -
    • Updates all values with newValue in the subrectangle whose upper left coordinate is (row1,col1) and bottom right coordinate is (row2,col2).
    • -
    - -

    2. getValue(int row, int col)

    - -
      -
    • Returns the current value of the coordinate (row,col) from the rectangle.
    • -
    - -

     

    - -

    Example 1:

    - -
    -
    -Input
    -
    -["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]
    -
    -[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]
    -
    -Output
    -
    -[null,1,null,5,5,null,10,5]
    -
    -Explanation
    -
    -SubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]);  
    -
    -// The initial rectangle (4x3) looks like:
    -
    -// 1 2 1
    -
    -// 4 3 4
    -
    -// 3 2 1
    -
    -// 1 1 1
    -
    -subrectangleQueries.getValue(0, 2); // return 1
    -
    -subrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);
    -
    -// After this update the rectangle looks like:
    -
    -// 5 5 5
    -
    -// 5 5 5
    -
    -// 5 5 5
    -
    -// 5 5 5 
    -
    -subrectangleQueries.getValue(0, 2); // return 5
    -
    -subrectangleQueries.getValue(3, 1); // return 5
    -
    -subrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);
    -
    -// After this update the rectangle looks like:
    -
    -// 5   5   5
    -
    -// 5   5   5
    -
    -// 5   5   5
    -
    -// 10  10  10 
    -
    -subrectangleQueries.getValue(3, 1); // return 10
    -
    -subrectangleQueries.getValue(0, 2); // return 5
    -
    -
    - -

    Example 2:

    - -
    -
    -Input
    -
    -["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"]
    -
    -[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]
    -
    -Output
    -
    -[null,1,null,100,100,null,20]
    -
    -Explanation
    -
    -SubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);
    -
    -subrectangleQueries.getValue(0, 0); // return 1
    -
    -subrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);
    -
    -subrectangleQueries.getValue(0, 0); // return 100
    -
    -subrectangleQueries.getValue(2, 2); // return 100
    -
    -subrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);
    -
    -subrectangleQueries.getValue(2, 2); // return 20
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • There will be at most 500 operations considering both methods: updateSubrectangle and getValue.
    • -
    • 1 <= rows, cols <= 100
    • -
    • rows == rectangle.length
    • -
    • cols == rectangle[i].length
    • -
    • 0 <= row1 <= row2 < rows
    • -
    • 0 <= col1 <= col2 < cols
    • -
    • 1 <= newValue, rectangle[i][j] <= 10^9
    • -
    • 0 <= row < rows
    • -
    • 0 <= col < cols
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md b/leetcode/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md deleted file mode 100644 index 4842352c..00000000 --- a/leetcode/solution/1500-1599/1535.Find the Winner of an Array Game/README_EN.md +++ /dev/null @@ -1,107 +0,0 @@ -# [1535. Find the Winner of an Array Game](https://leetcode.com/problems/find-the-winner-of-an-array-game) - -[中文文档](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README.md) - -## Description - -

    Given an integer array arr of distinct integers and an integer k.

    - -

    A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0 and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.

    - -

    Return the integer which will win the game.

    - -

    It is guaranteed that there will be a winner of the game.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: arr = [2,1,3,5,4,6,7], k = 2
    -
    -Output: 5
    -
    -Explanation: Let's see the rounds of the game:
    -
    -Round |       arr       | winner | win_count
    -
    -  1   | [2,1,3,5,4,6,7] | 2      | 1
    -
    -  2   | [2,3,5,4,6,7,1] | 3      | 1
    -
    -  3   | [3,5,4,6,7,1,2] | 5      | 1
    -
    -  4   | [5,4,6,7,1,2,3] | 5      | 2
    -
    -So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: arr = [3,2,1], k = 10
    -
    -Output: 3
    -
    -Explanation: 3 will win the first 10 rounds consecutively.
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: arr = [1,9,8,2,3,7,6,4,5], k = 7
    -
    -Output: 9
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: arr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000
    -
    -Output: 99
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 2 <= arr.length <= 10^5
    • -
    • 1 <= arr[i] <= 10^6
    • -
    • arr contains distinct integers.
    • -
    • 1 <= k <= 10^9
    • - -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1537.Get the Maximum Score/README_EN.md b/leetcode/solution/1500-1599/1537.Get the Maximum Score/README_EN.md deleted file mode 100644 index c178cdf3..00000000 --- a/leetcode/solution/1500-1599/1537.Get the Maximum Score/README_EN.md +++ /dev/null @@ -1,93 +0,0 @@ -# [1537. Get the Maximum Score](https://leetcode.com/problems/get-the-maximum-score) - -[中文文档](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README.md) - -## Description - -

    You are given two sorted arrays of distinct integers nums1 and nums2.

    - -

    A valid path is defined as follows:

    - -
      -
    • Choose array nums1 or nums2 to traverse (from index-0).
    • -
    • Traverse the current array from left to right.
    • -
    • If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).
    • -
    - -

    Score is defined as the sum of uniques values in a valid path.

    - -

    Return the maximum score you can obtain of all possible valid paths.

    - -

    Since the answer may be too large, return it modulo 10^9 + 7.

    - -

     

    -

    Example 1:

    - -![](./images/sample_1_1893.png) - -
    -Input: nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]
    -Output: 30
    -Explanation: Valid paths:
    -[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10],  (starting from nums1)
    -[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10]    (starting from nums2)
    -The maximum is obtained with the path in green [2,4,6,8,10].
    -
    - -

    Example 2:

    - -
    -Input: nums1 = [1,3,5,7,9], nums2 = [3,5,100]
    -Output: 109
    -Explanation: Maximum sum is obtained with the path [1,3,5,100].
    -
    - -

    Example 3:

    - -
    -Input: nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]
    -Output: 40
    -Explanation: There are no common elements between nums1 and nums2.
    -Maximum sum is obtained with the path [6,7,8,9,10].
    -
    - -

    Example 4:

    - -
    -Input: nums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]
    -Output: 61
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums1.length <= 10^5
    • -
    • 1 <= nums2.length <= 10^5
    • -
    • 1 <= nums1[i], nums2[i] <= 10^7
    • -
    • nums1 and nums2 are strictly increasing.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md b/leetcode/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md deleted file mode 100644 index ee0bd1a3..00000000 --- a/leetcode/solution/1500-1599/1541.Minimum Insertions to Balance a Parentheses String/README_EN.md +++ /dev/null @@ -1,93 +0,0 @@ -# [1541. Minimum Insertions to Balance a Parentheses String](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string) - -[中文文档](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md) - -## Description - -

    Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:

    - -
      -
    • Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.
    • -
    • Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.
    • -
    - -

    In other words, we treat '(' as openning parenthesis and '))' as closing parenthesis.

    - -

    For example, "())", "())(())))" and "(())())))" are balanced, ")()", "()))" and "(()))" are not balanced.

    - -

    You can insert the characters '(' and ')' at any position of the string to balance it if needed.

    - -

    Return the minimum number of insertions needed to make s balanced.

    - -

     

    -

    Example 1:

    - -
    -Input: s = "(()))"
    -Output: 1
    -Explanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to to add one more ')' at the end of the string to be "(())))" which is balanced.
    -
    - -

    Example 2:

    - -
    -Input: s = "())"
    -Output: 0
    -Explanation: The string is already balanced.
    -
    - -

    Example 3:

    - -
    -Input: s = "))())("
    -Output: 3
    -Explanation: Add '(' to match the first '))', Add '))' to match the last '('.
    -
    - -

    Example 4:

    - -
    -Input: s = "(((((("
    -Output: 12
    -Explanation: Add 12 ')' to balance the string.
    -
    - -

    Example 5:

    - -
    -Input: s = ")))))))"
    -Output: 5
    -Explanation: Add 4 '(' at the beginning of the string and one ')' at the end. The string becomes "(((())))))))".
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= s.length <= 10^5
    • -
    • s consists of '(' and ')' only.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1544.Make The String Great/README_EN.md b/leetcode/solution/1500-1599/1544.Make The String Great/README_EN.md deleted file mode 100644 index 539bf939..00000000 --- a/leetcode/solution/1500-1599/1544.Make The String Great/README_EN.md +++ /dev/null @@ -1,93 +0,0 @@ -# [1544. Make The String Great](https://leetcode.com/problems/make-the-string-great) - -[中文文档](/solution/1500-1599/1544.Make%20The%20String%20Great/README.md) - -## Description - -

    Given a string s of lower and upper case English letters.

    - -

    A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:

    - -
      -
    • 0 <= i <= s.length - 2
    • -
    • s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
    • -
    - -

    To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.

    - -

    Return the string after making it good. The answer is guaranteed to be unique under the given constraints.

    - -

    Notice that an empty string is also good.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: s = "leEeetcode"
    -
    -Output: "leetcode"
    -
    -Explanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: s = "abBAcC"
    -
    -Output: ""
    -
    -Explanation: We have many possible scenarios, and all lead to the same answer. For example:
    -
    -"abBAcC" --> "aAcC" --> "cC" --> ""
    -
    -"abBAcC" --> "abBA" --> "aA" --> ""
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: s = "s"
    -
    -Output: "s"
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= s.length <= 100
    • -
    • s contains only lower and upper case English letters.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md b/leetcode/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md deleted file mode 100644 index 86a9595a..00000000 --- a/leetcode/solution/1500-1599/1545.Find Kth Bit in Nth Binary String/README_EN.md +++ /dev/null @@ -1,104 +0,0 @@ -# [1545. Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string) - -[中文文档](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README.md) - -## Description - -

    Given two positive integers n and k, the binary string  Sn is formed as follows:

    - -
      -
    • S1 = "0"
    • -
    • Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
    • -
    - -

    Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).

    - -

    For example, the first 4 strings in the above sequence are:

    - -
      -
    • S= "0"
    • -
    • S= "011"
    • -
    • S= "0111001"
    • -
    • S4 = "011100110110001"
    • -
    - -

    Return the kth bit in Sn. It is guaranteed that k is valid for the given n.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: n = 3, k = 1
    -
    -Output: "0"
    -
    -Explanation: S3 is "0111001". The first bit is "0".
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: n = 4, k = 11
    -
    -Output: "1"
    -
    -Explanation: S4 is "011100110110001". The 11th bit is "1".
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: n = 1, k = 1
    -
    -Output: "0"
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: n = 2, k = 3
    -
    -Output: "1"
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= n <= 20
    • -
    • 1 <= k <= 2n - 1
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md b/leetcode/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md deleted file mode 100644 index f1007ab6..00000000 --- a/leetcode/solution/1500-1599/1546.Maximum Number of Non-Overlapping Subarrays With Sum Equals Target/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target) - -[中文文档](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README.md) - -## Description - -

    Given an array nums and an integer target.

    - -

    Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.

    - -

     

    -

    Example 1:

    - -
    -Input: nums = [1,1,1,1,1], target = 2
    -Output: 2
    -Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).
    -
    - -

    Example 2:

    - -
    -Input: nums = [-1,3,5,1,4,2,-9], target = 6
    -Output: 2
    -Explanation: There are 3 subarrays with sum equal to 6.
    -([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping.
    - -

    Example 3:

    - -
    -Input: nums = [-2,6,6,3,5,4,1,2,8], target = 10
    -Output: 3
    -
    - -

    Example 4:

    - -
    -Input: nums = [0,0,0], target = 0
    -Output: 3
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 10^5
    • -
    • -10^4 <= nums[i] <= 10^4
    • -
    • 0 <= target <= 10^6
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md b/leetcode/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md deleted file mode 100644 index adcabdae..00000000 --- a/leetcode/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md +++ /dev/null @@ -1,56 +0,0 @@ -# [1550. Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds) - -[中文文档](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README.md) - -## Description - -Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. - -

     

    -

    Example 1:

    - -
    -Input: arr = [2,6,4,1]
    -Output: false
    -Explanation: There are no three consecutive odds.
    -
    - -

    Example 2:

    - -
    -Input: arr = [1,2,34,3,4,5,7,23,12]
    -Output: true
    -Explanation: [5,7,23] are three consecutive odds.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= arr.length <= 1000
    • -
    • 1 <= arr[i] <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md b/leetcode/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md deleted file mode 100644 index 18176c62..00000000 --- a/leetcode/solution/1500-1599/1551.Minimum Operations to Make Array Equal/README_EN.md +++ /dev/null @@ -1,71 +0,0 @@ -# [1551. Minimum Operations to Make Array Equal](https://leetcode.com/problems/minimum-operations-to-make-array-equal) - -[中文文档](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README.md) - -## Description - -

    You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).

    - -

    In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.

    - -

    Given an integer n, the length of the array. Return the minimum number of operations needed to make all the elements of arr equal.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: n = 3
    -
    -Output: 2
    -
    -Explanation: arr = [1, 3, 5]
    -
    -First operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]
    -
    -In the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: n = 6
    -
    -Output: 9
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= n <= 10^4
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md b/leetcode/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md deleted file mode 100644 index 125096c8..00000000 --- a/leetcode/solution/1500-1599/1552.Magnetic Force Between Two Balls/README_EN.md +++ /dev/null @@ -1,65 +0,0 @@ -# [1552. Magnetic Force Between Two Balls](https://leetcode.com/problems/magnetic-force-between-two-balls) - -[中文文档](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README.md) - -## Description - -

    In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.

    - -

    Rick stated that magnetic force between two different balls at positions x and y is |x - y|.

    - -

    Given the integer array position and the integer m. Return the required force.

    - -

     

    -

    Example 1:

    - -![](./images/q3v1.jpg) - -
    -Input: position = [1,2,3,4,7], m = 3
    -Output: 3
    -Explanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.
    -
    - -

    Example 2:

    - -
    -Input: position = [5,4,3,2,1,1000000000], m = 2
    -Output: 999999999
    -Explanation: We can use baskets 1 and 1000000000.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • n == position.length
    • -
    • 2 <= n <= 10^5
    • -
    • 1 <= position[i] <= 10^9
    • -
    • All integers in position are distinct.
    • -
    • 2 <= m <= position.length
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md b/leetcode/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md deleted file mode 100644 index 91ab7f01..00000000 --- a/leetcode/solution/1500-1599/1553.Minimum Number of Days to Eat N Oranges/README_EN.md +++ /dev/null @@ -1,113 +0,0 @@ -# [1553. Minimum Number of Days to Eat N Oranges](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges) - -[中文文档](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README.md) - -## Description - -

    There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:

    - -
      -
    • Eat one orange.
    • -
    • If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges.
    • -
    • If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges.
    • -
    - -

    You can only choose one of the actions per day.

    - -

    Return the minimum number of days to eat n oranges.

    - -

     

    - -

    Example 1:

    - -
    -
    -Input: n = 10
    -
    -Output: 4
    -
    -Explanation: You have 10 oranges.
    -
    -Day 1: Eat 1 orange,  10 - 1 = 9.  
    -
    -Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)
    -
    -Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. 
    -
    -Day 4: Eat the last orange  1 - 1  = 0.
    -
    -You need at least 4 days to eat the 10 oranges.
    -
    -
    - -

    Example 2:

    - -
    -
    -Input: n = 6
    -
    -Output: 3
    -
    -Explanation: You have 6 oranges.
    -
    -Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).
    -
    -Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)
    -
    -Day 3: Eat the last orange  1 - 1  = 0.
    -
    -You need at least 3 days to eat the 6 oranges.
    -
    -
    - -

    Example 3:

    - -
    -
    -Input: n = 1
    -
    -Output: 1
    -
    -
    - -

    Example 4:

    - -
    -
    -Input: n = 56
    -
    -Output: 6
    -
    -
    - -

     

    - -

    Constraints:

    - -
      -
    • 1 <= n <= 2*10^9
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md b/leetcode/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md deleted file mode 100644 index 83641d72..00000000 --- a/leetcode/solution/1500-1599/1560.Most Visited Sector in a Circular Track/README_EN.md +++ /dev/null @@ -1,72 +0,0 @@ -# [1560. Most Visited Sector in a Circular Track](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) - -[中文文档](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README.md) - -## Description - -

    Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]

    - -

    Return an array of the most visited sectors sorted in ascending order.

    - -

    Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).

    - -

     

    -

    Example 1:

    - -![](./images/tmp.jpg) - -
    -Input: n = 4, rounds = [1,3,1,2]
    -Output: [1,2]
    -Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:
    -1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)
    -We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.
    - -

    Example 2:

    - -
    -Input: n = 2, rounds = [2,1,2,1,2,1,2,1,2]
    -Output: [2]
    -
    - -

    Example 3:

    - -
    -Input: n = 7, rounds = [1,3,5,7]
    -Output: [1,2,3,4,5,6,7]
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 2 <= n <= 100
    • -
    • 1 <= m <= 100
    • -
    • rounds.length == m + 1
    • -
    • 1 <= rounds[i] <= n
    • -
    • rounds[i] != rounds[i + 1] for 0 <= i < m
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md b/leetcode/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md deleted file mode 100644 index bf8b3da4..00000000 --- a/leetcode/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README_EN.md +++ /dev/null @@ -1,78 +0,0 @@ -# [1561. Maximum Number of Coins You Can Get](https://leetcode.com/problems/maximum-number-of-coins-you-can-get) - -[中文文档](/solution/1500-1599/1561.Maximum Number of Coins You Can Get/README.md) - -## Description - -

    There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:

    - -
      -
    • In each step, you will choose any 3 piles of coins (not necessarily consecutive).
    • -
    • Of your choice, Alice will pick the pile with the maximum number of coins.
    • -
    • You will pick the next pile with maximum number of coins.
    • -
    • Your friend Bob will pick the last pile.
    • -
    • Repeat until there are no more piles of coins.
    • -
    - -

    Given an array of integers piles where piles[i] is the number of coins in the ith pile.

    - -

    Return the maximum number of coins which you can have.

    - -

     

    -

    Example 1:

    - -
    -Input: piles = [2,4,1,2,7,8]
    -Output: 9
    -Explanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.
    -Choose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.
    -The maximum number of coins which you can have are: 7 + 2 = 9.
    -On the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.
    -
    - -

    Example 2:

    - -
    -Input: piles = [2,4,5]
    -Output: 4
    -
    - -

    Example 3:

    - -
    -Input: piles = [9,8,7,6,5,1,2,3,4]
    -Output: 18
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 3 <= piles.length <= 10^5
    • -
    • piles.length % 3 == 0
    • -
    • 1 <= piles[i] <= 10^4
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md b/leetcode/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md deleted file mode 100644 index 3e5ccaf9..00000000 --- a/leetcode/solution/1500-1599/1562.Find Latest Group of Size M/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [1562. Find Latest Group of Size M](https://leetcode.com/problems/find-latest-group-of-size-m) - -[中文文档](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README.md) - -## Description - -

    Given an array arr that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero.

    - -

    At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1. You are given an integer m and you need to find the latest step at which there exists a group of ones of length m. A group of ones is a contiguous substring of 1s such that it cannot be extended in either direction.

    - -

    Return the latest step at which there exists a group of ones of length exactly m. If no such group exists, return -1.

    - -

     

    -

    Example 1:

    - -
    -Input: arr = [3,5,1,2,4], m = 1
    -Output: 4
    -Explanation:
    -Step 1: "00100", groups: ["1"]
    -Step 2: "00101", groups: ["1", "1"]
    -Step 3: "10101", groups: ["1", "1", "1"]
    -Step 4: "11101", groups: ["111", "1"]
    -Step 5: "11111", groups: ["11111"]
    -The latest step at which there exists a group of size 1 is step 4.
    - -

    Example 2:

    - -
    -Input: arr = [3,1,5,4,2], m = 2
    -Output: -1
    -Explanation:
    -Step 1: "00100", groups: ["1"]
    -Step 2: "10100", groups: ["1", "1"]
    -Step 3: "10101", groups: ["1", "1", "1"]
    -Step 4: "10111", groups: ["1", "111"]
    -Step 5: "11111", groups: ["11111"]
    -No group of size 2 exists during any step.
    -
    - -

    Example 3:

    - -
    -Input: arr = [1], m = 1
    -Output: 1
    -
    - -

    Example 4:

    - -
    -Input: arr = [2,1], m = 2
    -Output: 2
    -
    - -

     

    -

    Constraints:

    - -
      -
    • n == arr.length
    • -
    • 1 <= n <= 10^5
    • -
    • 1 <= arr[i] <= n
    • -
    • All integers in arr are distinct.
    • -
    • 1 <= m <= arr.length
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md b/leetcode/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md deleted file mode 100644 index 612f8049..00000000 --- a/leetcode/solution/1500-1599/1566.Detect Pattern of Length M Repeated K or More Times/README_EN.md +++ /dev/null @@ -1,86 +0,0 @@ -# [1566. Detect Pattern of Length M Repeated K or More Times](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) - -[中文文档](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README.md) - -## Description - -

    Given an array of positive integers arr,  find a pattern of length m that is repeated k or more times.

    - -

    A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.

    - -

    Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.

    - -

     

    -

    Example 1:

    - -
    -Input: arr = [1,2,4,4,4,4], m = 1, k = 3
    -Output: true
    -Explanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.
    -
    - -

    Example 2:

    - -
    -Input: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2
    -Output: true
    -Explanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.
    -
    - -

    Example 3:

    - -
    -Input: arr = [1,2,1,2,1,3], m = 2, k = 3
    -Output: false
    -Explanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times.
    -
    - -

    Example 4:

    - -
    -Input: arr = [1,2,3,1,2], m = 2, k = 2
    -Output: false
    -Explanation: Notice that the pattern (1,2) exists twice but not consecutively, so it doesn't count.
    -
    - -

    Example 5:

    - -
    -Input: arr = [2,2,2,2], m = 2, k = 3
    -Output: false
    -Explanation: The only pattern of length 2 is (2,2) however it's repeated only twice. Notice that we do not count overlapping repetitions.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 2 <= arr.length <= 100
    • -
    • 1 <= arr[i] <= 100
    • -
    • 1 <= m <= 100
    • -
    • 2 <= k <= 100
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md b/leetcode/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md deleted file mode 100644 index aeb97020..00000000 --- a/leetcode/solution/1500-1599/1567.Maximum Length of Subarray With Positive Product/README_EN.md +++ /dev/null @@ -1,82 +0,0 @@ -# [1567. Maximum Length of Subarray With Positive Product](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product) - -[中文文档](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md) - -## Description - -

    Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.

    - -

    A subarray of an array is a consecutive sequence of zero or more values taken out of that array.

    - -

    Return the maximum length of a subarray with positive product.

    - -

     

    -

    Example 1:

    - -
    -Input: nums = [1,-2,-3,4]
    -Output: 4
    -Explanation: The array nums already has a positive product of 24.
    -
    - -

    Example 2:

    - -
    -Input: nums = [0,1,-2,-3,-4]
    -Output: 3
    -Explanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.
    -Notice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.
    - -

    Example 3:

    - -
    -Input: nums = [-1,-2,-3,0,1]
    -Output: 2
    -Explanation: The longest subarray with positive product is [-1,-2] or [-2,-3].
    -
    - -

    Example 4:

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

    Example 5:

    - -
    -Input: nums = [1,2,3,5,-6,4,0,10]
    -Output: 4
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 10^5
    • -
    • -10^9 <= nums[i] <= 10^9
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md b/leetcode/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md deleted file mode 100644 index 8e446ae9..00000000 --- a/leetcode/solution/1500-1599/1569.Number of Ways to Reorder Array to Get Same BST/README_EN.md +++ /dev/null @@ -1,99 +0,0 @@ -# [1569. Number of Ways to Reorder Array to Get Same BST](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst) - -[中文文档](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README.md) - -## Description - -

    Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.

    - -

    For example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child. The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.

    - -

    Return the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.

    - -

    Since the answer may be very large, return it modulo 10^9 + 7.

    - -

     

    -

    Example 1:

    - -![](./images/bb.png) - -
    -Input: nums = [2,1,3]
    -Output: 1
    -Explanation: We can reorder nums to be [2,3,1] which will yield the same BST. There are no other ways to reorder nums which will yield the same BST.
    -
    - -

    Example 2:

    - -![](./images/ex1.png) - -
    -Input: nums = [3,4,5,1,2]
    -Output: 5
    -Explanation: The following 5 arrays will yield the same BST: 
    -[3,1,2,4,5]
    -[3,1,4,2,5]
    -[3,1,4,5,2]
    -[3,4,1,2,5]
    -[3,4,1,5,2]
    -
    - -

    Example 3:

    - -![](./images/ex4.png) - -
    -Input: nums = [1,2,3]
    -Output: 0
    -Explanation: There are no other orderings of nums that will yield the same BST.
    -
    - -

    Example 4:

    - -![](./images/abc.png) - -
    -Input: nums = [3,1,2,5,4,6]
    -Output: 19
    -
    - -

    Example 5:

    - -
    -Input: nums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]
    -Output: 216212978
    -Explanation: The number of ways to reorder nums to get the same BST is 3216212999. Taking this number modulo 10^9 + 7 gives 216212978.
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= nums.length <= 1000
    • -
    • 1 <= nums[i] <= nums.length
    • -
    • All integers in nums are distinct.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md b/leetcode/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md deleted file mode 100644 index 81e5639d..00000000 --- a/leetcode/solution/1500-1599/1572.Matrix Diagonal Sum/README_EN.md +++ /dev/null @@ -1,73 +0,0 @@ -# [1572. Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum) - -[中文文档](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README.md) - -## Description - -

    Given a square matrix mat, return the sum of the matrix diagonals.

    - -

    Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.

    - -

     

    -

    Example 1:

    - -![](./images/sample_1911.png) - -
    -Input: mat = [[1,2,3],
    -              [4,5,6],
    -              [7,8,9]]
    -Output: 25
    -Explanation: Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25
    -Notice that element mat[1][1] = 5 is counted only once.
    -
    - -

    Example 2:

    - -
    -Input: mat = [[1,1,1,1],
    -              [1,1,1,1],
    -              [1,1,1,1],
    -              [1,1,1,1]]
    -Output: 8
    -
    - -

    Example 3:

    - -
    -Input: mat = [[5]]
    -Output: 5
    -
    - -

     

    -

    Constraints:

    - -
      -
    • n == mat.length == mat[i].length
    • -
    • 1 <= n <= 100
    • -
    • 1 <= mat[i][j] <= 100
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md b/leetcode/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md deleted file mode 100644 index 9f6a4a35..00000000 --- a/leetcode/solution/1500-1599/1573.Number of Ways to Split a String/README_EN.md +++ /dev/null @@ -1,81 +0,0 @@ -# [1573. Number of Ways to Split a String](https://leetcode.com/problems/number-of-ways-to-split-a-string) - -[中文文档](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README.md) - -## Description - -

    Given a binary string s (a string consisting only of '0's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s).

    - -

    Return the number of ways s can be split such that the number of characters '1' is the same in s1, s2, and s3.

    - -

    Since the answer may be too large, return it modulo 10^9 + 7.

    - -

     

    -

    Example 1:

    - -
    -Input: s = "10101"
    -Output: 4
    -Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.
    -"1|010|1"
    -"1|01|01"
    -"10|10|1"
    -"10|1|01"
    -
    - -

    Example 2:

    - -
    -Input: s = "1001"
    -Output: 0
    -
    - -

    Example 3:

    - -
    -Input: s = "0000"
    -Output: 3
    -Explanation: There are three ways to split s in 3 parts.
    -"0|0|00"
    -"0|00|0"
    -"00|0|0"
    -
    - -

    Example 4:

    - -
    -Input: s = "100100010100110"
    -Output: 12
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 3 <= s.length <= 10^5
    • -
    • s[i] is '0' or '1'.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md b/leetcode/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md deleted file mode 100644 index fc1e274a..00000000 --- a/leetcode/solution/1500-1599/1574.Shortest Subarray to be Removed to Make Array Sorted/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [1574. Shortest Subarray to be Removed to Make Array Sorted](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted) - -[中文文档](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README.md) - -## Description - -

    Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.

    - -

    A subarray is a contiguous subsequence of the array.

    - -

    Return the length of the shortest subarray to remove.

    - -

     

    -

    Example 1:

    - -
    -Input: arr = [1,2,3,10,4,2,3,5]
    -Output: 3
    -Explanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted.
    -Another correct solution is to remove the subarray [3,10,4].
    - -

    Example 2:

    - -
    -Input: arr = [5,4,3,2,1]
    -Output: 4
    -Explanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1].
    -
    - -

    Example 3:

    - -
    -Input: arr = [1,2,3]
    -Output: 0
    -Explanation: The array is already non-decreasing. We do not need to remove any elements.
    -
    - -

    Example 4:

    - -
    -Input: arr = [1]
    -Output: 0
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= arr.length <= 10^5
    • -
    • 0 <= arr[i] <= 10^9
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/README_EN.md b/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/README_EN.md deleted file mode 100644 index 6e414a85..00000000 --- a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/README_EN.md +++ /dev/null @@ -1,119 +0,0 @@ -# [1576. Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) - -[中文文档](/solution/1500-1599/1576.Replace%20All%20S%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md) - -## Description - -

    Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.

    - -

    It is guaranteed that there are no consecutive repeating characters in the given string except for '?'.

    - -

    Return the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.

    - -

     

    -

    Example 1:

    - -
    -Input: s = "?zs"
    -Output: "azs"
    -Explanation: There are 25 solutions for this problem. From "azs" to "yzs", all are valid. Only "z" is an invalid modification as the string will consist of consecutive repeating characters in "zzs".
    - -

    Example 2:

    - -
    -Input: s = "ubv?w"
    -Output: "ubvaw"
    -Explanation: There are 24 solutions for this problem. Only "v" and "w" are invalid modifications as the strings will consist of consecutive repeating characters in "ubvvw" and "ubvww".
    -
    - -

    Example 3:

    - -
    -Input: s = "j?qg??b"
    -Output: "jaqgacb"
    -
    - -

    Example 4:

    - -
    -Input: s = "??yw?ipkj?"
    -Output: "acywaipkja"
    -
    - -

     

    -

    Constraints:

    - -
      -
    • -

      1 <= s.length <= 100

      -
    • -
    • -

      s contains only lower case English letters and '?'.

      -
    • -
    - -## Solutions - - - -### **Python3** - -```python -class Solution: - def modifyString(self, s: str) -> str: - s = list(s) - for i in range(len(s)): - if s[i] == '?': - ahead = ' ' if i == 0 else s[i - 1] - behind = ' ' if i == len(s) - 1 else s[i + 1] - for c in string.ascii_lowercase: - if c != ahead and c != behind: - s[i] = c - break - return "".join(s) -``` - -### **Java** - -```java -class Solution { - public String modifyString(String s) { - char[] chars = s.toCharArray(); - for (int i = 0; i < chars.length; i++) { - if (chars[i] == '?') { - // 前面的字符 - char ahead = i == 0 ? ' ' : chars[i - 1]; - // 后面的字符 - char behind = i == chars.length - 1 ? ' ' : chars[i + 1]; - char temp = 'a'; - while (temp == ahead || temp == behind) { - temp++; - } - chars[i] = temp; - } - } - return new String(chars); - } -} -``` - -### **Go** - -```go -func modifyString(s string) string { - data := []byte(" " + s + " ") - for i, c := range data { - if c == byte('?') { - ahead, behind := data[i-1], data[i+1] - for t := byte('a'); t <= byte('z'); t++ { - if t != ahead && t != behind { - data[i] = t - } - } - } - } - return string(data[1 : len(data)-1]) -} -``` - - diff --git a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.go b/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.go deleted file mode 100644 index be92f600..00000000 --- a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.go +++ /dev/null @@ -1,14 +0,0 @@ -func modifyString(s string) string { - data := []byte(" " + s + " ") - for i, c := range data { - if c == byte('?') { - ahead, behind := data[i-1], data[i+1] - for t := byte('a'); t <= byte('z'); t++ { - if t != ahead && t != behind { - data[i] = t - } - } - } - } - return string(data[1 : len(data)-1]) -} \ No newline at end of file diff --git a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.py b/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.py deleted file mode 100644 index 1b9c680b..00000000 --- a/leetcode/solution/1500-1599/1576.Replace All S to Avoid Consecutive Repeating Characters/Solution.py +++ /dev/null @@ -1,12 +0,0 @@ -class Solution: - def modifyString(self, s: str) -> str: - s = list(s) - for i in range(len(s)): - if s[i] == '?': - ahead = ' ' if i == 0 else s[i - 1] - behind = ' ' if i == len(s) - 1 else s[i + 1] - for c in string.ascii_lowercase: - if c != ahead and c != behind: - s[i] = c - break - return "".join(s) \ No newline at end of file diff --git a/leetcode/solution/1500-1599/1578.Minimum Deletion Cost to Avoid Repeating Letters/README_EN.md b/leetcode/solution/1500-1599/1578.Minimum Deletion Cost to Avoid Repeating Letters/README_EN.md deleted file mode 100644 index d67149ea..00000000 --- a/leetcode/solution/1500-1599/1578.Minimum Deletion Cost to Avoid Repeating Letters/README_EN.md +++ /dev/null @@ -1,70 +0,0 @@ -# [1578. Minimum Deletion Cost to Avoid Repeating Letters](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters) - -[中文文档](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README.md) - -## Description - -

    Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s.

    - -

    Return the minimum cost of deletions such that there are no two identical letters next to each other.

    - -

    Notice that you will delete the chosen characters at the same time, in other words, after deleting a character, the costs of deleting other characters will not change.

    - -

     

    -

    Example 1:

    - -
    -Input: s = "abaac", cost = [1,2,3,4,5]
    -Output: 3
    -Explanation: Delete the letter "a" with cost 3 to get "abac" (String without two identical letters next to each other).
    -
    - -

    Example 2:

    - -
    -Input: s = "abc", cost = [1,2,3]
    -Output: 0
    -Explanation: You don't need to delete any character because there are no identical letters next to each other.
    -
    - -

    Example 3:

    - -
    -Input: s = "aabaa", cost = [1,2,3,4,1]
    -Output: 2
    -Explanation: Delete the first and the last character, getting the string ("aba").
    -
    - -

     

    -

    Constraints:

    - -
      -
    • s.length == cost.length
    • -
    • 1 <= s.length, cost.length <= 10^5
    • -
    • 1 <= cost[i] <= 10^4
    • -
    • s contains only lowercase English letters.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md b/leetcode/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md deleted file mode 100644 index 2ff67112..00000000 --- a/leetcode/solution/1500-1599/1579.Remove Max Number of Edges to Keep Graph Fully Traversable/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [1579. Remove Max Number of Edges to Keep Graph Fully Traversable](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable) - -[中文文档](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README.md) - -## Description - -

    Alice and Bob have an undirected graph of n nodes and 3 types of edges:

    - -
      -
    • Type 1: Can be traversed by Alice only.
    • -
    • Type 2: Can be traversed by Bob only.
    • -
    • Type 3: Can by traversed by both Alice and Bob.
    • -
    - -

    Given an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.

    - -

    Return the maximum number of edges you can remove, or return -1 if it's impossible for the graph to be fully traversed by Alice and Bob.

    - -

     

    -

    Example 1:

    - -![](./images/ex1.png) - -
    -Input: n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]
    -Output: 2
    -Explanation: If we remove the 2 edges [1,1,2] and [1,1,3]. The graph will still be fully traversable by Alice and Bob. Removing any additional edge will not make it so. So the maximum number of edges we can remove is 2.
    -
    - -

    Example 2:

    - -![](./images/ex2.png) - -
    -Input: n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]
    -Output: 0
    -Explanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.
    -
    - -

    Example 3:

    - -![](./images/ex3.png) - -
    -Input: n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]
    -Output: -1
    -Explanation: In the current graph, Alice cannot reach node 4 from the other nodes. Likewise, Bob cannot reach 1. Therefore it's impossible to make the graph fully traversable.
    - -

     

    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= n <= 10^5
    • -
    • 1 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)
    • -
    • edges[i].length == 3
    • -
    • 1 <= edges[i][0] <= 3
    • -
    • 1 <= edges[i][1] < edges[i][2] <= n
    • -
    • All tuples (typei, ui, vi) are distinct.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md b/leetcode/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md deleted file mode 100644 index d602ff84..00000000 --- a/leetcode/solution/1500-1599/1582.Special Positions in a Binary Matrix/README_EN.md +++ /dev/null @@ -1,85 +0,0 @@ -# [1582. Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix) - -[中文文档](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README.md) - -## Description - -

    Given a rows x cols matrix mat, where mat[i][j] is either 0 or 1, return the number of special positions in mat.

    - -

    A position (i,j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).

    - -

     

    -

    Example 1:

    - -
    -Input: mat = [[1,0,0],
    -              [0,0,1],
    -              [1,0,0]]
    -Output: 1
    -Explanation: (1,2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.
    -
    - -

    Example 2:

    - -
    -Input: mat = [[1,0,0],
    -              [0,1,0],
    -              [0,0,1]]
    -Output: 3
    -Explanation: (0,0), (1,1) and (2,2) are special positions. 
    -
    - -

    Example 3:

    - -
    -Input: mat = [[0,0,0,1],
    -              [1,0,0,0],
    -              [0,1,1,0],
    -              [0,0,0,0]]
    -Output: 2
    -
    - -

    Example 4:

    - -
    -Input: mat = [[0,0,0,0,0],
    -              [1,0,0,0,0],
    -              [0,1,0,0,0],
    -              [0,0,1,0,0],
    -              [0,0,0,1,1]]
    -Output: 3
    -
    - -

     

    -

    Constraints:

    - -
      -
    • rows == mat.length
    • -
    • cols == mat[i].length
    • -
    • 1 <= rows, cols <= 100
    • -
    • mat[i][j] is 0 or 1.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md b/leetcode/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md deleted file mode 100644 index 682812e5..00000000 --- a/leetcode/solution/1500-1599/1583.Count Unhappy Friends/README_EN.md +++ /dev/null @@ -1,93 +0,0 @@ -# [1583. Count Unhappy Friends](https://leetcode.com/problems/count-unhappy-friends) - -[中文文档](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README.md) - -## Description - -

    You are given a list of preferences for n friends, where n is always even.

    - -

    For each person ipreferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 to n-1.

    - -

    All the friends are divided into pairs. The pairings are given in a list pairs, where pairs[i] = [xi, yi] denotes xi is paired with yi and yi is paired with xi.

    - -

    However, this pairing may cause some of the friends to be unhappy. A friend x is unhappy if x is paired with y and there exists a friend u who is paired with v but:

    - -
      -
    • x prefers u over y, and
    • -
    • u prefers x over v.
    • -
    - -

    Return the number of unhappy friends.

    - -

     

    -

    Example 1:

    - -
    -Input: n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]
    -Output: 2
    -Explanation:
    -Friend 1 is unhappy because:
    -- 1 is paired with 0 but prefers 3 over 0, and
    -- 3 prefers 1 over 2.
    -Friend 3 is unhappy because:
    -- 3 is paired with 2 but prefers 1 over 2, and
    -- 1 prefers 3 over 0.
    -Friends 0 and 2 are happy.
    -
    - -

    Example 2:

    - -
    -Input: n = 2, preferences = [[1], [0]], pairs = [[1, 0]]
    -Output: 0
    -Explanation: Both friends 0 and 1 are happy.
    -
    - -

    Example 3:

    - -
    -Input: n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]
    -Output: 4
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 2 <= n <= 500
    • -
    • n is even.
    • -
    • preferences.length == n
    • -
    • preferences[i].length == n - 1
    • -
    • 0 <= preferences[i][j] <= n - 1
    • -
    • preferences[i] does not contain i.
    • -
    • All values in preferences[i] are unique.
    • -
    • pairs.length == n/2
    • -
    • pairs[i].length == 2
    • -
    • xi != yi
    • -
    • 0 <= xi, yi <= n - 1
    • -
    • Each person is contained in exactly one pair.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md b/leetcode/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md deleted file mode 100644 index 32280c04..00000000 --- a/leetcode/solution/1500-1599/1584.Min Cost to Connect All Points/README_EN.md +++ /dev/null @@ -1,88 +0,0 @@ -# [1584. Min Cost to Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points) - -[中文文档](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README.md) - -## Description - -

    You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].

    - -

    The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.

    - -

    Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.

    - -

     

    -

    Example 1:

    - -![](./images/d.png) - -
    -Input: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
    -Output: 20
    -Explanation:
    -
    -We can connect the points as shown above to get the minimum cost of 20.
    -Notice that there is a unique path between every pair of points.
    -
    - -![](./images/c.png) - -

    Example 2:

    - -
    -Input: points = [[3,12],[-2,5],[-4,1]]
    -Output: 18
    -
    - -

    Example 3:

    - -
    -Input: points = [[0,0],[1,1],[1,0],[-1,1]]
    -Output: 4
    -
    - -

    Example 4:

    - -
    -Input: points = [[-1000000,-1000000],[1000000,1000000]]
    -Output: 4000000
    -
    - -

    Example 5:

    - -
    -Input: points = [[0,0]]
    -Output: 0
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= points.length <= 1000
    • -
    • -106 <= xi, yi <= 106
    • -
    • All pairs (xi, yi) are distinct.
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md b/leetcode/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md deleted file mode 100644 index cdca0b64..00000000 --- a/leetcode/solution/1500-1599/1588.Sum of All Odd Length Subarrays/README_EN.md +++ /dev/null @@ -1,75 +0,0 @@ -# [1588. Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) - -[中文文档](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README.md) - -## Description - -

    Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays.

    - -

    A subarray is a contiguous subsequence of the array.

    - -

    Return the sum of all odd-length subarrays of arr.

    - -

     

    -

    Example 1:

    - -
    -Input: arr = [1,4,2,5,3]
    -Output: 58
    -Explanation: The odd-length subarrays of arr and their sums are:
    -[1] = 1
    -[4] = 4
    -[2] = 2
    -[5] = 5
    -[3] = 3
    -[1,4,2] = 7
    -[4,2,5] = 11
    -[2,5,3] = 10
    -[1,4,2,5,3] = 15
    -If we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58
    - -

    Example 2:

    - -
    -Input: arr = [1,2]
    -Output: 3
    -Explanation: There are only 2 subarrays of odd length, [1] and [2]. Their sum is 3.
    - -

    Example 3:

    - -
    -Input: arr = [10,11,12]
    -Output: 66
    -
    - -

     

    -

    Constraints:

    - -
      -
    • 1 <= arr.length <= 100
    • -
    • 1 <= arr[i] <= 1000
    • -
    - -## Solutions - - - -### **Python3** - -```python - -``` - -### **Java** - -```java - -``` - -### **...** - -``` - -``` - - diff --git a/leetcode/solution/README_EN.md b/leetcode/solution/README_EN.md deleted file mode 100644 index ca9d70de..00000000 --- a/leetcode/solution/README_EN.md +++ /dev/null @@ -1,1611 +0,0 @@ -# LeetCode - -[中文文档](/solution/README.md) - -## Solutions - -Press Control+F(or Command+F on the Mac) to search anything you want. - -| # | Solution | Tags | Difficulty | Remark | -| --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ---------- | ------ | -| [0001](https://leetcode.com/problems/two-sum) | [Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [0002](https://leetcode.com/problems/add-two-numbers) | [Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md) | `Linked List`,`Math` | Medium | | -| [0003](https://leetcode.com/problems/longest-substring-without-repeating-characters) | [Longest Substring Without Repeating Characters](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md) | `Hash Table`,`Two Pointers`,`String`,`Sliding Window` | Medium | | -| [0004](https://leetcode.com/problems/median-of-two-sorted-arrays) | [Median of Two Sorted Arrays](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md) | `Array`,`Binary Search`,`Divide and Conquer` | Hard | | -| [0005](https://leetcode.com/problems/longest-palindromic-substring) | [Longest Palindromic Substring](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md) | `String`,`Dynamic Programming` | Medium | | -| [0006](https://leetcode.com/problems/zigzag-conversion) | [ZigZag Conversion](/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md) | `String` | Medium | | -| [0007](https://leetcode.com/problems/reverse-integer) | [Reverse Integer](/solution/0000-0099/0007.Reverse%20Integer/README_EN.md) | `Math` | Easy | | -| [0008](https://leetcode.com/problems/string-to-integer-atoi) | [String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md) | `Math`,`String` | Medium | | -| [0009](https://leetcode.com/problems/palindrome-number) | [Palindrome Number](/solution/0000-0099/0009.Palindrome%20Number/README_EN.md) | `Math` | Easy | | -| [0010](https://leetcode.com/problems/regular-expression-matching) | [Regular Expression Matching](/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md) | `String`,`Dynamic Programming`,`Backtracking` | Hard | | -| [0011](https://leetcode.com/problems/container-with-most-water) | [Container With Most Water](/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0012](https://leetcode.com/problems/integer-to-roman) | [Integer to Roman](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md) | `Math`,`String` | Medium | | -| [0013](https://leetcode.com/problems/roman-to-integer) | [Roman to Integer](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md) | `Math`,`String` | Easy | | -| [0014](https://leetcode.com/problems/longest-common-prefix) | [Longest Common Prefix](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md) | `String` | Easy | | -| [0015](https://leetcode.com/problems/3sum) | [3Sum](/solution/0000-0099/0015.3Sum/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0016](https://leetcode.com/problems/3sum-closest) | [3Sum Closest](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0017](https://leetcode.com/problems/letter-combinations-of-a-phone-number) | [Letter Combinations of a Phone Number](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md) | `String`,`Backtracking` | Medium | | -| [0018](https://leetcode.com/problems/4sum) | [4Sum](/solution/0000-0099/0018.4Sum/README_EN.md) | `Array`,`Hash Table`,`Two Pointers` | Medium | | -| [0019](https://leetcode.com/problems/remove-nth-node-from-end-of-list) | [Remove Nth Node From End of List](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | | -| [0020](https://leetcode.com/problems/valid-parentheses) | [Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md) | `Stack`,`String` | Easy | | -| [0021](https://leetcode.com/problems/merge-two-sorted-lists) | [Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md) | `Linked List` | Easy | | -| [0022](https://leetcode.com/problems/generate-parentheses) | [Generate Parentheses](/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md) | `String`,`Backtracking` | Medium | | -| [0023](https://leetcode.com/problems/merge-k-sorted-lists) | [Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md) | `Heap`,`Linked List`,`Divide and Conquer` | Hard | | -| [0024](https://leetcode.com/problems/swap-nodes-in-pairs) | [Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md) | `Linked List` | Medium | | -| [0025](https://leetcode.com/problems/reverse-nodes-in-k-group) | [Reverse Nodes in k-Group](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md) | `Linked List` | Hard | | -| [0026](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0027](https://leetcode.com/problems/remove-element) | [Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0028](https://leetcode.com/problems/implement-strstr) | [Implement strStr()](/solution/0000-0099/0028.Implement%20strStr%28%29/README_EN.md) | `Two Pointers`,`String` | Easy | | -| [0029](https://leetcode.com/problems/divide-two-integers) | [Divide Two Integers](/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md) | `Math`,`Binary Search` | Medium | | -| [0030](https://leetcode.com/problems/substring-with-concatenation-of-all-words) | [Substring with Concatenation of All Words](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md) | `Hash Table`,`Two Pointers`,`String` | Hard | | -| [0031](https://leetcode.com/problems/next-permutation) | [Next Permutation](/solution/0000-0099/0031.Next%20Permutation/README_EN.md) | `Array` | Medium | | -| [0032](https://leetcode.com/problems/longest-valid-parentheses) | [Longest Valid Parentheses](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0033](https://leetcode.com/problems/search-in-rotated-sorted-array) | [Search in Rotated Sorted Array](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0034](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array) | [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0035](https://leetcode.com/problems/search-insert-position) | [Search Insert Position](/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md) | `Array`,`Binary Search` | Easy | | -| [0036](https://leetcode.com/problems/valid-sudoku) | [Valid Sudoku](/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md) | `Hash Table` | Medium | | -| [0037](https://leetcode.com/problems/sudoku-solver) | [Sudoku Solver](/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md) | `Hash Table`,`Backtracking` | Hard | | -| [0038](https://leetcode.com/problems/count-and-say) | [Count and Say](/solution/0000-0099/0038.Count%20and%20Say/README_EN.md) | `String` | Easy | | -| [0039](https://leetcode.com/problems/combination-sum) | [Combination Sum](/solution/0000-0099/0039.Combination%20Sum/README_EN.md) | `Array`,`Backtracking` | Medium | | -| [0040](https://leetcode.com/problems/combination-sum-ii) | [Combination Sum II](/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md) | `Array`,`Backtracking` | Medium | | -| [0041](https://leetcode.com/problems/first-missing-positive) | [First Missing Positive](/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md) | `Array` | Hard | | -| [0042](https://leetcode.com/problems/trapping-rain-water) | [Trapping Rain Water](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md) | `Stack`,`Array`,`Two Pointers` | Hard | | -| [0043](https://leetcode.com/problems/multiply-strings) | [Multiply Strings](/solution/0000-0099/0043.Multiply%20Strings/README_EN.md) | `Math`,`String` | Medium | | -| [0044](https://leetcode.com/problems/wildcard-matching) | [Wildcard Matching](/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md) | `Greedy`,`String`,`Dynamic Programming`,`Backtracking` | Hard | | -| [0045](https://leetcode.com/problems/jump-game-ii) | [Jump Game II](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md) | `Greedy`,`Array` | Hard | | -| [0046](https://leetcode.com/problems/permutations) | [Permutations](/solution/0000-0099/0046.Permutations/README_EN.md) | `Backtracking` | Medium | | -| [0047](https://leetcode.com/problems/permutations-ii) | [Permutations II](/solution/0000-0099/0047.Permutations%20II/README_EN.md) | `Backtracking` | Medium | | -| [0048](https://leetcode.com/problems/rotate-image) | [Rotate Image](/solution/0000-0099/0048.Rotate%20Image/README_EN.md) | `Array` | Medium | | -| [0049](https://leetcode.com/problems/group-anagrams) | [Group Anagrams](/solution/0000-0099/0049.Group%20Anagrams/README_EN.md) | `Hash Table`,`String` | Medium | | -| [0050](https://leetcode.com/problems/powx-n) | [Pow(x, n)](/solution/0000-0099/0050.Pow%28x%2C%20n%29/README_EN.md) | `Math`,`Binary Search` | Medium | | -| [0051](https://leetcode.com/problems/n-queens) | [N-Queens](/solution/0000-0099/0051.N-Queens/README_EN.md) | `Backtracking` | Hard | | -| [0052](https://leetcode.com/problems/n-queens-ii) | [N-Queens II](/solution/0000-0099/0052.N-Queens%20II/README_EN.md) | `Backtracking` | Hard | | -| [0053](https://leetcode.com/problems/maximum-subarray) | [Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md) | `Array`,`Divide and Conquer`,`Dynamic Programming` | Easy | | -| [0054](https://leetcode.com/problems/spiral-matrix) | [Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md) | `Array` | Medium | | -| [0055](https://leetcode.com/problems/jump-game) | [Jump Game](/solution/0000-0099/0055.Jump%20Game/README_EN.md) | `Greedy`,`Array` | Medium | | -| [0056](https://leetcode.com/problems/merge-intervals) | [Merge Intervals](/solution/0000-0099/0056.Merge%20Intervals/README_EN.md) | `Sort`,`Array` | Medium | | -| [0057](https://leetcode.com/problems/insert-interval) | [Insert Interval](/solution/0000-0099/0057.Insert%20Interval/README_EN.md) | `Sort`,`Array` | Hard | | -| [0058](https://leetcode.com/problems/length-of-last-word) | [Length of Last Word](/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md) | `String` | Easy | | -| [0059](https://leetcode.com/problems/spiral-matrix-ii) | [Spiral Matrix II](/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md) | `Array` | Medium | | -| [0060](https://leetcode.com/problems/permutation-sequence) | [Permutation Sequence](/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md) | `Math`,`Backtracking` | Hard | | -| [0061](https://leetcode.com/problems/rotate-list) | [Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | | -| [0062](https://leetcode.com/problems/unique-paths) | [Unique Paths](/solution/0000-0099/0062.Unique%20Paths/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0063](https://leetcode.com/problems/unique-paths-ii) | [Unique Paths II](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0064](https://leetcode.com/problems/minimum-path-sum) | [Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0065](https://leetcode.com/problems/valid-number) | [Valid Number](/solution/0000-0099/0065.Valid%20Number/README_EN.md) | `Math`,`String` | Hard | | -| [0066](https://leetcode.com/problems/plus-one) | [Plus One](/solution/0000-0099/0066.Plus%20One/README_EN.md) | `Array` | Easy | | -| [0067](https://leetcode.com/problems/add-binary) | [Add Binary](/solution/0000-0099/0067.Add%20Binary/README_EN.md) | `Math`,`String` | Easy | | -| [0068](https://leetcode.com/problems/text-justification) | [Text Justification](/solution/0000-0099/0068.Text%20Justification/README_EN.md) | `String` | Hard | | -| [0069](https://leetcode.com/problems/sqrtx) | [Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md) | `Math`,`Binary Search` | Easy | | -| [0070](https://leetcode.com/problems/climbing-stairs) | [Climbing Stairs](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md) | `Dynamic Programming` | Easy | | -| [0071](https://leetcode.com/problems/simplify-path) | [Simplify Path](/solution/0000-0099/0071.Simplify%20Path/README_EN.md) | `Stack`,`String` | Medium | | -| [0072](https://leetcode.com/problems/edit-distance) | [Edit Distance](/solution/0000-0099/0072.Edit%20Distance/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0073](https://leetcode.com/problems/set-matrix-zeroes) | [Set Matrix Zeroes](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md) | `Array` | Medium | | -| [0074](https://leetcode.com/problems/search-a-2d-matrix) | [Search a 2D Matrix](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0075](https://leetcode.com/problems/sort-colors) | [Sort Colors](/solution/0000-0099/0075.Sort%20Colors/README_EN.md) | `Sort`,`Array`,`Two Pointers` | Medium | | -| [0076](https://leetcode.com/problems/minimum-window-substring) | [Minimum Window Substring](/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md) | `Hash Table`,`Two Pointers`,`String`,`Sliding Window` | Hard | | -| [0077](https://leetcode.com/problems/combinations) | [Combinations](/solution/0000-0099/0077.Combinations/README_EN.md) | `Backtracking` | Medium | | -| [0078](https://leetcode.com/problems/subsets) | [Subsets](/solution/0000-0099/0078.Subsets/README_EN.md) | `Bit Manipulation`,`Array`,`Backtracking` | Medium | | -| [0079](https://leetcode.com/problems/word-search) | [Word Search](/solution/0000-0099/0079.Word%20Search/README_EN.md) | `Array`,`Backtracking` | Medium | | -| [0080](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii) | [Remove Duplicates from Sorted Array II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0081](https://leetcode.com/problems/search-in-rotated-sorted-array-ii) | [Search in Rotated Sorted Array II](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0082](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii) | [Remove Duplicates from Sorted List II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md) | `Linked List` | Medium | | -| [0083](https://leetcode.com/problems/remove-duplicates-from-sorted-list) | [Remove Duplicates from Sorted List](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md) | `Linked List` | Easy | | -| [0084](https://leetcode.com/problems/largest-rectangle-in-histogram) | [Largest Rectangle in Histogram](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md) | `Stack`,`Array` | Hard | | -| [0085](https://leetcode.com/problems/maximal-rectangle) | [Maximal Rectangle](/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md) | `Stack`,`Array`,`Hash Table`,`Dynamic Programming` | Hard | | -| [0086](https://leetcode.com/problems/partition-list) | [Partition List](/solution/0000-0099/0086.Partition%20List/README_EN.md) | `Linked List`,`Two Pointers` | Medium | | -| [0087](https://leetcode.com/problems/scramble-string) | [Scramble String](/solution/0000-0099/0087.Scramble%20String/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0088](https://leetcode.com/problems/merge-sorted-array) | [Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0089](https://leetcode.com/problems/gray-code) | [Gray Code](/solution/0000-0099/0089.Gray%20Code/README_EN.md) | `Backtracking` | Medium | | -| [0090](https://leetcode.com/problems/subsets-ii) | [Subsets II](/solution/0000-0099/0090.Subsets%20II/README_EN.md) | `Array`,`Backtracking` | Medium | | -| [0091](https://leetcode.com/problems/decode-ways) | [Decode Ways](/solution/0000-0099/0091.Decode%20Ways/README_EN.md) | `String`,`Dynamic Programming` | Medium | | -| [0092](https://leetcode.com/problems/reverse-linked-list-ii) | [Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md) | `Linked List` | Medium | | -| [0093](https://leetcode.com/problems/restore-ip-addresses) | [Restore IP Addresses](/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md) | `String`,`Backtracking` | Medium | | -| [0094](https://leetcode.com/problems/binary-tree-inorder-traversal) | [Binary Tree Inorder Traversal](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md) | `Stack`,`Tree`,`Hash Table` | Medium | | -| [0095](https://leetcode.com/problems/unique-binary-search-trees-ii) | [Unique Binary Search Trees II](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md) | `Tree`,`Dynamic Programming` | Medium | | -| [0096](https://leetcode.com/problems/unique-binary-search-trees) | [Unique Binary Search Trees](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md) | `Tree`,`Dynamic Programming` | Medium | | -| [0097](https://leetcode.com/problems/interleaving-string) | [Interleaving String](/solution/0000-0099/0097.Interleaving%20String/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0098](https://leetcode.com/problems/validate-binary-search-tree) | [Validate Binary Search Tree](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0099](https://leetcode.com/problems/recover-binary-search-tree) | [Recover Binary Search Tree](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Hard | | -| [0100](https://leetcode.com/problems/same-tree) | [Same Tree](/solution/0100-0199/0100.Same%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0101](https://leetcode.com/problems/symmetric-tree) | [Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Easy | | -| [0102](https://leetcode.com/problems/binary-tree-level-order-traversal) | [Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md) | `Tree`,`Breadth-first Search` | Medium | | -| [0103](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal) | [Binary Tree Zigzag Level Order Traversal](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md) | `Stack`,`Tree`,`Breadth-first Search` | Medium | | -| [0104](https://leetcode.com/problems/maximum-depth-of-binary-tree) | [Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0105](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | [Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md) | `Tree`,`Depth-first Search`,`Array` | Medium | | -| [0106](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | [Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md) | `Tree`,`Depth-first Search`,`Array` | Medium | | -| [0107](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | [Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md) | `Tree`,`Breadth-first Search` | Easy | | -| [0108](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | [Convert Sorted Array to Binary Search Tree](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0109](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree) | [Convert Sorted List to Binary Search Tree](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md) | `Depth-first Search`,`Linked List` | Medium | | -| [0110](https://leetcode.com/problems/balanced-binary-tree) | [Balanced Binary Tree](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0111](https://leetcode.com/problems/minimum-depth-of-binary-tree) | [Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Easy | | -| [0112](https://leetcode.com/problems/path-sum) | [Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0113](https://leetcode.com/problems/path-sum-ii) | [Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0114](https://leetcode.com/problems/flatten-binary-tree-to-linked-list) | [Flatten Binary Tree to Linked List](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0115](https://leetcode.com/problems/distinct-subsequences) | [Distinct Subsequences](/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0116](https://leetcode.com/problems/populating-next-right-pointers-in-each-node) | [Populating Next Right Pointers in Each Node](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0117](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii) | [Populating Next Right Pointers in Each Node II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0118](https://leetcode.com/problems/pascals-triangle) | [Pascal's Triangle](/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md) | `Array` | Easy | | -| [0119](https://leetcode.com/problems/pascals-triangle-ii) | [Pascal's Triangle II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md) | `Array` | Easy | | -| [0120](https://leetcode.com/problems/triangle) | [Triangle](/solution/0100-0199/0120.Triangle/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0121](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | [Best Time to Buy and Sell Stock](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md) | `Array`,`Dynamic Programming` | Easy | | -| [0122](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii) | [Best Time to Buy and Sell Stock II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md) | `Greedy`,`Array` | Easy | | -| [0123](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii) | [Best Time to Buy and Sell Stock III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md) | `Array`,`Dynamic Programming` | Hard | | -| [0124](https://leetcode.com/problems/binary-tree-maximum-path-sum) | [Binary Tree Maximum Path Sum](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Hard | | -| [0125](https://leetcode.com/problems/valid-palindrome) | [Valid Palindrome](/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md) | `Two Pointers`,`String` | Easy | | -| [0126](https://leetcode.com/problems/word-ladder-ii) | [Word Ladder II](/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md) | `Breadth-first Search`,`Array`,`String`,`Backtracking` | Hard | | -| [0127](https://leetcode.com/problems/word-ladder) | [Word Ladder](/solution/0100-0199/0127.Word%20Ladder/README_EN.md) | `Breadth-first Search` | Medium | | -| [0128](https://leetcode.com/problems/longest-consecutive-sequence) | [Longest Consecutive Sequence](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md) | `Union Find`,`Array` | Hard | | -| [0129](https://leetcode.com/problems/sum-root-to-leaf-numbers) | [Sum Root to Leaf Numbers](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0130](https://leetcode.com/problems/surrounded-regions) | [Surrounded Regions](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | | -| [0131](https://leetcode.com/problems/palindrome-partitioning) | [Palindrome Partitioning](/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md) | `Backtracking` | Medium | | -| [0132](https://leetcode.com/problems/palindrome-partitioning-ii) | [Palindrome Partitioning II](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [0133](https://leetcode.com/problems/clone-graph) | [Clone Graph](/solution/0100-0199/0133.Clone%20Graph/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Graph` | Medium | | -| [0134](https://leetcode.com/problems/gas-station) | [Gas Station](/solution/0100-0199/0134.Gas%20Station/README_EN.md) | `Greedy` | Medium | | -| [0135](https://leetcode.com/problems/candy) | [Candy](/solution/0100-0199/0135.Candy/README_EN.md) | `Greedy` | Hard | | -| [0136](https://leetcode.com/problems/single-number) | [Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md) | `Bit Manipulation`,`Hash Table` | Easy | | -| [0137](https://leetcode.com/problems/single-number-ii) | [Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md) | `Bit Manipulation` | Medium | | -| [0138](https://leetcode.com/problems/copy-list-with-random-pointer) | [Copy List with Random Pointer](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md) | `Hash Table`,`Linked List` | Medium | | -| [0139](https://leetcode.com/problems/word-break) | [Word Break](/solution/0100-0199/0139.Word%20Break/README_EN.md) | `Dynamic Programming` | Medium | | -| [0140](https://leetcode.com/problems/word-break-ii) | [Word Break II](/solution/0100-0199/0140.Word%20Break%20II/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | | -| [0141](https://leetcode.com/problems/linked-list-cycle) | [Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md) | `Linked List`,`Two Pointers` | Easy | | -| [0142](https://leetcode.com/problems/linked-list-cycle-ii) | [Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md) | `Linked List`,`Two Pointers` | Medium | | -| [0143](https://leetcode.com/problems/reorder-list) | [Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md) | `Linked List` | Medium | | -| [0144](https://leetcode.com/problems/binary-tree-preorder-traversal) | [Binary Tree Preorder Traversal](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md) | `Stack`,`Tree` | Medium | | -| [0145](https://leetcode.com/problems/binary-tree-postorder-traversal) | [Binary Tree Postorder Traversal](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md) | `Stack`,`Tree` | Medium | | -| [0146](https://leetcode.com/problems/lru-cache) | [LRU Cache](/solution/0100-0199/0146.LRU%20Cache/README_EN.md) | `Design` | Medium | | -| [0147](https://leetcode.com/problems/insertion-sort-list) | [Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md) | `Sort`,`Linked List` | Medium | | -| [0148](https://leetcode.com/problems/sort-list) | [Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md) | `Sort`,`Linked List` | Medium | | -| [0149](https://leetcode.com/problems/max-points-on-a-line) | [Max Points on a Line](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md) | `Hash Table`,`Math` | Hard | | -| [0150](https://leetcode.com/problems/evaluate-reverse-polish-notation) | [Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md) | `Stack` | Medium | | -| [0151](https://leetcode.com/problems/reverse-words-in-a-string) | [Reverse Words in a String](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md) | `String` | Medium | | -| [0152](https://leetcode.com/problems/maximum-product-subarray) | [Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0153](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array) | [Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0154](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii) | [Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md) | `Array`,`Binary Search` | Hard | | -| [0155](https://leetcode.com/problems/min-stack) | [Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md) | `Stack`,`Design` | Easy | | -| [0156](https://leetcode.com/problems/binary-tree-upside-down) | [Binary Tree Upside Down](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md) | `Tree` | Medium | 🔒 | -| [0157](https://leetcode.com/problems/read-n-characters-given-read4) | [Read N Characters Given Read4](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md) | `String` | Easy | 🔒 | -| [0158](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times) | [Read N Characters Given Read4 II - Call multiple times](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md) | `String` | Hard | 🔒 | -| [0159](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters) | [Longest Substring with At Most Two Distinct Characters](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md) | `Hash Table`,`Two Pointers`,`String`,`Sliding Window` | Medium | 🔒 | -| [0160](https://leetcode.com/problems/intersection-of-two-linked-lists) | [Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md) | `Linked List` | Easy | | -| [0161](https://leetcode.com/problems/one-edit-distance) | [One Edit Distance](/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md) | `String` | Medium | 🔒 | -| [0162](https://leetcode.com/problems/find-peak-element) | [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [0163](https://leetcode.com/problems/missing-ranges) | [Missing Ranges](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md) | `Array` | Medium | 🔒 | -| [0164](https://leetcode.com/problems/maximum-gap) | [Maximum Gap](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md) | `Sort` | Hard | | -| [0165](https://leetcode.com/problems/compare-version-numbers) | [Compare Version Numbers](/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md) | `String` | Medium | | -| [0166](https://leetcode.com/problems/fraction-to-recurring-decimal) | [Fraction to Recurring Decimal](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md) | `Hash Table`,`Math` | Medium | | -| [0167](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | [Two Sum II - Input array is sorted](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md) | `Array`,`Two Pointers`,`Binary Search` | Easy | | -| [0168](https://leetcode.com/problems/excel-sheet-column-title) | [Excel Sheet Column Title](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md) | `Math` | Easy | | -| [0169](https://leetcode.com/problems/majority-element) | [Majority Element](/solution/0100-0199/0169.Majority%20Element/README_EN.md) | `Bit Manipulation`,`Array`,`Divide and Conquer` | Easy | | -| [0170](https://leetcode.com/problems/two-sum-iii-data-structure-design) | [Two Sum III - Data structure design](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md) | `Design`,`Hash Table` | Easy | 🔒 | -| [0171](https://leetcode.com/problems/excel-sheet-column-number) | [Excel Sheet Column Number](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md) | `Math` | Easy | | -| [0172](https://leetcode.com/problems/factorial-trailing-zeroes) | [Factorial Trailing Zeroes](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md) | `Math` | Easy | | -| [0173](https://leetcode.com/problems/binary-search-tree-iterator) | [Binary Search Tree Iterator](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md) | `Stack`,`Tree`,`Design` | Medium | | -| [0174](https://leetcode.com/problems/dungeon-game) | [Dungeon Game](/solution/0100-0199/0174.Dungeon%20Game/README_EN.md) | `Binary Search`,`Dynamic Programming` | Hard | | -| [0175](https://leetcode.com/problems/combine-two-tables) | [Combine Two Tables](/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md) | | Easy | | -| [0176](https://leetcode.com/problems/second-highest-salary) | [Second Highest Salary](/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md) | | Easy | | -| [0177](https://leetcode.com/problems/nth-highest-salary) | [Nth Highest Salary](/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md) | | Medium | | -| [0178](https://leetcode.com/problems/rank-scores) | [Rank Scores](/solution/0100-0199/0178.Rank%20Scores/README_EN.md) | | Medium | | -| [0179](https://leetcode.com/problems/largest-number) | [Largest Number](/solution/0100-0199/0179.Largest%20Number/README_EN.md) | `Sort` | Medium | | -| [0180](https://leetcode.com/problems/consecutive-numbers) | [Consecutive Numbers](/solution/0100-0199/0180.Consecutive%20Numbers/README_EN.md) | | Medium | | -| [0181](https://leetcode.com/problems/employees-earning-more-than-their-managers) | [Employees Earning More Than Their Managers](/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README_EN.md) | | Easy | | -| [0182](https://leetcode.com/problems/duplicate-emails) | [Duplicate Emails](/solution/0100-0199/0182.Duplicate%20Emails/README_EN.md) | | Easy | | -| [0183](https://leetcode.com/problems/customers-who-never-order) | [Customers Who Never Order](/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README_EN.md) | | Easy | | -| [0184](https://leetcode.com/problems/department-highest-salary) | [Department Highest Salary](/solution/0100-0199/0184.Department%20Highest%20Salary/README_EN.md) | | Medium | | -| [0185](https://leetcode.com/problems/department-top-three-salaries) | [Department Top Three Salaries](/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README_EN.md) | | Hard | | -| [0186](https://leetcode.com/problems/reverse-words-in-a-string-ii) | [Reverse Words in a String II](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md) | `String` | Medium | 🔒 | -| [0187](https://leetcode.com/problems/repeated-dna-sequences) | [Repeated DNA Sequences](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README_EN.md) | `Bit Manipulation`,`Hash Table` | Medium | | -| [0188](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv) | [Best Time to Buy and Sell Stock IV](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README_EN.md) | `Dynamic Programming` | Hard | | -| [0189](https://leetcode.com/problems/rotate-array) | [Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md) | `Array` | Easy | | -| [0190](https://leetcode.com/problems/reverse-bits) | [Reverse Bits](/solution/0100-0199/0190.Reverse%20Bits/README_EN.md) | `Bit Manipulation` | Easy | | -| [0191](https://leetcode.com/problems/number-of-1-bits) | [Number of 1 Bits](/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md) | `Bit Manipulation` | Easy | | -| [0192](https://leetcode.com/problems/word-frequency) | [Word Frequency](/solution/0100-0199/0192.Word%20Frequency/README_EN.md) | | Medium | | -| [0193](https://leetcode.com/problems/valid-phone-numbers) | [Valid Phone Numbers](/solution/0100-0199/0193.Valid%20Phone%20Numbers/README_EN.md) | | Easy | | -| [0194](https://leetcode.com/problems/transpose-file) | [Transpose File](/solution/0100-0199/0194.Transpose%20File/README_EN.md) | | Medium | | -| [0195](https://leetcode.com/problems/tenth-line) | [Tenth Line](/solution/0100-0199/0195.Tenth%20Line/README_EN.md) | | Easy | | -| [0196](https://leetcode.com/problems/delete-duplicate-emails) | [Delete Duplicate Emails](/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README_EN.md) | | Easy | | -| [0197](https://leetcode.com/problems/rising-temperature) | [Rising Temperature](/solution/0100-0199/0197.Rising%20Temperature/README_EN.md) | | Easy | | -| [0198](https://leetcode.com/problems/house-robber) | [House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md) | `Dynamic Programming` | Easy | | -| [0199](https://leetcode.com/problems/binary-tree-right-side-view) | [Binary Tree Right Side View](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Medium | | -| [0200](https://leetcode.com/problems/number-of-islands) | [Number of Islands](/solution/0200-0299/0200.Number%20of%20Islands/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | | -| [0201](https://leetcode.com/problems/bitwise-and-of-numbers-range) | [Bitwise AND of Numbers Range](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README_EN.md) | `Bit Manipulation` | Medium | | -| [0202](https://leetcode.com/problems/happy-number) | [Happy Number](/solution/0200-0299/0202.Happy%20Number/README_EN.md) | `Hash Table`,`Math` | Easy | | -| [0203](https://leetcode.com/problems/remove-linked-list-elements) | [Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md) | `Linked List` | Easy | | -| [0204](https://leetcode.com/problems/count-primes) | [Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md) | `Hash Table`,`Math` | Easy | | -| [0205](https://leetcode.com/problems/isomorphic-strings) | [Isomorphic Strings](/solution/0200-0299/0205.Isomorphic%20Strings/README_EN.md) | `Hash Table` | Easy | | -| [0206](https://leetcode.com/problems/reverse-linked-list) | [Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md) | `Linked List` | Easy | | -| [0207](https://leetcode.com/problems/course-schedule) | [Course Schedule](/solution/0200-0299/0207.Course%20Schedule/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort` | Medium | | -| [0208](https://leetcode.com/problems/implement-trie-prefix-tree) | [Implement Trie (Prefix Tree)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md) | `Design`,`Trie` | Medium | | -| [0209](https://leetcode.com/problems/minimum-size-subarray-sum) | [Minimum Size Subarray Sum](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README_EN.md) | `Array`,`Two Pointers`,`Binary Search` | Medium | | -| [0210](https://leetcode.com/problems/course-schedule-ii) | [Course Schedule II](/solution/0200-0299/0210.Course%20Schedule%20II/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort` | Medium | | -| [0211](https://leetcode.com/problems/design-add-and-search-words-data-structure) | [Design Add and Search Words Data Structure](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README_EN.md) | `Design`,`Trie`,`Backtracking` | Medium | | -| [0212](https://leetcode.com/problems/word-search-ii) | [Word Search II](/solution/0200-0299/0212.Word%20Search%20II/README_EN.md) | `Trie`,`Backtracking` | Hard | | -| [0213](https://leetcode.com/problems/house-robber-ii) | [House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md) | `Dynamic Programming` | Medium | | -| [0214](https://leetcode.com/problems/shortest-palindrome) | [Shortest Palindrome](/solution/0200-0299/0214.Shortest%20Palindrome/README_EN.md) | `String` | Hard | | -| [0215](https://leetcode.com/problems/kth-largest-element-in-an-array) | [Kth Largest Element in an Array](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README_EN.md) | `Heap`,`Divide and Conquer` | Medium | | -| [0216](https://leetcode.com/problems/combination-sum-iii) | [Combination Sum III](/solution/0200-0299/0216.Combination%20Sum%20III/README_EN.md) | `Array`,`Backtracking` | Medium | | -| [0217](https://leetcode.com/problems/contains-duplicate) | [Contains Duplicate](/solution/0200-0299/0217.Contains%20Duplicate/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [0218](https://leetcode.com/problems/the-skyline-problem) | [The Skyline Problem](/solution/0200-0299/0218.The%20Skyline%20Problem/README_EN.md) | `Heap`,`Binary Indexed Tree`,`Segment Tree`,`Divide and Conquer`,`Line Sweep` | Hard | | -| [0219](https://leetcode.com/problems/contains-duplicate-ii) | [Contains Duplicate II](/solution/0200-0299/0219.Contains%20Duplicate%20II/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [0220](https://leetcode.com/problems/contains-duplicate-iii) | [Contains Duplicate III](/solution/0200-0299/0220.Contains%20Duplicate%20III/README_EN.md) | `Sort`,`Ordered Map` | Medium | | -| [0221](https://leetcode.com/problems/maximal-square) | [Maximal Square](/solution/0200-0299/0221.Maximal%20Square/README_EN.md) | `Dynamic Programming` | Medium | | -| [0222](https://leetcode.com/problems/count-complete-tree-nodes) | [Count Complete Tree Nodes](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README_EN.md) | `Tree`,`Binary Search` | Medium | | -| [0223](https://leetcode.com/problems/rectangle-area) | [Rectangle Area](/solution/0200-0299/0223.Rectangle%20Area/README_EN.md) | `Math` | Medium | | -| [0224](https://leetcode.com/problems/basic-calculator) | [Basic Calculator](/solution/0200-0299/0224.Basic%20Calculator/README_EN.md) | `Stack`,`Math` | Hard | | -| [0225](https://leetcode.com/problems/implement-stack-using-queues) | [Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md) | `Stack`,`Design` | Easy | | -| [0226](https://leetcode.com/problems/invert-binary-tree) | [Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md) | `Tree` | Easy | | -| [0227](https://leetcode.com/problems/basic-calculator-ii) | [Basic Calculator II](/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md) | `String` | Medium | | -| [0228](https://leetcode.com/problems/summary-ranges) | [Summary Ranges](/solution/0200-0299/0228.Summary%20Ranges/README_EN.md) | `Array` | Medium | | -| [0229](https://leetcode.com/problems/majority-element-ii) | [Majority Element II](/solution/0200-0299/0229.Majority%20Element%20II/README_EN.md) | `Array` | Medium | | -| [0230](https://leetcode.com/problems/kth-smallest-element-in-a-bst) | [Kth Smallest Element in a BST](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README_EN.md) | `Tree`,`Binary Search` | Medium | | -| [0231](https://leetcode.com/problems/power-of-two) | [Power of Two](/solution/0200-0299/0231.Power%20of%20Two/README_EN.md) | `Bit Manipulation`,`Math` | Easy | | -| [0232](https://leetcode.com/problems/implement-queue-using-stacks) | [Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md) | `Stack`,`Design` | Easy | | -| [0233](https://leetcode.com/problems/number-of-digit-one) | [Number of Digit One](/solution/0200-0299/0233.Number%20of%20Digit%20One/README_EN.md) | `Math` | Hard | | -| [0234](https://leetcode.com/problems/palindrome-linked-list) | [Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md) | `Linked List`,`Two Pointers` | Easy | | -| [0235](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | [Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree` | Easy | | -| [0236](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree) | [Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md) | `Tree` | Medium | | -| [0237](https://leetcode.com/problems/delete-node-in-a-linked-list) | [Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md) | `Linked List` | Easy | | -| [0238](https://leetcode.com/problems/product-of-array-except-self) | [Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md) | `Array` | Medium | | -| [0239](https://leetcode.com/problems/sliding-window-maximum) | [Sliding Window Maximum](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README_EN.md) | `Heap`,`Sliding Window` | Hard | | -| [0240](https://leetcode.com/problems/search-a-2d-matrix-ii) | [Search a 2D Matrix II](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README_EN.md) | `Binary Search`,`Divide and Conquer` | Medium | | -| [0241](https://leetcode.com/problems/different-ways-to-add-parentheses) | [Different Ways to Add Parentheses](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README_EN.md) | `Divide and Conquer` | Medium | | -| [0242](https://leetcode.com/problems/valid-anagram) | [Valid Anagram](/solution/0200-0299/0242.Valid%20Anagram/README_EN.md) | `Sort`,`Hash Table` | Easy | | -| [0243](https://leetcode.com/problems/shortest-word-distance) | [Shortest Word Distance](/solution/0200-0299/0243.Shortest%20Word%20Distance/README_EN.md) | `Array` | Easy | 🔒 | -| [0244](https://leetcode.com/problems/shortest-word-distance-ii) | [Shortest Word Distance II](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README_EN.md) | `Design`,`Hash Table` | Medium | 🔒 | -| [0245](https://leetcode.com/problems/shortest-word-distance-iii) | [Shortest Word Distance III](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README_EN.md) | `Array` | Medium | 🔒 | -| [0246](https://leetcode.com/problems/strobogrammatic-number) | [Strobogrammatic Number](/solution/0200-0299/0246.Strobogrammatic%20Number/README_EN.md) | `Hash Table`,`Math` | Easy | 🔒 | -| [0247](https://leetcode.com/problems/strobogrammatic-number-ii) | [Strobogrammatic Number II](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README_EN.md) | `Recursion`,`Math` | Medium | 🔒 | -| [0248](https://leetcode.com/problems/strobogrammatic-number-iii) | [Strobogrammatic Number III](/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README_EN.md) | `Recursion`,`Math` | Hard | 🔒 | -| [0249](https://leetcode.com/problems/group-shifted-strings) | [Group Shifted Strings](/solution/0200-0299/0249.Group%20Shifted%20Strings/README_EN.md) | `Hash Table`,`String` | Medium | 🔒 | -| [0250](https://leetcode.com/problems/count-univalue-subtrees) | [Count Univalue Subtrees](/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README_EN.md) | `Tree` | Medium | 🔒 | -| [0251](https://leetcode.com/problems/flatten-2d-vector) | [Flatten 2D Vector](/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md) | `Design` | Medium | 🔒 | -| [0252](https://leetcode.com/problems/meeting-rooms) | [Meeting Rooms](/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md) | `Sort` | Easy | 🔒 | -| [0253](https://leetcode.com/problems/meeting-rooms-ii) | [Meeting Rooms II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md) | `Heap`,`Greedy`,`Sort` | Medium | 🔒 | -| [0254](https://leetcode.com/problems/factor-combinations) | [Factor Combinations](/solution/0200-0299/0254.Factor%20Combinations/README_EN.md) | `Backtracking` | Medium | 🔒 | -| [0255](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree) | [Verify Preorder Sequence in Binary Search Tree](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md) | `Stack`,`Tree` | Medium | 🔒 | -| [0256](https://leetcode.com/problems/paint-house) | [Paint House](/solution/0200-0299/0256.Paint%20House/README_EN.md) | `Dynamic Programming` | Medium | 🔒 | -| [0257](https://leetcode.com/problems/binary-tree-paths) | [Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0258](https://leetcode.com/problems/add-digits) | [Add Digits](/solution/0200-0299/0258.Add%20Digits/README_EN.md) | `Math` | Easy | | -| [0259](https://leetcode.com/problems/3sum-smaller) | [3Sum Smaller](/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md) | `Array`,`Two Pointers` | Medium | 🔒 | -| [0260](https://leetcode.com/problems/single-number-iii) | [Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md) | `Bit Manipulation` | Medium | | -| [0261](https://leetcode.com/problems/graph-valid-tree) | [Graph Valid Tree](/solution/0200-0299/0261.Graph%20Valid%20Tree/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph` | Medium | 🔒 | -| [0262](https://leetcode.com/problems/trips-and-users) | [Trips and Users](/solution/0200-0299/0262.Trips%20and%20Users/README_EN.md) | | Hard | | -| [0263](https://leetcode.com/problems/ugly-number) | [Ugly Number](/solution/0200-0299/0263.Ugly%20Number/README_EN.md) | `Math` | Easy | | -| [0264](https://leetcode.com/problems/ugly-number-ii) | [Ugly Number II](/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md) | `Heap`,`Math`,`Dynamic Programming` | Medium | | -| [0265](https://leetcode.com/problems/paint-house-ii) | [Paint House II](/solution/0200-0299/0265.Paint%20House%20II/README_EN.md) | `Dynamic Programming` | Hard | 🔒 | -| [0266](https://leetcode.com/problems/palindrome-permutation) | [Palindrome Permutation](/solution/0200-0299/0266.Palindrome%20Permutation/README_EN.md) | `Hash Table` | Easy | 🔒 | -| [0267](https://leetcode.com/problems/palindrome-permutation-ii) | [Palindrome Permutation II](/solution/0200-0299/0267.Palindrome%20Permutation%20II/README_EN.md) | `Backtracking` | Medium | 🔒 | -| [0268](https://leetcode.com/problems/missing-number) | [Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Easy | | -| [0269](https://leetcode.com/problems/alien-dictionary) | [Alien Dictionary](/solution/0200-0299/0269.Alien%20Dictionary/README_EN.md) | `Graph`,`Topological Sort` | Hard | 🔒 | -| [0270](https://leetcode.com/problems/closest-binary-search-tree-value) | [Closest Binary Search Tree Value](/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README_EN.md) | `Tree`,`Binary Search` | Easy | 🔒 | -| [0271](https://leetcode.com/problems/encode-and-decode-strings) | [Encode and Decode Strings](/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README_EN.md) | `String` | Medium | 🔒 | -| [0272](https://leetcode.com/problems/closest-binary-search-tree-value-ii) | [Closest Binary Search Tree Value II](/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README_EN.md) | `Stack`,`Tree` | Hard | 🔒 | -| [0273](https://leetcode.com/problems/integer-to-english-words) | [Integer to English Words](/solution/0200-0299/0273.Integer%20to%20English%20Words/README_EN.md) | `Math`,`String` | Hard | | -| [0274](https://leetcode.com/problems/h-index) | [H-Index](/solution/0200-0299/0274.H-Index/README_EN.md) | `Sort`,`Hash Table` | Medium | | -| [0275](https://leetcode.com/problems/h-index-ii) | [H-Index II](/solution/0200-0299/0275.H-Index%20II/README_EN.md) | `Binary Search` | Medium | | -| [0276](https://leetcode.com/problems/paint-fence) | [Paint Fence](/solution/0200-0299/0276.Paint%20Fence/README_EN.md) | `Dynamic Programming` | Easy | 🔒 | -| [0277](https://leetcode.com/problems/find-the-celebrity) | [Find the Celebrity](/solution/0200-0299/0277.Find%20the%20Celebrity/README_EN.md) | `Array` | Medium | 🔒 | -| [0278](https://leetcode.com/problems/first-bad-version) | [First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md) | `Binary Search` | Easy | | -| [0279](https://leetcode.com/problems/perfect-squares) | [Perfect Squares](/solution/0200-0299/0279.Perfect%20Squares/README_EN.md) | `Breadth-first Search`,`Math`,`Dynamic Programming` | Medium | | -| [0280](https://leetcode.com/problems/wiggle-sort) | [Wiggle Sort](/solution/0200-0299/0280.Wiggle%20Sort/README_EN.md) | `Sort`,`Array` | Medium | 🔒 | -| [0281](https://leetcode.com/problems/zigzag-iterator) | [Zigzag Iterator](/solution/0200-0299/0281.Zigzag%20Iterator/README_EN.md) | `Design` | Medium | 🔒 | -| [0282](https://leetcode.com/problems/expression-add-operators) | [Expression Add Operators](/solution/0200-0299/0282.Expression%20Add%20Operators/README_EN.md) | `Divide and Conquer` | Hard | | -| [0283](https://leetcode.com/problems/move-zeroes) | [Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0284](https://leetcode.com/problems/peeking-iterator) | [Peeking Iterator](/solution/0200-0299/0284.Peeking%20Iterator/README_EN.md) | `Design` | Medium | | -| [0285](https://leetcode.com/problems/inorder-successor-in-bst) | [Inorder Successor in BST](/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README_EN.md) | `Tree` | Medium | 🔒 | -| [0286](https://leetcode.com/problems/walls-and-gates) | [Walls and Gates](/solution/0200-0299/0286.Walls%20and%20Gates/README_EN.md) | `Breadth-first Search` | Medium | 🔒 | -| [0287](https://leetcode.com/problems/find-the-duplicate-number) | [Find the Duplicate Number](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README_EN.md) | `Array`,`Two Pointers`,`Binary Search` | Medium | | -| [0288](https://leetcode.com/problems/unique-word-abbreviation) | [Unique Word Abbreviation](/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README_EN.md) | `Design`,`Hash Table` | Medium | 🔒 | -| [0289](https://leetcode.com/problems/game-of-life) | [Game of Life](/solution/0200-0299/0289.Game%20of%20Life/README_EN.md) | `Array` | Medium | | -| [0290](https://leetcode.com/problems/word-pattern) | [Word Pattern](/solution/0200-0299/0290.Word%20Pattern/README_EN.md) | `Hash Table` | Easy | | -| [0291](https://leetcode.com/problems/word-pattern-ii) | [Word Pattern II](/solution/0200-0299/0291.Word%20Pattern%20II/README_EN.md) | `Backtracking` | Hard | 🔒 | -| [0292](https://leetcode.com/problems/nim-game) | [Nim Game](/solution/0200-0299/0292.Nim%20Game/README_EN.md) | `Brainteaser`,`Minimax` | Easy | | -| [0293](https://leetcode.com/problems/flip-game) | [Flip Game](/solution/0200-0299/0293.Flip%20Game/README_EN.md) | `String` | Easy | 🔒 | -| [0294](https://leetcode.com/problems/flip-game-ii) | [Flip Game II](/solution/0200-0299/0294.Flip%20Game%20II/README_EN.md) | `Minimax`,`Backtracking` | Medium | 🔒 | -| [0295](https://leetcode.com/problems/find-median-from-data-stream) | [Find Median from Data Stream](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README_EN.md) | `Heap`,`Design` | Hard | | -| [0296](https://leetcode.com/problems/best-meeting-point) | [Best Meeting Point](/solution/0200-0299/0296.Best%20Meeting%20Point/README_EN.md) | `Sort`,`Math` | Hard | 🔒 | -| [0297](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | [Serialize and Deserialize Binary Tree](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README_EN.md) | `Tree`,`Design` | Hard | | -| [0298](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | [Binary Tree Longest Consecutive Sequence](/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README_EN.md) | `Tree` | Medium | 🔒 | -| [0299](https://leetcode.com/problems/bulls-and-cows) | [Bulls and Cows](/solution/0200-0299/0299.Bulls%20and%20Cows/README_EN.md) | `Hash Table` | Medium | | -| [0300](https://leetcode.com/problems/longest-increasing-subsequence) | [Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md) | `Binary Search`,`Dynamic Programming` | Medium | | -| [0301](https://leetcode.com/problems/remove-invalid-parentheses) | [Remove Invalid Parentheses](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Hard | | -| [0302](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels) | [Smallest Rectangle Enclosing Black Pixels](/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README_EN.md) | `Binary Search` | Hard | 🔒 | -| [0303](https://leetcode.com/problems/range-sum-query-immutable) | [Range Sum Query - Immutable](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README_EN.md) | `Dynamic Programming` | Easy | | -| [0304](https://leetcode.com/problems/range-sum-query-2d-immutable) | [Range Sum Query 2D - Immutable](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md) | `Dynamic Programming` | Medium | | -| [0305](https://leetcode.com/problems/number-of-islands-ii) | [Number of Islands II](/solution/0300-0399/0305.Number%20of%20Islands%20II/README_EN.md) | `Union Find` | Hard | 🔒 | -| [0306](https://leetcode.com/problems/additive-number) | [Additive Number](/solution/0300-0399/0306.Additive%20Number/README_EN.md) | `Backtracking` | Medium | | -| [0307](https://leetcode.com/problems/range-sum-query-mutable) | [Range Sum Query - Mutable](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README_EN.md) | `Binary Indexed Tree`,`Segment Tree` | Medium | | -| [0308](https://leetcode.com/problems/range-sum-query-2d-mutable) | [Range Sum Query 2D - Mutable](/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README_EN.md) | `Binary Indexed Tree`,`Segment Tree` | Hard | 🔒 | -| [0309](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | [Best Time to Buy and Sell Stock with Cooldown](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md) | `Dynamic Programming` | Medium | | -| [0310](https://leetcode.com/problems/minimum-height-trees) | [Minimum Height Trees](/solution/0300-0399/0310.Minimum%20Height%20Trees/README_EN.md) | `Breadth-first Search`,`Graph` | Medium | | -| [0311](https://leetcode.com/problems/sparse-matrix-multiplication) | [Sparse Matrix Multiplication](/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README_EN.md) | `Hash Table` | Medium | 🔒 | -| [0312](https://leetcode.com/problems/burst-balloons) | [Burst Balloons](/solution/0300-0399/0312.Burst%20Balloons/README_EN.md) | `Divide and Conquer`,`Dynamic Programming` | Hard | | -| [0313](https://leetcode.com/problems/super-ugly-number) | [Super Ugly Number](/solution/0300-0399/0313.Super%20Ugly%20Number/README_EN.md) | `Heap`,`Math` | Medium | | -| [0314](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | [Binary Tree Vertical Order Traversal](/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [0315](https://leetcode.com/problems/count-of-smaller-numbers-after-self) | [Count of Smaller Numbers After Self](/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README_EN.md) | `Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer` | Hard | | -| [0316](https://leetcode.com/problems/remove-duplicate-letters) | [Remove Duplicate Letters](/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README_EN.md) | `Stack`,`Greedy` | Hard | | -| [0317](https://leetcode.com/problems/shortest-distance-from-all-buildings) | [Shortest Distance from All Buildings](/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README_EN.md) | `Breadth-first Search` | Hard | 🔒 | -| [0318](https://leetcode.com/problems/maximum-product-of-word-lengths) | [Maximum Product of Word Lengths](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md) | `Bit Manipulation` | Medium | | -| [0319](https://leetcode.com/problems/bulb-switcher) | [Bulb Switcher](/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md) | `Brainteaser`,`Math` | Medium | | -| [0320](https://leetcode.com/problems/generalized-abbreviation) | [Generalized Abbreviation](/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md) | `Bit Manipulation`,`Backtracking` | Medium | 🔒 | -| [0321](https://leetcode.com/problems/create-maximum-number) | [Create Maximum Number](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md) | `Greedy`,`Dynamic Programming` | Hard | | -| [0322](https://leetcode.com/problems/coin-change) | [Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md) | `Dynamic Programming` | Medium | | -| [0323](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | [Number of Connected Components in an Undirected Graph](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph` | Medium | 🔒 | -| [0324](https://leetcode.com/problems/wiggle-sort-ii) | [Wiggle Sort II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md) | `Sort` | Medium | | -| [0325](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k) | [Maximum Size Subarray Sum Equals k](/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README_EN.md) | `Hash Table` | Medium | 🔒 | -| [0326](https://leetcode.com/problems/power-of-three) | [Power of Three](/solution/0300-0399/0326.Power%20of%20Three/README_EN.md) | `Math` | Easy | | -| [0327](https://leetcode.com/problems/count-of-range-sum) | [Count of Range Sum](/solution/0300-0399/0327.Count%20of%20Range%20Sum/README_EN.md) | `Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer` | Hard | | -| [0328](https://leetcode.com/problems/odd-even-linked-list) | [Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md) | `Linked List` | Medium | | -| [0329](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) | [Longest Increasing Path in a Matrix](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README_EN.md) | `Depth-first Search`,`Topological Sort`,`Memoization` | Hard | | -| [0330](https://leetcode.com/problems/patching-array) | [Patching Array](/solution/0300-0399/0330.Patching%20Array/README_EN.md) | `Greedy` | Hard | | -| [0331](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | [Verify Preorder Serialization of a Binary Tree](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README_EN.md) | `Stack` | Medium | | -| [0332](https://leetcode.com/problems/reconstruct-itinerary) | [Reconstruct Itinerary](/solution/0300-0399/0332.Reconstruct%20Itinerary/README_EN.md) | `Depth-first Search`,`Graph` | Medium | | -| [0333](https://leetcode.com/problems/largest-bst-subtree) | [Largest BST Subtree](/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md) | `Tree` | Medium | 🔒 | -| [0334](https://leetcode.com/problems/increasing-triplet-subsequence) | [Increasing Triplet Subsequence](/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README_EN.md) | | Medium | | -| [0335](https://leetcode.com/problems/self-crossing) | [Self Crossing](/solution/0300-0399/0335.Self%20Crossing/README_EN.md) | `Math` | Hard | | -| [0336](https://leetcode.com/problems/palindrome-pairs) | [Palindrome Pairs](/solution/0300-0399/0336.Palindrome%20Pairs/README_EN.md) | `Trie`,`Hash Table`,`String` | Hard | | -| [0337](https://leetcode.com/problems/house-robber-iii) | [House Robber III](/solution/0300-0399/0337.House%20Robber%20III/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0338](https://leetcode.com/problems/counting-bits) | [Counting Bits](/solution/0300-0399/0338.Counting%20Bits/README_EN.md) | `Bit Manipulation`,`Dynamic Programming` | Medium | | -| [0339](https://leetcode.com/problems/nested-list-weight-sum) | [Nested List Weight Sum](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md) | `Depth-first Search` | Easy | 🔒 | -| [0340](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | [Longest Substring with At Most K Distinct Characters](/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README_EN.md) | `Hash Table`,`String`,`Sliding Window` | Hard | 🔒 | -| [0341](https://leetcode.com/problems/flatten-nested-list-iterator) | [Flatten Nested List Iterator](/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README_EN.md) | `Stack`,`Design` | Medium | | -| [0342](https://leetcode.com/problems/power-of-four) | [Power of Four](/solution/0300-0399/0342.Power%20of%20Four/README_EN.md) | `Bit Manipulation` | Easy | | -| [0343](https://leetcode.com/problems/integer-break) | [Integer Break](/solution/0300-0399/0343.Integer%20Break/README_EN.md) | `Math`,`Dynamic Programming` | Medium | | -| [0344](https://leetcode.com/problems/reverse-string) | [Reverse String](/solution/0300-0399/0344.Reverse%20String/README_EN.md) | `Two Pointers`,`String` | Easy | | -| [0345](https://leetcode.com/problems/reverse-vowels-of-a-string) | [Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md) | `Two Pointers`,`String` | Easy | | -| [0346](https://leetcode.com/problems/moving-average-from-data-stream) | [Moving Average from Data Stream](/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README_EN.md) | `Design`,`Queue` | Easy | 🔒 | -| [0347](https://leetcode.com/problems/top-k-frequent-elements) | [Top K Frequent Elements](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README_EN.md) | `Heap`,`Hash Table` | Medium | | -| [0348](https://leetcode.com/problems/design-tic-tac-toe) | [Design Tic-Tac-Toe](/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README_EN.md) | `Design` | Medium | 🔒 | -| [0349](https://leetcode.com/problems/intersection-of-two-arrays) | [Intersection of Two Arrays](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README_EN.md) | `Sort`,`Hash Table`,`Two Pointers`,`Binary Search` | Easy | | -| [0350](https://leetcode.com/problems/intersection-of-two-arrays-ii) | [Intersection of Two Arrays II](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README_EN.md) | `Sort`,`Hash Table`,`Two Pointers`,`Binary Search` | Easy | | -| [0351](https://leetcode.com/problems/android-unlock-patterns) | [Android Unlock Patterns](/solution/0300-0399/0351.Android%20Unlock%20Patterns/README_EN.md) | `Dynamic Programming`,`Backtracking` | Medium | 🔒 | -| [0352](https://leetcode.com/problems/data-stream-as-disjoint-intervals) | [Data Stream as Disjoint Intervals](/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README_EN.md) | `Binary Search`,`Ordered Map` | Hard | | -| [0353](https://leetcode.com/problems/design-snake-game) | [Design Snake Game](/solution/0300-0399/0353.Design%20Snake%20Game/README_EN.md) | `Design`,`Queue` | Medium | 🔒 | -| [0354](https://leetcode.com/problems/russian-doll-envelopes) | [Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md) | `Binary Search`,`Dynamic Programming` | Hard | | -| [0355](https://leetcode.com/problems/design-twitter) | [Design Twitter](/solution/0300-0399/0355.Design%20Twitter/README_EN.md) | `Heap`,`Design`,`Hash Table` | Medium | | -| [0356](https://leetcode.com/problems/line-reflection) | [Line Reflection](/solution/0300-0399/0356.Line%20Reflection/README_EN.md) | `Hash Table`,`Math` | Medium | 🔒 | -| [0357](https://leetcode.com/problems/count-numbers-with-unique-digits) | [Count Numbers with Unique Digits](/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README_EN.md) | `Math`,`Dynamic Programming`,`Backtracking` | Medium | | -| [0358](https://leetcode.com/problems/rearrange-string-k-distance-apart) | [Rearrange String k Distance Apart](/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README_EN.md) | `Heap`,`Greedy`,`Hash Table` | Hard | 🔒 | -| [0359](https://leetcode.com/problems/logger-rate-limiter) | [Logger Rate Limiter](/solution/0300-0399/0359.Logger%20Rate%20Limiter/README_EN.md) | `Design`,`Hash Table` | Easy | 🔒 | -| [0360](https://leetcode.com/problems/sort-transformed-array) | [Sort Transformed Array](/solution/0300-0399/0360.Sort%20Transformed%20Array/README_EN.md) | `Math`,`Two Pointers` | Medium | 🔒 | -| [0361](https://leetcode.com/problems/bomb-enemy) | [Bomb Enemy](/solution/0300-0399/0361.Bomb%20Enemy/README_EN.md) | `Dynamic Programming` | Medium | 🔒 | -| [0362](https://leetcode.com/problems/design-hit-counter) | [Design Hit Counter](/solution/0300-0399/0362.Design%20Hit%20Counter/README_EN.md) | `Design` | Medium | 🔒 | -| [0363](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k) | [Max Sum of Rectangle No Larger Than K](/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README_EN.md) | `Queue`,`Binary Search`,`Dynamic Programming` | Hard | | -| [0364](https://leetcode.com/problems/nested-list-weight-sum-ii) | [Nested List Weight Sum II](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md) | `Depth-first Search` | Medium | 🔒 | -| [0365](https://leetcode.com/problems/water-and-jug-problem) | [Water and Jug Problem](/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README_EN.md) | `Math` | Medium | | -| [0366](https://leetcode.com/problems/find-leaves-of-binary-tree) | [Find Leaves of Binary Tree](/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | 🔒 | -| [0367](https://leetcode.com/problems/valid-perfect-square) | [Valid Perfect Square](/solution/0300-0399/0367.Valid%20Perfect%20Square/README_EN.md) | `Math`,`Binary Search` | Easy | | -| [0368](https://leetcode.com/problems/largest-divisible-subset) | [Largest Divisible Subset](/solution/0300-0399/0368.Largest%20Divisible%20Subset/README_EN.md) | `Math`,`Dynamic Programming` | Medium | | -| [0369](https://leetcode.com/problems/plus-one-linked-list) | [Plus One Linked List](/solution/0300-0399/0369.Plus%20One%20Linked%20List/README_EN.md) | `Linked List` | Medium | 🔒 | -| [0370](https://leetcode.com/problems/range-addition) | [Range Addition](/solution/0300-0399/0370.Range%20Addition/README_EN.md) | `Array` | Medium | 🔒 | -| [0371](https://leetcode.com/problems/sum-of-two-integers) | [Sum of Two Integers](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README_EN.md) | `Bit Manipulation` | Easy | | -| [0372](https://leetcode.com/problems/super-pow) | [Super Pow](/solution/0300-0399/0372.Super%20Pow/README_EN.md) | `Math` | Medium | | -| [0373](https://leetcode.com/problems/find-k-pairs-with-smallest-sums) | [Find K Pairs with Smallest Sums](/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README_EN.md) | `Heap` | Medium | | -| [0374](https://leetcode.com/problems/guess-number-higher-or-lower) | [Guess Number Higher or Lower](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README_EN.md) | `Binary Search` | Easy | | -| [0375](https://leetcode.com/problems/guess-number-higher-or-lower-ii) | [Guess Number Higher or Lower II](/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README_EN.md) | `Minimax`,`Dynamic Programming` | Medium | | -| [0376](https://leetcode.com/problems/wiggle-subsequence) | [Wiggle Subsequence](/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md) | `Greedy`,`Dynamic Programming` | Medium | | -| [0377](https://leetcode.com/problems/combination-sum-iv) | [Combination Sum IV](/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md) | `Dynamic Programming` | Medium | | -| [0378](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix) | [Kth Smallest Element in a Sorted Matrix](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README_EN.md) | `Heap`,`Binary Search` | Medium | | -| [0379](https://leetcode.com/problems/design-phone-directory) | [Design Phone Directory](/solution/0300-0399/0379.Design%20Phone%20Directory/README_EN.md) | `Design`,`Linked List` | Medium | 🔒 | -| [0380](https://leetcode.com/problems/insert-delete-getrandom-o1) | [Insert Delete GetRandom O(1)](/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README_EN.md) | `Design`,`Array`,`Hash Table` | Medium | | -| [0381](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed) | [Insert Delete GetRandom O(1) - Duplicates allowed](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md) | `Design`,`Array`,`Hash Table` | Hard | | -| [0382](https://leetcode.com/problems/linked-list-random-node) | [Linked List Random Node](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md) | `Reservoir Sampling` | Medium | | -| [0383](https://leetcode.com/problems/ransom-note) | [Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md) | `String` | Easy | | -| [0384](https://leetcode.com/problems/shuffle-an-array) | [Shuffle an Array](/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md) | | Medium | | -| [0385](https://leetcode.com/problems/mini-parser) | [Mini Parser](/solution/0300-0399/0385.Mini%20Parser/README_EN.md) | `Stack`,`String` | Medium | | -| [0386](https://leetcode.com/problems/lexicographical-numbers) | [Lexicographical Numbers](/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md) | | Medium | | -| [0387](https://leetcode.com/problems/first-unique-character-in-a-string) | [First Unique Character in a String](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md) | `Hash Table`,`String` | Easy | | -| [0388](https://leetcode.com/problems/longest-absolute-file-path) | [Longest Absolute File Path](/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README_EN.md) | | Medium | | -| [0389](https://leetcode.com/problems/find-the-difference) | [Find the Difference](/solution/0300-0399/0389.Find%20the%20Difference/README_EN.md) | `Bit Manipulation`,`Hash Table` | Easy | | -| [0390](https://leetcode.com/problems/elimination-game) | [Elimination Game](/solution/0300-0399/0390.Elimination%20Game/README_EN.md) | | Medium | | -| [0391](https://leetcode.com/problems/perfect-rectangle) | [Perfect Rectangle](/solution/0300-0399/0391.Perfect%20Rectangle/README_EN.md) | `Line Sweep` | Hard | | -| [0392](https://leetcode.com/problems/is-subsequence) | [Is Subsequence](/solution/0300-0399/0392.Is%20Subsequence/README_EN.md) | `Greedy`,`Binary Search`,`Dynamic Programming` | Easy | | -| [0393](https://leetcode.com/problems/utf-8-validation) | [UTF-8 Validation](/solution/0300-0399/0393.UTF-8%20Validation/README_EN.md) | `Bit Manipulation` | Medium | | -| [0394](https://leetcode.com/problems/decode-string) | [Decode String](/solution/0300-0399/0394.Decode%20String/README_EN.md) | `Stack`,`Depth-first Search` | Medium | | -| [0395](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters) | [Longest Substring with At Least K Repeating Characters](/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README_EN.md) | | Medium | | -| [0396](https://leetcode.com/problems/rotate-function) | [Rotate Function](/solution/0300-0399/0396.Rotate%20Function/README_EN.md) | `Math` | Medium | | -| [0397](https://leetcode.com/problems/integer-replacement) | [Integer Replacement](/solution/0300-0399/0397.Integer%20Replacement/README_EN.md) | `Bit Manipulation`,`Math` | Medium | | -| [0398](https://leetcode.com/problems/random-pick-index) | [Random Pick Index](/solution/0300-0399/0398.Random%20Pick%20Index/README_EN.md) | `Reservoir Sampling` | Medium | | -| [0399](https://leetcode.com/problems/evaluate-division) | [Evaluate Division](/solution/0300-0399/0399.Evaluate%20Division/README_EN.md) | `Union Find`,`Graph` | Medium | | -| [0400](https://leetcode.com/problems/nth-digit) | [Nth Digit](/solution/0400-0499/0400.Nth%20Digit/README_EN.md) | `Math` | Medium | | -| [0401](https://leetcode.com/problems/binary-watch) | [Binary Watch](/solution/0400-0499/0401.Binary%20Watch/README_EN.md) | `Bit Manipulation`,`Backtracking` | Easy | | -| [0402](https://leetcode.com/problems/remove-k-digits) | [Remove K Digits](/solution/0400-0499/0402.Remove%20K%20Digits/README_EN.md) | `Stack`,`Greedy` | Medium | | -| [0403](https://leetcode.com/problems/frog-jump) | [Frog Jump](/solution/0400-0499/0403.Frog%20Jump/README_EN.md) | `Dynamic Programming` | Hard | | -| [0404](https://leetcode.com/problems/sum-of-left-leaves) | [Sum of Left Leaves](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README_EN.md) | `Tree` | Easy | | -| [0405](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | [Convert a Number to Hexadecimal](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README_EN.md) | `Bit Manipulation` | Easy | | -| [0406](https://leetcode.com/problems/queue-reconstruction-by-height) | [Queue Reconstruction by Height](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README_EN.md) | `Greedy` | Medium | | -| [0407](https://leetcode.com/problems/trapping-rain-water-ii) | [Trapping Rain Water II](/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README_EN.md) | `Heap`,`Breadth-first Search` | Hard | | -| [0408](https://leetcode.com/problems/valid-word-abbreviation) | [Valid Word Abbreviation](/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README_EN.md) | `String` | Easy | 🔒 | -| [0409](https://leetcode.com/problems/longest-palindrome) | [Longest Palindrome](/solution/0400-0499/0409.Longest%20Palindrome/README_EN.md) | `Hash Table` | Easy | | -| [0410](https://leetcode.com/problems/split-array-largest-sum) | [Split Array Largest Sum](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README_EN.md) | `Binary Search`,`Dynamic Programming` | Hard | | -| [0411](https://leetcode.com/problems/minimum-unique-word-abbreviation) | [Minimum Unique Word Abbreviation](/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README_EN.md) | `Bit Manipulation`,`Backtracking` | Hard | 🔒 | -| [0412](https://leetcode.com/problems/fizz-buzz) | [Fizz Buzz](/solution/0400-0499/0412.Fizz%20Buzz/README_EN.md) | | Easy | | -| [0413](https://leetcode.com/problems/arithmetic-slices) | [Arithmetic Slices](/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md) | `Math`,`Dynamic Programming` | Medium | | -| [0414](https://leetcode.com/problems/third-maximum-number) | [Third Maximum Number](/solution/0400-0499/0414.Third%20Maximum%20Number/README_EN.md) | `Array` | Easy | | -| [0415](https://leetcode.com/problems/add-strings) | [Add Strings](/solution/0400-0499/0415.Add%20Strings/README_EN.md) | `String` | Easy | | -| [0416](https://leetcode.com/problems/partition-equal-subset-sum) | [Partition Equal Subset Sum](/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [0417](https://leetcode.com/problems/pacific-atlantic-water-flow) | [Pacific Atlantic Water Flow](/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [0418](https://leetcode.com/problems/sentence-screen-fitting) | [Sentence Screen Fitting](/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README_EN.md) | `Dynamic Programming` | Medium | 🔒 | -| [0419](https://leetcode.com/problems/battleships-in-a-board) | [Battleships in a Board](/solution/0400-0499/0419.Battleships%20in%20a%20Board/README_EN.md) | | Medium | | -| [0420](https://leetcode.com/problems/strong-password-checker) | [Strong Password Checker](/solution/0400-0499/0420.Strong%20Password%20Checker/README_EN.md) | | Hard | | -| [0421](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array) | [Maximum XOR of Two Numbers in an Array](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README_EN.md) | `Bit Manipulation`,`Trie` | Medium | | -| [0422](https://leetcode.com/problems/valid-word-square) | [Valid Word Square](/solution/0400-0499/0422.Valid%20Word%20Square/README_EN.md) | | Easy | 🔒 | -| [0423](https://leetcode.com/problems/reconstruct-original-digits-from-english) | [Reconstruct Original Digits from English](/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README_EN.md) | `Math` | Medium | | -| [0424](https://leetcode.com/problems/longest-repeating-character-replacement) | [Longest Repeating Character Replacement](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README_EN.md) | `Two Pointers`,`Sliding Window` | Medium | | -| [0425](https://leetcode.com/problems/word-squares) | [Word Squares](/solution/0400-0499/0425.Word%20Squares/README_EN.md) | `Trie`,`Backtracking` | Hard | 🔒 | -| [0426](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) | [Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md) | `Tree`,`Linked List`,`Divide and Conquer` | Medium | 🔒 | -| [0427](https://leetcode.com/problems/construct-quad-tree) | [Construct Quad Tree](/solution/0400-0499/0427.Construct%20Quad%20Tree/README_EN.md) | | Medium | | -| [0428](https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree) | [Serialize and Deserialize N-ary Tree](/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README_EN.md) | `Tree` | Hard | 🔒 | -| [0429](https://leetcode.com/problems/n-ary-tree-level-order-traversal) | [N-ary Tree Level Order Traversal](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README_EN.md) | `Tree`,`Breadth-first Search` | Medium | | -| [0430](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list) | [Flatten a Multilevel Doubly Linked List](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README_EN.md) | `Depth-first Search`,`Linked List` | Medium | | -| [0431](https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree) | [Encode N-ary Tree to Binary Tree](/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README_EN.md) | `Tree` | Hard | 🔒 | -| [0432](https://leetcode.com/problems/all-oone-data-structure) | [All O`one Data Structure](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README_EN.md) | `Design` | Hard | | -| [0433](https://leetcode.com/problems/minimum-genetic-mutation) | [Minimum Genetic Mutation](/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README_EN.md) | | Medium | | -| [0434](https://leetcode.com/problems/number-of-segments-in-a-string) | [Number of Segments in a String](/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README_EN.md) | `String` | Easy | | -| [0435](https://leetcode.com/problems/non-overlapping-intervals) | [Non-overlapping Intervals](/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md) | `Greedy` | Medium | | -| [0436](https://leetcode.com/problems/find-right-interval) | [Find Right Interval](/solution/0400-0499/0436.Find%20Right%20Interval/README_EN.md) | `Binary Search` | Medium | | -| [0437](https://leetcode.com/problems/path-sum-iii) | [Path Sum III](/solution/0400-0499/0437.Path%20Sum%20III/README_EN.md) | `Tree` | Medium | | -| [0438](https://leetcode.com/problems/find-all-anagrams-in-a-string) | [Find All Anagrams in a String](/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README_EN.md) | `Hash Table` | Medium | | -| [0439](https://leetcode.com/problems/ternary-expression-parser) | [Ternary Expression Parser](/solution/0400-0499/0439.Ternary%20Expression%20Parser/README_EN.md) | `Stack`,`Depth-first Search` | Medium | 🔒 | -| [0440](https://leetcode.com/problems/k-th-smallest-in-lexicographical-order) | [K-th Smallest in Lexicographical Order](/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README_EN.md) | | Hard | | -| [0441](https://leetcode.com/problems/arranging-coins) | [Arranging Coins](/solution/0400-0499/0441.Arranging%20Coins/README_EN.md) | `Math`,`Binary Search` | Easy | | -| [0442](https://leetcode.com/problems/find-all-duplicates-in-an-array) | [Find All Duplicates in an Array](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README_EN.md) | `Array` | Medium | | -| [0443](https://leetcode.com/problems/string-compression) | [String Compression](/solution/0400-0499/0443.String%20Compression/README_EN.md) | `String` | Medium | | -| [0444](https://leetcode.com/problems/sequence-reconstruction) | [Sequence Reconstruction](/solution/0400-0499/0444.Sequence%20Reconstruction/README_EN.md) | `Graph`,`Topological Sort` | Medium | 🔒 | -| [0445](https://leetcode.com/problems/add-two-numbers-ii) | [Add Two Numbers II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md) | `Linked List` | Medium | | -| [0446](https://leetcode.com/problems/arithmetic-slices-ii-subsequence) | [Arithmetic Slices II - Subsequence](/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README_EN.md) | `Dynamic Programming` | Hard | | -| [0447](https://leetcode.com/problems/number-of-boomerangs) | [Number of Boomerangs](/solution/0400-0499/0447.Number%20of%20Boomerangs/README_EN.md) | `Hash Table` | Easy | | -| [0448](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | [Find All Numbers Disappeared in an Array](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README_EN.md) | `Array` | Easy | | -| [0449](https://leetcode.com/problems/serialize-and-deserialize-bst) | [Serialize and Deserialize BST](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README_EN.md) | `Tree` | Medium | | -| [0450](https://leetcode.com/problems/delete-node-in-a-bst) | [Delete Node in a BST](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README_EN.md) | `Tree` | Medium | | -| [0451](https://leetcode.com/problems/sort-characters-by-frequency) | [Sort Characters By Frequency](/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README_EN.md) | `Heap`,`Hash Table` | Medium | | -| [0452](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons) | [Minimum Number of Arrows to Burst Balloons](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README_EN.md) | `Greedy` | Medium | | -| [0453](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | [Minimum Moves to Equal Array Elements](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README_EN.md) | `Math` | Easy | | -| [0454](https://leetcode.com/problems/4sum-ii) | [4Sum II](/solution/0400-0499/0454.4Sum%20II/README_EN.md) | `Hash Table`,`Binary Search` | Medium | | -| [0455](https://leetcode.com/problems/assign-cookies) | [Assign Cookies](/solution/0400-0499/0455.Assign%20Cookies/README_EN.md) | `Greedy` | Easy | | -| [0456](https://leetcode.com/problems/132-pattern) | [132 Pattern](/solution/0400-0499/0456.132%20Pattern/README_EN.md) | `Stack` | Medium | | -| [0457](https://leetcode.com/problems/circular-array-loop) | [Circular Array Loop](/solution/0400-0499/0457.Circular%20Array%20Loop/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0458](https://leetcode.com/problems/poor-pigs) | [Poor Pigs](/solution/0400-0499/0458.Poor%20Pigs/README_EN.md) | `Math` | Hard | | -| [0459](https://leetcode.com/problems/repeated-substring-pattern) | [Repeated Substring Pattern](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README_EN.md) | `String` | Easy | | -| [0460](https://leetcode.com/problems/lfu-cache) | [LFU Cache](/solution/0400-0499/0460.LFU%20Cache/README_EN.md) | `Design` | Hard | | -| [0461](https://leetcode.com/problems/hamming-distance) | [Hamming Distance](/solution/0400-0499/0461.Hamming%20Distance/README_EN.md) | `Bit Manipulation` | Easy | | -| [0462](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii) | [Minimum Moves to Equal Array Elements II](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README_EN.md) | `Math` | Medium | | -| [0463](https://leetcode.com/problems/island-perimeter) | [Island Perimeter](/solution/0400-0499/0463.Island%20Perimeter/README_EN.md) | `Hash Table` | Easy | | -| [0464](https://leetcode.com/problems/can-i-win) | [Can I Win](/solution/0400-0499/0464.Can%20I%20Win/README_EN.md) | `Minimax`,`Dynamic Programming` | Medium | | -| [0465](https://leetcode.com/problems/optimal-account-balancing) | [Optimal Account Balancing](/solution/0400-0499/0465.Optimal%20Account%20Balancing/README_EN.md) | | Hard | 🔒 | -| [0466](https://leetcode.com/problems/count-the-repetitions) | [Count The Repetitions](/solution/0400-0499/0466.Count%20The%20Repetitions/README_EN.md) | `Dynamic Programming` | Hard | | -| [0467](https://leetcode.com/problems/unique-substrings-in-wraparound-string) | [Unique Substrings in Wraparound String](/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README_EN.md) | `Dynamic Programming` | Medium | | -| [0468](https://leetcode.com/problems/validate-ip-address) | [Validate IP Address](/solution/0400-0499/0468.Validate%20IP%20Address/README_EN.md) | `String` | Medium | | -| [0469](https://leetcode.com/problems/convex-polygon) | [Convex Polygon](/solution/0400-0499/0469.Convex%20Polygon/README_EN.md) | `Math` | Medium | 🔒 | -| [0470](https://leetcode.com/problems/implement-rand10-using-rand7) | [Implement Rand10() Using Rand7()](/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README_EN.md) | `Random`,`Rejection Sampling` | Medium | | -| [0471](https://leetcode.com/problems/encode-string-with-shortest-length) | [Encode String with Shortest Length](/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README_EN.md) | `Dynamic Programming` | Hard | 🔒 | -| [0472](https://leetcode.com/problems/concatenated-words) | [Concatenated Words](/solution/0400-0499/0472.Concatenated%20Words/README_EN.md) | `Depth-first Search`,`Trie`,`Dynamic Programming` | Hard | | -| [0473](https://leetcode.com/problems/matchsticks-to-square) | [Matchsticks to Square](/solution/0400-0499/0473.Matchsticks%20to%20Square/README_EN.md) | `Depth-first Search` | Medium | | -| [0474](https://leetcode.com/problems/ones-and-zeroes) | [Ones and Zeroes](/solution/0400-0499/0474.Ones%20and%20Zeroes/README_EN.md) | `Dynamic Programming` | Medium | | -| [0475](https://leetcode.com/problems/heaters) | [Heaters](/solution/0400-0499/0475.Heaters/README_EN.md) | `Binary Search` | Easy | | -| [0476](https://leetcode.com/problems/number-complement) | [Number Complement](/solution/0400-0499/0476.Number%20Complement/README_EN.md) | `Bit Manipulation` | Easy | | -| [0477](https://leetcode.com/problems/total-hamming-distance) | [Total Hamming Distance](/solution/0400-0499/0477.Total%20Hamming%20Distance/README_EN.md) | `Bit Manipulation` | Medium | | -| [0478](https://leetcode.com/problems/generate-random-point-in-a-circle) | [Generate Random Point in a Circle](/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README_EN.md) | `Math`,`Random`,`Rejection Sampling` | Medium | | -| [0479](https://leetcode.com/problems/largest-palindrome-product) | [Largest Palindrome Product](/solution/0400-0499/0479.Largest%20Palindrome%20Product/README_EN.md) | | Hard | | -| [0480](https://leetcode.com/problems/sliding-window-median) | [Sliding Window Median](/solution/0400-0499/0480.Sliding%20Window%20Median/README_EN.md) | `Sliding Window` | Hard | | -| [0481](https://leetcode.com/problems/magical-string) | [Magical String](/solution/0400-0499/0481.Magical%20String/README_EN.md) | | Medium | | -| [0482](https://leetcode.com/problems/license-key-formatting) | [License Key Formatting](/solution/0400-0499/0482.License%20Key%20Formatting/README_EN.md) | | Easy | | -| [0483](https://leetcode.com/problems/smallest-good-base) | [Smallest Good Base](/solution/0400-0499/0483.Smallest%20Good%20Base/README_EN.md) | `Math`,`Binary Search` | Hard | | -| [0484](https://leetcode.com/problems/find-permutation) | [Find Permutation](/solution/0400-0499/0484.Find%20Permutation/README_EN.md) | `Greedy` | Medium | 🔒 | -| [0485](https://leetcode.com/problems/max-consecutive-ones) | [Max Consecutive Ones](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README_EN.md) | `Array` | Easy | | -| [0486](https://leetcode.com/problems/predict-the-winner) | [Predict the Winner](/solution/0400-0499/0486.Predict%20the%20Winner/README_EN.md) | `Minimax`,`Dynamic Programming` | Medium | | -| [0487](https://leetcode.com/problems/max-consecutive-ones-ii) | [Max Consecutive Ones II](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README_EN.md) | `Two Pointers` | Medium | 🔒 | -| [0488](https://leetcode.com/problems/zuma-game) | [Zuma Game](/solution/0400-0499/0488.Zuma%20Game/README_EN.md) | `Depth-first Search` | Hard | | -| [0489](https://leetcode.com/problems/robot-room-cleaner) | [Robot Room Cleaner](/solution/0400-0499/0489.Robot%20Room%20Cleaner/README_EN.md) | `Depth-first Search` | Hard | 🔒 | -| [0490](https://leetcode.com/problems/the-maze) | [The Maze](/solution/0400-0499/0490.The%20Maze/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [0491](https://leetcode.com/problems/increasing-subsequences) | [Increasing Subsequences](/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md) | `Depth-first Search` | Medium | | -| [0492](https://leetcode.com/problems/construct-the-rectangle) | [Construct the Rectangle](/solution/0400-0499/0492.Construct%20the%20Rectangle/README_EN.md) | | Easy | | -| [0493](https://leetcode.com/problems/reverse-pairs) | [Reverse Pairs](/solution/0400-0499/0493.Reverse%20Pairs/README_EN.md) | `Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer` | Hard | | -| [0494](https://leetcode.com/problems/target-sum) | [Target Sum](/solution/0400-0499/0494.Target%20Sum/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Medium | | -| [0495](https://leetcode.com/problems/teemo-attacking) | [Teemo Attacking](/solution/0400-0499/0495.Teemo%20Attacking/README_EN.md) | `Array` | Medium | | -| [0496](https://leetcode.com/problems/next-greater-element-i) | [Next Greater Element I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md) | `Stack` | Easy | | -| [0497](https://leetcode.com/problems/random-point-in-non-overlapping-rectangles) | [Random Point in Non-overlapping Rectangles](/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README_EN.md) | `Binary Search`,`Random` | Medium | | -| [0498](https://leetcode.com/problems/diagonal-traverse) | [Diagonal Traverse](/solution/0400-0499/0498.Diagonal%20Traverse/README_EN.md) | | Medium | | -| [0499](https://leetcode.com/problems/the-maze-iii) | [The Maze III](/solution/0400-0499/0499.The%20Maze%20III/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Hard | 🔒 | -| [0500](https://leetcode.com/problems/keyboard-row) | [Keyboard Row](/solution/0500-0599/0500.Keyboard%20Row/README_EN.md) | `Hash Table` | Easy | | -| [0501](https://leetcode.com/problems/find-mode-in-binary-search-tree) | [Find Mode in Binary Search Tree](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README_EN.md) | `Tree` | Easy | | -| [0502](https://leetcode.com/problems/ipo) | [IPO](/solution/0500-0599/0502.IPO/README_EN.md) | `Heap`,`Greedy` | Hard | | -| [0503](https://leetcode.com/problems/next-greater-element-ii) | [Next Greater Element II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md) | `Stack` | Medium | | -| [0504](https://leetcode.com/problems/base-7) | [Base 7](/solution/0500-0599/0504.Base%207/README_EN.md) | | Easy | | -| [0505](https://leetcode.com/problems/the-maze-ii) | [The Maze II](/solution/0500-0599/0505.The%20Maze%20II/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [0506](https://leetcode.com/problems/relative-ranks) | [Relative Ranks](/solution/0500-0599/0506.Relative%20Ranks/README_EN.md) | | Easy | | -| [0507](https://leetcode.com/problems/perfect-number) | [Perfect Number](/solution/0500-0599/0507.Perfect%20Number/README_EN.md) | `Math` | Easy | | -| [0508](https://leetcode.com/problems/most-frequent-subtree-sum) | [Most Frequent Subtree Sum](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README_EN.md) | `Tree`,`Hash Table` | Medium | | -| [0509](https://leetcode.com/problems/fibonacci-number) | [Fibonacci Number](/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md) | `Array` | Easy | | -| [0510](https://leetcode.com/problems/inorder-successor-in-bst-ii) | [Inorder Successor in BST II](/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README_EN.md) | `Tree` | Medium | 🔒 | -| [0511](https://leetcode.com/problems/game-play-analysis-i) | [Game Play Analysis I](/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README_EN.md) | | Easy | 🔒 | -| [0512](https://leetcode.com/problems/game-play-analysis-ii) | [Game Play Analysis II](/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README_EN.md) | | Easy | 🔒 | -| [0513](https://leetcode.com/problems/find-bottom-left-tree-value) | [Find Bottom Left Tree Value](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Medium | | -| [0514](https://leetcode.com/problems/freedom-trail) | [Freedom Trail](/solution/0500-0599/0514.Freedom%20Trail/README_EN.md) | `Depth-first Search`,`Divide and Conquer`,`Dynamic Programming` | Hard | | -| [0515](https://leetcode.com/problems/find-largest-value-in-each-tree-row) | [Find Largest Value in Each Tree Row](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Medium | | -| [0516](https://leetcode.com/problems/longest-palindromic-subsequence) | [Longest Palindromic Subsequence](/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md) | `Dynamic Programming` | Medium | | -| [0517](https://leetcode.com/problems/super-washing-machines) | [Super Washing Machines](/solution/0500-0599/0517.Super%20Washing%20Machines/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [0518](https://leetcode.com/problems/coin-change-2) | [Coin Change 2](/solution/0500-0599/0518.Coin%20Change%202/README_EN.md) | | Medium | | -| [0519](https://leetcode.com/problems/random-flip-matrix) | [Random Flip Matrix](/solution/0500-0599/0519.Random%20Flip%20Matrix/README_EN.md) | `Random` | Medium | | -| [0520](https://leetcode.com/problems/detect-capital) | [Detect Capital](/solution/0500-0599/0520.Detect%20Capital/README_EN.md) | `String` | Easy | | -| [0521](https://leetcode.com/problems/longest-uncommon-subsequence-i) | [Longest Uncommon Subsequence I](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README_EN.md) | `Brainteaser`,`String` | Easy | | -| [0522](https://leetcode.com/problems/longest-uncommon-subsequence-ii) | [Longest Uncommon Subsequence II](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README_EN.md) | `String` | Medium | | -| [0523](https://leetcode.com/problems/continuous-subarray-sum) | [Continuous Subarray Sum](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README_EN.md) | `Math`,`Dynamic Programming` | Medium | | -| [0524](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting) | [Longest Word in Dictionary through Deleting](/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README_EN.md) | `Sort`,`Two Pointers` | Medium | | -| [0525](https://leetcode.com/problems/contiguous-array) | [Contiguous Array](/solution/0500-0599/0525.Contiguous%20Array/README_EN.md) | `Hash Table` | Medium | | -| [0526](https://leetcode.com/problems/beautiful-arrangement) | [Beautiful Arrangement](/solution/0500-0599/0526.Beautiful%20Arrangement/README_EN.md) | `Backtracking` | Medium | | -| [0527](https://leetcode.com/problems/word-abbreviation) | [Word Abbreviation](/solution/0500-0599/0527.Word%20Abbreviation/README_EN.md) | `Sort`,`String` | Hard | 🔒 | -| [0528](https://leetcode.com/problems/random-pick-with-weight) | [Random Pick with Weight](/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README_EN.md) | `Binary Search`,`Random` | Medium | | -| [0529](https://leetcode.com/problems/minesweeper) | [Minesweeper](/solution/0500-0599/0529.Minesweeper/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [0530](https://leetcode.com/problems/minimum-absolute-difference-in-bst) | [Minimum Absolute Difference in BST](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README_EN.md) | `Tree` | Easy | | -| [0531](https://leetcode.com/problems/lonely-pixel-i) | [Lonely Pixel I](/solution/0500-0599/0531.Lonely%20Pixel%20I/README_EN.md) | `Depth-first Search`,`Array` | Medium | 🔒 | -| [0532](https://leetcode.com/problems/k-diff-pairs-in-an-array) | [K-diff Pairs in an Array](/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0533](https://leetcode.com/problems/lonely-pixel-ii) | [Lonely Pixel II](/solution/0500-0599/0533.Lonely%20Pixel%20II/README_EN.md) | `Depth-first Search`,`Array` | Medium | 🔒 | -| [0534](https://leetcode.com/problems/game-play-analysis-iii) | [Game Play Analysis III](/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README_EN.md) | | Medium | 🔒 | -| [0535](https://leetcode.com/problems/encode-and-decode-tinyurl) | [Encode and Decode TinyURL](/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README_EN.md) | `Hash Table`,`Math` | Medium | | -| [0536](https://leetcode.com/problems/construct-binary-tree-from-string) | [Construct Binary Tree from String](/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md) | `Tree`,`String` | Medium | 🔒 | -| [0537](https://leetcode.com/problems/complex-number-multiplication) | [Complex Number Multiplication](/solution/0500-0599/0537.Complex%20Number%20Multiplication/README_EN.md) | `Math`,`String` | Medium | | -| [0538](https://leetcode.com/problems/convert-bst-to-greater-tree) | [Convert BST to Greater Tree](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README_EN.md) | `Tree` | Medium | | -| [0539](https://leetcode.com/problems/minimum-time-difference) | [Minimum Time Difference](/solution/0500-0599/0539.Minimum%20Time%20Difference/README_EN.md) | `String` | Medium | | -| [0540](https://leetcode.com/problems/single-element-in-a-sorted-array) | [Single Element in a Sorted Array](/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README_EN.md) | | Medium | | -| [0541](https://leetcode.com/problems/reverse-string-ii) | [Reverse String II](/solution/0500-0599/0541.Reverse%20String%20II/README_EN.md) | `String` | Easy | | -| [0542](https://leetcode.com/problems/01-matrix) | [01 Matrix](/solution/0500-0599/0542.01%20Matrix/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [0543](https://leetcode.com/problems/diameter-of-binary-tree) | [Diameter of Binary Tree](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README_EN.md) | `Tree` | Easy | | -| [0544](https://leetcode.com/problems/output-contest-matches) | [Output Contest Matches](/solution/0500-0599/0544.Output%20Contest%20Matches/README_EN.md) | `Recursion`,`String` | Medium | 🔒 | -| [0545](https://leetcode.com/problems/boundary-of-binary-tree) | [Boundary of Binary Tree](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md) | `Tree` | Medium | 🔒 | -| [0546](https://leetcode.com/problems/remove-boxes) | [Remove Boxes](/solution/0500-0599/0546.Remove%20Boxes/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Hard | | -| [0547](https://leetcode.com/problems/friend-circles) | [Friend Circles](/solution/0500-0599/0547.Friend%20Circles/README_EN.md) | `Depth-first Search`,`Union Find` | Medium | | -| [0548](https://leetcode.com/problems/split-array-with-equal-sum) | [Split Array with Equal Sum](/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README_EN.md) | `Array` | Medium | 🔒 | -| [0549](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii) | [Binary Tree Longest Consecutive Sequence II](/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README_EN.md) | `Tree` | Medium | 🔒 | -| [0550](https://leetcode.com/problems/game-play-analysis-iv) | [Game Play Analysis IV](/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README_EN.md) | | Medium | 🔒 | -| [0551](https://leetcode.com/problems/student-attendance-record-i) | [Student Attendance Record I](/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README_EN.md) | `String` | Easy | | -| [0552](https://leetcode.com/problems/student-attendance-record-ii) | [Student Attendance Record II](/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [0553](https://leetcode.com/problems/optimal-division) | [Optimal Division](/solution/0500-0599/0553.Optimal%20Division/README_EN.md) | `Math`,`String` | Medium | | -| [0554](https://leetcode.com/problems/brick-wall) | [Brick Wall](/solution/0500-0599/0554.Brick%20Wall/README_EN.md) | `Hash Table` | Medium | | -| [0555](https://leetcode.com/problems/split-concatenated-strings) | [Split Concatenated Strings](/solution/0500-0599/0555.Split%20Concatenated%20Strings/README_EN.md) | `String` | Medium | 🔒 | -| [0556](https://leetcode.com/problems/next-greater-element-iii) | [Next Greater Element III](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README_EN.md) | `String` | Medium | | -| [0557](https://leetcode.com/problems/reverse-words-in-a-string-iii) | [Reverse Words in a String III](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README_EN.md) | `String` | Easy | | -| [0558](https://leetcode.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees) | [Logical OR of Two Binary Grids Represented as Quad-Trees](/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README_EN.md) | | Medium | | -| [0559](https://leetcode.com/problems/maximum-depth-of-n-ary-tree) | [Maximum Depth of N-ary Tree](/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Easy | | -| [0560](https://leetcode.com/problems/subarray-sum-equals-k) | [Subarray Sum Equals K](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md) | `Array`,`Hash Table` | Medium | | -| [0561](https://leetcode.com/problems/array-partition-i) | [Array Partition I](/solution/0500-0599/0561.Array%20Partition%20I/README_EN.md) | `Array` | Easy | | -| [0562](https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix) | [Longest Line of Consecutive One in Matrix](/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README_EN.md) | `Array` | Medium | 🔒 | -| [0563](https://leetcode.com/problems/binary-tree-tilt) | [Binary Tree Tilt](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README_EN.md) | `Tree` | Easy | | -| [0564](https://leetcode.com/problems/find-the-closest-palindrome) | [Find the Closest Palindrome](/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README_EN.md) | `String` | Hard | | -| [0565](https://leetcode.com/problems/array-nesting) | [Array Nesting](/solution/0500-0599/0565.Array%20Nesting/README_EN.md) | `Array` | Medium | | -| [0566](https://leetcode.com/problems/reshape-the-matrix) | [Reshape the Matrix](/solution/0500-0599/0566.Reshape%20the%20Matrix/README_EN.md) | `Array` | Easy | | -| [0567](https://leetcode.com/problems/permutation-in-string) | [Permutation in String](/solution/0500-0599/0567.Permutation%20in%20String/README_EN.md) | `Two Pointers`,`Sliding Window` | Medium | | -| [0568](https://leetcode.com/problems/maximum-vacation-days) | [Maximum Vacation Days](/solution/0500-0599/0568.Maximum%20Vacation%20Days/README_EN.md) | `Dynamic Programming` | Hard | 🔒 | -| [0569](https://leetcode.com/problems/median-employee-salary) | [Median Employee Salary](/solution/0500-0599/0569.Median%20Employee%20Salary/README_EN.md) | | Hard | 🔒 | -| [0570](https://leetcode.com/problems/managers-with-at-least-5-direct-reports) | [Managers with at Least 5 Direct Reports](/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README_EN.md) | | Medium | 🔒 | -| [0571](https://leetcode.com/problems/find-median-given-frequency-of-numbers) | [Find Median Given Frequency of Numbers](/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README_EN.md) | | Hard | 🔒 | -| [0572](https://leetcode.com/problems/subtree-of-another-tree) | [Subtree of Another Tree](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README_EN.md) | `Tree` | Easy | | -| [0573](https://leetcode.com/problems/squirrel-simulation) | [Squirrel Simulation](/solution/0500-0599/0573.Squirrel%20Simulation/README_EN.md) | `Math` | Medium | 🔒 | -| [0574](https://leetcode.com/problems/winning-candidate) | [Winning Candidate](/solution/0500-0599/0574.Winning%20Candidate/README_EN.md) | | Medium | 🔒 | -| [0575](https://leetcode.com/problems/distribute-candies) | [Distribute Candies](/solution/0500-0599/0575.Distribute%20Candies/README_EN.md) | `Hash Table` | Easy | | -| [0576](https://leetcode.com/problems/out-of-boundary-paths) | [Out of Boundary Paths](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Medium | | -| [0577](https://leetcode.com/problems/employee-bonus) | [Employee Bonus](/solution/0500-0599/0577.Employee%20Bonus/README_EN.md) | | Easy | 🔒 | -| [0578](https://leetcode.com/problems/get-highest-answer-rate-question) | [Get Highest Answer Rate Question](/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README_EN.md) | | Medium | 🔒 | -| [0579](https://leetcode.com/problems/find-cumulative-salary-of-an-employee) | [Find Cumulative Salary of an Employee](/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README_EN.md) | | Hard | 🔒 | -| [0580](https://leetcode.com/problems/count-student-number-in-departments) | [Count Student Number in Departments](/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README_EN.md) | | Medium | 🔒 | -| [0581](https://leetcode.com/problems/shortest-unsorted-continuous-subarray) | [Shortest Unsorted Continuous Subarray](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README_EN.md) | `Array` | Easy | | -| [0582](https://leetcode.com/problems/kill-process) | [Kill Process](/solution/0500-0599/0582.Kill%20Process/README_EN.md) | `Tree`,`Queue` | Medium | 🔒 | -| [0583](https://leetcode.com/problems/delete-operation-for-two-strings) | [Delete Operation for Two Strings](/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README_EN.md) | `String` | Medium | | -| [0584](https://leetcode.com/problems/find-customer-referee) | [Find Customer Referee](/solution/0500-0599/0584.Find%20Customer%20Referee/README_EN.md) | | Easy | 🔒 | -| [0585](https://leetcode.com/problems/investments-in-2016) | [Investments in 2016](/solution/0500-0599/0585.Investments%20in%202016/README_EN.md) | | Medium | 🔒 | -| [0586](https://leetcode.com/problems/customer-placing-the-largest-number-of-orders) | [Customer Placing the Largest Number of Orders](/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README_EN.md) | | Easy | 🔒 | -| [0587](https://leetcode.com/problems/erect-the-fence) | [Erect the Fence](/solution/0500-0599/0587.Erect%20the%20Fence/README_EN.md) | `Geometry` | Hard | | -| [0588](https://leetcode.com/problems/design-in-memory-file-system) | [Design In-Memory File System](/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README_EN.md) | `Design` | Hard | 🔒 | -| [0589](https://leetcode.com/problems/n-ary-tree-preorder-traversal) | [N-ary Tree Preorder Traversal](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README_EN.md) | `Tree` | Easy | | -| [0590](https://leetcode.com/problems/n-ary-tree-postorder-traversal) | [N-ary Tree Postorder Traversal](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README_EN.md) | `Tree` | Easy | | -| [0591](https://leetcode.com/problems/tag-validator) | [Tag Validator](/solution/0500-0599/0591.Tag%20Validator/README_EN.md) | `Stack`,`String` | Hard | | -| [0592](https://leetcode.com/problems/fraction-addition-and-subtraction) | [Fraction Addition and Subtraction](/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README_EN.md) | `Math` | Medium | | -| [0593](https://leetcode.com/problems/valid-square) | [Valid Square](/solution/0500-0599/0593.Valid%20Square/README_EN.md) | `Math` | Medium | | -| [0594](https://leetcode.com/problems/longest-harmonious-subsequence) | [Longest Harmonious Subsequence](/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README_EN.md) | `Hash Table` | Easy | | -| [0595](https://leetcode.com/problems/big-countries) | [Big Countries](/solution/0500-0599/0595.Big%20Countries/README_EN.md) | | Easy | | -| [0596](https://leetcode.com/problems/classes-more-than-5-students) | [Classes More Than 5 Students](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md) | | Easy | | -| [0597](https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate) | [Friend Requests I: Overall Acceptance Rate](/solution/0500-0599/0597.Friend%20Requests%20I%3A%20Overall%20Acceptance%20Rate/README_EN.md) | | Easy | 🔒 | -| [0598](https://leetcode.com/problems/range-addition-ii) | [Range Addition II](/solution/0500-0599/0598.Range%20Addition%20II/README_EN.md) | `Math` | Easy | | -| [0599](https://leetcode.com/problems/minimum-index-sum-of-two-lists) | [Minimum Index Sum of Two Lists](/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README_EN.md) | `Hash Table` | Easy | | -| [0600](https://leetcode.com/problems/non-negative-integers-without-consecutive-ones) | [Non-negative Integers without Consecutive Ones](/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README_EN.md) | `Dynamic Programming` | Hard | | -| [0601](https://leetcode.com/problems/human-traffic-of-stadium) | [Human Traffic of Stadium](/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README_EN.md) | | Hard | | -| [0602](https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends) | [Friend Requests II: Who Has the Most Friends](/solution/0600-0699/0602.Friend%20Requests%20II%3A%20Who%20Has%20the%20Most%20Friends/README_EN.md) | | Medium | 🔒 | -| [0603](https://leetcode.com/problems/consecutive-available-seats) | [Consecutive Available Seats](/solution/0600-0699/0603.Consecutive%20Available%20Seats/README_EN.md) | | Easy | 🔒 | -| [0604](https://leetcode.com/problems/design-compressed-string-iterator) | [Design Compressed String Iterator](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README_EN.md) | `Design` | Easy | 🔒 | -| [0605](https://leetcode.com/problems/can-place-flowers) | [Can Place Flowers](/solution/0600-0699/0605.Can%20Place%20Flowers/README_EN.md) | `Array` | Easy | | -| [0606](https://leetcode.com/problems/construct-string-from-binary-tree) | [Construct String from Binary Tree](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README_EN.md) | `Tree`,`String` | Easy | | -| [0607](https://leetcode.com/problems/sales-person) | [Sales Person](/solution/0600-0699/0607.Sales%20Person/README_EN.md) | | Easy | 🔒 | -| [0608](https://leetcode.com/problems/tree-node) | [Tree Node](/solution/0600-0699/0608.Tree%20Node/README_EN.md) | | Medium | 🔒 | -| [0609](https://leetcode.com/problems/find-duplicate-file-in-system) | [Find Duplicate File in System](/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README_EN.md) | `Hash Table`,`String` | Medium | | -| [0610](https://leetcode.com/problems/triangle-judgement) | [Triangle Judgement](/solution/0600-0699/0610.Triangle%20Judgement/README_EN.md) | | Easy | 🔒 | -| [0611](https://leetcode.com/problems/valid-triangle-number) | [Valid Triangle Number](/solution/0600-0699/0611.Valid%20Triangle%20Number/README_EN.md) | `Array` | Medium | | -| [0612](https://leetcode.com/problems/shortest-distance-in-a-plane) | [Shortest Distance in a Plane](/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README_EN.md) | | Medium | 🔒 | -| [0613](https://leetcode.com/problems/shortest-distance-in-a-line) | [Shortest Distance in a Line](/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README_EN.md) | | Easy | 🔒 | -| [0614](https://leetcode.com/problems/second-degree-follower) | [Second Degree Follower](/solution/0600-0699/0614.Second%20Degree%20Follower/README_EN.md) | | Medium | 🔒 | -| [0615](https://leetcode.com/problems/average-salary-departments-vs-company) | [Average Salary: Departments VS Company](/solution/0600-0699/0615.Average%20Salary%3A%20Departments%20VS%20Company/README_EN.md) | | Hard | 🔒 | -| [0616](https://leetcode.com/problems/add-bold-tag-in-string) | [Add Bold Tag in String](/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README_EN.md) | `String` | Medium | 🔒 | -| [0617](https://leetcode.com/problems/merge-two-binary-trees) | [Merge Two Binary Trees](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README_EN.md) | `Tree` | Easy | | -| [0618](https://leetcode.com/problems/students-report-by-geography) | [Students Report By Geography](/solution/0600-0699/0618.Students%20Report%20By%20Geography/README_EN.md) | | Hard | 🔒 | -| [0619](https://leetcode.com/problems/biggest-single-number) | [Biggest Single Number](/solution/0600-0699/0619.Biggest%20Single%20Number/README_EN.md) | | Easy | 🔒 | -| [0620](https://leetcode.com/problems/not-boring-movies) | [Not Boring Movies](/solution/0600-0699/0620.Not%20Boring%20Movies/README_EN.md) | | Easy | | -| [0621](https://leetcode.com/problems/task-scheduler) | [Task Scheduler](/solution/0600-0699/0621.Task%20Scheduler/README_EN.md) | `Greedy`,`Queue`,`Array` | Medium | | -| [0622](https://leetcode.com/problems/design-circular-queue) | [Design Circular Queue](/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md) | `Design`,`Queue` | Medium | | -| [0623](https://leetcode.com/problems/add-one-row-to-tree) | [Add One Row to Tree](/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README_EN.md) | `Tree` | Medium | | -| [0624](https://leetcode.com/problems/maximum-distance-in-arrays) | [Maximum Distance in Arrays](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md) | `Array`,`Hash Table` | Easy | 🔒 | -| [0625](https://leetcode.com/problems/minimum-factorization) | [Minimum Factorization](/solution/0600-0699/0625.Minimum%20Factorization/README_EN.md) | `Recursion`,`Math` | Medium | 🔒 | -| [0626](https://leetcode.com/problems/exchange-seats) | [Exchange Seats](/solution/0600-0699/0626.Exchange%20Seats/README_EN.md) | | Medium | | -| [0627](https://leetcode.com/problems/swap-salary) | [Swap Salary](/solution/0600-0699/0627.Swap%20Salary/README_EN.md) | | Easy | | -| [0628](https://leetcode.com/problems/maximum-product-of-three-numbers) | [Maximum Product of Three Numbers](/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README_EN.md) | `Array`,`Math` | Easy | | -| [0629](https://leetcode.com/problems/k-inverse-pairs-array) | [K Inverse Pairs Array](/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README_EN.md) | `Dynamic Programming` | Hard | | -| [0630](https://leetcode.com/problems/course-schedule-iii) | [Course Schedule III](/solution/0600-0699/0630.Course%20Schedule%20III/README_EN.md) | `Greedy` | Hard | | -| [0631](https://leetcode.com/problems/design-excel-sum-formula) | [Design Excel Sum Formula](/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README_EN.md) | `Design` | Hard | 🔒 | -| [0632](https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists) | [Smallest Range Covering Elements from K Lists](/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README_EN.md) | `Hash Table`,`Two Pointers`,`String` | Hard | | -| [0633](https://leetcode.com/problems/sum-of-square-numbers) | [Sum of Square Numbers](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README_EN.md) | `Math` | Medium | | -| [0634](https://leetcode.com/problems/find-the-derangement-of-an-array) | [Find the Derangement of An Array](/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README_EN.md) | `Math` | Medium | 🔒 | -| [0635](https://leetcode.com/problems/design-log-storage-system) | [Design Log Storage System](/solution/0600-0699/0635.Design%20Log%20Storage%20System/README_EN.md) | `Design`,`String` | Medium | 🔒 | -| [0636](https://leetcode.com/problems/exclusive-time-of-functions) | [Exclusive Time of Functions](/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README_EN.md) | `Stack` | Medium | | -| [0637](https://leetcode.com/problems/average-of-levels-in-binary-tree) | [Average of Levels in Binary Tree](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README_EN.md) | `Tree` | Easy | | -| [0638](https://leetcode.com/problems/shopping-offers) | [Shopping Offers](/solution/0600-0699/0638.Shopping%20Offers/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Medium | | -| [0639](https://leetcode.com/problems/decode-ways-ii) | [Decode Ways II](/solution/0600-0699/0639.Decode%20Ways%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [0640](https://leetcode.com/problems/solve-the-equation) | [Solve the Equation](/solution/0600-0699/0640.Solve%20the%20Equation/README_EN.md) | `Math` | Medium | | -| [0641](https://leetcode.com/problems/design-circular-deque) | [Design Circular Deque](/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md) | `Design`,`Queue` | Medium | | -| [0642](https://leetcode.com/problems/design-search-autocomplete-system) | [Design Search Autocomplete System](/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md) | `Design`,`Trie` | Hard | 🔒 | -| [0643](https://leetcode.com/problems/maximum-average-subarray-i) | [Maximum Average Subarray I](/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README_EN.md) | `Array` | Easy | | -| [0644](https://leetcode.com/problems/maximum-average-subarray-ii) | [Maximum Average Subarray II](/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README_EN.md) | `Array`,`Binary Search` | Hard | 🔒 | -| [0645](https://leetcode.com/problems/set-mismatch) | [Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md) | `Hash Table`,`Math` | Easy | | -| [0646](https://leetcode.com/problems/maximum-length-of-pair-chain) | [Maximum Length of Pair Chain](/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README_EN.md) | `Dynamic Programming` | Medium | | -| [0647](https://leetcode.com/problems/palindromic-substrings) | [Palindromic Substrings](/solution/0600-0699/0647.Palindromic%20Substrings/README_EN.md) | `String`,`Dynamic Programming` | Medium | | -| [0648](https://leetcode.com/problems/replace-words) | [Replace Words](/solution/0600-0699/0648.Replace%20Words/README_EN.md) | `Trie`,`Hash Table` | Medium | | -| [0649](https://leetcode.com/problems/dota2-senate) | [Dota2 Senate](/solution/0600-0699/0649.Dota2%20Senate/README_EN.md) | `Greedy` | Medium | | -| [0650](https://leetcode.com/problems/2-keys-keyboard) | [2 Keys Keyboard](/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md) | `Dynamic Programming` | Medium | | -| [0651](https://leetcode.com/problems/4-keys-keyboard) | [4 Keys Keyboard](/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md) | `Greedy`,`Math`,`Dynamic Programming` | Medium | 🔒 | -| [0652](https://leetcode.com/problems/find-duplicate-subtrees) | [Find Duplicate Subtrees](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README_EN.md) | `Tree` | Medium | | -| [0653](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | [Two Sum IV - Input is a BST](/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README_EN.md) | `Tree` | Easy | | -| [0654](https://leetcode.com/problems/maximum-binary-tree) | [Maximum Binary Tree](/solution/0600-0699/0654.Maximum%20Binary%20Tree/README_EN.md) | `Tree` | Medium | | -| [0655](https://leetcode.com/problems/print-binary-tree) | [Print Binary Tree](/solution/0600-0699/0655.Print%20Binary%20Tree/README_EN.md) | `Tree` | Medium | | -| [0656](https://leetcode.com/problems/coin-path) | [Coin Path](/solution/0600-0699/0656.Coin%20Path/README_EN.md) | `Dynamic Programming` | Hard | 🔒 | -| [0657](https://leetcode.com/problems/robot-return-to-origin) | [Robot Return to Origin](/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README_EN.md) | `String` | Easy | | -| [0658](https://leetcode.com/problems/find-k-closest-elements) | [Find K Closest Elements](/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README_EN.md) | `Binary Search` | Medium | | -| [0659](https://leetcode.com/problems/split-array-into-consecutive-subsequences) | [Split Array into Consecutive Subsequences](/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README_EN.md) | `Heap`,`Greedy` | Medium | | -| [0660](https://leetcode.com/problems/remove-9) | [Remove 9](/solution/0600-0699/0660.Remove%209/README_EN.md) | `Math` | Hard | 🔒 | -| [0661](https://leetcode.com/problems/image-smoother) | [Image Smoother](/solution/0600-0699/0661.Image%20Smoother/README_EN.md) | `Array` | Easy | | -| [0662](https://leetcode.com/problems/maximum-width-of-binary-tree) | [Maximum Width of Binary Tree](/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README_EN.md) | `Tree` | Medium | | -| [0663](https://leetcode.com/problems/equal-tree-partition) | [Equal Tree Partition](/solution/0600-0699/0663.Equal%20Tree%20Partition/README_EN.md) | `Tree` | Medium | 🔒 | -| [0664](https://leetcode.com/problems/strange-printer) | [Strange Printer](/solution/0600-0699/0664.Strange%20Printer/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Hard | | -| [0665](https://leetcode.com/problems/non-decreasing-array) | [Non-decreasing Array](/solution/0600-0699/0665.Non-decreasing%20Array/README_EN.md) | `Array` | Easy | | -| [0666](https://leetcode.com/problems/path-sum-iv) | [Path Sum IV](/solution/0600-0699/0666.Path%20Sum%20IV/README_EN.md) | `Tree` | Medium | 🔒 | -| [0667](https://leetcode.com/problems/beautiful-arrangement-ii) | [Beautiful Arrangement II](/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README_EN.md) | `Array` | Medium | | -| [0668](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table) | [Kth Smallest Number in Multiplication Table](/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README_EN.md) | `Binary Search` | Hard | | -| [0669](https://leetcode.com/problems/trim-a-binary-search-tree) | [Trim a Binary Search Tree](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree` | Easy | | -| [0670](https://leetcode.com/problems/maximum-swap) | [Maximum Swap](/solution/0600-0699/0670.Maximum%20Swap/README_EN.md) | `Array`,`Math` | Medium | | -| [0671](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree) | [Second Minimum Node In a Binary Tree](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README_EN.md) | `Tree` | Easy | | -| [0672](https://leetcode.com/problems/bulb-switcher-ii) | [Bulb Switcher II](/solution/0600-0699/0672.Bulb%20Switcher%20II/README_EN.md) | `Math` | Medium | | -| [0673](https://leetcode.com/problems/number-of-longest-increasing-subsequence) | [Number of Longest Increasing Subsequence](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README_EN.md) | `Dynamic Programming` | Medium | | -| [0674](https://leetcode.com/problems/longest-continuous-increasing-subsequence) | [Longest Continuous Increasing Subsequence](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README_EN.md) | `Array` | Easy | | -| [0675](https://leetcode.com/problems/cut-off-trees-for-golf-event) | [Cut Off Trees for Golf Event](/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README_EN.md) | `Breadth-first Search` | Hard | | -| [0676](https://leetcode.com/problems/implement-magic-dictionary) | [Implement Magic Dictionary](/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README_EN.md) | `Trie`,`Hash Table` | Medium | | -| [0677](https://leetcode.com/problems/map-sum-pairs) | [Map Sum Pairs](/solution/0600-0699/0677.Map%20Sum%20Pairs/README_EN.md) | `Trie` | Medium | | -| [0678](https://leetcode.com/problems/valid-parenthesis-string) | [Valid Parenthesis String](/solution/0600-0699/0678.Valid%20Parenthesis%20String/README_EN.md) | `String` | Medium | | -| [0679](https://leetcode.com/problems/24-game) | [24 Game](/solution/0600-0699/0679.24%20Game/README_EN.md) | `Depth-first Search` | Hard | | -| [0680](https://leetcode.com/problems/valid-palindrome-ii) | [Valid Palindrome II](/solution/0600-0699/0680.Valid%20Palindrome%20II/README_EN.md) | `String` | Easy | | -| [0681](https://leetcode.com/problems/next-closest-time) | [Next Closest Time](/solution/0600-0699/0681.Next%20Closest%20Time/README_EN.md) | `String` | Medium | 🔒 | -| [0682](https://leetcode.com/problems/baseball-game) | [Baseball Game](/solution/0600-0699/0682.Baseball%20Game/README_EN.md) | `Stack` | Easy | | -| [0683](https://leetcode.com/problems/k-empty-slots) | [K Empty Slots](/solution/0600-0699/0683.K%20Empty%20Slots/README_EN.md) | `Ordered Map` | Hard | 🔒 | -| [0684](https://leetcode.com/problems/redundant-connection) | [Redundant Connection](/solution/0600-0699/0684.Redundant%20Connection/README_EN.md) | `Tree`,`Union Find`,`Graph` | Medium | | -| [0685](https://leetcode.com/problems/redundant-connection-ii) | [Redundant Connection II](/solution/0600-0699/0685.Redundant%20Connection%20II/README_EN.md) | `Tree`,`Depth-first Search`,`Union Find`,`Graph` | Hard | | -| [0686](https://leetcode.com/problems/repeated-string-match) | [Repeated String Match](/solution/0600-0699/0686.Repeated%20String%20Match/README_EN.md) | `String` | Medium | | -| [0687](https://leetcode.com/problems/longest-univalue-path) | [Longest Univalue Path](/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md) | `Tree`,`Recursion` | Easy | | -| [0688](https://leetcode.com/problems/knight-probability-in-chessboard) | [Knight Probability in Chessboard](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md) | `Dynamic Programming` | Medium | | -| [0689](https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays) | [Maximum Sum of 3 Non-Overlapping Subarrays](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md) | `Array`,`Dynamic Programming` | Hard | | -| [0690](https://leetcode.com/problems/employee-importance) | [Employee Importance](/solution/0600-0699/0690.Employee%20Importance/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Hash Table` | Easy | | -| [0691](https://leetcode.com/problems/stickers-to-spell-word) | [Stickers to Spell Word](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | | -| [0692](https://leetcode.com/problems/top-k-frequent-words) | [Top K Frequent Words](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md) | `Heap`,`Trie`,`Hash Table` | Medium | | -| [0693](https://leetcode.com/problems/binary-number-with-alternating-bits) | [Binary Number with Alternating Bits](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md) | `Bit Manipulation` | Easy | | -| [0694](https://leetcode.com/problems/number-of-distinct-islands) | [Number of Distinct Islands](/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README_EN.md) | `Depth-first Search`,`Hash Table` | Medium | 🔒 | -| [0695](https://leetcode.com/problems/max-area-of-island) | [Max Area of Island](/solution/0600-0699/0695.Max%20Area%20of%20Island/README_EN.md) | `Depth-first Search`,`Array` | Medium | | -| [0696](https://leetcode.com/problems/count-binary-substrings) | [Count Binary Substrings](/solution/0600-0699/0696.Count%20Binary%20Substrings/README_EN.md) | `String` | Easy | | -| [0697](https://leetcode.com/problems/degree-of-an-array) | [Degree of an Array](/solution/0600-0699/0697.Degree%20of%20an%20Array/README_EN.md) | `Array` | Easy | | -| [0698](https://leetcode.com/problems/partition-to-k-equal-sum-subsets) | [Partition to K Equal Sum Subsets](/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README_EN.md) | `Recursion`,`Dynamic Programming` | Medium | | -| [0699](https://leetcode.com/problems/falling-squares) | [Falling Squares](/solution/0600-0699/0699.Falling%20Squares/README_EN.md) | `Segment Tree`,`Ordered Map` | Hard | | -| [0700](https://leetcode.com/problems/search-in-a-binary-search-tree) | [Search in a Binary Search Tree](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree` | Easy | | -| [0701](https://leetcode.com/problems/insert-into-a-binary-search-tree) | [Insert into a Binary Search Tree](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README_EN.md) | `Tree` | Medium | | -| [0702](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size) | [Search in a Sorted Array of Unknown Size](/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README_EN.md) | `Binary Search` | Medium | 🔒 | -| [0703](https://leetcode.com/problems/kth-largest-element-in-a-stream) | [Kth Largest Element in a Stream](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README_EN.md) | `Heap` | Easy | | -| [0704](https://leetcode.com/problems/binary-search) | [Binary Search](/solution/0700-0799/0704.Binary%20Search/README_EN.md) | `Binary Search` | Easy | | -| [0705](https://leetcode.com/problems/design-hashset) | [Design HashSet](/solution/0700-0799/0705.Design%20HashSet/README_EN.md) | `Design`,`Hash Table` | Easy | | -| [0706](https://leetcode.com/problems/design-hashmap) | [Design HashMap](/solution/0700-0799/0706.Design%20HashMap/README_EN.md) | `Design`,`Hash Table` | Easy | | -| [0707](https://leetcode.com/problems/design-linked-list) | [Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md) | `Design`,`Linked List` | Medium | | -| [0708](https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list) | [Insert into a Sorted Circular Linked List](/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README_EN.md) | `Linked List` | Medium | 🔒 | -| [0709](https://leetcode.com/problems/to-lower-case) | [To Lower Case](/solution/0700-0799/0709.To%20Lower%20Case/README_EN.md) | `String` | Easy | | -| [0710](https://leetcode.com/problems/random-pick-with-blacklist) | [Random Pick with Blacklist](/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README_EN.md) | `Sort`,`Hash Table`,`Binary Search`,`Random` | Hard | | -| [0711](https://leetcode.com/problems/number-of-distinct-islands-ii) | [Number of Distinct Islands II](/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README_EN.md) | `Depth-first Search`,`Hash Table` | Hard | 🔒 | -| [0712](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings) | [Minimum ASCII Delete Sum for Two Strings](/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README_EN.md) | `Dynamic Programming` | Medium | | -| [0713](https://leetcode.com/problems/subarray-product-less-than-k) | [Subarray Product Less Than K](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md) | `Array`,`Two Pointers` | Medium | | -| [0714](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee) | [Best Time to Buy and Sell Stock with Transaction Fee](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md) | `Greedy`,`Array`,`Dynamic Programming` | Medium | | -| [0715](https://leetcode.com/problems/range-module) | [Range Module](/solution/0700-0799/0715.Range%20Module/README_EN.md) | `Segment Tree`,`Ordered Map` | Hard | | -| [0716](https://leetcode.com/problems/max-stack) | [Max Stack](/solution/0700-0799/0716.Max%20Stack/README_EN.md) | `Design` | Easy | 🔒 | -| [0717](https://leetcode.com/problems/1-bit-and-2-bit-characters) | [1-bit and 2-bit Characters](/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README_EN.md) | `Array` | Easy | | -| [0718](https://leetcode.com/problems/maximum-length-of-repeated-subarray) | [Maximum Length of Repeated Subarray](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README_EN.md) | `Array`,`Hash Table`,`Binary Search`,`Dynamic Programming` | Medium | | -| [0719](https://leetcode.com/problems/find-k-th-smallest-pair-distance) | [Find K-th Smallest Pair Distance](/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README_EN.md) | `Heap`,`Array`,`Binary Search` | Hard | | -| [0720](https://leetcode.com/problems/longest-word-in-dictionary) | [Longest Word in Dictionary](/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README_EN.md) | `Trie`,`Hash Table` | Easy | | -| [0721](https://leetcode.com/problems/accounts-merge) | [Accounts Merge](/solution/0700-0799/0721.Accounts%20Merge/README_EN.md) | `Depth-first Search`,`Union Find` | Medium | | -| [0722](https://leetcode.com/problems/remove-comments) | [Remove Comments](/solution/0700-0799/0722.Remove%20Comments/README_EN.md) | `String` | Medium | | -| [0723](https://leetcode.com/problems/candy-crush) | [Candy Crush](/solution/0700-0799/0723.Candy%20Crush/README_EN.md) | `Array`,`Two Pointers` | Medium | 🔒 | -| [0724](https://leetcode.com/problems/find-pivot-index) | [Find Pivot Index](/solution/0700-0799/0724.Find%20Pivot%20Index/README_EN.md) | `Array` | Easy | | -| [0725](https://leetcode.com/problems/split-linked-list-in-parts) | [Split Linked List in Parts](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README_EN.md) | `Linked List` | Medium | | -| [0726](https://leetcode.com/problems/number-of-atoms) | [Number of Atoms](/solution/0700-0799/0726.Number%20of%20Atoms/README_EN.md) | `Stack`,`Recursion`,`Hash Table` | Hard | | -| [0727](https://leetcode.com/problems/minimum-window-subsequence) | [Minimum Window Subsequence](/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README_EN.md) | `Dynamic Programming`,`Sliding Window` | Hard | 🔒 | -| [0728](https://leetcode.com/problems/self-dividing-numbers) | [Self Dividing Numbers](/solution/0700-0799/0728.Self%20Dividing%20Numbers/README_EN.md) | `Math` | Easy | | -| [0729](https://leetcode.com/problems/my-calendar-i) | [My Calendar I](/solution/0700-0799/0729.My%20Calendar%20I/README_EN.md) | `Array` | Medium | | -| [0730](https://leetcode.com/problems/count-different-palindromic-subsequences) | [Count Different Palindromic Subsequences](/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [0731](https://leetcode.com/problems/my-calendar-ii) | [My Calendar II](/solution/0700-0799/0731.My%20Calendar%20II/README_EN.md) | `Ordered Map` | Medium | | -| [0732](https://leetcode.com/problems/my-calendar-iii) | [My Calendar III](/solution/0700-0799/0732.My%20Calendar%20III/README_EN.md) | `Segment Tree`,`Ordered Map` | Hard | | -| [0733](https://leetcode.com/problems/flood-fill) | [Flood Fill](/solution/0700-0799/0733.Flood%20Fill/README_EN.md) | `Depth-first Search` | Easy | | -| [0734](https://leetcode.com/problems/sentence-similarity) | [Sentence Similarity](/solution/0700-0799/0734.Sentence%20Similarity/README_EN.md) | `Hash Table` | Easy | 🔒 | -| [0735](https://leetcode.com/problems/asteroid-collision) | [Asteroid Collision](/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md) | `Stack` | Medium | | -| [0736](https://leetcode.com/problems/parse-lisp-expression) | [Parse Lisp Expression](/solution/0700-0799/0736.Parse%20Lisp%20Expression/README_EN.md) | `String` | Hard | | -| [0737](https://leetcode.com/problems/sentence-similarity-ii) | [Sentence Similarity II](/solution/0700-0799/0737.Sentence%20Similarity%20II/README_EN.md) | `Depth-first Search`,`Union Find` | Medium | 🔒 | -| [0738](https://leetcode.com/problems/monotone-increasing-digits) | [Monotone Increasing Digits](/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README_EN.md) | `Greedy` | Medium | | -| [0739](https://leetcode.com/problems/daily-temperatures) | [Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md) | `Stack`,`Hash Table` | Medium | | -| [0740](https://leetcode.com/problems/delete-and-earn) | [Delete and Earn](/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md) | `Dynamic Programming` | Medium | | -| [0741](https://leetcode.com/problems/cherry-pickup) | [Cherry Pickup](/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md) | `Dynamic Programming` | Hard | | -| [0742](https://leetcode.com/problems/closest-leaf-in-a-binary-tree) | [Closest Leaf in a Binary Tree](/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README_EN.md) | `Tree` | Medium | 🔒 | -| [0743](https://leetcode.com/problems/network-delay-time) | [Network Delay Time](/solution/0700-0799/0743.Network%20Delay%20Time/README_EN.md) | `Heap`,`Depth-first Search`,`Breadth-first Search`,`Graph` | Medium | | -| [0744](https://leetcode.com/problems/find-smallest-letter-greater-than-target) | [Find Smallest Letter Greater Than Target](/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README_EN.md) | `Binary Search` | Easy | | -| [0745](https://leetcode.com/problems/prefix-and-suffix-search) | [Prefix and Suffix Search](/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README_EN.md) | `Trie` | Hard | | -| [0746](https://leetcode.com/problems/min-cost-climbing-stairs) | [Min Cost Climbing Stairs](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md) | `Array`,`Dynamic Programming` | Easy | | -| [0747](https://leetcode.com/problems/largest-number-at-least-twice-of-others) | [Largest Number At Least Twice of Others](/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README_EN.md) | `Array` | Easy | | -| [0748](https://leetcode.com/problems/shortest-completing-word) | [Shortest Completing Word](/solution/0700-0799/0748.Shortest%20Completing%20Word/README_EN.md) | `Hash Table` | Easy | | -| [0749](https://leetcode.com/problems/contain-virus) | [Contain Virus](/solution/0700-0799/0749.Contain%20Virus/README_EN.md) | `Depth-first Search` | Hard | | -| [0750](https://leetcode.com/problems/number-of-corner-rectangles) | [Number Of Corner Rectangles](/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README_EN.md) | `Dynamic Programming` | Medium | 🔒 | -| [0751](https://leetcode.com/problems/ip-to-cidr) | [IP to CIDR](/solution/0700-0799/0751.IP%20to%20CIDR/README_EN.md) | `Bit Manipulation` | Easy | 🔒 | -| [0752](https://leetcode.com/problems/open-the-lock) | [Open the Lock](/solution/0700-0799/0752.Open%20the%20Lock/README_EN.md) | `Breadth-first Search` | Medium | | -| [0753](https://leetcode.com/problems/cracking-the-safe) | [Cracking the Safe](/solution/0700-0799/0753.Cracking%20the%20Safe/README_EN.md) | `Depth-first Search`,`Math` | Hard | | -| [0754](https://leetcode.com/problems/reach-a-number) | [Reach a Number](/solution/0700-0799/0754.Reach%20a%20Number/README_EN.md) | `Math` | Medium | | -| [0755](https://leetcode.com/problems/pour-water) | [Pour Water](/solution/0700-0799/0755.Pour%20Water/README_EN.md) | `Array` | Medium | 🔒 | -| [0756](https://leetcode.com/problems/pyramid-transition-matrix) | [Pyramid Transition Matrix](/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README_EN.md) | `Bit Manipulation`,`Depth-first Search` | Medium | | -| [0757](https://leetcode.com/problems/set-intersection-size-at-least-two) | [Set Intersection Size At Least Two](/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README_EN.md) | `Greedy` | Hard | | -| [0758](https://leetcode.com/problems/bold-words-in-string) | [Bold Words in String](/solution/0700-0799/0758.Bold%20Words%20in%20String/README_EN.md) | `String` | Easy | 🔒 | -| [0759](https://leetcode.com/problems/employee-free-time) | [Employee Free Time](/solution/0700-0799/0759.Employee%20Free%20Time/README_EN.md) | `Heap`,`Greedy` | Hard | 🔒 | -| [0760](https://leetcode.com/problems/find-anagram-mappings) | [Find Anagram Mappings](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README_EN.md) | `Hash Table` | Easy | 🔒 | -| [0761](https://leetcode.com/problems/special-binary-string) | [Special Binary String](/solution/0700-0799/0761.Special%20Binary%20String/README_EN.md) | `Recursion`,`String` | Hard | | -| [0762](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation) | [Prime Number of Set Bits in Binary Representation](/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README_EN.md) | `Bit Manipulation` | Easy | | -| [0763](https://leetcode.com/problems/partition-labels) | [Partition Labels](/solution/0700-0799/0763.Partition%20Labels/README_EN.md) | `Greedy`,`Two Pointers` | Medium | | -| [0764](https://leetcode.com/problems/largest-plus-sign) | [Largest Plus Sign](/solution/0700-0799/0764.Largest%20Plus%20Sign/README_EN.md) | `Dynamic Programming` | Medium | | -| [0765](https://leetcode.com/problems/couples-holding-hands) | [Couples Holding Hands](/solution/0700-0799/0765.Couples%20Holding%20Hands/README_EN.md) | `Greedy`,`Union Find`,`Graph` | Hard | | -| [0766](https://leetcode.com/problems/toeplitz-matrix) | [Toeplitz Matrix](/solution/0700-0799/0766.Toeplitz%20Matrix/README_EN.md) | `Array` | Easy | | -| [0767](https://leetcode.com/problems/reorganize-string) | [Reorganize String](/solution/0700-0799/0767.Reorganize%20String/README_EN.md) | `Heap`,`Greedy`,`Sort`,`String` | Medium | | -| [0768](https://leetcode.com/problems/max-chunks-to-make-sorted-ii) | [Max Chunks To Make Sorted II](/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README_EN.md) | `Array` | Hard | | -| [0769](https://leetcode.com/problems/max-chunks-to-make-sorted) | [Max Chunks To Make Sorted](/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README_EN.md) | `Array` | Medium | | -| [0770](https://leetcode.com/problems/basic-calculator-iv) | [Basic Calculator IV](/solution/0700-0799/0770.Basic%20Calculator%20IV/README_EN.md) | `Stack`,`Hash Table`,`String` | Hard | | -| [0771](https://leetcode.com/problems/jewels-and-stones) | [Jewels and Stones](/solution/0700-0799/0771.Jewels%20and%20Stones/README_EN.md) | `Hash Table` | Easy | | -| [0772](https://leetcode.com/problems/basic-calculator-iii) | [Basic Calculator III](/solution/0700-0799/0772.Basic%20Calculator%20III/README_EN.md) | `Stack`,`String` | Hard | 🔒 | -| [0773](https://leetcode.com/problems/sliding-puzzle) | [Sliding Puzzle](/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md) | `Breadth-first Search` | Hard | | -| [0774](https://leetcode.com/problems/minimize-max-distance-to-gas-station) | [Minimize Max Distance to Gas Station](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README_EN.md) | `Binary Search` | Hard | 🔒 | -| [0775](https://leetcode.com/problems/global-and-local-inversions) | [Global and Local Inversions](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README_EN.md) | `Array`,`Math` | Medium | | -| [0776](https://leetcode.com/problems/split-bst) | [Split BST](/solution/0700-0799/0776.Split%20BST/README_EN.md) | `Tree`,`Recursion` | Medium | 🔒 | -| [0777](https://leetcode.com/problems/swap-adjacent-in-lr-string) | [Swap Adjacent in LR String](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md) | `Brainteaser` | Medium | | -| [0778](https://leetcode.com/problems/swim-in-rising-water) | [Swim in Rising Water](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README_EN.md) | `Heap`,`Depth-first Search`,`Union Find`,`Binary Search` | Hard | | -| [0779](https://leetcode.com/problems/k-th-symbol-in-grammar) | [K-th Symbol in Grammar](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README_EN.md) | `Recursion` | Medium | | -| [0780](https://leetcode.com/problems/reaching-points) | [Reaching Points](/solution/0700-0799/0780.Reaching%20Points/README_EN.md) | `Math` | Hard | | -| [0781](https://leetcode.com/problems/rabbits-in-forest) | [Rabbits in Forest](/solution/0700-0799/0781.Rabbits%20in%20Forest/README_EN.md) | `Hash Table`,`Math` | Medium | | -| [0782](https://leetcode.com/problems/transform-to-chessboard) | [Transform to Chessboard](/solution/0700-0799/0782.Transform%20to%20Chessboard/README_EN.md) | `Array`,`Math` | Hard | | -| [0783](https://leetcode.com/problems/minimum-distance-between-bst-nodes) | [Minimum Distance Between BST Nodes](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README_EN.md) | `Tree`,`Recursion` | Easy | | -| [0784](https://leetcode.com/problems/letter-case-permutation) | [Letter Case Permutation](/solution/0700-0799/0784.Letter%20Case%20Permutation/README_EN.md) | `Bit Manipulation`,`Backtracking` | Medium | | -| [0785](https://leetcode.com/problems/is-graph-bipartite) | [Is Graph Bipartite?](/solution/0700-0799/0785.Is%20Graph%20Bipartite%3F/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Graph` | Medium | | -| [0786](https://leetcode.com/problems/k-th-smallest-prime-fraction) | [K-th Smallest Prime Fraction](/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README_EN.md) | `Heap`,`Binary Search` | Hard | | -| [0787](https://leetcode.com/problems/cheapest-flights-within-k-stops) | [Cheapest Flights Within K Stops](/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README_EN.md) | `Heap`,`Breadth-first Search`,`Dynamic Programming` | Medium | | -| [0788](https://leetcode.com/problems/rotated-digits) | [Rotated Digits](/solution/0700-0799/0788.Rotated%20Digits/README_EN.md) | `String` | Easy | | -| [0789](https://leetcode.com/problems/escape-the-ghosts) | [Escape The Ghosts](/solution/0700-0799/0789.Escape%20The%20Ghosts/README_EN.md) | `Math` | Medium | | -| [0790](https://leetcode.com/problems/domino-and-tromino-tiling) | [Domino and Tromino Tiling](/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README_EN.md) | `Dynamic Programming` | Medium | | -| [0791](https://leetcode.com/problems/custom-sort-string) | [Custom Sort String](/solution/0700-0799/0791.Custom%20Sort%20String/README_EN.md) | `String` | Medium | | -| [0792](https://leetcode.com/problems/number-of-matching-subsequences) | [Number of Matching Subsequences](/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README_EN.md) | `Array` | Medium | | -| [0793](https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function) | [Preimage Size of Factorial Zeroes Function](/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README_EN.md) | `Binary Search` | Hard | | -| [0794](https://leetcode.com/problems/valid-tic-tac-toe-state) | [Valid Tic-Tac-Toe State](/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README_EN.md) | `Recursion`,`Math` | Medium | | -| [0795](https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum) | [Number of Subarrays with Bounded Maximum](/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README_EN.md) | `Array` | Medium | | -| [0796](https://leetcode.com/problems/rotate-string) | [Rotate String](/solution/0700-0799/0796.Rotate%20String/README_EN.md) | | Easy | | -| [0797](https://leetcode.com/problems/all-paths-from-source-to-target) | [All Paths From Source to Target](/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README_EN.md) | | Medium | | -| [0798](https://leetcode.com/problems/smallest-rotation-with-highest-score) | [Smallest Rotation with Highest Score](/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README_EN.md) | | Hard | | -| [0799](https://leetcode.com/problems/champagne-tower) | [Champagne Tower](/solution/0700-0799/0799.Champagne%20Tower/README_EN.md) | | Medium | | -| [0800](https://leetcode.com/problems/similar-rgb-color) | [Similar RGB Color](/solution/0800-0899/0800.Similar%20RGB%20Color/README_EN.md) | `Math`,`String` | Easy | 🔒 | -| [0801](https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing) | [Minimum Swaps To Make Sequences Increasing](/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README_EN.md) | `Dynamic Programming` | Medium | | -| [0802](https://leetcode.com/problems/find-eventual-safe-states) | [Find Eventual Safe States](/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README_EN.md) | `Depth-first Search`,`Graph` | Medium | | -| [0803](https://leetcode.com/problems/bricks-falling-when-hit) | [Bricks Falling When Hit](/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README_EN.md) | `Union Find` | Hard | | -| [0804](https://leetcode.com/problems/unique-morse-code-words) | [Unique Morse Code Words](/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README_EN.md) | `String` | Easy | | -| [0805](https://leetcode.com/problems/split-array-with-same-average) | [Split Array With Same Average](/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README_EN.md) | `Math` | Hard | | -| [0806](https://leetcode.com/problems/number-of-lines-to-write-string) | [Number of Lines To Write String](/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README_EN.md) | | Easy | | -| [0807](https://leetcode.com/problems/max-increase-to-keep-city-skyline) | [Max Increase to Keep City Skyline](/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README_EN.md) | | Medium | | -| [0808](https://leetcode.com/problems/soup-servings) | [Soup Servings](/solution/0800-0899/0808.Soup%20Servings/README_EN.md) | `Dynamic Programming` | Medium | | -| [0809](https://leetcode.com/problems/expressive-words) | [Expressive Words](/solution/0800-0899/0809.Expressive%20Words/README_EN.md) | `String` | Medium | | -| [0810](https://leetcode.com/problems/chalkboard-xor-game) | [Chalkboard XOR Game](/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README_EN.md) | `Math` | Hard | | -| [0811](https://leetcode.com/problems/subdomain-visit-count) | [Subdomain Visit Count](/solution/0800-0899/0811.Subdomain%20Visit%20Count/README_EN.md) | `Hash Table` | Easy | | -| [0812](https://leetcode.com/problems/largest-triangle-area) | [Largest Triangle Area](/solution/0800-0899/0812.Largest%20Triangle%20Area/README_EN.md) | `Math` | Easy | | -| [0813](https://leetcode.com/problems/largest-sum-of-averages) | [Largest Sum of Averages](/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README_EN.md) | `Dynamic Programming` | Medium | | -| [0814](https://leetcode.com/problems/binary-tree-pruning) | [Binary Tree Pruning](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README_EN.md) | `Tree` | Medium | | -| [0815](https://leetcode.com/problems/bus-routes) | [Bus Routes](/solution/0800-0899/0815.Bus%20Routes/README_EN.md) | `Breadth-first Search` | Hard | | -| [0816](https://leetcode.com/problems/ambiguous-coordinates) | [Ambiguous Coordinates](/solution/0800-0899/0816.Ambiguous%20Coordinates/README_EN.md) | `String` | Medium | | -| [0817](https://leetcode.com/problems/linked-list-components) | [Linked List Components](/solution/0800-0899/0817.Linked%20List%20Components/README_EN.md) | `Linked List` | Medium | | -| [0818](https://leetcode.com/problems/race-car) | [Race Car](/solution/0800-0899/0818.Race%20Car/README_EN.md) | `Heap`,`Dynamic Programming` | Hard | | -| [0819](https://leetcode.com/problems/most-common-word) | [Most Common Word](/solution/0800-0899/0819.Most%20Common%20Word/README_EN.md) | `String` | Easy | | -| [0820](https://leetcode.com/problems/short-encoding-of-words) | [Short Encoding of Words](/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README_EN.md) | | Medium | | -| [0821](https://leetcode.com/problems/shortest-distance-to-a-character) | [Shortest Distance to a Character](/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README_EN.md) | | Easy | | -| [0822](https://leetcode.com/problems/card-flipping-game) | [Card Flipping Game](/solution/0800-0899/0822.Card%20Flipping%20Game/README_EN.md) | | Medium | | -| [0823](https://leetcode.com/problems/binary-trees-with-factors) | [Binary Trees With Factors](/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README_EN.md) | | Medium | | -| [0824](https://leetcode.com/problems/goat-latin) | [Goat Latin](/solution/0800-0899/0824.Goat%20Latin/README_EN.md) | `String` | Easy | | -| [0825](https://leetcode.com/problems/friends-of-appropriate-ages) | [Friends Of Appropriate Ages](/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README_EN.md) | `Array` | Medium | | -| [0826](https://leetcode.com/problems/most-profit-assigning-work) | [Most Profit Assigning Work](/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README_EN.md) | `Two Pointers` | Medium | | -| [0827](https://leetcode.com/problems/making-a-large-island) | [Making A Large Island](/solution/0800-0899/0827.Making%20A%20Large%20Island/README_EN.md) | `Depth-first Search` | Hard | | -| [0828](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string) | [Count Unique Characters of All Substrings of a Given String](/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README_EN.md) | `Two Pointers` | Hard | | -| [0829](https://leetcode.com/problems/consecutive-numbers-sum) | [Consecutive Numbers Sum](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README_EN.md) | `Math` | Hard | | -| [0830](https://leetcode.com/problems/positions-of-large-groups) | [Positions of Large Groups](/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README_EN.md) | `Array` | Easy | | -| [0831](https://leetcode.com/problems/masking-personal-information) | [Masking Personal Information](/solution/0800-0899/0831.Masking%20Personal%20Information/README_EN.md) | `String` | Medium | | -| [0832](https://leetcode.com/problems/flipping-an-image) | [Flipping an Image](/solution/0800-0899/0832.Flipping%20an%20Image/README_EN.md) | `Array` | Easy | | -| [0833](https://leetcode.com/problems/find-and-replace-in-string) | [Find And Replace in String](/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README_EN.md) | `String` | Medium | | -| [0834](https://leetcode.com/problems/sum-of-distances-in-tree) | [Sum of Distances in Tree](/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Hard | | -| [0835](https://leetcode.com/problems/image-overlap) | [Image Overlap](/solution/0800-0899/0835.Image%20Overlap/README_EN.md) | `Array` | Medium | | -| [0836](https://leetcode.com/problems/rectangle-overlap) | [Rectangle Overlap](/solution/0800-0899/0836.Rectangle%20Overlap/README_EN.md) | `Math` | Easy | | -| [0837](https://leetcode.com/problems/new-21-game) | [New 21 Game](/solution/0800-0899/0837.New%2021%20Game/README_EN.md) | `Dynamic Programming` | Medium | | -| [0838](https://leetcode.com/problems/push-dominoes) | [Push Dominoes](/solution/0800-0899/0838.Push%20Dominoes/README_EN.md) | `Two Pointers`,`Dynamic Programming` | Medium | | -| [0839](https://leetcode.com/problems/similar-string-groups) | [Similar String Groups](/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md) | `Depth-first Search`,`Union Find`,`Graph` | Hard | | -| [0840](https://leetcode.com/problems/magic-squares-in-grid) | [Magic Squares In Grid](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md) | `Array` | Medium | | -| [0841](https://leetcode.com/problems/keys-and-rooms) | [Keys and Rooms](/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md) | `Depth-first Search`,`Graph` | Medium | | -| [0842](https://leetcode.com/problems/split-array-into-fibonacci-sequence) | [Split Array into Fibonacci Sequence](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md) | `Greedy`,`String`,`Backtracking` | Medium | | -| [0843](https://leetcode.com/problems/guess-the-word) | [Guess the Word](/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md) | `Minimax` | Hard | | -| [0844](https://leetcode.com/problems/backspace-string-compare) | [Backspace String Compare](/solution/0800-0899/0844.Backspace%20String%20Compare/README_EN.md) | `Stack`,`Two Pointers` | Easy | | -| [0845](https://leetcode.com/problems/longest-mountain-in-array) | [Longest Mountain in Array](/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README_EN.md) | `Two Pointers` | Medium | | -| [0846](https://leetcode.com/problems/hand-of-straights) | [Hand of Straights](/solution/0800-0899/0846.Hand%20of%20Straights/README_EN.md) | `Ordered Map` | Medium | | -| [0847](https://leetcode.com/problems/shortest-path-visiting-all-nodes) | [Shortest Path Visiting All Nodes](/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README_EN.md) | `Breadth-first Search`,`Dynamic Programming` | Hard | | -| [0848](https://leetcode.com/problems/shifting-letters) | [Shifting Letters](/solution/0800-0899/0848.Shifting%20Letters/README_EN.md) | `String` | Medium | | -| [0849](https://leetcode.com/problems/maximize-distance-to-closest-person) | [Maximize Distance to Closest Person](/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README_EN.md) | `Array` | Medium | | -| [0850](https://leetcode.com/problems/rectangle-area-ii) | [Rectangle Area II](/solution/0800-0899/0850.Rectangle%20Area%20II/README_EN.md) | `Segment Tree`,`Line Sweep` | Hard | | -| [0851](https://leetcode.com/problems/loud-and-rich) | [Loud and Rich](/solution/0800-0899/0851.Loud%20and%20Rich/README_EN.md) | `Depth-first Search` | Medium | | -| [0852](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [Peak Index in a Mountain Array](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README_EN.md) | `Binary Search` | Easy | | -| [0853](https://leetcode.com/problems/car-fleet) | [Car Fleet](/solution/0800-0899/0853.Car%20Fleet/README_EN.md) | `Sort` | Medium | | -| [0854](https://leetcode.com/problems/k-similar-strings) | [K-Similar Strings](/solution/0800-0899/0854.K-Similar%20Strings/README_EN.md) | `Breadth-first Search`,`Graph` | Hard | | -| [0855](https://leetcode.com/problems/exam-room) | [Exam Room](/solution/0800-0899/0855.Exam%20Room/README_EN.md) | `Ordered Map` | Medium | | -| [0856](https://leetcode.com/problems/score-of-parentheses) | [Score of Parentheses](/solution/0800-0899/0856.Score%20of%20Parentheses/README_EN.md) | `Stack`,`String` | Medium | | -| [0857](https://leetcode.com/problems/minimum-cost-to-hire-k-workers) | [Minimum Cost to Hire K Workers](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README_EN.md) | `Heap` | Hard | | -| [0858](https://leetcode.com/problems/mirror-reflection) | [Mirror Reflection](/solution/0800-0899/0858.Mirror%20Reflection/README_EN.md) | `Math` | Medium | | -| [0859](https://leetcode.com/problems/buddy-strings) | [Buddy Strings](/solution/0800-0899/0859.Buddy%20Strings/README_EN.md) | `String` | Easy | | -| [0860](https://leetcode.com/problems/lemonade-change) | [Lemonade Change](/solution/0800-0899/0860.Lemonade%20Change/README_EN.md) | `Greedy` | Easy | | -| [0861](https://leetcode.com/problems/score-after-flipping-matrix) | [Score After Flipping Matrix](/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README_EN.md) | `Greedy` | Medium | | -| [0862](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k) | [Shortest Subarray with Sum at Least K](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README_EN.md) | `Queue`,`Binary Search` | Hard | | -| [0863](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree) | [All Nodes Distance K in Binary Tree](/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Medium | | -| [0864](https://leetcode.com/problems/shortest-path-to-get-all-keys) | [Shortest Path to Get All Keys](/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README_EN.md) | `Heap`,`Breadth-first Search` | Hard | | -| [0865](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes) | [Smallest Subtree with all the Deepest Nodes](/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README_EN.md) | `Tree` | Medium | | -| [0866](https://leetcode.com/problems/prime-palindrome) | [Prime Palindrome](/solution/0800-0899/0866.Prime%20Palindrome/README_EN.md) | `Math` | Medium | | -| [0867](https://leetcode.com/problems/transpose-matrix) | [Transpose Matrix](/solution/0800-0899/0867.Transpose%20Matrix/README_EN.md) | `Array` | Easy | | -| [0868](https://leetcode.com/problems/binary-gap) | [Binary Gap](/solution/0800-0899/0868.Binary%20Gap/README_EN.md) | `Math` | Easy | | -| [0869](https://leetcode.com/problems/reordered-power-of-2) | [Reordered Power of 2](/solution/0800-0899/0869.Reordered%20Power%20of%202/README_EN.md) | `Math` | Medium | | -| [0870](https://leetcode.com/problems/advantage-shuffle) | [Advantage Shuffle](/solution/0800-0899/0870.Advantage%20Shuffle/README_EN.md) | `Greedy`,`Array` | Medium | | -| [0871](https://leetcode.com/problems/minimum-number-of-refueling-stops) | [Minimum Number of Refueling Stops](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md) | `Heap`,`Dynamic Programming` | Hard | | -| [0872](https://leetcode.com/problems/leaf-similar-trees) | [Leaf-Similar Trees](/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0873](https://leetcode.com/problems/length-of-longest-fibonacci-subsequence) | [Length of Longest Fibonacci Subsequence](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [0874](https://leetcode.com/problems/walking-robot-simulation) | [Walking Robot Simulation](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md) | `Greedy` | Easy | | -| [0875](https://leetcode.com/problems/koko-eating-bananas) | [Koko Eating Bananas](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md) | `Binary Search` | Medium | | -| [0876](https://leetcode.com/problems/middle-of-the-linked-list) | [Middle of the Linked List](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md) | `Linked List` | Easy | | -| [0877](https://leetcode.com/problems/stone-game) | [Stone Game](/solution/0800-0899/0877.Stone%20Game/README_EN.md) | `Minimax`,`Math`,`Dynamic Programming` | Medium | | -| [0878](https://leetcode.com/problems/nth-magical-number) | [Nth Magical Number](/solution/0800-0899/0878.Nth%20Magical%20Number/README_EN.md) | `Math`,`Binary Search` | Hard | | -| [0879](https://leetcode.com/problems/profitable-schemes) | [Profitable Schemes](/solution/0800-0899/0879.Profitable%20Schemes/README_EN.md) | `Dynamic Programming` | Hard | | -| [0880](https://leetcode.com/problems/decoded-string-at-index) | [Decoded String at Index](/solution/0800-0899/0880.Decoded%20String%20at%20Index/README_EN.md) | `Stack` | Medium | | -| [0881](https://leetcode.com/problems/boats-to-save-people) | [Boats to Save People](/solution/0800-0899/0881.Boats%20to%20Save%20People/README_EN.md) | `Greedy`,`Two Pointers` | Medium | | -| [0882](https://leetcode.com/problems/reachable-nodes-in-subdivided-graph) | [Reachable Nodes In Subdivided Graph](/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README_EN.md) | `Heap` | Hard | | -| [0883](https://leetcode.com/problems/projection-area-of-3d-shapes) | [Projection Area of 3D Shapes](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README_EN.md) | `Math` | Easy | | -| [0884](https://leetcode.com/problems/uncommon-words-from-two-sentences) | [Uncommon Words from Two Sentences](/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README_EN.md) | `Hash Table` | Easy | | -| [0885](https://leetcode.com/problems/spiral-matrix-iii) | [Spiral Matrix III](/solution/0800-0899/0885.Spiral%20Matrix%20III/README_EN.md) | `Math` | Medium | | -| [0886](https://leetcode.com/problems/possible-bipartition) | [Possible Bipartition](/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md) | `Depth-first Search`,`Graph` | Medium | | -| [0887](https://leetcode.com/problems/super-egg-drop) | [Super Egg Drop](/solution/0800-0899/0887.Super%20Egg%20Drop/README_EN.md) | `Math`,`Binary Search`,`Dynamic Programming` | Hard | | -| [0888](https://leetcode.com/problems/fair-candy-swap) | [Fair Candy Swap](/solution/0800-0899/0888.Fair%20Candy%20Swap/README_EN.md) | `Array` | Easy | | -| [0889](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | [Construct Binary Tree from Preorder and Postorder Traversal](/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README_EN.md) | `Tree` | Medium | | -| [0890](https://leetcode.com/problems/find-and-replace-pattern) | [Find and Replace Pattern](/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README_EN.md) | `String` | Medium | | -| [0891](https://leetcode.com/problems/sum-of-subsequence-widths) | [Sum of Subsequence Widths](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README_EN.md) | `Array`,`Math` | Hard | | -| [0892](https://leetcode.com/problems/surface-area-of-3d-shapes) | [Surface Area of 3D Shapes](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README_EN.md) | `Geometry`,`Math` | Easy | | -| [0893](https://leetcode.com/problems/groups-of-special-equivalent-strings) | [Groups of Special-Equivalent Strings](/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README_EN.md) | `String` | Easy | | -| [0894](https://leetcode.com/problems/all-possible-full-binary-trees) | [All Possible Full Binary Trees](/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README_EN.md) | `Tree`,`Recursion` | Medium | | -| [0895](https://leetcode.com/problems/maximum-frequency-stack) | [Maximum Frequency Stack](/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README_EN.md) | `Stack`,`Hash Table` | Hard | | -| [0896](https://leetcode.com/problems/monotonic-array) | [Monotonic Array](/solution/0800-0899/0896.Monotonic%20Array/README_EN.md) | `Array` | Easy | | -| [0897](https://leetcode.com/problems/increasing-order-search-tree) | [Increasing Order Search Tree](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Easy | | -| [0898](https://leetcode.com/problems/bitwise-ors-of-subarrays) | [Bitwise ORs of Subarrays](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README_EN.md) | `Bit Manipulation`,`Dynamic Programming` | Medium | | -| [0899](https://leetcode.com/problems/orderly-queue) | [Orderly Queue](/solution/0800-0899/0899.Orderly%20Queue/README_EN.md) | `Math`,`String` | Hard | | -| [0900](https://leetcode.com/problems/rle-iterator) | [RLE Iterator](/solution/0900-0999/0900.RLE%20Iterator/README_EN.md) | `Array` | Medium | | -| [0901](https://leetcode.com/problems/online-stock-span) | [Online Stock Span](/solution/0900-0999/0901.Online%20Stock%20Span/README_EN.md) | `Stack` | Medium | | -| [0902](https://leetcode.com/problems/numbers-at-most-n-given-digit-set) | [Numbers At Most N Given Digit Set](/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [0903](https://leetcode.com/problems/valid-permutations-for-di-sequence) | [Valid Permutations for DI Sequence](/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README_EN.md) | `Divide and Conquer`,`Dynamic Programming` | Hard | | -| [0904](https://leetcode.com/problems/fruit-into-baskets) | [Fruit Into Baskets](/solution/0900-0999/0904.Fruit%20Into%20Baskets/README_EN.md) | `Two Pointers` | Medium | | -| [0905](https://leetcode.com/problems/sort-array-by-parity) | [Sort Array By Parity](/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README_EN.md) | `Array` | Easy | | -| [0906](https://leetcode.com/problems/super-palindromes) | [Super Palindromes](/solution/0900-0999/0906.Super%20Palindromes/README_EN.md) | `Math` | Hard | | -| [0907](https://leetcode.com/problems/sum-of-subarray-minimums) | [Sum of Subarray Minimums](/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README_EN.md) | `Stack`,`Array` | Medium | | -| [0908](https://leetcode.com/problems/smallest-range-i) | [Smallest Range I](/solution/0900-0999/0908.Smallest%20Range%20I/README_EN.md) | `Math` | Easy | | -| [0909](https://leetcode.com/problems/snakes-and-ladders) | [Snakes and Ladders](/solution/0900-0999/0909.Snakes%20and%20Ladders/README_EN.md) | `Breadth-first Search` | Medium | | -| [0910](https://leetcode.com/problems/smallest-range-ii) | [Smallest Range II](/solution/0900-0999/0910.Smallest%20Range%20II/README_EN.md) | `Greedy`,`Math` | Medium | | -| [0911](https://leetcode.com/problems/online-election) | [Online Election](/solution/0900-0999/0911.Online%20Election/README_EN.md) | `Binary Search` | Medium | | -| [0912](https://leetcode.com/problems/sort-an-array) | [Sort an Array](/solution/0900-0999/0912.Sort%20an%20Array/README_EN.md) | | Medium | | -| [0913](https://leetcode.com/problems/cat-and-mouse) | [Cat and Mouse](/solution/0900-0999/0913.Cat%20and%20Mouse/README_EN.md) | `Breadth-first Search`,`Minimax` | Hard | | -| [0914](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | [X of a Kind in a Deck of Cards](/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README_EN.md) | `Array`,`Math` | Easy | | -| [0915](https://leetcode.com/problems/partition-array-into-disjoint-intervals) | [Partition Array into Disjoint Intervals](/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README_EN.md) | `Array` | Medium | | -| [0916](https://leetcode.com/problems/word-subsets) | [Word Subsets](/solution/0900-0999/0916.Word%20Subsets/README_EN.md) | `String` | Medium | | -| [0917](https://leetcode.com/problems/reverse-only-letters) | [Reverse Only Letters](/solution/0900-0999/0917.Reverse%20Only%20Letters/README_EN.md) | `String` | Easy | | -| [0918](https://leetcode.com/problems/maximum-sum-circular-subarray) | [Maximum Sum Circular Subarray](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md) | `Array` | Medium | | -| [0919](https://leetcode.com/problems/complete-binary-tree-inserter) | [Complete Binary Tree Inserter](/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README_EN.md) | `Tree` | Medium | | -| [0920](https://leetcode.com/problems/number-of-music-playlists) | [Number of Music Playlists](/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README_EN.md) | `Dynamic Programming` | Hard | | -| [0921](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid) | [Minimum Add to Make Parentheses Valid](/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README_EN.md) | `Stack`,`Greedy` | Medium | | -| [0922](https://leetcode.com/problems/sort-array-by-parity-ii) | [Sort Array By Parity II](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README_EN.md) | `Sort`,`Array` | Easy | | -| [0923](https://leetcode.com/problems/3sum-with-multiplicity) | [3Sum With Multiplicity](/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README_EN.md) | `Two Pointers` | Medium | | -| [0924](https://leetcode.com/problems/minimize-malware-spread) | [Minimize Malware Spread](/solution/0900-0999/0924.Minimize%20Malware%20Spread/README_EN.md) | `Depth-first Search`,`Union Find` | Hard | | -| [0925](https://leetcode.com/problems/long-pressed-name) | [Long Pressed Name](/solution/0900-0999/0925.Long%20Pressed%20Name/README_EN.md) | `Two Pointers`,`String` | Easy | | -| [0926](https://leetcode.com/problems/flip-string-to-monotone-increasing) | [Flip String to Monotone Increasing](/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README_EN.md) | `Array` | Medium | | -| [0927](https://leetcode.com/problems/three-equal-parts) | [Three Equal Parts](/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md) | `Greedy`,`Math`,`Binary Search` | Hard | | -| [0928](https://leetcode.com/problems/minimize-malware-spread-ii) | [Minimize Malware Spread II](/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README_EN.md) | `Depth-first Search`,`Union Find`,`Graph` | Hard | | -| [0929](https://leetcode.com/problems/unique-email-addresses) | [Unique Email Addresses](/solution/0900-0999/0929.Unique%20Email%20Addresses/README_EN.md) | `String` | Easy | | -| [0930](https://leetcode.com/problems/binary-subarrays-with-sum) | [Binary Subarrays With Sum](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README_EN.md) | `Hash Table`,`Two Pointers` | Medium | | -| [0931](https://leetcode.com/problems/minimum-falling-path-sum) | [Minimum Falling Path Sum](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [0932](https://leetcode.com/problems/beautiful-array) | [Beautiful Array](/solution/0900-0999/0932.Beautiful%20Array/README_EN.md) | `Divide and Conquer` | Medium | | -| [0933](https://leetcode.com/problems/number-of-recent-calls) | [Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md) | `Queue` | Easy | | -| [0934](https://leetcode.com/problems/shortest-bridge) | [Shortest Bridge](/solution/0900-0999/0934.Shortest%20Bridge/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [0935](https://leetcode.com/problems/knight-dialer) | [Knight Dialer](/solution/0900-0999/0935.Knight%20Dialer/README_EN.md) | `Dynamic Programming` | Medium | | -| [0936](https://leetcode.com/problems/stamping-the-sequence) | [Stamping The Sequence](/solution/0900-0999/0936.Stamping%20The%20Sequence/README_EN.md) | `Greedy`,`String` | Hard | | -| [0937](https://leetcode.com/problems/reorder-data-in-log-files) | [Reorder Data in Log Files](/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README_EN.md) | `String` | Easy | | -| [0938](https://leetcode.com/problems/range-sum-of-bst) | [Range Sum of BST](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README_EN.md) | `Tree`,`Recursion` | Easy | | -| [0939](https://leetcode.com/problems/minimum-area-rectangle) | [Minimum Area Rectangle](/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README_EN.md) | `Hash Table` | Medium | | -| [0940](https://leetcode.com/problems/distinct-subsequences-ii) | [Distinct Subsequences II](/solution/0900-0999/0940.Distinct%20Subsequences%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [0941](https://leetcode.com/problems/valid-mountain-array) | [Valid Mountain Array](/solution/0900-0999/0941.Valid%20Mountain%20Array/README_EN.md) | `Array` | Easy | | -| [0942](https://leetcode.com/problems/di-string-match) | [DI String Match](/solution/0900-0999/0942.DI%20String%20Match/README_EN.md) | `Math` | Easy | | -| [0943](https://leetcode.com/problems/find-the-shortest-superstring) | [Find the Shortest Superstring](/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README_EN.md) | `Dynamic Programming` | Hard | | -| [0944](https://leetcode.com/problems/delete-columns-to-make-sorted) | [Delete Columns to Make Sorted](/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README_EN.md) | `Greedy` | Easy | | -| [0945](https://leetcode.com/problems/minimum-increment-to-make-array-unique) | [Minimum Increment to Make Array Unique](/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README_EN.md) | `Array` | Medium | | -| [0946](https://leetcode.com/problems/validate-stack-sequences) | [Validate Stack Sequences](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README_EN.md) | `Stack` | Medium | | -| [0947](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column) | [Most Stones Removed with Same Row or Column](/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README_EN.md) | `Depth-first Search`,`Union Find` | Medium | | -| [0948](https://leetcode.com/problems/bag-of-tokens) | [Bag of Tokens](/solution/0900-0999/0948.Bag%20of%20Tokens/README_EN.md) | `Greedy` | Medium | | -| [0949](https://leetcode.com/problems/largest-time-for-given-digits) | [Largest Time for Given Digits](/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README_EN.md) | `Math` | Medium | | -| [0950](https://leetcode.com/problems/reveal-cards-in-increasing-order) | [Reveal Cards In Increasing Order](/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README_EN.md) | `Array` | Medium | | -| [0951](https://leetcode.com/problems/flip-equivalent-binary-trees) | [Flip Equivalent Binary Trees](/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README_EN.md) | `Tree` | Medium | | -| [0952](https://leetcode.com/problems/largest-component-size-by-common-factor) | [Largest Component Size by Common Factor](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README_EN.md) | `Union Find`,`Math` | Hard | | -| [0953](https://leetcode.com/problems/verifying-an-alien-dictionary) | [Verifying an Alien Dictionary](/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README_EN.md) | `Hash Table` | Easy | | -| [0954](https://leetcode.com/problems/array-of-doubled-pairs) | [Array of Doubled Pairs](/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README_EN.md) | `Array`,`Hash Table` | Medium | | -| [0955](https://leetcode.com/problems/delete-columns-to-make-sorted-ii) | [Delete Columns to Make Sorted II](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README_EN.md) | `Greedy` | Medium | | -| [0956](https://leetcode.com/problems/tallest-billboard) | [Tallest Billboard](/solution/0900-0999/0956.Tallest%20Billboard/README_EN.md) | `Dynamic Programming` | Hard | | -| [0957](https://leetcode.com/problems/prison-cells-after-n-days) | [Prison Cells After N Days](/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README_EN.md) | `Hash Table` | Medium | | -| [0958](https://leetcode.com/problems/check-completeness-of-a-binary-tree) | [Check Completeness of a Binary Tree](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README_EN.md) | `Tree` | Medium | | -| [0959](https://leetcode.com/problems/regions-cut-by-slashes) | [Regions Cut By Slashes](/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README_EN.md) | `Depth-first Search`,`Union Find`,`Graph` | Medium | | -| [0960](https://leetcode.com/problems/delete-columns-to-make-sorted-iii) | [Delete Columns to Make Sorted III](/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README_EN.md) | `Dynamic Programming` | Hard | | -| [0961](https://leetcode.com/problems/n-repeated-element-in-size-2n-array) | [N-Repeated Element in Size 2N Array](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README_EN.md) | `Hash Table` | Easy | | -| [0962](https://leetcode.com/problems/maximum-width-ramp) | [Maximum Width Ramp](/solution/0900-0999/0962.Maximum%20Width%20Ramp/README_EN.md) | `Array` | Medium | | -| [0963](https://leetcode.com/problems/minimum-area-rectangle-ii) | [Minimum Area Rectangle II](/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README_EN.md) | `Geometry`,`Math` | Medium | | -| [0964](https://leetcode.com/problems/least-operators-to-express-number) | [Least Operators to Express Number](/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [0965](https://leetcode.com/problems/univalued-binary-tree) | [Univalued Binary Tree](/solution/0900-0999/0965.Univalued%20Binary%20Tree/README_EN.md) | `Tree` | Easy | | -| [0966](https://leetcode.com/problems/vowel-spellchecker) | [Vowel Spellchecker](/solution/0900-0999/0966.Vowel%20Spellchecker/README_EN.md) | `Hash Table`,`String` | Medium | | -| [0967](https://leetcode.com/problems/numbers-with-same-consecutive-differences) | [Numbers With Same Consecutive Differences](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [0968](https://leetcode.com/problems/binary-tree-cameras) | [Binary Tree Cameras](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md) | `Tree`,`Depth-first Search`,`Dynamic Programming` | Hard | | -| [0969](https://leetcode.com/problems/pancake-sorting) | [Pancake Sorting](/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md) | `Sort`,`Array` | Medium | | -| [0970](https://leetcode.com/problems/powerful-integers) | [Powerful Integers](/solution/0900-0999/0970.Powerful%20Integers/README_EN.md) | `Hash Table`,`Math` | Easy | | -| [0971](https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal) | [Flip Binary Tree To Match Preorder Traversal](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0972](https://leetcode.com/problems/equal-rational-numbers) | [Equal Rational Numbers](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md) | `Math` | Hard | | -| [0973](https://leetcode.com/problems/k-closest-points-to-origin) | [K Closest Points to Origin](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md) | `Heap`,`Sort`,`Divide and Conquer` | Medium | | -| [0974](https://leetcode.com/problems/subarray-sums-divisible-by-k) | [Subarray Sums Divisible by K](/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README_EN.md) | `Array`,`Hash Table` | Medium | | -| [0975](https://leetcode.com/problems/odd-even-jump) | [Odd Even Jump](/solution/0900-0999/0975.Odd%20Even%20Jump/README_EN.md) | `Stack`,`Dynamic Programming`,`Ordered Map` | Hard | | -| [0976](https://leetcode.com/problems/largest-perimeter-triangle) | [Largest Perimeter Triangle](/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README_EN.md) | `Sort`,`Math` | Easy | | -| [0977](https://leetcode.com/problems/squares-of-a-sorted-array) | [Squares of a Sorted Array](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README_EN.md) | `Array`,`Two Pointers` | Easy | | -| [0978](https://leetcode.com/problems/longest-turbulent-subarray) | [Longest Turbulent Subarray](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README_EN.md) | `Array`,`Dynamic Programming`,`Sliding Window` | Medium | | -| [0979](https://leetcode.com/problems/distribute-coins-in-binary-tree) | [Distribute Coins in Binary Tree](/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0980](https://leetcode.com/problems/unique-paths-iii) | [Unique Paths III](/solution/0900-0999/0980.Unique%20Paths%20III/README_EN.md) | `Depth-first Search`,`Backtracking` | Hard | | -| [0981](https://leetcode.com/problems/time-based-key-value-store) | [Time Based Key-Value Store](/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README_EN.md) | `Hash Table`,`Binary Search` | Medium | | -| [0982](https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero) | [Triples with Bitwise AND Equal To Zero](/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README_EN.md) | `Dynamic Programming` | Hard | | -| [0983](https://leetcode.com/problems/minimum-cost-for-tickets) | [Minimum Cost For Tickets](/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README_EN.md) | `Dynamic Programming` | Medium | | -| [0984](https://leetcode.com/problems/string-without-aaa-or-bbb) | [String Without AAA or BBB](/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README_EN.md) | `Greedy` | Medium | | -| [0985](https://leetcode.com/problems/sum-of-even-numbers-after-queries) | [Sum of Even Numbers After Queries](/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README_EN.md) | `Array` | Easy | | -| [0986](https://leetcode.com/problems/interval-list-intersections) | [Interval List Intersections](/solution/0900-0999/0986.Interval%20List%20Intersections/README_EN.md) | `Two Pointers` | Medium | | -| [0987](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree) | [Vertical Order Traversal of a Binary Tree](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README_EN.md) | `Tree`,`Hash Table` | Medium | | -| [0988](https://leetcode.com/problems/smallest-string-starting-from-leaf) | [Smallest String Starting From Leaf](/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [0989](https://leetcode.com/problems/add-to-array-form-of-integer) | [Add to Array-Form of Integer](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README_EN.md) | `Array` | Easy | | -| [0990](https://leetcode.com/problems/satisfiability-of-equality-equations) | [Satisfiability of Equality Equations](/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README_EN.md) | `Union Find`,`Graph` | Medium | | -| [0991](https://leetcode.com/problems/broken-calculator) | [Broken Calculator](/solution/0900-0999/0991.Broken%20Calculator/README_EN.md) | `Greedy`,`Math` | Medium | | -| [0992](https://leetcode.com/problems/subarrays-with-k-different-integers) | [Subarrays with K Different Integers](/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README_EN.md) | `Hash Table`,`Two Pointers`,`Sliding Window` | Hard | | -| [0993](https://leetcode.com/problems/cousins-in-binary-tree) | [Cousins in Binary Tree](/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README_EN.md) | `Tree`,`Breadth-first Search` | Easy | | -| [0994](https://leetcode.com/problems/rotting-oranges) | [Rotting Oranges](/solution/0900-0999/0994.Rotting%20Oranges/README_EN.md) | `Breadth-first Search` | Medium | | -| [0995](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips) | [Minimum Number of K Consecutive Bit Flips](/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README_EN.md) | `Greedy`,`Sliding Window` | Hard | | -| [0996](https://leetcode.com/problems/number-of-squareful-arrays) | [Number of Squareful Arrays](/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README_EN.md) | `Graph`,`Math`,`Backtracking` | Hard | | -| [0997](https://leetcode.com/problems/find-the-town-judge) | [Find the Town Judge](/solution/0900-0999/0997.Find%20the%20Town%20Judge/README_EN.md) | `Graph` | Easy | | -| [0998](https://leetcode.com/problems/maximum-binary-tree-ii) | [Maximum Binary Tree II](/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README_EN.md) | `Tree` | Medium | | -| [0999](https://leetcode.com/problems/available-captures-for-rook) | [Available Captures for Rook](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README_EN.md) | `Array` | Easy | | -| [1000](https://leetcode.com/problems/minimum-cost-to-merge-stones) | [Minimum Cost to Merge Stones](/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README_EN.md) | `Dynamic Programming` | Hard | | -| [1001](https://leetcode.com/problems/grid-illumination) | [Grid Illumination](/solution/1000-1099/1001.Grid%20Illumination/README_EN.md) | `Hash Table` | Hard | | -| [1002](https://leetcode.com/problems/find-common-characters) | [Find Common Characters](/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [1003](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions) | [Check If Word Is Valid After Substitutions](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md) | `Stack`,`String` | Medium | | -| [1004](https://leetcode.com/problems/max-consecutive-ones-iii) | [Max Consecutive Ones III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md) | `Two Pointers`,`Sliding Window` | Medium | | -| [1005](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations) | [Maximize Sum Of Array After K Negations](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md) | `Greedy` | Easy | | -| [1006](https://leetcode.com/problems/clumsy-factorial) | [Clumsy Factorial](/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md) | `Math` | Medium | | -| [1007](https://leetcode.com/problems/minimum-domino-rotations-for-equal-row) | [Minimum Domino Rotations For Equal Row](/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1008](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal) | [Construct Binary Search Tree from Preorder Traversal](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README_EN.md) | `Tree` | Medium | | -| [1009](https://leetcode.com/problems/complement-of-base-10-integer) | [Complement of Base 10 Integer](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README_EN.md) | `Math` | Easy | | -| [1010](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60) | [Pairs of Songs With Total Durations Divisible by 60](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README_EN.md) | `Array` | Easy | | -| [1011](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days) | [Capacity To Ship Packages Within D Days](/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1012](https://leetcode.com/problems/numbers-with-repeated-digits) | [Numbers With Repeated Digits](/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [1013](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum) | [Partition Array Into Three Parts With Equal Sum](/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README_EN.md) | `Array` | Easy | | -| [1014](https://leetcode.com/problems/best-sightseeing-pair) | [Best Sightseeing Pair](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md) | `Array` | Medium | | -| [1015](https://leetcode.com/problems/smallest-integer-divisible-by-k) | [Smallest Integer Divisible by K](/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README_EN.md) | `Math` | Medium | | -| [1016](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n) | [Binary String With Substrings Representing 1 To N](/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README_EN.md) | `String` | Medium | | -| [1017](https://leetcode.com/problems/convert-to-base-2) | [Convert to Base -2](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README_EN.md) | `Math` | Medium | | -| [1018](https://leetcode.com/problems/binary-prefix-divisible-by-5) | [Binary Prefix Divisible By 5](/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README_EN.md) | `Array` | Easy | | -| [1019](https://leetcode.com/problems/next-greater-node-in-linked-list) | [Next Greater Node In Linked List](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README_EN.md) | `Stack`,`Linked List` | Medium | | -| [1020](https://leetcode.com/problems/number-of-enclaves) | [Number of Enclaves](/solution/1000-1099/1020.Number%20of%20Enclaves/README_EN.md) | `Depth-first Search` | Medium | | -| [1021](https://leetcode.com/problems/remove-outermost-parentheses) | [Remove Outermost Parentheses](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README_EN.md) | `Stack` | Easy | | -| [1022](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers) | [Sum of Root To Leaf Binary Numbers](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README_EN.md) | `Tree` | Easy | | -| [1023](https://leetcode.com/problems/camelcase-matching) | [Camelcase Matching](/solution/1000-1099/1023.Camelcase%20Matching/README_EN.md) | `Trie`,`String` | Medium | | -| [1024](https://leetcode.com/problems/video-stitching) | [Video Stitching](/solution/1000-1099/1024.Video%20Stitching/README_EN.md) | `Dynamic Programming` | Medium | | -| [1025](https://leetcode.com/problems/divisor-game) | [Divisor Game](/solution/1000-1099/1025.Divisor%20Game/README_EN.md) | `Math`,`Dynamic Programming` | Easy | | -| [1026](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor) | [Maximum Difference Between Node and Ancestor](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1027](https://leetcode.com/problems/longest-arithmetic-subsequence) | [Longest Arithmetic Subsequence](/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README_EN.md) | `Dynamic Programming` | Medium | | -| [1028](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal) | [Recover a Tree From Preorder Traversal](/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README_EN.md) | `Tree`,`Depth-first Search` | Hard | | -| [1029](https://leetcode.com/problems/two-city-scheduling) | [Two City Scheduling](/solution/1000-1099/1029.Two%20City%20Scheduling/README_EN.md) | `Greedy` | Medium | | -| [1030](https://leetcode.com/problems/matrix-cells-in-distance-order) | [Matrix Cells in Distance Order](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README_EN.md) | `Sort` | Easy | | -| [1031](https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays) | [Maximum Sum of Two Non-Overlapping Subarrays](/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README_EN.md) | `Array` | Medium | | -| [1032](https://leetcode.com/problems/stream-of-characters) | [Stream of Characters](/solution/1000-1099/1032.Stream%20of%20Characters/README_EN.md) | `Trie` | Hard | | -| [1033](https://leetcode.com/problems/moving-stones-until-consecutive) | [Moving Stones Until Consecutive](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README_EN.md) | `Brainteaser` | Easy | | -| [1034](https://leetcode.com/problems/coloring-a-border) | [Coloring A Border](/solution/1000-1099/1034.Coloring%20A%20Border/README_EN.md) | `Depth-first Search` | Medium | | -| [1035](https://leetcode.com/problems/uncrossed-lines) | [Uncrossed Lines](/solution/1000-1099/1035.Uncrossed%20Lines/README_EN.md) | `Array` | Medium | | -| [1036](https://leetcode.com/problems/escape-a-large-maze) | [Escape a Large Maze](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README_EN.md) | `Breadth-first Search` | Hard | | -| [1037](https://leetcode.com/problems/valid-boomerang) | [Valid Boomerang](/solution/1000-1099/1037.Valid%20Boomerang/README_EN.md) | `Math` | Easy | | -| [1038](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree) | [Binary Search Tree to Greater Sum Tree](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README_EN.md) | `Binary Search Tree` | Medium | | -| [1039](https://leetcode.com/problems/minimum-score-triangulation-of-polygon) | [Minimum Score Triangulation of Polygon](/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README_EN.md) | `Dynamic Programming` | Medium | | -| [1040](https://leetcode.com/problems/moving-stones-until-consecutive-ii) | [Moving Stones Until Consecutive II](/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README_EN.md) | `Array`,`Sliding Window` | Medium | | -| [1041](https://leetcode.com/problems/robot-bounded-in-circle) | [Robot Bounded In Circle](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README_EN.md) | `Math` | Medium | | -| [1042](https://leetcode.com/problems/flower-planting-with-no-adjacent) | [Flower Planting With No Adjacent](/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README_EN.md) | `Graph` | Easy | | -| [1043](https://leetcode.com/problems/partition-array-for-maximum-sum) | [Partition Array for Maximum Sum](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [1044](https://leetcode.com/problems/longest-duplicate-substring) | [Longest Duplicate Substring](/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README_EN.md) | `Hash Table`,`Binary Search` | Hard | | -| [1045](https://leetcode.com/problems/customers-who-bought-all-products) | [Customers Who Bought All Products](/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README_EN.md) | | Medium | 🔒 | -| [1046](https://leetcode.com/problems/last-stone-weight) | [Last Stone Weight](/solution/1000-1099/1046.Last%20Stone%20Weight/README_EN.md) | `Heap`,`Greedy` | Easy | | -| [1047](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string) | [Remove All Adjacent Duplicates In String](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README_EN.md) | `Stack` | Easy | | -| [1048](https://leetcode.com/problems/longest-string-chain) | [Longest String Chain](/solution/1000-1099/1048.Longest%20String%20Chain/README_EN.md) | `Hash Table`,`Dynamic Programming` | Medium | | -| [1049](https://leetcode.com/problems/last-stone-weight-ii) | [Last Stone Weight II](/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README_EN.md) | `Dynamic Programming` | Medium | | -| [1050](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times) | [Actors and Directors Who Cooperated At Least Three Times](/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README_EN.md) | | Easy | 🔒 | -| [1051](https://leetcode.com/problems/height-checker) | [Height Checker](/solution/1000-1099/1051.Height%20Checker/README_EN.md) | `Array` | Easy | | -| [1052](https://leetcode.com/problems/grumpy-bookstore-owner) | [Grumpy Bookstore Owner](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README_EN.md) | `Array`,`Sliding Window` | Medium | | -| [1053](https://leetcode.com/problems/previous-permutation-with-one-swap) | [Previous Permutation With One Swap](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1054](https://leetcode.com/problems/distant-barcodes) | [Distant Barcodes](/solution/1000-1099/1054.Distant%20Barcodes/README_EN.md) | `Heap`,`Sort` | Medium | | -| [1055](https://leetcode.com/problems/shortest-way-to-form-string) | [Shortest Way to Form String](/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README_EN.md) | `Greedy`,`Dynamic Programming` | Medium | 🔒 | -| [1056](https://leetcode.com/problems/confusing-number) | [Confusing Number](/solution/1000-1099/1056.Confusing%20Number/README_EN.md) | `Math` | Easy | 🔒 | -| [1057](https://leetcode.com/problems/campus-bikes) | [Campus Bikes](/solution/1000-1099/1057.Campus%20Bikes/README_EN.md) | `Greedy`,`Sort` | Medium | 🔒 | -| [1058](https://leetcode.com/problems/minimize-rounding-error-to-meet-target) | [Minimize Rounding Error to Meet Target](/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README_EN.md) | `Greedy`,`Math`,`Dynamic Programming` | Medium | 🔒 | -| [1059](https://leetcode.com/problems/all-paths-from-source-lead-to-destination) | [All Paths from Source Lead to Destination](/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README_EN.md) | `Depth-first Search`,`Graph` | Medium | 🔒 | -| [1060](https://leetcode.com/problems/missing-element-in-sorted-array) | [Missing Element in Sorted Array](/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README_EN.md) | `Binary Search` | Medium | 🔒 | -| [1061](https://leetcode.com/problems/lexicographically-smallest-equivalent-string) | [Lexicographically Smallest Equivalent String](/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README_EN.md) | `Depth-first Search`,`Union Find` | Medium | 🔒 | -| [1062](https://leetcode.com/problems/longest-repeating-substring) | [Longest Repeating Substring](/solution/1000-1099/1062.Longest%20Repeating%20Substring/README_EN.md) | `String` | Medium | 🔒 | -| [1063](https://leetcode.com/problems/number-of-valid-subarrays) | [Number of Valid Subarrays](/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README_EN.md) | `Stack` | Hard | 🔒 | -| [1064](https://leetcode.com/problems/fixed-point) | [Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md) | `Array`,`Binary Search` | Easy | 🔒 | -| [1065](https://leetcode.com/problems/index-pairs-of-a-string) | [Index Pairs of a String](/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README_EN.md) | `Trie`,`String` | Easy | 🔒 | -| [1066](https://leetcode.com/problems/campus-bikes-ii) | [Campus Bikes II](/solution/1000-1099/1066.Campus%20Bikes%20II/README_EN.md) | `Dynamic Programming`,`Backtracking` | Medium | 🔒 | -| [1067](https://leetcode.com/problems/digit-count-in-range) | [Digit Count in Range](/solution/1000-1099/1067.Digit%20Count%20in%20Range/README_EN.md) | `Math`,`Dynamic Programming` | Hard | 🔒 | -| [1068](https://leetcode.com/problems/product-sales-analysis-i) | [Product Sales Analysis I](/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README_EN.md) | | Easy | 🔒 | -| [1069](https://leetcode.com/problems/product-sales-analysis-ii) | [Product Sales Analysis II](/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README_EN.md) | | Easy | 🔒 | -| [1070](https://leetcode.com/problems/product-sales-analysis-iii) | [Product Sales Analysis III](/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README_EN.md) | | Medium | 🔒 | -| [1071](https://leetcode.com/problems/greatest-common-divisor-of-strings) | [Greatest Common Divisor of Strings](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README_EN.md) | `String` | Easy | | -| [1072](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows) | [Flip Columns For Maximum Number of Equal Rows](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README_EN.md) | `Hash Table` | Medium | | -| [1073](https://leetcode.com/problems/adding-two-negabinary-numbers) | [Adding Two Negabinary Numbers](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README_EN.md) | `Math` | Medium | | -| [1074](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target) | [Number of Submatrices That Sum to Target](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README_EN.md) | `Array`,`Dynamic Programming`,`Sliding Window` | Hard | | -| [1075](https://leetcode.com/problems/project-employees-i) | [Project Employees I](/solution/1000-1099/1075.Project%20Employees%20I/README_EN.md) | | Easy | 🔒 | -| [1076](https://leetcode.com/problems/project-employees-ii) | [Project Employees II](/solution/1000-1099/1076.Project%20Employees%20II/README_EN.md) | | Easy | 🔒 | -| [1077](https://leetcode.com/problems/project-employees-iii) | [Project Employees III](/solution/1000-1099/1077.Project%20Employees%20III/README_EN.md) | | Medium | 🔒 | -| [1078](https://leetcode.com/problems/occurrences-after-bigram) | [Occurrences After Bigram](/solution/1000-1099/1078.Occurrences%20After%20Bigram/README_EN.md) | `Hash Table` | Easy | | -| [1079](https://leetcode.com/problems/letter-tile-possibilities) | [Letter Tile Possibilities](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README_EN.md) | `Backtracking` | Medium | | -| [1080](https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths) | [Insufficient Nodes in Root to Leaf Paths](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README_EN.md) | `Depth-first Search` | Medium | | -| [1081](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters) | [Smallest Subsequence of Distinct Characters](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README_EN.md) | `String` | Medium | | -| [1082](https://leetcode.com/problems/sales-analysis-i) | [Sales Analysis I](/solution/1000-1099/1082.Sales%20Analysis%20I/README_EN.md) | | Easy | 🔒 | -| [1083](https://leetcode.com/problems/sales-analysis-ii) | [Sales Analysis II](/solution/1000-1099/1083.Sales%20Analysis%20II/README_EN.md) | | Easy | 🔒 | -| [1084](https://leetcode.com/problems/sales-analysis-iii) | [Sales Analysis III](/solution/1000-1099/1084.Sales%20Analysis%20III/README_EN.md) | | Easy | 🔒 | -| [1085](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number) | [Sum of Digits in the Minimum Number](/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README_EN.md) | `Array` | Easy | 🔒 | -| [1086](https://leetcode.com/problems/high-five) | [High Five](/solution/1000-1099/1086.High%20Five/README_EN.md) | `Sort`,`Array`,`Hash Table` | Easy | 🔒 | -| [1087](https://leetcode.com/problems/brace-expansion) | [Brace Expansion](/solution/1000-1099/1087.Brace%20Expansion/README_EN.md) | `Backtracking` | Medium | 🔒 | -| [1088](https://leetcode.com/problems/confusing-number-ii) | [Confusing Number II](/solution/1000-1099/1088.Confusing%20Number%20II/README_EN.md) | `Math`,`Backtracking` | Hard | 🔒 | -| [1089](https://leetcode.com/problems/duplicate-zeros) | [Duplicate Zeros](/solution/1000-1099/1089.Duplicate%20Zeros/README_EN.md) | `Array` | Easy | | -| [1090](https://leetcode.com/problems/largest-values-from-labels) | [Largest Values From Labels](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README_EN.md) | `Greedy`,`Hash Table` | Medium | | -| [1091](https://leetcode.com/problems/shortest-path-in-binary-matrix) | [Shortest Path in Binary Matrix](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README_EN.md) | `Breadth-first Search` | Medium | | -| [1092](https://leetcode.com/problems/shortest-common-supersequence) | [Shortest Common Supersequence ](/solution/1000-1099/1092.Shortest%20Common%20Supersequence%20/README_EN.md) | `Dynamic Programming` | Hard | | -| [1093](https://leetcode.com/problems/statistics-from-a-large-sample) | [Statistics from a Large Sample](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README_EN.md) | `Math`,`Two Pointers` | Medium | | -| [1094](https://leetcode.com/problems/car-pooling) | [Car Pooling](/solution/1000-1099/1094.Car%20Pooling/README_EN.md) | `Greedy` | Medium | | -| [1095](https://leetcode.com/problems/find-in-mountain-array) | [Find in Mountain Array](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README_EN.md) | `Binary Search` | Hard | | -| [1096](https://leetcode.com/problems/brace-expansion-ii) | [Brace Expansion II](/solution/1000-1099/1096.Brace%20Expansion%20II/README_EN.md) | `String` | Hard | | -| [1097](https://leetcode.com/problems/game-play-analysis-v) | [Game Play Analysis V](/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README_EN.md) | | Hard | 🔒 | -| [1098](https://leetcode.com/problems/unpopular-books) | [Unpopular Books](/solution/1000-1099/1098.Unpopular%20Books/README_EN.md) | | Medium | 🔒 | -| [1099](https://leetcode.com/problems/two-sum-less-than-k) | [Two Sum Less Than K](/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README_EN.md) | `Array` | Easy | 🔒 | -| [1100](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters) | [Find K-Length Substrings With No Repeated Characters](/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README_EN.md) | `String`,`Sliding Window` | Medium | 🔒 | -| [1101](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends) | [The Earliest Moment When Everyone Become Friends](/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README_EN.md) | `Union Find` | Medium | 🔒 | -| [1102](https://leetcode.com/problems/path-with-maximum-minimum-value) | [Path With Maximum Minimum Value](/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README_EN.md) | `Depth-first Search`,`Union Find`,`Graph` | Medium | 🔒 | -| [1103](https://leetcode.com/problems/distribute-candies-to-people) | [Distribute Candies to People](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README_EN.md) | `Math` | Easy | | -| [1104](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree) | [Path In Zigzag Labelled Binary Tree](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README_EN.md) | `Tree`,`Math` | Medium | | -| [1105](https://leetcode.com/problems/filling-bookcase-shelves) | [Filling Bookcase Shelves](/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README_EN.md) | `Dynamic Programming` | Medium | | -| [1106](https://leetcode.com/problems/parsing-a-boolean-expression) | [Parsing A Boolean Expression](/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README_EN.md) | `String` | Hard | | -| [1107](https://leetcode.com/problems/new-users-daily-count) | [New Users Daily Count](/solution/1100-1199/1107.New%20Users%20Daily%20Count/README_EN.md) | | Medium | 🔒 | -| [1108](https://leetcode.com/problems/defanging-an-ip-address) | [Defanging an IP Address](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README_EN.md) | `String` | Easy | | -| [1109](https://leetcode.com/problems/corporate-flight-bookings) | [Corporate Flight Bookings](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README_EN.md) | `Array`,`Math` | Medium | | -| [1110](https://leetcode.com/problems/delete-nodes-and-return-forest) | [Delete Nodes And Return Forest](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1111](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings) | [Maximum Nesting Depth of Two Valid Parentheses Strings](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README_EN.md) | `Greedy`,`Binary Search` | Medium | | -| [1112](https://leetcode.com/problems/highest-grade-for-each-student) | [Highest Grade For Each Student](/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README_EN.md) | | Medium | 🔒 | -| [1113](https://leetcode.com/problems/reported-posts) | [Reported Posts](/solution/1100-1199/1113.Reported%20Posts/README_EN.md) | | Easy | 🔒 | -| [1114](https://leetcode.com/problems/print-in-order) | [Print in Order](/solution/1100-1199/1114.Print%20in%20Order/README_EN.md) | | Easy | | -| [1115](https://leetcode.com/problems/print-foobar-alternately) | [Print FooBar Alternately](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README_EN.md) | | Medium | | -| [1116](https://leetcode.com/problems/print-zero-even-odd) | [Print Zero Even Odd](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README_EN.md) | | Medium | | -| [1117](https://leetcode.com/problems/building-h2o) | [Building H2O](/solution/1100-1199/1117.Building%20H2O/README_EN.md) | | Medium | | -| [1118](https://leetcode.com/problems/number-of-days-in-a-month) | [Number of Days in a Month](/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README_EN.md) | | Easy | 🔒 | -| [1119](https://leetcode.com/problems/remove-vowels-from-a-string) | [Remove Vowels from a String](/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README_EN.md) | `String` | Easy | 🔒 | -| [1120](https://leetcode.com/problems/maximum-average-subtree) | [Maximum Average Subtree](/solution/1100-1199/1120.Maximum%20Average%20Subtree/README_EN.md) | `Tree` | Medium | 🔒 | -| [1121](https://leetcode.com/problems/divide-array-into-increasing-sequences) | [Divide Array Into Increasing Sequences](/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README_EN.md) | `Math` | Hard | 🔒 | -| [1122](https://leetcode.com/problems/relative-sort-array) | [Relative Sort Array](/solution/1100-1199/1122.Relative%20Sort%20Array/README_EN.md) | `Sort`,`Array` | Easy | | -| [1123](https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves) | [Lowest Common Ancestor of Deepest Leaves](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1124](https://leetcode.com/problems/longest-well-performing-interval) | [Longest Well-Performing Interval](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README_EN.md) | `Stack` | Medium | | -| [1125](https://leetcode.com/problems/smallest-sufficient-team) | [Smallest Sufficient Team](/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README_EN.md) | `Bit Manipulation`,`Dynamic Programming` | Hard | | -| [1126](https://leetcode.com/problems/active-businesses) | [Active Businesses](/solution/1100-1199/1126.Active%20Businesses/README_EN.md) | | Medium | 🔒 | -| [1127](https://leetcode.com/problems/user-purchase-platform) | [User Purchase Platform](/solution/1100-1199/1127.User%20Purchase%20Platform/README_EN.md) | | Hard | 🔒 | -| [1128](https://leetcode.com/problems/number-of-equivalent-domino-pairs) | [Number of Equivalent Domino Pairs](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README_EN.md) | `Array` | Easy | | -| [1129](https://leetcode.com/problems/shortest-path-with-alternating-colors) | [Shortest Path with Alternating Colors](/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README_EN.md) | `Breadth-first Search`,`Graph` | Medium | | -| [1130](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values) | [Minimum Cost Tree From Leaf Values](/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README_EN.md) | `Stack`,`Tree`,`Dynamic Programming` | Medium | | -| [1131](https://leetcode.com/problems/maximum-of-absolute-value-expression) | [Maximum of Absolute Value Expression](/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README_EN.md) | `Bit Manipulation`,`Math` | Medium | | -| [1132](https://leetcode.com/problems/reported-posts-ii) | [Reported Posts II](/solution/1100-1199/1132.Reported%20Posts%20II/README_EN.md) | | Medium | 🔒 | -| [1133](https://leetcode.com/problems/largest-unique-number) | [Largest Unique Number](/solution/1100-1199/1133.Largest%20Unique%20Number/README_EN.md) | `Array`,`Hash Table` | Easy | 🔒 | -| [1134](https://leetcode.com/problems/armstrong-number) | [Armstrong Number](/solution/1100-1199/1134.Armstrong%20Number/README_EN.md) | `Math` | Easy | 🔒 | -| [1135](https://leetcode.com/problems/connecting-cities-with-minimum-cost) | [Connecting Cities With Minimum Cost](/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README_EN.md) | `Union Find`,`Graph` | Medium | 🔒 | -| [1136](https://leetcode.com/problems/parallel-courses) | [Parallel Courses](/solution/1100-1199/1136.Parallel%20Courses/README_EN.md) | `Depth-first Search`,`Graph`,`Dynamic Programming` | Hard | 🔒 | -| [1137](https://leetcode.com/problems/n-th-tribonacci-number) | [N-th Tribonacci Number](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md) | `Recursion` | Easy | | -| [1138](https://leetcode.com/problems/alphabet-board-path) | [Alphabet Board Path](/solution/1100-1199/1138.Alphabet%20Board%20Path/README_EN.md) | `Hash Table`,`String` | Medium | | -| [1139](https://leetcode.com/problems/largest-1-bordered-square) | [Largest 1-Bordered Square](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README_EN.md) | `Dynamic Programming` | Medium | | -| [1140](https://leetcode.com/problems/stone-game-ii) | [Stone Game II](/solution/1100-1199/1140.Stone%20Game%20II/README_EN.md) | `Dynamic Programming` | Medium | | -| [1141](https://leetcode.com/problems/user-activity-for-the-past-30-days-i) | [User Activity for the Past 30 Days I](/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README_EN.md) | | Easy | 🔒 | -| [1142](https://leetcode.com/problems/user-activity-for-the-past-30-days-ii) | [User Activity for the Past 30 Days II](/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README_EN.md) | | Easy | 🔒 | -| [1143](https://leetcode.com/problems/longest-common-subsequence) | [Longest Common Subsequence](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md) | `Dynamic Programming` | Medium | | -| [1144](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag) | [Decrease Elements To Make Array Zigzag](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README_EN.md) | `Array` | Medium | | -| [1145](https://leetcode.com/problems/binary-tree-coloring-game) | [Binary Tree Coloring Game](/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1146](https://leetcode.com/problems/snapshot-array) | [Snapshot Array](/solution/1100-1199/1146.Snapshot%20Array/README_EN.md) | `Array` | Medium | | -| [1147](https://leetcode.com/problems/longest-chunked-palindrome-decomposition) | [Longest Chunked Palindrome Decomposition](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README_EN.md) | `Dynamic Programming` | Hard | | -| [1148](https://leetcode.com/problems/article-views-i) | [Article Views I](/solution/1100-1199/1148.Article%20Views%20I/README_EN.md) | | Easy | 🔒 | -| [1149](https://leetcode.com/problems/article-views-ii) | [Article Views II](/solution/1100-1199/1149.Article%20Views%20II/README_EN.md) | | Medium | 🔒 | -| [1150](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | [Check If a Number Is Majority Element in a Sorted Array](/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README_EN.md) | `Array`,`Binary Search` | Easy | 🔒 | -| [1151](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together) | [Minimum Swaps to Group All 1's Together](/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README_EN.md) | `Array`,`Sliding Window` | Medium | 🔒 | -| [1152](https://leetcode.com/problems/analyze-user-website-visit-pattern) | [Analyze User Website Visit Pattern](/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README_EN.md) | `Sort`,`Array`,`Hash Table` | Medium | 🔒 | -| [1153](https://leetcode.com/problems/string-transforms-into-another-string) | [String Transforms Into Another String](/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README_EN.md) | `Graph` | Hard | 🔒 | -| [1154](https://leetcode.com/problems/day-of-the-year) | [Day of the Year](/solution/1100-1199/1154.Day%20of%20the%20Year/README_EN.md) | `Math` | Easy | | -| [1155](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum) | [Number of Dice Rolls With Target Sum](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [1156](https://leetcode.com/problems/swap-for-longest-repeated-character-substring) | [Swap For Longest Repeated Character Substring](/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README_EN.md) | `String` | Medium | | -| [1157](https://leetcode.com/problems/online-majority-element-in-subarray) | [Online Majority Element In Subarray](/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README_EN.md) | `Segment Tree`,`Array`,`Binary Search` | Hard | | -| [1158](https://leetcode.com/problems/market-analysis-i) | [Market Analysis I](/solution/1100-1199/1158.Market%20Analysis%20I/README_EN.md) | | Medium | 🔒 | -| [1159](https://leetcode.com/problems/market-analysis-ii) | [Market Analysis II](/solution/1100-1199/1159.Market%20Analysis%20II/README_EN.md) | | Hard | 🔒 | -| [1160](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters) | [Find Words That Can Be Formed by Characters](/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [1161](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree) | [Maximum Level Sum of a Binary Tree](/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README_EN.md) | `Graph` | Medium | | -| [1162](https://leetcode.com/problems/as-far-from-land-as-possible) | [As Far from Land as Possible](/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README_EN.md) | `Breadth-first Search`,`Graph` | Medium | | -| [1163](https://leetcode.com/problems/last-substring-in-lexicographical-order) | [Last Substring in Lexicographical Order](/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README_EN.md) | `String` | Hard | | -| [1164](https://leetcode.com/problems/product-price-at-a-given-date) | [Product Price at a Given Date](/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README_EN.md) | | Medium | 🔒 | -| [1165](https://leetcode.com/problems/single-row-keyboard) | [Single-Row Keyboard](/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md) | `String` | Easy | 🔒 | -| [1166](https://leetcode.com/problems/design-file-system) | [Design File System](/solution/1100-1199/1166.Design%20File%20System/README_EN.md) | `Design`,`Hash Table` | Medium | 🔒 | -| [1167](https://leetcode.com/problems/minimum-cost-to-connect-sticks) | [Minimum Cost to Connect Sticks](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md) | `Greedy` | Medium | 🔒 | -| [1168](https://leetcode.com/problems/optimize-water-distribution-in-a-village) | [Optimize Water Distribution in a Village](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md) | `Union Find`,`Graph` | Hard | 🔒 | -| [1169](https://leetcode.com/problems/invalid-transactions) | [Invalid Transactions](/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md) | `Array`,`String` | Medium | | -| [1170](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character) | [Compare Strings by Frequency of the Smallest Character](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md) | `Array`,`String` | Easy | | -| [1171](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list) | [Remove Zero Sum Consecutive Nodes from Linked List](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md) | `Linked List` | Medium | | -| [1172](https://leetcode.com/problems/dinner-plate-stacks) | [Dinner Plate Stacks](/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README_EN.md) | `Design` | Hard | | -| [1173](https://leetcode.com/problems/immediate-food-delivery-i) | [Immediate Food Delivery I](/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README_EN.md) | | Easy | 🔒 | -| [1174](https://leetcode.com/problems/immediate-food-delivery-ii) | [Immediate Food Delivery II](/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README_EN.md) | | Medium | 🔒 | -| [1175](https://leetcode.com/problems/prime-arrangements) | [Prime Arrangements](/solution/1100-1199/1175.Prime%20Arrangements/README_EN.md) | `Math` | Easy | | -| [1176](https://leetcode.com/problems/diet-plan-performance) | [Diet Plan Performance](/solution/1100-1199/1176.Diet%20Plan%20Performance/README_EN.md) | `Array`,`Sliding Window` | Easy | 🔒 | -| [1177](https://leetcode.com/problems/can-make-palindrome-from-substring) | [Can Make Palindrome from Substring](/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README_EN.md) | `Array`,`String` | Medium | | -| [1178](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle) | [Number of Valid Words for Each Puzzle](/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README_EN.md) | `Bit Manipulation`,`Hash Table` | Hard | | -| [1179](https://leetcode.com/problems/reformat-department-table) | [Reformat Department Table](/solution/1100-1199/1179.Reformat%20Department%20Table/README_EN.md) | | Easy | | -| [1180](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter) | [Count Substrings with Only One Distinct Letter](/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README_EN.md) | `Math`,`String` | Easy | 🔒 | -| [1181](https://leetcode.com/problems/before-and-after-puzzle) | [Before and After Puzzle](/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README_EN.md) | `String` | Medium | 🔒 | -| [1182](https://leetcode.com/problems/shortest-distance-to-target-color) | [Shortest Distance to Target Color](/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README_EN.md) | `Binary Search` | Medium | 🔒 | -| [1183](https://leetcode.com/problems/maximum-number-of-ones) | [Maximum Number of Ones](/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README_EN.md) | `Sort`,`Math` | Hard | 🔒 | -| [1184](https://leetcode.com/problems/distance-between-bus-stops) | [Distance Between Bus Stops](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README_EN.md) | `Array` | Easy | | -| [1185](https://leetcode.com/problems/day-of-the-week) | [Day of the Week](/solution/1100-1199/1185.Day%20of%20the%20Week/README_EN.md) | `Array` | Easy | | -| [1186](https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion) | [Maximum Subarray Sum with One Deletion](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md) | `Dynamic Programming` | Medium | | -| [1187](https://leetcode.com/problems/make-array-strictly-increasing) | [Make Array Strictly Increasing](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md) | `Dynamic Programming` | Hard | | -| [1188](https://leetcode.com/problems/design-bounded-blocking-queue) | [Design Bounded Blocking Queue](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md) | | Medium | 🔒 | -| [1189](https://leetcode.com/problems/maximum-number-of-balloons) | [Maximum Number of Balloons](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md) | `Hash Table`,`String` | Easy | | -| [1190](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses) | [Reverse Substrings Between Each Pair of Parentheses](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md) | `Stack` | Medium | | -| [1191](https://leetcode.com/problems/k-concatenation-maximum-sum) | [K-Concatenation Maximum Sum](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [1192](https://leetcode.com/problems/critical-connections-in-a-network) | [Critical Connections in a Network](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md) | `Depth-first Search` | Hard | | -| [1193](https://leetcode.com/problems/monthly-transactions-i) | [Monthly Transactions I](/solution/1100-1199/1193.Monthly%20Transactions%20I/README_EN.md) | | Medium | 🔒 | -| [1194](https://leetcode.com/problems/tournament-winners) | [Tournament Winners](/solution/1100-1199/1194.Tournament%20Winners/README_EN.md) | | Hard | 🔒 | -| [1195](https://leetcode.com/problems/fizz-buzz-multithreaded) | [Fizz Buzz Multithreaded](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README_EN.md) | | Medium | | -| [1196](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket) | [How Many Apples Can You Put into the Basket](/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README_EN.md) | `Greedy` | Easy | 🔒 | -| [1197](https://leetcode.com/problems/minimum-knight-moves) | [Minimum Knight Moves](/solution/1100-1199/1197.Minimum%20Knight%20Moves/README_EN.md) | `Breadth-first Search` | Medium | 🔒 | -| [1198](https://leetcode.com/problems/find-smallest-common-element-in-all-rows) | [Find Smallest Common Element in All Rows](/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md) | `Hash Table`,`Binary Search` | Medium | 🔒 | -| [1199](https://leetcode.com/problems/minimum-time-to-build-blocks) | [Minimum Time to Build Blocks](/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README_EN.md) | `Math`,`Dynamic Programming` | Hard | 🔒 | -| [1200](https://leetcode.com/problems/minimum-absolute-difference) | [Minimum Absolute Difference](/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README_EN.md) | `Array` | Easy | | -| [1201](https://leetcode.com/problems/ugly-number-iii) | [Ugly Number III](/solution/1200-1299/1201.Ugly%20Number%20III/README_EN.md) | `Math`,`Binary Search` | Medium | | -| [1202](https://leetcode.com/problems/smallest-string-with-swaps) | [Smallest String With Swaps](/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README_EN.md) | `Union Find`,`Array` | Medium | | -| [1203](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies) | [Sort Items by Groups Respecting Dependencies](/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README_EN.md) | `Depth-first Search`,`Graph`,`Topological Sort` | Hard | | -| [1204](https://leetcode.com/problems/last-person-to-fit-in-the-elevator) | [Last Person to Fit in the Elevator](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README_EN.md) | | Medium | 🔒 | -| [1205](https://leetcode.com/problems/monthly-transactions-ii) | [Monthly Transactions II](/solution/1200-1299/1205.Monthly%20Transactions%20II/README_EN.md) | | Medium | 🔒 | -| [1206](https://leetcode.com/problems/design-skiplist) | [Design Skiplist](/solution/1200-1299/1206.Design%20Skiplist/README_EN.md) | `Design` | Hard | | -| [1207](https://leetcode.com/problems/unique-number-of-occurrences) | [Unique Number of Occurrences](/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README_EN.md) | `Hash Table` | Easy | | -| [1208](https://leetcode.com/problems/get-equal-substrings-within-budget) | [Get Equal Substrings Within Budget](/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README_EN.md) | `Array`,`Sliding Window` | Medium | | -| [1209](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii) | [Remove All Adjacent Duplicates in String II](/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README_EN.md) | `Stack` | Medium | | -| [1210](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations) | [Minimum Moves to Reach Target with Rotations](/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README_EN.md) | `Breadth-first Search` | Hard | | -| [1211](https://leetcode.com/problems/queries-quality-and-percentage) | [Queries Quality and Percentage](/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README_EN.md) | | Easy | 🔒 | -| [1212](https://leetcode.com/problems/team-scores-in-football-tournament) | [Team Scores in Football Tournament](/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README_EN.md) | | Medium | 🔒 | -| [1213](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | [Intersection of Three Sorted Arrays](/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README_EN.md) | `Hash Table`,`Two Pointers` | Easy | 🔒 | -| [1214](https://leetcode.com/problems/two-sum-bsts) | [Two Sum BSTs](/solution/1200-1299/1214.Two%20Sum%20BSTs/README_EN.md) | `Binary Search Tree` | Medium | 🔒 | -| [1215](https://leetcode.com/problems/stepping-numbers) | [Stepping Numbers](/solution/1200-1299/1215.Stepping%20Numbers/README_EN.md) | `Backtracking` | Medium | 🔒 | -| [1216](https://leetcode.com/problems/valid-palindrome-iii) | [Valid Palindrome III](/solution/1200-1299/1216.Valid%20Palindrome%20III/README_EN.md) | `String`,`Dynamic Programming` | Hard | 🔒 | -| [1217](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position) | [Minimum Cost to Move Chips to The Same Position](/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README_EN.md) | `Greedy`,`Array`,`Math` | Easy | | -| [1218](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference) | [Longest Arithmetic Subsequence of Given Difference](/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README_EN.md) | `Math`,`Dynamic Programming` | Medium | | -| [1219](https://leetcode.com/problems/path-with-maximum-gold) | [Path with Maximum Gold](/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README_EN.md) | `Backtracking` | Medium | | -| [1220](https://leetcode.com/problems/count-vowels-permutation) | [Count Vowels Permutation](/solution/1200-1299/1220.Count%20Vowels%20Permutation/README_EN.md) | `Dynamic Programming` | Hard | | -| [1221](https://leetcode.com/problems/split-a-string-in-balanced-strings) | [Split a String in Balanced Strings](/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README_EN.md) | `Greedy`,`String` | Easy | | -| [1222](https://leetcode.com/problems/queens-that-can-attack-the-king) | [Queens That Can Attack the King](/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README_EN.md) | `Array` | Medium | | -| [1223](https://leetcode.com/problems/dice-roll-simulation) | [Dice Roll Simulation](/solution/1200-1299/1223.Dice%20Roll%20Simulation/README_EN.md) | `Dynamic Programming` | Medium | | -| [1224](https://leetcode.com/problems/maximum-equal-frequency) | [Maximum Equal Frequency](/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README_EN.md) | `Hash Table` | Hard | | -| [1225](https://leetcode.com/problems/report-contiguous-dates) | [Report Contiguous Dates](/solution/1200-1299/1225.Report%20Contiguous%20Dates/README_EN.md) | | Hard | 🔒 | -| [1226](https://leetcode.com/problems/the-dining-philosophers) | [The Dining Philosophers](/solution/1200-1299/1226.The%20Dining%20Philosophers/README_EN.md) | | Medium | | -| [1227](https://leetcode.com/problems/airplane-seat-assignment-probability) | [Airplane Seat Assignment Probability](/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README_EN.md) | `Brainteaser`,`Math`,`Dynamic Programming` | Medium | | -| [1228](https://leetcode.com/problems/missing-number-in-arithmetic-progression) | [Missing Number In Arithmetic Progression](/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README_EN.md) | `Math` | Easy | 🔒 | -| [1229](https://leetcode.com/problems/meeting-scheduler) | [Meeting Scheduler](/solution/1200-1299/1229.Meeting%20Scheduler/README_EN.md) | `Line Sweep` | Medium | 🔒 | -| [1230](https://leetcode.com/problems/toss-strange-coins) | [Toss Strange Coins](/solution/1200-1299/1230.Toss%20Strange%20Coins/README_EN.md) | `Math`,`Dynamic Programming` | Medium | 🔒 | -| [1231](https://leetcode.com/problems/divide-chocolate) | [Divide Chocolate](/solution/1200-1299/1231.Divide%20Chocolate/README_EN.md) | `Greedy`,`Binary Search` | Hard | 🔒 | -| [1232](https://leetcode.com/problems/check-if-it-is-a-straight-line) | [Check If It Is a Straight Line](/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README_EN.md) | `Geometry`,`Array`,`Math` | Easy | | -| [1233](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem) | [Remove Sub-Folders from the Filesystem](/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README_EN.md) | `Array`,`String` | Medium | | -| [1234](https://leetcode.com/problems/replace-the-substring-for-balanced-string) | [Replace the Substring for Balanced String](/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README_EN.md) | `Two Pointers`,`String` | Medium | | -| [1235](https://leetcode.com/problems/maximum-profit-in-job-scheduling) | [Maximum Profit in Job Scheduling](/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README_EN.md) | `Sort`,`Binary Search`,`Dynamic Programming` | Hard | | -| [1236](https://leetcode.com/problems/web-crawler) | [Web Crawler](/solution/1200-1299/1236.Web%20Crawler/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [1237](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation) | [Find Positive Integer Solution for a Given Equation](/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README_EN.md) | `Math`,`Binary Search` | Easy | | -| [1238](https://leetcode.com/problems/circular-permutation-in-binary-representation) | [Circular Permutation in Binary Representation](/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README_EN.md) | `Math` | Medium | | -| [1239](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters) | [Maximum Length of a Concatenated String with Unique Characters](/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README_EN.md) | `Bit Manipulation`,`Backtracking` | Medium | | -| [1240](https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares) | [Tiling a Rectangle with the Fewest Squares](/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README_EN.md) | `Dynamic Programming`,`Backtracking` | Hard | | -| [1241](https://leetcode.com/problems/number-of-comments-per-post) | [Number of Comments per Post](/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README_EN.md) | | Easy | 🔒 | -| [1242](https://leetcode.com/problems/web-crawler-multithreaded) | [Web Crawler Multithreaded](/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [1243](https://leetcode.com/problems/array-transformation) | [Array Transformation](/solution/1200-1299/1243.Array%20Transformation/README_EN.md) | `Array` | Easy | 🔒 | -| [1244](https://leetcode.com/problems/design-a-leaderboard) | [Design A Leaderboard](/solution/1200-1299/1244.Design%20A%20Leaderboard/README_EN.md) | `Sort`,`Design`,`Hash Table` | Medium | 🔒 | -| [1245](https://leetcode.com/problems/tree-diameter) | [Tree Diameter](/solution/1200-1299/1245.Tree%20Diameter/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search` | Medium | 🔒 | -| [1246](https://leetcode.com/problems/palindrome-removal) | [Palindrome Removal](/solution/1200-1299/1246.Palindrome%20Removal/README_EN.md) | `Dynamic Programming` | Hard | 🔒 | -| [1247](https://leetcode.com/problems/minimum-swaps-to-make-strings-equal) | [Minimum Swaps to Make Strings Equal](/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_EN.md) | `Greedy`,`String` | Medium | | -| [1248](https://leetcode.com/problems/count-number-of-nice-subarrays) | [Count Number of Nice Subarrays](/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README_EN.md) | `Two Pointers` | Medium | | -| [1249](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | [Minimum Remove to Make Valid Parentheses](/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_EN.md) | `Stack`,`String` | Medium | | -| [1250](https://leetcode.com/problems/check-if-it-is-a-good-array) | [Check If It Is a Good Array](/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README_EN.md) | `Math` | Hard | | -| [1251](https://leetcode.com/problems/average-selling-price) | [Average Selling Price](/solution/1200-1299/1251.Average%20Selling%20Price/README_EN.md) | | Easy | 🔒 | -| [1252](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [Cells with Odd Values in a Matrix](/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_EN.md) | `Array` | Easy | | -| [1253](https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix) | [Reconstruct a 2-Row Binary Matrix](/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README_EN.md) | `Greedy`,`Math` | Medium | | -| [1254](https://leetcode.com/problems/number-of-closed-islands) | [Number of Closed Islands](/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README_EN.md) | `Depth-first Search` | Medium | | -| [1255](https://leetcode.com/problems/maximum-score-words-formed-by-letters) | [Maximum Score Words Formed by Letters](/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README_EN.md) | `Bit Manipulation` | Hard | | -| [1256](https://leetcode.com/problems/encode-number) | [Encode Number](/solution/1200-1299/1256.Encode%20Number/README_EN.md) | `Bit Manipulation`,`Math` | Medium | 🔒 | -| [1257](https://leetcode.com/problems/smallest-common-region) | [Smallest Common Region](/solution/1200-1299/1257.Smallest%20Common%20Region/README_EN.md) | `Tree` | Medium | 🔒 | -| [1258](https://leetcode.com/problems/synonymous-sentences) | [Synonymous Sentences](/solution/1200-1299/1258.Synonymous%20Sentences/README_EN.md) | `Backtracking` | Medium | 🔒 | -| [1259](https://leetcode.com/problems/handshakes-that-dont-cross) | [Handshakes That Don't Cross](/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README_EN.md) | `Math`,`Dynamic Programming` | Hard | 🔒 | -| [1260](https://leetcode.com/problems/shift-2d-grid) | [Shift 2D Grid](/solution/1200-1299/1260.Shift%202D%20Grid/README_EN.md) | `Array` | Easy | | -| [1261](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree) | [Find Elements in a Contaminated Binary Tree](/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README_EN.md) | `Tree`,`Hash Table` | Medium | | -| [1262](https://leetcode.com/problems/greatest-sum-divisible-by-three) | [Greatest Sum Divisible by Three](/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README_EN.md) | `Dynamic Programming` | Medium | | -| [1263](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location) | [Minimum Moves to Move a Box to Their Target Location](/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README_EN.md) | `Breadth-first Search` | Hard | | -| [1264](https://leetcode.com/problems/page-recommendations) | [Page Recommendations](/solution/1200-1299/1264.Page%20Recommendations/README_EN.md) | | Medium | 🔒 | -| [1265](https://leetcode.com/problems/print-immutable-linked-list-in-reverse) | [Print Immutable Linked List in Reverse](/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README_EN.md) | | Medium | 🔒 | -| [1266](https://leetcode.com/problems/minimum-time-visiting-all-points) | [Minimum Time Visiting All Points](/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README_EN.md) | `Geometry`,`Array` | Easy | | -| [1267](https://leetcode.com/problems/count-servers-that-communicate) | [Count Servers that Communicate](/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README_EN.md) | `Graph`,`Array` | Medium | | -| [1268](https://leetcode.com/problems/search-suggestions-system) | [Search Suggestions System](/solution/1200-1299/1268.Search%20Suggestions%20System/README_EN.md) | `String` | Medium | | -| [1269](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps) | [Number of Ways to Stay in the Same Place After Some Steps](/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README_EN.md) | `Dynamic Programming` | Hard | | -| [1270](https://leetcode.com/problems/all-people-report-to-the-given-manager) | [All People Report to the Given Manager](/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README_EN.md) | | Medium | 🔒 | -| [1271](https://leetcode.com/problems/hexspeak) | [Hexspeak](/solution/1200-1299/1271.Hexspeak/README_EN.md) | `Math`,`String` | Easy | 🔒 | -| [1272](https://leetcode.com/problems/remove-interval) | [Remove Interval](/solution/1200-1299/1272.Remove%20Interval/README_EN.md) | `Math`,`Line Sweep` | Medium | 🔒 | -| [1273](https://leetcode.com/problems/delete-tree-nodes) | [Delete Tree Nodes](/solution/1200-1299/1273.Delete%20Tree%20Nodes/README_EN.md) | `Depth-first Search`,`Dynamic Programming` | Medium | 🔒 | -| [1274](https://leetcode.com/problems/number-of-ships-in-a-rectangle) | [Number of Ships in a Rectangle](/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README_EN.md) | `Divide and Conquer` | Hard | 🔒 | -| [1275](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | [Find Winner on a Tic Tac Toe Game](/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README_EN.md) | `Array` | Easy | | -| [1276](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients) | [Number of Burgers with No Waste of Ingredients](/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README_EN.md) | `Greedy`,`Math` | Medium | | -| [1277](https://leetcode.com/problems/count-square-submatrices-with-all-ones) | [Count Square Submatrices with All Ones](/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README_EN.md) | `Array`,`Dynamic Programming` | Medium | | -| [1278](https://leetcode.com/problems/palindrome-partitioning-iii) | [Palindrome Partitioning III](/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README_EN.md) | `Dynamic Programming` | Hard | | -| [1279](https://leetcode.com/problems/traffic-light-controlled-intersection) | [Traffic Light Controlled Intersection](/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README_EN.md) | | Easy | 🔒 | -| [1280](https://leetcode.com/problems/students-and-examinations) | [Students and Examinations](/solution/1200-1299/1280.Students%20and%20Examinations/README_EN.md) | | Easy | 🔒 | -| [1281](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | [Subtract the Product and Sum of Digits of an Integer](/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README_EN.md) | `Math` | Easy | | -| [1282](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to) | [Group the People Given the Group Size They Belong To](/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README_EN.md) | `Greedy` | Medium | | -| [1283](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold) | [Find the Smallest Divisor Given a Threshold](/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README_EN.md) | `Binary Search` | Medium | | -| [1284](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | [Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README_EN.md) | `Breadth-first Search` | Hard | | -| [1285](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges) | [Find the Start and End Number of Continuous Ranges](/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README_EN.md) | | Medium | 🔒 | -| [1286](https://leetcode.com/problems/iterator-for-combination) | [Iterator for Combination](/solution/1200-1299/1286.Iterator%20for%20Combination/README_EN.md) | `Design`,`Backtracking` | Medium | | -| [1287](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array) | [Element Appearing More Than 25% In Sorted Array](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README_EN.md) | `Array` | Easy | | -| [1288](https://leetcode.com/problems/remove-covered-intervals) | [Remove Covered Intervals](/solution/1200-1299/1288.Remove%20Covered%20Intervals/README_EN.md) | `Line Sweep` | Medium | | -| [1289](https://leetcode.com/problems/minimum-falling-path-sum-ii) | [Minimum Falling Path Sum II](/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [1290](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer) | [Convert Binary Number in a Linked List to Integer](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README_EN.md) | `Bit Manipulation`,`Linked List` | Easy | | -| [1291](https://leetcode.com/problems/sequential-digits) | [Sequential Digits](/solution/1200-1299/1291.Sequential%20Digits/README_EN.md) | `Backtracking` | Medium | | -| [1292](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold) | [Maximum Side Length of a Square with Sum Less than or Equal to Threshold](/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1293](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination) | [Shortest Path in a Grid with Obstacles Elimination](/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README_EN.md) | `Breadth-first Search` | Hard | | -| [1294](https://leetcode.com/problems/weather-type-in-each-country) | [Weather Type in Each Country](/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README_EN.md) | | Easy | 🔒 | -| [1295](https://leetcode.com/problems/find-numbers-with-even-number-of-digits) | [Find Numbers with Even Number of Digits](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README_EN.md) | `Array` | Easy | | -| [1296](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers) | [Divide Array in Sets of K Consecutive Numbers](/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1297](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring) | [Maximum Number of Occurrences of a Substring](/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README_EN.md) | `Bit Manipulation`,`String` | Medium | | -| [1298](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes) | [Maximum Candies You Can Get from Boxes](/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README_EN.md) | `Breadth-first Search` | Hard | | -| [1299](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side) | [Replace Elements with Greatest Element on Right Side](/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README_EN.md) | `Array` | Easy | | -| [1300](https://leetcode.com/problems/sum-of-mutated-array-closest-to-target) | [Sum of Mutated Array Closest to Target](/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1301](https://leetcode.com/problems/number-of-paths-with-max-score) | [Number of Paths with Max Score](/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README_EN.md) | `Dynamic Programming` | Hard | | -| [1302](https://leetcode.com/problems/deepest-leaves-sum) | [Deepest Leaves Sum](/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1303](https://leetcode.com/problems/find-the-team-size) | [Find the Team Size](/solution/1300-1399/1303.Find%20the%20Team%20Size/README_EN.md) | | Easy | 🔒 | -| [1304](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero) | [Find N Unique Integers Sum up to Zero](/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README_EN.md) | `Array` | Easy | | -| [1305](https://leetcode.com/problems/all-elements-in-two-binary-search-trees) | [All Elements in Two Binary Search Trees](/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README_EN.md) | `Sort`,`Tree` | Medium | | -| [1306](https://leetcode.com/problems/jump-game-iii) | [Jump Game III](/solution/1300-1399/1306.Jump%20Game%20III/README_EN.md) | `Breadth-first Search`,`Graph` | Medium | | -| [1307](https://leetcode.com/problems/verbal-arithmetic-puzzle) | [Verbal Arithmetic Puzzle](/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README_EN.md) | `Math`,`Backtracking` | Hard | | -| [1308](https://leetcode.com/problems/running-total-for-different-genders) | [Running Total for Different Genders](/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README_EN.md) | | Medium | 🔒 | -| [1309](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | [Decrypt String from Alphabet to Integer Mapping](/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README_EN.md) | `String` | Easy | | -| [1310](https://leetcode.com/problems/xor-queries-of-a-subarray) | [XOR Queries of a Subarray](/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README_EN.md) | `Bit Manipulation` | Medium | | -| [1311](https://leetcode.com/problems/get-watched-videos-by-your-friends) | [Get Watched Videos by Your Friends](/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README_EN.md) | `Breadth-first Search`,`Hash Table`,`String` | Medium | | -| [1312](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome) | [Minimum Insertion Steps to Make a String Palindrome](/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README_EN.md) | `Dynamic Programming` | Hard | | -| [1313](https://leetcode.com/problems/decompress-run-length-encoded-list) | [Decompress Run-Length Encoded List](/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README_EN.md) | `Array` | Easy | | -| [1314](https://leetcode.com/problems/matrix-block-sum) | [Matrix Block Sum](/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [1315](https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent) | [Sum of Nodes with Even-Valued Grandparent](/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1316](https://leetcode.com/problems/distinct-echo-substrings) | [Distinct Echo Substrings](/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README_EN.md) | `String` | Hard | | -| [1317](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers) | [Convert Integer to the Sum of Two No-Zero Integers](/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README_EN.md) | `Math` | Easy | | -| [1318](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | [Minimum Flips to Make a OR b Equal to c](/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README_EN.md) | `Bit Manipulation` | Medium | | -| [1319](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | [Number of Operations to Make Network Connected](/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README_EN.md) | `Depth-first Search`,`Breadth-first Search`,`Union Find` | Medium | | -| [1320](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers) | [Minimum Distance to Type a Word Using Two Fingers](/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README_EN.md) | `Dynamic Programming` | Hard | | -| [1321](https://leetcode.com/problems/restaurant-growth) | [Restaurant Growth](/solution/1300-1399/1321.Restaurant%20Growth/README_EN.md) | | Medium | 🔒 | -| [1322](https://leetcode.com/problems/ads-performance) | [Ads Performance](/solution/1300-1399/1322.Ads%20Performance/README_EN.md) | | Easy | 🔒 | -| [1323](https://leetcode.com/problems/maximum-69-number) | [Maximum 69 Number](/solution/1300-1399/1323.Maximum%2069%20Number/README_EN.md) | `Math` | Easy | | -| [1324](https://leetcode.com/problems/print-words-vertically) | [Print Words Vertically](/solution/1300-1399/1324.Print%20Words%20Vertically/README_EN.md) | `String` | Medium | | -| [1325](https://leetcode.com/problems/delete-leaves-with-a-given-value) | [Delete Leaves With a Given Value](/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README_EN.md) | `Tree` | Medium | | -| [1326](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden) | [Minimum Number of Taps to Open to Water a Garden](/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README_EN.md) | `Greedy`,`Dynamic Programming` | Hard | | -| [1327](https://leetcode.com/problems/list-the-products-ordered-in-a-period) | [List the Products Ordered in a Period](/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README_EN.md) | | Easy | 🔒 | -| [1328](https://leetcode.com/problems/break-a-palindrome) | [Break a Palindrome](/solution/1300-1399/1328.Break%20a%20Palindrome/README_EN.md) | `String` | Medium | | -| [1329](https://leetcode.com/problems/sort-the-matrix-diagonally) | [Sort the Matrix Diagonally](/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README_EN.md) | `Sort`,`Array` | Medium | | -| [1330](https://leetcode.com/problems/reverse-subarray-to-maximize-array-value) | [Reverse Subarray To Maximize Array Value](/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README_EN.md) | `Array`,`Math` | Hard | | -| [1331](https://leetcode.com/problems/rank-transform-of-an-array) | [Rank Transform of an Array](/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README_EN.md) | `Array` | Easy | | -| [1332](https://leetcode.com/problems/remove-palindromic-subsequences) | [Remove Palindromic Subsequences](/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README_EN.md) | `String` | Easy | | -| [1333](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance) | [Filter Restaurants by Vegan-Friendly, Price and Distance](/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README_EN.md) | `Sort`,`Array` | Medium | | -| [1334](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance) | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README_EN.md) | `Graph` | Medium | | -| [1335](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule) | [Minimum Difficulty of a Job Schedule](/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README_EN.md) | `Dynamic Programming` | Hard | | -| [1336](https://leetcode.com/problems/number-of-transactions-per-visit) | [Number of Transactions per Visit](/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README_EN.md) | | Hard | 🔒 | -| [1337](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix) | [The K Weakest Rows in a Matrix](/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README_EN.md) | `Array`,`Binary Search` | Easy | | -| [1338](https://leetcode.com/problems/reduce-array-size-to-the-half) | [Reduce Array Size to The Half](/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1339](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree) | [Maximum Product of Splitted Binary Tree](/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README_EN.md) | `Tree`,`Dynamic Programming` | Medium | | -| [1340](https://leetcode.com/problems/jump-game-v) | [Jump Game V](/solution/1300-1399/1340.Jump%20Game%20V/README_EN.md) | `Dynamic Programming` | Hard | | -| [1341](https://leetcode.com/problems/movie-rating) | [Movie Rating](/solution/1300-1399/1341.Movie%20Rating/README_EN.md) | | Medium | 🔒 | -| [1342](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero) | [Number of Steps to Reduce a Number to Zero](/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README_EN.md) | `Bit Manipulation` | Easy | | -| [1343](https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold) | [Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold](/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README_EN.md) | `Array` | Medium | | -| [1344](https://leetcode.com/problems/angle-between-hands-of-a-clock) | [Angle Between Hands of a Clock](/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README_EN.md) | `Math` | Medium | | -| [1345](https://leetcode.com/problems/jump-game-iv) | [Jump Game IV](/solution/1300-1399/1345.Jump%20Game%20IV/README_EN.md) | `Breadth-first Search` | Hard | | -| [1346](https://leetcode.com/problems/check-if-n-and-its-double-exist) | [Check If N and Its Double Exist](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README_EN.md) | `Array` | Easy | | -| [1347](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram) | [Minimum Number of Steps to Make Two Strings Anagram](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README_EN.md) | `String` | Medium | | -| [1348](https://leetcode.com/problems/tweet-counts-per-frequency) | [Tweet Counts Per Frequency](/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README_EN.md) | `Design` | Medium | | -| [1349](https://leetcode.com/problems/maximum-students-taking-exam) | [Maximum Students Taking Exam](/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README_EN.md) | `Dynamic Programming` | Hard | | -| [1350](https://leetcode.com/problems/students-with-invalid-departments) | [Students With Invalid Departments](/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README_EN.md) | | Easy | 🔒 | -| [1351](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix) | [Count Negative Numbers in a Sorted Matrix](/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README_EN.md) | `Array`,`Binary Search` | Easy | | -| [1352](https://leetcode.com/problems/product-of-the-last-k-numbers) | [Product of the Last K Numbers](/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README_EN.md) | `Design`,`Array` | Medium | | -| [1353](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended) | [Maximum Number of Events That Can Be Attended](/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README_EN.md) | `Greedy`,`Sort`,`Segment Tree` | Medium | | -| [1354](https://leetcode.com/problems/construct-target-array-with-multiple-sums) | [Construct Target Array With Multiple Sums](/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README_EN.md) | `Greedy` | Hard | | -| [1355](https://leetcode.com/problems/activity-participants) | [Activity Participants](/solution/1300-1399/1355.Activity%20Participants/README_EN.md) | | Medium | 🔒 | -| [1356](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | [Sort Integers by The Number of 1 Bits](/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README_EN.md) | `Sort`,`Bit Manipulation` | Easy | | -| [1357](https://leetcode.com/problems/apply-discount-every-n-orders) | [Apply Discount Every n Orders](/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README_EN.md) | `Design` | Medium | | -| [1358](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters) | [Number of Substrings Containing All Three Characters](/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README_EN.md) | `String` | Medium | | -| [1359](https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options) | [Count All Valid Pickup and Delivery Options](/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [1360](https://leetcode.com/problems/number-of-days-between-two-dates) | [Number of Days Between Two Dates](/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README_EN.md) | | Easy | | -| [1361](https://leetcode.com/problems/validate-binary-tree-nodes) | [Validate Binary Tree Nodes](/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README_EN.md) | `Graph` | Medium | | -| [1362](https://leetcode.com/problems/closest-divisors) | [Closest Divisors](/solution/1300-1399/1362.Closest%20Divisors/README_EN.md) | `Math` | Medium | | -| [1363](https://leetcode.com/problems/largest-multiple-of-three) | [Largest Multiple of Three](/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [1364](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer) | [Number of Trusted Contacts of a Customer](/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README_EN.md) | | Medium | 🔒 | -| [1365](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | [How Many Numbers Are Smaller Than the Current Number](/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [1366](https://leetcode.com/problems/rank-teams-by-votes) | [Rank Teams by Votes](/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README_EN.md) | `Sort`,`Array` | Medium | | -| [1367](https://leetcode.com/problems/linked-list-in-binary-tree) | [Linked List in Binary Tree](/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README_EN.md) | `Tree`,`Linked List`,`Dynamic Programming` | Medium | | -| [1368](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | [Minimum Cost to Make at Least One Valid Path in a Grid](/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README_EN.md) | `Breadth-first Search` | Hard | | -| [1369](https://leetcode.com/problems/get-the-second-most-recent-activity) | [Get the Second Most Recent Activity](/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README_EN.md) | | Hard | 🔒 | -| [1370](https://leetcode.com/problems/increasing-decreasing-string) | [Increasing Decreasing String](/solution/1300-1399/1370.Increasing%20Decreasing%20String/README_EN.md) | `Sort`,`String` | Easy | | -| [1371](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts) | [Find the Longest Substring Containing Vowels in Even Counts](/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README_EN.md) | `String` | Medium | | -| [1372](https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree) | [Longest ZigZag Path in a Binary Tree](/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README_EN.md) | `Tree`,`Dynamic Programming` | Medium | | -| [1373](https://leetcode.com/problems/maximum-sum-bst-in-binary-tree) | [Maximum Sum BST in Binary Tree](/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README_EN.md) | `Binary Search Tree`,`Dynamic Programming` | Hard | | -| [1374](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts) | [Generate a String With Characters That Have Odd Counts](/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README_EN.md) | `String` | Easy | | -| [1375](https://leetcode.com/problems/bulb-switcher-iii) | [Bulb Switcher III](/solution/1300-1399/1375.Bulb%20Switcher%20III/README_EN.md) | `Array` | Medium | | -| [1376](https://leetcode.com/problems/time-needed-to-inform-all-employees) | [Time Needed to Inform All Employees](/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README_EN.md) | `Depth-first Search` | Medium | | -| [1377](https://leetcode.com/problems/frog-position-after-t-seconds) | [Frog Position After T Seconds](/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README_EN.md) | `Depth-first Search` | Hard | | -| [1378](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier) | [Replace Employee ID With The Unique Identifier](/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README_EN.md) | | Easy | 🔒 | -| [1379](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README_EN.md) | `Tree` | Medium | | -| [1380](https://leetcode.com/problems/lucky-numbers-in-a-matrix) | [Lucky Numbers in a Matrix](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md) | `Array` | Easy | | -| [1381](https://leetcode.com/problems/design-a-stack-with-increment-operation) | [Design a Stack With Increment Operation](/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README_EN.md) | `Stack`,`Design` | Medium | | -| [1382](https://leetcode.com/problems/balance-a-binary-search-tree) | [Balance a Binary Search Tree](/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README_EN.md) | `Binary Search Tree` | Medium | | -| [1383](https://leetcode.com/problems/maximum-performance-of-a-team) | [Maximum Performance of a Team](/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README_EN.md) | `Greedy`,`Sort` | Hard | | -| [1384](https://leetcode.com/problems/total-sales-amount-by-year) | [Total Sales Amount by Year](/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README_EN.md) | | Hard | 🔒 | -| [1385](https://leetcode.com/problems/find-the-distance-value-between-two-arrays) | [Find the Distance Value Between Two Arrays](/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README_EN.md) | `Array` | Easy | | -| [1386](https://leetcode.com/problems/cinema-seat-allocation) | [Cinema Seat Allocation](/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1387](https://leetcode.com/problems/sort-integers-by-the-power-value) | [Sort Integers by The Power Value](/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README_EN.md) | `Sort`,`Graph` | Medium | | -| [1388](https://leetcode.com/problems/pizza-with-3n-slices) | [Pizza With 3n Slices](/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README_EN.md) | `Dynamic Programming` | Hard | | -| [1389](https://leetcode.com/problems/create-target-array-in-the-given-order) | [Create Target Array in the Given Order](/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README_EN.md) | `Array` | Easy | | -| [1390](https://leetcode.com/problems/four-divisors) | [Four Divisors](/solution/1300-1399/1390.Four%20Divisors/README_EN.md) | `Math` | Medium | | -| [1391](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid) | [Check if There is a Valid Path in a Grid](/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [1392](https://leetcode.com/problems/longest-happy-prefix) | [Longest Happy Prefix](/solution/1300-1399/1392.Longest%20Happy%20Prefix/README_EN.md) | `String` | Hard | | -| [1393](https://leetcode.com/problems/capital-gainloss) | [Capital Gain/Loss](/solution/1300-1399/1393.Capital%20Gain/Loss/README_EN.md) | | Medium | 🔒 | -| [1394](https://leetcode.com/problems/find-lucky-integer-in-an-array) | [Find Lucky Integer in an Array](/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README_EN.md) | `Array` | Easy | | -| [1395](https://leetcode.com/problems/count-number-of-teams) | [Count Number of Teams](/solution/1300-1399/1395.Count%20Number%20of%20Teams/README_EN.md) | `Array` | Medium | | -| [1396](https://leetcode.com/problems/design-underground-system) | [Design Underground System](/solution/1300-1399/1396.Design%20Underground%20System/README_EN.md) | `Design` | Medium | | -| [1397](https://leetcode.com/problems/find-all-good-strings) | [Find All Good Strings](/solution/1300-1399/1397.Find%20All%20Good%20Strings/README_EN.md) | `Dynamic Programming` | Hard | | -| [1398](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c) | [Customers Who Bought Products A and B but Not C](/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README_EN.md) | | Medium | 🔒 | -| [1399](https://leetcode.com/problems/count-largest-group) | [Count Largest Group](/solution/1300-1399/1399.Count%20Largest%20Group/README_EN.md) | `Array` | Easy | | -| [1400](https://leetcode.com/problems/construct-k-palindrome-strings) | [Construct K Palindrome Strings](/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README_EN.md) | `Greedy` | Medium | | -| [1401](https://leetcode.com/problems/circle-and-rectangle-overlapping) | [Circle and Rectangle Overlapping](/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README_EN.md) | `Geometry` | Medium | | -| [1402](https://leetcode.com/problems/reducing-dishes) | [Reducing Dishes](/solution/1400-1499/1402.Reducing%20Dishes/README_EN.md) | `Dynamic Programming` | Hard | | -| [1403](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [Minimum Subsequence in Non-Increasing Order](/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README_EN.md) | `Greedy`,`Sort` | Easy | | -| [1404](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one) | [Number of Steps to Reduce a Number in Binary Representation to One](/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README_EN.md) | `Bit Manipulation`,`String` | Medium | | -| [1405](https://leetcode.com/problems/longest-happy-string) | [Longest Happy String](/solution/1400-1499/1405.Longest%20Happy%20String/README_EN.md) | `Greedy`,`Dynamic Programming` | Medium | | -| [1406](https://leetcode.com/problems/stone-game-iii) | [Stone Game III](/solution/1400-1499/1406.Stone%20Game%20III/README_EN.md) | `Dynamic Programming` | Hard | | -| [1407](https://leetcode.com/problems/top-travellers) | [Top Travellers](/solution/1400-1499/1407.Top%20Travellers/README_EN.md) | | Easy | 🔒 | -| [1408](https://leetcode.com/problems/string-matching-in-an-array) | [String Matching in an Array](/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README_EN.md) | `String` | Easy | | -| [1409](https://leetcode.com/problems/queries-on-a-permutation-with-key) | [Queries on a Permutation With Key](/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README_EN.md) | `Array` | Medium | | -| [1410](https://leetcode.com/problems/html-entity-parser) | [HTML Entity Parser](/solution/1400-1499/1410.HTML%20Entity%20Parser/README_EN.md) | `Stack`,`String` | Medium | | -| [1411](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid) | [Number of Ways to Paint N × 3 Grid](/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README_EN.md) | | | | -| [1412](https://leetcode.com/problems/find-the-quiet-students-in-all-exams) | [Find the Quiet Students in All Exams](/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README_EN.md) | | Hard | 🔒 | -| [1413](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [Minimum Value to Get Positive Step by Step Sum](/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README_EN.md) | `Array` | Easy | | -| [1414](https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k) | [Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README_EN.md) | `Greedy`,`Array` | Medium | | -| [1415](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n) | [The k-th Lexicographical String of All Happy Strings of Length n](/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README_EN.md) | `Backtracking` | Medium | | -| [1416](https://leetcode.com/problems/restore-the-array) | [Restore The Array](/solution/1400-1499/1416.Restore%20The%20Array/README_EN.md) | `Dynamic Programming` | Hard | | -| [1417](https://leetcode.com/problems/reformat-the-string) | [Reformat The String](/solution/1400-1499/1417.Reformat%20The%20String/README_EN.md) | `String` | Easy | | -| [1418](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant) | [Display Table of Food Orders in a Restaurant](/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README_EN.md) | `Hash Table` | Medium | | -| [1419](https://leetcode.com/problems/minimum-number-of-frogs-croaking) | [Minimum Number of Frogs Croaking](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md) | `String` | Medium | | -| [1420](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons) | [Build Array Where You Can Find The Maximum Exactly K Comparisons](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md) | `Dynamic Programming` | Hard | | -| [1421](https://leetcode.com/problems/npv-queries) | [NPV Queries](/solution/1400-1499/1421.NPV%20Queries/README_EN.md) | | Medium | 🔒 | -| [1422](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | [Maximum Score After Splitting a String](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md) | `String` | Easy | | -| [1423](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards) | [Maximum Points You Can Obtain from Cards](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md) | `Array`,`Dynamic Programming`,`Sliding Window` | Medium | | -| [1424](https://leetcode.com/problems/diagonal-traverse-ii) | [Diagonal Traverse II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md) | `Sort`,`Array` | Medium | | -| [1425](https://leetcode.com/problems/constrained-subsequence-sum) | [Constrained Subsequence Sum](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md) | `Dynamic Programming` | Hard | | -| [1426](https://leetcode.com/problems/counting-elements) | [Counting Elements](/solution/1400-1499/1426.Counting%20Elements/README_EN.md) | `Array` | Easy | 🔒 | -| [1427](https://leetcode.com/problems/perform-string-shifts) | [Perform String Shifts](/solution/1400-1499/1427.Perform%20String%20Shifts/README_EN.md) | `Array`,`Math` | Easy | 🔒 | -| [1428](https://leetcode.com/problems/leftmost-column-with-at-least-a-one) | [Leftmost Column with at Least a One](/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README_EN.md) | `Array` | Medium | 🔒 | -| [1429](https://leetcode.com/problems/first-unique-number) | [First Unique Number](/solution/1400-1499/1429.First%20Unique%20Number/README_EN.md) | `Design`,`Hash Table` | Medium | 🔒 | -| [1430](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) | [Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README_EN.md) | `Tree` | Medium | 🔒 | -| [1431](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies) | [Kids With the Greatest Number of Candies](/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README_EN.md) | `Array` | Easy | | -| [1432](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer) | [Max Difference You Can Get From Changing an Integer](/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README_EN.md) | `String` | Medium | | -| [1433](https://leetcode.com/problems/check-if-a-string-can-break-another-string) | [Check If a String Can Break Another String](/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README_EN.md) | `Greedy`,`String` | Medium | | -| [1434](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other) | [Number of Ways to Wear Different Hats to Each Other](/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README_EN.md) | `Bit Manipulation`,`Dynamic Programming` | Hard | | -| [1435](https://leetcode.com/problems/create-a-session-bar-chart) | [Create a Session Bar Chart](/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README_EN.md) | | Easy | 🔒 | -| [1436](https://leetcode.com/problems/destination-city) | [Destination City](/solution/1400-1499/1436.Destination%20City/README_EN.md) | `String` | Easy | | -| [1437](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [Check If All 1's Are at Least Length K Places Away](/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README_EN.md) | `Array` | Medium | | -| [1438](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README_EN.md) | `Array`,`Sliding Window` | Medium | | -| [1439](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows) | [Find the Kth Smallest Sum of a Matrix With Sorted Rows](/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README_EN.md) | `Heap` | Hard | | -| [1440](https://leetcode.com/problems/evaluate-boolean-expression) | [Evaluate Boolean Expression](/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README_EN.md) | | Medium | 🔒 | -| [1441](https://leetcode.com/problems/build-an-array-with-stack-operations) | [Build an Array With Stack Operations](/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README_EN.md) | `Stack` | Easy | | -| [1442](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor) | [Count Triplets That Can Form Two Arrays of Equal XOR](/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README_EN.md) | `Bit Manipulation`,`Array`,`Math` | Medium | | -| [1443](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree) | [Minimum Time to Collect All Apples in a Tree](/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1444](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza) | [Number of Ways of Cutting a Pizza](/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README_EN.md) | `Dynamic Programming` | Hard | | -| [1445](https://leetcode.com/problems/apples-oranges) | [Apples & Oranges](/solution/1400-1499/1445.Apples%20%26%20Oranges/README_EN.md) | | Medium | 🔒 | -| [1446](https://leetcode.com/problems/consecutive-characters) | [Consecutive Characters](/solution/1400-1499/1446.Consecutive%20Characters/README_EN.md) | `String` | Easy | | -| [1447](https://leetcode.com/problems/simplified-fractions) | [Simplified Fractions](/solution/1400-1499/1447.Simplified%20Fractions/README_EN.md) | `Math` | Medium | | -| [1448](https://leetcode.com/problems/count-good-nodes-in-binary-tree) | [Count Good Nodes in Binary Tree](/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1449](https://leetcode.com/problems/form-largest-integer-with-digits-that-add-up-to-target) | [Form Largest Integer With Digits That Add up to Target](/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [1450](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | [Number of Students Doing Homework at a Given Time](/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README_EN.md) | `Array` | Easy | | -| [1451](https://leetcode.com/problems/rearrange-words-in-a-sentence) | [Rearrange Words in a Sentence](/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README_EN.md) | `Sort`,`String` | Medium | | -| [1452](https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list) | [People Whose List of Favorite Companies Is Not a Subset of Another List](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md) | `Sort`,`String` | Medium | | -| [1453](https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard) | [Maximum Number of Darts Inside of a Circular Dartboard](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md) | `Geometry` | Hard | | -| [1454](https://leetcode.com/problems/active-users) | [Active Users](/solution/1400-1499/1454.Active%20Users/README_EN.md) | | Medium | 🔒 | -| [1455](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | [Check If a Word Occurs As a Prefix of Any Word in a Sentence](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md) | `String` | Easy | | -| [1456](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | [Maximum Number of Vowels in a Substring of Given Length](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md) | `String`,`Sliding Window` | Medium | | -| [1457](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree) | [Pseudo-Palindromic Paths in a Binary Tree](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md) | `Bit Manipulation`,`Tree`,`Depth-first Search` | Medium | | -| [1458](https://leetcode.com/problems/max-dot-product-of-two-subsequences) | [Max Dot Product of Two Subsequences](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md) | `Dynamic Programming` | Hard | | -| [1459](https://leetcode.com/problems/rectangles-area) | [Rectangles Area](/solution/1400-1499/1459.Rectangles%20Area/README_EN.md) | | Medium | 🔒 | -| [1460](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | [Make Two Arrays Equal by Reversing Sub-arrays](/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README_EN.md) | `Array` | Easy | | -| [1461](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k) | [Check If a String Contains All Binary Codes of Size K](/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README_EN.md) | `Bit Manipulation`,`String` | Medium | | -| [1462](https://leetcode.com/problems/course-schedule-iv) | [Course Schedule IV](/solution/1400-1499/1462.Course%20Schedule%20IV/README_EN.md) | `Graph` | Medium | | -| [1463](https://leetcode.com/problems/cherry-pickup-ii) | [Cherry Pickup II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md) | `Dynamic Programming` | Hard | | -| [1464](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array) | [Maximum Product of Two Elements in an Array](/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README_EN.md) | `Array` | Easy | | -| [1465](https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts) | [Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README_EN.md) | `Array` | Medium | | -| [1466](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | [Reorder Routes to Make All Paths Lead to the City Zero](/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1467](https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls) | [Probability of a Two Boxes Having The Same Number of Distinct Balls](/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README_EN.md) | `Math`,`Backtracking` | Hard | | -| [1468](https://leetcode.com/problems/calculate-salaries) | [Calculate Salaries](/solution/1400-1499/1468.Calculate%20Salaries/README_EN.md) | | Medium | 🔒 | -| [1469](https://leetcode.com/problems/find-all-the-lonely-nodes) | [Find All The Lonely Nodes](/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README_EN.md) | `Tree`,`Depth-first Search` | Easy | 🔒 | -| [1470](https://leetcode.com/problems/shuffle-the-array) | [Shuffle the Array](/solution/1400-1499/1470.Shuffle%20the%20Array/README_EN.md) | `Array` | Easy | | -| [1471](https://leetcode.com/problems/the-k-strongest-values-in-an-array) | [The k Strongest Values in an Array](/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README_EN.md) | `Sort`,`Array` | Medium | | -| [1472](https://leetcode.com/problems/design-browser-history) | [Design Browser History](/solution/1400-1499/1472.Design%20Browser%20History/README_EN.md) | `Design` | Medium | | -| [1473](https://leetcode.com/problems/paint-house-iii) | [Paint House III](/solution/1400-1499/1473.Paint%20House%20III/README_EN.md) | `Dynamic Programming` | Hard | | -| [1474](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | [Delete N Nodes After M Nodes of a Linked List](/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README_EN.md) | `Linked List` | Easy | 🔒 | -| [1475](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop) | [Final Prices With a Special Discount in a Shop](/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README_EN.md) | `Array` | Easy | | -| [1476](https://leetcode.com/problems/subrectangle-queries) | [Subrectangle Queries](/solution/1400-1499/1476.Subrectangle%20Queries/README_EN.md) | `Array` | Medium | | -| [1477](https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum) | [Find Two Non-overlapping Sub-arrays Each With Target Sum](/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README_EN.md) | `Dynamic Programming` | Medium | | -| [1478](https://leetcode.com/problems/allocate-mailboxes) | [Allocate Mailboxes](/solution/1400-1499/1478.Allocate%20Mailboxes/README_EN.md) | `Math`,`Dynamic Programming` | Hard | | -| [1479](https://leetcode.com/problems/sales-by-day-of-the-week) | [Sales by Day of the Week](/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README_EN.md) | | Hard | 🔒 | -| [1480](https://leetcode.com/problems/running-sum-of-1d-array) | [Running Sum of 1d Array](/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README_EN.md) | `Array` | Easy | | -| [1481](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals) | [Least Number of Unique Integers after K Removals](/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README_EN.md) | `Sort`,`Array` | Medium | | -| [1482](https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets) | [Minimum Number of Days to Make m Bouquets](/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1483](https://leetcode.com/problems/kth-ancestor-of-a-tree-node) | [Kth Ancestor of a Tree Node](/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README_EN.md) | `Dynamic Programming` | Hard | | -| [1484](https://leetcode.com/problems/group-sold-products-by-the-date) | [Group Sold Products By The Date](/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README_EN.md) | | Easy | 🔒 | -| [1485](https://leetcode.com/problems/clone-binary-tree-with-random-pointer) | [Clone Binary Tree With Random Pointer](/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README_EN.md) | `Tree`,`Depth-first Search` | Medium | 🔒 | -| [1486](https://leetcode.com/problems/xor-operation-in-an-array) | [XOR Operation in an Array](/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README_EN.md) | `Bit Manipulation`,`Array` | Easy | | -| [1487](https://leetcode.com/problems/making-file-names-unique) | [Making File Names Unique](/solution/1400-1499/1487.Making%20File%20Names%20Unique/README_EN.md) | `Hash Table`,`String` | Medium | | -| [1488](https://leetcode.com/problems/avoid-flood-in-the-city) | [Avoid Flood in The City](/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README_EN.md) | `Array`,`Hash Table` | Medium | | -| [1489](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree) | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README_EN.md) | `Depth-first Search`,`Union Find` | Hard | | -| [1490](https://leetcode.com/problems/clone-n-ary-tree) | [Clone N-ary Tree](/solution/1400-1499/1490.Clone%20N-ary%20Tree/README_EN.md) | `Tree`,`Depth-first Search`,`Breadth-first Search`,`Hash Table` | Medium | 🔒 | -| [1491](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) | [Average Salary Excluding the Minimum and Maximum Salary](/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README_EN.md) | `Sort`,`Array` | Easy | | -| [1492](https://leetcode.com/problems/the-kth-factor-of-n) | [The kth Factor of n](/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README_EN.md) | `Math` | Medium | | -| [1493](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element) | [Longest Subarray of 1's After Deleting One Element](/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README_EN.md) | `Array` | Medium | | -| [1494](https://leetcode.com/problems/parallel-courses-ii) | [Parallel Courses II](/solution/1400-1499/1494.Parallel%20Courses%20II/README_EN.md) | `Graph` | Hard | | -| [1495](https://leetcode.com/problems/friendly-movies-streamed-last-month) | [Friendly Movies Streamed Last Month](/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README_EN.md) | | Easy | 🔒 | -| [1496](https://leetcode.com/problems/path-crossing) | [Path Crossing](/solution/1400-1499/1496.Path%20Crossing/README_EN.md) | `String` | Easy | | -| [1497](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k) | [Check If Array Pairs Are Divisible by k](/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README_EN.md) | `Greedy`,`Array`,`Math` | Medium | | -| [1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition) | [Number of Subsequences That Satisfy the Given Sum Condition](/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README_EN.md) | `Sort`,`Sliding Window` | Medium | | -| [1499](https://leetcode.com/problems/max-value-of-equation) | [Max Value of Equation](/solution/1400-1499/1499.Max%20Value%20of%20Equation/README_EN.md) | `Array`,`Sliding Window` | Hard | | -| [1500](https://leetcode.com/problems/design-a-file-sharing-system) | [Design a File Sharing System](/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README_EN.md) | `Design`,`Array` | Medium | 🔒 | -| [1501](https://leetcode.com/problems/countries-you-can-safely-invest-in) | [Countries You Can Safely Invest In](/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README_EN.md) | | Medium | 🔒 | -| [1502](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence) | [Can Make Arithmetic Progression From Sequence](/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README_EN.md) | `Sort`,`Array` | Easy | | -| [1503](https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank) | [Last Moment Before All Ants Fall Out of a Plank](/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README_EN.md) | `Brainteaser`,`Array` | Medium | | -| [1504](https://leetcode.com/problems/count-submatrices-with-all-ones) | [Count Submatrices With All Ones](/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README_EN.md) | `Dynamic Programming` | Medium | | -| [1505](https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits) | [Minimum Possible Integer After at Most K Adjacent Swaps On Digits](/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README_EN.md) | `Greedy` | Hard | | -| [1506](https://leetcode.com/problems/find-root-of-n-ary-tree) | [Find Root of N-Ary Tree](/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README_EN.md) | | Medium | 🔒 | -| [1507](https://leetcode.com/problems/reformat-date) | [Reformat Date](/solution/1500-1599/1507.Reformat%20Date/README_EN.md) | `String` | Easy | | -| [1508](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums) | [Range Sum of Sorted Subarray Sums](/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README_EN.md) | `Sort`,`Array` | Medium | | -| [1509](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves) | [Minimum Difference Between Largest and Smallest Value in Three Moves](/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README_EN.md) | `Sort`,`Array` | Medium | | -| [1510](https://leetcode.com/problems/stone-game-iv) | [Stone Game IV](/solution/1500-1599/1510.Stone%20Game%20IV/README_EN.md) | `Dynamic Programming` | Hard | | -| [1511](https://leetcode.com/problems/customer-order-frequency) | [Customer Order Frequency](/solution/1500-1599/1511.Customer%20Order%20Frequency/README_EN.md) | | Easy | 🔒 | -| [1512](https://leetcode.com/problems/number-of-good-pairs) | [Number of Good Pairs](/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README_EN.md) | `Array`,`Hash Table`,`Math` | Easy | | -| [1513](https://leetcode.com/problems/number-of-substrings-with-only-1s) | [Number of Substrings With Only 1s](/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README_EN.md) | `Math`,`String` | Medium | | -| [1514](https://leetcode.com/problems/path-with-maximum-probability) | [Path with Maximum Probability](/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README_EN.md) | `Graph` | Medium | | -| [1515](https://leetcode.com/problems/best-position-for-a-service-centre) | [Best Position for a Service Centre](/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README_EN.md) | `Geometry` | Hard | | -| [1516](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree) | [Move Sub-Tree of N-Ary Tree](/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README_EN.md) | `Tree` | Hard | 🔒 | -| [1517](https://leetcode.com/problems/find-users-with-valid-e-mails) | [Find Users With Valid E-Mails](/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README_EN.md) | | Easy | 🔒 | -| [1518](https://leetcode.com/problems/water-bottles) | [Water Bottles](/solution/1500-1599/1518.Water%20Bottles/README_EN.md) | `Greedy` | Easy | | -| [1519](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label) | [Number of Nodes in the Sub-Tree With the Same Label](/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README_EN.md) | `Depth-first Search`,`Breadth-first Search` | Medium | | -| [1520](https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings) | [Maximum Number of Non-Overlapping Substrings](/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README_EN.md) | `Greedy` | Hard | | -| [1521](https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target) | [Find a Value of a Mysterious Function Closest to Target](/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README_EN.md) | `Bit Manipulation`,`Segment Tree`,`Binary Search` | Hard | | -| [1522](https://leetcode.com/problems/diameter-of-n-ary-tree) | [Diameter of N-Ary Tree](/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README_EN.md) | | Medium | 🔒 | -| [1523](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range) | [Count Odd Numbers in an Interval Range](/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README_EN.md) | `Math` | Easy | | -| [1524](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum) | [Number of Sub-arrays With Odd Sum](/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README_EN.md) | `Array`,`Math` | Medium | | -| [1525](https://leetcode.com/problems/number-of-good-ways-to-split-a-string) | [Number of Good Ways to Split a String](/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README_EN.md) | `Bit Manipulation`,`String` | Medium | | -| [1526](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array) | [Minimum Number of Increments on Subarrays to Form a Target Array](/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README_EN.md) | `Segment Tree` | Hard | | -| [1527](https://leetcode.com/problems/patients-with-a-condition) | [Patients With a Condition](/solution/1500-1599/1527.Patients%20With%20a%20Condition/README_EN.md) | | Easy | 🔒 | -| [1528](https://leetcode.com/problems/shuffle-string) | [Shuffle String](/solution/1500-1599/1528.Shuffle%20String/README_EN.md) | `Sort` | Easy | | -| [1529](https://leetcode.com/problems/bulb-switcher-iv) | [Bulb Switcher IV](/solution/1500-1599/1529.Bulb%20Switcher%20IV/README_EN.md) | `String` | Medium | | -| [1530](https://leetcode.com/problems/number-of-good-leaf-nodes-pairs) | [Number of Good Leaf Nodes Pairs](/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README_EN.md) | `Tree`,`Depth-first Search` | Medium | | -| [1531](https://leetcode.com/problems/string-compression-ii) | [String Compression II](/solution/1500-1599/1531.String%20Compression%20II/README_EN.md) | `String`,`Dynamic Programming` | Hard | | -| [1532](https://leetcode.com/problems/the-most-recent-three-orders) | [The Most Recent Three Orders](/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README_EN.md) | | Medium | 🔒 | -| [1533](https://leetcode.com/problems/find-the-index-of-the-large-integer) | [Find the Index of the Large Integer](/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README_EN.md) | `Binary Search` | Medium | 🔒 | -| [1534](https://leetcode.com/problems/count-good-triplets) | [Count Good Triplets](/solution/1500-1599/1534.Count%20Good%20Triplets/README_EN.md) | `Array` | Easy | | -| [1535](https://leetcode.com/problems/find-the-winner-of-an-array-game) | [Find the Winner of an Array Game](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README_EN.md) | `Array` | Medium | | -| [1536](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid) | [Minimum Swaps to Arrange a Binary Grid](/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README_EN.md) | `Greedy` | Medium | | -| [1537](https://leetcode.com/problems/get-the-maximum-score) | [Get the Maximum Score](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README_EN.md) | `Dynamic Programming` | Hard | | -| [1538](https://leetcode.com/problems/guess-the-majority-in-a-hidden-array) | [Guess the Majority in a Hidden Array](/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README_EN.md) | | Medium | 🔒 | -| [1539](https://leetcode.com/problems/kth-missing-positive-number) | [Kth Missing Positive Number](/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README_EN.md) | `Array`,`Hash Table` | Easy | | -| [1540](https://leetcode.com/problems/can-convert-string-in-k-moves) | [Can Convert String in K Moves](/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README_EN.md) | `Greedy`,`String` | Medium | | -| [1541](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string) | [Minimum Insertions to Balance a Parentheses String](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README_EN.md) | `Stack`,`String` | Medium | | -| [1542](https://leetcode.com/problems/find-longest-awesome-substring) | [Find Longest Awesome Substring](/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README_EN.md) | `Bit Manipulation`,`String` | Hard | | -| [1543](https://leetcode.com/problems/fix-product-name-format) | [Fix Product Name Format](/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README_EN.md) | | Easy | 🔒 | -| [1544](https://leetcode.com/problems/make-the-string-great) | [Make The String Great](/solution/1500-1599/1544.Make%20The%20String%20Great/README_EN.md) | `Stack`,`String` | Easy | | -| [1545](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string) | [Find Kth Bit in Nth Binary String](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README_EN.md) | `String` | Medium | | -| [1546](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target) | [Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README_EN.md) | `Dynamic Programming` | Medium | | -| [1547](https://leetcode.com/problems/minimum-cost-to-cut-a-stick) | [Minimum Cost to Cut a Stick](/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README_EN.md) | `Dynamic Programming` | Hard | | -| [1548](https://leetcode.com/problems/the-most-similar-path-in-a-graph) | [The Most Similar Path in a Graph](/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README_EN.md) | `Graph`,`Dynamic Programming` | Hard | 🔒 | -| [1549](https://leetcode.com/problems/the-most-recent-orders-for-each-product) | [The Most Recent Orders for Each Product](/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README_EN.md) | | Medium | 🔒 | -| [1550](https://leetcode.com/problems/three-consecutive-odds) | [Three Consecutive Odds](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README_EN.md) | `Array` | Easy | | -| [1551](https://leetcode.com/problems/minimum-operations-to-make-array-equal) | [Minimum Operations to Make Array Equal](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README_EN.md) | `Math` | Medium | | -| [1552](https://leetcode.com/problems/magnetic-force-between-two-balls) | [Magnetic Force Between Two Balls](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1553](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges) | [Minimum Number of Days to Eat N Oranges](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README_EN.md) | `Dynamic Programming` | Hard | | -| [1554](https://leetcode.com/problems/strings-differ-by-one-character) | [Strings Differ by One Character](/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README_EN.md) | | Medium | 🔒 | -| [1555](https://leetcode.com/problems/bank-account-summary) | [Bank Account Summary](/solution/1500-1599/1555.Bank%20Account%20Summary/README_EN.md) | | Medium | 🔒 | -| [1556](https://leetcode.com/problems/thousand-separator) | [Thousand Separator](/solution/1500-1599/1556.Thousand%20Separator/README_EN.md) | `String` | Easy | | -| [1557](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes) | [Minimum Number of Vertices to Reach All Nodes](/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README_EN.md) | `Graph` | Medium | | -| [1558](https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array) | [Minimum Numbers of Function Calls to Make Target Array](/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README_EN.md) | `Greedy` | Medium | | -| [1559](https://leetcode.com/problems/detect-cycles-in-2d-grid) | [Detect Cycles in 2D Grid](/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README_EN.md) | `Depth-first Search` | Hard | | -| [1560](https://leetcode.com/problems/most-visited-sector-in-a-circular-track) | [Most Visited Sector in a Circular Track](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README_EN.md) | `Array` | Easy | | -| [1561](https://leetcode.com/problems/maximum-number-of-coins-you-can-get) | [Maximum Number of Coins You Can Get](/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README_EN.md) | `Sort` | Medium | | -| [1562](https://leetcode.com/problems/find-latest-group-of-size-m) | [Find Latest Group of Size M](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README_EN.md) | `Binary Search` | Medium | | -| [1563](https://leetcode.com/problems/stone-game-v) | [Stone Game V](/solution/1500-1599/1563.Stone%20Game%20V/README_EN.md) | `Dynamic Programming` | Hard | | -| [1564](https://leetcode.com/problems/put-boxes-into-the-warehouse-i) | [Put Boxes Into the Warehouse I](/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README_EN.md) | `Greedy` | Medium | 🔒 | -| [1565](https://leetcode.com/problems/unique-orders-and-customers-per-month) | [Unique Orders and Customers Per Month](/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README_EN.md) | | Easy | 🔒 | -| [1566](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times) | [Detect Pattern of Length M Repeated K or More Times](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README_EN.md) | `Array` | Easy | | -| [1567](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product) | [Maximum Length of Subarray With Positive Product](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md) | `Greedy` | Medium | | -| [1568](https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island) | [Minimum Number of Days to Disconnect Island](/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README_EN.md) | `Greedy` | Hard | | -| [1569](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst) | [Number of Ways to Reorder Array to Get Same BST](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README_EN.md) | `Dynamic Programming` | Hard | | -| [1570](https://leetcode.com/problems/dot-product-of-two-sparse-vectors) | [Dot Product of Two Sparse Vectors](/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README_EN.md) | `Array`,`Hash Table`,`Two Pointers` | Medium | 🔒 | -| [1571](https://leetcode.com/problems/warehouse-manager) | [Warehouse Manager](/solution/1500-1599/1571.Warehouse%20Manager/README_EN.md) | | Easy | 🔒 | -| [1572](https://leetcode.com/problems/matrix-diagonal-sum) | [Matrix Diagonal Sum](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README_EN.md) | `Array` | Easy | | -| [1573](https://leetcode.com/problems/number-of-ways-to-split-a-string) | [Number of Ways to Split a String](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README_EN.md) | `String` | Medium | | -| [1574](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted) | [Shortest Subarray to be Removed to Make Array Sorted](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1575](https://leetcode.com/problems/count-all-possible-routes) | [Count All Possible Routes](/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README_EN.md) | `Dynamic Programming` | Hard | | -| [1576](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters) | [Replace All ?'s to Avoid Consecutive Repeating Characters](/solution/1500-1599/1576.Replace%20All%20S%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md) | `String` | Easy | | -| [1577](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers) | [Number of Ways Where Square of Number Is Equal to Product of Two Numbers](/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README_EN.md) | `Hash Table`,`Math` | Medium | | -| [1578](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters) | [Minimum Deletion Cost to Avoid Repeating Letters](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README_EN.md) | `Greedy` | Medium | | -| [1579](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable) | [Remove Max Number of Edges to Keep Graph Fully Traversable](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README_EN.md) | `Union Find` | Hard | | -| [1580](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii) | [Put Boxes Into the Warehouse II](/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README_EN.md) | `Greedy` | Medium | 🔒 | -| [1581](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions) | [Customer Who Visited but Did Not Make Any Transactions](/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README_EN.md) | | Easy | 🔒 | -| [1582](https://leetcode.com/problems/special-positions-in-a-binary-matrix) | [Special Positions in a Binary Matrix](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README_EN.md) | `Array` | Easy | | -| [1583](https://leetcode.com/problems/count-unhappy-friends) | [Count Unhappy Friends](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README_EN.md) | `Array` | Medium | | -| [1584](https://leetcode.com/problems/min-cost-to-connect-all-points) | [Min Cost to Connect All Points](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README_EN.md) | `Union Find` | Medium | | -| [1585](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations) | [Check If String Is Transformable With Substring Sort Operations](/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README_EN.md) | `Greedy`,`String` | Hard | | -| [1586](https://leetcode.com/problems/binary-search-tree-iterator-ii) | [Binary Search Tree Iterator II](/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README_EN.md) | `Design` | Medium | 🔒 | -| [1587](https://leetcode.com/problems/bank-account-summary-ii) | [Bank Account Summary II](/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README_EN.md) | | Easy | 🔒 | -| [1588](https://leetcode.com/problems/sum-of-all-odd-length-subarrays) | [Sum of All Odd Length Subarrays](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README_EN.md) | `Array` | Easy | | -| [1589](https://leetcode.com/problems/maximum-sum-obtained-of-any-permutation) | [Maximum Sum Obtained of Any Permutation](/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README_EN.md) | `Greedy` | Medium | | -| [1590](https://leetcode.com/problems/make-sum-divisible-by-p) | [Make Sum Divisible by P](/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README_EN.md) | `Array`,`Binary Search` | Medium | | -| [1591](https://leetcode.com/problems/strange-printer-ii) | [Strange Printer II](/solution/1500-1599/1591.Strange%20Printer%20II/README_EN.md) | `Greedy` | Hard | | -| [1592](https://leetcode.com/problems/rearrange-spaces-between-words) | [Rearrange Spaces Between Words](/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README_EN.md) | `String` | Easy | | -| [1593](https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings) | [Split a String Into the Max Number of Unique Substrings](/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README_EN.md) | `Backtracking` | Medium | | -| [1594](https://leetcode.com/problems/maximum-non-negative-product-in-a-matrix) | [Maximum Non Negative Product in a Matrix](/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README_EN.md) | `Greedy`,`Dynamic Programming` | Medium | | -| [1595](https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points) | [Minimum Cost to Connect Two Groups of Points](/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README_EN.md) | `Graph`,`Dynamic Programming` | Hard | | -| [1596](https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer) | [The Most Frequently Ordered Products for Each Customer](/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README_EN.md) | | Medium | 🔒 | -| [1597](https://leetcode.com/problems/build-binary-expression-tree-from-infix-expression) | [Build Binary Expression Tree From Infix Expression](/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README_EN.md) | `Tree`,`String` | Medium | 🔒 | - -## Copyright - -[@Doocs](https://github.com/doocs) diff --git a/notes/src/main/java/org/example/Main.java b/notes/src/main/java/org/example/Main.java new file mode 100644 index 00000000..4a8a6efb --- /dev/null +++ b/notes/src/main/java/org/example/Main.java @@ -0,0 +1,17 @@ +package org.example; + +//TIP 要运行代码,请按 或 +// 点击装订区域中的 图标。 +public class Main { + public static void main(String[] args) { + //TIP 当文本光标位于高亮显示的文本处时按 + // 查看 IntelliJ IDEA 建议如何修正。 + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP 按 开始调试代码。我们已经设置了一个 断点 + // 但您始终可以通过按 添加更多断点。 + System.out.println("i = " + i); + } + } +} From dad10366b6789ce8b867886a83a39c10920295a0 Mon Sep 17 00:00:00 2001 From: hjh <544789628@qq.com> Date: Wed, 16 Jul 2025 00:58:42 +0800 Subject: [PATCH 3/3] init --- notes/src/main/java/org/example/Main.java | 6 ++++++ .../src/main/java/org/example}/datastructure/ListNode.java | 2 +- .../main/java/org/example}/datastructure/TreeLinkNode.java | 2 +- .../src/main/java/org/example}/datastructure/TreeNode.java | 2 +- .../main/java/org/example}/tools/listnode/ArrayUtils.java | 2 +- .../java/org/example}/tools/listnode/ListNodeUtils.java | 5 +++-- .../java/org/example}/tools/listnode/TreeNodeUtils.java | 5 +++-- 7 files changed, 16 insertions(+), 8 deletions(-) rename {src/main/java => notes/src/main/java/org/example}/datastructure/ListNode.java (90%) rename {src/main/java => notes/src/main/java/org/example}/datastructure/TreeLinkNode.java (96%) rename {src/main/java => notes/src/main/java/org/example}/datastructure/TreeNode.java (92%) rename {src/main/java => notes/src/main/java/org/example}/tools/listnode/ArrayUtils.java (88%) rename {src/main/java => notes/src/main/java/org/example}/tools/listnode/ListNodeUtils.java (96%) rename {src/main/java => notes/src/main/java/org/example}/tools/listnode/TreeNodeUtils.java (94%) diff --git a/notes/src/main/java/org/example/Main.java b/notes/src/main/java/org/example/Main.java index 4a8a6efb..dafe2ee2 100644 --- a/notes/src/main/java/org/example/Main.java +++ b/notes/src/main/java/org/example/Main.java @@ -1,5 +1,8 @@ package org.example; +import org.example.datastructure.TreeNode; +import org.example.tools.listnode.TreeNodeUtils; + //TIP 要运行代码,请按 或 // 点击装订区域中的 图标。 public class Main { @@ -13,5 +16,8 @@ public static void main(String[] args) { // 但您始终可以通过按 添加更多断点。 System.out.println("i = " + i); } + + TreeNode treeNode = TreeNodeUtils.buildTree(); + TreeNodeUtils.printTree(treeNode); } } diff --git a/src/main/java/datastructure/ListNode.java b/notes/src/main/java/org/example/datastructure/ListNode.java similarity index 90% rename from src/main/java/datastructure/ListNode.java rename to notes/src/main/java/org/example/datastructure/ListNode.java index 68fbada8..a4ee698f 100644 --- a/src/main/java/datastructure/ListNode.java +++ b/notes/src/main/java/org/example/datastructure/ListNode.java @@ -1,4 +1,4 @@ -package datastructure; +package org.example.datastructure; import lombok.Data; diff --git a/src/main/java/datastructure/TreeLinkNode.java b/notes/src/main/java/org/example/datastructure/TreeLinkNode.java similarity index 96% rename from src/main/java/datastructure/TreeLinkNode.java rename to notes/src/main/java/org/example/datastructure/TreeLinkNode.java index 20266f05..3eaab032 100644 --- a/src/main/java/datastructure/TreeLinkNode.java +++ b/notes/src/main/java/org/example/datastructure/TreeLinkNode.java @@ -1,4 +1,4 @@ -package datastructure; +package org.example.datastructure; import lombok.Data; diff --git a/src/main/java/datastructure/TreeNode.java b/notes/src/main/java/org/example/datastructure/TreeNode.java similarity index 92% rename from src/main/java/datastructure/TreeNode.java rename to notes/src/main/java/org/example/datastructure/TreeNode.java index 3306d01c..0690845b 100644 --- a/src/main/java/datastructure/TreeNode.java +++ b/notes/src/main/java/org/example/datastructure/TreeNode.java @@ -1,4 +1,4 @@ -package datastructure; +package org.example.datastructure; import lombok.Data; diff --git a/src/main/java/tools/listnode/ArrayUtils.java b/notes/src/main/java/org/example/tools/listnode/ArrayUtils.java similarity index 88% rename from src/main/java/tools/listnode/ArrayUtils.java rename to notes/src/main/java/org/example/tools/listnode/ArrayUtils.java index faceedcb..87f64ba5 100644 --- a/src/main/java/tools/listnode/ArrayUtils.java +++ b/notes/src/main/java/org/example/tools/listnode/ArrayUtils.java @@ -1,4 +1,4 @@ -package tools.listnode; +package org.example.tools.listnode; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/tools/listnode/ListNodeUtils.java b/notes/src/main/java/org/example/tools/listnode/ListNodeUtils.java similarity index 96% rename from src/main/java/tools/listnode/ListNodeUtils.java rename to notes/src/main/java/org/example/tools/listnode/ListNodeUtils.java index c73a3533..f561e196 100644 --- a/src/main/java/tools/listnode/ListNodeUtils.java +++ b/notes/src/main/java/org/example/tools/listnode/ListNodeUtils.java @@ -1,6 +1,7 @@ -package tools.listnode; +package org.example.tools.listnode; -import datastructure.ListNode; + +import org.example.datastructure.ListNode; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/tools/listnode/TreeNodeUtils.java b/notes/src/main/java/org/example/tools/listnode/TreeNodeUtils.java similarity index 94% rename from src/main/java/tools/listnode/TreeNodeUtils.java rename to notes/src/main/java/org/example/tools/listnode/TreeNodeUtils.java index 7889c49b..de892f2e 100644 --- a/src/main/java/tools/listnode/TreeNodeUtils.java +++ b/notes/src/main/java/org/example/tools/listnode/TreeNodeUtils.java @@ -1,6 +1,7 @@ -package tools.listnode; +package org.example.tools.listnode; -import datastructure.TreeNode; + +import org.example.datastructure.TreeNode; public class TreeNodeUtils { public static void printTree(TreeNode root) {