├── .github └── workflows │ └── jekyll-gh-pages.yml ├── 0295-find-median-from-data-stream ├── 0295-find-median-from-data-stream.cpp ├── 0295-find-median-from-data-stream.java ├── 0295-find-median-from-data-stream.py ├── NOTES.md └── README.md ├── 0345-reverse-vowels-of-a-string ├── 0345-reverse-vowels-of-a-string.cpp ├── 0345-reverse-vowels-of-a-string.java ├── 0345-reverse-vowels-of-a-string.py ├── NOTES.md └── README.md ├── 0380-insert-delete-getrandom-o1 ├── 0380-insert-delete-getrandom-o1.java ├── 0380-insert-delete-getrandom-o1.py ├── NOTES.md └── README.md ├── 0947-most-stones-removed-with-same-row-or-column ├── 0947-most-stones-removed-with-same-row-or-column.cpp ├── 0947-most-stones-removed-with-same-row-or-column.java └── README.md ├── 0976-largest-perimeter-triangle ├── 0976-largest-perimeter-triangle.cpp ├── 0976-largest-perimeter-triangle.py └── NOTES.md ├── 0989-add-to-array-form-of-integer ├── solution.cpp ├── solution.java └── solution.py ├── 100-same-tree ├── 100-same-tree.c ├── 100-same-tree.cpp ├── 100-same-tree.java ├── 100-same-tree.py ├── NOTES.md └── README.md ├── 101-symmetric-tree ├── 101-symmetric-tree.cpp ├── 101-symmetric-tree.java ├── 101-symmetric-tree.py ├── NOTES.md └── README.md ├── 1011-capacity-to-shift-packages ├── solution.cpp ├── solution.java └── solution.py ├── 102-binary-tree-level-order-traversal ├── 102-binary-tree-level-order-traversal.cpp ├── 102-binary-tree-level-order-traversal.java ├── 102-binary-tree-level-order-traversal.js ├── 102-binary-tree-level-order-traversal.py ├── NOTES.md └── README.md ├── 1027-Longest Arithmetic Subsequence ├── solution.cpp ├── solution.java └── solution.py ├── 103-binary-tree-zigzag-level-order-traversal ├── 0103-binary-tree-zigzag-level-order-traversal.java ├── 0103-binary-tree-zigzag-level-order-traversal.py ├── NOTES.md └── README.md ├── 1035-uncrossed lines ├── solution.cpp ├── solution.java └── solution.py ├── 104-maximum-depth-of-binary-tree ├── 104-maximum-depth-of-binary-tree.cpp ├── 104-maximum-depth-of-binary-tree.java ├── 104-maximum-depth-of-binary-tree.py └── NOTES.md ├── 1046-Last Stone Weight ├── solution.cpp ├── solution.java └── solution.py ├── 1047-remove-all-adjacent-duplicates-in-string ├── 1047-remove-all-adjacent-duplicates-in-string.cpp ├── 1047-remove-all-adjacent-duplicates-in-string.java ├── NOTES.md └── README.md ├── 1048-longest-string-chain ├── 1048-longest-string-chain.cpp ├── 1048-longest-string-chain.java ├── 1048-longest-string-chain.js ├── 1048-longest-string-chain.py ├── NOTES.md └── README.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.js ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.py ├── NOTES.md └── README.md ├── 106-Construct Binary Tree from Inorder and Postorder Traversal ├── solution.cpp ├── solution.java └── solution.py ├── 1074-number-of-submatrices-that-sum-to-target ├── 1074-number-of-submatrices-that-sum-to-target.cpp ├── 1074-number-of-submatrices-that-sum-to-target.java ├── 1074-number-of-submatrices-that-sum-to-target.js ├── 1074-number-of-submatrices-that-sum-to-target.py ├── NOTES.md └── README.md ├── 108-convert-sorted-array-to-binary-search-tree ├── 108-convert-sorted-array-to-binary-search-tree.cpp ├── 108-convert-sorted-array-to-binary-search-tree.java ├── 108-convert-sorted-array-to-binary-search-tree.py ├── NOTES.md └── README.md ├── 109-convert-sorted-list-to-binary-search-tree ├── solution.cpp ├── solution.java └── solution.py ├── 1091-Shortest-Path-in-Binary-Matrix ├── solution.cpp ├── solution.java └── solution.py ├── 110-balanced-binary-tree ├── 110-balanced-binary-tree.cpp ├── 110-balanced-binary-tree.java ├── 110-balanced-binary-tree.py ├── NOTES.md └── README.md ├── 111-minimum-depth-of-binary-tree ├── 111-minimum-depth-of-binary-tree.cpp ├── 111-minimum-depth-of-binary-tree.java ├── NOTES.md ├── README.md └── solution.py ├── 112-path-sum ├── 112-path-sum.cpp ├── 112-path-sum.java ├── NOTES.md └── README.md ├── 1125-Smallest Sufficient Team ├── solution.cpp ├── solution.java └── solution.py ├── 113-path-sum-ii ├── 113-path-sum-ii.cpp ├── 113-path-sum-ii.java └── README.md ├── 114-flatten-binary-tree-to-linked-list ├── 114-flatten-binary-tree-to-linked-list.cpp ├── 114-flatten-binary-tree-to-linked-list.java ├── 114-flatten-binary-tree-to-linked-list.js ├── 114-flatten-binary-tree-to-linked-list.py ├── NOTES.md └── README.md ├── 1140-Stone Game II ├── solution.cpp ├── solution.java └── solution.py ├── 1146-Snapshot-Array ├── solution.cpp ├── solution.java └── solution.py ├── 115-distinct-subsequences ├── 115-distinct-subsequences.java ├── NOTES.md └── README.md ├── 1155-number-of-dice-rolls-with-target-sum ├── 1155-number-of-dice-rolls-with-target-sum.cpp ├── 1155-number-of-dice-rolls-with-target-sum.java └── NOTES.md ├── 1161-Maximum-Level-Sum-of-a-Binary-Tree ├── solution.cpp ├── solution.java └── solution.py ├── 118-pascals-triangle ├── 118-pascals-triangle.cpp ├── 118-pascals-triangle.java ├── 118-pascals-triangle.js ├── 118-pascals-triangle.py ├── NOTES.md └── README.md ├── 1187-Make-Array-Strictly-Increasing ├── solution.cpp ├── solution.java └── solution.py ├── 12-integer-to-roman ├── 0012-integer-to-roman.cpp ├── 0012-integer-to-roman.java ├── NOTES.md └── README.md ├── 120-triangle ├── 120-triangle.cpp ├── 120-triangle.java ├── 120-triangle.js ├── 120-triangle.py ├── NOTES.md └── README.md ├── 1200-minimum-absolute-difference ├── 1200-minimum-absolute-difference.cpp ├── 1200-minimum-absolute-difference.java ├── 1200-minimum-absolute-difference.py ├── NOTES.md └── README.md ├── 1207-unique-number-of-occurrences ├── 1207-unique-number-of-occurrences.cpp ├── NOTES.md └── README.md ├── 121-best-time-to-buy-and-sell-stocks ├── solution.cpp ├── solution.java └── solution.py ├── 1218-Longest Arithmetic Subsequence of Given Difference ├── solution.cpp ├── solution.java └── solution.py ├── 1220-count-vowels-permutation ├── 1220-count-vowels-permutation.py └── README.md ├── 123-best-time-to-buy-and-sell-stock-iii ├── 123-best-time-to-buy-and-sell-stock-iii.java ├── NOTES.md └── README.md ├── 1232-check-if-is-a-straight-line ├── solution.cpp ├── solution.java └── solution.py ├── 1235-maximum-profit-in-job-scheduling ├── 1235-maximum-profit-in-job-scheduling.cpp ├── 1235-maximum-profit-in-job-scheduling.java ├── 1235-maximum-profit-in-job-scheduling.py ├── NOTES.md └── README.md ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters.java └── README.md ├── 124-binary-tree-maximum-path-sum ├── 124-binary-tree-maximum-path-sum.java ├── NOTES.md └── README.md ├── 126-word-ladder-ii ├── 126-word-ladder-ii.cpp ├── 126-word-ladder-ii.java ├── NOTES.md └── README.md ├── 1268-search-suggestions-system ├── 1268-search-suggestions-system.cpp ├── 1268-search-suggestions-system.java ├── 1268-search-suggestions-system.js ├── 1268-search-suggestions-system.py ├── NOTES.md └── README.md ├── 127-word-ladder ├── 127-word-ladder.cpp ├── 127-word-ladder.java ├── 127-word-ladder.py └── README.md ├── 128-longest-consecutive-sequence ├── 128-longest-consecutive-sequence.cpp ├── 128-longest-consecutive-sequence.java ├── 128-longest-consecutive-sequence.py ├── NOTES.md └── README.md ├── 129-sum-root-to-leaf-number ├── solution.cpp ├── solution.java └── solution.py ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.cpp ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.java ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.py └── NOTES.md ├── 13-roman-to-integer ├── 13-roman-to-integer.cpp ├── 13-roman-to-integer.java ├── 13-roman-to-integer.js ├── 13-roman-to-integer.py ├── NOTES.md └── README.md ├── 1312-Minimum Insertion Steps to Make a String Palindrome ├── solution.cpp ├── solution.java └── solution.py ├── 1318-Minimum-Flips to-Make-a-OR-b-Equal-to-c ├── solution.cpp ├── solution.java └── solution.py ├── 132-palindrome-partitioning-ii ├── 132-palindrome-partitioning-ii.cpp ├── 132-palindrome-partitioning-ii.java ├── NOTES.md └── README.md ├── 1323-maximum-69-number ├── 1323-maximum-69-number.cpp ├── 1323-maximum-69-number.java ├── 1323-maximum-69-number.py ├── NOTES.md └── README.md ├── 1326-Minimum number of taps to open to water a garden ├── solution.cpp ├── solution.java └── solution.py ├── 1328-break-a-palindrome ├── 1328-break-a-palindrome.java ├── 1328-break-a-palindrome.py ├── NOTES.md └── README.md ├── 1329-sort-the-matrix-diagonally ├── 1329-sort-the-matrix-diagonally.cpp ├── 1329-sort-the-matrix-diagonally.java ├── 1329-sort-the-matrix-diagonally.py └── NOTES.md ├── 1335-minimum-difficulty-of-a-job-schedule ├── 1335-minimum-difficulty-of-a-job-schedule.cpp ├── 1335-minimum-difficulty-of-a-job-schedule.java ├── 1335-minimum-difficulty-of-a-job-schedule.py ├── NOTES.md └── README.md ├── 1338-reduce-array-size-to-the-half ├── 1338-reduce-array-size-to-the-half.cpp ├── 1338-reduce-array-size-to-the-half.java ├── 1338-reduce-array-size-to-the-half.py ├── NOTES.md └── README.md ├── 1345-jump-game-iv ├── solution.java └── solution.py ├── 135-candy ├── 135-candy.cpp ├── 135-candy.java ├── 135-candy.py ├── NOTES.md └── README.md ├── 1351-Count-Negative-Numbers-in-a-Sorted-Matrix ├── solution.cpp ├── solution.java └── solution.py ├── 1354-construct-target-array-with-multiple-sums ├── 1354-construct-target-array-with-multiple-sums.cpp ├── 1354-construct-target-array-with-multiple-sums.java ├── 1354-construct-target-array-with-multiple-sums.js ├── 1354-construct-target-array-with-multiple-sums.py ├── NOTES.md └── README.md ├── 137-single-number-ii ├── solution.cpp ├── solution.java └── solution.py ├── 1376-time-needed-to-inform-all-employees ├── solution.cpp ├── solution.java └── solution.py ├── 138-copy-list-with-random-pointer ├── solution.cpp ├── solution.java └── solution.py ├── 1383-maximum-performance-of-a-team ├── 1383-maximum-performance-of-a-team.cpp ├── 1383-maximum-performance-of-a-team.java ├── 1383-maximum-performance-of-a-team.js ├── 1383-maximum-performance-of-a-team.py ├── NOTES.md └── README.md ├── 139-word-break ├── solution.cpp ├── solution.java └── solution.py ├── 1396-design-underground-system ├── solution.cpp ├── solution.java └── solution.py ├── 140-word-break-ii ├── 140-word-break-ii.cpp ├── 140-word-break-ii.py ├── NOTES.md └── README.md ├── 1402-reducing-dishes ├── solution.cpp └── solution.java ├── 1406-stone-game-iii ├── solution.cpp ├── solution.java └── solution.py ├── 1416-Restore The Array ├── solution.cpp └── solution.py ├── 142-linked-list-cycle-ii ├── solution.cpp ├── solution.java └── solution.py ├── 1422-maximum-score-after-splitting-a-string ├── solution.c ├── solution.cpp ├── solution.py └── solution.rs ├── 1423-maximum-points-you-can-obtain-from-cards ├── 1423-maximum-points-you-can-obtain-from-cards.cpp ├── 1423-maximum-points-you-can-obtain-from-cards.java ├── NOTES.md └── README.md ├── 1431-Kids-With-the Greatest Number of Candies ├── solution.java └── solution.py ├── 1448-count-good-nodes-in-binary-tree ├── 1448-count-good-nodes-in-binary-tree.java └── README.md ├── 1456-Maximum Number of Vowels in a Substring of Given Length ├── solution.cpp ├── solution.java └── solution.py ├── 1457-pseudo-palindromic-paths-in-a-binary-tree ├── 1457-pseudo-palindromic-paths-in-a-binary-tree.cpp ├── 1457-pseudo-palindromic-paths-in-a-binary-tree.java ├── 1457-pseudo-palindromic-paths-in-a-binary-tree.py ├── NOTES.md └── README.md ├── 146-LRU Cache ├── solution.cpp ├── solution.java └── solution.py ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.java ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.js ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.py ├── NOTES.md └── README.md ├── 1473-paint-house-iii ├── 1473-paint-house-iii.cpp ├── 1473-paint-house-iii.java ├── NOTES.md └── README.md ├── 1488-avoid-flood-in-the-city ├── 1488-avoid-flood-in-the-city.cpp ├── 1488-avoid-flood-in-the-city.py ├── NOTES.md └── README.md ├── 1489-Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree ├── solution.cpp ├── solution.java └── solution.py ├── 149-max-points-on-a-line ├── 149-max-points-on-a-line.cpp ├── 149-max-points-on-a-line.py └── README.md ├── 1491-Average Salary Excluding the Minimum and Maximum Salary ├── solution.cpp ├── solution.java └── solution.py ├── 1493-Longest Subarray of 1’s After Deleting One Element ├── solution.cpp ├── solution.java └── solution.py ├── 1498-Number of Subsequences That Satisfy the Given Sum Condition ├── solution.cpp ├── solution.java └── solution.py ├── 1502-can-make-arithmetic-progression-from-a-sequence ├── solution.cpp ├── solution.java └── solution.py ├── 151-reverse-words-in-a-string ├── 151-reverse-words-in-a-string.java ├── 151-reverse-words-in-a-string.py └── README.md ├── 151-rreverse-words-in-a-string ├── 0151-reverse-words-in-a-string.cpp ├── 0151-reverse-words-in-a-string.java ├── NOTES.md └── README.md ├── 1514-Path with Maximum Probability ├── solution.cpp ├── solution.java └── solution.py ├── 1531-string-compression-ii ├── 1531-string-compression-ii.cpp ├── 1531-string-compression-ii.py └── NOTES.md ├── 1539-kth-missing-positive-number ├── solution.cpp └── solution.java ├── 154-find-minimum-in-rotated-sorted-array-ii ├── 154-find-minimum-in-rotated-sorted-array-ii.cpp ├── 154-find-minimum-in-rotated-sorted-array-ii.java ├── 154-find-minimum-in-rotated-sorted-array-ii.py ├── NOTES.md └── README.md ├── 1544-make-the-string-great ├── 1544-make-the-string-great.cpp ├── NOTES.md └── README.md ├── 1547-minimum-cost-to-cut-a-stick ├── solution.cpp ├── solution.java └── solution.py ├── 1557-Minimum-Number-of-Vertices-to-Reach-all-Nodes ├── solution.cpp ├── solution.java └── solution.py ├── 1569-Number of Ways to Reorder Array to Get Same BST ├── solution.cpp ├── solution.java └── solution.py ├── 1572-matrix diagonal sum ├── solution.cpp ├── solution.java └── solution.py ├── 1575-Count All Possible Routes ├── solution.cpp ├── solution.java └── solution.py ├── 1578-minimum-time-to-make-rope-colorful ├── 1578-minimum-time-to-make-rope-colorful.java └── README.md ├── 1579-remove-max-number-of-edges-to-make-graph ├── solution.cpp ├── solution.java └── solution.py ├── 16-3sum-closest ├── 16-3sum-closest.cpp ├── 16-3sum-closest.java ├── 16-3sum-closest.py ├── NOTES.md └── README.md ├── 1601-Maximum Number of Achievable Transfer Requests ├── solution.cpp ├── solution.java └── solution.py ├── 1603-Design-Parking-System ├── solution.cpp ├── solution.java └── solution.py ├── 1615-maximal-network-rank ├── solution.cpp ├── solution.py └── solutiuon.java ├── 1639-Number of Ways to Form a Target String Given a Dictionary ├── solution.cpp ├── solution.java └── solution.py ├── 164-maximum-gap ├── 164-maximum-gap.cpp ├── 164-maximum-gap.java ├── 164-maximum-gap.py ├── NOTES.md └── README.md ├── 1642-furthest-building-you-can-reach ├── 1642-furthest-building-you-can-reach.cpp ├── 1642-furthest-building-you-can-reach.java ├── 1642-furthest-building-you-can-reach.js ├── 1642-furthest-building-you-can-reach.py ├── NOTES.md └── README.md ├── 1647-minimum-deletions-to-make-character-frequencies-unique ├── 1647-minimum-deletions-to-make-character-frequencies-unique.cpp ├── 1647-minimum-deletions-to-make-character-frequencies-unique.py ├── NOTES.md └── README.md ├── 1657-determine-if-two-strings-are-close ├── 1657-determine-if-two-strings-are-close.cpp ├── 1657-determine-if-two-strings-are-close.java ├── 1657-determine-if-two-strings-are-close.py ├── NOTES.md └── README.md ├── 1658-minimum-operations-to-reduce-x-to-zero ├── 1658-minimum-operations-to-reduce-x-to-zero.py ├── NOTES.md └── README.md ├── 1662-check-if-two-string-arrays-are-equivalent ├── 1662-check-if-two-string-arrays-are-equivalent.java ├── 1662-check-if-two-string-arrays-are-equivalent.py ├── NOTES.md └── README.md ├── 1675-Minimize-Deviation-in-Array ├── solution.js └── solution1.js ├── 168-Excel Sheet Column Title ├── solution.cpp ├── solution.java └── solution.py ├── 1680-concatenation-of-consecutive-binary-numbers ├── 1680-concatenation-of-consecutive-binary-numbers.js ├── NOTES.md └── README.md ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers.cpp ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers.java ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers.py ├── NOTES.md └── README.md ├── 1695-maximum-erasure-value ├── 1695-maximum-erasure-value.cpp ├── 1695-maximum-erasure-value.java ├── 1695-maximum-erasure-value.js ├── 1695-maximum-erasure-value.py ├── NOTES.md └── README.md ├── 1696-jump-game-vi ├── 1696-jump-game-vi.cpp ├── 1696-jump-game-vi.java ├── 1696-jump-game-vi.js ├── 1696-jump-game-vi.py ├── NOTES.md └── README.md ├── 1697-Checking the Existence of Edge Length Limited Paths ├── solution.cpp ├── solution.java └── solution.py ├── 17-letter-combinations-of-phone-number ├── solution.cpp ├── solution.java └── solution.py ├── 1704-determine-if-string-halves-are-alike ├── 1704-determine-if-string-halves-are-alike.js └── README.md ├── 1706-where-will-the-ball-fall ├── 1706-where-will-the-ball-fall.cpp ├── 1706-where-will-the-ball-fall.java ├── 1706-where-will-the-ball-fall.py ├── NOTES.md └── README.md ├── 1710-maximum-units-on-a-truck ├── 1710-maximum-units-on-a-truck.cpp ├── 1710-maximum-units-on-a-truck.java ├── 1710-maximum-units-on-a-truck.js ├── 1710-maximum-units-on-a-truck.py ├── NOTES.md └── README.md ├── 1721-Swapping-Nodes-in-a-Linked-List ├── solution.cpp ├── solution.java └── solution.py ├── 1732-Find-the-Highest-Altitude ├── solution.cpp ├── solution.java └── solution.py ├── 174-dungeon-game ├── 174-dungeon-game.cpp ├── 174-dungeon-game.java ├── 174-dungeon-game.py ├── NOTES.md └── README.md ├── 1751-Maximum Number of Events That Can Be Attended II ├── solution.cpp ├── solution.java └── solution.py ├── 1768-Merge Strings Alternately ├── solution.cpp ├── solution.java └── solution.py ├── 1770-maximum-score-from-performing-multiplication-operations ├── 1770-maximum-score-from-performing-multiplication-operations.cpp ├── 1770-maximum-score-from-performing-multiplication-operations.java ├── NOTES.md └── README.md ├── 1799-Maximize-Score-After-N-Operations ├── solution.cpp ├── solution.java └── solution.py ├── 1802-Maximum-Value-at-a-Given-Index-in-a-Bounded-Array ├── solution.cpp ├── solution.java └── solution.py ├── 1822-Sign of the Product of an Array ├── solution.cpp ├── solution.java └── solution.py ├── 1832-check-if-the-sentence-is-pangram ├── 1832-check-if-the-sentence-is-pangram.cpp ├── 1832-check-if-the-sentence-is-pangram.java ├── 1832-check-if-the-sentence-is-pangram.py ├── NOTES.md └── README.md ├── 185-department-top-three-salaries ├── 185-department-top-three-salaries.sql ├── NOTES.md └── README.md ├── 1870-minimum-speed-to-arrive-on-time ├── solution.cpp ├── solution.java └── solution.py ├── 1879-minimum-xor-sum-of-two-arrays ├── 1879-minimum-xor-sum-of-two-arrays.py ├── NOTES.md └── README.md ├── 188-best-time-to-buy-and-sell-stock-iv ├── 188-best-time-to-buy-and-sell-stock-iv.cpp ├── 188-best-time-to-buy-and-sell-stock-iv.java ├── 188-best-time-to-buy-and-sell-stock-iv.py ├── NOTES.md └── README.md ├── 1894-find-the-student ├── solution.cpp ├── solution.java └── solution.py ├── 19-remove-nth-node-from-end-of-list ├── 19-remove-nth-node-from-end-of-list.cpp ├── 19-remove-nth-node-from-end-of-list.java ├── 19-remove-nth-node-from-end-of-list.js ├── 19-remove-nth-node-from-end-of-list.py ├── NOTES.md └── README.md ├── 1926-nearest-exit-from-entrance-in-maze ├── 1926-nearest-exit-from-entrance-in-maze.cpp ├── 1926-nearest-exit-from-entrance-in-maze.py ├── NOTES.md └── README.md ├── 1964-find the longest valid obstacle course ├── solution.cpp ├── solution.java └── solution.py ├── 1970-Last Day Where You Can Still Cross ├── solution.cpp ├── solution.java └── solution.py ├── 1982-find-array-given-subset-sums ├── 1982-find-array-given-subset-sums.py └── README.md ├── 1987-number-of-unique-good-subsequences ├── 1987-number-of-unique-good-subsequences.cpp ├── NOTES.md └── README.md ├── 199-binary-tree-right-side-view ├── 199-binary-tree-right-side-view.js └── README.md ├── 1996-the-number-of-weak-characters-in-the-game ├── 1996-the-number-of-weak-characters-in-the-game.cpp └── README.md ├── 20-valid-parentheses ├── 20-valid-parentheses.c ├── 20-valid-parentheses.cpp ├── 20-valid-parentheses.java ├── 20-valid-parentheses.py ├── NOTES.md └── README.md ├── 200-number-of-islands ├── 200-number-of-islands.cpp ├── 200-number-of-islands.java ├── 200-number-of-islands.py ├── NOTES.md └── README.md ├── 2007-find-original-array-from-doubled-array ├── 2007-find-original-array-from-doubled-array.cpp ├── 2007-find-original-array-from-doubled-array.java ├── 2007-find-original-array-from-doubled-array.py ├── NOTES.md └── README.md ├── 2022-converting-1d-to-2d ├── solution.cpp ├── solution.java └── solution.py ├── 2024-Maximize the Confusion of an Exam ├── solution.cpp ├── solution.java └── solution.py ├── 2028-find-missing-observation └── solution.py ├── 2059-minimum-operations-to-convert-number ├── 2059-minimum-operations-to-convert-number.java └── NOTES.md ├── 207-course-schedule ├── solution.cpp ├── solution.java └── solution.py ├── 208-implement-trie ├── solution.cpp ├── solution.java └── solution.py ├── 209-Minimum Size Subarray Sum ├── solution.cpp ├── solution.java └── solution.py ├── 2090-k-radius-subarray-averages ├── solution.cpp ├── solution.java └── solution.py ├── 2095-delete-the-middle-node-of-a-linked-list ├── 2095-delete-the-middle-node-of-a-linked-list.cpp ├── 2095-delete-the-middle-node-of-a-linked-list.py ├── NOTES.md └── README.md ├── 21-merge-two-sorted-lists ├── 21-merge-two-sorted-lists.java ├── NOTES.md └── README.md ├── 2101-detonate-maximum-bombs ├── solution.cpp ├── solution.java └── solution.py ├── 2116-check-if-a-parantheses-string-can-be-valid └── solution.py ├── 212-word-search-ii ├── 212-word-search-ii.java └── README.md ├── 212-wword-search-ii ├── 0212-word-search-ii.java ├── 0212-word-search-ii.py ├── NOTES.md └── README.md ├── 2122-recover-the-original-array ├── 2122-recover-the-original-array.cpp ├── 2122-recover-the-original-array.java ├── 2122-recover-the-original-array.py └── README.md ├── 2130-maximum-twin-sum-of-a-linked-list ├── solution.cpp ├── solution.java └── solution.py ├── 2131-longest-palindrome-by-concatenating-two-letter-words ├── 2131-longest-palindrome-by-concatenating-two-letter-words.cpp ├── 2131-longest-palindrome-by-concatenating-two-letter-words.java ├── 2131-longest-palindrome-by-concatenating-two-letter-words.py ├── NOTES.md └── README.md ├── 2136-earliest-possible-day-of-full-bloom ├── 2136-earliest-possible-day-of-full-bloom.cpp ├── 2136-earliest-possible-day-of-full-bloom.py └── README.md ├── 214-shortest-palindrome ├── 214-shortest-palindrome.cpp ├── 214-shortest-palindrome.java ├── 214-shortest-palindrome.py ├── NOTES.md └── README.md ├── 2140-solving questions with brainpower ├── solution.cpp ├── solution.java └── solution.py ├── 2141-maximum-running-time-for-N-computers ├── solution.cpp ├── solution.java └── solution.py ├── 215-kth-largest-element-in-an-array ├── 215-kth-largest-element-in-an-array.cpp ├── 215-kth-largest-element-in-an-array.py ├── NOTES.md └── README.md ├── 2156-find-substring-with-given-hash-value ├── 2156-find-substring-with-given-hash-value.cpp ├── 2156-find-substring-with-given-hash-value.java ├── 2156-find-substring-with-given-hash-value.py ├── NOTES.md └── README.md ├── 2172-maximum-and-sum-of-array ├── 2172-maximum-and-sum-of-array.cpp ├── 2172-maximum-and-sum-of-array.java ├── NOTES.md └── README.md ├── 218-the-skyline-problem ├── 218-the-skyline-problem.cpp ├── 218-the-skyline-problem.py ├── NOTES.md └── README.md ├── 2187-minimum-time-to-complete-trip ├── solution.cpp ├── solution.java └── solution.py ├── 219-contains-duplicate-ii ├── 0219-contains-duplicate-ii.cpp ├── 0219-contains-duplicate-ii.java ├── 0219-contains-duplicate-ii.py └── README.md ├── 22-generate-parentheses ├── 22-generate-parentheses.cpp ├── 22-generate-parentheses.java ├── 22-generate-parentheses.js ├── 22-generate-parentheses.py ├── NOTES.md └── README.md ├── 2215-Find the Difference of Two Arrays ├── solution.cpp ├── solution.java └── solution.py ├── 2218-Maximum Value of K Coins From Piles ├── solution.cpp ├── solution.java └── solution.py ├── 222-count-complete-tree-nodes ├── 0222-count-complete-tree-nodes.cpp ├── 0222-count-complete-tree-nodes.java ├── NOTES.md └── README.md ├── 2225-find-players-with-zero-or-one-losses ├── 2225-find-players-with-zero-or-one-losses.cpp ├── 2225-find-players-with-zero-or-one-losses.java ├── 2225-find-players-with-zero-or-one-losses.py ├── NOTES.md └── README.md ├── 223-rectangle-area ├── 0223-rectangle-area.cpp ├── 0223-rectangle-area.java ├── 0223-rectangle-area.py ├── NOTES.md └── README.md ├── 224-basic-calculator ├── 224-basic-calculator.java ├── 224-basic-calculator.py ├── NOTES.md └── README.md ├── 224-bbasic-calculator ├── 0224-basic-calculator.cpp ├── NOTES.md └── README.md ├── 225-implement-stack-using-queues ├── solution.cpp ├── solution.java └── solution.py ├── 2256-minimum-average-difference ├── 2256-minimum-average-difference.cpp ├── 2256-minimum-average-difference.java ├── 2256-minimum-average-difference.py ├── NOTES.md └── README.md ├── 226-invert-binary-tree ├── solution.cpp └── solution.java ├── 2272-Substring With Largest Variance ├── solution.cpp ├── solution.java └── solution.py ├── 228-Summary-Ranges ├── slution.java ├── solution.cpp └── solution.py ├── 2289-steps-to-make-array-non-decreasing ├── 2289-steps-to-make-array-non-decreasing.cpp ├── 2289-steps-to-make-array-non-decreasing.py ├── NOTES.md └── README.md ├── 2301-match-substring-after-replacement ├── 2301-match-substring-after-replacement.cpp ├── 2301-match-substring-after-replacement.java ├── 2301-match-substring-after-replacement.py ├── NOTES.md └── README.md ├── 2302-count-subarrays-with-score-less-than-k ├── 2302-count-subarrays-with-score-less-than-k.cpp ├── 2302-count-subarrays-with-score-less-than-k.java ├── NOTES.md └── README.md ├── 2305-Fair Distribution of Cookies ├── solution.cpp ├── solution.java └── solution.py ├── 2328-Number-of-Increasing-Paths-in-a-Grid ├── solution.cpp ├── solution.java └── solution.py ├── 233-number-of-digit-one ├── 233-number-of-digit-one.cpp ├── 233-number-of-digit-one.java ├── 233-number-of-digit-one.py ├── NOTES.md └── README.md ├── 2336-smallest-positive-number-infinite-set ├── solution.cpp ├── solution.java └── solution.py ├── 234-palindrome-linked-list ├── 234-palindrome-linked-list.cpp ├── 234-palindrome-linked-list.java ├── NOTES.md └── README.md ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── 235-lowest-common-ancestor-of-a-binary-search-tree.cpp ├── 235-lowest-common-ancestor-of-a-binary-search-tree.java ├── 235-lowest-common-ancestor-of-a-binary-search-tree.py ├── NOTES.md └── README.md ├── 2352-Equal-Row-and-Column-Pairs ├── solution.cpp ├── solution.java └── solution.py ├── 2359-Find Closest Node to Given Two Nodes └── solution.py ├── 236-lowest-common-ancestor-of-a-binary-tree ├── 236-lowest-common-ancestor-of-a-binary-tree.cpp ├── 236-lowest-common-ancestor-of-a-binary-tree.java ├── 236-lowest-common-ancestor-of-a-binary-tree.py ├── NOTES.md └── README.md ├── 2366-Minimum Replacements to Sort the Array ├── solution.cpp ├── solution.java └── solution.py ├── 2369-check-if-there-is--valid-partition ├── solution.cpp ├── solution.java └── solution.py ├── 237-delete-node-in-a-linked-list ├── 0237-delete-node-in-a-linked-list.java ├── 0237-delete-node-in-a-linked-list.py ├── NOTES.md └── README.md ├── 239-sliding-window-maximum ├── 239-sliding-window-maximum.java ├── NOTES.md └── README.md ├── 24-swap-nodes-in-pairs ├── 24-swap-nodes-in-pairs.java ├── NOTES.md ├── README.md ├── solution.cpp └── solution.py ├── 240-search-a-2d-matrix-ii ├── 240-search-a-2d-matrix-ii.cpp ├── 240-search-a-2d-matrix-ii.java ├── 240-search-a-2d-matrix-ii.js ├── 240-search-a-2d-matrix-ii.py ├── NOTES.md └── README.md ├── 242-valid-anagram ├── 242-valid-anagram.cpp ├── 242-valid-anagram.java ├── 242-valid-anagram.js ├── 242-valid-anagram.py ├── NOTES.md └── README.md ├── 2444-count-subarrays-with-fixed-bounds ├── solution.cpp ├── solution.java └── solution.py ├── 2448-minimum-cost-to-make-array-equal ├── solution.cpp ├── solution.java └── solution.py ├── 2462-Total Cost to Hire K Workers ├── solution.cpp ├── solution.java └── solution.py ├── 2466-count-ways-to-build-good-strings ├── solution.cpp ├── solution.java └── solution.py ├── 2483-minimum-penalty-for-a-shop ├── solution.cpp ├── solution.java └── solution.py ├── 2542-Maximum-Subsequence-Score ├── solution.cpp ├── solution.java └── solution.py ├── 2551-Put Marbles in Bags ├── solution.cpp ├── solution.java └── solution.py ├── 258-Add digits ├── solution.cpp ├── solution.java └── solution.py ├── 26-remove-duplicates-from-sorted-array ├── 0026-remove-duplicates-from-sorted-array.cpp ├── NOTES.md └── README.md ├── 2616-Minimize the Maximum Difference of Pairs ├── solution.cpp ├── solution.java └── solution.py ├── 262-trips-and-users ├── 262-trips-and-users.sql └── README.md ├── 27-remove-element ├── 27-remove-element.py ├── NOTES.md └── README.md ├── 273-integer-to-english-words ├── 273-integer-to-english-words.java ├── 273-integer-to-english-words.py ├── NOTES.md └── README.md ├── 279-perfect-squares ├── 0279-perfect-squares.cpp ├── 0279-perfect-squares.py ├── NOTES.md └── README.md ├── 28-find-the-index-of-the-first-occurence ├── solution.cpp ├── solution.java └── solution.py ├── 28-implement-strstr ├── 28-implement-strstr.c ├── 28-implement-strstr.cpp ├── 28-implement-strstr.java ├── 28-implement-strstr.js ├── 28-implement-strstr.py ├── NOTES.md └── README.md ├── 282-expression-add-operators ├── 282-expression-add-operators.cpp ├── 282-expression-add-operators.java ├── NOTES.md └── README.md ├── 295-find-median-from-data-stream ├── 295-find-median-from-data-stream.cpp ├── 295-find-median-from-data-stream.java ├── 295-find-median-from-data-stream.py ├── NOTES.md └── README.md ├── 297-serialize-and-deserialize-binary-tree ├── 297-serialize-and-deserialize-binary-tree.java ├── 297-serialize-and-deserialize-binary-tree.py ├── NOTES.md └── README.md ├── 3-longest-substring-without-repeating-characters ├── 3-longest-substring-without-repeating-characters.cpp ├── 3-longest-substring-without-repeating-characters.js ├── NOTES.md └── README.md ├── 30-substring-with-concatenation-of-all-words ├── 30-substring-with-concatenation-of-all-words.java └── README.md ├── 300-longest-increasing-subsequence ├── 300-longest-increasing-subsequence.cpp ├── 300-longest-increasing-subsequence.java ├── 300-longest-increasing-subsequence.py ├── NOTES.md └── README.md ├── 307-range-sum-query-mutable ├── 307-range-sum-query-mutable.cpp ├── 307-range-sum-query-mutable.java └── README.md ├── 315-count-of-smaller-numbers-after-self ├── 315-count-of-smaller-numbers-after-self.cpp ├── 315-count-of-smaller-numbers-after-self.java ├── 315-count-of-smaller-numbers-after-self.py ├── NOTES.md └── README.md ├── 319-bulb-switcher ├── solution.cpp ├── solution.java └── solution.py ├── 326-power-of-three ├── 326-power-of-three.cpp ├── 326-power-of-three.java ├── 326-power-of-three.js ├── 326-power-of-three.py ├── NOTES.md └── README.md ├── 33-search-in-rotated-sorted-array ├── 33-search-in-rotated-sorted-array.cpp └── README.md ├── 334-increasing-triplet-subsequence ├── 0334-increasing-triplet-subsequence.cpp ├── 0334-increasing-triplet-subsequence.py └── NOTES.md ├── 336-palindrome-pairs ├── 336-palindrome-pairs.java ├── 336-palindrome-pairs.py └── README.md ├── 34-find-first-and-last-position-of-element-in-sorted-array ├── 34-find-first-and-last-position-of-element-in-sorted-array.cpp ├── 34-find-first-and-last-position-of-element-in-sorted-array.java ├── 34-find-first-and-last-position-of-element-in-sorted-array.js ├── 34-find-first-and-last-position-of-element-in-sorted-array.py ├── NOTES.md └── README.md ├── 342-power-of-four ├── 342-power-of-four.cpp ├── 342-power-of-four.java ├── 342-power-of-four.py ├── NOTES.md └── README.md ├── 347-top-k-frequent-elements ├── solution.cpp ├── solution.java └── solution.py ├── 36-valid-sudoku ├── 36-valid-sudoku.c ├── 36-valid-sudoku.cpp ├── 36-valid-sudoku.java ├── 36-valid-sudoku.py ├── NOTES.md └── README.md ├── 36-vvalid-sudoku ├── 0036-valid-sudoku.cpp ├── 0036-valid-sudoku.java ├── NOTES.md └── README.md ├── 363-max-sum-of-rectangle-no-larger-than-k ├── 363-max-sum-of-rectangle-no-larger-than-k.cpp ├── 363-max-sum-of-rectangle-no-larger-than-k.java ├── NOTES.md └── README.md ├── 373-find-k-pairs-with-smallest-sum ├── solution.cpp ├── solution.java └── solution.py ├── 374-guess-number-higher-or-lower ├── 0374-guess-number-higher-or-lower.cpp ├── 0374-guess-number-higher-or-lower.java ├── NOTES.md └── README.md ├── 376-wiggle-subsequence ├── 376-wiggle-subsequence.cpp ├── 376-wiggle-subsequence.java ├── 376-wiggle-subsequence.js ├── 376-wiggle-subsequence.py ├── NOTES.md └── README.md ├── 377-combination-sum-iv ├── 377-combination-sum-iv.cpp ├── 377-combination-sum-iv.java ├── 377-combination-sum-iv.js ├── 377-combination-sum-iv.py ├── NOTES.md └── README.md ├── 378-kth-smallest-element-in-a-sorted-matrix ├── 378-kth-smallest-element-in-a-sorted-matrix.cpp ├── 378-kth-smallest-element-in-a-sorted-matrix.java ├── NOTES.md └── README.md ├── 38-ccount-and-say ├── 0038-count-and-say.cpp ├── 0038-count-and-say.java ├── 0038-count-and-say.py └── README.md ├── 38-count-and-say └── README.md ├── 382-linked-list-random-node ├── solution.cpp └── solution.java ├── 383-ransom-note ├── 383-ransom-note.js └── README.md ├── 387-first-unique-character-in-a-string ├── 387-first-unique-character-in-a-string.cpp ├── 387-first-unique-character-in-a-string.java ├── 387-first-unique-character-in-a-string.py ├── NOTES.md └── README.md ├── 39-combination-sum ├── NOTES.md └── README.md ├── 393-utf-8-validation ├── 393-utf-8-validation.cpp ├── 393-utf-8-validation.java └── NOTES.md ├── 399-evaluate-division ├── solution.cpp ├── solution.java └── solution.py ├── 40-combination-sum-ii ├── 40-combination-sum-ii.java ├── NOTES.md └── README.md ├── 406-queue-reconstruction-by-height ├── 406-queue-reconstruction-by-height.py └── NOTES.md ├── 417-pacific-atlantic-water-flow ├── 417-pacific-atlantic-water-flow.cpp ├── NOTES.md └── README.md ├── 42-trapping-rain-water ├── 42-trapping-rain-water.cpp └── README.md ├── 427-construct-quad-tree ├── solution.cpp └── solution.java ├── 429-n-ary-tree-level-order-traversal ├── 429-n-ary-tree-level-order-traversal.cpp ├── 429-n-ary-tree-level-order-traversal.java └── README.md ├── 43-multiply-strings ├── 43-multiply-strings.py ├── NOTES.md └── README.md ├── 433-minimum-genetic-mutation ├── 0433-minimum-genetic-mutation.cpp ├── 0433-minimum-genetic-mutation.java └── NOTES.md ├── 435-non-overlapping-intervals ├── solution.cpp ├── solution.java └── solution.py ├── 442-find-all-duplicates-in-an-array ├── 442-find-all-duplicates-in-an-array.cpp ├── 442-find-all-duplicates-in-an-array.java ├── 442-find-all-duplicates-in-an-array.py ├── NOTES.md └── README.md ├── 443-string-compression ├── solution.cpp ├── solution.java └── solution.py ├── 445-Add Two Numbers II ├── solution.cpp ├── solution.java └── solution.py ├── 446-arithmetic-slices-ii-subsequence ├── 0446-arithmetic-slices-ii-subsequence.java ├── NOTES.md └── README.md ├── 448-find-all-numbers-disappeared-in-an-array ├── 448-find-all-numbers-disappeared-in-an-array.cpp ├── 448-find-all-numbers-disappeared-in-an-array.py ├── NOTES.md └── README.md ├── 45-jump-game-ii ├── 45-jump-game-ii.cpp ├── 45-jump-game-ii.java ├── 45-jump-game-ii.js ├── 45-jump-game-ii.py ├── NOTES.md └── README.md ├── 451-sort-characters-by-frequency ├── 0451-sort-characters-by-frequency.cpp ├── 0451-sort-characters-by-frequency.java ├── 0451-sort-characters-by-frequency.py ├── NOTES.md └── README.md ├── 455-Assign Cookies └── solution.py ├── 458-poor-pigs ├── 458-poor-pigs.cpp ├── 458-poor-pigs.java └── README.md ├── 46-permutations ├── 46-permutations.java ├── NOTES.md └── README.md ├── 462-minimum-moves-to-equal-array-elements-ii ├── 462-minimum-moves-to-equal-array-elements-ii.cpp ├── 462-minimum-moves-to-equal-array-elements-ii.java ├── 462-minimum-moves-to-equal-array-elements-ii.py ├── NOTES.md └── README.md ├── 47-permutations-ii ├── 47-permutations-ii.java └── README.md ├── 473-matchsticks-to-square ├── 473-matchsticks-to-square.cpp ├── NOTES.md └── README.md ├── 48-rotate-image ├── 48-rotate-image.cpp ├── 48-rotate-image.java ├── 48-rotate-image.js ├── 48-rotate-image.py ├── NOTES.md └── README.md ├── 486-Predict the Winner ├── solution.cpp ├── solution.java └── solution.py ├── 49-ggroup-anagrams ├── 0049-group-anagrams.cpp ├── 0049-group-anagrams.java ├── NOTES.md └── README.md ├── 49-group-anagrams ├── 49-group-anagrams.cpp ├── 49-group-anagrams.java ├── 49-group-anagrams.py ├── NOTES.md └── README.md ├── 5-longest-palindromic-substring ├── 5-longest-palindromic-substring.cpp ├── NOTES.md └── README.md ├── 50-powx-n ├── 50-powx-n.py └── README.md ├── 502-IPO ├── solution.cpp └── solution.java ├── 509-fibonacci-number ├── 509-fibonacci-number.cpp ├── 509-fibonacci-number.java ├── 509-fibonacci-number.js ├── 509-fibonacci-number.py ├── NOTES.md └── README.md ├── 518-coin-change-ii ├── solution.cpp ├── solution.java └── solution.py ├── 523-continuous-subarray-sum ├── 0523-continuous-subarray-sum.cpp ├── 0523-continuous-subarray-sum.java ├── 0523-continuous-subarray-sum.py ├── NOTES.md └── README.md ├── 53-maximum-subarray ├── 53-maximum-subarray.c ├── 53-maximum-subarray.cpp ├── NOTES.md └── README.md ├── 530-Minimum-Absolute-Difference-in-BST ├── solution.cpp ├── solution.java └── solution.py ├── 54-spiral-matrix ├── 54-spiral-matrix.java └── README.md ├── 540-single-element-in-a-sorted-array ├── solution.cpp ├── solution.java └── solution.py ├── 547-number-of-provinces ├── solution.cpp ├── solution.java └── solution.py ├── 55-jump-game ├── 55-jump-game.cpp ├── 55-jump-game.java ├── NOTES.md └── README.md ├── 554-brick-wall ├── 554-brick-wall.cpp ├── 554-brick-wall.java ├── 554-brick-wall.js ├── 554-brick-wall.py ├── NOTES.md └── README.md ├── 557-reverse-words-in-a-string-iii ├── 557-reverse-words-in-a-string-iii.cpp ├── 557-reverse-words-in-a-string-iii.java ├── NOTES.md └── README.md ├── 56-merge-intervals ├── 56-merge-intervals.py ├── NOTES.md └── README.md ├── 57-insert-interval ├── 57-insert-interval.cpp ├── 57-insert-interval.java ├── 57-insert-interval.py ├── NOTES.md └── README.md ├── 576-out-of-boundary-paths ├── 576-out-of-boundary-paths.cpp ├── 576-out-of-boundary-paths.java ├── 576-out-of-boundary-paths.js ├── 576-out-of-boundary-paths.py ├── NOTES.md └── README.md ├── 58-length-of-last-word ├── 58-length-of-last-word.cpp ├── 58-length-of-last-word.java ├── 58-length-of-last-word.py ├── NOTES.md └── README.md ├── 583-delete-operation-for-two-strings ├── 583-delete-operation-for-two-strings.cpp ├── 583-delete-operation-for-two-strings.java ├── 583-delete-operation-for-two-strings.js ├── 583-delete-operation-for-two-strings.py ├── NOTES.md └── README.md ├── 587-erect-the-fence ├── 0587-erect-the-fence.java └── README.md ├── 59-spiral-matrix-ii ├── 59-spiral-matrix-ii.cpp ├── 59-spiral-matrix-ii.java ├── NOTES.md └── README.md ├── 60-permutation-sequence ├── 60-permutation-sequence.cpp ├── 60-permutation-sequence.java ├── NOTES.md └── README.md ├── 605-can-place-flowers ├── solution.cpp ├── solution.java └── solution.py ├── 606-construct-string-from-binary-tree ├── 606-construct-string-from-binary-tree.java ├── 606-construct-string-from-binary-tree.py └── NOTES.md ├── 609-find-duplicate-file-in-system ├── 609-find-duplicate-file-in-system.cpp ├── 609-find-duplicate-file-in-system.java ├── 609-find-duplicate-file-in-system.py ├── NOTES.md └── README.md ├── 61-rotate-list ├── 61-rotate-list.java ├── NOTES.md └── README.md ├── 62-unique-paths ├── 62-unique-paths.java ├── NOTES.md └── README.md ├── 622-design-circular-queue ├── 622-design-circular-queue.cpp ├── 622-design-circular-queue.java ├── 622-design-circular-queue.py ├── NOTES.md └── README.md ├── 623-add-one-row-to-tree ├── 623-add-one-row-to-tree.cpp ├── 623-add-one-row-to-tree.java ├── NOTES.md └── README.md ├── 629-k-inverse-pairs-array ├── 629-k-inverse-pairs-array.py └── README.md ├── 63-unique-paths-ii ├── solution.cpp ├── solution.java └── solution.py ├── 630-course-schedule-iii ├── 630-course-schedule-iii.cpp ├── 630-course-schedule-iii.java ├── 630-course-schedule-iii.js ├── 630-course-schedule-iii.py ├── NOTES.md └── README.md ├── 637-average-of-levels-in-binary-tree ├── 637-average-of-levels-in-binary-tree.cpp ├── 637-average-of-levels-in-binary-tree.java ├── 637-average-of-levels-in-binary-tree.js ├── NOTES.md └── README.md ├── 64-minimum-path-sum ├── 64-minimum-path-sum.cpp ├── 64-minimum-path-sum.java ├── NOTES.md └── README.md ├── 645-set-mismatch ├── 645-set-mismatch.java ├── 645-set-mismatch.js ├── 645-set-mismatch.py ├── NOTES.md └── README.md ├── 645-set-mismatchh ├── 0645-set-mismatch.cpp └── README.md ├── 65-valid-number ├── 65-valid-number.cpp ├── NOTES.md └── README.md ├── 652-find-duplicate-subtrees ├── solution.cpp ├── solution.java └── solution.py ├── 653-two-sum-iv-input-is-a-bst ├── 653-two-sum-iv-input-is-a-bst.cpp ├── 653-two-sum-iv-input-is-a-bst.java ├── 653-two-sum-iv-input-is-a-bst.py ├── NOTES.md └── README.md ├── 658-find-k-closest-elements ├── 658-find-k-closest-elements.cpp ├── 658-find-k-closest-elements.java ├── 658-find-k-closest-elements.py └── README.md ├── 659-split-array-into-consecutive-subsequences ├── 659-split-array-into-consecutive-subsequences.java ├── NOTES.md └── README.md ├── 66-plus-one ├── 66-plus-one.c ├── 66-plus-one.java ├── 66-plus-one.py ├── NOTES.md └── README.md ├── 662-Maximum Width of Binary Tree ├── solution.java └── solution.py ├── 664-Strange-printer ├── solution.cpp ├── solution.java └── solution.py ├── 665-non-decreasing-array ├── 665-non-decreasing-array.cpp ├── 665-non-decreasing-array.java ├── 665-non-decreasing-array.js ├── 665-non-decreasing-array.py ├── NOTES.md └── README.md ├── 67-aadd-binary ├── add-binary.cpp ├── add-binary.java └── add-binary.py ├── 67-add-binary ├── 67-add-binary.c ├── 67-add-binary.cpp ├── 67-add-binary.java ├── 67-add-binary.py ├── NOTES.md └── README.md ├── 673-Number of Longest Increasing Sub-sequences ├── solution.cpp ├── solution.java └── solution.py ├── 68-text-justification ├── 68-text-justification.cpp ├── 68-text-justification.java ├── 68-text-justification.py ├── NOTES.md └── README.md ├── 688-Knight Probability in Chessboard ├── solution.cpp ├── solution.java └── solution.py ├── 69-sqrtx ├── 69-sqrtx.c ├── 69-sqrtx.cpp ├── 69-sqrtx.java ├── 69-sqrtx.py ├── NOTES.md └── README.md ├── 692-top-k-frequent-words ├── 0692-top-k-frequent-words.cpp ├── 0692-top-k-frequent-words.java ├── 0692-top-k-frequent-words.py ├── NOTES.md └── README.md ├── 695-max-area-of-island ├── 695-max-area-of-island.cpp ├── 695-max-area-of-island.py └── NOTES.md ├── 70-climbing-stairs ├── 70-climbing-stairs.java └── README.md ├── 703-Kth-Largest-Element-in-a-Stream ├── solution.cpp ├── solution.java └── solution.py ├── 705-design-hashset ├── solution.cpp ├── solution.java └── solution.py ├── 71-simplify-path ├── 71-simplify-path.c ├── 71-simplify-path.cpp ├── 71-simplify-path.java ├── 71-simplify-path.py ├── NOTES.md └── README.md ├── 712-Minimum ASCII Delete Sum for Two Strings ├── solution.cpp ├── solution.java └── solution.py ├── 714-Best Time to Buy and Sell Stock with Transaction Fee ├── solution.cpp ├── solution.java └── solution.py ├── 718-maximum-length-of-repeated-subarray ├── 718-maximum-length-of-repeated-subarray.cpp ├── 718-maximum-length-of-repeated-subarray.py ├── NOTES.md └── README.md ├── 72-edit-distance ├── 72-edit-distance.java ├── NOTES.md └── README.md ├── 725. Split Linked List in Parts ├── solution.cpp ├── solution.java └── solution.py ├── 729-my-calendar-i ├── 729-my-calendar-i.cpp ├── 729-my-calendar-i.js ├── 729-my-calendar-i.py └── README.md ├── 73-set-matrix-zeroes ├── 73-set-matrix-zeroes.java └── README.md ├── 732-my-calendar-iii ├── 732-my-calendar-iii.cpp ├── 732-my-calendar-iii.py └── NOTES.md ├── 735-Asteroid Collision ├── solution.cpp ├── solution.java └── solution.py ├── 74-search-a-2d-matrix ├── 74-search-a-2d-matrix.cpp ├── NOTES.md ├── README.md ├── solution.java └── solution.py ├── 744-find-smallest-letter-greater-than-target ├── solution.cpp ├── solution.java └── solution.py ├── 745-prefix-and-suffix-search ├── 745-prefix-and-suffix-search.cpp ├── 745-prefix-and-suffix-search.java └── NOTES.md ├── 746-min-cost-climbing-stairs ├── 746-min-cost-climbing-stairs.cpp ├── 746-min-cost-climbing-stairs.java ├── 746-min-cost-climbing-stairs.js ├── 746-min-cost-climbing-stairs.py ├── NOTES.md └── README.md ├── 75-sort-colors ├── 75-sort-colors.cpp ├── NOTES.md └── README.md ├── 76-minimum-window-substring ├── 76-minimum-window-substring.java └── NOTES.md ├── 76-mminimum-window-substring ├── 0076-minimum-window-substring.cpp ├── 0076-minimum-window-substring.java ├── 0076-minimum-window-substring.py ├── NOTES.md └── README.md ├── 766-toeplitz-matrix ├── 0766-toeplitz-matrix.cpp ├── 0766-toeplitz-matrix.java ├── 0766-toeplitz-matrix.py ├── NOTES.md └── README.md ├── 767-reorganize-string ├── solution.cpp ├── solution.java └── solution.py ├── 77-combinations ├── 77-combinations.cpp ├── 77-combinations.java ├── 77-combinations.js ├── 77-combinations.py ├── NOTES.md └── README.md ├── 778-swim-in-rising-water ├── 778-swim-in-rising-water.cpp ├── 778-swim-in-rising-water.java ├── 778-swim-in-rising-water.js ├── 778-swim-in-rising-water.py ├── NOTES.md └── README.md ├── 78-subsets ├── 78-subsets.java └── README.md ├── 785-is-graph-bipartite ├── solution.cpp ├── solution.java └── solution.py ├── 79-word-search ├── 79-word-search.java ├── NOTES.md └── README.md ├── 79-wword-search ├── 0079-word-search.cpp ├── NOTES.md └── README.md ├── 792-number-of-matching-subsequences ├── 792-number-of-matching-subsequences.cpp ├── 792-number-of-matching-subsequences.java ├── 792-number-of-matching-subsequences.py ├── NOTES.md └── README.md ├── 80-remove-duplicates-from-sorted-array-ii ├── 80-remove-duplicates-from-sorted-array-ii.cpp ├── 80-remove-duplicates-from-sorted-array-ii.java ├── NOTES.md └── README.md ├── 802-Find Eventual Safe States ├── solution.cpp ├── solution.java └── solution.py ├── 804-unique-morse-code-words ├── 804-unique-morse-code-words.cpp ├── 804-unique-morse-code-words.java ├── 804-unique-morse-code-words.py ├── NOTES.md └── README.md ├── 808-Soup-serving ├── solution.cpp ├── solution.java └── solution.py ├── 81-search-in-rotated-sorted-array-ii ├── 81-search-in-rotated-sorted-array-ii.cpp ├── 81-search-in-rotated-sorted-array-ii.java ├── 81-search-in-rotated-sorted-array-ii.py ├── NOTES.md └── README.md ├── 814-binary-tree-pruning ├── 814-binary-tree-pruning.cpp ├── 814-binary-tree-pruning.py ├── NOTES.md └── README.md ├── 82-remove-duplicates-from-sorted-list-ii ├── 82-remove-duplicates-from-sorted-list-ii.cpp ├── 82-remove-duplicates-from-sorted-list-ii.java ├── 82-remove-duplicates-from-sorted-list-ii.py ├── NOTES.md └── README.md ├── 820-short-encoding-of-words ├── 820-short-encoding-of-words.cpp ├── 820-short-encoding-of-words.java ├── 820-short-encoding-of-words.js ├── 820-short-encoding-of-words.py ├── NOTES.md └── README.md ├── 823-binary-trees-with-factors ├── 823-binary-trees-with-factors.cpp ├── 823-binary-trees-with-factors.java ├── 823-binary-trees-with-factors.js ├── 823-binary-trees-with-factors.py └── README.md ├── 83-remove-duplicates-from-sorted-list ├── 83-remove-duplicates-from-sorted-list.cpp ├── 83-remove-duplicates-from-sorted-list.java ├── 83-remove-duplicates-from-sorted-list.py ├── NOTES.md └── README.md ├── 835-image-overlap ├── 0835-image-overlap.java ├── 0835-image-overlap.py ├── NOTES.md └── README.md ├── 837-new-21-game ├── solution.cpp ├── solution.java └── solution.py ├── 838-push-dominoes ├── 838-push-dominoes.java ├── 838-push-dominoes.py ├── NOTES.md └── README.md ├── 839-similar string groups ├── solution.cpp ├── solution.java └── solution.py ├── 84-largest-rectangle-in-histogram ├── 84-largest-rectangle-in-histogram.java ├── NOTES.md └── README.md ├── 85-maximal-rectangle ├── NOTES.md └── README.md ├── 852-Peak Index in a Mountain Array ├── solution.cpp ├── solution.java └── solution.py ├── 858-mirror-reflection ├── 858-mirror-reflection.cpp ├── 858-mirror-reflection.java └── README.md ├── 859-buddy-strings ├── solution.cpp ├── solution.java └── solution.py ├── 86-partition-list ├── 86-partition-list.cpp ├── 86-partition-list.java ├── 86-partition-list.py ├── NOTES.md └── README.md ├── 863-All Nodes Distance K in Binary Tree ├── solution.cpp ├── solution.java └── solution.py ├── 864-Shortest Path to Get All Keys ├── solution.cpp ├── solution.java └── solution.py ├── 869-reordered-power-of-2 ├── 869-reordered-power-of-2.cpp ├── 869-reordered-power-of-2.java ├── 869-reordered-power-of-2.js ├── 869-reordered-power-of-2.py ├── NOTES.md └── README.md ├── 87-scramble-string ├── 87-scramble-string.java ├── NOTES.md └── README.md ├── 871-minimum-number-of-refueling-stops ├── 871-minimum-number-of-refueling-stops.cpp ├── 871-minimum-number-of-refueling-stops.java ├── 871-minimum-number-of-refueling-stops.js ├── NOTES.md └── README.md ├── 874-walking-robot └── solution.py ├── 875-koko-eating-bananas ├── solution.cpp ├── solution.java └── solution.py ├── 876-middle-of-the-linked-list ├── 0876-middle-of-the-linked-list.cpp ├── 0876-middle-of-the-linked-list.java ├── 0876-middle-of-the-linked-list.py ├── NOTES.md └── README.md ├── 879-Profitable Schemes ├── solution.cpp ├── solution.java └── solution.py ├── 89-gray-code ├── 89-gray-code.cpp ├── 89-gray-code.java ├── 89-gray-code.py ├── NOTES.md └── README.md ├── 890-find-and-replace-pattern ├── 890-find-and-replace-pattern.cpp ├── 890-find-and-replace-pattern.java ├── 890-find-and-replace-pattern.py ├── NOTES.md └── README.md ├── 894-All Possible Full Binary Trees ├── solution.cpp ├── solution.java └── solution.py ├── 899-orderly-queue ├── 0899-orderly-queue.cpp ├── 0899-orderly-queue.java ├── 0899-orderly-queue.py ├── NOTES.md └── README.md ├── 90-subsets-ii ├── 90-subsets-ii.cpp ├── 90-subsets-ii.java ├── NOTES.md └── README.md ├── 901-online-stock-span ├── 0901-online-stock-span.cpp ├── 0901-online-stock-span.java └── README.md ├── 907-sum-of-subarray-minimums ├── 0907-sum-of-subarray-minimums.cpp ├── 0907-sum-of-subarray-minimums.java ├── NOTES.md └── README.md ├── 909-snakes-and-ladders ├── solution.cpp ├── solution.java └── solution.py ├── 91-decode-ways ├── 91-decode-ways.cpp ├── 91-decode-ways.java ├── 91-decode-ways.py ├── NOTES.md └── README.md ├── 912-sort-an-array ├── solution.cpp ├── solution.java └── solution.py ├── 916-word-subsets ├── 916-word-subsets.cpp ├── 916-word-subsets.java ├── 916-word-subsets.js ├── 916-word-subsets.py ├── NOTES.md └── README.md ├── 92-reverse-linked-list-ii ├── 92-reverse-linked-list-ii.cpp ├── 92-reverse-linked-list-ii.java ├── NOTES.md └── README.md ├── 920-number-of-music-playlist ├── solution.cpp ├── solution.java └── solution.py ├── 93-restore-ip-addresses ├── 93-restore-ip-addresses.java ├── NOTES.md └── README.md ├── 934-shortest-bridge ├── solution.cpp ├── solution.java └── solution.py ├── 936-stamping-the-sequence ├── 936-stamping-the-sequence.cpp ├── 936-stamping-the-sequence.java ├── 936-stamping-the-sequence.js ├── 936-stamping-the-sequence.py ├── NOTES.md └── README.md ├── 94-binary-tree-inorder-traversal ├── 94-binary-tree-inorder-traversal.cpp ├── 94-binary-tree-inorder-traversal.java ├── 94-binary-tree-inorder-traversal.py ├── NOTES.md └── README.md ├── 946-validate-stack-sequences ├── solution.cpp ├── solution.java └── solution.py ├── 948-bag-of-tokens ├── 948-bag-of-tokens.cpp ├── 948-bag-of-tokens.java ├── NOTES.md └── README.md ├── 95-unique-binary-search-trees-ii ├── 95-unique-binary-search-trees-ii.cpp ├── 95-unique-binary-search-trees-ii.java ├── 95-unique-binary-search-trees-ii.py ├── NOTES.md └── README.md ├── 956-Tallest Billboard ├── solution.cpp ├── solution.java └── solution.py ├── 96-unique-binary-search-trees ├── 96-unique-binary-search-trees.cpp ├── 96-unique-binary-search-trees.java ├── 96-unique-binary-search-trees.py ├── NOTES.md └── README.md ├── 967-numbers-with-same-consecutive-differences ├── 967-numbers-with-same-consecutive-differences.java ├── NOTES.md └── README.md ├── 968-binary-tree-cameras ├── 968-binary-tree-cameras.cpp ├── 968-binary-tree-cameras.java ├── 968-binary-tree-cameras.js ├── 968-binary-tree-cameras.py ├── NOTES.md └── README.md ├── 97-interleaving-string ├── 97-interleaving-string.cpp ├── 97-interleaving-string.java ├── 97-interleaving-string.py ├── NOTES.md └── README.md ├── 98-validate-binary-search-tree ├── 98-validate-binary-search-tree.cpp ├── 98-validate-binary-search-tree.java ├── 98-validate-binary-search-tree.py ├── NOTES.md └── README.md ├── 980-unique-paths-iii ├── 980-unique-paths-iii.cpp ├── NOTES.md └── README.md ├── 981-time-based-key-value-store ├── 981-time-based-key-value-store.java ├── 981-time-based-key-value-store.py └── NOTES.md ├── 983-minimum-cost-for-tickets ├── solution.cpp └── solution.java ├── 985-sum-of-even-numbers-after-queries ├── 985-sum-of-even-numbers-after-queries.java ├── 985-sum-of-even-numbers-after-queries.py ├── NOTES.md └── README.md ├── 987-vertical-order-traversal-of-a-binary-tree ├── 987-vertical-order-traversal-of-a-binary-tree.cpp ├── 987-vertical-order-traversal-of-a-binary-tree.py ├── NOTES.md └── README.md ├── 99-recover-binary-search-tree ├── 99-recover-binary-search-tree.cpp ├── 99-recover-binary-search-tree.java ├── 99-recover-binary-search-tree.py ├── NOTES.md └── README.md ├── 990-satisfiability-of-equality-equations ├── 990-satisfiability-of-equality-equations.cpp ├── 990-satisfiability-of-equality-equations.java ├── 990-satisfiability-of-equality-equations.py ├── NOTES.md └── README.md ├── 997-find-the-town-judge ├── solution.cpp ├── solution.java └── solution.py ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md └── profile.png /0295-find-median-from-data-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0345-reverse-vowels-of-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0380-insert-delete-getrandom-o1/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0976-largest-perimeter-triangle/0976-largest-perimeter-triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestPerimeter(vector& A) { 4 | sort(begin(A), end(A)); 5 | 6 | for (int i = A.size() - 1; i > 1; --i) 7 | if (A[i - 2] + A[i - 1] > A[i]) 8 | return A[i - 2] + A[i - 1] + A[i]; 9 | 10 | return 0; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /0976-largest-perimeter-triangle/0976-largest-perimeter-triangle.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestPerimeter(self, A: List[int]) -> int: 3 | A = sorted(A) 4 | 5 | for i in range(len(A) - 1, 1, -1): 6 | if A[i - 2] + A[i - 1] > A[i]: 7 | return A[i - 2] + A[i - 1] + A[i] 8 | 9 | return 0 10 | -------------------------------------------------------------------------------- /0976-largest-perimeter-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0989-add-to-array-form-of-integer/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector addToArrayForm(vector& num, int k) { 4 | for (int i = num.size() - 1; i >= 0; --i) { 5 | num[i] += k; 6 | k = num[i] / 10; 7 | num[i] %= 10; 8 | } 9 | 10 | while (k > 0) { 11 | num.insert(begin(num), k % 10); 12 | k /= 10; 13 | } 14 | 15 | return num; 16 | } 17 | }; -------------------------------------------------------------------------------- /0989-add-to-array-form-of-integer/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List addToArrayForm(int[] num, int k) { 3 | List ans = new LinkedList<>(); 4 | 5 | for (int i = num.length - 1; i >= 0; --i) { 6 | ans.add(0, (num[i] + k) % 10); 7 | k = (num[i] + k) / 10; 8 | } 9 | 10 | while (k > 0) { 11 | ans.add(0, k % 10); 12 | k /= 10; 13 | } 14 | 15 | return ans; 16 | } 17 | } -------------------------------------------------------------------------------- /0989-add-to-array-form-of-integer/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addToArrayForm(self, num: List[int], k: int) -> List[int]: 3 | for i in reversed(range(len(num))): 4 | k, num[i] = divmod(num[i] + k, 10) 5 | 6 | while k > 0: 7 | num = [k % 10] + num 8 | k //= 10 9 | 10 | return num -------------------------------------------------------------------------------- /100-same-tree/100-same-tree.c: -------------------------------------------------------------------------------- 1 | bool isSameTree(struct TreeNode* p, struct TreeNode* q) { 2 | if (p == NULL && q == NULL) { 3 | return true; 4 | } else if ((p == NULL && q != NULL) || (p != NULL && q == NULL)) { 5 | return false; 6 | } 7 | if (p->val == q->val) { 8 | if (isSameTree(p->left , q->left) && isSameTree(p->right, q->right)) { 9 | return true; 10 | } 11 | } 12 | return false; 13 | } -------------------------------------------------------------------------------- /100-same-tree/100-same-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSameTree(TreeNode* p, TreeNode* q) { 4 | if(p == NULL && q == NULL)return true; 5 | if(p == NULL || q == NULL)return false; 6 | return (p->val == q->val)&&isSameTree(p->left, q->left)&&isSameTree(p->right, q->right); 7 | } 8 | }; -------------------------------------------------------------------------------- /100-same-tree/100-same-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSameTree(TreeNode p, TreeNode q) { 3 | if(p != null && q != null && q.val == p.val) { 4 | return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); 5 | } 6 | return p == null && q == null; 7 | } 8 | } -------------------------------------------------------------------------------- /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /101-symmetric-tree/101-symmetric-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSymmetric(TreeNode* root) { 4 | return isSymmetric(root, root); 5 | } 6 | 7 | private: 8 | bool isSymmetric(TreeNode* p, TreeNode* q) { 9 | if (!p || !q) 10 | return p == q; 11 | 12 | return p->val == q->val && 13 | isSymmetric(p->left, q->right) && 14 | isSymmetric(p->right, q->left); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /101-symmetric-tree/101-symmetric-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSymmetric(TreeNode root) { 3 | return isSymmetric(root, root); 4 | } 5 | 6 | private boolean isSymmetric(TreeNode p, TreeNode q) { 7 | if (p == null || q == null) 8 | return p == q; 9 | 10 | return p.val == q.val && isSymmetric(p.left, q.right) && isSymmetric(p.right, q.left); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /101-symmetric-tree/101-symmetric-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSymmetric(self, root: Optional[TreeNode]) -> bool: 3 | def isSymmetric(p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: 4 | if not p or not q: 5 | return p == q 6 | 7 | return p.val == q.val and \ 8 | isSymmetric(p.left, q.right) and \ 9 | isSymmetric(p.right, q.left) 10 | 11 | return isSymmetric(root, root) 12 | -------------------------------------------------------------------------------- /101-symmetric-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/102-binary-tree-level-order-traversal.js: -------------------------------------------------------------------------------- 1 | var levelOrder = function(root) { 2 | let q = [root], ans = [] 3 | while (q[0]) { 4 | let qlen = q.length, row = [] 5 | for (let i = 0; i < qlen; i++) { 6 | let curr = q.shift() 7 | row.push(curr.val) 8 | if (curr.left) q.push(curr.left) 9 | if (curr.right) q.push(curr.right) 10 | } 11 | ans.push(row) 12 | } 13 | return ans 14 | }; -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /103-binary-tree-zigzag-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1035-uncrossed lines/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int: 3 | m = len(nums1) 4 | n = len(nums2) 5 | dp = [[0] * (n + 1) for _ in range(m + 1)] 6 | 7 | for i in range(1, m + 1): 8 | for j in range(1, n + 1): 9 | dp[i][j] = dp[i - 1][j - 1] + 1 \ 10 | if nums1[i - 1] == nums2[j - 1] \ 11 | else max(dp[i - 1][j], dp[i][j - 1]) 12 | 13 | return dp[m][n] -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/104-maximum-depth-of-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDepth(TreeNode* root) { 4 | if (!root) 5 | return 0; 6 | return 1 + max(maxDepth(root->left), maxDepth(root->right)); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/104-maximum-depth-of-binary-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxDepth(TreeNode root) { 3 | if (root == null) 4 | return 0; 5 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/104-maximum-depth-of-binary-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, root: Optional[TreeNode]) -> int: 3 | if not root: 4 | return 0 5 | return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) 6 | -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1047-remove-all-adjacent-duplicates-in-string/1047-remove-all-adjacent-duplicates-in-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeDuplicates(const string& S) { 4 | string ans; 5 | 6 | for (const char c : S) 7 | if (!ans.empty() && ans.back() == c) 8 | ans.pop_back(); 9 | else 10 | ans.push_back(c); 11 | 12 | return ans; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /1047-remove-all-adjacent-duplicates-in-string/1047-remove-all-adjacent-duplicates-in-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeDuplicates(final String S) { 3 | StringBuilder sb = new StringBuilder(); 4 | 5 | for (final char c : S.toCharArray()) { 6 | final int n = sb.length(); 7 | if (n > 0 && sb.charAt(n - 1) == c) 8 | sb.deleteCharAt(n - 1); 9 | else 10 | sb.append(c); 11 | } 12 | 13 | return sb.toString(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /1047-remove-all-adjacent-duplicates-in-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1048-longest-string-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1074-number-of-submatrices-that-sum-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/108-convert-sorted-array-to-binary-search-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]: 3 | def build(l: int, r: int) -> Optional[TreeNode]: 4 | if l > r: 5 | return None 6 | 7 | m = (l + r) // 2 8 | return TreeNode(nums[m], 9 | build(l, m - 1), 10 | build(m + 1, r)) 11 | 12 | return build(0, len(nums) - 1) 13 | -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /110-balanced-binary-tree/110-balanced-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isBalanced(TreeNode* root) { 4 | if (!root) 5 | return true; 6 | return abs(maxDepth(root->left) - maxDepth(root->right)) <= 1 && 7 | isBalanced(root->left) && 8 | isBalanced(root->right); 9 | } 10 | 11 | private: 12 | int maxDepth(TreeNode* root) { 13 | if (!root) 14 | return 0; 15 | return 1 + max(maxDepth(root->left), maxDepth(root->right)); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /110-balanced-binary-tree/110-balanced-binary-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isBalanced(self, root: Optional[TreeNode]) -> bool: 3 | if not root: 4 | return True 5 | 6 | def maxDepth(root: Optional[TreeNode]) -> int: 7 | if not root: 8 | return 0 9 | return 1 + max(maxDepth(root.left), maxDepth(root.right)) 10 | 11 | return abs(maxDepth(root.left) - maxDepth(root.right)) <= 1 and \ 12 | self.isBalanced(root.left) and self.isBalanced(root.right) 13 | -------------------------------------------------------------------------------- /110-balanced-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/111-minimum-depth-of-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minDepth(TreeNode* root) { 4 | if (!root) 5 | return 0; 6 | if (!root->left) 7 | return minDepth(root->right) + 1; 8 | if (!root->right) 9 | return minDepth(root->left) + 1; 10 | return min(minDepth(root->left), minDepth(root->right)) + 1; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/111-minimum-depth-of-binary-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minDepth(TreeNode root) { 3 | if (root == null) 4 | return 0; 5 | if (root.left == null) 6 | return minDepth(root.right) + 1; 7 | if (root.right == null) 8 | return minDepth(root.left) + 1; 9 | return Math.min(minDepth(root.left), minDepth(root.right)) + 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /112-path-sum/112-path-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool hasPathSum(TreeNode* root, int sum) { 4 | if (!root) 5 | return false; 6 | if (root->val == sum && !root->left && !root->right) 7 | return true; 8 | return hasPathSum(root->left, sum - root->val) || 9 | hasPathSum(root->right, sum - root->val); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /112-path-sum/112-path-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean hasPathSum(TreeNode root, int sum) { 3 | if (root == null) 4 | return false; 5 | if (root.val == sum && root.left == null && root.right == null) 6 | return true; 7 | return hasPathSum(root.left, sum - root.val) || 8 | hasPathSum(root.right, sum - root.val); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /112-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/114-flatten-binary-tree-to-linked-list.js: -------------------------------------------------------------------------------- 1 | var flatten = function(root) { 2 | let head = null, curr = root 3 | while (head != root) { 4 | if (curr.right === head) curr.right = null 5 | if (curr.left === head) curr.left = null 6 | if (curr.right) curr = curr.right 7 | else if (curr.left) curr = curr.left 8 | else curr.right = head, head = curr, curr = root 9 | } 10 | }; -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/114-flatten-binary-tree-to-linked-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def flatten(self, root: TreeNode) -> None: 3 | head, curr = None, root 4 | while head != root: 5 | if curr.right == head: curr.right = None 6 | if curr.left == head: curr.left = None 7 | if curr.right: curr = curr.right 8 | elif curr.left: curr = curr.left 9 | else: curr.right, head, curr = head, curr, root -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /115-distinct-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1155-number-of-dice-rolls-with-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /118-pascals-triangle/118-pascals-triangle.js: -------------------------------------------------------------------------------- 1 | var generate = function(numRows) { 2 | let ans = new Array(numRows) 3 | for (let i = 0; i < numRows; i++) { 4 | let row = new Uint32Array(i+1).fill(1), 5 | mid = i >> 1 6 | for (let j = 1; j <= mid; j++) { 7 | let val = ans[i-1][j-1] + ans[i-1][j] 8 | row[j] = val, row[row.length-j-1] = val 9 | } 10 | ans[i] = row 11 | } 12 | return ans 13 | }; -------------------------------------------------------------------------------- /118-pascals-triangle/118-pascals-triangle.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generate(self, numRows: int) -> List[List[int]]: 3 | ans = [None] * numRows 4 | for i in range(numRows): 5 | row, mid = [1] * (i + 1), (i >> 1) + 1 6 | for j in range(1, mid): 7 | val = ans[i-1][j-1] + ans[i-1][j] 8 | row[j], row[len(row)-j-1] = val, val 9 | ans[i] = row 10 | return ans -------------------------------------------------------------------------------- /118-pascals-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /12-integer-to-roman/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /120-triangle/120-triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumTotal(vector>& T) { 4 | for (int i = T.size() - 2; ~i; i--) 5 | for (int j = T[i].size() - 1; ~j; j--) 6 | T[i][j] += min(T[i+1][j], T[i+1][j+1]); 7 | return T[0][0]; 8 | } 9 | }; -------------------------------------------------------------------------------- /120-triangle/120-triangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimumTotal(List> T) { 3 | for (int i = T.size() - 2; i >= 0; i--) 4 | for (int j = T.get(i).size() - 1; j >= 0; j--) { 5 | int min = Math.min(T.get(i+1).get(j), T.get(i+1).get(j+1)); 6 | T.get(i).set(j, T.get(i).get(j) + min); 7 | } 8 | return T.get(0).get(0); 9 | } 10 | } -------------------------------------------------------------------------------- /120-triangle/120-triangle.js: -------------------------------------------------------------------------------- 1 | var minimumTotal = function(T) { 2 | for (let i = T.length - 2; ~i; i--) 3 | for (let j = T[i].length - 1; ~j; j--) 4 | T[i][j] += Math.min(T[i+1][j], T[i+1][j+1]) 5 | return T[0][0] 6 | } -------------------------------------------------------------------------------- /120-triangle/120-triangle.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumTotal(self, T: List[List[int]]) -> int: 3 | for i in range(len(T)-2,-1,-1): 4 | for j in range(len(T[i])-1,-1,-1): 5 | T[i][j] += min(T[i+1][j], T[i+1][j+1]) 6 | return T[0][0] -------------------------------------------------------------------------------- /120-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1200-minimum-absolute-difference/1200-minimum-absolute-difference.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]: 3 | ans = [] 4 | min = math.inf 5 | 6 | arr.sort() 7 | 8 | for i in range(len(arr) - 1): 9 | diff = arr[i + 1] - arr[i] 10 | if diff < min: 11 | min = diff 12 | ans = [] 13 | if diff == min: 14 | ans.append([arr[i], arr[i + 1]]) 15 | 16 | return ans 17 | -------------------------------------------------------------------------------- /1200-minimum-absolute-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool uniqueOccurrences(vector& arr) { 4 | unordered_map count; 5 | unordered_set occurrences; 6 | 7 | for (const int a : arr) 8 | ++count[a]; 9 | 10 | for (const auto& [_, value] : count) 11 | if (!occurrences.insert(value).second) 12 | return false; 13 | 14 | return true; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /1207-unique-number-of-occurrences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stocks/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int sellOne = 0; 5 | int holdOne = INT_MIN; 6 | 7 | for (const int price : prices) { 8 | sellOne = max(sellOne, holdOne + price); 9 | holdOne = max(holdOne, -price); 10 | } 11 | 12 | return sellOne; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stocks/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int sellOne = 0; 4 | int holdOne = Integer.MIN_VALUE; 5 | 6 | for (final int price : prices) { 7 | sellOne = Math.max(sellOne, holdOne + price); 8 | holdOne = Math.max(holdOne, -price); 9 | } 10 | 11 | return sellOne; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stocks/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | sellOne = 0 4 | holdOne = -math.inf 5 | 6 | for price in prices: 7 | sellOne = max(sellOne, holdOne + price) 8 | holdOne = max(holdOne, -price) 9 | 10 | return sellOne 11 | -------------------------------------------------------------------------------- /1218-Longest Arithmetic Subsequence of Given Difference/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestSubsequence(int[] arr, int difference) { 3 | int ans = 0; 4 | Map lengthAt = new HashMap<>(); 5 | 6 | for (final int a : arr) { 7 | lengthAt.put(a, lengthAt.getOrDefault(a - difference, 0) + 1); 8 | ans = Math.max(ans, lengthAt.get(a)); 9 | } 10 | 11 | return ans; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /1218-Longest Arithmetic Subsequence of Given Difference/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestSubsequence(self, arr: List[int], difference: int) -> int: 3 | ans = 0 4 | lengthAt = {} 5 | 6 | for a in arr: 7 | lengthAt[a] = lengthAt.get(a - difference, 0) + 1 8 | ans = max(ans, lengthAt[a]) 9 | 10 | return ans 11 | -------------------------------------------------------------------------------- /123-best-time-to-buy-and-sell-stock-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1232-check-if-is-a-straight-line/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkStraightLine(self, coordinates: List[List[int]]) -> bool: 3 | x0, y0, x1, y1 = *coordinates[0], *coordinates[1] 4 | dx = x1 - x0 5 | dy = y1 - y0 6 | 7 | return all((x - x0) * dy == (y - y0) * dx for x, y in coordinates) -------------------------------------------------------------------------------- /1235-maximum-profit-in-job-scheduling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /126-word-ladder-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1268-search-suggestions-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /128-longest-consecutive-sequence/128-longest-consecutive-sequence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestConsecutive(self, nums: List[int]) -> int: 3 | ans = 0 4 | seen = set(nums) 5 | 6 | for num in nums: 7 | if num - 1 in seen: 8 | continue 9 | length = 0 10 | while num in seen: 11 | num += 1 12 | length += 1 13 | ans = max(ans, length) 14 | 15 | return ans 16 | -------------------------------------------------------------------------------- /128-longest-consecutive-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /13-roman-to-integer/13-roman-to-integer.js: -------------------------------------------------------------------------------- 1 | const roman = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} 2 | 3 | var romanToInt = function(S) { 4 | let ans = 0 5 | for (let i = S.length-1; ~i; i--) { 6 | let num = roman[S.charAt(i)] 7 | if (4 * num < ans) ans -= num 8 | else ans += num 9 | } 10 | return ans 11 | }; -------------------------------------------------------------------------------- /13-roman-to-integer/13-roman-to-integer.py: -------------------------------------------------------------------------------- 1 | roman = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} 2 | 3 | class Solution: 4 | def romanToInt(self, S: str) -> int: 5 | ans = 0 6 | for i in range(len(S)-1,-1,-1): 7 | num = roman[S[i]] 8 | if 4 * num < ans: ans -= num 9 | else: ans += num 10 | return ans -------------------------------------------------------------------------------- /13-roman-to-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1318-Minimum-Flips to-Make-a-OR-b-Equal-to-c/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minFlips(int a, int b, int c) { 3 | final int kMaxBit = 30; 4 | int ans = 0; 5 | 6 | for (int i = 0; i < kMaxBit; ++i) 7 | if ((c >> i & 1) == 1) 8 | ans += ((a >> i & 1) == 0 && (b >> i & 1) == 0) ? 1 : 0; 9 | else // (c >> i & 1) == 0 10 | ans += ((a >> i & 1) == 1 ? 1 : 0) + ((b >> i & 1) == 1 ? 1 : 0); 11 | 12 | return ans; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /132-palindrome-partitioning-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1323-maximum-69-number/1323-maximum-69-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximum69Number(int num) { 4 | string ans = to_string(num); 5 | 6 | for (char& c : ans) 7 | if (c == '6') { 8 | c = '9'; 9 | break; 10 | } 11 | 12 | return stoi(ans); 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /1323-maximum-69-number/1323-maximum-69-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximum69Number(int num) { 3 | char[] ans = String.valueOf(num).toCharArray(); 4 | 5 | for (int i = 0; i < ans.length; ++i) 6 | if (ans[i] == '6') { 7 | ans[i] = '9'; 8 | break; 9 | } 10 | 11 | return Integer.valueOf(String.valueOf(ans)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /1323-maximum-69-number/1323-maximum-69-number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximum69Number(self, num: int) -> int: 3 | return int(str(num).replace('6', '9', 1)) 4 | -------------------------------------------------------------------------------- /1323-maximum-69-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1328-break-a-palindrome/1328-break-a-palindrome.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def breakPalindrome(self, palindrome: str) -> str: 3 | n = len(palindrome) 4 | for i in range(n//2): 5 | if palindrome[i] != 'a': 6 | return palindrome.replace(palindrome[i], 'a', 1) 7 | return palindrome[:-1] + 'b' if n > 1 else "" -------------------------------------------------------------------------------- /1328-break-a-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1329-sort-the-matrix-diagonally/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1335-minimum-difficulty-of-a-job-schedule/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1338-reduce-array-size-to-the-half/1338-reduce-array-size-to-the-half.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSetSize(self, arr: List[int]) -> int: 3 | n = len(arr) 4 | 5 | count = Counter(arr).most_common() 6 | count.sort(key=lambda c: -c[1]) 7 | 8 | sum = 0 9 | for i, c in enumerate(count): 10 | sum += c[1] 11 | if sum >= n // 2: 12 | return i + 1 13 | -------------------------------------------------------------------------------- /1338-reduce-array-size-to-the-half/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /135-candy/135-candy.cpp: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def candy(self, ratings: List[int]) -> int: 3 | n = len(ratings) 4 | 5 | ans = 0 6 | l = [1] * n 7 | r = [1] * n 8 | 9 | for i in range(1, n): 10 | if ratings[i] > ratings[i - 1]: 11 | l[i] = l[i - 1] + 1 12 | 13 | for i in range(n - 2, -1, -1): 14 | if ratings[i] > ratings[i + 1]: 15 | r[i] = r[i + 1] + 1 16 | 17 | for a, b in zip(l, r): 18 | ans += max(a, b) 19 | 20 | return ans 21 | -------------------------------------------------------------------------------- /135-candy/135-candy.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def candy(self, ratings: List[int]) -> int: 3 | n = len(ratings) 4 | 5 | ans = 0 6 | l = [1] * n 7 | r = [1] * n 8 | 9 | for i in range(1, n): 10 | if ratings[i] > ratings[i - 1]: 11 | l[i] = l[i - 1] + 1 12 | 13 | for i in range(n - 2, -1, -1): 14 | if ratings[i] > ratings[i + 1]: 15 | r[i] = r[i + 1] + 1 16 | 17 | for a, b in zip(l, r): 18 | ans += max(a, b) 19 | 20 | return ans 21 | -------------------------------------------------------------------------------- /135-candy/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1351-Count-Negative-Numbers-in-a-Sorted-Matrix/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countNegatives(int[][] grid) { 3 | final int m = grid.length; 4 | final int n = grid[0].length; 5 | int ans = 0; 6 | int i = m - 1; 7 | int j = 0; 8 | 9 | while (i >= 0 && j < n) { 10 | if (grid[i][j] < 0) { 11 | ans += n - j; 12 | --i; 13 | } else { 14 | ++j; 15 | } 16 | } 17 | 18 | return ans; 19 | } 20 | } -------------------------------------------------------------------------------- /1351-Count-Negative-Numbers-in-a-Sorted-Matrix/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countNegatives(self, grid: List[List[int]]) -> int: 3 | m = len(grid) 4 | n = len(grid[0]) 5 | ans = 0 6 | i = m - 1 7 | j = 0 8 | 9 | while i >= 0 and j < n: 10 | if grid[i][j] < 0: 11 | ans += n - j 12 | i -= 1 13 | else: 14 | j += 1 15 | 16 | return ans -------------------------------------------------------------------------------- /1354-construct-target-array-with-multiple-sums/1354-construct-target-array-with-multiple-sums.js: -------------------------------------------------------------------------------- 1 | var isPossible = function(target) { 2 | let pq = new MaxPriorityQueue({priority: x => x}), sum = 0 3 | for (let num of target) sum += num, pq.enqueue(num) 4 | while (pq.front().element !== 1) { 5 | let num = pq.dequeue().element 6 | sum -= num 7 | if (num <= sum || sum < 1) return false 8 | num %= sum, sum += num, pq.enqueue(num || sum) 9 | } 10 | return true 11 | }; -------------------------------------------------------------------------------- /1354-construct-target-array-with-multiple-sums/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /137-single-number-ii/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | int ans = 0; 5 | 6 | for (int i = 0; i < 32; ++i) { 7 | int sum = 0; 8 | for (const int num : nums) 9 | sum += num >> i & 1; 10 | sum %= 3; 11 | ans |= sum << i; 12 | } 13 | 14 | return ans; 15 | } 16 | }; -------------------------------------------------------------------------------- /137-single-number-ii/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int ans = 0; 4 | 5 | for (int i = 0; i < 32; ++i) { 6 | int sum = 0; 7 | for (final int num : nums) 8 | sum += num >> i & 1; 9 | sum %= 3; 10 | ans |= sum << i; 11 | } 12 | 13 | return ans; 14 | } 15 | } -------------------------------------------------------------------------------- /137-single-number-ii/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | ones = 0 4 | twos = 0 5 | 6 | for num in nums: 7 | ones ^= num & ~twos 8 | twos ^= num & ~ones 9 | 10 | return ones -------------------------------------------------------------------------------- /1383-maximum-performance-of-a-team/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /139-word-break/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wordBreak(self, s: str, wordDict: List[str]) -> bool: 3 | wordSet = set(wordDict) 4 | 5 | @functools.lru_cache(None) 6 | def wordBreak(s: str) -> bool: 7 | if s in wordSet: 8 | return True 9 | return any(s[:i] in wordSet and wordBreak(s[i:]) for i in range(len(s))) 10 | 11 | return wordBreak(s) -------------------------------------------------------------------------------- /140-word-break-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1402-reducing-dishes/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSatisfaction(vector& satisfaction) { 4 | int ans = 0; 5 | int sumSatisfaction = 0; 6 | 7 | sort(begin(satisfaction), end(satisfaction), greater<>()); 8 | 9 | for (const int s : satisfaction) { 10 | sumSatisfaction += s; 11 | if (sumSatisfaction <= 0) 12 | return ans; 13 | ans += sumSatisfaction; 14 | } 15 | 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /142-linked-list-cycle-ii/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCycle(self, head: ListNode) -> ListNode: 3 | slow = head 4 | fast = head 5 | 6 | while fast and fast.next: 7 | slow = slow.next 8 | fast = fast.next.next 9 | if slow == fast: 10 | slow = head 11 | while slow != fast: 12 | slow = slow.next 13 | fast = fast.next 14 | return slow 15 | 16 | return None 17 | -------------------------------------------------------------------------------- /1423-maximum-points-you-can-obtain-from-cards/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1431-Kids-With-the Greatest Number of Candies/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: 3 | max_candies = max(candies) 4 | result = [] 5 | for i in range(len(candies)): 6 | if candies[i] + extraCandies >= max_candies: 7 | result.append(True) 8 | else: 9 | result.append(False) 10 | return result -------------------------------------------------------------------------------- /1456-Maximum Number of Vowels in a Substring of Given Length/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxVowels(self, s: str, k: int) -> int: 3 | ans = 0 4 | maxi = 0 5 | vowels = {'a', 'e', 'i', 'o', 'u'} 6 | 7 | for i, c in enumerate(s): 8 | if c in vowels: 9 | maxi += 1 10 | if i >= k and s[i - k] in vowels: 11 | maxi -= 1 12 | ans = max(ans, maxi) 13 | 14 | return ans -------------------------------------------------------------------------------- /1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1473-paint-house-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1488-avoid-flood-in-the-city/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1491-Average Salary Excluding the Minimum and Maximum Salary/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def average(self, salary: List[int]) -> float: 3 | min_salary = min(salary) 4 | max_salary = max(salary) 5 | total_salary = sum(salary) - min_salary - max_salary 6 | num_employees = len(salary) - 2 7 | return total_salary / num_employees -------------------------------------------------------------------------------- /1493-Longest Subarray of 1’s After Deleting One Element/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestSubarray(vector& nums) { 4 | int ans = 0; 5 | int count0 = 0; 6 | 7 | for (int l = 0, r = 0; r < nums.size(); ++r) { 8 | if (nums[r] == 0) 9 | ++count0; 10 | while (count0 == 2) 11 | if (nums[l++] == 0) 12 | --count0; 13 | ans = max(ans, r - l); 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /1493-Longest Subarray of 1’s After Deleting One Element/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestSubarray(int[] nums) { 3 | int ans = 0; 4 | int count0 = 0; 5 | 6 | for (int l = 0, r = 0; r < nums.length; ++r) { 7 | if (nums[r] == 0) 8 | ++count0; 9 | while (count0 == 2) 10 | if (nums[l++] == 0) 11 | --count0; 12 | ans = Math.max(ans, r - l); 13 | } 14 | 15 | return ans; 16 | } 17 | } -------------------------------------------------------------------------------- /1493-Longest Subarray of 1’s After Deleting One Element/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestSubarray(self, nums: List[int]) -> int: 3 | ans = 0 4 | count0 = 0 5 | 6 | l = 0 7 | for r, num in enumerate(nums): 8 | if num == 0: 9 | count0 += 1 10 | while count0 == 2: 11 | if nums[l] == 0: 12 | count0 -= 1 13 | l += 1 14 | ans = max(ans, r - l) 15 | 16 | return ans -------------------------------------------------------------------------------- /1498-Number of Subsequences That Satisfy the Given Sum Condition/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSubseq(self, nums: List[int], target: int) -> int: 3 | kMod = 1_000_000_007 4 | n = len(nums) 5 | ans = 0 6 | 7 | nums.sort() 8 | 9 | l = 0 10 | r = n - 1 11 | while l <= r: 12 | if nums[l] + nums[r] <= target: 13 | ans += pow(2, r - l, kMod) 14 | l += 1 15 | else: 16 | r -= 1 17 | 18 | return ans % kMod -------------------------------------------------------------------------------- /1502-can-make-arithmetic-progression-from-a-sequence/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canMakeArithmeticProgression(std::vector& arr) { 4 | std::sort(arr.begin(), arr.end()); 5 | int diff = arr[1] - arr[0]; 6 | 7 | for (int i = 2; i < arr.size(); i++) { 8 | if (arr[i] - arr[i-1] != diff) { 9 | return false; 10 | } 11 | } 12 | 13 | return true; 14 | } 15 | }; -------------------------------------------------------------------------------- /1502-can-make-arithmetic-progression-from-a-sequence/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canMakeArithmeticProgression(int[] arr) { 3 | Arrays.sort(arr); 4 | int diff = arr[1] - arr[0]; 5 | 6 | for (int i = 2; i < arr.length; i++) { 7 | if (arr[i] - arr[i-1] != diff) { 8 | return false; 9 | } 10 | } 11 | 12 | return true; 13 | } 14 | } -------------------------------------------------------------------------------- /1502-can-make-arithmetic-progression-from-a-sequence/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canMakeArithmeticProgression(self, arr): 3 | arr.sort() 4 | diff = arr[1] - arr[0] 5 | 6 | 7 | for i in range(2, len(arr)): 8 | if arr[i] - arr[i-1] != diff: 9 | return False 10 | 11 | return True -------------------------------------------------------------------------------- /151-reverse-words-in-a-string/151-reverse-words-in-a-string.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseWords(self, s: str) -> str: 3 | return ' '.join(s.split()[::-1]) -------------------------------------------------------------------------------- /151-rreverse-words-in-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1531-string-compression-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /154-find-minimum-in-rotated-sorted-array-ii/154-find-minimum-in-rotated-sorted-array-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMin(vector& nums) { 4 | int l = 0; 5 | int r = nums.size() - 1; 6 | 7 | while (l < r) { 8 | const int m = (l + r) / 2; 9 | if (nums[m] == nums[r]) 10 | --r; 11 | else if (nums[m] < nums[r]) 12 | r = m; 13 | else 14 | l = m + 1; 15 | } 16 | 17 | return nums[l]; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /154-find-minimum-in-rotated-sorted-array-ii/154-find-minimum-in-rotated-sorted-array-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findMin(int[] nums) { 3 | int l = 0; 4 | int r = nums.length - 1; 5 | 6 | while (l < r) { 7 | final int m = (l + r) / 2; 8 | if (nums[m] == nums[r]) 9 | --r; 10 | else if (nums[m] < nums[r]) 11 | r = m; 12 | else 13 | l = m + 1; 14 | } 15 | 16 | return nums[l]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /154-find-minimum-in-rotated-sorted-array-ii/154-find-minimum-in-rotated-sorted-array-ii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMin(self, nums: List[int]) -> int: 3 | l = 0 4 | r = len(nums) - 1 5 | 6 | while l < r: 7 | m = (l + r) // 2 8 | if nums[m] == nums[r]: 9 | r -= 1 10 | elif nums[m] < nums[r]: 11 | r = m 12 | else: 13 | l = m + 1 14 | 15 | return nums[l] 16 | -------------------------------------------------------------------------------- /154-find-minimum-in-rotated-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1544-make-the-string-great/1544-make-the-string-great.cpp: -------------------------------------------------------------------------------- 1 | 2 | class Solution { 3 | public: 4 | string makeGood(string s) { 5 | string ans; 6 | for (char c : s) { 7 | if (ans.length() && 8 | abs(ans.back() - c) == abs('a' - 'A')) 9 | ans.pop_back(); 10 | else 11 | ans.push_back(c); 12 | } 13 | return ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /1544-make-the-string-great/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1557-Minimum-Number-of-Vertices-to-Reach-all-Nodes/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findSmallestSetOfVertices(int n, vector>& edges) { 4 | vector res, seen(n); 5 | for (auto& e: edges) 6 | seen[e[1]] = 1; 7 | for (int i = 0; i < n; ++i) 8 | if (seen[i] == 0) 9 | res.push_back(i); 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /1572-matrix diagonal sum/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int diagonalSum(vector>& mat) { 4 | int n = mat.size(); 5 | int result = 0; 6 | for (int i = 0; i < n; i++) { 7 | result += mat[i][i] + mat[i][n - i - 1]; 8 | } 9 | if (n % 2 == 1) { 10 | result -= mat[n / 2][n / 2]; 11 | } 12 | return result; 13 | } 14 | }; -------------------------------------------------------------------------------- /1572-matrix diagonal sum/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def diagonalSum(self, mat: List[List[int]]) -> int: 3 | n = len(mat) 4 | result = 0 5 | for i in range(n): 6 | result += mat[i][i] + mat[i][n - i - 1] 7 | if n % 2 == 1: 8 | result -= mat[n // 2][n // 2] 9 | return result -------------------------------------------------------------------------------- /1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minCost(String colors, int[] neededTime) { 3 | int ans = 0; 4 | for(int i=1; i 0; 9 | } 10 | 11 | private: 12 | vector count; 13 | }; -------------------------------------------------------------------------------- /1603-Design-Parking-System/solution.java: -------------------------------------------------------------------------------- 1 | class ParkingSystem { 2 | public ParkingSystem(int big, int medium, int small) { 3 | count = new int[] {big, medium, small}; 4 | } 5 | 6 | public boolean addCar(int carType) { 7 | return count[carType - 1]-- > 0; 8 | } 9 | 10 | private int[] count; 11 | } -------------------------------------------------------------------------------- /1603-Design-Parking-System/solution.py: -------------------------------------------------------------------------------- 1 | class ParkingSystem: 2 | def __init__(self, big: int, medium: int, small: int): 3 | self.count = [big, medium, small] 4 | 5 | def addCar(self, carType: int) -> bool: 6 | self.count[carType - 1] -= 1 7 | return self.count[carType - 1] >= 0 -------------------------------------------------------------------------------- /164-maximum-gap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1642-furthest-building-you-can-reach/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def closeStrings(self, word1: str, word2: str) -> bool: 3 | if len(word1) != len(word2): 4 | return False 5 | 6 | count1 = Counter(word1) 7 | count2 = Counter(word2) 8 | 9 | if count1.keys() != count2.keys(): 10 | return False 11 | 12 | return sorted(count1.values()) == sorted(count2.values()) 13 | -------------------------------------------------------------------------------- /1657-determine-if-two-strings-are-close/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1658-minimum-operations-to-reduce-x-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: 3 | s1, s2 = ''.join(word1), ''.join(word2) 4 | return s1 == s2 -------------------------------------------------------------------------------- /1662-check-if-two-string-arrays-are-equivalent/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1675-Minimize-Deviation-in-Array/solution1.js: -------------------------------------------------------------------------------- 1 | var minimumDeviation = function(nums) { 2 | let pq = new MaxPriorityQueue({priority: x => x}) 3 | for (let n of nums) { 4 | if (n % 2) n *= 2 5 | pq.enqueue(n) 6 | } 7 | let ans = pq.front().element - pq.back().element 8 | while (pq.front().element % 2 === 0) { 9 | pq.enqueue(pq.dequeue().element / 2) 10 | ans = Math.min(ans, pq.front().element - pq.back().element) 11 | } 12 | return ans 13 | }; -------------------------------------------------------------------------------- /168-Excel Sheet Column Title/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string convertToTitle(int n) { 4 | return n == 0 ? "" 5 | : convertToTitle((n - 1) / 26) + (char)('A' + ((n - 1) % 26)); 6 | } 7 | }; -------------------------------------------------------------------------------- /168-Excel Sheet Column Title/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String convertToTitle(int n) { 3 | return n == 0 ? "" : convertToTitle((n - 1) / 26) + (char) ('A' + ((n - 1) % 26)); 4 | } 5 | } -------------------------------------------------------------------------------- /168-Excel Sheet Column Title/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, n: int) -> str: 3 | return self.convertToTitle((n - 1) // 26) + \ 4 | chr(ord('A') + (n - 1) % 26) if n else '' -------------------------------------------------------------------------------- /1680-concatenation-of-consecutive-binary-numbers/1680-concatenation-of-consecutive-binary-numbers.js: -------------------------------------------------------------------------------- 1 | var concatenatedBinary = function(n) { 2 | let ans = 1, len = 0b100 3 | for (let i = 2; i <= n; i++) { 4 | if (i === len) len <<= 1 5 | ans = (ans * len + i) % 1000000007 6 | } 7 | return ans 8 | }; -------------------------------------------------------------------------------- /1680-concatenation-of-consecutive-binary-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/1689-partitioning-into-minimum-number-of-deci-binary-numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minPartitions(string n) { 4 | char best = '0'; 5 | for (auto& c : n) 6 | if (c > best) best = c; 7 | return best - '0'; 8 | } 9 | }; -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/1689-partitioning-into-minimum-number-of-deci-binary-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPartitions(String n) { 3 | char best = '0'; 4 | for (char c : n.toCharArray()) 5 | if (c > best) best = c; 6 | return best - '0'; 7 | } 8 | } -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/1689-partitioning-into-minimum-number-of-deci-binary-numbers.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minPartitions(self, n: str) -> int: 3 | return max(n) -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1695-maximum-erasure-value/1695-maximum-erasure-value.js: -------------------------------------------------------------------------------- 1 | var maximumUniqueSubarray = function(nums) { 2 | let nmap = new Int8Array(10001), total = 0, best = 0 3 | for (let left = 0, right = 0; right < nums.length; right++) { 4 | nmap[nums[right]]++, total += nums[right] 5 | while (nmap[nums[right]] > 1) 6 | nmap[nums[left]]--, total -= nums[left++] 7 | best = Math.max(best, total) 8 | } 9 | return best 10 | }; -------------------------------------------------------------------------------- /1695-maximum-erasure-value/1695-maximum-erasure-value.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumUniqueSubarray(self, nums: List[int]) -> int: 3 | nmap, total, best, left = [0] * 10001, 0, 0, 0 4 | for right in nums: 5 | nmap[right] += 1 6 | total += right 7 | while nmap[right] > 1: 8 | nmap[nums[left]] -= 1 9 | total -= nums[left] 10 | left += 1 11 | best = max(best, total) 12 | return best -------------------------------------------------------------------------------- /1695-maximum-erasure-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1696-jump-game-vi/1696-jump-game-vi.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxResult(vector& nums, int k) { 4 | int n = nums.size(), a = 0, b = 0; 5 | int deq[n]; 6 | deq[0] = n - 1; 7 | for (int i = n - 2; i >= 0; i--) { 8 | if (deq[a] - i > k) a++; 9 | nums[i] += nums[deq[a]]; 10 | while (b >= a && nums[deq[b]] <= nums[i]) b--; 11 | deq[++b] = i; 12 | } 13 | return nums[0]; 14 | } 15 | }; -------------------------------------------------------------------------------- /1696-jump-game-vi/1696-jump-game-vi.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxResult(int[] nums, int k) { 3 | int n = nums.length, a = 0, b = 0; 4 | int[] deq = new int[n]; 5 | deq[0] = n - 1; 6 | for (int i = n - 2; i >= 0; i--) { 7 | if (deq[a] - i > k) a++; 8 | nums[i] += nums[deq[a]]; 9 | while (b >= a && nums[deq[b]] <= nums[i]) b--; 10 | deq[++b] = i; 11 | } 12 | return nums[0]; 13 | } 14 | } -------------------------------------------------------------------------------- /1696-jump-game-vi/1696-jump-game-vi.js: -------------------------------------------------------------------------------- 1 | var maxResult = function(nums, k) { 2 | let n = nums.length, deq = [n-1] 3 | for (let i = n - 2; ~i; i--) { 4 | if (deq[0] - i > k) deq.shift() 5 | nums[i] += nums[deq[0]] 6 | while (deq.length && nums[deq[deq.length-1]] <= nums[i]) deq.pop() 7 | deq.push(i) 8 | } 9 | return nums[0] 10 | }; -------------------------------------------------------------------------------- /1696-jump-game-vi/1696-jump-game-vi.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxResult(self, nums: List[int], k: int) -> int: 3 | n = len(nums) 4 | deq = deque([n-1]) 5 | for i in range(n-2, -1, -1): 6 | if deq[0] - i > k: deq.popleft() 7 | nums[i] += nums[deq[0]] 8 | while len(deq) and nums[deq[-1]] <= nums[i]: deq.pop() 9 | deq.append(i) 10 | return nums[0] -------------------------------------------------------------------------------- /1696-jump-game-vi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.js: -------------------------------------------------------------------------------- 1 | const vowels = "aeiouAEIOU" 2 | 3 | var halvesAreAlike = function(S) { 4 | let mid = S.length / 2, ans = 0 5 | for (let i = 0, j = mid; i < mid; i++, j++) 6 | ans += vowels.includes(S.charAt(i)) - vowels.includes(S.charAt(j)) 7 | return ans === 0 8 | }; -------------------------------------------------------------------------------- /1706-where-will-the-ball-fall/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/1710-maximum-units-on-a-truck.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumUnits(vector>& B, int T) { 4 | sort(B.begin(), B.end(), [](auto& a, auto& b) { return b[1] < a[1];}); 5 | int ans = 0; 6 | for (auto& b : B) { 7 | int count = min(b[0], T); 8 | ans += count * b[1], T -= count; 9 | if (!T) return ans; 10 | } 11 | return ans; 12 | } 13 | }; -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/1710-maximum-units-on-a-truck.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximumUnits(int[][] B, int T) { 3 | Arrays.sort(B, (a,b) -> b[1] - a[1]); 4 | int ans = 0; 5 | for (int[] b : B) { 6 | int count = Math.min(b[0], T); 7 | ans += count * b[1]; 8 | T -= count; 9 | if (T == 0) return ans; 10 | } 11 | return ans; 12 | } 13 | } -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/1710-maximum-units-on-a-truck.js: -------------------------------------------------------------------------------- 1 | var maximumUnits = function(B, T) { 2 | B.sort((a,b) => b[1] - a[1]) 3 | let ans = 0 4 | for (let i = 0; T && i < B.length; i++) { 5 | let count = Math.min(B[i][0], T) 6 | ans += count * B[i][1], T -= count 7 | } 8 | return ans 9 | }; -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/1710-maximum-units-on-a-truck.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumUnits(self, B: List[List[int]], T: int) -> int: 3 | B.sort(key=lambda x: x[1], reverse=True) 4 | ans = 0 5 | for b,n in B: 6 | boxes = min(b, T) 7 | ans += boxes * n 8 | T -= boxes 9 | if T == 0: return ans 10 | return ans -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1732-Find-the-Highest-Altitude/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int largestAltitude(int[] gain) { 3 | int altitude = 0, max = 0; 4 | 5 | for (var g : gain) { 6 | altitude += g; 7 | max = Math.max(max, altitude); 8 | } 9 | return max; 10 | } 11 | } -------------------------------------------------------------------------------- /1732-Find-the-Highest-Altitude/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestAltitude(self, gain: List[int]) -> int: 3 | curr=0 4 | highest=0 5 | for x in gain: 6 | curr+=x 7 | highest=max(curr,highest) 8 | 9 | return highest -------------------------------------------------------------------------------- /174-dungeon-game/174-dungeon-game.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def calculateMinimumHP(self, dungeon: List[List[int]]) -> int: 3 | m = len(dungeon) 4 | n = len(dungeon[0]) 5 | dp = [math.inf] * (n + 1) 6 | dp[n - 1] = 1 7 | 8 | for i in reversed(range(m)): 9 | for j in reversed(range(n)): 10 | dp[j] = min(dp[j], dp[j + 1]) - dungeon[i][j] 11 | dp[j] = max(dp[j], 1) 12 | 13 | return dp[0] 14 | -------------------------------------------------------------------------------- /174-dungeon-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1768-Merge Strings Alternately/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string mergeAlternately(string word1, string word2) { 4 | const int n = min(word1.length(), word2.length()); 5 | string prefix; 6 | 7 | for (int i = 0; i < n; ++i) { 8 | prefix += word1[i]; 9 | prefix += word2[i]; 10 | } 11 | 12 | return prefix + word1.substr(n) + word2.substr(n); 13 | } 14 | }; -------------------------------------------------------------------------------- /1768-Merge Strings Alternately/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String mergeAlternately(String word1, String word2) { 3 | final int n = Math.min(word1.length(), word2.length()); 4 | StringBuilder sb = new StringBuilder(); 5 | 6 | for (int i = 0; i < n; ++i) { 7 | sb.append(word1.charAt(i)); 8 | sb.append(word2.charAt(i)); 9 | } 10 | 11 | return sb.append(word1.substring(n)).append(word2.substring(n)).toString(); 12 | } 13 | } -------------------------------------------------------------------------------- /1768-Merge Strings Alternately/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mergeAlternately(self, word1: str, word2: str) -> str: 3 | return ''.join(a + b for a, b in zip_longest(word1, word2, fillvalue='')) -------------------------------------------------------------------------------- /1770-maximum-score-from-performing-multiplication-operations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1822-Sign of the Product of an Array/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int arraySign(vector& nums) { 4 | int sign = 1; 5 | 6 | for (const int num : nums) { 7 | if (num == 0) 8 | return 0; 9 | if (num < 0) 10 | sign = -sign; 11 | } 12 | 13 | return sign; 14 | } 15 | }; -------------------------------------------------------------------------------- /1822-Sign of the Product of an Array/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int arraySign(int[] nums) { 3 | int sign = 1; 4 | 5 | for (final int num : nums) { 6 | if (num == 0) 7 | return 0; 8 | if (num < 0) 9 | sign = -sign; 10 | } 11 | 12 | return sign; 13 | } 14 | } -------------------------------------------------------------------------------- /1822-Sign of the Product of an Array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arraySign(self, nums: List[int]) -> int: 3 | sign = 1 4 | 5 | for num in nums: 6 | if num == 0: 7 | return 0 8 | if num < 0: 9 | sign = -sign 10 | 11 | return sign -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/1832-check-if-the-sentence-is-pangram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkIfPangram(string sentence) { 4 | return unordered_set(begin(sentence), end(sentence)).size() == 26; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/1832-check-if-the-sentence-is-pangram.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkIfPangram(String sentence) { 3 | Set seen = new HashSet<>(); 4 | 5 | for (final char c : sentence.toCharArray()) 6 | seen.add(c); 7 | 8 | return seen.size() == 26; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/1832-check-if-the-sentence-is-pangram.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfPangram(self, sentence: str) -> bool: 3 | return len(set(sentence)) == 26 4 | -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /185-department-top-three-salaries/185-department-top-three-salaries.sql: -------------------------------------------------------------------------------- 1 | SELECT d.Name as Department, 2 | e.Name as Employee, 3 | e.Salary as Salary 4 | FROM Department d, Employee e 5 | WHERE( 6 | SELECT COUNT(distinct Salary) 7 | FROM Employee 8 | WHERE Salary > e.Salary AND DepartmentId = d.Id 9 | ) < 3 AND e.DepartmentId = d.Id 10 | ORDER BY d.Id, e.Salary desc; -------------------------------------------------------------------------------- /185-department-top-three-salaries/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1879-minimum-xor-sum-of-two-arrays/1879-minimum-xor-sum-of-two-arrays.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: 3 | @lru_cache(None) 4 | def dp(mask: int) -> int: 5 | i = bin(mask).count("1") 6 | if i == len(nums1): 7 | return 0 8 | return min((nums1[i] ^ nums2[j]) + dp(mask | 1 << j) 9 | for j in range(len(nums2)) if not mask >> j & 1) 10 | return dp(0) 11 | -------------------------------------------------------------------------------- /1879-minimum-xor-sum-of-two-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /188-best-time-to-buy-and-sell-stock-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1894-find-the-student/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int chalkReplacer(vector& chalk, int k) { 4 | k %= accumulate(chalk.begin(), chalk.end(), 0L); 5 | if (k == 0) 6 | return 0; 7 | 8 | for (int i = 0; i < chalk.size(); ++i) { 9 | k -= chalk[i]; 10 | if (k < 0) 11 | return i; 12 | } 13 | 14 | throw; 15 | } 16 | }; -------------------------------------------------------------------------------- /1894-find-the-student/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int chalkReplacer(int[] chalk, int k) { 3 | k %= Arrays.stream(chalk).asLongStream().sum(); 4 | if (k == 0) 5 | return 0; 6 | 7 | for (int i = 0; i < chalk.length; ++i) { 8 | k -= chalk[i]; 9 | if (k < 0) 10 | return i; 11 | } 12 | 13 | throw new IllegalArgumentException(); 14 | } 15 | } -------------------------------------------------------------------------------- /1894-find-the-student/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def chalkReplacer(self, chalk: list[int], k: int) -> int: 3 | k %= sum(chalk) 4 | if k == 0: 5 | return 0 6 | 7 | for i, c in enumerate(chalk): 8 | k -= c 9 | if k < 0: 10 | return i -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.js: -------------------------------------------------------------------------------- 1 | var removeNthFromEnd = function(head, n) { 2 | let fast = head, slow = head 3 | for (let i = 0; i < n; i++) fast = fast.next 4 | if (!fast) return head.next 5 | while (fast.next) fast = fast.next, slow = slow.next 6 | slow.next = slow.next.next 7 | return head 8 | }; -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: 3 | fast, slow = head, head 4 | for _ in range(n): fast = fast.next 5 | if not fast: return head.next 6 | while fast.next: fast, slow = fast.next, slow.next 7 | slow.next = slow.next.next 8 | return head -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1926-nearest-exit-from-entrance-in-maze/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1987-number-of-unique-good-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /20-valid-parentheses/20-valid-parentheses.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isValid(self, s: str) -> bool: 3 | stack = [] 4 | dic = {'(': ')', '[': ']', '{': '}'} 5 | for c in s: 6 | if stack and stack[-1] in "([{" and dic[stack[-1]] == c: 7 | stack.pop() 8 | else: 9 | stack.append(c) 10 | return not stack -------------------------------------------------------------------------------- /20-valid-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /200-number-of-islands/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2007-find-original-array-from-doubled-array/2007-find-original-array-from-doubled-array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findOriginalArray(self, changed: List[int]) -> List[int]: 3 | ans = [] 4 | q = deque() 5 | 6 | for num in sorted(changed): 7 | if q and num == q[0]: 8 | q.popleft() 9 | else: 10 | q.append(num * 2) 11 | ans.append(num) 12 | 13 | return [] if q else ans 14 | -------------------------------------------------------------------------------- /2007-find-original-array-from-doubled-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2022-converting-1d-to-2d/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> construct2DArray(vector& original, int m, int n) { 4 | if (original.size() != m * n) 5 | return {}; 6 | 7 | vector> ans(m, vector(n)); 8 | 9 | for (int i = 0; i < original.size(); ++i) 10 | ans[i / n][i % n] = original[i]; 11 | 12 | return ans; 13 | } 14 | }; -------------------------------------------------------------------------------- /2022-converting-1d-to-2d/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] construct2DArray(int[] original, int m, int n) { 3 | if (original.length != m * n) 4 | return new int[][] {}; 5 | 6 | int[][] ans = new int[m][n]; 7 | 8 | for (int i = 0; i < original.length; ++i) 9 | ans[i / n][i % n] = original[i]; 10 | 11 | return ans; 12 | } 13 | } -------------------------------------------------------------------------------- /2022-converting-1d-to-2d/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def construct2DArray(self, original: list[int], 3 | m: int, n: int) -> list[list[int]]: 4 | if len(original) != m * n: 5 | return [] 6 | 7 | ans = [[0] * n for _ in range(m)] 8 | 9 | for i, num in enumerate(original): 10 | ans[i // n][i % n] = num 11 | 12 | return ans -------------------------------------------------------------------------------- /2028-find-missing-observation/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingRolls(self, rolls: list[int], mean: int, n: int) -> list[int]: 3 | targetSum = (len(rolls) + n) * mean 4 | missingSum = targetSum - sum(rolls) 5 | if missingSum > n * 6 or missingSum < n: 6 | return [] 7 | 8 | ans = [missingSum // n] * n 9 | for i in range(missingSum % n): 10 | ans[i] += 1 11 | 12 | return ans -------------------------------------------------------------------------------- /2059-minimum-operations-to-convert-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /209-Minimum Size Subarray Sum/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minSubArrayLen(int s, vector& nums) { 4 | int ans = INT_MAX; 5 | int sum = 0; 6 | 7 | for (int l = 0, r = 0; r < nums.size(); ++r) { 8 | sum += nums[r]; 9 | while (sum >= s) { 10 | ans = min(ans, r - l + 1); 11 | sum -= nums[l++]; 12 | } 13 | } 14 | 15 | return ans < INT_MAX ? ans : 0; 16 | } 17 | }; -------------------------------------------------------------------------------- /209-Minimum Size Subarray Sum/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minSubArrayLen(int s, int[] nums) { 3 | int ans = Integer.MAX_VALUE; 4 | int sum = 0; 5 | 6 | for (int l = 0, r = 0; r < nums.length; ++r) { 7 | sum += nums[r]; 8 | while (sum >= s) { 9 | ans = Math.min(ans, r - l + 1); 10 | sum -= nums[l++]; 11 | } 12 | } 13 | 14 | return ans != Integer.MAX_VALUE ? ans : 0; 15 | } 16 | } -------------------------------------------------------------------------------- /209-Minimum Size Subarray Sum/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSubArrayLen(self, s: int, nums: List[int]) -> int: 3 | ans = math.inf 4 | summ = 0 5 | j = 0 6 | 7 | for i, num in enumerate(nums): 8 | summ += num 9 | while summ >= s: 10 | ans = min(ans, i - j + 1) 11 | summ -= nums[j] 12 | j += 1 13 | 14 | return ans if ans != math.inf else 0 -------------------------------------------------------------------------------- /2090-k-radius-subarray-averages/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getAverages(self, nums: List[int], k: int) -> List[int]: 3 | n = len(nums) 4 | size = 2 * k + 1 5 | ans = [-1] * n 6 | if size > n: 7 | return ans 8 | 9 | summ = sum(nums[:size]) 10 | 11 | for i in range(k, n - k): 12 | ans[i] = summ // size 13 | if i + k + 1 < n: 14 | summ += nums[i + k + 1] - nums[i - k] 15 | 16 | return ans -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/2095-delete-the-middle-node-of-a-linked-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteMiddle(self, head: Optional[ListNode]) -> Optional[ListNode]: 3 | dummy = ListNode(0, head) 4 | slow = dummy 5 | fast = dummy 6 | 7 | while fast.next and fast.next.next: 8 | slow = slow.next 9 | fast = fast.next.next 10 | 11 | # Delete the middle node 12 | slow.next = slow.next.next 13 | return dummy.next 14 | -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /212-wword-search-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2131-longest-palindrome-by-concatenating-two-letter-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2136-earliest-possible-day-of-full-bloom/2136-earliest-possible-day-of-full-bloom.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int: 3 | ans = 0 4 | time = 0 5 | 6 | for p, g in sorted([(p, g) for (p, g) in zip(plantTime, growTime)], key=lambda x: -x[1]): 7 | time += p 8 | ans = max(ans, time + g) 9 | 10 | return ans 11 | -------------------------------------------------------------------------------- /214-shortest-palindrome/214-shortest-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string shortestPalindrome(string s) { 4 | string t = s; 5 | reverse(begin(t), end(t)); 6 | 7 | const string_view sv_s(s); 8 | const string_view sv_t(t); 9 | 10 | for (int i = 0; i < s.length(); ++i) 11 | if (sv_s.substr(0, s.length() - i) == sv_t.substr(i)) 12 | return t.substr(0, i) + s; 13 | 14 | return t + s; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /214-shortest-palindrome/214-shortest-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String shortestPalindrome(String s) { 3 | final String t = new StringBuilder(s).reverse().toString(); 4 | 5 | for (int i = 0; i < t.length(); ++i) 6 | if (s.startsWith(t.substring(i))) 7 | return t.substring(0, i) + s; 8 | 9 | return t + s; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /214-shortest-palindrome/214-shortest-palindrome.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shortestPalindrome(self, s: str) -> str: 3 | t = s[::-1] 4 | 5 | for i in range(len(t)): 6 | if s.startswith(t[i:]): 7 | return t[:i] + s 8 | 9 | return t + s 10 | -------------------------------------------------------------------------------- /214-shortest-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/215-kth-largest-element-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findKthLargest(vector& nums, int k) { 4 | multiset min_heap; //min heap implemetation 5 | for (int num : nums){ 6 | min_heap.insert(num); 7 | if(min_heap.size() > k) min_heap.erase(min_heap.begin()); 8 | 9 | } 10 | 11 | return *min_heap.begin(); 12 | } 13 | }; -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/215-kth-largest-element-in-an-array.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def findKthLargest(self, nums, k): 3 | """ 4 | :type nums: List[int] 5 | :type k: int 6 | :rtype: int 7 | """ 8 | pq = [] 9 | for val in nums: 10 | heapq.heappush(pq, val) 11 | if len(pq) > k: 12 | heapq.heappop(pq) 13 | 14 | return heapq.heappop(pq) -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2156-find-substring-with-given-hash-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2172-maximum-and-sum-of-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /218-the-skyline-problem/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2187-minimum-time-to-complete-trip/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumTime(self, time: List[int], totalTrips: int) -> int: 3 | l = 1 4 | r = min(time) * totalTrips 5 | 6 | while l < r: 7 | m = (l + r) // 2 8 | if sum(m // t for t in time) >= totalTrips: 9 | r = m 10 | else: 11 | l = m + 1 12 | 13 | return l 14 | -------------------------------------------------------------------------------- /219-contains-duplicate-ii/0219-contains-duplicate-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsNearbyDuplicate(vector& nums, int k) { 4 | unordered_set seen; 5 | 6 | for (int i = 0; i < nums.size(); ++i) { 7 | if (!seen.insert(nums[i]).second) 8 | return true; 9 | if (i >= k) 10 | seen.erase(nums[i - k]); 11 | } 12 | 13 | return false; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /219-contains-duplicate-ii/0219-contains-duplicate-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsNearbyDuplicate(int[] nums, int k) { 3 | Set seen = new HashSet<>(); 4 | 5 | for (int i = 0; i < nums.length; ++i) { 6 | if (!seen.add(nums[i])) 7 | return true; 8 | if (i >= k) 9 | seen.remove(nums[i - k]); 10 | } 11 | 12 | return false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /219-contains-duplicate-ii/0219-contains-duplicate-ii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: 3 | seen = set() 4 | 5 | for i, num in enumerate(nums): 6 | if i > k: 7 | seen.remove(nums[i - k - 1]) 8 | if num in seen: 9 | return True 10 | seen.add(num) 11 | 12 | return False 13 | -------------------------------------------------------------------------------- /22-generate-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2215-Find the Difference of Two Arrays/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> findDifference(int[] nums1, int[] nums2) { 3 | Set set1 = Arrays.stream(nums1).boxed().collect(Collectors.toSet()); 4 | Set set2 = Arrays.stream(nums2).boxed().collect(Collectors.toSet()); 5 | Arrays.stream(nums1).forEach(set2::remove); 6 | Arrays.stream(nums2).forEach(set1::remove); 7 | return Arrays.asList(new ArrayList<>(set1), new ArrayList<>(set2)); 8 | } 9 | } -------------------------------------------------------------------------------- /2215-Find the Difference of Two Arrays/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: 3 | set1 = set(nums1) 4 | set2 = set(nums2) 5 | return [set1 - set2, set2 - set1] -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/0222-count-complete-tree-nodes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countNodes(TreeNode* root) { 4 | if (root == nullptr) 5 | return 0; 6 | return 1 + countNodes(root->left) + countNodes(root->right); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/0222-count-complete-tree-nodes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countNodes(TreeNode root) { 3 | if (root == null) 4 | return 0; 5 | return 1 + countNodes(root.left) + countNodes(root.right); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2225-find-players-with-zero-or-one-losses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /223-rectangle-area/0223-rectangle-area.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int computeArea(long A, long B, long C, long D, 4 | long E, long F, long G, long H) { 5 | const long x = max(A, E) < min(C, G) ? (min(C, G) - max(A, E)) : 0; 6 | const long y = max(B, F) < min(D, H) ? (min(D, H) - max(B, F)) : 0; 7 | return (C - A) * (D - B) + (G - E) * (H - F) - x * y; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /223-rectangle-area/0223-rectangle-area.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int computeArea(long A, long B, long C, long D, long E, long F, long G, long H) { 3 | final long x = Math.max(A, E) < Math.min(C, G) ? (Math.min(C, G) - Math.max(A, E)) : 0; 4 | final long y = Math.max(B, F) < Math.min(D, H) ? (Math.min(D, H) - Math.max(B, F)) : 0; 5 | return (int) ((C - A) * (D - B) + (G - E) * (H - F) - x * y); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /223-rectangle-area/0223-rectangle-area.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def computeArea(self, A: int, B: int, C: int, D: int, E: int, F: int, G: int, H: int) -> int: 3 | x = min(C, G) - max(A, E) if max(A, E) < min(C, G) else 0 4 | y = min(D, H) - max(B, F) if max(B, F) < min(D, H) else 0 5 | return (C - A) * (D - B) + (G - E) * (H - F) - x * y 6 | -------------------------------------------------------------------------------- /223-rectangle-area/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /224-basic-calculator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /224-bbasic-calculator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /225-implement-stack-using-queues/solution.java: -------------------------------------------------------------------------------- 1 | class MyStack { 2 | public void push(int x) { 3 | q.offer(x); 4 | for (int i = 0; i < q.size() - 1; ++i) 5 | q.offer(q.poll()); 6 | } 7 | 8 | public int pop() { 9 | return q.poll(); 10 | } 11 | 12 | public int top() { 13 | return q.peek(); 14 | } 15 | 16 | public boolean empty() { 17 | return q.isEmpty(); 18 | } 19 | 20 | private Queue q = new ArrayDeque<>(); 21 | } -------------------------------------------------------------------------------- /225-implement-stack-using-queues/solution.py: -------------------------------------------------------------------------------- 1 | class MyStack: 2 | def __init__(self): 3 | self.q = collections.deque() 4 | 5 | def push(self, x: int) -> None: 6 | self.q.append(x) 7 | for _ in range(len(self.q) - 1): 8 | self.q.append(self.q.popleft()) 9 | 10 | def pop(self) -> int: 11 | return self.q.popleft() 12 | 13 | def top(self) -> int: 14 | return self.q[0] 15 | 16 | def empty(self) -> bool: 17 | return not self.q -------------------------------------------------------------------------------- /2256-minimum-average-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* invertTree(TreeNode* root) { 4 | if (root == nullptr) 5 | return nullptr; 6 | 7 | TreeNode* const left = root->left; 8 | TreeNode* const right = root->right; 9 | root->left = invertTree(right); 10 | root->right = invertTree(left); 11 | return root; 12 | } 13 | }; -------------------------------------------------------------------------------- /226-invert-binary-tree/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public TreeNode invertTree(TreeNode root) { 3 | if (root == null) 4 | return null; 5 | 6 | TreeNode left = root.left; 7 | TreeNode right = root.right; 8 | root.left = invertTree(right); 9 | root.right = invertTree(left); 10 | return root; 11 | } 12 | } -------------------------------------------------------------------------------- /228-Summary-Ranges/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def summaryRanges(self, nums: List[int]) -> List[str]: 3 | ans = [] 4 | 5 | i = 0 6 | while i < len(nums): 7 | begin = nums[i] 8 | while i < len(nums) - 1 and nums[i] == nums[i + 1] - 1: 9 | i += 1 10 | end = nums[i] 11 | if begin == end: 12 | ans.append(str(begin)) 13 | else: 14 | ans.append(str(begin) + "->" + str(end)) 15 | i += 1 16 | 17 | return ans -------------------------------------------------------------------------------- /2289-steps-to-make-array-non-decreasing/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2301-match-substring-after-replacement/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2302-count-subarrays-with-score-less-than-k/2302-count-subarrays-with-score-less-than-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countSubarrays(vector& nums, long long k) { 4 | long long ans = 0; 5 | long long sum = 0; 6 | 7 | for (int l = 0, r = 0; r < nums.size(); ++r) { 8 | sum += nums[r]; 9 | while (sum * (r - l + 1) >= k) 10 | sum -= nums[l++]; 11 | ans += r - l + 1; 12 | } 13 | 14 | return ans; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /2302-count-subarrays-with-score-less-than-k/2302-count-subarrays-with-score-less-than-k.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long countSubarrays(int[] nums, long k) { 3 | long ans = 0; 4 | long sum = 0; 5 | 6 | for (int l = 0, r = 0; r < nums.length; ++r) { 7 | sum += nums[r]; 8 | while (sum * (r - l + 1) >= k) 9 | sum -= nums[l++]; 10 | ans += r - l + 1; 11 | } 12 | 13 | return ans; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2302-count-subarrays-with-score-less-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /233-number-of-digit-one/233-number-of-digit-one.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countDigitOne(self, n: int) -> int: 3 | ans = 0 4 | 5 | pow10 = 1 6 | while pow10 <= n: 7 | divisor = pow10 * 10 8 | quotient = n // divisor 9 | remainder = n % divisor 10 | if quotient > 0: 11 | ans += quotient * pow10 12 | if remainder >= pow10: 13 | ans += min(remainder - pow10 + 1, pow10) 14 | pow10 *= 10 15 | 16 | return ans 17 | -------------------------------------------------------------------------------- /233-number-of-digit-one/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2336-smallest-positive-number-infinite-set/solution.cpp: -------------------------------------------------------------------------------- 1 | class SmallestInfiniteSet { 2 | public: 3 | int popSmallest() { 4 | if (added.empty()) 5 | return curr++; 6 | const int min = *begin(added); 7 | added.erase(begin(added)); 8 | return min; 9 | } 10 | 11 | void addBack(int num) { 12 | if (num < curr) 13 | added.insert(num); 14 | } 15 | 16 | private: 17 | int curr = 1; 18 | set added; 19 | }; -------------------------------------------------------------------------------- /2336-smallest-positive-number-infinite-set/solution.java: -------------------------------------------------------------------------------- 1 | class SmallestInfiniteSet { 2 | public int popSmallest() { 3 | if (added.isEmpty()) 4 | return curr++; 5 | final int min = added.first(); 6 | added.remove(min); 7 | return min; 8 | } 9 | 10 | public void addBack(int num) { 11 | if (num < curr) 12 | added.add(num); 13 | } 14 | 15 | private int curr = 1; 16 | private TreeSet added = new TreeSet<>(); 17 | } 18 | -------------------------------------------------------------------------------- /234-palindrome-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/235-lowest-common-ancestor-of-a-binary-search-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 4 | if (root->val > max(p->val, q->val)) 5 | return lowestCommonAncestor(root->left, p, q); 6 | if (root->val < min(p->val, q->val)) 7 | return lowestCommonAncestor(root->right, p, q); 8 | return root; 9 | } 10 | }; -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/235-lowest-common-ancestor-of-a-binary-search-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { 3 | if (root.val > Math.max(p.val, q.val)) 4 | return lowestCommonAncestor(root.left, p, q); 5 | if (root.val < Math.min(p.val, q.val)) 6 | return lowestCommonAncestor(root.right, p, q); 7 | return root; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/235-lowest-common-ancestor-of-a-binary-search-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': 3 | if root.val > max(p.val, q.val): 4 | return self.lowestCommonAncestor(root.left, p, q) 5 | if root.val < min(p.val, q.val): 6 | return self.lowestCommonAncestor(root.right, p, q) 7 | return root 8 | -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2352-Equal-Row-and-Column-Pairs/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int equalPairs(int[][] grid) { 3 | final int n = grid.length; 4 | int ans = 0; 5 | 6 | for (int i = 0; i < n; ++i) 7 | for (int j = 0; j < n; ++j) { 8 | int k = 0; 9 | for (; k < n; ++k) 10 | if (grid[i][k] != grid[k][j]) 11 | break; 12 | if (k == n) // R[i] == C[j] 13 | ++ans; 14 | } 15 | 16 | return ans; 17 | } 18 | } -------------------------------------------------------------------------------- /2352-Equal-Row-and-Column-Pairs/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def equalPairs(self, grid: List[List[int]]) -> int: 3 | n = len(grid) 4 | ans = 0 5 | 6 | for i in range(n): 7 | for j in range(n): 8 | k = 0 9 | while k < n: 10 | if grid[i][k] != grid[k][j]: 11 | break 12 | k += 1 13 | if k == n: # R[i] == C[j] 14 | ans += 1 15 | 16 | return ans -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/236-lowest-common-ancestor-of-a-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 4 | if (!root || root == p || root == q) 5 | return root; 6 | 7 | TreeNode* l = lowestCommonAncestor(root->left, p, q); 8 | TreeNode* r = lowestCommonAncestor(root->right, p, q); 9 | 10 | if (l && r) 11 | return root; 12 | return l ? l : r; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/236-lowest-common-ancestor-of-a-binary-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': 3 | if not root or root == p or root == q: 4 | return root 5 | 6 | l = self.lowestCommonAncestor(root.left, p, q) 7 | r = self.lowestCommonAncestor(root.right, p, q) 8 | 9 | if l and r: 10 | return root 11 | return l or r 12 | -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2366-Minimum Replacements to Sort the Array/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minimumReplacement(vector& nums) { 4 | long long ans = 0; 5 | 6 | int max = nums.back(); 7 | for (int i = nums.size() - 2; i >= 0; --i) { 8 | const int ops = (nums[i] - 1) / max; 9 | ans += ops; 10 | max = nums[i] / (ops + 1); 11 | } 12 | 13 | return ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /2366-Minimum Replacements to Sort the Array/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long minimumReplacement(int[] nums) { 3 | long ans = 0; 4 | 5 | int max = nums[nums.length - 1]; 6 | for (int i = nums.length - 2; i >= 0; --i) { 7 | final int ops = (nums[i] - 1) / max; 8 | ans += ops; 9 | max = nums[i] / (ops + 1); 10 | } 11 | 12 | return ans; 13 | } 14 | } -------------------------------------------------------------------------------- /2366-Minimum Replacements to Sort the Array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumReplacement(self, nums: List[int]) -> int: 3 | ans = 0 4 | 5 | max = nums[-1] 6 | for i in range(len(nums) - 2, -1, -1): 7 | ops = (nums[i] - 1) // max 8 | ans += ops 9 | max = nums[i] // (ops + 1) 10 | 11 | return ans -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void deleteNode(ListNode* node) { 4 | node->val = node->next->val; 5 | node->next = node->next->next; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteNode(self, node): 3 | node.val = node.next.val 4 | node.next = node.next.next 5 | -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /239-sliding-window-maximum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /24-swap-nodes-in-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool searchMatrix(vector>& M, int T) { 4 | int y = M.size(), i = 0, j = M[0].size() - 1; 5 | while (i < y && ~j) { 6 | int cell = M[i][j]; 7 | if (cell == T) return true; 8 | else if (cell > T) j--; 9 | else i++; 10 | } 11 | return false; 12 | } 13 | }; -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean searchMatrix(int[][] M, int T) { 3 | int y = M.length, i = 0, j = M[0].length - 1; 4 | while (i < y && j >= 0) { 5 | int cell = M[i][j]; 6 | if (cell == T) return true; 7 | else if (cell > T) j--; 8 | else i++; 9 | } 10 | return false; 11 | } 12 | } -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.js: -------------------------------------------------------------------------------- 1 | var searchMatrix = function(M, T) { 2 | let y = M.length, i = 0, j = M[0].length - 1 3 | while (i < y && ~j) { 4 | let cell = M[i][j] 5 | if (cell === T) return true 6 | else if (cell > T) j-- 7 | else i++ 8 | } 9 | return false 10 | }; -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchMatrix(self, M: List[List[int]], T: int) -> bool: 3 | y, i, j = len(M), 0, len(M[0]) - 1 4 | while i < y and ~j: 5 | cell = M[i][j] 6 | if cell == T: return True 7 | elif cell > T: j -= 1 8 | else: i += 1 9 | return False -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /242-valid-anagram/242-valid-anagram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isAnagram(string S, string T) { 4 | int len = S.length(); 5 | int fMap [123] = {0}; 6 | if (T.length() != len) return false; 7 | for (int i = 0; i < len; i++) 8 | fMap[int(S[i])]++; 9 | for (int i = 0; i < len; i++) 10 | if (fMap[int(T[i])]-- == 0) return false; 11 | return true; 12 | } 13 | }; -------------------------------------------------------------------------------- /242-valid-anagram/242-valid-anagram.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isAnagram(String S, String T) { 3 | int len = S.length(); 4 | int[] fMap = new int[123]; 5 | if (T.length() != len) return false; 6 | for (int i = 0; i < len; i++) 7 | fMap[S.codePointAt(i)]++; 8 | for (int i = 0; i < len; i++) 9 | if (--fMap[T.codePointAt(i)] < 0) return false; 10 | return true; 11 | } 12 | } -------------------------------------------------------------------------------- /242-valid-anagram/242-valid-anagram.js: -------------------------------------------------------------------------------- 1 | var isAnagram = function(S, T) { 2 | let len = S.length, fMap = new Int16Array(123) 3 | if (T.length !== len) return false 4 | for (let i = 0; i < len; i++) 5 | fMap[S.charCodeAt(i)]++ 6 | for (let i = 0; i < len; i++) 7 | if (--fMap[T.charCodeAt(i)] < 0) return false 8 | return true 9 | }; -------------------------------------------------------------------------------- /242-valid-anagram/242-valid-anagram.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAnagram(self, S: str, T: str) -> bool: 3 | SMap = {c: S.count(c) for c in set(S)} 4 | TMap = {c: T.count(c) for c in set(T)} 5 | return SMap == TMap -------------------------------------------------------------------------------- /242-valid-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2483-minimum-penalty-for-a-shop/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bestClosingTime(self, customers: str) -> int: 3 | # Instead of computing the minimum penalty, we can compute the max profit. 4 | ans = 0 5 | profit = 0 6 | maxProfit = 0 7 | 8 | for i, customer in enumerate(customers): 9 | profit += 1 if customer == 'Y' else -1 10 | if profit > maxProfit: 11 | maxProfit = profit 12 | ans = i + 1 13 | 14 | return ans 15 | -------------------------------------------------------------------------------- /258-Add digits/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int addDigits(int num) { 4 | return 1 + (num - 1) % 9; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /258-Add digits/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addDigits(int num) { 3 | return 1 + (num - 1) % 9; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /258-Add digits/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addDigits(self, num: int) -> int: 3 | return 0 if num == 0 else 1 + (num - 1) % 9 4 | -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int i = 0; 5 | 6 | for (const int num : nums) 7 | if (i < 1 || num > nums[i - 1]) 8 | nums[i++] = num; 9 | 10 | return i; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /262-trips-and-users/262-trips-and-users.sql: -------------------------------------------------------------------------------- 1 | select t.Request_at as Day, 2 | cast(sum(case when Status <> 'completed' then 1.00 else 0.00 end)/count(*) as decimal(10,2)) as 'Cancellation Rate' 3 | from Trips as t 4 | join Users as uc on t.Client_Id = uc.Users_Id and uc.Banned = 'No' 5 | join Users as ud on t.Driver_id = ud.Users_Id and ud.Banned = 'No' 6 | where t.Request_at between '2013-10-01' and '2013-10-03' 7 | group by t.Request_at -------------------------------------------------------------------------------- /27-remove-element/27-remove-element.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums, val): 3 | count = 0 4 | for i in range(len(nums)): 5 | if nums[i] != val : 6 | nums[count] = nums[i] 7 | count +=1 8 | return count -------------------------------------------------------------------------------- /27-remove-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /273-integer-to-english-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /279-perfect-squares/0279-perfect-squares.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numSquares(int n) { 4 | vector dp(n + 1, n); // 1^2 x n 5 | 6 | dp[0] = 0; // No way 7 | dp[1] = 1; // 1^2 8 | 9 | for (int i = 2; i <= n; ++i) 10 | for (int j = 1; j * j <= i; ++j) 11 | dp[i] = min(dp[i], dp[i - j * j] + 1); 12 | 13 | return dp[n]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /279-perfect-squares/0279-perfect-squares.py: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numSquares(int n) { 3 | int[] dp = new int[n + 1]; 4 | Arrays.fill(dp, n); // 1^2 x n 5 | 6 | dp[0] = 0; // No way 7 | dp[1] = 1; // 1^2 8 | 9 | for (int i = 2; i <= n; ++i) 10 | for (int j = 1; j * j <= i; ++j) 11 | dp[i] = Math.min(dp[i], dp[i - j * j] + 1); 12 | 13 | return dp[n]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /279-perfect-squares/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /28-find-the-index-of-the-first-occurence/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int strStr(string haystack, string needle) { 4 | const int m = haystack.length(); 5 | const int n = needle.length(); 6 | 7 | for (int i = 0; i < m - n + 1; i++) 8 | if (haystack.substr(i, n) == needle) 9 | return i; 10 | 11 | return -1; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /28-find-the-index-of-the-first-occurence/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int strStr(String haystack, String needle) { 3 | final int m = haystack.length(); 4 | final int n = needle.length(); 5 | 6 | for (int i = 0; i < m - n + 1; ++i) 7 | if (haystack.substring(i, i + n).equals(needle)) 8 | return i; 9 | 10 | return -1; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /28-find-the-index-of-the-first-occurence/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | m = len(haystack) 4 | n = len(needle) 5 | 6 | for i in range(m - n + 1): 7 | if haystack[i:i + n] == needle: 8 | return i 9 | 10 | return -1 11 | -------------------------------------------------------------------------------- /28-implement-strstr/28-implement-strstr.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int strStr(string haystack, string needle) 4 | { 5 | if(needle==" ") 6 | return 0; 7 | if(haystack.find(needle)!=string::npos) 8 | return haystack.find(needle); 9 | return -1; 10 | } 11 | }; -------------------------------------------------------------------------------- /28-implement-strstr/28-implement-strstr.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int strStr(String haystack, String needle) { 3 | return haystack.indexOf(needle); 4 | } 5 | } -------------------------------------------------------------------------------- /28-implement-strstr/28-implement-strstr.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | try: 4 | return 0 if len(needle) == 0 else haystack.index(needle, 0, len(haystack)) 5 | except: 6 | return -1 -------------------------------------------------------------------------------- /28-implement-strstr/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /282-expression-add-operators/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /295-find-median-from-data-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /297-serialize-and-deserialize-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/300-longest-increasing-subsequence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLIS(self, nums: List[int]) -> int: 3 | if not nums: 4 | return 0 5 | 6 | # dp[i] := LIS ending at nums[i] 7 | dp = [1] * len(nums) 8 | 9 | for i in range(1, len(nums)): 10 | for j in range(i): 11 | if nums[j] < nums[i]: 12 | dp[i] = max(dp[i], dp[j] + 1) 13 | 14 | return max(dp) 15 | -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /315-count-of-smaller-numbers-after-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /319-bulb-switcher/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int bulbSwitch(int n) { 4 | 5 | return sqrt(n); 6 | } 7 | }; -------------------------------------------------------------------------------- /319-bulb-switcher/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int bulbSwitch(int n) { 3 | 4 | return (int) Math.sqrt(n); 5 | } 6 | } -------------------------------------------------------------------------------- /319-bulb-switcher/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bulbSwitch(self, n: int) -> int: 3 | return int(sqrt(n)) -------------------------------------------------------------------------------- /326-power-of-three/326-power-of-three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) { 4 | return n > 0 && 1162261467 % n == 0; 5 | } 6 | }; -------------------------------------------------------------------------------- /326-power-of-three/326-power-of-three.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfThree(int n) { 3 | return n > 0 && 1162261467 % n == 0; 4 | } 5 | } -------------------------------------------------------------------------------- /326-power-of-three/326-power-of-three.js: -------------------------------------------------------------------------------- 1 | var isPowerOfThree = function(n) { 2 | return n > 0 && 1162261467 % n === 0 3 | }; -------------------------------------------------------------------------------- /326-power-of-three/326-power-of-three.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | return n > 0 and 1162261467 % n == 0 -------------------------------------------------------------------------------- /326-power-of-three/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /334-increasing-triplet-subsequence/0334-increasing-triplet-subsequence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def increasingTriplet(self, nums: List[int]) -> bool: 3 | first = math.inf 4 | second = math.inf 5 | 6 | for num in nums: 7 | if num <= first: 8 | first = num 9 | elif num <= second: # First < num <= second 10 | second = num 11 | else: 12 | return True # First < second < num (third) 13 | 14 | return False 15 | -------------------------------------------------------------------------------- /334-increasing-triplet-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /34-find-first-and-last-position-of-element-in-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /342-power-of-four/342-power-of-four.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfFour(int n) { 3 | // Why (4^n - 1) % 3 == 0? 4 | // (4^n - 1) = (2^n - 1)(2^n + 1) and 2^n - 1, 2^n, 2^n + 1 are 5 | // three consecutive numbers; among one of them, there must be a multiple 6 | // of 3, and that can't be 2^n, so it must be either 2^n - 1 or 2^n + 1. 7 | // Therefore, 4^n - 1 is a multiple of 3 8 | return n > 0 && Integer.bitCount(n) == 1 && (n - 1) % 3 == 0; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /342-power-of-four/342-power-of-four.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfFour(self, n: int) -> bool: 3 | # Why (4^n - 1) % 3 == 0? 4 | # (4^n - 1) = (2^n - 1)(2^n + 1) and 2^n - 1, 2^n, 2^n + 1 are 5 | # three consecutive numbers among one of them, there must be a multiple 6 | # of 3, and that can't be 2^n, so it must be either 2^n - 1 or 2^n + 1. 7 | # Therefore, 4^n - 1 is a multiple of 3. 8 | return n > 0 and bin(n).count('1') == 1 and (n - 1) % 3 == 0 9 | -------------------------------------------------------------------------------- /342-power-of-four/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /347-top-k-frequent-elements/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def topKFrequent(self, nums, k): 3 | counter = Counter(nums) 4 | heap = [] 5 | 6 | for num, freq in counter.items(): 7 | heapq.heappush(heap, (-freq, num)) 8 | 9 | result = [] 10 | for _ in range(k): 11 | result.append(heapq.heappop(heap)[1]) 12 | 13 | return result -------------------------------------------------------------------------------- /36-valid-sudoku/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /36-vvalid-sudoku/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /363-max-sum-of-rectangle-no-larger-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /374-guess-number-higher-or-lower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /376-wiggle-subsequence/376-wiggle-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int wiggleMaxLength(vector& N) { 4 | int len = N.size(), i = 1, ans = 1; 5 | while (i < len && N[i] == N[i-1]) i++; 6 | if (i == len) return 1; 7 | bool up = N[i-1] > N[i]; 8 | for (; i < len; i++) 9 | if ((up && N[i] < N[i-1]) || (!up && N[i] > N[i-1])) 10 | up = !up, ans++; 11 | return ans; 12 | } 13 | }; -------------------------------------------------------------------------------- /376-wiggle-subsequence/376-wiggle-subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int wiggleMaxLength(int[] N) { 3 | int len = N.length, i = 1, ans = 1; 4 | while (i < len && N[i] == N[i-1]) i++; 5 | if (i == len) return 1; 6 | boolean up = N[i-1] > N[i]; 7 | for (; i < len; i++) 8 | if ((up && N[i] < N[i-1]) || (!up && N[i] > N[i-1])) { 9 | up = !up; 10 | ans++; 11 | } 12 | return ans; 13 | } 14 | } -------------------------------------------------------------------------------- /376-wiggle-subsequence/376-wiggle-subsequence.js: -------------------------------------------------------------------------------- 1 | var wiggleMaxLength = function(N) { 2 | let len = N.length, i = 1 3 | while (N[i] === N[i-1]) i++ 4 | let up = N[i-1] > N[i], ans = 1 5 | for (; i < len; i++) 6 | if ((up && N[i] < N[i-1]) || (!up && N[i] > N[i-1])) 7 | up = !up, ans++ 8 | return ans 9 | }; -------------------------------------------------------------------------------- /376-wiggle-subsequence/376-wiggle-subsequence.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wiggleMaxLength(self, N: List[int]) -> int: 3 | lenN, i = len(N), 1 4 | while i < lenN and N[i] == N[i-1]: i += 1 5 | if i == lenN: return 1 6 | up, ans = N[i-1] > N[i], 1 7 | while i < lenN: 8 | if (up and N[i] < N[i-1]) or (not up and N[i] > N[i-1]): 9 | up = not up 10 | ans += 1 11 | i += 1 12 | return ans -------------------------------------------------------------------------------- /376-wiggle-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int combinationSum4(vector& N, int T) { 4 | vector dp(T+1, 0); 5 | dp[0] = 1; 6 | for (int i = 1; i <= T; i++) 7 | for (int num : N) 8 | if (num <= i) dp[i] += dp[i-num]; 9 | return dp[T]; 10 | } 11 | }; -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int combinationSum4(int[] N, int T) { 3 | int[] dp = new int[T+1]; 4 | dp[0] = 1; 5 | for (int i = 1; i <= T; i++) 6 | for (int num : N) 7 | if (num <= i) dp[i] += dp[i-num]; 8 | return dp[T]; 9 | } 10 | } -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.js: -------------------------------------------------------------------------------- 1 | var combinationSum4 = function(N, T) { 2 | let dp = new Uint32Array(T+1) 3 | dp[0] = 1 4 | for (let i = 1; i <= T; i++) 5 | for (let num of N) 6 | if (num <= i) dp[i] += dp[i-num] 7 | return dp[T] 8 | }; -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def combinationSum4(self, N: List[int], T: int) -> int: 3 | dp = [0] * (T + 1) 4 | dp[0] = 1 5 | for i in range(1, T+1): 6 | for num in N: 7 | if num <= i: dp[i] += dp[i-num] 8 | return dp[T] -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /378-kth-smallest-element-in-a-sorted-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /38-ccount-and-say/0038-count-and-say.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countAndSay(self, n: int) -> str: 3 | ans = '1' 4 | 5 | for _ in range(n - 1): 6 | nxt = '' 7 | i = 0 8 | while i < len(ans): 9 | count = 1 10 | while i + 1 < len(ans) and ans[i] == ans[i + 1]: 11 | count += 1 12 | i += 1 13 | nxt += str(count) + ans[i] 14 | i += 1 15 | ans = nxt 16 | 17 | return ans 18 | -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/387-first-unique-character-in-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int firstUniqChar(string s) { 4 | vector count(128); 5 | 6 | for (const char c : s) 7 | ++count[c]; 8 | 9 | for (int i = 0; i < s.length(); ++i) 10 | if (count[s[i]] == 1) 11 | return i; 12 | 13 | return -1; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/387-first-unique-character-in-a-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int firstUniqChar(String s) { 3 | int[] count = new int[128]; 4 | 5 | for (final char c : s.toCharArray()) 6 | ++count[c]; 7 | 8 | for (int i = 0; i < s.length(); ++i) 9 | if (count[s.charAt(i)] == 1) 10 | return i; 11 | 12 | return -1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/387-first-unique-character-in-a-string.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | count = Counter(s) 4 | 5 | for i, c in enumerate(s): 6 | if count[c] == 1: 7 | return i 8 | 9 | return -1 10 | -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /39-combination-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /393-utf-8-validation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /40-combination-sum-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /406-queue-reconstruction-by-height/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /417-pacific-atlantic-water-flow/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /43-multiply-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /433-minimum-genetic-mutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /435-non-overlapping-intervals/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: 3 | ans = 0 4 | currentEnd = -math.inf 5 | 6 | for interval in sorted(intervals, key=lambda x: x[1]): 7 | if interval[0] >= currentEnd: 8 | currentEnd = interval[1] 9 | else: 10 | ans += 1 11 | 12 | return ans -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/442-find-all-duplicates-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findDuplicates(vector& nums) { 4 | vector ans; 5 | 6 | for (const int num : nums) { 7 | nums[abs(num) - 1] *= -1; 8 | if (nums[abs(num) - 1] > 0) 9 | ans.push_back(abs(num)); 10 | } 11 | 12 | return ans; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/442-find-all-duplicates-in-an-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List findDuplicates(int[] nums) { 3 | List ans = new ArrayList<>(); 4 | 5 | for (final int num : nums) { 6 | nums[Math.abs(num) - 1] *= -1; 7 | if (nums[Math.abs(num) - 1] > 0) 8 | ans.add(Math.abs(num)); 9 | } 10 | 11 | return ans; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/442-find-all-duplicates-in-an-array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicates(self, nums: List[int]) -> List[int]: 3 | ans = [] 4 | 5 | for num in nums: 6 | nums[abs(num) - 1] *= -1 7 | if nums[abs(num) - 1] > 0: 8 | ans.append(abs(num)) 9 | 10 | return ans 11 | -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /446-arithmetic-slices-ii-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /448-find-all-numbers-disappeared-in-an-array/448-find-all-numbers-disappeared-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findDisappearedNumbers(vector& nums) { 4 | vector ans; 5 | 6 | for (const int num : nums) { 7 | const int index = abs(num) - 1; 8 | nums[index] = -abs(nums[index]); 9 | } 10 | 11 | for (int i = 0; i < nums.size(); ++i) 12 | if (nums[i] > 0) 13 | ans.push_back(i + 1); 14 | 15 | return ans; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /448-find-all-numbers-disappeared-in-an-array/448-find-all-numbers-disappeared-in-an-array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDisappearedNumbers(self, nums: List[int]) -> List[int]: 3 | for num in nums: 4 | index = abs(num) - 1 5 | nums[index] = -abs(nums[index]) 6 | 7 | return [i + 1 for i, num in enumerate(nums) if num > 0] 8 | -------------------------------------------------------------------------------- /448-find-all-numbers-disappeared-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int jump(vector& N) { 4 | int len = N.size() - 1, curr = -1, next = 0, ans = 0; 5 | for (int i = 0; next < len; i++) { 6 | if (i > curr) ans++, curr = next; 7 | next = max(next, N[i] + i); 8 | }; 9 | return ans; 10 | } 11 | }; -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int jump(int[] N) { 3 | int len = N.length - 1, curr = -1, next = 0, ans = 0; 4 | for (int i = 0; next < len; i++) { 5 | if (i > curr) { 6 | ans++; 7 | curr = next; 8 | }; 9 | next = Math.max(next, N[i] + i); 10 | }; 11 | return ans; 12 | }; 13 | }; -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.js: -------------------------------------------------------------------------------- 1 | var jump = function(N) { 2 | let len = N.length - 1, curr = -1, next = 0, ans = 0 3 | for (let i = 0; next < len; i++) { 4 | if (i > curr) ans++, curr = next 5 | next = Math.max(next, N[i] + i) 6 | } 7 | return ans 8 | }; -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def jump(self, N: List[int]) -> int: 3 | Nlen, curr, nxt, ans, i = len(N) - 1, -1, 0, 0, 0 4 | while nxt < Nlen: 5 | if i > curr: 6 | ans += 1 7 | curr = nxt 8 | nxt = max(nxt, N[i] + i) 9 | i += 1 10 | return ans -------------------------------------------------------------------------------- /45-jump-game-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def frequencySort(self, s: str) -> str: 3 | ans = [] 4 | bucket = [[] for _ in range(len(s) + 1)] 5 | 6 | for c, freq in Counter(s).items(): 7 | bucket[freq].append(c) 8 | 9 | for freq in reversed(range(len(bucket))): 10 | for c in bucket[freq]: 11 | ans.append(c * freq) 12 | 13 | return ''.join(ans) 14 | -------------------------------------------------------------------------------- /451-sort-characters-by-frequency/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /458-poor-pigs/458-poor-pigs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int poorPigs(int buckets, int minutesToDie, int minutesToTest) { 4 | return ceil(log(buckets) / log(minutesToTest / minutesToDie + 1)); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /458-poor-pigs/458-poor-pigs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int poorPigs(int buckets, int minutesToDie, int minutesToTest) { 3 | return (int) Math.ceil(Math.log(buckets) / Math.log(minutesToTest / minutesToDie + 1)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /46-permutations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/462-minimum-moves-to-equal-array-elements-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minMoves2(vector& nums) { 4 | const int n = nums.size(); 5 | nth_element(begin(nums), begin(nums) + n / 2, end(nums)); 6 | const int median = nums[n / 2]; 7 | return accumulate(begin(nums), end(nums), 0, 8 | [&](int a, int b) { return a + abs(b - median); }); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/462-minimum-moves-to-equal-array-elements-ii.py: -------------------------------------------------------------------------------- 1 | import statistics 2 | 3 | 4 | class Solution: 5 | def minMoves2(self, nums: List[int]) -> int: 6 | median = int(statistics.median(nums)) 7 | return sum(abs(num - median) for num in nums) 8 | -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /473-matchsticks-to-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.js: -------------------------------------------------------------------------------- 1 | var rotate = function(M) { 2 | let n = M.length, depth = ~~(n / 2) 3 | for (let i = 0; i < depth; i++) { 4 | let len = n - 2 * i - 1, opp = n - 1 - i 5 | for (let j = 0; j < len; j++) { 6 | let temp = M[i][i+j] 7 | M[i][i+j] = M[opp-j][i] 8 | M[opp-j][i] = M[opp][opp-j] 9 | M[opp][opp-j] = M[i+j][opp] 10 | M[i+j][opp] = temp 11 | } 12 | } 13 | }; -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotate(self, M: List[List[int]]) -> None: 3 | n = len(M) 4 | depth = n // 2 5 | for i in range(depth): 6 | rlen, opp = n - 2 * i - 1, n - 1 - i 7 | for j in range(rlen): 8 | temp = M[i][i+j] 9 | M[i][i+j] = M[opp-j][i] 10 | M[opp-j][i] = M[opp][opp-j] 11 | M[opp][opp-j] = M[i+j][opp] 12 | M[i+j][opp] = temp -------------------------------------------------------------------------------- /48-rotate-image/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /49-ggroup-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /49-group-anagrams/49-group-anagrams.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | anagrams = {} 4 | 5 | for s in strs: 6 | s_sorted = "".join(sorted(s)) 7 | if s_sorted not in anagrams: 8 | anagrams[s_sorted] = [] 9 | anagrams[s_sorted].append(s) 10 | 11 | return [list(value) for key, value in anagrams.items()] -------------------------------------------------------------------------------- /49-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /5-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /50-powx-n/50-powx-n.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def myPow(self, x: float, n: int) -> float: 3 | def pow(x, n): 4 | if n == 0: 5 | return 1 6 | 7 | r = pow(x, n//2) 8 | if n % 2 == 0: 9 | return r * r 10 | else: 11 | return r * r * x 12 | 13 | if n < 0: 14 | n *= -1 15 | x = 1/x 16 | 17 | return pow(x, n) -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fib(int n) { 4 | if (n < 2) return n; 5 | int a = 0, b = 1, temp; 6 | for (int i = 1; i < n; i++) 7 | temp = a, a = b, b += temp; 8 | return b; 9 | } 10 | }; -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int fib(int n) { 3 | if (n < 2) return n; 4 | int a = 0, b = 1, temp; 5 | for (int i = 1; i < n; i++) { 6 | temp = a; 7 | a = b; 8 | b += temp; 9 | } 10 | return b; 11 | } 12 | } -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.js: -------------------------------------------------------------------------------- 1 | var fib = function(n) { 2 | if (n < 2) return n 3 | let a = 0, b = 1 4 | for (let i = 1; i < n; i++) 5 | [a,b] = [b,a+b] 6 | return b 7 | }; -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fib(self, n: int) -> int: 3 | if n < 2: return n 4 | a, b = 0, 1 5 | for _ in range(1,n): 6 | a, b = b, a+b 7 | return b -------------------------------------------------------------------------------- /509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /518-coin-change-ii/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int change(int amount, vector& coins) { 4 | vector dp(amount + 1); 5 | dp[0] = 1; 6 | 7 | for (const int coin : coins) 8 | for (int i = coin; i <= amount; ++i) 9 | dp[i] += dp[i - coin]; 10 | 11 | return dp[amount]; 12 | } 13 | }; -------------------------------------------------------------------------------- /518-coin-change-ii/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int change(int amount, int[] coins) { 3 | int[] dp = new int[amount + 1]; 4 | dp[0] = 1; 5 | 6 | for (final int coin : coins) 7 | for (int i = coin; i <= amount; ++i) 8 | dp[i] += dp[i - coin]; 9 | 10 | return dp[amount]; 11 | } 12 | } -------------------------------------------------------------------------------- /518-coin-change-ii/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def change(self, amount: int, coins: List[int]) -> int: 3 | dp = [1] + [0] * amount 4 | 5 | for coin in coins: 6 | for i in range(coin, amount + 1): 7 | dp[i] += dp[i - coin] 8 | 9 | return dp[amount] -------------------------------------------------------------------------------- /523-continuous-subarray-sum/0523-continuous-subarray-sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkSubarraySum(self, nums: List[int], k: int) -> bool: 3 | prefix = 0 4 | prefixToIndex = {0: -1} 5 | 6 | for i, num in enumerate(nums): 7 | prefix += num 8 | if k != 0: 9 | prefix %= k 10 | if prefix in prefixToIndex: 11 | if i - prefixToIndex[prefix] > 1: 12 | return True 13 | else: 14 | prefixToIndex[prefix] = i 15 | 16 | return False 17 | -------------------------------------------------------------------------------- /523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/53-maximum-subarray.c: -------------------------------------------------------------------------------- 1 | int maxSubArray(int* nums, int n) { 2 | int ans=nums[0],i,sum=0; 3 | for(i=0;i& nums) 4 | { 5 | int sum=nums[0]; 6 | for(int i=1;i& nums) { 4 | int l = 0; 5 | int r = nums.size() - 1; 6 | 7 | while (l < r) { 8 | int m = (l + r) / 2; 9 | if (m & 1) 10 | --m; 11 | if (nums[m] == nums[m + 1]) 12 | l = m + 2; 13 | else 14 | r = m; 15 | } 16 | 17 | return nums[l]; 18 | } 19 | }; -------------------------------------------------------------------------------- /540-single-element-in-a-sorted-array/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNonDuplicate(int[] nums) { 3 | int l = 0; 4 | int r = nums.length - 1; 5 | 6 | while (l < r) { 7 | int m = (l + r) / 2; 8 | if (m % 2 == 1) 9 | --m; 10 | if (nums[m] == nums[m + 1]) 11 | l = m + 2; 12 | else 13 | r = m; 14 | } 15 | 16 | return nums[l]; 17 | } 18 | } -------------------------------------------------------------------------------- /540-single-element-in-a-sorted-array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNonDuplicate(self, nums: List[int]) -> int: 3 | l = 0 4 | r = len(nums) - 1 5 | 6 | while l < r: 7 | m = (l + r) // 2 8 | if m % 2 == 1: 9 | m -= 1 10 | if nums[m] == nums[m + 1]: 11 | l = m + 2 12 | else: 13 | r = m 14 | 15 | return nums[l] -------------------------------------------------------------------------------- /55-jump-game/55-jump-game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canJump(vector& nums) { 4 | int n = nums.size(); 5 | int i = 0; 6 | for (int reach = 0; i < n && i <= reach; ++i) 7 | reach = max(i + nums[i], reach); 8 | return i == n; 9 | } 10 | }; -------------------------------------------------------------------------------- /55-jump-game/55-jump-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int i = 0; 4 | for (int reach = 0; i < nums.length && i <= reach; ++i) 5 | reach = Math.max(i + nums[i], reach); 6 | return i == nums.length; 7 | } 8 | } -------------------------------------------------------------------------------- /55-jump-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /554-brick-wall/554-brick-wall.js: -------------------------------------------------------------------------------- 1 | var leastBricks = function(wall) { 2 | let freq = new Map(), best = 0 3 | for (let i = 0; i < wall.length; i++) { 4 | let row = wall[i], rowSum = row[0] 5 | for (let j = 1; j < row.length; j++) { 6 | freq.set(rowSum, (freq.get(rowSum) || 0) + 1) 7 | rowSum += row[j] 8 | } 9 | } 10 | for (let [k,v] of freq) 11 | if (v > best) best = v 12 | return wall.length - best 13 | }; -------------------------------------------------------------------------------- /554-brick-wall/554-brick-wall.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def leastBricks(self, wall: List[List[int]]) -> int: 3 | freq = defaultdict(int) 4 | for row in wall: 5 | rowSum = row[0] 6 | for j in range(1, len(row)): 7 | freq[rowSum] += 1 8 | rowSum += row[j] 9 | return len(wall) - max(freq.values() or [0]) -------------------------------------------------------------------------------- /554-brick-wall/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/557-reverse-words-in-a-string-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reverseWords(string s) { 4 | int i = 0; 5 | int j = 0; 6 | 7 | while (i < s.length()) { 8 | while (i < j || i < s.length() && s[i] == ' ') 9 | ++i; 10 | while (j < i || j < s.length() && s[j] != ' ') 11 | ++j; 12 | reverse(begin(s) + i, begin(s) + j); 13 | } 14 | 15 | return s; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /56-merge-intervals/56-merge-intervals.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def merge(self, intervals: List[List[int]]) -> List[List[int]]: 3 | ans = [] 4 | for interval in sorted(intervals): 5 | if not ans or ans[-1][1] < interval[0]: 6 | ans.append(interval) 7 | else: 8 | ans[-1][1] = max(ans[-1][1], interval[1]) 9 | return ans -------------------------------------------------------------------------------- /56-merge-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /57-insert-interval/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /576-out-of-boundary-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /58-length-of-last-word/58-length-of-last-word.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLastWord(string s) { 4 | stringstream ss(s); 5 | string word; 6 | while(ss >> word) { 7 | } 8 | return word.size(); 9 | } 10 | }; -------------------------------------------------------------------------------- /58-length-of-last-word/58-length-of-last-word.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lengthOfLastWord(String s) { 3 | s = s.trim(); 4 | return s.length() - s.lastIndexOf(" ") - 1; 5 | } 6 | } -------------------------------------------------------------------------------- /58-length-of-last-word/58-length-of-last-word.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLastWord(self, s): 3 | """ 4 | :type s: str 5 | :rtype: int 6 | """ 7 | return len(s.rstrip().split(' ')[-1]) -------------------------------------------------------------------------------- /58-length-of-last-word/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /583-delete-operation-for-two-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /59-spiral-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /60-permutation-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /605-can-place-flowers/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: 3 | for i, flower in enumerate(flowerbed): 4 | if flower == 0 and (i == 0 or flowerbed[i - 1] == 0) and (i == len(flowerbed) - 1 or flowerbed[i + 1] == 0): 5 | flowerbed[i] = 1 6 | n -= 1 7 | if n <= 0: 8 | return True 9 | 10 | return False 11 | -------------------------------------------------------------------------------- /606-construct-string-from-binary-tree/606-construct-string-from-binary-tree.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def tree2str(self, t: Optional[TreeNode]) -> str: 3 | def dfs(root: Optional[TreeNode]) -> str: 4 | if not root: 5 | return '' 6 | if root.right: 7 | return str(root.val) + '(' + dfs(root.left) + ')(' + dfs(root.right) + ')' 8 | if root.left: 9 | return str(root.val) + '(' + dfs(root.left) + ')' 10 | return str(root.val) 11 | return dfs(t) 12 | -------------------------------------------------------------------------------- /606-construct-string-from-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /609-find-duplicate-file-in-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /61-rotate-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/62-unique-paths.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int uniquePaths(int m, int n) { 3 | int[] dp = new int[n]; 4 | dp[0] = 1; 5 | for (int i = 0; i < m; i++) { 6 | for (int j = 1; j < n; j++) { 7 | dp[j] += dp[j - 1]; 8 | } 9 | } 10 | return dp[n - 1]; 11 | } 12 | } -------------------------------------------------------------------------------- /62-unique-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /622-design-circular-queue/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /623-add-one-row-to-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /630-course-schedule-iii/630-course-schedule-iii.js: -------------------------------------------------------------------------------- 1 | var scheduleCourse = function(C) { 2 | C.sort((a,b) => a[1] - b[1]) 3 | let total = 0, pq = new MaxPriorityQueue({priority: x => x}) 4 | for (let [dur, end] of C) 5 | if (dur + total <= end) 6 | total += dur, pq.enqueue(dur) 7 | else if (pq.front() && pq.front().element > dur) 8 | total += dur - pq.dequeue().element, pq.enqueue(dur) 9 | return pq.size() 10 | }; -------------------------------------------------------------------------------- /630-course-schedule-iii/630-course-schedule-iii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def scheduleCourse(self, C: List[List[int]]) -> int: 3 | heap, total = [], 0 4 | for dur, end in sorted(C, key=lambda el: el[1]): 5 | if dur + total <= end: 6 | total += dur 7 | heappush(heap, -dur) 8 | elif heap and -heap[0] > dur: 9 | total += dur + heappop(heap) 10 | heappush(heap, -dur) 11 | return len(heap) -------------------------------------------------------------------------------- /630-course-schedule-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /637-average-of-levels-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /64-minimum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /645-set-mismatch/645-set-mismatch.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] findErrorNums(int[] nums) { 3 | int N = nums.length; 4 | int[] ans = new int[2]; 5 | for (int num : nums) 6 | nums[(num - 1) % 10000] += 10000; 7 | for (int i = 0; i < N; i++) 8 | if (nums[i] > 20000) ans[0] = i + 1; 9 | else if (nums[i] < 10001) ans[1] = i + 1; 10 | return ans; 11 | } 12 | } -------------------------------------------------------------------------------- /645-set-mismatch/645-set-mismatch.js: -------------------------------------------------------------------------------- 1 | var findErrorNums = function(nums) { 2 | let N = nums.length, ans = [,] 3 | for (let i = 0; i < N; i++) 4 | nums[(nums[i] - 1) % 10000] += 10000 5 | for (let i = 0; i < N; i++) 6 | if (nums[i] > 20000) ans[0] = i + 1 7 | else if (nums[i] < 10001) ans[1] = i + 1 8 | return ans 9 | }; -------------------------------------------------------------------------------- /645-set-mismatch/645-set-mismatch.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findErrorNums(self, nums): 3 | ans = [0,0] 4 | for num in nums: 5 | nums[(num - 1) % 10000] += 10000 6 | for i in range(len(nums)): 7 | if nums[i] > 20000: ans[0] = i + 1 8 | elif nums[i] < 10001: ans[1] = i + 1 9 | return ans -------------------------------------------------------------------------------- /645-set-mismatch/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /645-set-mismatchh/0645-set-mismatch.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findErrorNums(vector& nums) { 4 | int duplicate; 5 | 6 | for (const int num : nums) 7 | if (nums[abs(num) - 1] < 0) 8 | duplicate = abs(num); 9 | else 10 | nums[abs(num) - 1] *= -1; 11 | 12 | for (int i = 0; i < nums.size(); ++i) 13 | if (nums[i] > 0) 14 | return {duplicate, i + 1}; 15 | 16 | throw; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /65-valid-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /653-two-sum-iv-input-is-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /658-find-k-closest-elements/658-find-k-closest-elements.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findClosestElements(vector& arr, int k, int x) { 4 | int l = 0; 5 | int r = arr.size() - k; 6 | 7 | while (l < r) { 8 | const int m = (l + r) / 2; 9 | if (x - arr[m] <= arr[m + k] - x) 10 | r = m; 11 | else 12 | l = m + 1; 13 | } 14 | 15 | return {begin(arr) + l, begin(arr) + l + k}; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /658-find-k-closest-elements/658-find-k-closest-elements.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List findClosestElements(int[] arr, int k, int x) { 3 | int l = 0; 4 | int r = arr.length - k; 5 | 6 | while (l < r) { 7 | final int m = (l + r) / 2; 8 | if (x - arr[m] <= arr[m + k] - x) 9 | r = m; 10 | else 11 | l = m + 1; 12 | } 13 | 14 | return Arrays.stream(arr, l, l + k).boxed().collect(Collectors.toList()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /658-find-k-closest-elements/658-find-k-closest-elements.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]: 3 | l = 0 4 | r = len(arr) - k 5 | 6 | while l < r: 7 | m = (l + r) // 2 8 | if x - arr[m] <= arr[m + k] - x: 9 | r = m 10 | else: 11 | l = m + 1 12 | 13 | return arr[l:l + k] 14 | -------------------------------------------------------------------------------- /659-split-array-into-consecutive-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /66-plus-one/66-plus-one.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def plusOne(self, digits): 3 | digits=str(int(''.join([str(x) for x in digits]))+1) 4 | ret=[] 5 | for i in range(len(digits)): 6 | ret.append(int(digits[i:i+1])) 7 | return ret -------------------------------------------------------------------------------- /66-plus-one/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /665-non-decreasing-array/665-non-decreasing-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPossibility(vector& N) { 4 | for (int i = 1, err = 0; i < N.size(); i++) 5 | if (N[i] < N[i-1]) 6 | if (err++ || (i > 1 && i < N.size() - 1 && N[i-2] > N[i] && N[i+1] < N[i-1])) 7 | return false; 8 | return true; 9 | } 10 | }; -------------------------------------------------------------------------------- /665-non-decreasing-array/665-non-decreasing-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkPossibility(int[] N) { 3 | for (int i = 1, err = 0; i < N.length; i++) 4 | if (N[i] < N[i-1]) 5 | if (err++ > 0 || (i > 1 && i < N.length - 1 && N[i-2] > N[i] && N[i+1] < N[i-1])) 6 | return false; 7 | return true; 8 | } 9 | } -------------------------------------------------------------------------------- /665-non-decreasing-array/665-non-decreasing-array.js: -------------------------------------------------------------------------------- 1 | var checkPossibility = function(N) { 2 | for (let i = 1, err = 0; i < N.length; i++) 3 | if (N[i] < N[i-1]) 4 | if (err++ || (i > 1 && i < N.length - 1 && N[i-2] > N[i] && N[i+1] < N[i-1])) 5 | return false 6 | return true 7 | }; -------------------------------------------------------------------------------- /665-non-decreasing-array/665-non-decreasing-array.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkPossibility(self, N: List[int]) -> bool: 3 | err = 0 4 | for i in range(1, len(N)): 5 | if N[i] < N[i-1]: 6 | if err or (i > 1 and i < len(N) - 1 and N[i-2] > N[i] and N[i+1] < N[i-1]): 7 | return False 8 | err = 1 9 | return True -------------------------------------------------------------------------------- /665-non-decreasing-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /67-aadd-binary/add-binary.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addBinary(self, a: str, b: str) -> str: 3 | s = [] 4 | carry = 0 5 | i = len(a) - 1 6 | j = len(b) - 1 7 | 8 | while i >= 0 or j >= 0 or carry: 9 | if i >= 0: 10 | carry += int(a[i]) 11 | i -= 1 12 | if j >= 0: 13 | carry += int(b[j]) 14 | j -= 1 15 | s.append(str(carry % 2)) 16 | carry //= 2 17 | 18 | return ''.join(reversed(s)) -------------------------------------------------------------------------------- /67-add-binary/67-add-binary.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addBinary(self, a: str, b: str) -> str: 3 | carry = 0 4 | result = '' 5 | 6 | a = list(a) 7 | b = list(b) 8 | 9 | while a or b or carry: 10 | if a: 11 | carry += int(a.pop()) 12 | if b: 13 | carry += int(b.pop()) 14 | 15 | result += str(carry %2) 16 | carry //= 2 17 | 18 | return result[::-1] -------------------------------------------------------------------------------- /67-add-binary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /68-text-justification/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /69-sqrtx/69-sqrtx.c: -------------------------------------------------------------------------------- 1 | long int mySqrt(int x){ 2 | long int i=1,rt; 3 | if(x==0) return 0; 4 | for(i;i*i<=x;i++) 5 | { 6 | rt=i; 7 | } 8 | return rt; 9 | } -------------------------------------------------------------------------------- /69-sqrtx/69-sqrtx.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mySqrt(int x) { 4 | int y = 1; 5 | int n = x; 6 | while (n > y) { 7 | n = y + (n - y) / 2; 8 | y = x / n; 9 | } 10 | return n; 11 | } 12 | }; -------------------------------------------------------------------------------- /69-sqrtx/69-sqrtx.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public int mySqrt(int x) { 3 | int left=1,right =x, result=0; 4 | while(left int: 3 | return floor(sqrt(x)) -------------------------------------------------------------------------------- /69-sqrtx/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /692-top-k-frequent-words/0692-top-k-frequent-words.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def topKFrequent(self, words: List[str], k: int) -> List[str]: 3 | ans = [] 4 | bucket = [[] for _ in range(len(words) + 1)] 5 | 6 | for word, freq in Counter(words).items(): 7 | bucket[freq].append(word) 8 | 9 | for b in reversed(bucket): 10 | for word in sorted(b): 11 | ans.append(word) 12 | if len(ans) == k: 13 | return ans 14 | -------------------------------------------------------------------------------- /692-top-k-frequent-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /695-max-area-of-island/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /70-climbing-stairs/70-climbing-stairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int climbStairs(int n) { 3 | if (n == 1) { 4 | return 1; 5 | } 6 | int first = 1; 7 | int second = 2; 8 | for (int i = 3; i <= n; i++) { 9 | int third = first + second; 10 | first = second; 11 | second = third; 12 | } 13 | return second; 14 | } 15 | } -------------------------------------------------------------------------------- /705-design-hashset/solution.cpp: -------------------------------------------------------------------------------- 1 | class MyHashSet { 2 | public: 3 | /** Initialize your data structure here. */ 4 | MyHashSet() : set(1000001) {} 5 | 6 | void add(int key) { 7 | set[key] = true; 8 | } 9 | 10 | void remove(int key) { 11 | set[key] = false; 12 | } 13 | 14 | /** Returns true if this set contains the specified element */ 15 | bool contains(int key) { 16 | return set[key]; 17 | } 18 | 19 | private: 20 | vector set; 21 | }; 22 | -------------------------------------------------------------------------------- /705-design-hashset/solution.py: -------------------------------------------------------------------------------- 1 | class MyHashSet: 2 | def __init__(self): 3 | self.set = [False] * 1000001 4 | 5 | def add(self, key: int) -> None: 6 | self.set[key] = True 7 | 8 | def remove(self, key: int) -> None: 9 | self.set[key] = False 10 | 11 | def contains(self, key: int) -> bool: 12 | return self.set[key] 13 | -------------------------------------------------------------------------------- /71-simplify-path/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /714-Best Time to Buy and Sell Stock with Transaction Fee/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices, int fee) { 4 | int sell = 0; 5 | int hold = INT_MIN; 6 | 7 | for (const int price : prices) { 8 | sell = max(sell, hold + price); 9 | hold = max(hold, sell - price - fee); 10 | } 11 | 12 | return sell; 13 | } 14 | }; -------------------------------------------------------------------------------- /714-Best Time to Buy and Sell Stock with Transaction Fee/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices, int fee) { 3 | int sell = 0; 4 | int hold = Integer.MIN_VALUE; 5 | 6 | for (final int price : prices) { 7 | sell = Math.max(sell, hold + price); 8 | hold = Math.max(hold, sell - price - fee); 9 | } 10 | 11 | return sell; 12 | } 13 | } -------------------------------------------------------------------------------- /714-Best Time to Buy and Sell Stock with Transaction Fee/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int], fee: int) -> int: 3 | sell = 0 4 | hold = -math.inf 5 | 6 | for price in prices: 7 | sell = max(sell, hold + price) 8 | hold = max(hold, sell - price - fee) 9 | 10 | return sell -------------------------------------------------------------------------------- /718-maximum-length-of-repeated-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /72-edit-distance/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /729-my-calendar-i/729-my-calendar-i.cpp: -------------------------------------------------------------------------------- 1 | class MyCalendar { 2 | public: 3 | set> calendar = {{INT_MAX, INT_MAX}}; 4 | bool book(int start, int end) { 5 | auto pair = calendar.upper_bound({start, end}); 6 | bool res = end <= pair->second; 7 | if (res) calendar.insert({end, start}); 8 | return res; 9 | } 10 | }; -------------------------------------------------------------------------------- /729-my-calendar-i/729-my-calendar-i.py: -------------------------------------------------------------------------------- 1 | from sortedcontainers import SortedDict 2 | class MyCalendar: 3 | def __init__(self): 4 | self.calendar = SortedDict({float('inf'):float('inf')}) 5 | def book(self, start: int, end: int) -> bool: 6 | ix = self.calendar.bisect_right(start) 7 | k,v = self.calendar.peekitem(ix) 8 | res = end <= v 9 | if res: self.calendar[end] = start 10 | return res -------------------------------------------------------------------------------- /732-my-calendar-iii/732-my-calendar-iii.cpp: -------------------------------------------------------------------------------- 1 | class MyCalendarThree { 2 | public: 3 | int book(int start, int end) { 4 | ++timeline[start]; 5 | --timeline[end]; 6 | 7 | int ans = 0; 8 | int activeEvents = 0; 9 | 10 | for (const auto& [_, count] : timeline) { 11 | activeEvents += count; 12 | ans = max(ans, activeEvents); 13 | } 14 | 15 | return ans; 16 | } 17 | 18 | private: 19 | map timeline; 20 | }; 21 | -------------------------------------------------------------------------------- /732-my-calendar-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /74-search-a-2d-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /744-find-smallest-letter-greater-than-target/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public char nextGreatestLetter(char[] letters, char target) { 3 | int l = 0; 4 | int r = letters.length; 5 | 6 | while (l < r) { 7 | final int m = (l + r) / 2; 8 | if (letters[m] > target) 9 | r = m; 10 | else 11 | l = m + 1; 12 | } 13 | 14 | return letters[l % letters.length]; 15 | } 16 | } -------------------------------------------------------------------------------- /744-find-smallest-letter-greater-than-target/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def nextGreatestLetter(self, letters: List[str], target: str) -> str: 3 | l = bisect.bisect_right(range(len(letters)), target, 4 | key=lambda m: letters[m]) 5 | return letters[l % len(letters)] -------------------------------------------------------------------------------- /745-prefix-and-suffix-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minCostClimbingStairs(vector& cost) { 4 | for (int i = cost.size() - 3; ~i; i--) 5 | cost[i] += min(cost[i+1], cost[i+2]); 6 | return min(cost[0], cost[1]); 7 | } 8 | }; -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minCostClimbingStairs(int[] cost) { 3 | for (int i = cost.length - 3; i >= 0; i--) 4 | cost[i] += Math.min(cost[i+1], cost[i+2]); 5 | return Math.min(cost[0], cost[1]); 6 | } 7 | } -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.js: -------------------------------------------------------------------------------- 1 | var minCostClimbingStairs = function(cost) { 2 | for (let i = cost.length - 3; ~i; i--) 3 | cost[i] += Math.min(cost[i+1], cost[i+2]) 4 | return Math.min(cost[0], cost[1]) 5 | }; -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostClimbingStairs(self, cost: List[int]) -> int: 3 | for i in range(len(cost) - 3, -1, -1): 4 | cost[i] += min(cost[i+1], cost[i+2]) 5 | return min(cost[0], cost[1]) -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /75-sort-colors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /76-minimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /76-mminimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /766-toeplitz-matrix/0766-toeplitz-matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isToeplitzMatrix(vector>& matrix) { 4 | for (int i = 0; i + 1 < matrix.size(); ++i) 5 | for (int j = 0; j + 1 < matrix[0].size(); ++j) 6 | if (matrix[i][j] != matrix[i + 1][j + 1]) 7 | return false; 8 | return true; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /766-toeplitz-matrix/0766-toeplitz-matrix.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isToeplitzMatrix(int[][] matrix) { 3 | for (int i = 0; i + 1 < matrix.length; ++i) 4 | for (int j = 0; j + 1 < matrix[0].length; ++j) 5 | if (matrix[i][j] != matrix[i + 1][j + 1]) 6 | return false; 7 | return true; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /766-toeplitz-matrix/0766-toeplitz-matrix.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool: 3 | for i in range(len(matrix) - 1): 4 | for j in range(len(matrix[0]) - 1): 5 | if matrix[i][j] != matrix[i + 1][j + 1]: 6 | return False 7 | 8 | return True 9 | -------------------------------------------------------------------------------- /766-toeplitz-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /77-combinations/77-combinations.js: -------------------------------------------------------------------------------- 1 | var combine = function(n, k) { 2 | if (n < k || k < 1) return []; 3 | 4 | var res = []; 5 | 6 | helper(res, [], 0, n, k); 7 | 8 | return res; 9 | }; 10 | 11 | var helper = function (res, now, start, n, k) { 12 | if (k === 0) { 13 | res.push(Array.from(now)); 14 | return; 15 | } 16 | 17 | for (var i = start; i < n; i++) { 18 | now.push(i + 1) 19 | helper(res, now, i + 1, n, k - 1); 20 | now.pop(); 21 | } 22 | }; -------------------------------------------------------------------------------- /77-combinations/77-combinations.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def combine(self, n: int, k: int) -> List[List[int]]: 3 | ans = [] 4 | 5 | def dfs(s: int, path: List[int]) -> None: 6 | if len(path) == k: 7 | ans.append(path.copy()) 8 | return 9 | 10 | for i in range(s, n + 1): 11 | path.append(i) 12 | dfs(i + 1, path) 13 | path.pop() 14 | 15 | dfs(1, []) 16 | return ans 17 | -------------------------------------------------------------------------------- /77-combinations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /778-swim-in-rising-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /79-word-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /79-wword-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/80-remove-duplicates-from-sorted-array-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int i = 0; 5 | 6 | for (const int num : nums) 7 | if (i < 2 || num > nums[i - 2]) 8 | nums[i++] = num; 9 | 10 | return i; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/80-remove-duplicates-from-sorted-array-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | int i = 0; 4 | 5 | for (final int num : nums) 6 | if (i < 2 || num > nums[i - 2]) 7 | nums[i++] = num; 8 | 9 | return i; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /804-unique-morse-code-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /81-search-in-rotated-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /814-binary-tree-pruning/814-binary-tree-pruning.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def pruneTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: 3 | if not root: 4 | return None 5 | root.left = self.pruneTree(root.left) 6 | root.right = self.pruneTree(root.right) 7 | if not root.left and not root.right and not root.val: 8 | return None 9 | return root 10 | -------------------------------------------------------------------------------- /814-binary-tree-pruning/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /82-remove-duplicates-from-sorted-list-ii/82-remove-duplicates-from-sorted-list-ii.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteDuplicates(self, head: ListNode) -> ListNode: 3 | dummy = ListNode(0, head) 4 | prev = dummy 5 | 6 | while head: 7 | while head.next and head.val == head.next.val: 8 | head = head.next 9 | if prev.next == head: 10 | prev = prev.next 11 | else: 12 | prev.next = head.next 13 | head = head.next 14 | 15 | return dummy.next 16 | -------------------------------------------------------------------------------- /82-remove-duplicates-from-sorted-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /820-short-encoding-of-words/820-short-encoding-of-words.js: -------------------------------------------------------------------------------- 1 | var minimumLengthEncoding = function(W) { 2 | let set = new Set(W) 3 | for (let word of W) 4 | if (set.has(word)) 5 | for (let i = 1; i < word.length; i++) 6 | set.delete(word.slice(i)) 7 | return Array.from(set).join().length + 1 8 | }; -------------------------------------------------------------------------------- /820-short-encoding-of-words/820-short-encoding-of-words.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumLengthEncoding(self, W: List[str]) -> int: 3 | wset = set(W) 4 | for word in W: 5 | if word in wset: 6 | for i in range(1,len(word)): 7 | wset.discard(word[i:]) 8 | return len("#".join(list(wset))) + 1 -------------------------------------------------------------------------------- /820-short-encoding-of-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* deleteDuplicates(ListNode* head) { 4 | ListNode* curr = head; 5 | 6 | while (curr) { 7 | while (curr->next && curr->val == curr->next->val) 8 | curr->next = curr->next->next; 9 | curr = curr->next; 10 | } 11 | 12 | return head; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode deleteDuplicates(ListNode head) { 3 | ListNode curr = head; 4 | 5 | while (curr != null) { 6 | while (curr.next != null && curr.val == curr.next.val) 7 | curr.next = curr.next.next; 8 | curr = curr.next; 9 | } 10 | 11 | return head; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteDuplicates(self, head: ListNode) -> ListNode: 3 | curr = head 4 | 5 | while curr: 6 | while curr.next and curr.val == curr.next.val: 7 | curr.next = curr.next.next 8 | curr = curr.next 9 | 10 | return head 11 | -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /835-image-overlap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /838-push-dominoes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /84-largest-rectangle-in-histogram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /85-maximal-rectangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /852-Peak Index in a Mountain Array/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int peakIndexInMountainArray(vector& arr) { 4 | int l=0; 5 | int r= arr.size()-1; 6 | 7 | while(larr[m+1]){ 10 | r=m; 11 | } 12 | else{ 13 | l=m+1; 14 | } 15 | } 16 | return l; 17 | 18 | } 19 | }; -------------------------------------------------------------------------------- /852-Peak Index in a Mountain Array/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int peakIndexInMountainArray(int[] arr) { 3 | int l = 0; 4 | int r = arr.length - 1; 5 | 6 | while (l < r) { 7 | final int m = (l + r) / 2; 8 | if (arr[m] >= arr[m + 1]) 9 | r = m; 10 | else 11 | l = m + 1; 12 | } 13 | 14 | return l; 15 | } 16 | } -------------------------------------------------------------------------------- /852-Peak Index in a Mountain Array/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def peakIndexInMountainArray(self, arr: List[int]) -> int: 3 | l = 0 4 | r = len(arr) - 1 5 | 6 | while l < r: 7 | m = (l + r) // 2 8 | if arr[m] >= arr[m + 1]: 9 | r = m 10 | else: 11 | l = m + 1 12 | 13 | return l -------------------------------------------------------------------------------- /858-mirror-reflection/858-mirror-reflection.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mirrorReflection(int p, int q) { 4 | int m = 1; // # of room extension + 1 5 | int n = 1; // # of reflection + 1 6 | 7 | while (m * p != n * q) 8 | m = ++n * q / p; 9 | 10 | if (n % 2 == 0) 11 | return 2; 12 | if (m % 2 == 0) 13 | return 0; 14 | if (m % 2 == 1) 15 | return 1; 16 | throw; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /858-mirror-reflection/858-mirror-reflection.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int mirrorReflection(int p, int q) { 3 | int m = 1; // # of room extension + 1 4 | int n = 1; // # of reflection + 1 5 | 6 | while (m * p != n * q) 7 | m = ++n * q / p; 8 | 9 | if (n % 2 == 0) 10 | return 2; 11 | if (m % 2 == 0) 12 | return 0; 13 | if (m % 2 == 1) 14 | return 1; 15 | throw new IllegalArgumentException(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /859-buddy-strings/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def buddyStrings(self, A: str, B: str) -> bool: 3 | if len(A) != len(B): 4 | return False 5 | if A == B and len(set(A)) < len(A): 6 | return True 7 | 8 | diff = [(a, b) for a, b in zip(A, B) if a != b] 9 | 10 | return len(diff) == 2 and diff[0] == diff[1][::-1] -------------------------------------------------------------------------------- /86-partition-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /869-reordered-power-of-2/869-reordered-power-of-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool reorderedPowerOf2(int N) { 4 | string res1 = to_string(N); 5 | sort(res1.begin(), res1.end()); 6 | for (int i = 0; i < 30; i++) { 7 | string res2 = to_string(1 << i); 8 | sort(res2.begin(), res2.end()); 9 | if (res1 == res2) return true; 10 | } 11 | return false; 12 | } 13 | }; -------------------------------------------------------------------------------- /869-reordered-power-of-2/869-reordered-power-of-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean reorderedPowerOf2(int N) { 3 | char[] res1 = String.valueOf(N).toCharArray(); 4 | Arrays.sort(res1); 5 | for (int i = 0; i < 30; i++) { 6 | char[] res2 = String.valueOf(1 << i).toCharArray(); 7 | Arrays.sort(res2); 8 | if (Arrays.equals(res1, res2)) return true; 9 | } 10 | return false; 11 | } 12 | } -------------------------------------------------------------------------------- /869-reordered-power-of-2/869-reordered-power-of-2.js: -------------------------------------------------------------------------------- 1 | var reorderedPowerOf2 = function(N) { 2 | let res = N.toString().split("").sort().join("") 3 | for (let i = 0; i < 30; i++) 4 | if ((1 << i).toString().split("").sort().join("") === res) return true 5 | return false 6 | }; -------------------------------------------------------------------------------- /869-reordered-power-of-2/869-reordered-power-of-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reorderedPowerOf2(self, N: int) -> bool: 3 | res = sorted([int(x) for x in str(N)]) 4 | for i in range(30): 5 | if sorted([int(x) for x in str(1 << i)]) == res: return True 6 | return False -------------------------------------------------------------------------------- /869-reordered-power-of-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /87-scramble-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/871-minimum-number-of-refueling-stops.js: -------------------------------------------------------------------------------- 1 | var minRefuelStops = function(T, F, S) { 2 | let n = S.length, pq = new MaxPriorityQueue(), ans = 0 3 | for (let i = 0; i <= n; i++) { 4 | let dist = i === n ? T : S[i][0] 5 | while (F < dist) { 6 | if (!pq.size()) return -1 7 | F += pq.dequeue().element, ans++ 8 | } 9 | if (i < n) pq.enqueue(S[i][1]) 10 | } 11 | return ans 12 | }; -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /875-koko-eating-bananas/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minEatingSpeed(self, piles: List[int], h: int) -> int: 3 | l = 1 4 | r = max(piles) 5 | 6 | # Hours to eat all piles with speed m 7 | def eatHours(m: int) -> int: 8 | return sum((pile - 1) // m + 1 for pile in piles) 9 | 10 | while l < r: 11 | m = (l + r) // 2 12 | if eatHours(m) <= h: 13 | r = m 14 | else: 15 | l = m + 1 16 | 17 | return l 18 | -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* middleNode(ListNode* head) { 4 | ListNode* slow = head; 5 | ListNode* fast = head; 6 | 7 | while (fast && fast->next) { 8 | slow = slow->next; 9 | fast = fast->next->next; 10 | } 11 | 12 | return slow; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/0876-middle-of-the-linked-list.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode middleNode(ListNode head) { 3 | ListNode slow = head; 4 | ListNode fast = head; 5 | 6 | while (fast != null && fast.next != null) { 7 | slow = slow.next; 8 | fast = fast.next.next; 9 | } 10 | 11 | return slow; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def middleNode(self, head: ListNode) -> ListNode: 3 | slow = head 4 | fast = head 5 | 6 | while fast and fast.next: 7 | slow = slow.next 8 | fast = fast.next.next 9 | 10 | return slow 11 | -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /89-gray-code/89-gray-code.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector grayCode(int n) { 4 | vector ans{0}; 5 | 6 | for (int i = 0; i < n; ++i) 7 | for (int j = ans.size() - 1; j >= 0; --j) 8 | ans.push_back(ans[j] | 1 << i); 9 | 10 | return ans; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /89-gray-code/89-gray-code.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List grayCode(int n) { 3 | List ans = new ArrayList<>(); 4 | ans.add(0); 5 | 6 | for (int i = 0; i < n; ++i) 7 | for (int j = ans.size() - 1; j >= 0; --j) 8 | ans.add(ans.get(j) | 1 << i); 9 | 10 | return ans; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /89-gray-code/89-gray-code.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def grayCode(self, n: int) -> List[int]: 3 | ans = [0] 4 | 5 | for i in range(n): 6 | for j in reversed(range(len(ans))): 7 | ans.append(ans[j] | 1 << i) 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /89-gray-code/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /890-find-and-replace-pattern/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /899-orderly-queue/0899-orderly-queue.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string orderlyQueue(string S, int K) { 4 | if (K > 1) { 5 | sort(begin(S), end(S)); 6 | return S; 7 | } 8 | 9 | string ans = S; 10 | 11 | for (int i = 1; i < S.length(); ++i) 12 | ans = min(ans, S.substr(i) + S.substr(0, i)); 13 | 14 | return ans; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /899-orderly-queue/0899-orderly-queue.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def orderlyQueue(self, S: str, K: int) -> str: 3 | return ''.join(sorted(S)) if K > 1 else min(S[i:] + S[:i] for i in range(len(S))) 4 | -------------------------------------------------------------------------------- /899-orderly-queue/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /90-subsets-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /901-online-stock-span/0901-online-stock-span.cpp: -------------------------------------------------------------------------------- 1 | class StockSpanner { 2 | public: 3 | StockSpanner() {} 4 | int next(int price) { 5 | int span = 1; 6 | while(!stack_.empty() && price >= stack_.top().first){ 7 | span += stack_.top().second; 8 | stack_.pop(); 9 | } 10 | stack_.emplace(price, span); 11 | return span; 12 | } 13 | private: 14 | stack> stack_; // first: price, second: span 15 | }; -------------------------------------------------------------------------------- /901-online-stock-span/0901-online-stock-span.java: -------------------------------------------------------------------------------- 1 | class StockSpanner { 2 | private Stack stack; 3 | public StockSpanner() { 4 | this.stack = new Stack<>(); 5 | } 6 | 7 | public int next(int price) { 8 | int count = 1; 9 | while(!stack.isEmpty() && stack.peek()[0] <= price){ 10 | count += stack.pop()[1]; 11 | } 12 | stack.push(new int[]{price, count}); 13 | return count; 14 | } 15 | } -------------------------------------------------------------------------------- /907-sum-of-subarray-minimums/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /916-word-subsets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /92-reverse-linked-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /93-restore-ip-addresses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /936-stamping-the-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/94-binary-tree-inorder-traversal.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: 3 | ans = [] 4 | stack = [] 5 | 6 | while root or stack: 7 | while root: 8 | stack.append(root) 9 | root = root.left 10 | root = stack.pop() 11 | ans.append(root.val) 12 | root = root.right 13 | 14 | return ans 15 | -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /946-validate-stack-sequences/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool validateStackSequences(vector& pushed, vector& popped) { 4 | stack stack; 5 | int i = 0; // popped's index 6 | 7 | for (const int x : pushed) { 8 | stack.push(x); 9 | while (!stack.empty() && stack.top() == popped[i]) { 10 | stack.pop(); 11 | ++i; 12 | } 13 | } 14 | 15 | return stack.empty(); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /946-validate-stack-sequences/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validateStackSequences(int[] pushed, int[] popped) { 3 | Deque stack = new ArrayDeque<>(); 4 | int i = 0; // popped's index 5 | 6 | for (final int x : pushed) { 7 | stack.push(x); 8 | while (!stack.isEmpty() && stack.peek() == popped[i]) { 9 | stack.pop(); 10 | ++i; 11 | } 12 | } 13 | 14 | return stack.isEmpty(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /946-validate-stack-sequences/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: 3 | stack = [] 4 | i = 0 # popped's index 5 | 6 | for x in pushed: 7 | stack.append(x) 8 | while stack and stack[-1] == popped[i]: 9 | stack.pop() 10 | i += 1 11 | 12 | return not stack 13 | -------------------------------------------------------------------------------- /948-bag-of-tokens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /95-unique-binary-search-trees-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /96-unique-binary-search-trees/96-unique-binary-search-trees.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numTrees(int n) { 4 | // G[i] := # of unique BST's that store values 1..i 5 | vector G(n + 1); 6 | G[0] = 1; 7 | G[1] = 1; 8 | 9 | for (int i = 2; i <= n; ++i) 10 | for (int j = 0; j < i; ++j) 11 | G[i] += G[j] * G[i - j - 1]; 12 | 13 | return G[n]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /96-unique-binary-search-trees/96-unique-binary-search-trees.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numTrees(int n) { 3 | // G[i] := # of unique BST's that store values 1..i 4 | int[] G = new int[n + 1]; 5 | G[0] = 1; 6 | G[1] = 1; 7 | 8 | for (int i = 2; i <= n; ++i) 9 | for (int j = 0; j < i; ++j) 10 | G[i] += G[j] * G[i - j - 1]; 11 | 12 | return G[n]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /96-unique-binary-search-trees/96-unique-binary-search-trees.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numTrees(self, n: int) -> int: 3 | # G[i] := # of unique BST's that store values 1..i 4 | G = [1, 1] + [0] * (n - 1) 5 | 6 | for i in range(2, n + 1): 7 | for j in range(i): 8 | G[i] += G[j] * G[i - j - 1] 9 | 10 | return G[n] 11 | -------------------------------------------------------------------------------- /96-unique-binary-search-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /967-numbers-with-same-consecutive-differences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /968-binary-tree-cameras/968-binary-tree-cameras.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minCameraCover(TreeNode* root) { 4 | return dfs(root) > 2 ? ans + 1 : ans; 5 | } 6 | int dfs(TreeNode* node) { 7 | if (!node) return 0; 8 | int val = dfs(node->left) + dfs(node->right); 9 | if (val == 0) return 3; 10 | if (val < 3) return 0; 11 | ans++; 12 | return 1; 13 | } 14 | private: 15 | int ans = 0; 16 | }; -------------------------------------------------------------------------------- /968-binary-tree-cameras/968-binary-tree-cameras.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private int ans = 0; 3 | public int minCameraCover(TreeNode root) { 4 | return dfs(root) > 2 ? ans + 1 : ans; 5 | } 6 | public int dfs(TreeNode node) { 7 | if (node == null) return 0; 8 | int val = dfs(node.left) + dfs(node.right); 9 | if (val == 0) return 3; 10 | if (val < 3) return 0; 11 | ans++; 12 | return 1; 13 | } 14 | } -------------------------------------------------------------------------------- /968-binary-tree-cameras/968-binary-tree-cameras.js: -------------------------------------------------------------------------------- 1 | var minCameraCover = function(root) { 2 | let ans = 0 3 | const dfs = node => { 4 | if (!node) return 0 5 | let val = dfs(node.left) + dfs(node.right) 6 | if (val === 0) return 3 7 | if (val < 3) return 0 8 | ans++ 9 | return 1 10 | } 11 | return dfs(root) > 2 ? ans + 1 : ans 12 | }; -------------------------------------------------------------------------------- /968-binary-tree-cameras/968-binary-tree-cameras.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | ans = 0 3 | def minCameraCover(self, root: TreeNode) -> int: 4 | def dfs(node: TreeNode) -> int: 5 | if not node: return 0 6 | val = dfs(node.left) + dfs(node.right) 7 | if val == 0: return 3 8 | if val < 3: return 0 9 | self.ans += 1 10 | return 1 11 | return self.ans + 1 if dfs(root) > 2 else self.ans -------------------------------------------------------------------------------- /968-binary-tree-cameras/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /97-interleaving-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /980-unique-paths-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /981-time-based-key-value-store/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /985-sum-of-even-numbers-after-queries/985-sum-of-even-numbers-after-queries.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) -> List[int]: 3 | ans = [] 4 | summ = sum(a for a in A if a % 2 == 0) 5 | 6 | for q in queries: 7 | if A[q[1]] % 2 == 0: 8 | summ -= A[q[1]] 9 | A[q[1]] += q[0] 10 | if A[q[1]] % 2 == 0: 11 | summ += A[q[1]] 12 | ans.append(summ) 13 | 14 | return ans 15 | -------------------------------------------------------------------------------- /985-sum-of-even-numbers-after-queries/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /987-vertical-order-traversal-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /99-recover-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /990-satisfiability-of-equality-equations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /997-find-the-town-judge/solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findJudge(int n, vector>& trust) { 4 | vector count(n + 1); 5 | 6 | for (vector& t : trust) { 7 | --count[t[0]]; 8 | ++count[t[1]]; 9 | } 10 | 11 | for (int i = 1; i < n + 1; ++i) 12 | if (count[i] == n - 1) 13 | return i; 14 | 15 | return -1; 16 | } 17 | }; -------------------------------------------------------------------------------- /997-find-the-town-judge/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findJudge(int n, int[][] trust) { 3 | int[] count = new int[n + 1]; 4 | 5 | for (int[] t : trust) { 6 | --count[t[0]]; 7 | ++count[t[1]]; 8 | } 9 | 10 | for (int i = 1; i < n + 1; ++i) 11 | if (count[i] == n - 1) 12 | return i; 13 | 14 | return -1; 15 | } 16 | } -------------------------------------------------------------------------------- /997-find-the-town-judge/solution.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findJudge(self, n: int, trust: List[List[int]]) -> int: 3 | count = [0] * (n + 1) 4 | 5 | for a, b in trust: 6 | count[a] -= 1 7 | count[b] += 1 8 | 9 | for i in range(1, n + 1): 10 | if count[i] == n - 1: 11 | return i 12 | 13 | return -1 -------------------------------------------------------------------------------- /profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MonitSharma/LeetCode-Solutions/dfbc360af651caa6781fa7fbb8254f0ee18e96e9/profile.png --------------------------------------------------------------------------------