├── 0001-two-sum ├── 0001-two-sum.cpp ├── NOTES.md └── README.md ├── 0005-longest-palindromic-substring ├── 0005-longest-palindromic-substring.cpp ├── NOTES.md └── README.md ├── 0020-valid-parentheses ├── 0020-valid-parentheses.cpp ├── NOTES.md └── README.md ├── 0026-remove-duplicates-from-sorted-array ├── NOTES.md └── README.md ├── 0033-search-in-rotated-sorted-array ├── 0033-search-in-rotated-sorted-array.cpp ├── NOTES.md └── README.md ├── 0034-find-first-and-last-position-of-element-in-sorted-array ├── 0034-find-first-and-last-position-of-element-in-sorted-array.cpp ├── NOTES.md └── README.md ├── 0036-valid-sudoku ├── 0036-valid-sudoku.cpp ├── NOTES.md └── README.md ├── 0038-count-and-say ├── 0038-count-and-say.cpp └── README.md ├── 0045-jump-game-ii ├── 0045-jump-game-ii.cpp ├── NOTES.md └── README.md ├── 0049-group-anagrams ├── 0049-group-anagrams.cpp ├── NOTES.md └── README.md ├── 0050-powx-n ├── 0050-powx-n.cpp ├── NOTES.md └── README.md ├── 0054-spiral-matrix ├── 0054-spiral-matrix.cpp ├── NOTES.md └── README.md ├── 0055-jump-game ├── 0055-jump-game.cpp ├── NOTES.md └── README.md ├── 0057-insert-interval ├── 0057-insert-interval.cpp ├── NOTES.md └── README.md ├── 0059-spiral-matrix-ii ├── 0059-spiral-matrix-ii.cpp ├── NOTES.md └── README.md ├── 0063-unique-paths-ii ├── 0063-unique-paths-ii.cpp ├── NOTES.md └── README.md ├── 0067-add-binary ├── 0067-add-binary.cpp ├── NOTES.md └── README.md ├── 0070-climbing-stairs ├── 0070-climbing-stairs.cpp ├── NOTES.md └── README.md ├── 0071-simplify-path ├── 0071-simplify-path.cpp ├── NOTES.md └── README.md ├── 0076-minimum-window-substring ├── 0076-minimum-window-substring.cpp ├── NOTES.md └── README.md ├── 0093-restore-ip-addresses ├── 0093-restore-ip-addresses.cpp ├── NOTES.md └── README.md ├── 0100-same-tree ├── 0100-same-tree.cpp ├── NOTES.md └── README.md ├── 0105-construct-binary-tree-from-preorder-and-inorder-traversal ├── 0105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp └── README.md ├── 0109-convert-sorted-list-to-binary-search-tree ├── 0109-convert-sorted-list-to-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 0121-best-time-to-buy-and-sell-stock ├── 0121-best-time-to-buy-and-sell-stock.cpp ├── NOTES.md └── README.md ├── 0124-binary-tree-maximum-path-sum ├── 0124-binary-tree-maximum-path-sum.cpp ├── NOTES.md └── README.md ├── 0128-longest-consecutive-sequence ├── 0128-longest-consecutive-sequence.cpp ├── NOTES.md └── README.md ├── 0129-sum-root-to-leaf-numbers ├── 0129-sum-root-to-leaf-numbers.cpp ├── NOTES.md └── README.md ├── 0131-palindrome-partitioning ├── 0131-palindrome-partitioning.cpp ├── NOTES.md └── README.md ├── 0134-gas-station ├── 0134-gas-station.cpp ├── NOTES.md └── README.md ├── 0139-word-break ├── 0139-word-break.cpp ├── NOTES.md └── README.md ├── 0140-word-break-ii ├── 0140-word-break-ii.cpp ├── NOTES.md └── README.md ├── 0141-linked-list-cycle ├── 0141-linked-list-cycle.cpp ├── NOTES.md └── README.md ├── 0142-linked-list-cycle-ii ├── 0142-linked-list-cycle-ii.cpp ├── NOTES.md └── README.md ├── 0143-reorder-list ├── 0143-reorder-list.cpp ├── NOTES.md └── README.md ├── 0145-binary-tree-postorder-traversal ├── 0145-binary-tree-postorder-traversal.cpp └── README.md ├── 0150-evaluate-reverse-polish-notation ├── 0150-evaluate-reverse-polish-notation.cpp ├── NOTES.md └── README.md ├── 0151-reverse-words-in-a-string ├── 0151-reverse-words-in-a-string.cpp ├── NOTES.md └── README.md ├── 0169-majority-element ├── 0169-majority-element.cpp ├── NOTES.md └── README.md ├── 0198-house-robber ├── 0198-house-robber.cpp ├── NOTES.md └── README.md ├── 0212-word-search-ii ├── 0212-word-search-ii.cpp ├── NOTES.md └── README.md ├── 0217-contains-duplicate ├── 0217-contains-duplicate.cpp ├── NOTES.md └── README.md ├── 0219-contains-duplicate-ii ├── NOTES.md └── README.md ├── 0222-count-complete-tree-nodes ├── NOTES.md └── README.md ├── 0224-basic-calculator ├── 0224-basic-calculator.cpp ├── NOTES.md └── README.md ├── 0226-invert-binary-tree ├── 0226-invert-binary-tree.cpp ├── NOTES.md └── README.md ├── 0237-delete-node-in-a-linked-list ├── NOTES.md └── README.md ├── 0238-product-of-array-except-self ├── 0238-product-of-array-except-self.cpp ├── NOTES.md └── README.md ├── 0242-valid-anagram ├── 0242-valid-anagram.cpp ├── NOTES.md └── README.md ├── 0263-ugly-number ├── 0263-ugly-number.cpp ├── NOTES.md └── README.md ├── 0264-ugly-number-ii ├── 0264-ugly-number-ii.cpp └── README.md ├── 0279-perfect-squares ├── NOTES.md └── README.md ├── 0290-word-pattern ├── 0290-word-pattern.cpp ├── NOTES.md └── README.md ├── 0300-longest-increasing-subsequence ├── 0300-longest-increasing-subsequence.cpp ├── NOTES.md └── README.md ├── 0334-increasing-triplet-subsequence ├── 0334-increasing-triplet-subsequence.cpp ├── NOTES.md └── README.md ├── 0341-flatten-nested-list-iterator ├── 0341-flatten-nested-list-iterator.cpp ├── NOTES.md └── README.md ├── 0347-top-k-frequent-elements ├── 0347-top-k-frequent-elements.cpp ├── NOTES.md └── README.md ├── 0374-guess-number-higher-or-lower ├── NOTES.md └── README.md ├── 0392-is-subsequence ├── NOTES.md └── README.md ├── 0399-evaluate-division ├── 0399-evaluate-division.cpp ├── NOTES.md └── README.md ├── 0433-minimum-genetic-mutation ├── 0433-minimum-genetic-mutation.cpp ├── NOTES.md └── README.md ├── 0443-string-compression ├── 0443-string-compression.cpp ├── NOTES.md └── README.md ├── 0451-sort-characters-by-frequency ├── 0451-sort-characters-by-frequency.cpp ├── NOTES.md └── README.md ├── 0452-minimum-number-of-arrows-to-burst-balloons ├── 0452-minimum-number-of-arrows-to-burst-balloons.cpp ├── NOTES.md └── README.md ├── 0455-assign-cookies ├── 0455-assign-cookies.cpp ├── NOTES.md └── README.md ├── 0458-poor-pigs ├── 0458-poor-pigs.cpp ├── NOTES.md └── README.md ├── 0472-concatenated-words ├── 0472-concatenated-words.cpp ├── NOTES.md └── README.md ├── 0476-number-complement ├── 0476-number-complement.cpp └── README.md ├── 0513-find-bottom-left-tree-value ├── 0513-find-bottom-left-tree-value.cpp ├── NOTES.md └── README.md ├── 0516-longest-palindromic-subsequence ├── 0516-longest-palindromic-subsequence.cpp ├── NOTES.md └── README.md ├── 0520-detect-capital ├── 0520-detect-capital.cpp ├── NOTES.md └── README.md ├── 0523-continuous-subarray-sum ├── 0523-continuous-subarray-sum.cpp ├── NOTES.md └── README.md ├── 0530-minimum-absolute-difference-in-bst ├── 0530-minimum-absolute-difference-in-bst.cpp ├── NOTES.md └── README.md ├── 0540-single-element-in-a-sorted-array ├── 0540-single-element-in-a-sorted-array.cpp ├── NOTES.md └── README.md ├── 0542-01-matrix ├── 0542-01-matrix.cpp ├── NOTES.md └── README.md ├── 0567-permutation-in-string ├── 0567-permutation-in-string.cpp ├── NOTES.md └── README.md ├── 0592-fraction-addition-and-subtraction ├── 0592-fraction-addition-and-subtraction.cpp └── README.md ├── 0621-task-scheduler ├── 0621-task-scheduler.cpp ├── NOTES.md └── README.md ├── 0624-maximum-distance-in-arrays ├── 0624-maximum-distance-in-arrays.cpp └── README.md ├── 0633-sum-of-square-numbers ├── 0633-sum-of-square-numbers.cpp ├── NOTES.md └── README.md ├── 0645-set-mismatch ├── 0645-set-mismatch.cpp ├── NOTES.md └── README.md ├── 0646-maximum-length-of-pair-chain ├── 0646-maximum-length-of-pair-chain.cpp ├── NOTES.md └── README.md ├── 0647-palindromic-substrings ├── 0647-palindromic-substrings.cpp ├── NOTES.md └── README.md ├── 0652-find-duplicate-subtrees ├── 0652-find-duplicate-subtrees.cpp ├── NOTES.md └── README.md ├── 0662-maximum-width-of-binary-tree ├── 0662-maximum-width-of-binary-tree.cpp └── NOTES.md ├── 0673-number-of-longest-increasing-subsequence ├── 0673-number-of-longest-increasing-subsequence.cpp ├── NOTES.md └── README.md ├── 0692-top-k-frequent-words ├── 0692-top-k-frequent-words.cpp ├── NOTES.md └── README.md ├── 0703-kth-largest-element-in-a-stream ├── 0703-kth-largest-element-in-a-stream.cpp ├── NOTES.md └── README.md ├── 0704-binary-search ├── 0704-binary-search.cpp ├── NOTES.md └── README.md ├── 0713-subarray-product-less-than-k ├── 0713-subarray-product-less-than-k.cpp ├── NOTES.md └── README.md ├── 0714-best-time-to-buy-and-sell-stock-with-transaction-fee ├── 0714-best-time-to-buy-and-sell-stock-with-transaction-fee.cpp ├── NOTES.md └── README.md ├── 0726-number-of-atoms ├── 0726-number-of-atoms.cpp └── README.md ├── 0739-daily-temperatures ├── 0739-daily-temperatures.cpp ├── NOTES.md └── README.md ├── 0744-find-smallest-letter-greater-than-target ├── 0744-find-smallest-letter-greater-than-target.cpp ├── NOTES.md └── README.md ├── 0746-min-cost-climbing-stairs ├── 0746-min-cost-climbing-stairs.cpp ├── NOTES.md └── README.md ├── 0766-toeplitz-matrix ├── 0766-toeplitz-matrix.cpp ├── NOTES.md └── README.md ├── 0776-n-ary-tree-postorder-traversal ├── 0776-n-ary-tree-postorder-traversal.cpp └── README.md ├── 0787-cheapest-flights-within-k-stops ├── 0787-cheapest-flights-within-k-stops.cpp ├── NOTES.md └── README.md ├── 0789-kth-largest-element-in-a-stream ├── 0789-kth-largest-element-in-a-stream.cpp └── README.md ├── 0790-domino-and-tromino-tiling ├── 0790-domino-and-tromino-tiling.cpp ├── NOTES.md └── README.md ├── 0791-custom-sort-string ├── 0791-custom-sort-string.cpp ├── NOTES.md └── README.md ├── 0797-all-paths-from-source-to-target ├── 0797-all-paths-from-source-to-target.cpp ├── NOTES.md └── README.md ├── 0815-bus-routes ├── 0815-bus-routes.cpp ├── NOTES.md └── README.md ├── 0834-sum-of-distances-in-tree ├── 0834-sum-of-distances-in-tree.cpp ├── NOTES.md └── README.md ├── 0872-leaf-similar-trees ├── 0872-leaf-similar-trees.cpp ├── NOTES.md └── README.md ├── 0875-koko-eating-bananas ├── 0875-koko-eating-bananas.cpp ├── NOTES.md └── README.md ├── 0876-middle-of-the-linked-list ├── 0876-middle-of-the-linked-list.cpp ├── NOTES.md └── README.md ├── 0886-possible-bipartition ├── 0886-possible-bipartition.cpp ├── NOTES.md └── README.md ├── 0896-monotonic-array ├── 0896-monotonic-array.cpp ├── NOTES.md └── README.md ├── 0901-online-stock-span ├── NOTES.md └── README.md ├── 0905-length-of-longest-fibonacci-subsequence ├── 0905-length-of-longest-fibonacci-subsequence.cpp └── README.md ├── 0907-sum-of-subarray-minimums ├── 0907-sum-of-subarray-minimums.cpp ├── NOTES.md └── README.md ├── 0918-maximum-sum-circular-subarray ├── 0918-maximum-sum-circular-subarray.cpp ├── NOTES.md └── README.md ├── 0921-spiral-matrix-iii ├── 0921-spiral-matrix-iii.cpp └── README.md ├── 0925-construct-binary-tree-from-preorder-and-postorder-traversal ├── 0925-construct-binary-tree-from-preorder-and-postorder-traversal.cpp └── README.md ├── 0931-minimum-falling-path-sum ├── 0931-minimum-falling-path-sum.cpp ├── NOTES.md └── README.md ├── 0934-shortest-bridge ├── 0934-shortest-bridge.cpp ├── NOTES.md └── README.md ├── 0935-knight-dialer ├── 0935-knight-dialer.cpp ├── NOTES.md └── README.md ├── 0938-range-sum-of-bst ├── 0938-range-sum-of-bst.cpp ├── NOTES.md └── README.md ├── 0945-minimum-increment-to-make-array-unique ├── 0945-minimum-increment-to-make-array-unique.cpp ├── NOTES.md └── README.md ├── 0958-check-completeness-of-a-binary-tree ├── 0958-check-completeness-of-a-binary-tree.cpp ├── NOTES.md └── README.md ├── 0976-largest-perimeter-triangle ├── NOTES.md └── README.md ├── 0997-find-the-town-judge ├── 0997-find-the-town-judge.cpp ├── NOTES.md └── README.md ├── 1-two-sum ├── NOTES.md └── README.md ├── 100-same-tree ├── 100-same-tree.cpp ├── NOTES.md └── README.md ├── 1004-max-consecutive-ones-iii ├── 1004-max-consecutive-ones-iii.cpp ├── NOTES.md └── README.md ├── 1007-minimum-domino-rotations-for-equal-row ├── NOTES.md └── README.md ├── 1010-pairs-of-songs-with-total-durations-divisible-by-60 ├── NOTES.md └── README.md ├── 1011-capacity-to-ship-packages-within-d-days ├── 1011-capacity-to-ship-packages-within-d-days.cpp ├── NOTES.md └── README.md ├── 102-binary-tree-level-order-traversal ├── 102-binary-tree-level-order-traversal.cpp ├── NOTES.md └── README.md ├── 1022-sum-of-root-to-leaf-binary-numbers ├── 1022-sum-of-root-to-leaf-binary-numbers.cpp └── README.md ├── 1029-two-city-scheduling ├── NOTES.md └── README.md ├── 1035-uncrossed-lines ├── 1035-uncrossed-lines.cpp ├── NOTES.md └── README.md ├── 1038-binary-search-tree-to-greater-sum-tree ├── 1038-binary-search-tree-to-greater-sum-tree.cpp ├── NOTES.md └── README.md ├── 104-maximum-depth-of-binary-tree ├── NOTES.md └── README.md ├── 1043-partition-array-for-maximum-sum ├── 1043-partition-array-for-maximum-sum.cpp ├── NOTES.md └── README.md ├── 1046-last-stone-weight ├── 1046-last-stone-weight.java ├── NOTES.md └── README.md ├── 1047-remove-all-adjacent-duplicates-in-string ├── 1047-remove-all-adjacent-duplicates-in-string.cpp ├── NOTES.md └── README.md ├── 1048-longest-string-chain ├── 1048-longest-string-chain.cpp ├── NOTES.md └── README.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp ├── NOTES.md └── README.md ├── 1071-greatest-common-divisor-of-strings ├── 1071-greatest-common-divisor-of-strings.cpp ├── NOTES.md └── README.md ├── 1074-number-of-submatrices-that-sum-to-target ├── 1074-number-of-submatrices-that-sum-to-target.cpp ├── NOTES.md └── README.md ├── 108-convert-sorted-array-to-binary-search-tree ├── 108-convert-sorted-array-to-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 1091-shortest-path-in-binary-matrix ├── 1091-shortest-path-in-binary-matrix.cpp ├── NOTES.md └── README.md ├── 1093-recover-a-tree-from-preorder-traversal ├── 1093-recover-a-tree-from-preorder-traversal.cpp └── README.md ├── 1094-car-pooling ├── 1094-car-pooling.cpp ├── NOTES.md └── README.md ├── 11-container-with-most-water ├── NOTES.md └── README.md ├── 1101-the-earliest-moment-when-everyone-become-friends ├── 1101-the-earliest-moment-when-everyone-become-friends.cpp ├── NOTES.md └── README.md ├── 1110-delete-nodes-and-return-forest ├── 1110-delete-nodes-and-return-forest.cpp ├── NOTES.md └── README.md ├── 112-path-sum ├── 112-path-sum.cpp ├── NOTES.md └── README.md ├── 113-path-sum-ii ├── 113-path-sum-ii.cpp ├── NOTES.md └── README.md ├── 1136-parallel-courses ├── 1136-parallel-courses.cpp ├── NOTES.md └── README.md ├── 1137-n-th-tribonacci-number ├── 1137-n-th-tribonacci-number.cpp ├── NOTES.md └── README.md ├── 114-flatten-binary-tree-to-linked-list ├── 114-flatten-binary-tree-to-linked-list.cpp └── README.md ├── 1143-longest-common-subsequence ├── 1143-longest-common-subsequence.cpp ├── NOTES.md └── README.md ├── 1146-snapshot-array ├── 1146-snapshot-array.cpp ├── NOTES.md └── README.md ├── 1153-string-transforms-into-another-string ├── 1153-string-transforms-into-another-string.cpp ├── NOTES.md └── README.md ├── 1155-number-of-dice-rolls-with-target-sum ├── 1155-number-of-dice-rolls-with-target-sum.cpp ├── NOTES.md └── README.md ├── 1161-maximum-level-sum-of-a-binary-tree ├── NOTES.md └── README.md ├── 1167-minimum-cost-to-connect-sticks ├── NOTES.md └── README.md ├── 117-populating-next-right-pointers-in-each-node-ii ├── 117-populating-next-right-pointers-in-each-node-ii.cpp ├── NOTES.md └── README.md ├── 1170-shortest-common-supersequence ├── 1170-shortest-common-supersequence.cpp └── README.md ├── 118-pascals-triangle ├── 118-pascals-triangle.cpp ├── NOTES.md └── README.md ├── 1186-maximum-subarray-sum-with-one-deletion ├── 1186-maximum-subarray-sum-with-one-deletion.cpp ├── NOTES.md └── README.md ├── 1189-maximum-number-of-balloons ├── 1189-maximum-number-of-balloons.cpp ├── NOTES.md └── README.md ├── 1192-critical-connections-in-a-network ├── 1192-critical-connections-in-a-network.cpp └── README.md ├── 1196-filling-bookcase-shelves ├── 1196-filling-bookcase-shelves.cpp └── README.md ├── 12-integer-to-roman ├── NOTES.md └── README.md ├── 1207-delete-nodes-and-return-forest ├── 1207-delete-nodes-and-return-forest.cpp └── README.md ├── 1207-unique-number-of-occurrences ├── 1207-unique-number-of-occurrences.cpp ├── NOTES.md └── README.md ├── 1209-remove-all-adjacent-duplicates-in-string-ii ├── 1209-remove-all-adjacent-duplicates-in-string-ii.cpp ├── NOTES.md └── README.md ├── 121-best-time-to-buy-and-sell-stock └── README.md ├── 1218-longest-arithmetic-subsequence-of-given-difference ├── 1218-longest-arithmetic-subsequence-of-given-difference.cpp ├── NOTES.md └── README.md ├── 1220-count-vowels-permutation ├── 1220-count-vowels-permutation.cpp ├── NOTES.md └── README.md ├── 1232-check-if-it-is-a-straight-line ├── 1232-check-if-it-is-a-straight-line.cpp ├── NOTES.md └── README.md ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters.cpp ├── NOTES.md └── README.md ├── 124-binary-tree-maximum-path-sum ├── NOTES.md └── README.md ├── 1244-design-a-leaderboard ├── NOTES.md └── README.md ├── 1249-minimum-remove-to-make-valid-parentheses ├── 1249-minimum-remove-to-make-valid-parentheses.cpp ├── NOTES.md └── README.md ├── 126-word-ladder-ii ├── 126-word-ladder-ii.cpp ├── NOTES.md └── README.md ├── 1268-search-suggestions-system ├── 1268-search-suggestions-system.cpp ├── NOTES.md └── README.md ├── 127-word-ladder ├── 127-word-ladder.cpp ├── NOTES.md └── README.md ├── 1274-number-of-ships-in-a-rectangle ├── 1274-number-of-ships-in-a-rectangle.cpp ├── NOTES.md └── README.md ├── 1275-find-winner-on-a-tic-tac-toe-game ├── NOTES.md └── README.md ├── 128-longest-consecutive-sequence ├── 128-longest-consecutive-sequence.cpp ├── NOTES.md └── README.md ├── 1284-minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix ├── 1284-minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix.cpp ├── NOTES.md └── README.md ├── 1288-remove-covered-intervals ├── NOTES.md └── README.md ├── 1291-sequential-digits ├── 1291-sequential-digits.cpp ├── NOTES.md └── README.md ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.cpp ├── NOTES.md └── README.md ├── 1298-reverse-substrings-between-each-pair-of-parentheses ├── 1298-reverse-substrings-between-each-pair-of-parentheses.cpp └── README.md ├── 13-roman-to-integer ├── 13-roman-to-integer.cpp ├── NOTES.md └── README.md ├── 1304-find-n-unique-integers-sum-up-to-zero └── README.md ├── 131-palindrome-partitioning ├── 131-palindrome-partitioning.cpp ├── NOTES.md └── README.md ├── 1319-number-of-operations-to-make-network-connected ├── 1319-number-of-operations-to-make-network-connected.cpp ├── NOTES.md └── README.md ├── 1325-path-with-maximum-probability ├── 1325-path-with-maximum-probability.cpp └── README.md ├── 1328-break-a-palindrome ├── 1328-break-a-palindrome.cpp ├── NOTES.md └── README.md ├── 1329-sort-the-matrix-diagonally ├── 1329-sort-the-matrix-diagonally.cpp ├── NOTES.md └── README.md ├── 133-clone-graph ├── 133-clone-graph.cpp ├── NOTES.md └── README.md ├── 1332-remove-palindromic-subsequences ├── NOTES.md └── README.md ├── 1333-sort-the-jumbled-numbers ├── 1333-sort-the-jumbled-numbers.cpp └── README.md ├── 1345-jump-game-iv ├── 1345-jump-game-iv.cpp ├── NOTES.md └── README.md ├── 1347-minimum-number-of-steps-to-make-two-strings-anagram ├── NOTES.md └── README.md ├── 135-candy ├── 135-candy.cpp └── README.md ├── 1354-construct-target-array-with-multiple-sums ├── 1354-construct-target-array-with-multiple-sums.cpp ├── NOTES.md └── README.md ├── 1361-validate-binary-tree-nodes ├── 1361-validate-binary-tree-nodes.cpp ├── NOTES.md └── README.md ├── 1364-tuple-with-same-product ├── 1364-tuple-with-same-product.cpp └── README.md ├── 1377-frog-position-after-t-seconds ├── 1377-frog-position-after-t-seconds.cpp ├── NOTES.md └── README.md ├── 138-copy-list-with-random-pointer ├── 138-copy-list-with-random-pointer.cpp ├── NOTES.md └── README.md ├── 1381-design-a-stack-with-increment-operation ├── 1381-design-a-stack-with-increment-operation.cpp ├── NOTES.md └── README.md ├── 1383-maximum-performance-of-a-team ├── 1383-maximum-performance-of-a-team.cpp ├── NOTES.md └── README.md ├── 1386-cinema-seat-allocation ├── NOTES.md └── README.md ├── 1387-find-elements-in-a-contaminated-binary-tree ├── 1387-find-elements-in-a-contaminated-binary-tree.cpp └── README.md ├── 139-word-break ├── 139-word-break.cpp ├── NOTES.md └── README.md ├── 1396-design-underground-system ├── NOTES.md └── README.md ├── 140-word-break-ii ├── 140-word-break-ii.cpp ├── NOTES.md └── README.md ├── 1405-longest-happy-string ├── 1405-longest-happy-string.cpp ├── NOTES.md └── README.md ├── 141-linked-list-cycle ├── 141-linked-list-cycle.cpp ├── NOTES.md └── README.md ├── 1424-diagonal-traverse-ii ├── 1424-diagonal-traverse-ii.cpp ├── NOTES.md └── README.md ├── 1428-leftmost-column-with-at-least-a-one ├── 1428-leftmost-column-with-at-least-a-one.cpp ├── NOTES.md └── README.md ├── 143-reorder-list └── README.md ├── 1431-kids-with-the-greatest-number-of-candies ├── 1431-kids-with-the-greatest-number-of-candies.cpp └── NOTES.md ├── 1436-destination-city ├── 1436-destination-city.cpp ├── NOTES.md └── README.md ├── 144-binary-tree-preorder-traversal ├── 144-binary-tree-preorder-traversal.cpp ├── NOTES.md └── README.md ├── 1448-count-good-nodes-in-binary-tree ├── 1448-count-good-nodes-in-binary-tree.cpp ├── NOTES.md └── README.md ├── 1457-pseudo-palindromic-paths-in-a-binary-tree ├── NOTES.md └── README.md ├── 146-lru-cache ├── NOTES.md └── README.md ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts ├── NOTES.md └── README.md ├── 1472-design-browser-history ├── 1472-design-browser-history.cpp ├── NOTES.md └── README.md ├── 1473-paint-house-iii ├── 1473-paint-house-iii.cpp ├── NOTES.md └── README.md ├── 1477-product-of-the-last-k-numbers ├── 1477-product-of-the-last-k-numbers.cpp └── README.md ├── 1480-running-sum-of-1d-array ├── NOTES.md └── README.md ├── 1490-clone-n-ary-tree ├── 1490-clone-n-ary-tree.cpp ├── NOTES.md └── README.md ├── 1492-the-kth-factor-of-n ├── NOTES.md └── README.md ├── 1493-longest-subarray-of-1s-after-deleting-one-element ├── 1493-longest-subarray-of-1s-after-deleting-one-element.cpp ├── NOTES.md └── README.md ├── 1496-lucky-numbers-in-a-matrix ├── 1496-lucky-numbers-in-a-matrix.cpp └── README.md ├── 15-3sum ├── 15-3sum.cpp ├── NOTES.md └── README.md ├── 1504-count-submatrices-with-all-ones ├── 1504-count-submatrices-with-all-ones.cpp ├── NOTES.md └── README.md ├── 1507-reformat-date ├── NOTES.md └── README.md ├── 151-reverse-words-in-a-string ├── 151-reverse-words-in-a-string.cpp ├── NOTES.md └── README.md ├── 1510-stone-game-iv ├── 1510-stone-game-iv.cpp ├── NOTES.md └── README.md ├── 1511-count-number-of-teams ├── 1511-count-number-of-teams.cpp └── README.md ├── 1514-path-with-maximum-probability ├── 1514-path-with-maximum-probability.cpp ├── NOTES.md └── README.md ├── 1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n ├── 1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n.cpp └── README.md ├── 1519-number-of-nodes-in-the-sub-tree-with-the-same-label ├── 1519-number-of-nodes-in-the-sub-tree-with-the-same-label.cpp ├── NOTES.md └── README.md ├── 152-maximum-product-subarray ├── 152-maximum-product-subarray.cpp ├── NOTES.md └── README.md ├── 1522-diameter-of-n-ary-tree ├── 1522-diameter-of-n-ary-tree.cpp ├── NOTES.md └── README.md ├── 153-find-minimum-in-rotated-sorted-array ├── 153-find-minimum-in-rotated-sorted-array.cpp ├── NOTES.md └── README.md ├── 1530-number-of-good-leaf-nodes-pairs ├── 1530-number-of-good-leaf-nodes-pairs.cpp ├── NOTES.md └── README.md ├── 1539-kth-missing-positive-number ├── 1539-kth-missing-positive-number.cpp ├── NOTES.md └── README.md ├── 1544-make-the-string-great ├── NOTES.md └── README.md ├── 1548-the-most-similar-path-in-a-graph ├── 1548-the-most-similar-path-in-a-graph.cpp ├── NOTES.md └── README.md ├── 1553-minimum-number-of-days-to-eat-n-oranges └── README.md ├── 1554-strings-differ-by-one-character ├── 1554-strings-differ-by-one-character.cpp ├── NOTES.md └── README.md ├── 1556-make-two-arrays-equal-by-reversing-subarrays ├── 1556-make-two-arrays-equal-by-reversing-subarrays.cpp └── README.md ├── 1557-minimum-number-of-vertices-to-reach-all-nodes ├── 1557-minimum-number-of-vertices-to-reach-all-nodes.cpp ├── NOTES.md └── README.md ├── 1578-minimum-time-to-make-rope-colorful ├── 1578-minimum-time-to-make-rope-colorful.cpp ├── NOTES.md └── README.md ├── 1583-count-unhappy-friends ├── NOTES.md └── README.md ├── 1584-min-cost-to-connect-all-points ├── 1584-min-cost-to-connect-all-points.cpp ├── NOTES.md └── README.md ├── 16-3sum-closest ├── 16-3sum-closest.cpp ├── NOTES.md └── README.md ├── 160-intersection-of-two-linked-lists ├── 160-intersection-of-two-linked-lists.cpp ├── NOTES.md └── README.md ├── 1614-maximum-nesting-depth-of-the-parentheses ├── NOTES.md └── README.md ├── 1615-range-sum-of-sorted-subarray-sums ├── 1615-range-sum-of-sorted-subarray-sums.cpp └── README.md ├── 162-find-peak-element └── NOTES.md ├── 1631-number-of-sub-arrays-with-odd-sum ├── 1631-number-of-sub-arrays-with-odd-sum.cpp └── README.md ├── 1631-path-with-minimum-effort ├── 1631-path-with-minimum-effort.cpp ├── NOTES.md └── README.md ├── 1632-rank-transform-of-a-matrix ├── 1632-rank-transform-of-a-matrix.cpp ├── NOTES.md └── README.md ├── 1642-furthest-building-you-can-reach ├── 1642-furthest-building-you-can-reach.cpp ├── NOTES.md └── README.md ├── 1644-lowest-common-ancestor-of-a-binary-tree-ii ├── 1644-lowest-common-ancestor-of-a-binary-tree-ii.cpp ├── NOTES.md └── README.md ├── 1647-minimum-deletions-to-make-character-frequencies-unique ├── 1647-minimum-deletions-to-make-character-frequencies-unique.cpp ├── NOTES.md └── README.md ├── 1653-number-of-good-leaf-nodes-pairs ├── 1653-number-of-good-leaf-nodes-pairs.cpp └── README.md ├── 1656-design-an-ordered-stream └── README.md ├── 1657-determine-if-two-strings-are-close ├── 1657-determine-if-two-strings-are-close.cpp ├── NOTES.md └── README.md ├── 1658-minimum-operations-to-reduce-x-to-zero ├── 1658-minimum-operations-to-reduce-x-to-zero.cpp ├── NOTES.md └── README.md ├── 1662-check-if-two-string-arrays-are-equivalent ├── 1662-check-if-two-string-arrays-are-equivalent.cpp ├── NOTES.md └── README.md ├── 167-two-sum-ii-input-array-is-sorted ├── NOTES.md └── README.md ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers ├── NOTES.md └── README.md ├── 1691-minimum-number-of-days-to-disconnect-island ├── 1691-minimum-number-of-days-to-disconnect-island.cpp └── README.md ├── 1695-maximum-erasure-value ├── 1695-maximum-erasure-value.cpp ├── NOTES.md └── README.md ├── 1696-jump-game-vi ├── 1696-jump-game-vi.cpp ├── NOTES.md └── README.md ├── 1704-determine-if-string-halves-are-alike ├── 1704-determine-if-string-halves-are-alike.cpp ├── NOTES.md └── README.md ├── 1710-maximum-units-on-a-truck ├── 1710-maximum-units-on-a-truck.cpp ├── NOTES.md └── README.md ├── 1711-find-valid-matrix-given-row-and-column-sums ├── 1711-find-valid-matrix-given-row-and-column-sums.cpp └── README.md ├── 1721-swapping-nodes-in-a-linked-list ├── 1721-swapping-nodes-in-a-linked-list.cpp ├── NOTES.md └── README.md ├── 173-binary-search-tree-iterator └── NOTES.md ├── 1732-find-the-highest-altitude ├── 1732-find-the-highest-altitude.cpp ├── NOTES.md └── README.md ├── 1756-minimum-deletions-to-make-string-balanced ├── 1756-minimum-deletions-to-make-string-balanced.cpp └── README.md ├── 1762-buildings-with-an-ocean-view ├── 1762-buildings-with-an-ocean-view.cpp ├── NOTES.md └── README.md ├── 1774-closest-dessert-cost ├── NOTES.md └── README.md ├── 1778-shortest-path-in-a-hidden-grid ├── 1778-shortest-path-in-a-hidden-grid.cpp ├── NOTES.md └── README.md ├── 179-largest-number ├── NOTES.md └── README.md ├── 1791-find-center-of-star-graph ├── 1791-find-center-of-star-graph.cpp ├── NOTES.md └── README.md ├── 1803-average-waiting-time ├── 1803-average-waiting-time.cpp └── README.md ├── 1819-construct-the-lexicographically-largest-valid-sequence ├── 1819-construct-the-lexicographically-largest-valid-sequence.cpp └── README.md ├── 1822-sign-of-the-product-of-an-array ├── 1822-sign-of-the-product-of-an-array.cpp ├── NOTES.md └── README.md ├── 1832-check-if-the-sentence-is-pangram ├── 1832-check-if-the-sentence-is-pangram.cpp ├── NOTES.md └── README.md ├── 1834-single-threaded-cpu ├── 1834-single-threaded-cpu.cpp ├── NOTES.md └── README.md ├── 1849-maximum-absolute-sum-of-any-subarray ├── 1849-maximum-absolute-sum-of-any-subarray.cpp └── README.md ├── 1857-largest-color-value-in-a-directed-graph ├── 1857-largest-color-value-in-a-directed-graph.cpp ├── NOTES.md └── README.md ├── 1865-finding-pairs-with-a-certain-sum ├── NOTES.md └── README.md ├── 1889-check-if-number-is-a-sum-of-powers-of-three ├── 1889-check-if-number-is-a-sum-of-powers-of-three.cpp └── README.md ├── 19-remove-nth-node-from-end-of-list ├── NOTES.md └── README.md ├── 190-reverse-bits ├── 190-reverse-bits.cpp ├── NOTES.md └── README.md ├── 191-number-of-1-bits ├── NOTES.md └── README.md ├── 1915-check-if-one-string-swap-can-make-strings-equal ├── 1915-check-if-one-string-swap-can-make-strings-equal.cpp └── README.md ├── 1937-maximum-number-of-points-with-cost ├── 1937-maximum-number-of-points-with-cost.cpp ├── NOTES.md └── README.md ├── 1951-find-the-winner-of-the-circular-game ├── 1951-find-the-winner-of-the-circular-game.cpp └── README.md ├── 1974-minimum-time-to-type-word-using-special-typewriter ├── NOTES.md └── README.md ├── 1979-find-greatest-common-divisor-of-array ├── NOTES.md └── README.md ├── 198-house-robber ├── NOTES.md └── README.md ├── 199-binary-tree-right-side-view ├── 199-binary-tree-right-side-view.cpp ├── NOTES.md └── README.md ├── 1996-the-number-of-weak-characters-in-the-game ├── 1996-the-number-of-weak-characters-in-the-game.cpp ├── NOTES.md └── README.md ├── 2-add-two-numbers ├── NOTES.md └── README.md ├── 200-number-of-islands ├── 200-number-of-islands.cpp ├── 200-number-of-islands.java ├── NOTES.md └── README.md ├── 2007-find-original-array-from-doubled-array ├── 2007-find-original-array-from-doubled-array.cpp ├── NOTES.md └── README.md ├── 2013-detect-squares ├── NOTES.md └── README.md ├── 2021-remove-all-occurrences-of-a-substring ├── 2021-remove-all-occurrences-of-a-substring.cpp └── README.md ├── 2034-stock-price-fluctuation ├── 2034-stock-price-fluctuation.cpp ├── NOTES.md └── README.md ├── 2055-plates-between-candles ├── NOTES.md └── README.md ├── 2067-maximum-number-of-points-with-cost ├── 2067-maximum-number-of-points-with-cost.cpp └── README.md ├── 207-course-schedule ├── 207-course-schedule.cpp ├── NOTES.md └── README.md ├── 208-implement-trie-prefix-tree ├── 208-implement-trie-prefix-tree.cpp ├── NOTES.md └── README.md ├── 209-minimum-size-subarray-sum ├── 209-minimum-size-subarray-sum.cpp ├── NOTES.md └── README.md ├── 2092-find-all-people-with-secret ├── 2092-find-all-people-with-secret.cpp ├── NOTES.md └── README.md ├── 2095-delete-the-middle-node-of-a-linked-list ├── 2095-delete-the-middle-node-of-a-linked-list.cpp ├── NOTES.md └── README.md ├── 2096-step-by-step-directions-from-a-binary-tree-node-to-another ├── 2096-step-by-step-directions-from-a-binary-tree-node-to-another.cpp ├── NOTES.md └── README.md ├── 21-merge-two-sorted-lists ├── 21-merge-two-sorted-lists.cpp ├── NOTES.md └── README.md ├── 210-course-schedule-ii ├── 210-course-schedule-ii.cpp ├── NOTES.md └── README.md ├── 2107-find-unique-binary-string ├── 2107-find-unique-binary-string.cpp └── README.md ├── 2108-find-first-palindromic-string-in-the-array ├── 2108-find-first-palindromic-string-in-the-array.cpp ├── NOTES.md └── README.md ├── 211-design-add-and-search-words-data-structure ├── 211-design-add-and-search-words-data-structure.cpp ├── NOTES.md └── README.md ├── 2111-minimum-operations-to-make-the-array-k-increasing ├── NOTES.md └── README.md ├── 212-word-search-ii ├── NOTES.md └── README.md ├── 2125-number-of-laser-beams-in-a-bank ├── 2125-number-of-laser-beams-in-a-bank.cpp ├── NOTES.md └── README.md ├── 2128-remove-all-ones-with-row-and-column-flips ├── NOTES.md └── README.md ├── 213-house-robber-ii └── README.md ├── 2135-count-words-obtained-after-adding-a-letter ├── 2135-count-words-obtained-after-adding-a-letter.cpp ├── NOTES.md └── README.md ├── 2140-solving-questions-with-brainpower ├── 2140-solving-questions-with-brainpower.cpp ├── NOTES.md └── README.md ├── 215-kth-largest-element-in-an-array ├── 215-kth-largest-element-in-an-array.cpp ├── NOTES.md └── README.md ├── 2163-kth-distinct-string-in-an-array ├── 2163-kth-distinct-string-in-an-array.cpp └── README.md ├── 218-the-skyline-problem ├── NOTES.md └── README.md ├── 2182-find-the-minimum-and-maximum-number-of-nodes-between-critical-points ├── 2182-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.cpp └── README.md ├── 2187-minimum-time-to-complete-trips ├── 2187-minimum-time-to-complete-trips.cpp ├── NOTES.md └── README.md ├── 219-contains-duplicate-ii ├── NOTES.md └── README.md ├── 2209-minimum-white-tiles-after-covering-with-carpets ├── 2209-minimum-white-tiles-after-covering-with-carpets.cpp ├── NOTES.md └── README.md ├── 2215-find-the-difference-of-two-arrays ├── 2215-find-the-difference-of-two-arrays.cpp ├── NOTES.md └── README.md ├── 222-count-complete-tree-nodes ├── 222-count-complete-tree-nodes.cpp ├── NOTES.md └── README.md ├── 2222-number-of-ways-to-select-buildings ├── 2222-number-of-ways-to-select-buildings.cpp ├── NOTES.md └── README.md ├── 2227-encrypt-and-decrypt-strings ├── 2227-encrypt-and-decrypt-strings.cpp ├── NOTES.md └── README.md ├── 224-basic-calculator ├── 224-basic-calculator.cpp └── README.md ├── 2255-minimum-swaps-to-group-all-1s-together-ii ├── 2255-minimum-swaps-to-group-all-1s-together-ii.cpp └── README.md ├── 226-invert-binary-tree └── NOTES.md ├── 2265-partition-array-according-to-given-pivot ├── 2265-partition-array-according-to-given-pivot.cpp └── README.md ├── 227-basic-calculator-ii ├── 227-basic-calculator-ii.cpp ├── NOTES.md └── README.md ├── 23-merge-k-sorted-lists ├── NOTES.md └── README.md ├── 230-kth-smallest-element-in-a-bst ├── 230-kth-smallest-element-in-a-bst.cpp ├── NOTES.md └── README.md ├── 2305-fair-distribution-of-cookies ├── 2305-fair-distribution-of-cookies.cpp ├── NOTES.md └── README.md ├── 2316-count-unreachable-pairs-of-nodes-in-an-undirected-graph ├── 2316-count-unreachable-pairs-of-nodes-in-an-undirected-graph.cpp ├── NOTES.md └── README.md ├── 234-palindrome-linked-list ├── 234-palindrome-linked-list.cpp ├── NOTES.md └── README.md ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── NOTES.md └── README.md ├── 236-lowest-common-ancestor-of-a-binary-tree ├── 236-lowest-common-ancestor-of-a-binary-tree.cpp ├── NOTES.md └── README.md ├── 239-sliding-window-maximum ├── NOTES.md └── README.md ├── 2396-strictly-palindromic-number ├── NOTES.md └── README.md ├── 2397-maximum-rows-covered-by-columns ├── NOTES.md └── README.md ├── 240-search-a-2d-matrix-ii ├── 240-search-a-2d-matrix-ii.cpp ├── NOTES.md └── README.md ├── 242-valid-anagram ├── NOTES.md └── README.md ├── 2434-design-a-number-container-system ├── 2434-design-a-number-container-system.cpp └── README.md ├── 2448-count-number-of-bad-pairs ├── 2448-count-number-of-bad-pairs.cpp └── README.md ├── 2463-minimum-recolors-to-get-k-consecutive-black-blocks ├── 2463-minimum-recolors-to-get-k-consecutive-black-blocks.cpp └── README.md ├── 247-strobogrammatic-number-ii ├── NOTES.md └── README.md ├── 2472-build-a-matrix-with-conditions ├── 2472-build-a-matrix-with-conditions.cpp └── README.md ├── 2473-max-sum-of-a-pair-with-equal-sum-of-digits ├── 2473-max-sum-of-a-pair-with-equal-sum-of-digits.cpp └── README.md ├── 2487-remove-nodes-from-linked-list ├── 2487-remove-nodes-from-linked-list.cpp ├── NOTES.md └── README.md ├── 2502-sort-the-people ├── 2502-sort-the-people.cpp └── README.md ├── 253-meeting-rooms-ii ├── 253-meeting-rooms-ii.cpp ├── NOTES.md └── README.md ├── 2540-minimum-common-value ├── 2540-minimum-common-value.cpp ├── NOTES.md └── README.md ├── 2551-apply-operations-to-an-array ├── 2551-apply-operations-to-an-array.cpp └── README.md ├── 2564-most-profitable-path-in-a-tree ├── 2564-most-profitable-path-in-a-tree.cpp └── README.md ├── 26-remove-duplicates-from-sorted-array ├── 26-remove-duplicates-from-sorted-array.cpp ├── NOTES.md └── README.md ├── 261-graph-valid-tree ├── 261-graph-valid-tree.cpp └── NOTES.md ├── 2649-count-total-number-of-colored-cells ├── 2649-count-total-number-of-colored-cells.cpp └── README.md ├── 266-palindrome-permutation ├── 266-palindrome-permutation.cpp ├── NOTES.md └── README.md ├── 269-alien-dictionary ├── 269-alien-dictionary.cpp ├── NOTES.md └── README.md ├── 2707-merge-two-2d-arrays-by-summing-values ├── 2707-merge-two-2d-arrays-by-summing-values.cpp └── README.md ├── 271-encode-and-decode-strings ├── NOTES.md └── README.md ├── 2727-number-of-senior-citizens ├── 2727-number-of-senior-citizens.cpp └── README.md ├── 278-first-bad-version ├── 278-first-bad-version.cpp ├── NOTES.md └── README.md ├── 28-implement-strstr ├── 28-implement-strstr.cpp ├── NOTES.md └── README.md ├── 280-wiggle-sort └── NOTES.md ├── 2802-find-the-punishment-number-of-an-integer ├── 2802-find-the-punishment-number-of-an-integer.cpp └── README.md ├── 282-expression-add-operators ├── 282-expression-add-operators.cpp ├── NOTES.md └── README.md ├── 2846-robot-collisions ├── 2846-robot-collisions.cpp └── README.md ├── 286-walls-and-gates ├── 286-walls-and-gates.cpp ├── NOTES.md └── README.md ├── 290-word-pattern ├── NOTES.md └── README.md ├── 295-find-median-from-data-stream ├── NOTES.md └── README.md ├── 2966-divide-array-into-arrays-with-max-difference ├── 2966-divide-array-into-arrays-with-max-difference.cpp ├── NOTES.md └── README.md ├── 297-serialize-and-deserialize-binary-tree ├── 297-serialize-and-deserialize-binary-tree.cpp ├── NOTES.md └── README.md ├── 298-binary-tree-longest-consecutive-sequence ├── 298-binary-tree-longest-consecutive-sequence.cpp ├── NOTES.md └── README.md ├── 3-longest-substring-without-repeating-characters ├── NOTES.md └── README.md ├── 30-substring-with-concatenation-of-all-words ├── 30-substring-with-concatenation-of-all-words.cpp ├── NOTES.md └── README.md ├── 300-longest-increasing-subsequence ├── 300-longest-increasing-subsequence.cpp ├── NOTES.md └── README.md ├── 301-remove-invalid-parentheses ├── 301-remove-invalid-parentheses.cpp ├── NOTES.md └── README.md ├── 303-range-sum-query-immutable ├── NOTES.md └── README.md ├── 304-range-sum-query-2d-immutable ├── 304-range-sum-query-2d-immutable.cpp ├── NOTES.md └── README.md ├── 307-range-sum-query-mutable ├── 307-range-sum-query-mutable.cpp ├── NOTES.md └── README.md ├── 31-next-permutation ├── 31-next-permutation.cpp ├── NOTES.md └── README.md ├── 315-count-of-smaller-numbers-after-self ├── 315-count-of-smaller-numbers-after-self.cpp ├── NOTES.md └── README.md ├── 317-shortest-distance-from-all-buildings ├── 317-shortest-distance-from-all-buildings.cpp ├── NOTES.md └── README.md ├── 322-coin-change ├── 322-coin-change.cpp ├── NOTES.md └── README.md ├── 3227-find-missing-and-repeated-values ├── 3227-find-missing-and-repeated-values.cpp └── README.md ├── 323-number-of-connected-components-in-an-undirected-graph ├── 323-number-of-connected-components-in-an-undirected-graph.cpp ├── NOTES.md └── README.md ├── 3235-minimum-cost-to-convert-string-i ├── 3235-minimum-cost-to-convert-string-i.cpp └── README.md ├── 326-power-of-three ├── NOTES.md └── README.md ├── 3276-minimum-number-of-pushes-to-type-word-ii ├── 3276-minimum-number-of-pushes-to-type-word-ii.cpp └── README.md ├── 33-search-in-rotated-sorted-array ├── 33-search-in-rotated-sorted-array.cpp ├── NOTES.md └── README.md ├── 339-nested-list-weight-sum ├── NOTES.md └── 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 └── README.md ├── 340-longest-substring-with-at-most-k-distinct-characters ├── NOTES.md └── README.md ├── 341-flatten-nested-list-iterator ├── 341-flatten-nested-list-iterator.cpp ├── NOTES.md └── README.md ├── 342-power-of-four ├── 342-power-of-four.cpp ├── NOTES.md └── README.md ├── 3434-find-the-number-of-distinct-colors-among-the-balls ├── 3434-find-the-number-of-distinct-colors-among-the-balls.cpp └── README.md ├── 344-reverse-string ├── NOTES.md └── README.md ├── 3447-clear-digits ├── 3447-clear-digits.cpp └── README.md ├── 346-moving-average-from-data-stream ├── 346-moving-average-from-data-stream.cpp ├── NOTES.md └── README.md ├── 347-top-k-frequent-elements ├── 347-top-k-frequent-elements.cpp ├── 347-top-k-frequent-elements.java ├── NOTES.md └── README.md ├── 3483-alternating-groups-ii ├── 3483-alternating-groups-ii.cpp └── README.md ├── 349-intersection-of-two-arrays ├── 349-intersection-of-two-arrays.cpp ├── NOTES.md └── README.md ├── 353-design-snake-game ├── NOTES.md └── README.md ├── 355-design-twitter ├── 355-design-twitter.cpp ├── NOTES.md └── README.md ├── 363-max-sum-of-rectangle-no-larger-than-k ├── 363-max-sum-of-rectangle-no-larger-than-k.cpp ├── NOTES.md └── README.md ├── 367-valid-perfect-square ├── 367-valid-perfect-square.cpp ├── NOTES.md └── README.md ├── 370-range-addition ├── NOTES.md └── README.md ├── 374-guess-number-higher-or-lower ├── 374-guess-number-higher-or-lower.cpp ├── NOTES.md └── README.md ├── 376-wiggle-subsequence ├── 376-wiggle-subsequence.cpp ├── NOTES.md └── README.md ├── 377-combination-sum-iv ├── 377-combination-sum-iv.cpp ├── NOTES.md └── README.md ├── 378-kth-smallest-element-in-a-sorted-matrix ├── 378-kth-smallest-element-in-a-sorted-matrix.cpp ├── NOTES.md └── README.md ├── 380-insert-delete-getrandom-o1 ├── 380-insert-delete-getrandom-o1.cpp ├── NOTES.md └── README.md ├── 381-insert-delete-getrandom-o1-duplicates-allowed ├── 381-insert-delete-getrandom-o1-duplicates-allowed.cpp ├── NOTES.md └── README.md ├── 382-linked-list-random-node ├── 382-linked-list-random-node.cpp ├── NOTES.md └── README.md ├── 383-ransom-note ├── 383-ransom-note.cpp ├── NOTES.md └── README.md ├── 39-combination-sum ├── 39-combination-sum.cpp ├── NOTES.md └── README.md ├── 393-utf-8-validation ├── 393-utf-8-validation.cpp ├── NOTES.md └── README.md ├── 394-decode-string ├── 394-decode-string.cpp ├── NOTES.md └── README.md ├── 399-evaluate-division ├── 399-evaluate-division.cpp ├── NOTES.md └── README.md ├── 4-median-of-two-sorted-arrays ├── 4-median-of-two-sorted-arrays.cpp ├── NOTES.md └── README.md ├── 403-frog-jump ├── NOTES.md └── README.md ├── 408-valid-word-abbreviation ├── 408-valid-word-abbreviation.cpp ├── NOTES.md └── README.md ├── 416-partition-equal-subset-sum ├── 416-partition-equal-subset-sum.cpp ├── NOTES.md └── README.md ├── 417-pacific-atlantic-water-flow └── README.md ├── 42-trapping-rain-water ├── 42-trapping-rain-water.cpp ├── NOTES.md └── README.md ├── 424-longest-repeating-character-replacement ├── 424-longest-repeating-character-replacement.cpp ├── NOTES.md └── README.md ├── 429-n-ary-tree-level-order-traversal ├── 429-n-ary-tree-level-order-traversal.cpp ├── NOTES.md └── README.md ├── 430-flatten-a-multilevel-doubly-linked-list ├── NOTES.md └── README.md ├── 437-path-sum-iii ├── 437-path-sum-iii.cpp ├── NOTES.md └── README.md ├── 438-find-all-anagrams-in-a-string ├── 438-find-all-anagrams-in-a-string.cpp ├── NOTES.md └── README.md ├── 44-wildcard-matching ├── 44-wildcard-matching.cpp ├── NOTES.md └── README.md ├── 441-arranging-coins ├── NOTES.md └── README.md ├── 443-string-compression ├── 443-string-compression.cpp └── README.md ├── 444-sequence-reconstruction ├── 444-sequence-reconstruction.cpp ├── NOTES.md └── README.md ├── 445-add-two-numbers-ii ├── NOTES.md └── README.md ├── 447-number-of-boomerangs ├── NOTES.md └── README.md ├── 45-jump-game-ii ├── 45-jump-game-ii.cpp ├── NOTES.md └── README.md ├── 451-sort-characters-by-frequency ├── 451-sort-characters-by-frequency.cpp └── README.md ├── 452-minimum-number-of-arrows-to-burst-balloons ├── 452-minimum-number-of-arrows-to-burst-balloons.cpp ├── NOTES.md └── README.md ├── 457-circular-array-loop ├── NOTES.md └── README.md ├── 458-poor-pigs ├── 458-poor-pigs.cpp └── README.md ├── 462-minimum-moves-to-equal-array-elements-ii ├── 462-minimum-moves-to-equal-array-elements-ii.cpp ├── NOTES.md └── README.md ├── 463-island-perimeter ├── 463-island-perimeter.cpp ├── NOTES.md └── README.md ├── 47-permutations-ii ├── 47-permutations-ii.cpp ├── NOTES.md └── README.md ├── 472-concatenated-words ├── 472-concatenated-words.cpp ├── NOTES.md └── README.md ├── 473-matchsticks-to-square ├── 473-matchsticks-to-square.cpp ├── NOTES.md └── README.md ├── 48-rotate-image ├── 48-rotate-image.cpp ├── NOTES.md └── README.md ├── 489-robot-room-cleaner ├── 489-robot-room-cleaner.cpp ├── NOTES.md └── README.md ├── 490-the-maze ├── 490-the-maze.cpp ├── NOTES.md └── README.md ├── 494-target-sum ├── 494-target-sum.cpp ├── NOTES.md └── README.md ├── 496-next-greater-element-i ├── 496-next-greater-element-i.cpp ├── NOTES.md └── README.md ├── 498-diagonal-traverse ├── NOTES.md └── README.md ├── 499-the-maze-iii ├── 499-the-maze-iii.cpp ├── NOTES.md └── README.md ├── 5-longest-palindromic-substring └── README.md ├── 503-next-greater-element-ii ├── 503-next-greater-element-ii.cpp └── README.md ├── 505-the-maze-ii ├── 505-the-maze-ii.cpp ├── NOTES.md └── README.md ├── 509-fibonacci-number ├── 509-fibonacci-number.cpp ├── NOTES.md └── README.md ├── 51-n-queens ├── 51-n-queens.cpp ├── NOTES.md └── README.md ├── 518-coin-change-2 ├── NOTES.md └── README.md ├── 52-n-queens-ii ├── 52-n-queens-ii.cpp ├── NOTES.md └── README.md ├── 523-continuous-subarray-sum ├── 523-continuous-subarray-sum.cpp ├── NOTES.md └── README.md ├── 528-random-pick-with-weight ├── 528-random-pick-with-weight.cpp ├── NOTES.md └── README.md ├── 53-maximum-subarray ├── 53-maximum-subarray.cpp ├── NOTES.md └── README.md ├── 535-encode-and-decode-tinyurl ├── 535-encode-and-decode-tinyurl.cpp └── NOTES.md ├── 536-construct-binary-tree-from-string ├── 536-construct-binary-tree-from-string.cpp ├── NOTES.md └── README.md ├── 538-convert-bst-to-greater-tree ├── 538-convert-bst-to-greater-tree.cpp ├── NOTES.md └── README.md ├── 543-diameter-of-binary-tree ├── 543-diameter-of-binary-tree.cpp ├── NOTES.md └── README.md ├── 55-jump-game ├── 55-jump-game.cpp ├── NOTES.md └── README.md ├── 554-brick-wall ├── 554-brick-wall.cpp ├── NOTES.md └── README.md ├── 557-reverse-words-in-a-string-iii ├── 557-reverse-words-in-a-string-iii.cpp ├── NOTES.md └── README.md ├── 56-merge-intervals ├── 56-merge-intervals.cpp ├── NOTES.md └── README.md ├── 560-subarray-sum-equals-k ├── 560-subarray-sum-equals-k.cpp ├── NOTES.md └── README.md ├── 57-insert-interval ├── NOTES.md └── README.md ├── 572-subtree-of-another-tree ├── NOTES.md └── README.md ├── 576-out-of-boundary-paths ├── 576-out-of-boundary-paths.cpp ├── NOTES.md └── README.md ├── 581-shortest-unsorted-continuous-subarray ├── 581-shortest-unsorted-continuous-subarray.cpp ├── NOTES.md └── README.md ├── 583-delete-operation-for-two-strings ├── 583-delete-operation-for-two-strings.cpp └── NOTES.md ├── 588-design-in-memory-file-system ├── 588-design-in-memory-file-system.cpp ├── NOTES.md └── README.md ├── 59-spiral-matrix-ii ├── 59-spiral-matrix-ii.cpp ├── NOTES.md └── README.md ├── 61-rotate-list ├── NOTES.md └── README.md ├── 62-unique-paths ├── 62-unique-paths.cpp ├── NOTES.md └── README.md ├── 622-design-circular-queue ├── 622-design-circular-queue.cpp ├── NOTES.md └── README.md ├── 623-add-one-row-to-tree ├── 623-add-one-row-to-tree.cpp ├── NOTES.md └── README.md ├── 629-k-inverse-pairs-array ├── 629-k-inverse-pairs-array.cpp ├── NOTES.md └── README.md ├── 63-unique-paths-ii ├── 63-unique-paths-ii.cpp ├── NOTES.md └── README.md ├── 630-course-schedule-iii ├── NOTES.md └── README.md ├── 631-design-excel-sum-formula ├── 631-design-excel-sum-formula.cpp ├── NOTES.md └── README.md ├── 633-sum-of-square-numbers ├── NOTES.md └── README.md ├── 637-average-of-levels-in-binary-tree ├── NOTES.md └── README.md ├── 642-design-search-autocomplete-system ├── NOTES.md └── README.md ├── 646-maximum-length-of-pair-chain ├── 646-maximum-length-of-pair-chain.cpp ├── NOTES.md └── README.md ├── 647-palindromic-substrings ├── 647-palindromic-substrings.cpp ├── NOTES.md └── README.md ├── 653-two-sum-iv-input-is-a-bst ├── 653-two-sum-iv-input-is-a-bst.cpp ├── NOTES.md └── README.md ├── 658-find-k-closest-elements ├── 658-find-k-closest-elements.cpp ├── NOTES.md └── README.md ├── 665-non-decreasing-array ├── 665-non-decreasing-array.cpp ├── NOTES.md └── README.md ├── 669-trim-a-binary-search-tree ├── 669-trim-a-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 678-valid-parenthesis-string ├── 678-valid-parenthesis-string.cpp ├── NOTES.md └── README.md ├── 68-text-justification ├── 68-text-justification.cpp ├── NOTES.md └── README.md ├── 680-valid-palindrome-ii ├── 680-valid-palindrome-ii.cpp ├── NOTES.md └── README.md ├── 682-baseball-game ├── 682-baseball-game.java ├── NOTES.md └── README.md ├── 692-top-k-frequent-words ├── 692-top-k-frequent-words.cpp ├── NOTES.md └── README.md ├── 694-number-of-distinct-islands ├── 694-number-of-distinct-islands.cpp ├── NOTES.md └── README.md ├── 695-max-area-of-island ├── 695-max-area-of-island.cpp ├── NOTES.md └── README.md ├── 696-count-binary-substrings └── README.md ├── 700-search-in-a-binary-search-tree ├── 700-search-in-a-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 701-insert-into-a-binary-search-tree ├── 701-insert-into-a-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 703-kth-largest-element-in-a-stream ├── 703-kth-largest-element-in-a-stream.java ├── NOTES.md └── README.md ├── 708-insert-into-a-sorted-circular-linked-list ├── NOTES.md └── README.md ├── 71-simplify-path ├── 71-simplify-path.cpp ├── NOTES.md └── README.md ├── 710-random-pick-with-blacklist ├── 710-random-pick-with-blacklist.cpp ├── NOTES.md └── README.md ├── 715-range-module ├── 715-range-module.cpp └── NOTES.md ├── 716-max-stack ├── 716-max-stack.cpp ├── NOTES.md └── README.md ├── 720-longest-word-in-dictionary ├── 720-longest-word-in-dictionary.cpp ├── NOTES.md └── README.md ├── 723-candy-crush ├── NOTES.md └── README.md ├── 724-find-pivot-index ├── 724-find-pivot-index.cpp ├── NOTES.md └── README.md ├── 726-number-of-atoms ├── 726-number-of-atoms.cpp ├── NOTES.md └── README.md ├── 729-my-calendar-i ├── NOTES.md └── README.md ├── 73-set-matrix-zeroes ├── NOTES.md └── README.md ├── 739-daily-temperatures ├── 739-daily-temperatures.cpp ├── NOTES.md └── README.md ├── 741-cherry-pickup ├── 741-cherry-pickup.cpp ├── NOTES.md └── README.md ├── 743-network-delay-time ├── 743-network-delay-time.cpp └── NOTES.md ├── 745-prefix-and-suffix-search ├── 745-prefix-and-suffix-search.cpp ├── NOTES.md └── README.md ├── 746-min-cost-climbing-stairs ├── 746-min-cost-climbing-stairs.cpp ├── NOTES.md └── README.md ├── 752-open-the-lock ├── 752-open-the-lock.cpp ├── NOTES.md └── README.md ├── 753-cracking-the-safe ├── 753-cracking-the-safe.cpp ├── NOTES.md └── README.md ├── 76-minimum-window-substring ├── 76-minimum-window-substring.cpp ├── NOTES.md └── README.md ├── 766-toeplitz-matrix ├── 766-toeplitz-matrix.cpp ├── NOTES.md └── README.md ├── 767-reorganize-string ├── NOTES.md └── README.md ├── 78-subsets ├── 78-subsets.cpp ├── NOTES.md └── README.md ├── 780-reaching-points ├── 780-reaching-points.cpp ├── NOTES.md └── README.md ├── 785-is-graph-bipartite ├── 785-is-graph-bipartite.cpp ├── NOTES.md └── README.md ├── 787-cheapest-flights-within-k-stops ├── 787-cheapest-flights-within-k-stops.cpp ├── NOTES.md └── README.md ├── 79-word-search ├── NOTES.md └── README.md ├── 791-custom-sort-string ├── NOTES.md └── README.md ├── 792-number-of-matching-subsequences ├── 792-number-of-matching-subsequences.cpp ├── NOTES.md └── README.md ├── 794-valid-tic-tac-toe-state ├── NOTES.md └── README.md ├── 797-all-paths-from-source-to-target ├── NOTES.md └── README.md ├── 802-find-eventual-safe-states └── README.md ├── 811-subdomain-visit-count ├── 811-subdomain-visit-count.cpp ├── NOTES.md └── README.md ├── 814-binary-tree-pruning ├── 814-binary-tree-pruning.cpp └── README.md ├── 815-bus-routes ├── NOTES.md └── README.md ├── 82-remove-duplicates-from-sorted-list-ii ├── 82-remove-duplicates-from-sorted-list-ii.cpp ├── NOTES.md └── README.md ├── 820-short-encoding-of-words ├── NOTES.md └── README.md ├── 821-shortest-distance-to-a-character ├── NOTES.md └── README.md ├── 823-binary-trees-with-factors ├── 823-binary-trees-with-factors.cpp ├── NOTES.md └── README.md ├── 827-making-a-large-island ├── 827-making-a-large-island.cpp ├── NOTES.md └── README.md ├── 834-sum-of-distances-in-tree ├── NOTES.md └── README.md ├── 84-largest-rectangle-in-histogram ├── 84-largest-rectangle-in-histogram.cpp ├── NOTES.md └── README.md ├── 844-backspace-string-compare ├── 844-backspace-string-compare.cpp ├── NOTES.md └── README.md ├── 847-shortest-path-visiting-all-nodes ├── NOTES.md └── README.md ├── 85-maximal-rectangle ├── 85-maximal-rectangle.cpp ├── NOTES.md └── README.md ├── 855-exam-room ├── 855-exam-room.cpp ├── NOTES.md └── README.md ├── 858-mirror-reflection ├── NOTES.md └── README.md ├── 86-partition-list ├── 86-partition-list.cpp ├── NOTES.md └── README.md ├── 862-shortest-subarray-with-sum-at-least-k ├── 862-shortest-subarray-with-sum-at-least-k.cpp ├── NOTES.md └── README.md ├── 863-all-nodes-distance-k-in-binary-tree ├── 863-all-nodes-distance-k-in-binary-tree.cpp ├── NOTES.md └── README.md ├── 867-transpose-matrix ├── NOTES.md └── README.md ├── 871-minimum-number-of-refueling-stops ├── 871-minimum-number-of-refueling-stops.cpp ├── NOTES.md └── README.md ├── 88-merge-sorted-array ├── NOTES.md └── README.md ├── 882-reachable-nodes-in-subdivided-graph ├── 882-reachable-nodes-in-subdivided-graph.cpp ├── NOTES.md └── README.md ├── 886-possible-bipartition ├── 886-possible-bipartition.cpp ├── NOTES.md └── README.md ├── 890-find-and-replace-pattern ├── 890-find-and-replace-pattern.cpp ├── NOTES.md └── README.md ├── 894-all-possible-full-binary-trees ├── 894-all-possible-full-binary-trees.cpp ├── NOTES.md └── README.md ├── 895-maximum-frequency-stack ├── NOTES.md └── README.md ├── 897-increasing-order-search-tree ├── 897-increasing-order-search-tree.cpp ├── NOTES.md └── README.md ├── 901-online-stock-span ├── NOTES.md └── README.md ├── 909-snakes-and-ladders ├── NOTES.md └── README.md ├── 91-decode-ways ├── 91-decode-ways.cpp ├── NOTES.md └── README.md ├── 916-word-subsets ├── 916-word-subsets.cpp ├── NOTES.md └── README.md ├── 92-reverse-linked-list-ii └── README.md ├── 93-restore-ip-addresses ├── 93-restore-ip-addresses.cpp ├── NOTES.md └── README.md ├── 934-shortest-bridge ├── NOTES.md └── README.md ├── 935-knight-dialer ├── 935-knight-dialer.cpp ├── NOTES.md └── README.md ├── 937-reorder-data-in-log-files └── README.md ├── 938-range-sum-of-bst ├── 938-range-sum-of-bst.cpp ├── NOTES.md └── README.md ├── 939-minimum-area-rectangle ├── 939-minimum-area-rectangle.cpp ├── NOTES.md └── README.md ├── 94-binary-tree-inorder-traversal ├── 94-binary-tree-inorder-traversal.cpp ├── NOTES.md └── README.md ├── 941-valid-mountain-array ├── 941-valid-mountain-array.cpp ├── NOTES.md └── README.md ├── 947-most-stones-removed-with-same-row-or-column ├── NOTES.md └── README.md ├── 953-verifying-an-alien-dictionary ├── 953-verifying-an-alien-dictionary.cpp └── NOTES.md ├── 954-array-of-doubled-pairs ├── 954-array-of-doubled-pairs.cpp ├── NOTES.md └── README.md ├── 967-numbers-with-same-consecutive-differences ├── 967-numbers-with-same-consecutive-differences.cpp ├── NOTES.md └── README.md ├── 968-binary-tree-cameras ├── 968-binary-tree-cameras.cpp ├── NOTES.md └── README.md ├── 97-interleaving-string ├── 97-interleaving-string.cpp ├── NOTES.md └── README.md ├── 973-k-closest-points-to-origin ├── 973-k-closest-points-to-origin.cpp ├── NOTES.md └── README.md ├── 98-validate-binary-search-tree ├── NOTES.md └── README.md ├── 981-time-based-key-value-store ├── 981-time-based-key-value-store.cpp ├── NOTES.md └── README.md ├── 985-sum-of-even-numbers-after-queries ├── 985-sum-of-even-numbers-after-queries.cpp ├── NOTES.md └── README.md ├── 986-interval-list-intersections ├── 986-interval-list-intersections.cpp ├── NOTES.md └── README.md ├── 987-vertical-order-traversal-of-a-binary-tree ├── 987-vertical-order-traversal-of-a-binary-tree.cpp ├── NOTES.md └── README.md ├── 99-recover-binary-search-tree ├── 99-recover-binary-search-tree.java ├── NOTES.md └── README.md ├── 990-satisfiability-of-equality-equations ├── 990-satisfiability-of-equality-equations.cpp ├── NOTES.md └── README.md ├── 991-broken-calculator ├── 991-broken-calculator.cpp └── README.md ├── README.md ├── basic-calculator-ii ├── README.md └── basic-calculator-ii.cpp ├── decode-ways ├── README.md └── decode-ways.cpp ├── find-the-town-judge ├── README.md └── find-the-town-judge.cpp └── stats.json /0001-two-sum/0001-two-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& nums, int target) { 4 | unordered_map m; 5 | int n = nums.size(); 6 | 7 | for(int i = 0; i < n; i ++) { 8 | int num = nums[i]; 9 | 10 | if(m.count(num)) { 11 | return {m[num], i}; 12 | } 13 | 14 | int diff = target - num; 15 | m[diff] = i; 16 | } 17 | 18 | return {}; 19 | } 20 | }; -------------------------------------------------------------------------------- /0001-two-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0005-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0020-valid-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0026-remove-duplicates-from-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0033-search-in-rotated-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0034-find-first-and-last-position-of-element-in-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0036-valid-sudoku/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0038-count-and-say/0038-count-and-say.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string countAndSay(int n) { 4 | if(n == 0) return ""; 5 | 6 | string ans = "1"; 7 | 8 | for(int i = 1; i < n ; i ++) { 9 | string temp = ""; 10 | int m = ans.size(); 11 | for(int j = 0; j < m; j ++) { 12 | int count = 1; 13 | while(j + 1 < m && ans[j] == ans[j+1]) { 14 | cout << count << endl; 15 | count ++; 16 | j ++; 17 | } 18 | temp += to_string(count) + ans[j]; 19 | } 20 | ans = temp; 21 | } 22 | 23 | return ans; 24 | } 25 | }; -------------------------------------------------------------------------------- /0045-jump-game-ii/0045-jump-game-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int jump(vector& nums) { 4 | int jumps = 0; 5 | int curReach = 0; 6 | int maxReach = 0; 7 | int n = nums.size(); 8 | 9 | for(int i = 0; i < n; i ++) { 10 | maxReach = max(maxReach, i + nums[i]); 11 | 12 | if(i == curReach && i != n-1) { 13 | jumps ++; 14 | curReach = maxReach; 15 | maxReach = 0; 16 | } 17 | } 18 | 19 | return jumps; 20 | } 21 | }; -------------------------------------------------------------------------------- /0045-jump-game-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0049-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0050-powx-n/0050-powx-n.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double myPow(double x, int n) { 4 | double ans = 1.0; 5 | long newN = n; 6 | if(newN < 0) newN = -newN; 7 | while(newN > 0) { 8 | if(newN % 2) { 9 | ans = ans * x; 10 | newN --; 11 | } 12 | else { 13 | x = x * x; 14 | newN /= 2; 15 | } 16 | } 17 | 18 | if(n < 0) ans = (double)(1.0) / ans; 19 | 20 | return ans; 21 | } 22 | }; -------------------------------------------------------------------------------- /0050-powx-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0054-spiral-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0055-jump-game/0055-jump-game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canJump(vector& nums) { 4 | int reach = 0; 5 | int n = nums.size(); 6 | 7 | for(int i = 0; i < n; i ++) { 8 | if(i > reach) 9 | return false; 10 | reach = max(reach, i + nums[i]); 11 | } 12 | 13 | return true; 14 | } 15 | }; -------------------------------------------------------------------------------- /0055-jump-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0057-insert-interval/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0059-spiral-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0063-unique-paths-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0067-add-binary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0070-climbing-stairs/0070-climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int climbStairs(int n) { 4 | if(n == 1) 5 | return 1; 6 | 7 | if(n == 2) 8 | return 2; 9 | 10 | int prevTwo = 1; 11 | int prevOne = 2; 12 | 13 | for(int i = 3; i <= n; i ++) { 14 | int temp = prevOne + prevTwo; 15 | prevTwo = prevOne; 16 | prevOne = temp; 17 | } 18 | 19 | return prevOne; 20 | } 21 | }; -------------------------------------------------------------------------------- /0070-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0071-simplify-path/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0076-minimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0093-restore-ip-addresses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0109-convert-sorted-list-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int ans = 0; 5 | int localMin = prices[0]; 6 | int n = prices.size(); 7 | 8 | for(int i = 0; i < n; i ++) { 9 | if(prices[i] < localMin) { 10 | localMin = min(localMin, prices[i]); 11 | } 12 | 13 | ans = max(ans, prices[i] - localMin); 14 | } 15 | 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /0121-best-time-to-buy-and-sell-stock/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0128-longest-consecutive-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0129-sum-root-to-leaf-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0131-palindrome-partitioning/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0134-gas-station/0134-gas-station.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int canCompleteCircuit(vector& gas, vector& cost) { 4 | int n = gas.size(); 5 | 6 | int start = n - 1; 7 | int end = 0; 8 | int sum = gas[start] - cost[start]; 9 | 10 | while(start > end) { 11 | if(sum > 0) { 12 | sum += gas[end] - cost[end]; 13 | end ++; 14 | } 15 | else { 16 | start --; 17 | sum += gas[start] - cost[start]; 18 | } 19 | } 20 | 21 | return sum >= 0 ? start : -1; 22 | } 23 | }; -------------------------------------------------------------------------------- /0134-gas-station/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0139-word-break/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0140-word-break-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0141-linked-list-cycle/0141-linked-list-cycle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | bool hasCycle(ListNode *head) { 12 | ListNode* slow = head; 13 | if(!head || !head->next) 14 | return false; 15 | ListNode* fast = head->next; 16 | 17 | while(fast->next && fast->next->next) { 18 | if(fast == slow) 19 | return true; 20 | fast = fast->next->next; 21 | slow = slow->next; 22 | } 23 | 24 | return false; 25 | } 26 | }; -------------------------------------------------------------------------------- /0141-linked-list-cycle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0142-linked-list-cycle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0143-reorder-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0150-evaluate-reverse-polish-notation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0151-reverse-words-in-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0169-majority-element/0169-majority-element.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int majorityElement(vector& nums) { 4 | int cur = nums[0]; 5 | int count = 0; 6 | 7 | for(int num : nums) { 8 | if(cur == num) { 9 | count ++; 10 | } 11 | else { 12 | count --; 13 | } 14 | 15 | if(count < 0) { 16 | count = 1; 17 | cur = num; 18 | } 19 | } 20 | 21 | return cur; 22 | } 23 | }; -------------------------------------------------------------------------------- /0169-majority-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0198-house-robber/0198-house-robber.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int rob(vector& nums) { 4 | int n = nums.size(); 5 | 6 | int prevTwo = 0; 7 | int prevOne = 0; 8 | 9 | for(int i = 0; i < n; i ++) { 10 | int temp = max(prevTwo + nums[i], prevOne); 11 | prevTwo = prevOne; 12 | prevOne = temp; 13 | } 14 | 15 | return prevOne; 16 | } 17 | }; -------------------------------------------------------------------------------- /0198-house-robber/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0212-word-search-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0217-contains-duplicate/0217-contains-duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& nums) { 4 | unordered_set seen; 5 | 6 | for(int num : nums) { 7 | if(seen.count(num)) { 8 | return true; 9 | } 10 | 11 | seen.insert(num); 12 | } 13 | 14 | return false; 15 | } 16 | }; -------------------------------------------------------------------------------- /0217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0219-contains-duplicate-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0224-basic-calculator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0237-delete-node-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0238-product-of-array-except-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0242-valid-anagram/0242-valid-anagram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isAnagram(string s, string t) { 4 | unordered_map m; 5 | 6 | if(s.size() != t.size()) { 7 | return false; 8 | } 9 | 10 | for(char c : s) { 11 | m[c] ++; 12 | } 13 | 14 | for(char c : t) { 15 | if(m[c] == 0) { 16 | return false; 17 | } 18 | 19 | m[c] --; 20 | } 21 | 22 | return true; 23 | } 24 | }; -------------------------------------------------------------------------------- /0242-valid-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0263-ugly-number/0263-ugly-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isUgly(int n) { 4 | if(n == 0) 5 | return false; 6 | vector factors = {2, 3, 5}; 7 | 8 | for(int num : factors) { 9 | while(n % num == 0) 10 | n /= num; 11 | } 12 | 13 | return n == 1; 14 | } 15 | }; -------------------------------------------------------------------------------- /0263-ugly-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0279-perfect-squares/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0290-word-pattern/0290-word-pattern.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool wordPattern(string pattern, string s) { 4 | stringstream ss(s); 5 | string t; 6 | unordered_map m; 7 | unordered_map m2; 8 | int n = pattern.size(); 9 | int i = 0; 10 | 11 | while(ss >> t) { 12 | char ch = pattern[i]; 13 | if(m.count(ch) && m[ch] != t) { 14 | return false; 15 | } 16 | if(m2.count(t) && m2[t] != ch) { 17 | return false; 18 | } 19 | m[ch] = t; 20 | m2[t] = ch; 21 | 22 | i ++; 23 | } 24 | 25 | return i == n; 26 | } 27 | }; -------------------------------------------------------------------------------- /0290-word-pattern/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLIS(vector& nums) { 4 | vector dp; 5 | 6 | for(int num : nums) { 7 | auto it = lower_bound(dp.begin(), dp.end(), num); 8 | if(it == dp.end()) { 9 | dp.push_back(num); 10 | } 11 | else { 12 | *it = num; 13 | } 14 | } 15 | 16 | return dp.size(); 17 | } 18 | }; -------------------------------------------------------------------------------- /0300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0334-increasing-triplet-subsequence/0334-increasing-triplet-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool increasingTriplet(vector& nums) { 4 | int one = INT_MAX, two = INT_MAX; 5 | 6 | for(int num : nums) { 7 | if(num < one) { 8 | one = num; 9 | } 10 | if(num > one && num < two) { 11 | two = num; 12 | } 13 | if(num > two) 14 | return true; 15 | 16 | } 17 | return false; 18 | } 19 | }; -------------------------------------------------------------------------------- /0334-increasing-triplet-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0341-flatten-nested-list-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0347-top-k-frequent-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0374-guess-number-higher-or-lower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0392-is-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0399-evaluate-division/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0433-minimum-genetic-mutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0443-string-compression/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string frequencySort(string s) { 4 | unordered_map count; 5 | 6 | for(char c : s) { 7 | count[c] ++; 8 | } 9 | 10 | int n = s.size(); 11 | unordered_map> bucket; 12 | for(auto entry : count) { 13 | bucket[entry.second].push_back(entry.first); 14 | } 15 | 16 | string ans = ""; 17 | for(int i = n; i >= 0; i --) { 18 | int freq = i; 19 | auto& toappend = bucket[i]; 20 | for(auto c : toappend) { 21 | ans.append(freq, c); 22 | } 23 | } 24 | 25 | return ans; 26 | } 27 | }; -------------------------------------------------------------------------------- /0451-sort-characters-by-frequency/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0452-minimum-number-of-arrows-to-burst-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0455-assign-cookies/0455-assign-cookies.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findContentChildren(vector& g, vector& s) { 4 | int childIndex = 0; 5 | int cookieIndex = 0; 6 | 7 | int n = g.size(); 8 | int m = s.size(); 9 | 10 | sort(g.begin(), g.end()); 11 | sort(s.begin(), s.end()); 12 | 13 | while(cookieIndex < m && childIndex < n) { 14 | int curCookie = s[cookieIndex]; 15 | int curChildContent = g[childIndex]; 16 | 17 | if(curCookie >= curChildContent) { 18 | childIndex ++; 19 | } 20 | 21 | cookieIndex ++; 22 | } 23 | 24 | return childIndex; 25 | } 26 | }; -------------------------------------------------------------------------------- /0455-assign-cookies/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0458-poor-pigs/0458-poor-pigs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int poorPigs(int buckets, int minutesToDie, int minutesToTest) { 4 | int pigs = 0; 5 | while (pow(minutesToTest / minutesToDie + 1, pigs) < buckets) { 6 | pigs += 1; 7 | } 8 | return pigs; 9 | } 10 | }; -------------------------------------------------------------------------------- /0458-poor-pigs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0472-concatenated-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0476-number-complement/0476-number-complement.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findComplement(int num) { 4 | int bit = 1; 5 | int todo = num; 6 | 7 | while(todo != 0) { 8 | num = num ^ bit; 9 | 10 | todo = todo >> 1; 11 | bit = bit << 1; 12 | } 13 | 14 | return num; 15 | } 16 | }; -------------------------------------------------------------------------------- /0513-find-bottom-left-tree-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0516-longest-palindromic-subsequence/0516-longest-palindromic-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestPalindromeSubseq(string s) { 4 | int n = s.size(); 5 | vector> dp(n, vector(n)); 6 | 7 | for(int i = n-1; i >= 0; i --) { 8 | dp[i][i] = 1; 9 | for(int j = i+1; j < n; j ++) { 10 | // cout << i << " " << j << endl; 11 | if(s[i] == s[j]) { 12 | dp[i][j] = dp[i+1][j-1] + 2; 13 | } 14 | else { 15 | dp[i][j] = max(dp[i+1][j], dp[i][j-1]); 16 | } 17 | } 18 | } 19 | 20 | return dp[0][n-1]; 21 | } 22 | }; -------------------------------------------------------------------------------- /0516-longest-palindromic-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0520-detect-capital/0520-detect-capital.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool detectCapitalUse(string word) { 4 | int count=0; 5 | if(word.size()==1) 6 | return true; 7 | 8 | for(int i=0; i& nums, int k) { 4 | int sum = 0; 5 | unordered_map prevSum; 6 | int n = nums.size(); 7 | 8 | prevSum[0] = -1; 9 | for(int i = 0; i < n; i ++) { 10 | int num = nums[i]; 11 | sum += num; 12 | sum = sum % k; 13 | 14 | if(prevSum.count(sum)) { 15 | if(i - prevSum[sum] > 1) { 16 | return true; 17 | } 18 | } 19 | else { 20 | prevSum[sum] = i; 21 | } 22 | } 23 | 24 | return false; 25 | } 26 | }; -------------------------------------------------------------------------------- /0523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0530-minimum-absolute-difference-in-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0540-single-element-in-a-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0542-01-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0567-permutation-in-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0621-task-scheduler/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDistance(vector>& arrays) { 4 | int curMin = arrays[0].front(); 5 | int curMax = arrays[0].back(); 6 | int n = arrays.size(); 7 | int res = 0; 8 | 9 | for(int i = 1; i < n; i ++) { 10 | auto& arr = arrays[i]; 11 | 12 | 13 | res = max(res, curMax - arr.front()); 14 | res = max(res, arr.back() - curMin); 15 | 16 | curMin = min(curMin, arr.front()); 17 | curMax = max(curMax, arr.back()); 18 | } 19 | 20 | return res; 21 | } 22 | }; -------------------------------------------------------------------------------- /0633-sum-of-square-numbers/0633-sum-of-square-numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool judgeSquareSum(int c) { 4 | int m = sqrt(c); 5 | 6 | for(long long i = 0; i <= m; i ++) { 7 | int diff = c - i * i; 8 | long long b = round(sqrt(diff)); 9 | if(i * i + b * b == c) { 10 | return true; 11 | } 12 | } 13 | 14 | return false; 15 | } 16 | }; -------------------------------------------------------------------------------- /0633-sum-of-square-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0645-set-mismatch/0645-set-mismatch.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findErrorNums(vector& nums) { 4 | vector res(2); 5 | 6 | for(int num : nums) { 7 | if(nums[abs(num)-1] < 0) 8 | res[0] = abs(num); 9 | else 10 | nums[abs(num) - 1] *= -1; 11 | } 12 | 13 | for(int i = 0 ; i < nums.size(); i ++) { 14 | if(nums[i] > 0) { 15 | res[1] = i + 1; 16 | } 17 | } 18 | 19 | return res; 20 | } 21 | }; -------------------------------------------------------------------------------- /0645-set-mismatch/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0646-maximum-length-of-pair-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0647-palindromic-substrings/0647-palindromic-substrings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int n; 4 | int countSubstrings(string s) { 5 | n = s.size(); 6 | int res = 0; 7 | 8 | for(int i = 0; i < n ; i ++) { 9 | res += count(s, i, i); 10 | res += count(s, i, i+1); 11 | } 12 | 13 | return res; 14 | } 15 | 16 | int count(string s, int start, int end) { 17 | int res = 0; 18 | 19 | while(start >= 0 && end < n) { 20 | if(s[start] != s[end]) 21 | break; 22 | 23 | res ++; 24 | 25 | start --; 26 | end ++; 27 | } 28 | 29 | return res; 30 | } 31 | }; -------------------------------------------------------------------------------- /0647-palindromic-substrings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0652-find-duplicate-subtrees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0662-maximum-width-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0673-number-of-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0692-top-k-frequent-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0703-kth-largest-element-in-a-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0704-binary-search/0704-binary-search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | int n = nums.size(); 5 | int l = 0; 6 | int r = n; 7 | 8 | while(l < r) { 9 | int mid = l + (r - l) / 2; 10 | int cur = nums[mid]; 11 | if(cur == target) { 12 | return mid; 13 | } 14 | else if(cur < target) { 15 | l = mid + 1; 16 | } 17 | else { 18 | r = mid; 19 | } 20 | } 21 | 22 | return -1; 23 | } 24 | }; -------------------------------------------------------------------------------- /0704-binary-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numSubarrayProductLessThanK(vector& nums, int k) { 4 | int p1 = 0; 5 | int p2 = 0; 6 | int n = nums.size(); 7 | int cur = 1; 8 | int ans = 0; 9 | 10 | if(k <= 1) { 11 | return 0; 12 | } 13 | 14 | while(p2 < n) { 15 | cur *= nums[p2]; 16 | while(cur >= k) { 17 | cur /= nums[p1]; 18 | p1 ++; 19 | } 20 | ans += p2 - p1 + 1; 21 | p2 ++; 22 | } 23 | 24 | return ans; 25 | } 26 | }; -------------------------------------------------------------------------------- /0713-subarray-product-less-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0714-best-time-to-buy-and-sell-stock-with-transaction-fee/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices, int fee) { 4 | int buy = INT_MIN; 5 | int sell = 0; 6 | 7 | for(int p : prices) { 8 | buy = max(buy, sell - p); 9 | sell = max(sell, buy + p - fee); 10 | } 11 | 12 | return sell; 13 | } 14 | }; -------------------------------------------------------------------------------- /0714-best-time-to-buy-and-sell-stock-with-transaction-fee/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0739-daily-temperatures/0739-daily-temperatures.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector dailyTemperatures(vector& temperatures) { 4 | int n = temperatures.size(); 5 | vector res(n, 0); 6 | 7 | for(int i = n-2; i >= 0; i --) { 8 | int p = i + 1; 9 | int temp = temperatures[i]; 10 | while(p < n && temperatures[p] <= temp) { 11 | if(res[p] == 0) 12 | p = n; 13 | else 14 | p += res[p]; 15 | } 16 | 17 | if(p < n) 18 | res[i] = p - i; 19 | } 20 | 21 | return res; 22 | } 23 | }; -------------------------------------------------------------------------------- /0739-daily-temperatures/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0744-find-smallest-letter-greater-than-target/0744-find-smallest-letter-greater-than-target.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char nextGreatestLetter(vector& letters, char target) { 4 | int left = 0, right = letters.size() - 1, mid; 5 | while (left <= right) { 6 | mid = (left + right) / 2; 7 | if (letters[mid] <= target) { 8 | left = mid + 1; 9 | } else { 10 | right = mid - 1; 11 | } 12 | } 13 | 14 | return left == letters.size() ? letters[0] : letters[left]; 15 | } 16 | }; -------------------------------------------------------------------------------- /0744-find-smallest-letter-greater-than-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minCostClimbingStairs(vector& cost) { 4 | int n = cost.size(); 5 | 6 | int prevTwo = 0; 7 | int prevOne = 0; 8 | 9 | for(int i = 2; i <= n; i ++) { 10 | int temp = min(prevOne + cost[i-1], prevTwo + cost[i-2]); 11 | prevTwo = prevOne; 12 | prevOne = temp; 13 | } 14 | 15 | return prevOne; 16 | } 17 | }; -------------------------------------------------------------------------------- /0746-min-cost-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0766-toeplitz-matrix/0766-toeplitz-matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isToeplitzMatrix(vector>& matrix) { 4 | int rows = matrix.size(); 5 | int cols = matrix[0].size(); 6 | 7 | for(int i = 1; i < rows; i ++) { 8 | for(int j = 1; j < cols; j ++) { 9 | if(matrix[i][j] != matrix[i-1][j-1]) { 10 | return false; 11 | } 12 | } 13 | } 14 | 15 | return true; 16 | } 17 | }; -------------------------------------------------------------------------------- /0766-toeplitz-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findCheapestPrice(int n, vector>& flights, int src, int dst, int k) { 4 | vector dist(n, INT_MAX); 5 | dist[src] = 0; 6 | 7 | for(int i = 0; i <= k; i ++) { 8 | vector temp = dist; 9 | for(auto& f : flights) { 10 | if(dist[f[0]] != INT_MAX && dist[f[0]] + f[2] < temp[f[1]]) { 11 | temp[f[1]] = dist[f[0]] + f[2]; 12 | } 13 | } 14 | swap(temp, dist); 15 | } 16 | 17 | return dist[dst] == INT_MAX ? -1 : dist[dst]; 18 | } 19 | }; -------------------------------------------------------------------------------- /0787-cheapest-flights-within-k-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0790-domino-and-tromino-tiling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0791-custom-sort-string/0791-custom-sort-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string customSortString(string order, string s) { 4 | unordered_map m; 5 | 6 | for(char c : s) { 7 | m[c] ++; 8 | } 9 | 10 | string res = ""; 11 | for(char c : order) { 12 | if(m[c]) { 13 | res.append(m[c], c); 14 | m[c] = 0; 15 | } 16 | } 17 | 18 | for(auto entry : m) { 19 | if(entry.second > 0) { 20 | res.append(entry.second, entry.first); 21 | } 22 | } 23 | 24 | return res; 25 | } 26 | }; -------------------------------------------------------------------------------- /0791-custom-sort-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0797-all-paths-from-source-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0815-bus-routes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0834-sum-of-distances-in-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0872-leaf-similar-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0875-koko-eating-bananas/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | ListNode* middleNode(ListNode* head) { 14 | ListNode* slow = head; 15 | ListNode* fast = head; 16 | 17 | while(fast->next && fast->next->next) { 18 | slow = slow->next; 19 | fast = fast->next->next; 20 | } 21 | 22 | return fast->next ? slow->next : slow; 23 | } 24 | }; -------------------------------------------------------------------------------- /0876-middle-of-the-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0886-possible-bipartition/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0896-monotonic-array/0896-monotonic-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isMonotonic(vector A) { 4 | bool inc = true, dec = true; 5 | for (int i = 1; i < A.size(); ++i) 6 | inc &= A[i - 1] <= A[i], dec &= A[i - 1] >= A[i]; 7 | return inc || dec; 8 | } 9 | }; -------------------------------------------------------------------------------- /0896-monotonic-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0901-online-stock-span/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0907-sum-of-subarray-minimums/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0918-maximum-sum-circular-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minFallingPathSum(vector>& matrix) { 4 | int rows = matrix.size(); 5 | int cols = matrix[0].size(); 6 | int res = INT_MAX; 7 | 8 | for(int i = 1; i < rows; i ++) { 9 | for(int j = 0; j < cols; j ++) { 10 | int lefCol = max(0, j-1); 11 | int righCol = min(cols-1, j+1); 12 | matrix[i][j] = min(min(matrix[i-1][lefCol], matrix[i-1][j]), matrix[i-1][righCol]) + matrix[i][j]; 13 | } 14 | } 15 | 16 | for(int j = 0; j < cols; j ++) { 17 | res = min(res, matrix[rows-1][j]); 18 | } 19 | 20 | return res; 21 | } 22 | }; -------------------------------------------------------------------------------- /0931-minimum-falling-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0934-shortest-bridge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0935-knight-dialer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0938-range-sum-of-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minIncrementForUnique(vector& nums) { 4 | int n = nums.size(); 5 | int size = 100000 + n + 1; 6 | vector bucket(size); 7 | 8 | for(int num : nums) { 9 | bucket[num] +=1 ; 10 | } 11 | 12 | int res = 0; 13 | for(int i = 0; i < size; i ++) { 14 | if(bucket[i] == 0) { 15 | continue; 16 | } 17 | 18 | int extra = bucket[i] - 1; 19 | bucket[i+1] += extra; 20 | res += extra; 21 | } 22 | 23 | return res; 24 | } 25 | }; -------------------------------------------------------------------------------- /0945-minimum-increment-to-make-array-unique/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0958-check-completeness-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0976-largest-perimeter-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0997-find-the-town-judge/0997-find-the-town-judge.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findJudge(int n, vector>& trust) { 4 | unordered_map s; 5 | 6 | if(n == 1) 7 | return 1; 8 | 9 | for(auto t : trust) { 10 | s[t[0]] --; 11 | s[t[1]] ++; 12 | } 13 | 14 | for(auto entry : s) { 15 | if(entry.second == n-1) { 16 | return entry.first; 17 | } 18 | } 19 | 20 | return -1; 21 | } 22 | }; -------------------------------------------------------------------------------- /0997-find-the-town-judge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1-two-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1004-max-consecutive-ones-iii/1004-max-consecutive-ones-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestOnes(vector& nums, int k) { 4 | int curZeros = 0; 5 | int l = 0; 6 | int r = 0; 7 | int n = nums.size(); 8 | int ans = 0; 9 | 10 | while(r < n) { 11 | curZeros += nums[r] == 0; 12 | 13 | while(curZeros > k) { 14 | curZeros -= nums[l] == 0; 15 | l ++; 16 | } 17 | 18 | ans = max(ans, r - l + 1); 19 | r ++; 20 | } 21 | 22 | return ans; 23 | } 24 | }; -------------------------------------------------------------------------------- /1004-max-consecutive-ones-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1007-minimum-domino-rotations-for-equal-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1010-pairs-of-songs-with-total-durations-divisible-by-60/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1011-capacity-to-ship-packages-within-d-days/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1029-two-city-scheduling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1035-uncrossed-lines/1035-uncrossed-lines.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxUncrossedLines(vector& nums1, vector& nums2) { 4 | int n = nums1.size(); 5 | int m = nums2.size(); 6 | vector dp(m+1, 0); 7 | int ans = 0; 8 | 9 | for(int i = 1; i <= n; i ++) { 10 | vector temp(m+1, 0); 11 | for(int j = 1; j <= m; j ++) { 12 | if(nums1[i-1] == nums2[j-1]) { 13 | temp[j] = dp[j-1] + 1; 14 | } 15 | else { 16 | temp[j] = max(temp[j-1], dp[j]); 17 | } 18 | } 19 | swap(dp, temp); 20 | } 21 | 22 | return dp[m]; 23 | } 24 | }; -------------------------------------------------------------------------------- /1035-uncrossed-lines/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1038-binary-search-tree-to-greater-sum-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSumAfterPartitioning(vector& A, int K) { 4 | int N = A.size(); 5 | vector dp(N + 1); 6 | for (int i = 1; i <= N; ++i) { 7 | int curMax = 0, best = 0; 8 | for (int k = 1; k <= K && i - k >= 0; ++k) { 9 | curMax = max(curMax, A[i - k]); 10 | best = max(best, dp[i - k] + curMax * k); 11 | } 12 | dp[i] = best; 13 | } 14 | return dp[N]; 15 | } 16 | }; -------------------------------------------------------------------------------- /1043-partition-array-for-maximum-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1046-last-stone-weight/1046-last-stone-weight.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lastStoneWeight(int[] stones) { 3 | PriorityQueue pq = new PriorityQueue<>((a, b) -> b-a); 4 | 5 | for(int stone : stones) { 6 | pq.offer(stone); 7 | } 8 | 9 | while(pq.size() > 1) { 10 | int diff = pq.poll() - pq.poll(); 11 | pq.offer(diff); 12 | } 13 | 14 | return pq.peek(); 15 | } 16 | } -------------------------------------------------------------------------------- /1046-last-stone-weight/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(string s) { 4 | int i = 0, j = 0; 5 | int n = s.size(); 6 | 7 | while(j < n) { 8 | s[i] = s[j]; 9 | if(i > 0 && s[i] == s[i-1]) { 10 | i -= 2; 11 | } 12 | j ++; 13 | i ++; 14 | } 15 | 16 | return s.substr(0, i); 17 | } 18 | }; 19 | 20 | // x 21 | // cur: abbaca 22 | 23 | // j 24 | // temp: cab -------------------------------------------------------------------------------- /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 | ​ -------------------------------------------------------------------------------- /1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string gcdOfStrings(string str1, string str2) { 4 | if(str1 + str2 != str2 + str1) { 5 | return ""; 6 | } 7 | 8 | int len = gcd(str1.size(), str2.size()); 9 | return str1.substr(0, len); 10 | } 11 | }; -------------------------------------------------------------------------------- /1071-greatest-common-divisor-of-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1074-number-of-submatrices-that-sum-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1091-shortest-path-in-binary-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1094-car-pooling/1094-car-pooling.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool carPooling(vector>& trips, int capacity) { 4 | vector cur(1001, 0); 5 | 6 | for(auto trip : trips) { 7 | int pass = trip[0]; 8 | cur[trip[1]] += pass; 9 | cur[trip[2]] -= pass; 10 | } 11 | 12 | if(cur[0] > capacity) 13 | return false; 14 | 15 | for(int i = 1; i <= 1000; i ++) { 16 | cur[i] += cur[i-1]; 17 | // cout << i << " " << cur[i] << endl; 18 | if(cur[i] > capacity) 19 | return false; 20 | } 21 | 22 | return true; 23 | } 24 | }; -------------------------------------------------------------------------------- /1094-car-pooling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /11-container-with-most-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1101-the-earliest-moment-when-everyone-become-friends/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1110-delete-nodes-and-return-forest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /112-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /113-path-sum-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1136-parallel-courses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | unordered_map m; 4 | int tribonacci(int n) { 5 | if(n < 2) 6 | return n; 7 | if(n == 2) 8 | return 1; 9 | if(m[n]) 10 | return m[n]; 11 | 12 | int ans = tribonacci(n-1) + tribonacci(n-2) + tribonacci(n-3); 13 | return m[n] = ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1143-longest-common-subsequence/1143-longest-common-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestCommonSubsequence(string text1, string text2) { 4 | int m = text1.size(); 5 | int n = text2.size(); 6 | 7 | vector> dp(m+1, vector(n+1)); 8 | 9 | for(int i = 1; i <= m ; i ++) { 10 | for(int j = 1; j <= n; j ++) { 11 | if(text1[i-1] == text2[j-1]) { 12 | dp[i][j] = dp[i-1][j-1] + 1; 13 | } 14 | else { 15 | dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 16 | } 17 | } 18 | } 19 | 20 | return dp[m][n]; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /1143-longest-common-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1146-snapshot-array/1146-snapshot-array.cpp: -------------------------------------------------------------------------------- 1 | class SnapshotArray { 2 | unordered_map> m; 3 | int snaps = 0; 4 | public: 5 | SnapshotArray(int length) { 6 | } 7 | 8 | void set(int index, int val) { 9 | m[index][snaps] = val; 10 | } 11 | 12 | int snap() { 13 | return snaps ++; 14 | } 15 | 16 | int get(int index, int snap_id) { 17 | auto it = m[index].upper_bound(snap_id); 18 | return it == m[index].begin() ? 0 : (--it)->second; 19 | } 20 | }; 21 | 22 | /** 23 | * Your SnapshotArray object will be instantiated and called as such: 24 | * SnapshotArray* obj = new SnapshotArray(length); 25 | * obj->set(index,val); 26 | * int param_2 = obj->snap(); 27 | * int param_3 = obj->get(index,snap_id); 28 | */ -------------------------------------------------------------------------------- /1146-snapshot-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1153-string-transforms-into-another-string/1153-string-transforms-into-another-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canConvert(string str1, string str2) { 4 | unordered_map mapping; 5 | unordered_set used; 6 | int n = str1.size(); 7 | 8 | if(str1 == str2) 9 | return true; 10 | 11 | for(int i = 0; i < n; i ++) { 12 | if(mapping.count(str1[i]) && mapping[str1[i]] != str2[i]) { 13 | return false; 14 | } 15 | mapping[str1[i]] = str2[i]; 16 | used.insert(str2[i]); 17 | } 18 | 19 | return used.size() < 26; 20 | } 21 | }; -------------------------------------------------------------------------------- /1153-string-transforms-into-another-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | #define MOD 1000000007 4 | int dp[32][1002]; 5 | 6 | int solve(int d, int f, int target){ 7 | if(d==0 && target==0) return 1; 8 | if(d<=0 || target<=0) return 0; 9 | if(dp[d][target] != -1) return dp[d][target]; 10 | 11 | int sum=0; 12 | for(int i=1;i<=f;i++){ 13 | sum = (sum % MOD + solve(d-1,f,target-i)%MOD)%MOD; 14 | } 15 | dp[d][target] = sum; 16 | return dp[d][target]; 17 | } 18 | 19 | int numRollsToTarget(int d, int f, int target) { 20 | memset(dp,-1,sizeof(dp)); 21 | return solve(d,f,target); 22 | } 23 | }; -------------------------------------------------------------------------------- /1155-number-of-dice-rolls-with-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1161-maximum-level-sum-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1167-minimum-cost-to-connect-sticks/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /117-populating-next-right-pointers-in-each-node-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /118-pascals-triangle/118-pascals-triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> generate(int numRows) { 4 | vector> t(numRows); 5 | for(int i = 0; i < numRows; i ++) { 6 | t[i].resize(i + 1); 7 | t[i][0] = t[i][i] = 1; 8 | for(int j = 1; j < i; j ++) { 9 | t[i][j] = t[i - 1][j - 1] + t[i - 1][j]; 10 | } 11 | } 12 | return t; 13 | } 14 | }; -------------------------------------------------------------------------------- /118-pascals-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1186-maximum-subarray-sum-with-one-deletion/1186-maximum-subarray-sum-with-one-deletion.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumSum(vector& arr) { 4 | int drop = 0; 5 | int noDrop = arr[0]; 6 | int ans = arr[0]; 7 | int n = arr.size(); 8 | 9 | for(int i = 1; i < n; i ++) { 10 | drop = max(drop + arr[i], noDrop); 11 | noDrop = max(noDrop + arr[i], arr[i]); 12 | ans = max(ans, max(drop, noDrop)); 13 | } 14 | 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /1186-maximum-subarray-sum-with-one-deletion/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1189-maximum-number-of-balloons/1189-maximum-number-of-balloons.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxNumberOfBalloons(string text) { 4 | unordered_map count; 5 | 6 | for(char c : text) { 7 | count[c] ++; 8 | } 9 | 10 | string check = "balon"; 11 | int minn = INT_MAX; 12 | 13 | for(char c : check) { 14 | if(c == 'l') 15 | minn = min(minn, count[c] / 2); 16 | else if(c == 'o') 17 | minn = min(minn, count[c] / 2); 18 | else 19 | minn = min(minn, count[c]); 20 | } 21 | 22 | return minn; 23 | } 24 | }; -------------------------------------------------------------------------------- /1189-maximum-number-of-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /12-integer-to-roman/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 m; 5 | unordered_set occur; 6 | 7 | for(int num : arr) { 8 | m[num] ++; 9 | } 10 | 11 | for(auto& [num, count] : m) { 12 | if(occur.contains(count)) { 13 | return false; 14 | } 15 | 16 | occur.insert(count); 17 | } 18 | 19 | return true; 20 | } 21 | }; -------------------------------------------------------------------------------- /1207-unique-number-of-occurrences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1209-remove-all-adjacent-duplicates-in-string-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1218-longest-arithmetic-subsequence-of-given-difference/1218-longest-arithmetic-subsequence-of-given-difference.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestSubsequence(vector& arr, int difference) { 4 | unordered_map count; 5 | int ans = 0; 6 | 7 | for(int num : arr) { 8 | count[num] = count[num - difference] + 1; 9 | ans = max(ans, count[num]); 10 | } 11 | 12 | return ans; 13 | } 14 | }; -------------------------------------------------------------------------------- /1218-longest-arithmetic-subsequence-of-given-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1220-count-vowels-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1232-check-if-it-is-a-straight-line/1232-check-if-it-is-a-straight-line.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkStraightLine(vector>& coordinates) { 4 | if(coordinates.size() <= 2) return true; 5 | int x1 = coordinates[0][0]; 6 | int y1 = coordinates[0][1]; 7 | int x2 = coordinates[1][0]; 8 | int y2 = coordinates[1][1]; 9 | for(int i=2;i sequentialDigits(int l, int h) { 4 | queue q; 5 | for(int i = 1; i <= 9; i++) { 6 | q.push(i); 7 | } 8 | vector ret; 9 | while(!q.empty()) { 10 | int f = q.front(); 11 | q.pop(); 12 | if(f <= h && f >= l) { 13 | ret.push_back(f); 14 | } 15 | if(f > h) 16 | break; 17 | int num = f % 10; 18 | if(num < 9) { 19 | q.push(f * 10 + (num + 1)); 20 | } 21 | } 22 | return ret; 23 | } 24 | }; -------------------------------------------------------------------------------- /1291-sequential-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /13-roman-to-integer/13-roman-to-integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int romanToInt(string s) { 4 | map m = { { 'I' , 1 }, 5 | { 'V' , 5 }, 6 | { 'X' , 10 }, 7 | { 'L' , 50 }, 8 | { 'C' , 100 }, 9 | { 'D' , 500 }, 10 | { 'M' , 1000 }}; 11 | 12 | int sum = 0; 13 | for(int i = 0; i < s.length() - 1; i ++) { 14 | if(m[s[i]] < m[s[i+1]]) 15 | sum -= m[s[i]]; 16 | else 17 | sum += m[s[i]]; 18 | } 19 | sum += m[s[s.length()-1]]; 20 | // cout << sum << endl; 21 | return sum; 22 | } 23 | }; -------------------------------------------------------------------------------- /13-roman-to-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /131-palindrome-partitioning/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1319-number-of-operations-to-make-network-connected/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1328-break-a-palindrome/1328-break-a-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string breakPalindrome(string palindrome) { 4 | int n = palindrome.size(); 5 | if(n <= 1) 6 | return ""; 7 | for(int i = 0; i < n / 2; i ++) { 8 | if(palindrome[i] != 'a') { 9 | palindrome[i] = 'a'; 10 | return palindrome; 11 | } 12 | } 13 | 14 | palindrome[n-1] = 'b'; 15 | return palindrome; 16 | } 17 | }; -------------------------------------------------------------------------------- /1328-break-a-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1329-sort-the-matrix-diagonally/1329-sort-the-matrix-diagonally.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> diagonalSort(vector>& mat) { 4 | int m = mat.size(), n = mat[0].size(); 5 | // all elements on same diagonal have same i-j result. 6 | unordered_map, greater>> map; // min priority queue 7 | for (int i = 0; i < m; i++) { 8 | for (int j = 0; j < n; j++) { 9 | map[i - j].push(mat[i][j]); 10 | } 11 | } 12 | for (int i = 0; i < m; i++) { 13 | for (int j = 0; j < n; j++) { 14 | mat[i][j] = map[i - j].top(); map[i - j].pop(); 15 | } 16 | } 17 | return mat; 18 | } 19 | }; -------------------------------------------------------------------------------- /1329-sort-the-matrix-diagonally/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /133-clone-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1345-jump-game-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1347-minimum-number-of-steps-to-make-two-strings-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /135-candy/135-candy.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int candy(vector &ratings) 4 | { 5 | int size=ratings.size(); 6 | if(size<=1) 7 | return size; 8 | vector num(size,1); 9 | for (int i = 1; i < size; i++) 10 | { 11 | if(ratings[i]>ratings[i-1]) 12 | num[i]=num[i-1]+1; 13 | } 14 | for (int i= size-1; i>0 ; i--) 15 | { 16 | if(ratings[i-1]>ratings[i]) 17 | num[i-1]=max(num[i]+1,num[i-1]); 18 | } 19 | int result=0; 20 | for (int i = 0; i < size; i++) 21 | { 22 | result+=num[i]; 23 | // cout<& nums) { 4 | int n = nums.size(); 5 | unordered_map productCount; 6 | 7 | for(int i = 0; i < n; i ++) { 8 | for(int j = i + 1; j < n; j ++) { 9 | int product = nums[i] * nums[j]; 10 | productCount[product] ++; 11 | } 12 | } 13 | 14 | int res = 0; 15 | 16 | for(auto& entry : productCount) { 17 | int count = entry.second; 18 | int combinations = count * (count - 1) / 2; 19 | res += combinations * 8; 20 | } 21 | 22 | return res; 23 | } 24 | }; -------------------------------------------------------------------------------- /1377-frog-position-after-t-seconds/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /138-copy-list-with-random-pointer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1381-design-a-stack-with-increment-operation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1383-maximum-performance-of-a-team/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1386-cinema-seat-allocation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /139-word-break/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1396-design-underground-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /140-word-break-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1405-longest-happy-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /141-linked-list-cycle/141-linked-list-cycle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | bool hasCycle(ListNode *head) { 12 | ListNode* slow = head; 13 | if(!head || !head->next) 14 | return false; 15 | ListNode* fast = head->next; 16 | 17 | while(fast->next && fast->next->next) { 18 | if(fast == slow) 19 | return true; 20 | fast = fast->next->next; 21 | slow = slow->next; 22 | } 23 | 24 | return false; 25 | } 26 | }; -------------------------------------------------------------------------------- /141-linked-list-cycle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1424-diagonal-traverse-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1428-leftmost-column-with-at-least-a-one/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1431-kids-with-the-greatest-number-of-candies/1431-kids-with-the-greatest-number-of-candies.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector kidsWithCandies(vector& candies, int extraCandies) { 4 | // Find out the greatest number of candies among all the kids. 5 | int maxCandies = 0; 6 | for (int candy : candies) { 7 | maxCandies = max(maxCandies, candy); 8 | } 9 | // For each kid, check if they will have greatest number of candies 10 | // among all the kids. 11 | vector result; 12 | for (int candy : candies) { 13 | result.push_back(candy + extraCandies >= maxCandies); 14 | } 15 | 16 | return result; 17 | } 18 | }; -------------------------------------------------------------------------------- /1431-kids-with-the-greatest-number-of-candies/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1436-destination-city/1436-destination-city.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string destCity(vector>& paths) { 4 | unordered_set hasOutgoing; 5 | for (int i = 0; i < paths.size(); i++) { 6 | hasOutgoing.insert(paths[i][0]); 7 | } 8 | 9 | for (int i = 0; i < paths.size(); i++) { 10 | string candidate = paths[i][1]; 11 | if (hasOutgoing.find(candidate) == hasOutgoing.end()) { 12 | return candidate; 13 | } 14 | } 15 | 16 | return ""; 17 | } 18 | }; -------------------------------------------------------------------------------- /1436-destination-city/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1448-count-good-nodes-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /146-lru-cache/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1472-design-browser-history/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1473-paint-house-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1490-clone-n-ary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1492-the-kth-factor-of-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1493-longest-subarray-of-1s-after-deleting-one-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /15-3sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1504-count-submatrices-with-all-ones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1507-reformat-date/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /151-reverse-words-in-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1510-stone-game-iv/1510-stone-game-iv.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool winnerSquareGame(int n) { 4 | vector dp(n+1, false); 5 | dp[0] = false; 6 | dp[1] = true; 7 | 8 | for(int i = 2; i <= n; i ++) { 9 | bool res = false; 10 | for(int j = 1; j * j <= i; j ++) { 11 | res |= !dp[i-j*j]; 12 | } 13 | dp[i] = res; 14 | } 15 | 16 | return dp[n]; 17 | } 18 | }; 19 | 20 | // 1: w 21 | // 2 : l 22 | // 3: w 23 | // 4: w 24 | // 5: -------------------------------------------------------------------------------- /1510-stone-game-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1514-path-with-maximum-probability/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1519-number-of-nodes-in-the-sub-tree-with-the-same-label/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /152-maximum-product-subarray/152-maximum-product-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProduct(vector& nums) { 4 | int n = nums.size(); 5 | int globalMax = nums[0]; 6 | int curMax = nums[0]; 7 | int curMin = nums[0]; 8 | 9 | for(int i = 1; i < n; i ++) { 10 | int num = nums[i]; 11 | if(num < 0) { 12 | swap(curMax, curMin); 13 | } 14 | 15 | curMax = max(num, curMax * num); 16 | curMin = min(num, curMin * num); 17 | globalMax = max(curMax, globalMax); 18 | } 19 | 20 | return globalMax; 21 | } 22 | }; -------------------------------------------------------------------------------- /152-maximum-product-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1522-diameter-of-n-ary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /153-find-minimum-in-rotated-sorted-array/153-find-minimum-in-rotated-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMin(vector& nums) { 4 | int n = nums.size(); 5 | int l = 0, r = n-1; 6 | 7 | while(l < r) { 8 | int mid = l + (r - l) / 2; 9 | if(nums[mid] <= nums[r]) { 10 | r = mid; 11 | } 12 | else 13 | l = mid + 1; 14 | } 15 | 16 | return nums[l]; 17 | } 18 | }; -------------------------------------------------------------------------------- /153-find-minimum-in-rotated-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1530-number-of-good-leaf-nodes-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1539-kth-missing-positive-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1544-make-the-string-great/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1548-the-most-similar-path-in-a-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1554-strings-differ-by-one-character/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1556-make-two-arrays-equal-by-reversing-subarrays/1556-make-two-arrays-equal-by-reversing-subarrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canBeEqual(vector& target, vector& arr) { 4 | unordered_map nums; 5 | 6 | for(int num : target) { 7 | nums[num] ++; 8 | } 9 | 10 | for(int num : arr) { 11 | if(nums.count(num) == 0) { 12 | return false; 13 | } 14 | 15 | nums[num] --; 16 | 17 | if(nums[num] == 0) { 18 | nums.erase(num); 19 | } 20 | } 21 | 22 | return nums.size() == 0; 23 | } 24 | }; -------------------------------------------------------------------------------- /1557-minimum-number-of-vertices-to-reach-all-nodes/1557-minimum-number-of-vertices-to-reach-all-nodes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findSmallestSetOfVertices(int n, vector>& edges) { 4 | vector seen(n, false); 5 | 6 | for(auto& e : edges) { 7 | seen[e[1]] = true; 8 | } 9 | 10 | vector res; 11 | 12 | for(int i = 0; i < n; i ++) { 13 | if(seen[i] == false) { 14 | res.push_back(i); 15 | } 16 | } 17 | 18 | return res; 19 | } 20 | }; -------------------------------------------------------------------------------- /1557-minimum-number-of-vertices-to-reach-all-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minCost(string S, vector& C) { 4 | int n = S.size(); 5 | int curMax = 0; 6 | int res = 0; 7 | for(int i = 0; i < n; i ++) { 8 | if(i > 0 && S[i] != S[i-1]) { 9 | curMax = 0; 10 | } 11 | res += min(C[i], curMax); 12 | curMax = max(curMax, C[i]); 13 | } 14 | 15 | return res; 16 | } 17 | }; -------------------------------------------------------------------------------- /1578-minimum-time-to-make-rope-colorful/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1583-count-unhappy-friends/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1584-min-cost-to-connect-all-points/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /16-3sum-closest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /160-intersection-of-two-linked-lists/160-intersection-of-two-linked-lists.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 12 | ListNode* p1 = headA; 13 | ListNode* p2 = headB; 14 | 15 | while(p1 != p2) { 16 | p1 = p1 ? p1->next : headB; 17 | p2 = p2 ? p2->next : headA; 18 | } 19 | 20 | return p1; 21 | } 22 | }; -------------------------------------------------------------------------------- /160-intersection-of-two-linked-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1614-maximum-nesting-depth-of-the-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /162-find-peak-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1631-number-of-sub-arrays-with-odd-sum/1631-number-of-sub-arrays-with-odd-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mod = pow(10,9) + 7; 4 | int numOfSubarrays(vector& arr) { 5 | int odd = 0; 6 | int even = 0; 7 | int res = 0; 8 | 9 | for(int num : arr) { 10 | bool isOdd = num % 2; 11 | 12 | if(isOdd) { 13 | swap(even, odd); 14 | odd ++; 15 | } 16 | else { 17 | even ++; 18 | } 19 | 20 | res = (res + odd) % mod; 21 | } 22 | 23 | return res; 24 | } 25 | }; -------------------------------------------------------------------------------- /1631-path-with-minimum-effort/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1632-rank-transform-of-a-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int furthestBuilding(vector& A, int bricks, int ladders) { 4 | priority_queue, greater> pq; 5 | for (int i = 1; i < A.size(); i++) { 6 | int d = A[i] - A[i-1]; 7 | if (d > 0) 8 | pq.push(d); 9 | if (pq.size() > ladders) { 10 | bricks -= pq.top(); 11 | pq.pop(); 12 | } 13 | if (bricks < 0) 14 | return i-1; 15 | } 16 | return A.size() - 1; 17 | } 18 | }; -------------------------------------------------------------------------------- /1642-furthest-building-you-can-reach/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1644-lowest-common-ancestor-of-a-binary-tree-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /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/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1695-maximum-erasure-value/1695-maximum-erasure-value.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumUniqueSubarray(vector& nums) { 4 | unordered_set seen; 5 | int l = 0, r = 0; 6 | int n = nums.size(); 7 | int ans = 0; 8 | int sum = 0; 9 | 10 | while(r < n) { 11 | while(seen.find(nums[r]) != seen.end()) { 12 | sum -= nums[l]; 13 | seen.erase(nums[l]); 14 | l ++; 15 | } 16 | sum += nums[r]; 17 | ans = max(ans, sum); 18 | seen.insert(nums[r]); 19 | 20 | r ++; 21 | } 22 | 23 | return ans; 24 | } 25 | }; -------------------------------------------------------------------------------- /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 | vector dp(size(nums)); 5 | dp[0] = nums[0]; 6 | deque q{ 0 }; 7 | for(int i = 1; i < size(nums); i++) { 8 | if(q.front() < i - k) q.pop_front(); // can't reach current index from index stored in q 9 | dp[i] = nums[i] + dp[q.front()]; // update max score for current index 10 | while(!q.empty() && dp[q.back()] <= dp[i]) // pop indices which won't be ever chosen in the future 11 | q.pop_back(); 12 | q.push_back(i); // insert current index 13 | } 14 | return dp.back(); 15 | } 16 | }; -------------------------------------------------------------------------------- /1696-jump-game-vi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool halvesAreAlike(string s) { 4 | int vowelDiff = 0, mid = size(s) / 2; 5 | 6 | for(int i = 0; i < mid; i++) 7 | vowelDiff += isVowel(s[i]) - isVowel(s[mid + i]); 8 | 9 | return vowelDiff == 0; 10 | } 11 | bool isVowel(char &c){ 12 | return c == 'a' || c == 'e' || c =='i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'; 13 | } 14 | }; -------------------------------------------------------------------------------- /1704-determine-if-string-halves-are-alike/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>& boxTypes, int truckSize) { 4 | priority_queue, greater> pq; 5 | int sum = 0; 6 | 7 | for(auto& type : boxTypes) { 8 | int num = type[0]; 9 | int weight = type[1]; 10 | 11 | for(int i = 0; i < num; i ++) { 12 | pq.push(weight); 13 | sum += weight; 14 | 15 | if(pq.size() > truckSize) { 16 | sum -= pq.top(); 17 | pq.pop(); 18 | } 19 | } 20 | } 21 | 22 | return sum; 23 | } 24 | }; -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1721-swapping-nodes-in-a-linked-list/1721-swapping-nodes-in-a-linked-list.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* swapNodes(ListNode* head, int k) { 4 | ListNode *ptr1 = head, *ptr2 = head, *kth = NULL; 5 | while (--k) 6 | ptr1 = ptr1->next; 7 | 8 | kth = ptr1; 9 | ptr1 = ptr1->next; 10 | 11 | while (ptr1) { 12 | ptr1 = ptr1->next; 13 | ptr2 = ptr2->next; 14 | } 15 | swap(ptr2->val, kth->val); 16 | return head; 17 | } 18 | }; -------------------------------------------------------------------------------- /1721-swapping-nodes-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /173-binary-search-tree-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1732-find-the-highest-altitude/1732-find-the-highest-altitude.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestAltitude(vector& gain) { 4 | int currentAltitude = 0; 5 | // Highest altitude currently is 0. 6 | int highestPoint = currentAltitude; 7 | 8 | for (int altitudeGain : gain) { 9 | // Adding the gain in altitude to the current altitude. 10 | currentAltitude += altitudeGain; 11 | // Update the highest altitude. 12 | highestPoint = max(highestPoint, currentAltitude); 13 | } 14 | 15 | return highestPoint; 16 | } 17 | }; -------------------------------------------------------------------------------- /1732-find-the-highest-altitude/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1762-buildings-with-an-ocean-view/1762-buildings-with-an-ocean-view.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findBuildings(vector& heights) { 4 | vector res; 5 | int n = heights.size(); 6 | int curMax = 0; 7 | 8 | for(int i = n-1; i >= 0; i --) { 9 | int h = heights[i]; 10 | // cout << h << " " << curMax << endl; 11 | if(h > curMax) { 12 | // cout << "fuck" <>& edges) { 4 | auto& firstEdge = edges[0]; 5 | auto& secondEdge = edges[1]; 6 | 7 | return firstEdge[0] == secondEdge[0] ? firstEdge[0] : 8 | (firstEdge[0] == secondEdge[1] ? firstEdge[0] : firstEdge[1]); 9 | } 10 | }; -------------------------------------------------------------------------------- /1791-find-center-of-star-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1803-average-waiting-time/1803-average-waiting-time.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double averageWaitingTime(vector>& customers) { 4 | int n = customers.size(); 5 | double sum = 0; 6 | int cur = 0; 7 | 8 | for(auto& customer : customers) { 9 | int extra = max(0, cur - customer[0]); 10 | int wait = customer[1] + extra; 11 | 12 | sum += wait; 13 | cur = max(cur, customer[0] + wait); 14 | } 15 | 16 | return sum / n; 17 | } 18 | }; -------------------------------------------------------------------------------- /1822-sign-of-the-product-of-an-array/1822-sign-of-the-product-of-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int arraySign(vector& nums) { 4 | int sign = 1; 5 | 6 | for(int num : nums) { 7 | if(num == 0) { 8 | return 0; 9 | } 10 | if(num < 0) { 11 | sign = -sign; 12 | } 13 | } 14 | 15 | return sign; 16 | } 17 | }; -------------------------------------------------------------------------------- /1822-sign-of-the-product-of-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /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 | // Add every letter of 'sentence' to hash set 'seen'. 5 | unordered_set seen(sentence.begin(), sentence.end()); 6 | 7 | // If the size of 'seen' is 26, then 'sentence' is a pangram. 8 | return seen.size() == 26; 9 | } 10 | }; -------------------------------------------------------------------------------- /1832-check-if-the-sentence-is-pangram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1834-single-threaded-cpu/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1849-maximum-absolute-sum-of-any-subarray/1849-maximum-absolute-sum-of-any-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxAbsoluteSum(vector& nums) { 4 | int posSum = 0; 5 | int negSum = 0; 6 | int res = 0; 7 | 8 | for(int num : nums) { 9 | posSum = max(posSum + num, num); 10 | negSum = min(negSum + num, num); 11 | 12 | res = max(res, max(abs(negSum), abs(posSum))); 13 | } 14 | 15 | return res; 16 | } 17 | }; -------------------------------------------------------------------------------- /1857-largest-color-value-in-a-directed-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1865-finding-pairs-with-a-certain-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1889-check-if-number-is-a-sum-of-powers-of-three/1889-check-if-number-is-a-sum-of-powers-of-three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPowersOfThree(int n) { 4 | int largestPow = 0; 5 | 6 | while(pow(3, largestPow) <= n) { 7 | largestPow ++; 8 | } 9 | largestPow --; 10 | 11 | for(int i = largestPow; i >= 0; i --) { 12 | int curPow = pow(3, i); 13 | 14 | if(curPow > n) { 15 | continue; 16 | } 17 | 18 | n -= curPow; 19 | 20 | if(n == 0) { 21 | return true; 22 | } 23 | } 24 | 25 | return n == 0; 26 | } 27 | }; -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /190-reverse-bits/190-reverse-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | uint32_t reverseBits(uint32_t n) { 4 | uint32_t ans = 0; 5 | 6 | for(int i = 0; i < 32; i ++) { 7 | ans <<= 1; 8 | ans = ans | (n & 1); 9 | n >>= 1; 10 | } 11 | 12 | return ans; 13 | } 14 | }; -------------------------------------------------------------------------------- /190-reverse-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /191-number-of-1-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1915-check-if-one-string-swap-can-make-strings-equal/1915-check-if-one-string-swap-can-make-strings-equal.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool areAlmostEqual(string s1, string s2) { 4 | int diff = 0; 5 | int n = s1.size(); 6 | vector cs; 7 | int j = 0; 8 | 9 | for(int i = 0; i < n; i ++) { 10 | if(s1[i] != s2[i]) { 11 | cs.push_back(i); 12 | } 13 | 14 | if(cs.size() > 2) { 15 | return false; 16 | } 17 | } 18 | 19 | return cs.size() == 0 || (cs.size() == 2 && s1[cs[0]] == s2[cs[1]] && s1[cs[1]] == s2[cs[0]]); 20 | } 21 | }; -------------------------------------------------------------------------------- /1937-maximum-number-of-points-with-cost/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1951-find-the-winner-of-the-circular-game/1951-find-the-winner-of-the-circular-game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findTheWinner(int n, int k) { 4 | queue q; 5 | for(int i = 1; i <=n; i ++) { 6 | q.push(i); 7 | } 8 | 9 | while(q.size() > 1) { 10 | for(int i = 0; i < k-1; i ++) { 11 | q.push(q.front()); 12 | q.pop(); 13 | } 14 | 15 | q.pop(); 16 | } 17 | 18 | return q.front(); 19 | } 20 | }; -------------------------------------------------------------------------------- /1974-minimum-time-to-type-word-using-special-typewriter/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1979-find-greatest-common-divisor-of-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /198-house-robber/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /199-binary-tree-right-side-view/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1996-the-number-of-weak-characters-in-the-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2-add-two-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /200-number-of-islands/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2007-find-original-array-from-doubled-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2013-detect-squares/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2021-remove-all-occurrences-of-a-substring/2021-remove-all-occurrences-of-a-substring.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeOccurrences(string s, string part) { 4 | int i = 0; 5 | int j = 0; 6 | int n = s.size(); 7 | int partSize = part.size(); 8 | 9 | while(i < n) { 10 | s[j] = s[i]; 11 | 12 | if(j >= partSize - 1 && s.substr(j - partSize + 1, partSize) == part) { 13 | j -= partSize; 14 | } 15 | 16 | j ++; 17 | i ++; 18 | } 19 | 20 | return s.substr(0, j); 21 | } 22 | }; -------------------------------------------------------------------------------- /2034-stock-price-fluctuation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2055-plates-between-candles/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /207-course-schedule/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /208-implement-trie-prefix-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /209-minimum-size-subarray-sum/209-minimum-size-subarray-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minSubArrayLen(int target, vector& nums) { 4 | int l = 0; 5 | int r = 0; 6 | 7 | int n = nums.size(); 8 | int ans = INT_MAX; 9 | int sum = 0; 10 | 11 | while(r < n) { 12 | sum += nums[r]; 13 | 14 | while(sum >= target) { 15 | ans = min(ans, r -l + 1); 16 | sum -= nums[l]; 17 | l ++; 18 | } 19 | 20 | r ++; 21 | } 22 | 23 | return ans == INT_MAX ? 0 : ans; 24 | } 25 | }; -------------------------------------------------------------------------------- /209-minimum-size-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | sdfdsf 2 | ​ -------------------------------------------------------------------------------- /2092-find-all-people-with-secret/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2096-step-by-step-directions-from-a-binary-tree-node-to-another/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /210-course-schedule-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPal(string s) { 4 | int n = s.size(); 5 | int l = 0; 6 | int r = n -1; 7 | while(l < r) { 8 | if(s[l] != s[r]) 9 | return false; 10 | l ++; 11 | r --; 12 | } 13 | return true; 14 | } 15 | 16 | string firstPalindrome(vector& words) { 17 | 18 | for(auto w : words) { 19 | if(isPal(w)) { 20 | return w; 21 | } 22 | } 23 | 24 | return ""; 25 | } 26 | }; -------------------------------------------------------------------------------- /2108-find-first-palindromic-string-in-the-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /211-design-add-and-search-words-data-structure/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2111-minimum-operations-to-make-the-array-k-increasing/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /212-word-search-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfBeams(vector& bank) { 4 | int prev = 0; 5 | int sum = 0; 6 | 7 | for(auto &s : bank) { 8 | int sec = 0; 9 | for(char c : s) { 10 | sec += c == '1'; 11 | } 12 | 13 | 14 | sum += sec * prev; 15 | if(sec) { 16 | prev = sec; 17 | } 18 | } 19 | 20 | return sum; 21 | } 22 | }; -------------------------------------------------------------------------------- /2125-number-of-laser-beams-in-a-bank/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2128-remove-all-ones-with-row-and-column-flips/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2135-count-words-obtained-after-adding-a-letter/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2140-solving-questions-with-brainpower/2140-solving-questions-with-brainpower.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long mostPoints(vector>& questions) { 4 | int n = questions.size(); 5 | vector dp(n, 0); 6 | 7 | for(int i = n-1; i >= 0; i --) { 8 | long long solve = questions[i][0]; 9 | long long reach = questions[i][1] + 1; 10 | if(i + reach < n) { 11 | solve += dp[i+reach]; 12 | } 13 | long long skip = i < n-1 ? dp[i+1] : 0; 14 | dp[i] = max(solve, skip); 15 | } 16 | 17 | return dp[0]; 18 | } 19 | }; -------------------------------------------------------------------------------- /2140-solving-questions-with-brainpower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2163-kth-distinct-string-in-an-array/2163-kth-distinct-string-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string kthDistinct(vector& arr, int k) { 4 | unordered_map count; 5 | 6 | for(auto& str : arr) { 7 | count[str] ++; 8 | } 9 | 10 | for(auto& str : arr) { 11 | if(count[str] == 1) { 12 | k --; 13 | if(k == 0) { 14 | return str; 15 | } 16 | } 17 | } 18 | 19 | return ""; 20 | } 21 | }; -------------------------------------------------------------------------------- /218-the-skyline-problem/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2187-minimum-time-to-complete-trips/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /219-contains-duplicate-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2209-minimum-white-tiles-after-covering-with-carpets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2215-find-the-difference-of-two-arrays/2215-find-the-difference-of-two-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> findDifference(vector& nums1, vector& nums2) { 4 | unordered_set set1(nums1.begin(), nums1.end()); 5 | unordered_set set2(nums2.begin(), nums2.end()); 6 | 7 | vector distinct_nums1, distinct_nums2; 8 | for (int num : set1) { 9 | if (set2.count(num) == 0) { 10 | distinct_nums1.push_back(num); 11 | } 12 | } 13 | 14 | for (int num : set2) { 15 | if (set1.count(num) == 0) { 16 | distinct_nums2.push_back(num); 17 | } 18 | } 19 | 20 | return {distinct_nums1, distinct_nums2}; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /2215-find-the-difference-of-two-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2222-number-of-ways-to-select-buildings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2227-encrypt-and-decrypt-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2265-partition-array-according-to-given-pivot/2265-partition-array-according-to-given-pivot.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector pivotArray(vector& nums, int pivot) { 4 | int n = nums.size(); 5 | 6 | int insert1 = 0; 7 | int insert2 = n - 1; 8 | 9 | int less = 0; 10 | vector res(n, pivot); 11 | 12 | for(int i = 0; i < n; i ++) { 13 | int ri = n - 1 - i; 14 | 15 | if(nums[i] < pivot) { 16 | res[insert1] = nums[i]; 17 | insert1 ++; 18 | } 19 | 20 | if(nums[ri] > pivot) { 21 | res[insert2] = nums[ri]; 22 | insert2 --; 23 | } 24 | } 25 | 26 | return res; 27 | } 28 | }; -------------------------------------------------------------------------------- /227-basic-calculator-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /23-merge-k-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2305-fair-distribution-of-cookies/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2316-count-unreachable-pairs-of-nodes-in-an-undirected-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /234-palindrome-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /239-sliding-window-maximum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2396-strictly-palindromic-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2397-maximum-rows-covered-by-columns/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>& matrix, int target) { 4 | int rows = matrix.size(); 5 | int cols = matrix[0].size(); 6 | 7 | int row = 0; 8 | int col = cols-1; 9 | 10 | while(row < rows && col >= 0) { 11 | int val = matrix[row][col]; 12 | if(val == target) { 13 | return true; 14 | } 15 | else if(val > target) { 16 | col --; 17 | } 18 | else if(val < target) { 19 | row ++; 20 | } 21 | } 22 | 23 | return false; 24 | } 25 | }; -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /242-valid-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2448-count-number-of-bad-pairs/2448-count-number-of-bad-pairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countBadPairs(vector& nums) { 4 | long long goodPairs = 0; 5 | long long total = 0; 6 | unordered_map diffCount; 7 | int n = nums.size(); 8 | 9 | for(int i = 0; i < n; i ++) { 10 | int diff = nums[i] - i; 11 | total += i; 12 | goodPairs += diffCount[diff]; 13 | diffCount[diff] ++; 14 | } 15 | 16 | return total - goodPairs; 17 | } 18 | }; -------------------------------------------------------------------------------- /2463-minimum-recolors-to-get-k-consecutive-black-blocks/2463-minimum-recolors-to-get-k-consecutive-black-blocks.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumRecolors(string blocks, int k) { 4 | int n = blocks.size(); 5 | int res = INT_MAX; 6 | int black = 0; 7 | 8 | int i = 0; 9 | int j = 0; 10 | 11 | while(j < n) { 12 | black += blocks[j] == 'B'; 13 | 14 | if(j - i + 1 > k) { 15 | black -= blocks[i] == 'B'; 16 | i ++; 17 | } 18 | 19 | res = min(res, k - black); 20 | j ++; 21 | } 22 | 23 | return res; 24 | } 25 | }; -------------------------------------------------------------------------------- /247-strobogrammatic-number-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2473-max-sum-of-a-pair-with-equal-sum-of-digits/2473-max-sum-of-a-pair-with-equal-sum-of-digits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumSum(vector& nums) { 4 | int res = 0; 5 | vector m(82); 6 | 7 | for(int num : nums) { 8 | int sum = sumDigits(num); 9 | 10 | if(m[sum] > 0) { 11 | res = max(res, m[sum] + num); 12 | } 13 | 14 | m[sum] = max(m[sum], num); 15 | } 16 | 17 | return res == 0 ? -1 : res; 18 | } 19 | 20 | int sumDigits(int num) { 21 | int res = 0; 22 | 23 | while(num) { 24 | res += num % 10; 25 | num /= 10; 26 | } 27 | 28 | return res; 29 | } 30 | }; -------------------------------------------------------------------------------- /2487-remove-nodes-from-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2502-sort-the-people/2502-sort-the-people.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortPeople(vector& names, vector& heights) { 4 | vector> pairs; 5 | int n = names.size(); 6 | 7 | for(int i = 0; i < n; i ++) { 8 | pairs.push_back({heights[i], names[i]}); 9 | } 10 | 11 | sort(pairs.begin(), pairs.end()); 12 | 13 | vector res; 14 | 15 | for(auto& pair : pairs) { 16 | res.push_back(pair.second); 17 | } 18 | reverse(res.begin(), res.end()); 19 | 20 | return res; 21 | } 22 | }; -------------------------------------------------------------------------------- /253-meeting-rooms-ii/253-meeting-rooms-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minMeetingRooms(vector>& intervals) { 4 | sort(intervals.begin(), intervals.end()); 5 | priority_queue, greater> pq; 6 | 7 | for(auto& inter : intervals) { 8 | if(pq.size() == 0) 9 | pq.push(inter[1]); 10 | else if(inter[0] < pq.top()) { 11 | pq.push(inter[1]); 12 | } 13 | else { 14 | pq.pop(); 15 | pq.push(inter[1]); 16 | } 17 | } 18 | 19 | return pq.size(); 20 | } 21 | }; -------------------------------------------------------------------------------- /253-meeting-rooms-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2540-minimum-common-value/2540-minimum-common-value.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int getCommon(vector& nums1, vector& nums2) { 4 | int p1 = 0, p2 = 0; 5 | 6 | int n = nums1.size(); 7 | int m = nums2.size(); 8 | 9 | while(p1 < n && p2 < m) { 10 | if(nums1[p1] == nums2[p2]) { 11 | return nums1[p1]; 12 | } 13 | 14 | if(nums1[p1] < nums2[p2]) { 15 | p1 ++; 16 | } 17 | else { 18 | p2 ++; 19 | } 20 | } 21 | 22 | return -1; 23 | } 24 | }; -------------------------------------------------------------------------------- /2540-minimum-common-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2551-apply-operations-to-an-array/2551-apply-operations-to-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector applyOperations(vector& nums) { 4 | int n = nums.size(); 5 | int j = 0; 6 | 7 | for(int i = 0; i < n; i ++) { 8 | int num = nums[i]; 9 | 10 | if(i < n-1 && num == nums[i+1]) { 11 | num *= 2; 12 | nums[i + 1] = 0; 13 | } 14 | 15 | if(num != 0) { 16 | nums[i] = 0; 17 | nums[j] = num; 18 | j ++; 19 | } 20 | } 21 | 22 | return nums; 23 | } 24 | }; -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/26-remove-duplicates-from-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int outputIdx = 1; 5 | int n = nums.size(); 6 | 7 | if(nums.size() == 0) { 8 | return 0; 9 | } 10 | 11 | for(int i = 1; i < n; i ++) { 12 | if(nums[i] != nums[i-1]) { 13 | nums[outputIdx] = nums[i]; 14 | outputIdx ++; 15 | } 16 | } 17 | 18 | return outputIdx; 19 | } 20 | }; -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /261-graph-valid-tree/261-graph-valid-tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int find(vector& root, int child) { 4 | if(root[child] == -1) 5 | return child; 6 | return root[child] = find(root, root[child]); 7 | } 8 | 9 | bool validTree(int n, vector>& edges) { 10 | vector root(n, -1); 11 | 12 | if(edges.size() != n-1) { 13 | return false; 14 | } 15 | 16 | for(auto e : edges) { 17 | int px = find(root, e[0]); 18 | int py = find(root, e[1]); 19 | 20 | if(px != py) { 21 | root[px] = py; 22 | n --; 23 | } 24 | } 25 | 26 | return n == 1; 27 | } 28 | }; -------------------------------------------------------------------------------- /261-graph-valid-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2649-count-total-number-of-colored-cells/2649-count-total-number-of-colored-cells.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long coloredCells(int n) { 4 | long long res = 1; 5 | 6 | for(int i = 0; i < n; i ++) { 7 | res += 4 * i; 8 | } 9 | 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /266-palindrome-permutation/266-palindrome-permutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canPermutePalindrome(string s) { 4 | unordered_map count; 5 | 6 | for(char c : s) { 7 | count[c] ++; 8 | } 9 | 10 | bool seenOdd = false; 11 | 12 | for(auto entry : count) { 13 | if(entry.second % 2) { 14 | if(seenOdd) 15 | return false; 16 | seenOdd = true; 17 | } 18 | } 19 | 20 | return true; 21 | } 22 | }; -------------------------------------------------------------------------------- /266-palindrome-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /269-alien-dictionary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /271-encode-and-decode-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2727-number-of-senior-citizens/2727-number-of-senior-citizens.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countSeniors(vector& details) { 4 | int res = 0; 5 | 6 | for(auto& d : details) { 7 | int age = stoi(d.substr(11,2)); 8 | if(age > 60) 9 | res ++; 10 | } 11 | 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /278-first-bad-version/278-first-bad-version.cpp: -------------------------------------------------------------------------------- 1 | // The API isBadVersion is defined for you. 2 | // bool isBadVersion(int version); 3 | 4 | class Solution { 5 | public: 6 | int firstBadVersion(int n) { 7 | int l = 0; 8 | int r = n; 9 | 10 | while(l < r) { 11 | int mid = l + (r - l) / 2; 12 | if(isBadVersion(mid)) { 13 | r = mid; 14 | } 15 | else { 16 | l = mid + 1; 17 | } 18 | } 19 | 20 | return l; 21 | } 22 | }; -------------------------------------------------------------------------------- /278-first-bad-version/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /28-implement-strstr/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /280-wiggle-sort/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /282-expression-add-operators/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /286-walls-and-gates/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /290-word-pattern/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /295-find-median-from-data-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> divideArray(vector& nums, int k) { 4 | vector> ans; 5 | sort(nums.begin(), nums.end()); 6 | for(int i = 2; i < nums.size(); i += 3){ 7 | if(nums[i] - nums[i - 2] > k) return {}; 8 | ans.push_back({nums[i-2], nums[i-1], nums[i]}); 9 | } 10 | return ans; 11 | } 12 | }; -------------------------------------------------------------------------------- /2966-divide-array-into-arrays-with-max-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /297-serialize-and-deserialize-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /298-binary-tree-longest-consecutive-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /30-substring-with-concatenation-of-all-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/300-longest-increasing-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLIS(vector& nums) { 4 | vector dp; 5 | 6 | for(int num : nums) { 7 | auto it = lower_bound(dp.begin(), dp.end(), num); 8 | if(it == dp.end()) { 9 | dp.push_back(num); 10 | } 11 | else { 12 | *it = num; 13 | } 14 | } 15 | 16 | return dp.size(); 17 | } 18 | }; -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /301-remove-invalid-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /303-range-sum-query-immutable/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /304-range-sum-query-2d-immutable/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /307-range-sum-query-mutable/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /31-next-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /315-count-of-smaller-numbers-after-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /317-shortest-distance-from-all-buildings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /322-coin-change/322-coin-change.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int coinChange(vector& coins, int amount) { 4 | vector dp(amount+1, amount+1); 5 | 6 | dp[0] = 0; 7 | 8 | for(int i = 0; i <= amount; i ++) { 9 | for(int coin : coins) { 10 | int need = i - coin; 11 | if(need >= 0) 12 | dp[i] = min(dp[i], dp[need] + 1); 13 | } 14 | } 15 | 16 | return dp[amount] > amount ? -1 : dp[amount]; 17 | } 18 | }; -------------------------------------------------------------------------------- /322-coin-change/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /323-number-of-connected-components-in-an-undirected-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /326-power-of-three/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /33-search-in-rotated-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /339-nested-list-weight-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /340-longest-substring-with-at-most-k-distinct-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /341-flatten-nested-list-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /342-power-of-four/342-power-of-four.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfFour(int n) { 4 | if(n <= 0) 5 | return false; 6 | 7 | while(n > 1) { 8 | if(n % 4) 9 | return false; 10 | n = n / 4; 11 | } 12 | 13 | return true; 14 | } 15 | }; -------------------------------------------------------------------------------- /342-power-of-four/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /344-reverse-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3447-clear-digits/3447-clear-digits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string clearDigits(string s) { 4 | int i = 0; 5 | int j = 0; 6 | int n = s.size(); 7 | 8 | for(int i = 0; i < n; i ++) { 9 | char c = s[i]; 10 | if(isdigit(c)) { 11 | j --; 12 | } 13 | else { 14 | s[j] = s[i]; 15 | j ++; 16 | } 17 | } 18 | 19 | return s.substr(0, j); 20 | } 21 | }; -------------------------------------------------------------------------------- /346-moving-average-from-data-stream/346-moving-average-from-data-stream.cpp: -------------------------------------------------------------------------------- 1 | class MovingAverage { 2 | public: 3 | int windowSize = 0; 4 | int curSum = 0; 5 | deque deq; 6 | 7 | MovingAverage(int size) { 8 | windowSize = size; 9 | } 10 | 11 | double next(int val) { 12 | if(deq.size() == windowSize) { 13 | curSum -= deq.front(); 14 | deq.pop_front(); 15 | } 16 | 17 | curSum += val; 18 | deq.push_back(val); 19 | 20 | return (double)curSum / deq.size(); 21 | } 22 | }; 23 | 24 | /** 25 | * Your MovingAverage object will be instantiated and called as such: 26 | * MovingAverage* obj = new MovingAverage(size); 27 | * double param_1 = obj->next(val); 28 | */ -------------------------------------------------------------------------------- /346-moving-average-from-data-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /347-top-k-frequent-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3483-alternating-groups-ii/3483-alternating-groups-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfAlternatingGroups(vector& colors, int k) { 4 | int n = colors.size(); 5 | int end = n + k - 1;; 6 | int l = 0; 7 | int r = 1; 8 | int res = 0; 9 | 10 | while(r < end) { 11 | if(colors[r % n] == colors[(r - 1) % n]) { 12 | l = r; 13 | } 14 | else if(r - l + 1 == k) { 15 | res ++; 16 | l ++; 17 | } 18 | 19 | r ++; 20 | } 21 | 22 | return res; 23 | } 24 | }; -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/349-intersection-of-two-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector intersection(vector& nums1, vector& nums2) { 4 | unordered_set set1; 5 | 6 | for(int num : nums1) { 7 | set1.insert(num); 8 | } 9 | 10 | unordered_set set2; 11 | for(int num : nums2) { 12 | if(set1.count(num)) { 13 | set2.insert(num); 14 | } 15 | } 16 | 17 | return vector(set2.begin(), set2.end()); 18 | } 19 | }; -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /353-design-snake-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /355-design-twitter/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /363-max-sum-of-rectangle-no-larger-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /367-valid-perfect-square/367-valid-perfect-square.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool tooBig(int num, int target) { 4 | return num >= target / num; 5 | } 6 | 7 | bool isPerfectSquare(int num) { 8 | int l = 1; 9 | int r = num / 2; 10 | 11 | while(l < r) { 12 | int mid = l + (r - l) / 2; 13 | if(tooBig(mid, num)) { 14 | r = mid; 15 | } 16 | else { 17 | l = mid + 1; 18 | } 19 | } 20 | 21 | cout << l << endl; 22 | return l == (double)num / l; 23 | } 24 | }; -------------------------------------------------------------------------------- /367-valid-perfect-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /370-range-addition/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& nums) { 4 | int up = 1; 5 | int down = 1; 6 | int n = nums.size(); 7 | 8 | for(int i = 1; i < n; i ++) { 9 | if(nums[i] > nums[i-1]) { 10 | up = down + 1; 11 | } 12 | if(nums[i] < nums[i-1]) { 13 | down = up + 1; 14 | } 15 | } 16 | 17 | return max(up, down); 18 | } 19 | }; 20 | 21 | // 1,17,5,10,13,15,10,5,16,8 22 | // o 23 | 24 | // up: 6 25 | // down: 7 -------------------------------------------------------------------------------- /376-wiggle-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int combinationSum4(vector& nums, int target) { 4 | vector dp(target+1, 0); 5 | dp[0] = 1; 6 | 7 | for(int i = 1; i <= target; i ++) { 8 | for(int num : nums) { 9 | int need = i - num; 10 | if(need >= 0) { 11 | dp[i] += dp[need]; 12 | } 13 | } 14 | } 15 | 16 | return dp[target]; 17 | } 18 | }; 19 | 20 | // 1 0 0 0 0 21 | 22 | // 1: 1 1 1 1 1 23 | // 2: 1 1 2 2 3 24 | // 3: 1 1 2 3 4 25 | 26 | // 1, 1, 1 27 | // 1, 2 28 | // 3 29 | 30 | // 1 1 2 4 7 -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /378-kth-smallest-element-in-a-sorted-matrix/378-kth-smallest-element-in-a-sorted-matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int kthSmallest(vector>& matrix, int k) { 4 | priority_queue pq; 5 | int row = matrix.size(); 6 | int col = matrix[0].size(); 7 | 8 | for(int i = 0; i < row; i ++) { 9 | for(int j = 0; j < col; j ++) { 10 | pq.push(matrix[i][j]); 11 | if(pq.size() > k) 12 | pq.pop(); 13 | } 14 | } 15 | 16 | return pq.top(); 17 | } 18 | }; -------------------------------------------------------------------------------- /378-kth-smallest-element-in-a-sorted-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /380-insert-delete-getrandom-o1/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /381-insert-delete-getrandom-o1-duplicates-allowed/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /382-linked-list-random-node/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /383-ransom-note/383-ransom-note.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canConstruct(string ransomNote, string magazine) { 4 | unordered_map m; 5 | 6 | for(char c : magazine) { 7 | m[c] ++; 8 | } 9 | 10 | for(char c : ransomNote) { 11 | if(-- m[c] < 0) { 12 | return false; 13 | } 14 | } 15 | 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /383-ransom-note/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /39-combination-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /393-utf-8-validation/393-utf-8-validation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool validUtf8(vector& data) { 4 | int count = 0; 5 | for (auto c : data) { 6 | if (count == 0) { 7 | if ((c >> 5) == 0b110) count = 1; 8 | else if ((c >> 4) == 0b1110) count = 2; 9 | else if ((c >> 3) == 0b11110) count = 3; 10 | else if ((c >> 7)) return false; 11 | } else { 12 | if ((c >> 6) != 0b10) return false; 13 | count--; 14 | } 15 | } 16 | return count == 0; 17 | } 18 | }; -------------------------------------------------------------------------------- /393-utf-8-validation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /394-decode-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /399-evaluate-division/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /4-median-of-two-sorted-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /403-frog-jump/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /408-valid-word-abbreviation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/416-partition-equal-subset-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canPartition(vector& nums) { 4 | int sum = 0; 5 | for(int num : nums) { 6 | sum += num; 7 | } 8 | 9 | if(sum % 2) { 10 | return false; 11 | } 12 | 13 | int n = nums.size(); 14 | int target = sum / 2; 15 | 16 | vector dp(target + 1, false); 17 | dp[0] = true; 18 | 19 | for(int num : nums) { 20 | for(int i = target; i >= 0; i --) { 21 | int need = i - num; 22 | if(need < 0) 23 | continue; 24 | dp[i] = dp[i] || dp[need]; 25 | } 26 | } 27 | 28 | return dp[target]; 29 | } 30 | 31 | }; -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /42-trapping-rain-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /424-longest-repeating-character-replacement/424-longest-repeating-character-replacement.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int characterReplacement(string s, int k) { 4 | int l = 0; 5 | int r = 0; 6 | int n = s.size(); 7 | int maxx = 0; 8 | unordered_map count; 9 | int ans = 0; 10 | 11 | while(r < n) { 12 | char c = s[r]; 13 | maxx = max(maxx, ++count[c]); 14 | if(r - l + 1 - maxx > k) { 15 | maxx = max(maxx, -- count[s[l]]); 16 | l ++; 17 | } 18 | 19 | ans = max(ans, r - l + 1); 20 | 21 | r ++; 22 | } 23 | 24 | return ans; 25 | } 26 | }; -------------------------------------------------------------------------------- /424-longest-repeating-character-replacement/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /429-n-ary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /430-flatten-a-multilevel-doubly-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /437-path-sum-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /438-find-all-anagrams-in-a-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /44-wildcard-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /441-arranging-coins/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /444-sequence-reconstruction/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /445-add-two-numbers-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /447-number-of-boomerangs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int jump(vector& nums) { 4 | int jumps = 0; 5 | int curReach = 0; 6 | int maxReach = 0; 7 | int n = nums.size(); 8 | 9 | for(int i = 0; i < n; i ++) { 10 | maxReach = max(maxReach, i + nums[i]); 11 | 12 | if(i == curReach && i != n-1) { 13 | jumps ++; 14 | curReach = maxReach; 15 | maxReach = 0; 16 | } 17 | } 18 | 19 | return jumps; 20 | } 21 | }; -------------------------------------------------------------------------------- /45-jump-game-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /451-sort-characters-by-frequency/451-sort-characters-by-frequency.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string frequencySort(string s) { 4 | unordered_map count; 5 | 6 | for(char c : s) { 7 | count[c] ++; 8 | } 9 | 10 | int n = s.size(); 11 | unordered_map> bucket; 12 | for(auto entry : count) { 13 | bucket[entry.second].push_back(entry.first); 14 | } 15 | 16 | string ans = ""; 17 | for(int i = n; i >= 0; i --) { 18 | int freq = i; 19 | auto& toappend = bucket[i]; 20 | for(auto c : toappend) { 21 | ans.append(freq, c); 22 | } 23 | } 24 | 25 | return ans; 26 | } 27 | }; -------------------------------------------------------------------------------- /452-minimum-number-of-arrows-to-burst-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /457-circular-array-loop/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 | int pigs = 0; 5 | while (pow(minutesToTest / minutesToDie + 1, pigs) < buckets) { 6 | pigs += 1; 7 | } 8 | return pigs; 9 | } 10 | }; -------------------------------------------------------------------------------- /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 | sort(nums.begin(), nums.end()); 5 | int ans = 0; 6 | 7 | for(int i = 0; i < nums.size(); i ++) { 8 | ans += abs(nums[i] - nums[nums.size() / 2]); 9 | } 10 | 11 | return ans; 12 | } 13 | }; -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /463-island-perimeter/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /47-permutations-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /472-concatenated-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /473-matchsticks-to-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector>& matrix) { 4 | reverse(matrix.begin(), matrix.end()); 5 | int n = matrix.size(); 6 | 7 | for(int i = 0; i < n; i ++) { 8 | for(int j = 0; j < n; j ++) { 9 | if(j < i) { 10 | swap(matrix[i][j], matrix[j][i]); 11 | } 12 | } 13 | } 14 | } 15 | }; -------------------------------------------------------------------------------- /48-rotate-image/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /489-robot-room-cleaner/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /490-the-maze/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /494-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /496-next-greater-element-i/496-next-greater-element-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector nextGreaterElement(vector& nums1, vector& nums2) { 4 | stack stk; 5 | unordered_map map; 6 | 7 | for(int num : nums2) { 8 | while(!stk.empty() && num > stk.top()) { 9 | map[stk.top()] = num; 10 | stk.pop(); 11 | } 12 | stk.push(num); 13 | } 14 | 15 | vector res; 16 | for(int num : nums1) { 17 | if(map.count(num) == 0) { 18 | res.push_back(-1); 19 | continue; 20 | } 21 | res.push_back(map[num]); 22 | } 23 | 24 | return res; 25 | } 26 | }; -------------------------------------------------------------------------------- /496-next-greater-element-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /498-diagonal-traverse/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /499-the-maze-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /505-the-maze-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fib(int n) { 4 | int prevOne = 1; 5 | int prevTwo = 0; 6 | 7 | if(n <= 1) { 8 | return n; 9 | } 10 | 11 | for(int i = 2; i <= n; i ++) { 12 | int temp = prevOne + prevTwo; 13 | prevTwo = prevOne; 14 | prevOne = temp; 15 | } 16 | 17 | return prevOne; 18 | } 19 | }; -------------------------------------------------------------------------------- /509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /51-n-queens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /518-coin-change-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /52-n-queens-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /523-continuous-subarray-sum/523-continuous-subarray-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkSubarraySum(vector& nums, int k) { 4 | int sum = 0; 5 | unordered_map prevSum; 6 | int n = nums.size(); 7 | 8 | prevSum[0] = -1; 9 | for(int i = 0; i < n; i ++) { 10 | int num = nums[i]; 11 | sum += num; 12 | sum = sum % k; 13 | 14 | if(prevSum.count(sum)) { 15 | if(i - prevSum[sum] > 1) { 16 | return true; 17 | } 18 | } 19 | else { 20 | prevSum[sum] = i; 21 | } 22 | } 23 | 24 | return false; 25 | } 26 | }; -------------------------------------------------------------------------------- /523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /528-random-pick-with-weight/528-random-pick-with-weight.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sum = 0; 4 | vector prefix; 5 | 6 | Solution(vector& w) { 7 | prefix.push_back(0); 8 | for(int i = 1; i <= w.size(); i ++) { 9 | prefix.push_back(prefix[i-1] + w[i-1]); 10 | sum += w[i-1]; 11 | } 12 | } 13 | 14 | int pickIndex() { 15 | int pick = rand() % sum; 16 | auto it = upper_bound(prefix.begin(), prefix.end(), pick); 17 | return it - prefix.begin() - 1; 18 | } 19 | }; 20 | 21 | /** 22 | * Your Solution object will be instantiated and called as such: 23 | * Solution* obj = new Solution(w); 24 | * int param_1 = obj->pickIndex(); 25 | */ -------------------------------------------------------------------------------- /528-random-pick-with-weight/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/53-maximum-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& nums) { 4 | int curSum = 0; 5 | int globalSum = nums[0]; 6 | 7 | for(int num : nums) { 8 | if(curSum < 0) { 9 | curSum = 0; 10 | } 11 | 12 | curSum += num; 13 | globalSum = max(globalSum, curSum); 14 | } 15 | 16 | return globalSum; 17 | } 18 | }; -------------------------------------------------------------------------------- /53-maximum-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /535-encode-and-decode-tinyurl/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /536-construct-binary-tree-from-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /538-convert-bst-to-greater-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /55-jump-game/55-jump-game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canJump(vector& nums) { 4 | int reach = 0; 5 | int n = nums.size(); 6 | 7 | for(int i = 0; i < n; i ++) { 8 | if(i > reach) 9 | return false; 10 | reach = max(reach, i + nums[i]); 11 | } 12 | 13 | return true; 14 | } 15 | }; -------------------------------------------------------------------------------- /55-jump-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /554-brick-wall/554-brick-wall.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int leastBricks(vector>& wall) { 4 | unordered_map splits; 5 | int maxSplits = 0; 6 | 7 | for(auto& w : wall) { 8 | int sum = 0; 9 | int n = w.size(); 10 | for(int i = 0; i < n-1; i ++) { 11 | sum += w[i]; 12 | splits[sum] ++; 13 | maxSplits = max(maxSplits, splits[sum]); 14 | } 15 | } 16 | 17 | return wall.size() - maxSplits; 18 | } 19 | }; -------------------------------------------------------------------------------- /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 n = s.size(); 5 | int i = 0, j = 0; 6 | 7 | while(j < n) { 8 | if(s[j] == ' ') { 9 | reverse(s.begin() + i, s.begin() + j); 10 | i = j+1; 11 | } 12 | if(j == n-1) { 13 | reverse(s.begin() + i, s.end()); 14 | } 15 | j ++; 16 | } 17 | 18 | return s; 19 | } 20 | }; -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /56-merge-intervals/56-merge-intervals.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> merge(vector>& intervals) { 4 | vector> res; 5 | int n = intervals.size(); 6 | 7 | if(n == 0) 8 | return {}; 9 | 10 | sort(intervals.begin(), intervals.end()); 11 | 12 | res.push_back(intervals[0]); 13 | for(int i = 1; i < n; i ++) { 14 | auto& inter = intervals[i]; 15 | 16 | if(inter[0] > res.back()[1]) { 17 | res.push_back(inter); 18 | } 19 | else { 20 | res.back()[1] = max(res.back()[1], inter[1]); 21 | } 22 | } 23 | 24 | 25 | return res; 26 | } 27 | }; -------------------------------------------------------------------------------- /56-merge-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /560-subarray-sum-equals-k/560-subarray-sum-equals-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int subarraySum(vector& nums, int k) { 4 | unordered_map seen; 5 | seen[0] = 1; 6 | int curSum = 0; 7 | int count = 0; 8 | 9 | for(int num : nums) { 10 | curSum += num; 11 | count += seen[curSum - k]; 12 | seen[curSum] ++; 13 | } 14 | 15 | return count; 16 | } 17 | }; -------------------------------------------------------------------------------- /560-subarray-sum-equals-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /57-insert-interval/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /572-subtree-of-another-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /576-out-of-boundary-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /581-shortest-unsorted-continuous-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /583-delete-operation-for-two-strings/583-delete-operation-for-two-strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minDistance(string text1, string text2) { 4 | int n = text1.size(); 5 | int m = text2.size(); 6 | vector> dp(n+1, vector(m+1)); 7 | 8 | for(int i = 1; i <= n; i ++) { 9 | for(int j = 1; j <= m; j ++) { 10 | if(text1[i-1] == text2[j-1]) { 11 | dp[i][j] = dp[i-1][j-1] + 1; 12 | } 13 | else { 14 | dp[i][j] = max(dp[i][j-1], dp[i-1][j]); 15 | } 16 | } 17 | } 18 | 19 | int size = dp[n][m]; 20 | 21 | return n+m-2*size; 22 | } 23 | }; -------------------------------------------------------------------------------- /583-delete-operation-for-two-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /588-design-in-memory-file-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /59-spiral-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /61-rotate-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/62-unique-paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | vector dp(n, 1); 5 | 6 | for(int i = 1; i < m; i ++) { 7 | for(int j = 0; j < n; j ++) { 8 | if(j == 0) { 9 | dp[j] = 1; 10 | continue; 11 | } 12 | dp[j] = dp[j-1] + dp[j]; 13 | } 14 | } 15 | 16 | return dp[n-1]; 17 | } 18 | }; -------------------------------------------------------------------------------- /62-unique-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /622-design-circular-queue/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /623-add-one-row-to-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /629-k-inverse-pairs-array/629-k-inverse-pairs-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int kInversePairs(int n, int k) { 4 | vector dp(k+1, 0); 5 | int mod = 1e9+7; 6 | for(int i=1; i<=n; i++){ 7 | vector tmp(k+1, 0); 8 | tmp[0] = 1; 9 | for(int j =1; j<=k; j++){ 10 | long long val = (dp[j] + mod - ((j-i) >=0 ? dp[j-i] : 0))%mod; 11 | tmp[j] = (tmp[j-1] + val)%mod; 12 | } 13 | dp = tmp; 14 | } 15 | return (dp[k] + mod - (k>0 ? dp[k-1] : 0))%mod; 16 | } 17 | }; -------------------------------------------------------------------------------- /629-k-inverse-pairs-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /63-unique-paths-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /630-course-schedule-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /631-design-excel-sum-formula/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /633-sum-of-square-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /637-average-of-levels-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /642-design-search-autocomplete-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /646-maximum-length-of-pair-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /647-palindromic-substrings/647-palindromic-substrings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int n; 4 | int countSubstrings(string s) { 5 | n = s.size(); 6 | int res = 0; 7 | 8 | for(int i = 0; i < n ; i ++) { 9 | res += count(s, i, i); 10 | res += count(s, i, i+1); 11 | } 12 | 13 | return res; 14 | } 15 | 16 | int count(string s, int start, int end) { 17 | int res = 0; 18 | 19 | while(start >= 0 && end < n) { 20 | if(s[start] != s[end]) 21 | break; 22 | 23 | res ++; 24 | 25 | start --; 26 | end ++; 27 | } 28 | 29 | return res; 30 | } 31 | }; -------------------------------------------------------------------------------- /647-palindromic-substrings/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 n = arr.size(); 5 | int l = 0; 6 | int r = n - k; 7 | 8 | while(l < r) { 9 | int mid = l + (r - l) / 2; 10 | int val = arr[mid]; 11 | int next = arr[mid + k]; 12 | 13 | if(next - x < x - val) { 14 | l = mid + 1; 15 | } 16 | else { 17 | r = mid; 18 | } 19 | } 20 | 21 | return vector(arr.begin() + l, arr.begin() + l + k); 22 | } 23 | }; -------------------------------------------------------------------------------- /658-find-k-closest-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /665-non-decreasing-array/665-non-decreasing-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPossibility(vector& nums) { 4 | int wrong = 0; 5 | int n = nums.size(); 6 | 7 | for(int i = 1; i < n; i ++) { 8 | if(nums[i] < nums[i-1]) { 9 | if(wrong) { 10 | return false; 11 | } 12 | 13 | wrong ++; 14 | if(i > 1 && nums[i] < nums[i-2]) { 15 | nums[i] = nums[i-1]; 16 | } 17 | else { 18 | nums[i-1] = nums[i]; 19 | } 20 | } 21 | } 22 | 23 | return wrong <= 1; 24 | } 25 | }; -------------------------------------------------------------------------------- /665-non-decreasing-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /669-trim-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /678-valid-parenthesis-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /68-text-justification/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /680-valid-palindrome-ii/680-valid-palindrome-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPal(string s, int l, int r) { 4 | while(l < r) { 5 | if(s[l] != s[r]) 6 | return false; 7 | l ++; 8 | r --; 9 | } 10 | return true; 11 | } 12 | 13 | bool validPalindrome(string s) { 14 | int l = 0; 15 | int r = s.size() - 1; 16 | 17 | while(l < r) { 18 | if(s[l] != s[r]) { 19 | return isPal(s, l+1, r) || isPal(s, l, r-1); 20 | } 21 | 22 | l ++; 23 | r --; 24 | } 25 | 26 | return true; 27 | } 28 | }; -------------------------------------------------------------------------------- /680-valid-palindrome-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /682-baseball-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /692-top-k-frequent-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /694-number-of-distinct-islands/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /695-max-area-of-island/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /700-search-in-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /701-insert-into-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /703-kth-largest-element-in-a-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /708-insert-into-a-sorted-circular-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /71-simplify-path/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /710-random-pick-with-blacklist/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /715-range-module/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /716-max-stack/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /720-longest-word-in-dictionary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /723-candy-crush/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /724-find-pivot-index/724-find-pivot-index.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int pivotIndex(vector& nums) { 4 | int n = nums.size(); 5 | vector prefix(n+1, 0); 6 | 7 | for(int i = 1; i <= n; i ++) { 8 | prefix[i] = prefix[i-1] + nums[i-1]; 9 | } 10 | 11 | for(int i = 0; i < n; i ++) { 12 | if(prefix[n] - prefix[i+1] == prefix[i] - prefix[0]) 13 | return i; 14 | } 15 | 16 | return -1; 17 | } 18 | }; 19 | 20 | // 1 7 3 6 5 6 21 | // 0 1 8 11 17 22 28 22 | // 0 1 2 3 4 -------------------------------------------------------------------------------- /724-find-pivot-index/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /726-number-of-atoms/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /729-my-calendar-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /73-set-matrix-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /739-daily-temperatures/739-daily-temperatures.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector dailyTemperatures(vector& temperatures) { 4 | stack stk; 5 | int n = temperatures.size(); 6 | vector res(n, 0); 7 | 8 | for(int i = 0; i < n; i ++) { 9 | int temp = temperatures[i]; 10 | while(!stk.empty() && temp > temperatures[stk.top()]) { 11 | res[stk.top()] = i - stk.top(); 12 | stk.pop(); 13 | } 14 | stk.push(i); 15 | } 16 | 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /739-daily-temperatures/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /741-cherry-pickup/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /743-network-delay-time/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /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 | int n = cost.size(); 5 | 6 | int prevTwo = 0; 7 | int prevOne = 0; 8 | 9 | for(int i = 2; i <= n; i ++) { 10 | int temp = min(prevOne + cost[i-1], prevTwo + cost[i-2]); 11 | prevTwo = prevOne; 12 | prevOne = temp; 13 | } 14 | 15 | return prevOne; 16 | } 17 | }; -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /752-open-the-lock/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /753-cracking-the-safe/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /76-minimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /766-toeplitz-matrix/766-toeplitz-matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isToeplitzMatrix(vector>& matrix) { 4 | int rows = matrix.size(); 5 | int cols = matrix[0].size(); 6 | 7 | for(int i = 1; i < rows; i ++) { 8 | for(int j = 1; j < cols; j ++) { 9 | if(matrix[i][j] != matrix[i-1][j-1]) { 10 | return false; 11 | } 12 | } 13 | } 14 | 15 | return true; 16 | } 17 | }; 18 | 19 | // 1 2 3 4 20 | // 1 1 2 3 -------------------------------------------------------------------------------- /766-toeplitz-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /767-reorganize-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /78-subsets/78-subsets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void backtrack(vector>& res, vector& temp, vector& nums, int cur) { 4 | res.push_back(temp); 5 | if(cur == nums.size()) { 6 | return; 7 | } 8 | 9 | for(int i = cur; i < nums.size(); i ++) { 10 | temp.push_back(nums[i]); 11 | backtrack(res, temp, nums, i+1); 12 | temp.pop_back(); 13 | } 14 | } 15 | 16 | vector> subsets(vector& nums) { 17 | vector temp; 18 | vector> res; 19 | backtrack(res, temp, nums, 0); 20 | return res; 21 | } 22 | }; -------------------------------------------------------------------------------- /78-subsets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /780-reaching-points/780-reaching-points.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool reachingPoints(int sx, int sy, int tx, int ty) { 4 | if(sx > tx || sy > ty) 5 | return false; 6 | 7 | while(tx > sx && ty > sy) { 8 | if(tx > ty) { 9 | tx = tx % ty; 10 | } 11 | else { 12 | ty = ty % tx; 13 | } 14 | } 15 | 16 | if(tx != sx && ty != sy) { 17 | return false; 18 | } 19 | 20 | if(tx == sx) { 21 | int diff = ty - sy; 22 | return diff % tx == 0; 23 | } 24 | 25 | int diff = tx - sx; 26 | return diff % ty == 0; 27 | } 28 | }; -------------------------------------------------------------------------------- /780-reaching-points/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /785-is-graph-bipartite/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /787-cheapest-flights-within-k-stops/787-cheapest-flights-within-k-stops.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findCheapestPrice(int n, vector>& flights, int src, int dst, int k) { 4 | vector dist(n, INT_MAX); 5 | dist[src] = 0; 6 | 7 | for(int i = 0; i <= k; i ++) { 8 | vector temp = dist; 9 | for(auto& f : flights) { 10 | if(dist[f[0]] != INT_MAX && dist[f[0]] + f[2] < temp[f[1]]) { 11 | temp[f[1]] = dist[f[0]] + f[2]; 12 | } 13 | } 14 | swap(temp, dist); 15 | } 16 | 17 | return dist[dst] == INT_MAX ? -1 : dist[dst]; 18 | } 19 | }; -------------------------------------------------------------------------------- /787-cheapest-flights-within-k-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /79-word-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /791-custom-sort-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /794-valid-tic-tac-toe-state/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /797-all-paths-from-source-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /811-subdomain-visit-count/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /815-bus-routes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /82-remove-duplicates-from-sorted-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /820-short-encoding-of-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /821-shortest-distance-to-a-character/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /823-binary-trees-with-factors/823-binary-trees-with-factors.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numFactoredBinaryTrees(vector& A) { 4 | long res = 0, mod = pow(10, 9) + 7; 5 | sort(A.begin(), A.end()); 6 | unordered_map dp; 7 | for (int i = 0; i < A.size(); ++i) { 8 | dp[A[i]] = 1; 9 | for (int j = 0; j < i; ++j) 10 | if (A[i] % A[j] == 0) 11 | dp[A[i]] = (dp[A[i]] + dp[A[j]] * dp[A[i] / A[j]]) % mod; 12 | res = (res + dp[A[i]]) % mod; 13 | } 14 | return res; 15 | } 16 | }; -------------------------------------------------------------------------------- /823-binary-trees-with-factors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /827-making-a-large-island/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /834-sum-of-distances-in-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /84-largest-rectangle-in-histogram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /844-backspace-string-compare/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /847-shortest-path-visiting-all-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /85-maximal-rectangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /855-exam-room/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /858-mirror-reflection/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /86-partition-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /862-shortest-subarray-with-sum-at-least-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /863-all-nodes-distance-k-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /867-transpose-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/871-minimum-number-of-refueling-stops.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minRefuelStops(int target, int cur, vector> s) { 4 | int i = 0, res; 5 | priority_queuepq; 6 | for (res = 0; cur < target; res++) { 7 | while (i < s.size() && s[i][0] <= cur) 8 | pq.push(s[i++][1]); 9 | if (pq.empty()) return -1; 10 | cur += pq.top(), pq.pop(); 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /88-merge-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /882-reachable-nodes-in-subdivided-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /886-possible-bipartition/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /890-find-and-replace-pattern/890-find-and-replace-pattern.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findAndReplacePattern(vector words, string p) { 4 | vector res; 5 | for (string w : words) if (F(w) == F(p)) res.push_back(w); 6 | return res; 7 | } 8 | 9 | string F(string w) { 10 | unordered_map m; 11 | for (char c : w) if (!m.count(c)) m[c] = m.size(); 12 | for (int i = 0; i < w.length(); ++i) w[i] = 'a' + m[w[i]]; 13 | return w; 14 | } 15 | }; -------------------------------------------------------------------------------- /890-find-and-replace-pattern/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /894-all-possible-full-binary-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /895-maximum-frequency-stack/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /897-increasing-order-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /901-online-stock-span/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /909-snakes-and-ladders/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/91-decode-ways.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numDecodings(string s) { 4 | int n = s.size(); 5 | vector dp(n+1); 6 | 7 | dp[0] = 1; 8 | dp[1] = s[0] == '0' ? 0 : 1; 9 | 10 | for(int i = 2; i <= n; i ++) { 11 | int prevOne = stoi(s.substr(i-1, 1)); 12 | int prevTwo = stoi(s.substr(i-2, 2)); 13 | 14 | if(prevOne > 0 && prevOne <= 9) { 15 | dp[i] += dp[i-1]; 16 | } 17 | if(prevTwo >= 10 && prevTwo <= 26) { 18 | dp[i] += dp[i-2]; 19 | } 20 | } 21 | 22 | return dp[n]; 23 | } 24 | }; 25 | 26 | // 0 27 | 28 | // 226 -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /916-word-subsets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /93-restore-ip-addresses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /934-shortest-bridge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /935-knight-dialer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /938-range-sum-of-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /939-minimum-area-rectangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /941-valid-mountain-array/941-valid-mountain-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool validMountainArray(vector& arr) { 4 | int n = arr.size(); 5 | int l = 0; 6 | int r = n-1; 7 | 8 | while(l < n-1 && arr[l] < arr[l+1]) { 9 | l ++; 10 | } 11 | 12 | while(r > 0 && arr[r] < arr[r-1]) { 13 | r --; 14 | } 15 | 16 | return l > 0 && r < n-1 && l == r; 17 | } 18 | }; -------------------------------------------------------------------------------- /941-valid-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /947-most-stones-removed-with-same-row-or-column/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /953-verifying-an-alien-dictionary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /954-array-of-doubled-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /967-numbers-with-same-consecutive-differences/967-numbers-with-same-consecutive-differences.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int n ,k; 4 | vectora; 5 | void f(int sz,int val, int prev_digit){ 6 | if(sz==n){ 7 | a.push_back(val); 8 | return; 9 | } 10 | for(int i=0;i<=9;i++){ 11 | if(abs(i-prev_digit)==k){ 12 | f(sz+1,val*10+i,i); 13 | } 14 | } 15 | } 16 | vector numsSameConsecDiff(int n, int k) { 17 | this->n=n;this->k=k; 18 | for(int i=1;i<=9;i++){ 19 | f(1,i,i); 20 | } 21 | return a; 22 | } 23 | }; -------------------------------------------------------------------------------- /967-numbers-with-same-consecutive-differences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /968-binary-tree-cameras/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /97-interleaving-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /973-k-closest-points-to-origin/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /981-time-based-key-value-store/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /985-sum-of-even-numbers-after-queries/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /986-interval-list-intersections/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 | ​ -------------------------------------------------------------------------------- /991-broken-calculator/991-broken-calculator.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int brokenCalc(int startValue, int target) { 4 | int steps = 0; 5 | while(target > startValue) { 6 | if(target % 2) { 7 | target ++; 8 | } 9 | else { 10 | target /= 2; 11 | } 12 | steps ++; 13 | } 14 | return steps + startValue - target; 15 | } 16 | }; -------------------------------------------------------------------------------- /decode-ways/decode-ways.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numDecodings(string s) { 4 | int n = s.size(); 5 | 6 | int two = 1; 7 | int one = s[0] == '0' ? 0 : 1; 8 | 9 | for(int i = 2; i <= n; i ++) { 10 | int oneDigit = stoi(s.substr(i-1, 1)); 11 | int twoDigit = stoi(s.substr(i-2, 2)); 12 | int dp = 0; 13 | 14 | if(oneDigit >= 1 && oneDigit <= 9) { 15 | dp += one; 16 | } 17 | if(twoDigit >= 10 && twoDigit <= 26) { 18 | dp += two; 19 | } 20 | 21 | two = one; 22 | one = dp; 23 | } 24 | 25 | return one; 26 | } 27 | }; -------------------------------------------------------------------------------- /find-the-town-judge/find-the-town-judge.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findJudge(int n, vector>& trust) { 4 | unordered_map s; 5 | 6 | if(n == 1) 7 | return 1; 8 | 9 | for(auto t : trust) { 10 | s[t[0]] --; 11 | s[t[1]] ++; 12 | } 13 | 14 | for(auto entry : s) { 15 | if(entry.second == n-1) { 16 | return entry.first; 17 | } 18 | } 19 | 20 | return -1; 21 | } 22 | }; --------------------------------------------------------------------------------