├── 15-3sum └── NOTES.md ├── 18-4sum └── NOTES.md ├── 69-sqrtx ├── NOTES.md └── 69-sqrtx.java ├── 1-two-sum ├── NOTES.md └── 1-two-sum.java ├── 100-same-tree └── NOTES.md ├── 112-path-sum ├── NOTES.md └── 112-path-sum.java ├── 120-triangle ├── NOTES.md └── 120-triangle.java ├── 135-candy ├── NOTES.md └── 135-candy.java ├── 146-lru-cache └── NOTES.md ├── 148-sort-list └── NOTES.md ├── 372-super-pow ├── NOTES.md └── 372-super-pow.java ├── 400-nth-digit ├── NOTES.md ├── 400-nth-digit.java └── README.md ├── 412-fizz-buzz ├── NOTES.md └── 412-fizz-buzz.java ├── 50-powx-n ├── NOTES.md └── 50-powx-n.java ├── 51-n-queens └── NOTES.md ├── 542-01-matrix └── NOTES.md ├── 55-jump-game ├── NOTES.md ├── solution2.java ├── 55-jump-game.java └── solution1.java ├── 66-plus-one ├── NOTES.md └── 66-plus-one.java ├── 67-add-binary ├── NOTES.md └── README.md ├── 78-subsets ├── NOTES.md └── 78-subsets.java ├── 89-gray-code ├── NOTES.md └── 89-gray-code.java ├── 90-subsets-ii ├── NOTES.md ├── README.md └── 90-subsets-ii.java ├── 101-symmetric-tree └── NOTES.md ├── 1094-car-pooling └── NOTES.md ├── 113-path-sum-ii └── NOTES.md ├── 127-word-ladder └── NOTES.md ├── 133-clone-graph └── NOTES.md ├── 134-gas-station ├── NOTES.md └── 134-gas-station.java ├── 1340-jump-game-v └── NOTES.md ├── 1345-jump-game-iv └── NOTES.md ├── 139-word-break ├── NOTES.md └── 139-word-break.java ├── 16-3sum-closest ├── NOTES.md └── 16-3sum-closest.java ├── 1696-jump-game-vi └── NOTES.md ├── 179-largest-number ├── NOTES.md └── README.md ├── 1871-jump-game-vii ├── NOTES.md └── 1871-jump-game-vii.java ├── 189-rotate-array ├── NOTES.md └── 189-rotate-array.java ├── 190-reverse-bits ├── NOTES.md └── 190-reverse-bits.java ├── 198-house-robber ├── NOTES.md └── 198-house-robber.java ├── 2-add-two-numbers └── NOTES.md ├── 202-happy-number ├── NOTES.md └── 202-happy-number.java ├── 204-count-primes ├── NOTES.md ├── 204-count-primes.java └── README.md ├── 221-maximal-square └── NOTES.md ├── 231-power-of-two ├── NOTES.md └── 231-power-of-two.java ├── 258-add-digits ├── NOTES.md └── 258-add-digits.java ├── 263-ugly-number ├── NOTES.md └── 263-ugly-number.java ├── 264-ugly-number-ii ├── NOTES.md └── 264-ugly-number-ii.java ├── 268-missing-number ├── NOTES.md └── 268-missing-number.java ├── 27-remove-element ├── NOTES.md └── 27-remove-element.java ├── 312-burst-balloons └── NOTES.md ├── 322-coin-change └── NOTES.md ├── 338-counting-bits ├── NOTES.md ├── solution1.java └── 338-counting-bits.java ├── 343-integer-break ├── NOTES.md ├── 343-integer-break.java └── README.md ├── 344-reverse-string ├── NOTES.md └── 344-reverse-string.java ├── 36-valid-sudoku └── NOTES.md ├── 37-sudoku-solver └── NOTES.md ├── 38-count-and-say └── NOTES.md ├── 392-is-subsequence ├── NOTES.md └── 392-is-subsequence.java ├── 394-decode-string └── NOTES.md ├── 437-path-sum-iii └── NOTES.md ├── 45-jump-game-ii ├── NOTES.md ├── solution2.java ├── 45-jump-game-ii.java └── solution1.java ├── 455-assign-cookies └── NOTES.md ├── 46-permutations └── NOTES.md ├── 47-permutations-ii ├── NOTES.md └── README.md ├── 49-group-anagrams ├── NOTES.md └── 49-group-anagrams.java ├── 493-reverse-pairs ├── NOTES.md └── README.md ├── 494-target-sum └── NOTES.md ├── 518-coin-change-2 └── NOTES.md ├── 52-n-queens-ii └── NOTES.md ├── 529-minesweeper └── NOTES.md ├── 54-spiral-matrix ├── NOTES.md └── 54-spiral-matrix.java ├── 56-merge-intervals └── NOTES.md ├── 57-insert-interval └── NOTES.md ├── 61-rotate-list └── NOTES.md ├── 62-unique-paths ├── NOTES.md └── 62-unique-paths.java ├── 63-unique-paths-ii └── NOTES.md ├── 639-decode-ways-ii └── NOTES.md ├── 7-reverse-integer ├── NOTES.md └── 7-reverse-integer.java ├── 70-climbing-stairs ├── NOTES.md └── 70-climbing-stairs.java ├── 704-binary-search ├── NOTES.md └── 704-binary-search.java ├── 709-to-lower-case ├── NOTES.md └── 709-to-lower-case.java ├── 72-edit-distance └── NOTES.md ├── 729-my-calendar-i ├── NOTES.md └── 729-my-calendar-i.java ├── 75-sort-colors └── NOTES.md ├── 77-combinations ├── NOTES.md └── 77-combinations.java ├── 79-word-search └── NOTES.md ├── 796-rotate-string ├── NOTES.md └── 796-rotate-string.java ├── 835-image-overlap └── NOTES.md ├── 841-keys-and-rooms ├── NOTES.md └── 841-keys-and-rooms.java ├── 86-partition-list └── NOTES.md ├── 87-scramble-string └── NOTES.md ├── 877-stone-game ├── NOTES.md └── 877-stone-game.java ├── 91-decode-ways ├── NOTES.md └── 91-decode-ways.java ├── 912-sort-an-array ├── NOTES.md └── README.md ├── 935-knight-dialer └── NOTES.md ├── 1035-uncrossed-lines └── NOTES.md ├── 119-pascals-triangle-ii ├── NOTES.md └── 119-pascals-triangle-ii.java ├── 12-integer-to-roman ├── NOTES.md └── 12-integer-to-roman.java ├── 125-valid-palindrome ├── NOTES.md └── 125-valid-palindrome.java ├── 1291-sequential-digits ├── NOTES.md └── README.md ├── 13-roman-to-integer └── NOTES.md ├── 130-surrounded-regions └── NOTES.md ├── 1323-maximum-69-number └── NOTES.md ├── 137-single-number-ii └── NOTES.md ├── 141-linked-list-cycle ├── NOTES.md └── 141-linked-list-cycle.java ├── 162-find-peak-element └── NOTES.md ├── 169-majority-element └── NOTES.md ├── 175-combine-two-tables ├── NOTES.md └── 175-combine-two-tables.sql ├── 191-number-of-1-bits ├── NOTES.md └── 191-number-of-1-bits.java ├── 20-valid-parentheses └── NOTES.md ├── 206-reverse-linked-list ├── NOTES.md └── 206-reverse-linked-list.java ├── 207-course-schedule └── NOTES.md ├── 210-course-schedule-ii └── NOTES.md ├── 213-house-robber-ii └── NOTES.md ├── 216-combination-sum-iii ├── NOTES.md └── 216-combination-sum-iii.java ├── 217-contains-duplicate ├── NOTES.md └── 217-contains-duplicate.java ├── 22-generate-parentheses ├── NOTES.md ├── 22-generate-parentheses.java └── README.md ├── 224-basic-calculator └── NOTES.md ├── 226-invert-binary-tree ├── NOTES.md └── 226-invert-binary-tree.java ├── 227-basic-calculator-ii └── NOTES.md ├── 229-majority-element-ii └── NOTES.md ├── 23-merge-k-sorted-lists └── NOTES.md ├── 24-swap-nodes-in-pairs ├── NOTES.md └── 24-swap-nodes-in-pairs.java ├── 257-binary-tree-paths └── NOTES.md ├── 260-single-number-iii ├── NOTES.md └── 260-single-number-iii.java ├── 279-perfect-squares └── NOTES.md ├── 28-implement-strstr ├── NOTES.md └── 28-implement-strstr.java ├── 29-divide-two-integers ├── NOTES.md └── 29-divide-two-integers.java ├── 31-next-permutation ├── NOTES.md └── 31-next-permutation.java ├── 337-house-robber-iii └── NOTES.md ├── 377-combination-sum-iv └── NOTES.md ├── 389-find-the-difference ├── NOTES.md └── 389-find-the-difference.java ├── 397-integer-replacement ├── NOTES.md └── solution1.java ├── 399-evaluate-division └── NOTES.md ├── 40-combination-sum-ii └── NOTES.md ├── 409-longest-palindrome ├── NOTES.md └── 409-longest-palindrome.java ├── 42-trapping-rain-water └── NOTES.md ├── 43-multiply-strings └── NOTES.md ├── 44-wildcard-matching └── NOTES.md ├── 445-add-two-numbers-ii └── NOTES.md ├── 474-ones-and-zeroes └── NOTES.md ├── 498-diagonal-traverse └── NOTES.md ├── 53-maximum-subarray ├── NOTES.md └── 53-maximum-subarray.java ├── 547-number-of-provinces └── NOTES.md ├── 58-length-of-last-word ├── NOTES.md └── 58-length-of-last-word.java ├── 59-spiral-matrix-ii ├── NOTES.md └── README.md ├── 6-zigzag-conversion └── NOTES.md ├── 60-permutation-sequence └── NOTES.md ├── 650-2-keys-keyboard └── NOTES.md ├── 654-maximum-binary-tree └── NOTES.md ├── 680-valid-palindrome-ii ├── NOTES.md └── 680-valid-palindrome-ii.java ├── 724-find-pivot-index ├── NOTES.md └── 724-find-pivot-index.java ├── 73-set-matrix-zeroes ├── NOTES.md └── 73-set-matrix-zeroes.java ├── 739-daily-temperatures ├── NOTES.md └── 739-daily-temperatures.java ├── 74-search-a-2d-matrix └── NOTES.md ├── 740-delete-and-earn ├── NOTES.md └── 740-delete-and-earn.java ├── 743-network-delay-time └── NOTES.md ├── 767-reorganize-string ├── NOTES.md └── README.md ├── 781-rabbits-in-forest └── NOTES.md ├── 785-is-graph-bipartite └── NOTES.md ├── 85-maximal-rectangle └── NOTES.md ├── 858-mirror-reflection ├── NOTES.md └── illustrations.md ├── 875-koko-eating-bananas └── NOTES.md ├── 88-merge-sorted-array └── NOTES.md ├── 9-palindrome-number ├── NOTES.md └── 9-palindrome-number.java ├── 901-online-stock-span └── NOTES.md ├── 904-fruit-into-baskets └── NOTES.md ├── 910-smallest-range-ii └── NOTES.md ├── 934-shortest-bridge └── NOTES.md ├── 968-binary-tree-cameras └── NOTES.md ├── 969-pancake-sorting └── NOTES.md ├── 980-unique-paths-iii └── NOTES.md ├── 994-rotting-oranges └── NOTES.md ├── 997-find-the-town-judge ├── NOTES.md └── 997-find-the-town-judge.java ├── 1049-last-stone-weight-ii └── NOTES.md ├── 1052-grumpy-bookstore-owner └── NOTES.md ├── 1095-find-in-mountain-array └── NOTES.md ├── 11-container-with-most-water ├── NOTES.md └── 11-container-with-most-water.java ├── 110-balanced-binary-tree └── NOTES.md ├── 115-distinct-subsequences └── NOTES.md ├── 1219-path-with-maximum-gold └── NOTES.md ├── 129-sum-root-to-leaf-numbers └── NOTES.md ├── 131-palindrome-partitioning └── NOTES.md ├── 14-longest-common-prefix ├── NOTES.md └── 14-longest-common-prefix.java ├── 142-linked-list-cycle-ii └── NOTES.md ├── 1480-running-sum-of-1d-array ├── NOTES.md └── 1480-running-sum-of-1d-array.java ├── 149-max-points-on-a-line └── NOTES.md ├── 1492-the-kth-factor-of-n ├── NOTES.md └── 1492-the-kth-factor-of-n.java ├── 152-maximum-product-subarray ├── NOTES.md └── 152-maximum-product-subarray.java ├── 1695-maximum-erasure-value ├── NOTES.md └── 1695-maximum-erasure-value.java ├── 21-merge-two-sorted-lists └── NOTES.md ├── 219-contains-duplicate-ii ├── NOTES.md └── 219-contains-duplicate-ii.java ├── 239-sliding-window-maximum └── NOTES.md ├── 25-reverse-nodes-in-k-group └── NOTES.md ├── 310-minimum-height-trees └── NOTES.md ├── 316-remove-duplicate-letters └── NOTES.md ├── 32-longest-valid-parentheses └── NOTES.md ├── 328-odd-even-linked-list └── NOTES.md ├── 347-top-k-frequent-elements └── NOTES.md ├── 35-search-insert-position ├── NOTES.md └── 35-search-insert-position.java ├── 365-water-and-jug-problem ├── NOTES.md └── 365-water-and-jug-problem.java ├── 367-valid-perfect-square ├── NOTES.md └── 367-valid-perfect-square.java ├── 386-lexicographical-numbers ├── NOTES.md ├── 386-lexicographical-numbers.java └── README.md ├── 41-first-missing-positive └── NOTES.md ├── 450-delete-node-in-a-bst ├── NOTES.md └── illustrations.md ├── 485-max-consecutive-ones ├── NOTES.md └── 485-max-consecutive-ones.java ├── 491-increasing-subsequences └── NOTES.md ├── 496-next-greater-element-i └── NOTES.md ├── 503-next-greater-element-ii └── NOTES.md ├── 523-continuous-subarray-sum └── NOTES.md ├── 539-minimum-time-difference ├── NOTES.md └── README.md ├── 543-diameter-of-binary-tree └── NOTES.md ├── 560-subarray-sum-equals-k ├── NOTES.md └── 560-subarray-sum-equals-k.java ├── 611-valid-triangle-number └── NOTES.md ├── 617-merge-two-binary-trees ├── NOTES.md └── 617-merge-two-binary-trees.java ├── 647-palindromic-substrings └── NOTES.md ├── 652-find-duplicate-subtrees └── NOTES.md ├── 658-find-k-closest-elements └── NOTES.md ├── 684-redundant-connection └── NOTES.md ├── 685-redundant-connection-ii └── NOTES.md ├── 746-min-cost-climbing-stairs ├── NOTES.md └── 746-min-cost-climbing-stairs.java ├── 76-minimum-window-substring └── NOTES.md ├── 8-string-to-integer-atoi └── NOTES.md ├── 834-sum-of-distances-in-tree └── NOTES.md ├── 881-boats-to-save-people ├── NOTES.md └── 881-boats-to-save-people.java ├── 886-possible-bipartition └── NOTES.md ├── 890-find-and-replace-pattern └── NOTES.md ├── 92-reverse-linked-list-ii └── NOTES.md ├── 940-distinct-subsequences-ii └── NOTES.md ├── 946-validate-stack-sequences └── NOTES.md ├── 983-minimum-cost-for-tickets └── NOTES.md ├── 10-regular-expression-matching └── NOTES.md ├── 1004-max-consecutive-ones-iii ├── NOTES.md └── 1004-max-consecutive-ones-iii.java ├── 104-maximum-depth-of-binary-tree ├── NOTES.md └── 104-maximum-depth-of-binary-tree.java ├── 111-minimum-depth-of-binary-tree ├── NOTES.md └── 111-minimum-depth-of-binary-tree.java ├── 1143-longest-common-subsequence └── NOTES.md ├── 1220-count-vowels-permutation ├── NOTES.md └── 1220-count-vowels-permutation.java ├── 124-binary-tree-maximum-path-sum └── NOTES.md ├── 1278-palindrome-partitioning-iii └── NOTES.md ├── 128-longest-consecutive-sequence ├── NOTES.md └── 128-longest-consecutive-sequence.java ├── 1367-linked-list-in-binary-tree └── NOTES.md ├── 138-copy-list-with-random-pointer └── NOTES.md ├── 1483-kth-ancestor-of-a-tree-node └── NOTES.md ├── 1539-kth-missing-positive-number ├── NOTES.md └── solution1.java ├── 1654-minimum-jumps-to-reach-home └── NOTES.md ├── 171-excel-sheet-column-number ├── NOTES.md └── 171-excel-sheet-column-number.java ├── 1710-maximum-units-on-a-truck └── NOTES.md ├── 172-factorial-trailing-zeroes ├── NOTES.md └── 172-factorial-trailing-zeroes.java ├── 173-binary-search-tree-iterator └── NOTES.md ├── 1745-palindrome-partitioning-iv └── NOTES.md ├── 199-binary-tree-right-side-view └── NOTES.md ├── 2008-maximum-earnings-from-taxi └── NOTES.md ├── 203-remove-linked-list-elements ├── NOTES.md └── 203-remove-linked-list-elements.java ├── 209-minimum-size-subarray-sum ├── NOTES.md └── 209-minimum-size-subarray-sum.java ├── 2101-detonate-the-maximum-bombs └── NOTES.md ├── 222-count-complete-tree-nodes └── NOTES.md ├── 2236-root-equals-sum-of-children └── NOTES.md ├── 225-implement-stack-using-queues └── NOTES.md ├── 2276-count-integers-in-intervals └── NOTES.md ├── 2288-apply-discount-to-prices └── NOTES.md ├── 230-kth-smallest-element-in-a-bst └── NOTES.md ├── 232-implement-queue-using-stacks └── NOTES.md ├── 237-delete-node-in-a-linked-list ├── NOTES.md └── 237-delete-node-in-a-linked-list.java ├── 2370-longest-ideal-subsequence ├── NOTES.md └── 2370-longest-ideal-subsequence.java ├── 238-product-of-array-except-self ├── NOTES.md └── 238-product-of-array-except-self.java ├── 287-find-the-duplicate-number ├── NOTES.md └── 287-find-the-duplicate-number.java ├── 33-search-in-rotated-sorted-array └── NOTES.md ├── 349-intersection-of-two-arrays ├── NOTES.md └── 349-intersection-of-two-arrays.java ├── 350-intersection-of-two-arrays-ii └── NOTES.md ├── 374-guess-number-higher-or-lower └── NOTES.md ├── 4-median-of-two-sorted-arrays └── NOTES.md ├── 416-partition-equal-subset-sum └── NOTES.md ├── 435-non-overlapping-intervals └── NOTES.md ├── 5-longest-palindromic-substring ├── NOTES.md └── README.md ├── 513-find-bottom-left-tree-value └── NOTES.md ├── 538-convert-bst-to-greater-tree └── NOTES.md ├── 552-student-attendance-record-ii └── NOTES.md ├── 589-n-ary-tree-preorder-traversal └── NOTES.md ├── 646-maximum-length-of-pair-chain └── NOTES.md ├── 653-two-sum-iv-input-is-a-bst └── NOTES.md ├── 662-maximum-width-of-binary-tree └── NOTES.md ├── 713-subarray-product-less-than-k └── NOTES.md ├── 725-split-linked-list-in-parts └── NOTES.md ├── 775-global-and-local-inversions └── NOTES.md ├── 790-domino-and-tromino-tiling └── NOTES.md ├── 802-find-eventual-safe-states └── NOTES.md ├── 823-binary-trees-with-factors └── NOTES.md ├── 84-largest-rectangle-in-histogram └── NOTES.md ├── 876-middle-of-the-linked-list ├── NOTES.md └── 876-middle-of-the-linked-list.java ├── 918-maximum-sum-circular-subarray └── NOTES.md ├── 94-binary-tree-inorder-traversal └── NOTES.md ├── 95-unique-binary-search-trees-ii └── NOTES.md ├── 96-unique-binary-search-trees ├── NOTES.md └── 96-unique-binary-search-trees.java ├── 973-k-closest-points-to-origin └── NOTES.md ├── 974-subarray-sums-divisible-by-k ├── NOTES.md └── 974-subarray-sums-divisible-by-k.java ├── 98-validate-binary-search-tree └── NOTES.md ├── 986-interval-list-intersections └── NOTES.md ├── 99-recover-binary-search-tree └── NOTES.md ├── 102-binary-tree-level-order-traversal └── NOTES.md ├── 1042-flower-planting-with-no-adjacent └── NOTES.md ├── 1043-partition-array-for-maximum-sum └── NOTES.md ├── 114-flatten-binary-tree-to-linked-list └── NOTES.md ├── 121-best-time-to-buy-and-sell-stock ├── NOTES.md └── 121-best-time-to-buy-and-sell-stock.java ├── 122-best-time-to-buy-and-sell-stock-ii ├── NOTES.md └── 122-best-time-to-buy-and-sell-stock-ii.java ├── 1232-check-if-it-is-a-straight-line └── NOTES.md ├── 1332-remove-palindromic-subsequences ├── NOTES.md └── 1332-remove-palindromic-subsequences.java ├── 1338-reduce-array-size-to-the-half ├── NOTES.md └── 1338-reduce-array-size-to-the-half.java ├── 1373-maximum-sum-bst-in-binary-tree └── NOTES.md ├── 144-binary-tree-preorder-traversal └── NOTES.md ├── 145-binary-tree-postorder-traversal └── NOTES.md ├── 150-evaluate-reverse-polish-notation └── NOTES.md ├── 1514-path-with-maximum-probability └── NOTES.md ├── 1669-merge-in-between-linked-lists └── NOTES.md ├── 167-two-sum-ii-input-array-is-sorted ├── NOTES.md └── 167-two-sum-ii-input-array-is-sorted.java ├── 1865-finding-pairs-with-a-certain-sum └── NOTES.md ├── 188-best-time-to-buy-and-sell-stock-iv └── NOTES.md ├── 19-remove-nth-node-from-end-of-list └── NOTES.md ├── 1991-find-the-middle-index-in-array ├── NOTES.md └── 1991-find-the-middle-index-in-array.java ├── 2057-smallest-index-with-equal-value ├── NOTES.md └── 2057-smallest-index-with-equal-value.java ├── 2140-solving-questions-with-brainpower └── NOTES.md ├── 2149-rearrange-array-elements-by-sign ├── NOTES.md └── 2149-rearrange-array-elements-by-sign.java ├── 215-kth-largest-element-in-an-array └── NOTES.md ├── 2183-count-array-pairs-divisible-by-k └── NOTES.md ├── 2248-intersection-of-multiple-arrays └── NOTES.md ├── 26-remove-duplicates-from-sorted-array ├── NOTES.md └── 26-remove-duplicates-from-sorted-array.java ├── 300-longest-increasing-subsequence └── NOTES.md ├── 357-count-numbers-with-unique-digits ├── NOTES.md ├── 357-count-numbers-with-unique-digits.java └── README.md ├── 406-queue-reconstruction-by-height ├── NOTES.md └── 406-queue-reconstruction-by-height.java ├── 442-find-all-duplicates-in-an-array └── NOTES.md ├── 501-find-mode-in-binary-search-tree └── NOTES.md ├── 530-minimum-absolute-difference-in-bst └── NOTES.md ├── 583-delete-operation-for-two-strings └── NOTES.md ├── 590-n-ary-tree-postorder-traversal └── NOTES.md ├── 783-minimum-distance-between-bst-nodes └── NOTES.md ├── 792-number-of-matching-subsequences └── NOTES.md ├── 797-all-paths-from-source-to-target ├── NOTES.md └── 797-all-paths-from-source-to-target.java ├── 83-remove-duplicates-from-sorted-list ├── NOTES.md └── 83-remove-duplicates-from-sorted-list.java ├── 852-peak-index-in-a-mountain-array ├── NOTES.md └── 852-peak-index-in-a-mountain-array.java ├── 1007-minimum-domino-rotations-for-equal-row └── NOTES.md ├── 1038-binary-search-tree-to-greater-sum-tree └── NOTES.md ├── 107-binary-tree-level-order-traversal-ii └── NOTES.md ├── 1155-number-of-dice-rolls-with-target-sum ├── NOTES.md └── 1155-number-of-dice-rolls-with-target-sum.java ├── 123-best-time-to-buy-and-sell-stock-iii └── NOTES.md ├── 1277-count-square-submatrices-with-all-ones └── NOTES.md ├── 1372-longest-zigzag-path-in-a-binary-tree └── NOTES.md ├── 1376-time-needed-to-inform-all-employees └── NOTES.md ├── 153-find-minimum-in-rotated-sorted-array └── NOTES.md ├── 154-find-minimum-in-rotated-sorted-array-ii └── NOTES.md ├── 1636-sort-array-by-increasing-frequency └── NOTES.md ├── 1658-minimum-operations-to-reduce-x-to-zero └── NOTES.md ├── 17-letter-combinations-of-a-phone-number ├── NOTES.md └── 17-letter-combinations-of-a-phone-number.java ├── 1723-find-minimum-time-to-finish-all-jobs └── NOTES.md ├── 1823-find-the-winner-of-the-circular-game ├── NOTES.md └── 1823-find-the-winner-of-the-circular-game.java ├── 1926-nearest-exit-from-entrance-in-maze └── NOTES.md ├── 2289-steps-to-make-array-non-decreasing └── NOTES.md ├── 2300-successful-pairs-of-spells-and-potions └── NOTES.md ├── 236-lowest-common-ancestor-of-a-binary-tree └── NOTES.md ├── 297-serialize-and-deserialize-binary-tree └── NOTES.md ├── 421-maximum-xor-of-two-numbers-in-an-array └── NOTES.md ├── 453-minimum-moves-to-equal-array-elements ├── NOTES.md └── 453-minimum-moves-to-equal-array-elements.java ├── 515-find-largest-value-in-each-tree-row └── NOTES.md ├── 581-shortest-unsorted-continuous-subarray ├── NOTES.md └── solution1.java ├── 80-remove-duplicates-from-sorted-array-ii ├── NOTES.md └── 80-remove-duplicates-from-sorted-array-ii.java ├── 1005-maximize-sum-of-array-after-k-negations ├── NOTES.md └── 1005-maximize-sum-of-array-after-k-negations.java ├── 1011-capacity-to-ship-packages-within-d-days └── NOTES.md ├── 103-binary-tree-zigzag-level-order-traversal └── NOTES.md ├── 108-convert-sorted-array-to-binary-search-tree └── NOTES.md ├── 1081-smallest-subsequence-of-distinct-characters └── NOTES.md ├── 109-convert-sorted-list-to-binary-search-tree └── NOTES.md ├── 1123-lowest-common-ancestor-of-deepest-leaves └── NOTES.md ├── 116-populating-next-right-pointers-in-each-node └── NOTES.md ├── 1160-find-words-that-can-be-formed-by-characters └── NOTES.md ├── 1209-remove-all-adjacent-duplicates-in-string-ii ├── NOTES.md └── 1209-remove-all-adjacent-duplicates-in-string-ii.java ├── 1423-maximum-points-you-can-obtain-from-cards └── NOTES.md ├── 1828-queries-on-number-of-points-inside-a-circle └── NOTES.md ├── 2091-removing-minimum-and-maximum-from-array └── NOTES.md ├── 3-longest-substring-without-repeating-characters └── NOTES.md ├── 30-substring-with-concatenation-of-all-words └── NOTES.md ├── 452-minimum-number-of-arrows-to-burst-balloons └── NOTES.md ├── 462-minimum-moves-to-equal-array-elements-ii ├── NOTES.md └── 462-minimum-moves-to-equal-array-elements-ii.java ├── 673-number-of-longest-increasing-subsequence └── NOTES.md ├── 674-longest-continuous-increasing-subsequence ├── NOTES.md └── 674-longest-continuous-increasing-subsequence.java ├── 730-count-different-palindromic-subsequences └── NOTES.md ├── 744-find-smallest-letter-greater-than-target ├── NOTES.md └── 744-find-smallest-letter-greater-than-target.java ├── 865-smallest-subtree-with-all-the-deepest-nodes └── NOTES.md ├── 987-vertical-order-traversal-of-a-binary-tree └── NOTES.md ├── 117-populating-next-right-pointers-in-each-node-ii └── NOTES.md ├── 1319-number-of-operations-to-make-network-connected └── NOTES.md ├── 1326-minimum-number-of-taps-to-open-to-water-a-garden └── NOTES.md ├── 1353-maximum-number-of-events-that-can-be-attended └── NOTES.md ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── NOTES.md └── 235-lowest-common-ancestor-of-a-binary-search-tree.java ├── 309-best-time-to-buy-and-sell-stock-with-cooldown └── NOTES.md ├── 1008-construct-binary-search-tree-from-preorder-traversal └── NOTES.md ├── 1010-pairs-of-songs-with-total-durations-divisible-by-60 ├── NOTES.md └── 1010-pairs-of-songs-with-total-durations-divisible-by-60.java ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination └── NOTES.md ├── 1312-minimum-insertion-steps-to-make-a-string-palindrome └── NOTES.md ├── 1671-minimum-number-of-removals-to-make-mountain-array └── NOTES.md ├── 1775-equal-sum-arrays-with-minimum-number-of-operations └── NOTES.md ├── 714-best-time-to-buy-and-sell-stock-with-transaction-fee └── NOTES.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal └── NOTES.md ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal └── NOTES.md ├── 1374-generate-a-string-with-characters-that-have-odd-counts ├── NOTES.md └── 1374-generate-a-string-with-characters-that-have-odd-counts.java ├── 1647-minimum-deletions-to-make-character-frequencies-unique ├── NOTES.md └── 1647-minimum-deletions-to-make-character-frequencies-unique.java ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers ├── NOTES.md └── 1689-partitioning-into-minimum-number-of-deci-binary-numbers.java ├── 1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k ├── NOTES.md └── 1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k.java ├── 1498-number-of-subsequences-that-satisfy-the-given-sum-condition ├── NOTES.md └── 1498-number-of-subsequences-that-satisfy-the-given-sum-condition.java ├── 1888-minimum-number-of-flips-to-make-the-binary-string-alternating └── NOTES.md ├── 1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree └── NOTES.md ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts └── NOTES.md ├── 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance └── NOTES.md ├── 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit └── NOTES.md ├── 136-single-number └── 136-single-number.java ├── 509-fibonacci-number └── 509-fibonacci-number.java ├── 1137-n-th-tribonacci-number └── 1137-n-th-tribonacci-number.java ├── 283-move-zeroes └── 283-move-zeroes.java ├── 2206-divide-array-into-equal-pairs └── 2206-divide-array-into-equal-pairs.java ├── 240-search-a-2d-matrix-ii └── 240-search-a-2d-matrix-ii.java ├── 686-repeated-string-match └── 686-repeated-string-match.java ├── 2139-minimum-moves-to-reach-target-score └── 2139-minimum-moves-to-reach-target-score.java ├── 1306-jump-game-iii └── 1306-jump-game-iii.java ├── 1963-minimum-number-of-swaps-to-make-the-string-balanced └── 1963-minimum-number-of-swaps-to-make-the-string-balanced.java ├── 160-intersection-of-two-linked-lists └── 160-intersection-of-two-linked-lists.java ├── 633-sum-of-square-numbers ├── 633-sum-of-square-numbers.java └── README.md ├── 201-bitwise-and-of-numbers-range └── 201-bitwise-and-of-numbers-range.java ├── 700-search-in-a-binary-search-tree └── 700-search-in-a-binary-search-tree.java ├── 118-pascals-triangle └── 118-pascals-triangle.java ├── 64-minimum-path-sum └── 64-minimum-path-sum.java ├── Maximum difference of zeros and ones in binary string - GFG └── solution.java ├── 701-insert-into-a-binary-search-tree └── 701-insert-into-a-binary-search-tree.java ├── 48-rotate-image └── 48-rotate-image.java └── 71-simplify-path └── 71-simplify-path.java /15-3sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /18-4sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /69-sqrtx/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1-two-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /112-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /120-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /135-candy/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /146-lru-cache/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /148-sort-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /372-super-pow/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /400-nth-digit/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /412-fizz-buzz/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /50-powx-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /51-n-queens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /542-01-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /55-jump-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /66-plus-one/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /67-add-binary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /78-subsets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /89-gray-code/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /90-subsets-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /101-symmetric-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1094-car-pooling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /113-path-sum-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /127-word-ladder/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /133-clone-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /134-gas-station/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1340-jump-game-v/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1345-jump-game-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /139-word-break/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /16-3sum-closest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1696-jump-game-vi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /179-largest-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1871-jump-game-vii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /189-rotate-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /190-reverse-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /198-house-robber/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2-add-two-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /202-happy-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /204-count-primes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /221-maximal-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /231-power-of-two/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /258-add-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /263-ugly-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /264-ugly-number-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /268-missing-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /27-remove-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /312-burst-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /322-coin-change/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /338-counting-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /343-integer-break/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /344-reverse-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /36-valid-sudoku/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /37-sudoku-solver/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /38-count-and-say/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /392-is-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /394-decode-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /437-path-sum-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /45-jump-game-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /455-assign-cookies/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /46-permutations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /47-permutations-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /49-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /493-reverse-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /494-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /518-coin-change-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /52-n-queens-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /529-minesweeper/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /54-spiral-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /56-merge-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /57-insert-interval/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /61-rotate-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /63-unique-paths-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /639-decode-ways-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /7-reverse-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /70-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /704-binary-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /709-to-lower-case/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /72-edit-distance/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /729-my-calendar-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /75-sort-colors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /77-combinations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /79-word-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /796-rotate-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /835-image-overlap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /841-keys-and-rooms/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /86-partition-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /87-scramble-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /877-stone-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /912-sort-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /935-knight-dialer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1035-uncrossed-lines/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /119-pascals-triangle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /12-integer-to-roman/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /125-valid-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1291-sequential-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /13-roman-to-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /130-surrounded-regions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1323-maximum-69-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /137-single-number-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /141-linked-list-cycle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /162-find-peak-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /169-majority-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /175-combine-two-tables/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /191-number-of-1-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /20-valid-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /206-reverse-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /207-course-schedule/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /210-course-schedule-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /213-house-robber-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /216-combination-sum-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /22-generate-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /224-basic-calculator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /227-basic-calculator-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /229-majority-element-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /23-merge-k-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /24-swap-nodes-in-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /257-binary-tree-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /260-single-number-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /279-perfect-squares/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /28-implement-strstr/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /29-divide-two-integers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /31-next-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /337-house-robber-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /389-find-the-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /397-integer-replacement/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /399-evaluate-division/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /40-combination-sum-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /409-longest-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /42-trapping-rain-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /43-multiply-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /44-wildcard-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /445-add-two-numbers-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /474-ones-and-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /498-diagonal-traverse/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /547-number-of-provinces/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /58-length-of-last-word/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /59-spiral-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /6-zigzag-conversion/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /60-permutation-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /650-2-keys-keyboard/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /654-maximum-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /680-valid-palindrome-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /724-find-pivot-index/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /73-set-matrix-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /739-daily-temperatures/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /74-search-a-2d-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /740-delete-and-earn/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /743-network-delay-time/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /767-reorganize-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /781-rabbits-in-forest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /785-is-graph-bipartite/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /85-maximal-rectangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /858-mirror-reflection/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /875-koko-eating-bananas/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /88-merge-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /9-palindrome-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /901-online-stock-span/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /904-fruit-into-baskets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /910-smallest-range-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /934-shortest-bridge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /968-binary-tree-cameras/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /969-pancake-sorting/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /980-unique-paths-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /994-rotting-oranges/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /997-find-the-town-judge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1049-last-stone-weight-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1052-grumpy-bookstore-owner/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1095-find-in-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /11-container-with-most-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /110-balanced-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /115-distinct-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1219-path-with-maximum-gold/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /129-sum-root-to-leaf-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /131-palindrome-partitioning/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /14-longest-common-prefix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /142-linked-list-cycle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /149-max-points-on-a-line/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1492-the-kth-factor-of-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /152-maximum-product-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1695-maximum-erasure-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /219-contains-duplicate-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /239-sliding-window-maximum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /25-reverse-nodes-in-k-group/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /310-minimum-height-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /316-remove-duplicate-letters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /32-longest-valid-parentheses/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /328-odd-even-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /347-top-k-frequent-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /35-search-insert-position/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /365-water-and-jug-problem/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /367-valid-perfect-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /386-lexicographical-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /41-first-missing-positive/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /450-delete-node-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /485-max-consecutive-ones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /491-increasing-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /496-next-greater-element-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /503-next-greater-element-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /539-minimum-time-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /560-subarray-sum-equals-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /611-valid-triangle-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /617-merge-two-binary-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /647-palindromic-substrings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /652-find-duplicate-subtrees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /658-find-k-closest-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /684-redundant-connection/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /685-redundant-connection-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /76-minimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /8-string-to-integer-atoi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /834-sum-of-distances-in-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /881-boats-to-save-people/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /886-possible-bipartition/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /890-find-and-replace-pattern/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /92-reverse-linked-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /940-distinct-subsequences-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /946-validate-stack-sequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /983-minimum-cost-for-tickets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /10-regular-expression-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1004-max-consecutive-ones-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1143-longest-common-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1220-count-vowels-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1278-palindrome-partitioning-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /128-longest-consecutive-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1367-linked-list-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /138-copy-list-with-random-pointer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1483-kth-ancestor-of-a-tree-node/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1539-kth-missing-positive-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1654-minimum-jumps-to-reach-home/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /171-excel-sheet-column-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /172-factorial-trailing-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /173-binary-search-tree-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1745-palindrome-partitioning-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /199-binary-tree-right-side-view/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2008-maximum-earnings-from-taxi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /203-remove-linked-list-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /209-minimum-size-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2101-detonate-the-maximum-bombs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2236-root-equals-sum-of-children/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /225-implement-stack-using-queues/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2276-count-integers-in-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2288-apply-discount-to-prices/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /232-implement-queue-using-stacks/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2370-longest-ideal-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /238-product-of-array-except-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /287-find-the-duplicate-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /33-search-in-rotated-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /350-intersection-of-two-arrays-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /374-guess-number-higher-or-lower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /4-median-of-two-sorted-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /435-non-overlapping-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /5-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /513-find-bottom-left-tree-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /538-convert-bst-to-greater-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /552-student-attendance-record-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /589-n-ary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /646-maximum-length-of-pair-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /653-two-sum-iv-input-is-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /662-maximum-width-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /713-subarray-product-less-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /725-split-linked-list-in-parts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /775-global-and-local-inversions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /790-domino-and-tromino-tiling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /802-find-eventual-safe-states/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /823-binary-trees-with-factors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /84-largest-rectangle-in-histogram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /918-maximum-sum-circular-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /95-unique-binary-search-trees-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /96-unique-binary-search-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /973-k-closest-points-to-origin/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /974-subarray-sums-divisible-by-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /986-interval-list-intersections/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /99-recover-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1042-flower-planting-with-no-adjacent/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1043-partition-array-for-maximum-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /122-best-time-to-buy-and-sell-stock-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1232-check-if-it-is-a-straight-line/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1338-reduce-array-size-to-the-half/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1373-maximum-sum-bst-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /145-binary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /150-evaluate-reverse-polish-notation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1514-path-with-maximum-probability/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1669-merge-in-between-linked-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1865-finding-pairs-with-a-certain-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /188-best-time-to-buy-and-sell-stock-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1991-find-the-middle-index-in-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2057-smallest-index-with-equal-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2140-solving-questions-with-brainpower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2183-count-array-pairs-divisible-by-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2248-intersection-of-multiple-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /357-count-numbers-with-unique-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /406-queue-reconstruction-by-height/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /501-find-mode-in-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /530-minimum-absolute-difference-in-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /583-delete-operation-for-two-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /590-n-ary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /783-minimum-distance-between-bst-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /797-all-paths-from-source-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /852-peak-index-in-a-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1007-minimum-domino-rotations-for-equal-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1038-binary-search-tree-to-greater-sum-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /107-binary-tree-level-order-traversal-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1155-number-of-dice-rolls-with-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /123-best-time-to-buy-and-sell-stock-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1277-count-square-submatrices-with-all-ones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1372-longest-zigzag-path-in-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1376-time-needed-to-inform-all-employees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /153-find-minimum-in-rotated-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /154-find-minimum-in-rotated-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1636-sort-array-by-increasing-frequency/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1658-minimum-operations-to-reduce-x-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /17-letter-combinations-of-a-phone-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1723-find-minimum-time-to-finish-all-jobs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1823-find-the-winner-of-the-circular-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1926-nearest-exit-from-entrance-in-maze/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2289-steps-to-make-array-non-decreasing/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2300-successful-pairs-of-spells-and-potions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /297-serialize-and-deserialize-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /421-maximum-xor-of-two-numbers-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /453-minimum-moves-to-equal-array-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /515-find-largest-value-in-each-tree-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /581-shortest-unsorted-continuous-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1005-maximize-sum-of-array-after-k-negations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1011-capacity-to-ship-packages-within-d-days/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /103-binary-tree-zigzag-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1081-smallest-subsequence-of-distinct-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /109-convert-sorted-list-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1123-lowest-common-ancestor-of-deepest-leaves/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /116-populating-next-right-pointers-in-each-node/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1160-find-words-that-can-be-formed-by-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1209-remove-all-adjacent-duplicates-in-string-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1423-maximum-points-you-can-obtain-from-cards/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1828-queries-on-number-of-points-inside-a-circle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2091-removing-minimum-and-maximum-from-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /30-substring-with-concatenation-of-all-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /452-minimum-number-of-arrows-to-burst-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /673-number-of-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /674-longest-continuous-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /730-count-different-palindromic-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /744-find-smallest-letter-greater-than-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /865-smallest-subtree-with-all-the-deepest-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /987-vertical-order-traversal-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /117-populating-next-right-pointers-in-each-node-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1319-number-of-operations-to-make-network-connected/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1353-maximum-number-of-events-that-can-be-attended/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /309-best-time-to-buy-and-sell-stock-with-cooldown/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1008-construct-binary-search-tree-from-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1010-pairs-of-songs-with-total-durations-divisible-by-60/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1312-minimum-insertion-steps-to-make-a-string-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1671-minimum-number-of-removals-to-make-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1775-equal-sum-arrays-with-minimum-number-of-operations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /714-best-time-to-buy-and-sell-stock-with-transaction-fee/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /106-construct-binary-tree-from-inorder-and-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1374-generate-a-string-with-characters-that-have-odd-counts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1498-number-of-subsequences-that-satisfy-the-given-sum-condition/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1888-minimum-number-of-flips-to-make-the-binary-string-alternating/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /877-stone-game/877-stone-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean stoneGame(int[] piles) { 3 | return true; 4 | } 5 | } -------------------------------------------------------------------------------- /231-power-of-two/231-power-of-two.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfTwo(int n) { 3 | if (n<=0) return false; 4 | return (n&(n-1))==0; 5 | } 6 | } -------------------------------------------------------------------------------- /796-rotate-string/796-rotate-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean rotateString(String s, String goal) { 3 | s=s+s; 4 | return s.contains(goal) && s.length()==2*goal.length(); 5 | } 6 | } -------------------------------------------------------------------------------- /58-length-of-last-word/58-length-of-last-word.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lengthOfLastWord(String s) { 3 | String[] token = s.split(" "); 4 | return token[token.length-1].length(); 5 | } 6 | } -------------------------------------------------------------------------------- /136-single-number/136-single-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int ans = 0; 4 | for (int i=0;i=1) { 6 | ans = ans+n/x; 7 | x=5*x; 8 | } 9 | 10 | return ans; 11 | } 12 | } -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/80-remove-duplicates-from-sorted-array-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | int i=0; 4 | for (int n:nums) 5 | if (i<2 || n>nums[i-2]) 6 | nums[i++]=n; 7 | 8 | return i; 9 | } 10 | } -------------------------------------------------------------------------------- /217-contains-duplicate/217-contains-duplicate.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsDuplicate(int[] nums) { 3 | HashSet vals = new HashSet<>(); 4 | for (int i: nums) { 5 | if (!vals.add(i)) 6 | return true; 7 | } 8 | return false; 9 | } 10 | } -------------------------------------------------------------------------------- /1492-the-kth-factor-of-n/1492-the-kth-factor-of-n.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int kthFactor(int n, int k) { 3 | for (int i=1;i<=n;i++) { 4 | if (n%i==0) 5 | k--; 6 | 7 | if (k==0) 8 | return i; 9 | } 10 | 11 | return -1; 12 | } 13 | } -------------------------------------------------------------------------------- /287-find-the-duplicate-number/287-find-the-duplicate-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findDuplicate(int[] nums) { 3 | boolean[] arr = new boolean[nums.length]; 4 | for (int i=0,size=nums.length;i>>1; 10 | } 11 | return ans; 12 | } 13 | } -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/237-delete-node-in-a-linked-list.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode(int x) { val = x; } 7 | * } 8 | */ 9 | class Solution { 10 | public void deleteNode(ListNode node) { 11 | node.val=node.next.val; 12 | node.next=node.next.next; 13 | } 14 | } -------------------------------------------------------------------------------- /70-climbing-stairs/70-climbing-stairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int climbStairs(int n) { 3 | int ways[] = new int[n+1]; 4 | ways[1] = 1; 5 | 6 | for (int i=2;i<=n;i++) { 7 | if (i==2) 8 | ways[i]=2; // 1+1 and 2 9 | else 10 | ways[i]=ways[i-1]+ways[i-2]; 11 | } 12 | 13 | return ways[n]; 14 | } 15 | } -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/1480-running-sum-of-1d-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] runningSum(int[] nums) { 3 | int n = nums.length; 4 | int[] runningSums = new int[n]; 5 | int runningSum = 0; 6 | for (int i=0;i=0;i--) { 8 | char ch = columnTitle.charAt(i); 9 | number = number + (ch-'A'+1)*k; 10 | k=k*26; 11 | } 12 | return number; 13 | } 14 | } -------------------------------------------------------------------------------- /50-powx-n/50-powx-n.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double myPow(double x, int n) { 3 | double ans = 1; 4 | if (n<0) { 5 | x = 1.0/x; 6 | n = -n; 7 | } 8 | 9 | 10 | while (n!=0) { 11 | int last_bit = (n&1); 12 | ans *= last_bit==1 ? x : 1; 13 | x = x*x; 14 | n = n>>>1; 15 | } 16 | 17 | return ans; 18 | } 19 | } -------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int tribonacci(int n) { 3 | int dp[] = new int[n+1]; 4 | 5 | for (int i=0;i<=n;i++) { 6 | if (i==0) 7 | dp[i]=0; 8 | else if (i==1 || i==2) 9 | dp[i]=1; 10 | else 11 | dp[i]=dp[i-1]+dp[i-2]+dp[i-3]; 12 | } 13 | 14 | return dp[n]; 15 | } 16 | } -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/1689-partitioning-into-minimum-number-of-deci-binary-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPartitions(String n) { 3 | int maxDigit = 0; 4 | for (char ch: n.toCharArray()) { 5 | int digit = ch-'0'; 6 | if (digit==9) 7 | return 9; 8 | maxDigit = Math.max(digit,maxDigit); 9 | } 10 | return maxDigit; 11 | } 12 | } -------------------------------------------------------------------------------- /28-implement-strstr/28-implement-strstr.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int strStr(String haystack, String needle) { 3 | for (int i = 0; ; i++) { 4 | for (int j = 0; ; j++) { 5 | if (j == needle.length()) 6 | return i; 7 | if (i + j == haystack.length()) 8 | return -1; 9 | if (needle.charAt(j) != haystack.charAt(i + j)) 10 | break; 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /485-max-consecutive-ones/485-max-consecutive-ones.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findMaxConsecutiveOnes(int[] nums) { 3 | int maxOnes=0; 4 | int count=0; 5 | for (int i: nums) { 6 | count+=i; 7 | if (i==0) { 8 | maxOnes=Math.max(maxOnes,count); 9 | count=0; 10 | } 11 | } 12 | maxOnes=Math.max(maxOnes,count); 13 | return maxOnes; 14 | } 15 | } -------------------------------------------------------------------------------- /881-boats-to-save-people/881-boats-to-save-people.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numRescueBoats(int[] people, int limit) { 3 | Arrays.sort(people); 4 | int start=0,end=people.length-1; 5 | 6 | int count = 0; 7 | while (start<=end) { 8 | if (people[start]+people[end]<=limit) 9 | start++; 10 | end--; 11 | count++; 12 | } 13 | return count; 14 | } 15 | } -------------------------------------------------------------------------------- /122-best-time-to-buy-and-sell-stock-ii/122-best-time-to-buy-and-sell-stock-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int maxProfit = 0; 4 | for (int i=1;iprices[i-1]) { 6 | // Buy at prices[i-1] 7 | // Sell at prices[i] 8 | maxProfit += prices[i]-prices[i-1]; 9 | } 10 | } 11 | return maxProfit; 12 | } 13 | } -------------------------------------------------------------------------------- /450-delete-node-in-a-bst/illustrations.md: -------------------------------------------------------------------------------- 1 |

Illustrations

2 | 3 | When node to be deleted has only one child - 4 | ![image](https://user-images.githubusercontent.com/56895638/175042564-ceee9f5a-cfd2-4cc0-9dbb-f873a3fa41b7.png) 5 | 6 | 7 | When node to be deleted has both child, we find inorder succesor of node and replace its value and delete the successor node - 8 | ![image](https://user-images.githubusercontent.com/56895638/175042895-4d83e334-383e-4996-ace1-b7c10f078992.png) 9 | -------------------------------------------------------------------------------- /338-counting-bits/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] countBits(int n) { 3 | int ans[] = new int[n+1]; 4 | for (int i=0;i<=n;i++) { 5 | ans[i]=count(i); 6 | } 7 | return ans; 8 | } 9 | 10 | public int count(int num) { 11 | int ans = 0; 12 | while (num>0) { 13 | num = num&(num-1); // Removes the last set bit 14 | ans++; 15 | } 16 | return ans; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /258-add-digits/258-add-digits.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addDigits(int num) { 3 | int current = num; 4 | while (current/10!=0) { 5 | current=getNext(current); 6 | } 7 | return current; 8 | } 9 | 10 | private int getNext(int n) { 11 | int result = 0; 12 | while (n!=0) { 13 | int rem = n%10; 14 | n = n/10; 15 | result += rem; 16 | } 17 | return result; 18 | } 19 | } -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/462-minimum-moves-to-equal-array-elements-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minMoves2(int[] nums) { 3 | Arrays.sort(nums); 4 | int n = nums.length; 5 | 6 | int mid = n/2; 7 | 8 | int moves = 0; // Move complete array to equal to mid 9 | 10 | for (int i=0;i map = new HashMap<>(); 4 | for (int i = 0; i < nums.length; i++) { 5 | int complement = target - nums[i]; 6 | if (map.containsKey(complement)) { 7 | return new int[] { map.get(complement), i }; 8 | } 9 | map.put(nums[i], i); 10 | } 11 | throw new IllegalArgumentException("No two sum solution"); 12 | } 13 | } -------------------------------------------------------------------------------- /412-fizz-buzz/412-fizz-buzz.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List fizzBuzz(int n) { 3 | List ans = new ArrayList<>(); 4 | for (int i=1;i<=n;i++) { 5 | if (i%3==0 && i%5==0) 6 | ans.add("FizzBuzz"); 7 | else if (i%3==0) 8 | ans.add("Fizz"); 9 | else if (i%5==0) 10 | ans.add("Buzz"); 11 | else 12 | ans.add(Integer.toString(i)); 13 | } 14 | return ans; 15 | } 16 | } -------------------------------------------------------------------------------- /55-jump-game/solution2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int n = nums.length; 4 | boolean dp[] = new boolean[n]; 5 | dp[n-1]=true; 6 | for (int i=n-2;i>=0;i--) { 7 | int curr = nums[i]; 8 | for (int j=1;j<=curr;j++) { 9 | if (i+jx) 13 | high=(int)mid-1; 14 | else 15 | low=(int)mid+1; 16 | } 17 | return high; 18 | } 19 | } -------------------------------------------------------------------------------- /367-valid-perfect-square/367-valid-perfect-square.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPerfectSquare(int num) { 3 | int low = 0; 4 | int high = num; 5 | 6 | while (low<=high) { 7 | long mid = low + (high-low)/2; 8 | if (mid*mid==num) 9 | return true; 10 | else if (mid*mid>num) 11 | high=(int)mid-1; 12 | else 13 | low=(int)mid+1; 14 | } 15 | 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /55-jump-game/55-jump-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int n = nums.length; 4 | 5 | // Determines the last index through which we can reach 6 | // last index of array 7 | int lastGoodIndex = n-1; 8 | for (int i=n-2;i>=0;i--) { 9 | int curr = nums[i]; 10 | if (i+nums[i]>=lastGoodIndex) { 11 | lastGoodIndex=i; 12 | } 13 | } 14 | 15 | return lastGoodIndex==0; 16 | } 17 | } -------------------------------------------------------------------------------- /9-palindrome-number/9-palindrome-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(int x) { 3 | int y=reverse(x); 4 | if (x>=0 && x==y) 5 | return true; 6 | return false; 7 | } 8 | 9 | private int reverse(int x) 10 | { 11 | int reverse=0; 12 | int rem; 13 | 14 | while (x!=0) 15 | { 16 | rem=x%10; 17 | x=x/10; 18 | reverse=reverse*10+rem; 19 | } 20 | return reverse; 21 | } 22 | } -------------------------------------------------------------------------------- /283-move-zeroes/283-move-zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void moveZeroes(int[] nums) { 3 | int n=nums.length; 4 | int index=0; // Represents index where non-zero elements to be placed 5 | for (int i=0;i=0;i--) { 8 | int curr = nums[i]; 9 | for (int j=1;j<=curr;j++) { 10 | if (i+jarr[mid+1]) { 10 | high=mid-1; 11 | } 12 | else if (arr[mid]target) { 12 | high=mid-1; 13 | } 14 | else { 15 | low=mid+1; 16 | } 17 | } 18 | 19 | return low; 20 | } 21 | } -------------------------------------------------------------------------------- /997-find-the-town-judge/997-find-the-town-judge.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findJudge(int n, int[][] trust) { 3 | int indegree[] = new int[n+1]; // No of people who trust you 4 | int outdegree[] = new int[n+1]; // No of people you trust 5 | 6 | for (int[] t: trust) { 7 | indegree[t[1]]++; 8 | outdegree[t[0]]++; 9 | } 10 | 11 | for (int i=1;i<=n;i++) { 12 | if (indegree[i]==n-1 && outdegree[i]==0) 13 | return i; 14 | } 15 | 16 | return -1; 17 | } 18 | } -------------------------------------------------------------------------------- /2206-divide-array-into-equal-pairs/2206-divide-array-into-equal-pairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean divideArray(int[] nums) { 3 | HashMap hm = new HashMap<>(); 4 | for(int i=0;ie : hm.entrySet()) { 11 | if (e.getValue()%2!=0) 12 | return false; 13 | } 14 | return true; 15 | } 16 | } -------------------------------------------------------------------------------- /674-longest-continuous-increasing-subsequence/674-longest-continuous-increasing-subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findLengthOfLCIS(int[] nums) { 3 | int n=nums.length; 4 | int i=1; 5 | int LCIS=1; 6 | 7 | int currlen=1; 8 | while (inums[i-1]) { 10 | currlen++; 11 | } 12 | else { 13 | currlen=1; 14 | } 15 | LCIS=Math.max(LCIS,currlen); 16 | i++; 17 | } 18 | 19 | return LCIS; 20 | } 21 | } -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minCostClimbingStairs(int[] cost) { 3 | int n = cost.length; 4 | 5 | // dp[i] represents min cost from step i to reach top of the floor 6 | int dp[] = new int[n+1]; 7 | dp[n] = 0; 8 | 9 | for (int i=n-1;i>=0;i--) { 10 | if (i==n-1) 11 | dp[i] = cost[i]+dp[i+1]; 12 | else 13 | dp[i] = cost[i]+Math.min(dp[i+1],dp[i+2]); 14 | } 15 | 16 | return Math.min(dp[0],dp[1]); 17 | } 18 | } -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean searchMatrix(int[][] matrix, int target) { 3 | int m = matrix.length; 4 | int n = matrix[0].length; 5 | 6 | int start=0; 7 | int end=n-1; 8 | 9 | while (start-1) { 10 | if (matrix[start][end]==target) 11 | return true; 12 | else if (matrix[start][end]>target) 13 | end--; 14 | else 15 | start++; 16 | } 17 | 18 | return false; 19 | } 20 | } -------------------------------------------------------------------------------- /386-lexicographical-numbers/386-lexicographical-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List lexicalOrder(int n) { 3 | List res = new ArrayList<>(); 4 | getNums(res,0,n); 5 | return res; 6 | } 7 | 8 | public void getNums(List res,int i,int num) { 9 | //if (i>num) return; 10 | 11 | if (i!=0 && i<=num) 12 | res.add(i); 13 | 14 | for (int j= (i==0) ? 1:0;j<=9;j++) { 15 | int n = i*10+j; 16 | if (n<=num) { 17 | getNums(res,n,num); 18 | } 19 | else { 20 | return; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /406-queue-reconstruction-by-height/406-queue-reconstruction-by-height.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] reconstructQueue(int[][] people) { 3 | // Sort people on descending order of height 4 | // and ascending order of k 5 | Arrays.sort(people, (a,b) -> a[0]==b[0] ? a[1]-b[1] : b[0]-a[0]); 6 | 7 | // Now take one element from array and add it at the kth position 8 | List ordered = new LinkedList<>(); 9 | for (int[] p: people) 10 | ordered.add(p[1], p); 11 | 12 | return ordered.toArray(new int[people.length][2]); 13 | } 14 | } -------------------------------------------------------------------------------- /12-integer-to-roman/12-integer-to-roman.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String intToRoman(int num) { 3 | String dictionary[] = 4 | {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; 5 | int value[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; 6 | 7 | String output = ""; 8 | int i=0; 9 | while (num>0) { 10 | while (num>=value[i]) { 11 | num -= value[i]; 12 | output = output + dictionary[i]; 13 | } 14 | i++; 15 | } 16 | 17 | return output; 18 | } 19 | } -------------------------------------------------------------------------------- /1991-find-the-middle-index-in-array/1991-find-the-middle-index-in-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findMiddleIndex(int[] nums) { 3 | // Find the complete sum of array 4 | int prefixSum = 0; 5 | for (int i=0,size=nums.length;i map = new HashMap<>(); 5 | 6 | for (int i=0;i 1111 17 | lastBit -> 1 for odd numbers and 0 for even numbers 18 | Exclude last bit -> Number becomes 15/2 19 | 20 | i.e 21 | countSetBits[n] = lastBit(1 if set, 0 if unset) + countBits[n/2] 22 | 23 | */ 24 | -------------------------------------------------------------------------------- /724-find-pivot-index/724-find-pivot-index.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int pivotIndex(int[] nums) { 3 | int sumRight = sumOfArray(nums); 4 | int sumLeft = 0; 5 | for (int i=0;i=j) 8 | return true; 9 | 10 | if (s.charAt(i)==s.charAt(j)) 11 | return isPalindrome(s,i+1,j-1,delete); 12 | 13 | if (!delete) // Not deleted any character yet 14 | return isPalindrome(s,i+1,j,true) || isPalindrome(s,i,j-1,true); 15 | 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /686-repeated-string-match/686-repeated-string-match.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int repeatedStringMatch(String a, String b) { 3 | int aLen = a.length(); 4 | int bLen = b.length(); 5 | 6 | int repeat = (int)Math.ceil(bLen*1.0/aLen); 7 | 8 | String temp=""; 9 | for (int i=0;ihigh) { 8 | return -1; 9 | } 10 | 11 | int mid = (low+high)/2; 12 | if (nums[mid]==target) 13 | return mid; 14 | else if (nums[mid]>target) 15 | return binarySearch(nums,target,low,mid-1); 16 | else 17 | return binarySearch(nums,target,mid+1,high); 18 | } 19 | } -------------------------------------------------------------------------------- /264-ugly-number-ii/264-ugly-number-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int nthUglyNumber(int n) { 3 | if(n==1) return 1; 4 | PriorityQueue q = new PriorityQueue(); 5 | q.add(1); 6 | 7 | for(int i=1;i wordDict) { 3 | int n = s.length(); 4 | 5 | // DP array representing whether true or false upto that length 6 | boolean dp[] = new boolean[n+1]; 7 | 8 | dp[0]=true; 9 | 10 | for (int i=1;i<=n;i++) { 11 | for (int j=i-1;j>=0;j--) { 12 | if (dp[j] && wordDict.contains(s.substring(j,i))) { 13 | dp[i]=true; 14 | break; 15 | } 16 | } 17 | } 18 | return dp[n]; 19 | } 20 | } -------------------------------------------------------------------------------- /24-swap-nodes-in-pairs/24-swap-nodes-in-pairs.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode swapPairs(ListNode head) { 13 | if ((head == null)||(head.next == null)) 14 | return head; 15 | ListNode second = head.next; 16 | head.next = swapPairs(head.next.next); 17 | second.next = head; 18 | return second; 19 | } 20 | } -------------------------------------------------------------------------------- /581-shortest-unsorted-continuous-subarray/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findUnsortedSubarray(int[] nums) { 3 | int[] copy = nums.clone(); 4 | Arrays.sort(copy); 5 | 6 | int start = -1; 7 | int end = -1; 8 | for (int i=0;i map = new HashMap<>(); 4 | int count = 0; 5 | for (int t: time) { 6 | int rem = t%60; 7 | if (map.containsKey(60-rem)) { 8 | count += map.get(60-rem); 9 | } 10 | else if (rem==0 && map.containsKey(0)) { 11 | count += map.get(0); 12 | } 13 | map.put(rem,map.getOrDefault(rem,0)+1); 14 | } 15 | return count; 16 | } 17 | } -------------------------------------------------------------------------------- /22-generate-parentheses/22-generate-parentheses.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List generateParenthesis(int n) { 3 | List ans = new ArrayList<>(); 4 | helper(n,0,0,0,"",ans); 5 | return ans; 6 | } 7 | 8 | public void helper(int n,int i, int open,int close,String str,List ans) { 9 | if (i==2*n) { 10 | ans.add(str); 11 | return; 12 | } 13 | 14 | if (open set = new TreeSet<>(); 4 | int a = 1; 5 | int b = 1; 6 | set.add(1); 7 | int c = a+b; 8 | while (c<=k) { 9 | set.add(c); 10 | a=b; 11 | b=c; 12 | c=a+b; 13 | } 14 | 15 | int count = 0; 16 | while (k!=0) { 17 | k -= set.floor(k); 18 | count++; 19 | } 20 | 21 | return count; 22 | } 23 | } -------------------------------------------------------------------------------- /238-product-of-array-except-self/238-product-of-array-except-self.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] productExceptSelf(int[] nums) { 3 | int n=nums.length; 4 | int[] result = new int[n]; 5 | 6 | for (int i=0;i=0;i--) { 18 | result[i]*=suffix; 19 | suffix*=nums[i]; 20 | } 21 | 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /1306-jump-game-iii/1306-jump-game-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canReach(int[] arr, int start) { 3 | boolean visited[] = new boolean[arr.length]; 4 | return helper(arr,start,visited); 5 | } 6 | 7 | private boolean helper(int[] arr,int curr,boolean[] visited) { 8 | if (curr<0 || curr>=arr.length || visited[curr]) 9 | return false; 10 | 11 | if (arr[curr]==0) 12 | return true; 13 | 14 | visited[curr]=true; 15 | boolean x = helper(arr,curr+arr[curr],visited); 16 | boolean y = helper(arr,curr-arr[curr],visited); 17 | 18 | return x|y; 19 | } 20 | } -------------------------------------------------------------------------------- /372-super-pow/372-super-pow.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int MOD = 1337; 3 | 4 | public int superPow(int a, int[] b) { 5 | a%=MOD; 6 | int result = 1; 7 | 8 | for (int digit: b) { 9 | result = (pow(result,10)*pow(a,digit))%MOD; 10 | } 11 | 12 | return result; 13 | } 14 | 15 | private int pow(int x,int n) { 16 | int ans = 1; 17 | while (n!=0) { 18 | int last_bit = (n&1); 19 | if (last_bit==1) 20 | ans = (ans*x)%MOD; 21 | x = (x*x)%MOD; 22 | n = n>>>1; 23 | } 24 | 25 | return ans; 26 | } 27 | } -------------------------------------------------------------------------------- /120-triangle/120-triangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimumTotal(List> triangle) { 3 | int rows = triangle.size(); 4 | 5 | // Move from last second row to top 6 | for (int r=rows-2;r>=0;r--) { 7 | List curr = triangle.get(r); 8 | List next = triangle.get(r+1); 9 | 10 | int size = curr.size(); 11 | for (int i=0;i0 8 | while (n!=0) { 9 | n = n&(n-1); // Removes the last set bit 10 | ans++; 11 | } 12 | return ans; 13 | } 14 | } -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int jump(int[] nums) { 3 | int jumps = 0; 4 | int current = 0; 5 | int farthest = 0; // Farthest index where you can reach 6 | 7 | for (int i=0;i prefixSum = new HashMap<>(); 6 | prefixSum.put(0,1); // Prefix sum 0 - subarray with no elements 7 | 8 | int sum = 0; 9 | for (int i=0;itarget) 11 | high=mid-1; 12 | else 13 | low=mid+1; 14 | } 15 | 16 | return letters[low%letters.length]; 17 | } 18 | } -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/104-maximum-depth-of-binary-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public int maxDepth(TreeNode root) { 18 | if (root==null) 19 | return 0; 20 | return 1+Math.max(maxDepth(root.left), maxDepth(root.right)); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /1209-remove-all-adjacent-duplicates-in-string-ii/1209-remove-all-adjacent-duplicates-in-string-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeDuplicates(String s, int k) { 3 | int i = 0; 4 | int n = s.length(); 5 | int[] count = new int[n]; 6 | char[] copy = s.toCharArray(); 7 | for (int j=0;j0 && copy[i-1]==copy[j]) { 11 | count[i] = count[i-1]+1; 12 | } 13 | 14 | if (count[i]==k) { 15 | i-=k; 16 | } 17 | } 18 | 19 | return new String(copy,0,i); 20 | } 21 | } -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/876-middle-of-the-linked-list.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode middleNode(ListNode head) { 13 | ListNode slow = head; 14 | ListNode fast = head; 15 | 16 | while (fast!=null && fast.next!=null) { 17 | slow=slow.next; 18 | fast=fast.next.next; 19 | } 20 | 21 | return slow; 22 | } 23 | } -------------------------------------------------------------------------------- /1963-minimum-number-of-swaps-to-make-the-string-balanced/1963-minimum-number-of-swaps-to-make-the-string-balanced.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minSwaps(String s) { 3 | int swaps = 0; 4 | int close = 0; // close brackets 5 | for (char ch: s.toCharArray()) { 6 | if (ch==']') 7 | close++; 8 | else if (ch=='[') 9 | close--; 10 | 11 | // Swaps stores the maximum no of close brackets at a time 12 | swaps = Math.max(swaps,close); 13 | } 14 | 15 | // By swapping one bracket, two close brackets are managed 16 | return (swaps+1)/2; 17 | } 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /203-remove-linked-list-elements/203-remove-linked-list-elements.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode removeElements(ListNode head, int val) { 13 | if (head==null) 14 | return head; 15 | 16 | if (head.val==val) 17 | return removeElements(head.next,val); 18 | 19 | head.next = removeElements(head.next,val); 20 | return head; 21 | } 22 | } -------------------------------------------------------------------------------- /66-plus-one/66-plus-one.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] plusOne(int[] digits) { 3 | int ans[] = new int[digits.length]; 4 | int carry = 1; 5 | for (int i=digits.length-1;i>=0;i--) { 6 | if (digits[i]!=9 && carry==1) { 7 | ans[i]=digits[i]+carry; 8 | carry=0; 9 | } 10 | else if (carry==0) { 11 | ans[i]=digits[i]; 12 | } 13 | else { 14 | ans[i]=0; 15 | } 16 | } 17 | 18 | if (carry==1) { 19 | ans = new int[digits.length+1]; 20 | ans[0]=1; 21 | } 22 | 23 | return ans; 24 | } 25 | } -------------------------------------------------------------------------------- /152-maximum-product-subarray/152-maximum-product-subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProduct(int[] nums) { 3 | int max = nums[0]; //max product so far 4 | int min = nums[0]; //min product so far 5 | int ans = max; 6 | 7 | for (int i=1;i grayCode(int n) { 3 | List ans = new ArrayList<>(); 4 | 5 | int[] dp = new int[(int)Math.pow(2,n)]; 6 | dp[0]=0; 7 | dp[1]=1; 8 | for (int i=2;i<=n;i++) { 9 | int start = (int)Math.pow(2,i-1); 10 | int end = (int)Math.pow(2,i); 11 | int curr = 0; 12 | for (int k=end-1;k>=start;k--) { 13 | dp[k] = dp[curr]+start; 14 | curr++; 15 | } 16 | } 17 | 18 | for (int i=0;i22. Generate Parentheses

Medium


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

2 | 3 |

 

4 |

Example 1:

5 |
Input: n = 3
 6 | Output: ["((()))","(()())","(())()","()(())","()()()"]
 7 | 

Example 2:

8 |
Input: n = 1
 9 | Output: ["()"]
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= n <= 8
  • 16 |
17 |
-------------------------------------------------------------------------------- /62-unique-paths/62-unique-paths.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int uniquePaths(int m, int n) { 3 | // Dp array representing no of paths starting from that point (i,j) to finish 4 | int dp[][] = new int[m][n]; 5 | 6 | for (int i=m-1;i>=0;i--) { 7 | for(int j=n-1;j>=0;j--) { 8 | if (i==m-1 && j==n-1) { 9 | dp[i][j] = 1; 10 | } 11 | else { 12 | int t1 = (i+1)> combine(int n, int k) { 3 | List> ans = new ArrayList<>(); 4 | getCombinations(ans,n,1,k,new ArrayList<>()); 5 | return ans; 6 | } 7 | 8 | private void getCombinations(List> ans,int n, 9 | int index,int k,List temp) { 10 | if (k==0) { 11 | ans.add(temp); 12 | return; 13 | } 14 | 15 | for (int i=index;i<=n-k+1;i++) { 16 | temp.add(i); 17 | getCombinations(ans,n,i+1,k-1,new ArrayList<>(temp)); 18 | temp.remove(temp.size()-1); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /974-subarray-sums-divisible-by-k/974-subarray-sums-divisible-by-k.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int subarraysDivByK(int[] nums, int k) { 3 | // Stores remainder of prefix sum with k in array 4 | HashMap map = new HashMap<>(); 5 | 6 | int sum = 0; 7 | int count = 0; 8 | map.put(0,1); // remainder of sum 0 with k is 0 9 | for (int num: nums) { 10 | sum = sum+num; 11 | int rem = sum%k<0 ? sum%k+k : sum%k; 12 | if (map.containsKey(rem)) { 13 | count += map.get(rem); 14 | } 15 | map.put(rem,map.getOrDefault(rem,0)+1); 16 | } 17 | 18 | return count; 19 | } 20 | } -------------------------------------------------------------------------------- /1004-max-consecutive-ones-iii/1004-max-consecutive-ones-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestOnes(int[] nums, int k) { 3 | int n = nums.length; 4 | int max = 0; 5 | 6 | // Sliding window approach 7 | int start = 0; 8 | int count = 0; // Int zeroes count 9 | for (int end=0;endtarget) { 16 | right--; 17 | } 18 | else { 19 | left++; 20 | } 21 | } 22 | 23 | return ans; 24 | } 25 | } -------------------------------------------------------------------------------- /1220-count-vowels-permutation/1220-count-vowels-permutation.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int MOD = 1000000007; 3 | public int countVowelPermutation(int n) { 4 | int a=1; 5 | int e=1; 6 | int i=1; 7 | int o=1; 8 | int u=1; 9 | 10 | for (int p=2;p<=n;p++) { 11 | int newa = ((e+i)%MOD+u)%MOD; 12 | int newe = (a+i)%MOD; 13 | int newi = (e+o)%MOD; 14 | int newo = i; 15 | int newu = (i+o)%MOD; 16 | 17 | a = newa; 18 | e = newe; 19 | i = newi; 20 | o = newo; 21 | u = newu; 22 | } 23 | 24 | return (((((a+e)%MOD+i)%MOD)+o)%MOD+u)%MOD; 25 | } 26 | } -------------------------------------------------------------------------------- /204-count-primes/204-count-primes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countPrimes(int n) { 3 | // Using sieve of erastosthones 4 | boolean[] prime = new boolean[n]; 5 | Arrays.fill(prime,true); 6 | 7 | for (int i=2;i> rooms) { 3 | int n = rooms.size(); // No of rooms 4 | boolean[] visited = new boolean[n]; 5 | 6 | //DFS 7 | dfs(rooms,visited,0); 8 | 9 | for (int i=0;i> rooms,boolean[] visited,int currRoom) { 18 | visited[currRoom]=true; 19 | for (Integer r: rooms.get(currRoom)) { 20 | if (!visited[r]) 21 | dfs(rooms,visited,r); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /135-candy/135-candy.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int candy(int[] ratings) { 3 | int n = ratings.length; 4 | int candy[] = new int[n]; 5 | Arrays.fill(candy,1); 6 | 7 | for (int i=1;iratings[i-1] && candy[i]<=candy[i-1]) { 9 | candy[i] = candy[i-1]+1; 10 | } 11 | } 12 | 13 | for (int i=n-2;i>=0;i--) { 14 | if (ratings[i]>ratings[i+1] && candy[i]<=candy[i+1]) { 15 | candy[i] = candy[i+1]+1; 16 | } 17 | } 18 | 19 | int candies=0; 20 | for (int c: candy) { 21 | candies += c; 22 | } 23 | 24 | return candies; 25 | } 26 | } -------------------------------------------------------------------------------- /160-intersection-of-two-linked-lists/160-intersection-of-two-linked-lists.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode(int x) { 7 | * val = x; 8 | * next = null; 9 | * } 10 | * } 11 | */ 12 | public class Solution { 13 | public ListNode getIntersectionNode(ListNode headA, ListNode headB) { 14 | ListNode currA = headA; 15 | ListNode currB = headB; 16 | while (currA!=currB) { 17 | currA = currA==null ? headB : currA.next; // List A -> null -> List B 18 | currB = currB==null ? headA : currB.next; // List B -> null -> List A 19 | } 20 | 21 | return currA; 22 | } 23 | } -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removePalindromeSub(String s) { 3 | return isPalindrome(s) ? 1 : 2; 4 | } 5 | 6 | public boolean isPalindrome(String s) { 7 | int n = s.length(); 8 | for (int i=0;i912. Sort an Array

Medium


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

2 | 3 |

 

4 |

Example 1:

5 |
Input: nums = [5,2,3,1]
 6 | Output: [1,2,3,5]
 7 | 

Example 2:

8 |
Input: nums = [5,1,1,2,0,0]
 9 | Output: [0,0,1,1,2,5]
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= nums.length <= 5 * 104
  • 16 |
  • -5 * 104 <= nums[i] <= 5 * 104
  • 17 |
18 |
-------------------------------------------------------------------------------- /1005-maximize-sum-of-array-after-k-negations/1005-maximize-sum-of-array-after-k-negations.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int largestSumAfterKNegations(int[] nums, int k) { 3 | Arrays.sort(nums); 4 | 5 | for (int i=0;i0) 7 | break; 8 | if (nums[i]<0) { 9 | nums[i]=-nums[i]; 10 | k--; 11 | } 12 | } 13 | 14 | int sum = 0; 15 | int min = Integer.MAX_VALUE; 16 | for (int num: nums) { 17 | sum += num; 18 | min = Math.min(min,num); 19 | } 20 | 21 | if (k%2!=0) 22 | sum -= 2*min; 23 | 24 | return sum; 25 | } 26 | } -------------------------------------------------------------------------------- /29-divide-two-integers/29-divide-two-integers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int divide(int dividend, int divisor) { 3 | int quotient=0; 4 | int sign = (dividend>=0) == (divisor>=0) ? 1:-1; 5 | 6 | if (dividend==Integer.MIN_VALUE && divisor==-1) 7 | return Integer.MAX_VALUE; 8 | 9 | dividend=Math.abs(dividend); 10 | divisor=Math.abs(divisor); 11 | 12 | while (dividend-divisor>=0) { 13 | int count=0; 14 | while (dividend - (divisor<<1<= 0) { 15 | count++; 16 | } 17 | quotient += 1<n) 20 | high=(int)mid-1; 21 | else 22 | low=(int)mid+1; 23 | } 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /14-longest-common-prefix/14-longest-common-prefix.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String longestCommonPrefix(String[] strs) { 3 | String output = ""; 4 | 5 | for (int index=0,len=strs[0].length();index=temp.length()) 11 | return output; 12 | 13 | if (temp.charAt(index)!=ch) 14 | flag = false; 15 | } 16 | if (!flag) 17 | return output; 18 | output = output+ch; 19 | } 20 | return output; 21 | } 22 | } -------------------------------------------------------------------------------- /1539-kth-missing-positive-number/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findKthPositive(int[] arr, int k) { 3 | int n = arr.length; 4 | int diffs[] = new int[n]; 5 | diffs[0] = arr[0]-1; 6 | for (int i=1;itarget) 13 | high--; 14 | else 15 | low++; 16 | 17 | if (Math.abs(current_sum-target)>1; 15 | right=right>>1; 16 | shift++; 17 | } 18 | 19 | return left<p.val && root.val>q.val) 15 | return lowestCommonAncestor(root.left,p,q); 16 | 17 | // If both p and q larger than root 18 | if(root.valInteger.MAX_VALUE/10 || 17 | (reverse==Integer.MAX_VALUE/10 && rem>7)) 18 | return 0; 19 | if (reverse0 12 | 13 | for (int i=2;i<=n;i++) { 14 | if (s.charAt(i-1)>'0'){ 15 | dp[i] = dp[i-1]; 16 | } 17 | 18 | if(s.charAt(i-2)=='1' || s.charAt(i-2)=='2' && s.charAt(i-1)<'7') { 19 | dp[i] += dp[i-2]; 20 | } 21 | } 22 | 23 | return dp[n]; 24 | } 25 | } -------------------------------------------------------------------------------- /740-delete-and-earn/740-delete-and-earn.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int deleteAndEarn(int[] nums) { 3 | HashMap points = new HashMap<>(); 4 | int maxNum = 0; 5 | for (int i: nums) { 6 | points.put(i,points.getOrDefault(i,0)+i); 7 | maxNum=Math.max(maxNum,i); 8 | } 9 | 10 | // dp[i] stores max points that can be achieved using 0 to i 11 | int dp[] = new int[maxNum+1]; 12 | dp[0] = 0; 13 | dp[1] = points.getOrDefault(1,0); // Count of occurences of 1 14 | 15 | for (int i=2;i set = new HashSet<>(); 4 | for (int num: nums) { 5 | set.add(num); 6 | } 7 | 8 | int maxLen = 0; 9 | for (int num: nums) { 10 | if (!set.contains(num-1)) { 11 | int currentlen = 1; 12 | 13 | int current = num; 14 | while (set.contains(current+1)) { 15 | currentlen++; 16 | current=current+1; 17 | } 18 | 19 | maxLen = Math.max(maxLen,currentlen); 20 | } 21 | } 22 | 23 | return maxLen; 24 | } 25 | } -------------------------------------------------------------------------------- /739-daily-temperatures/739-daily-temperatures.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] dailyTemperatures(int[] temperatures) { 3 | int n = temperatures.length; 4 | 5 | // Similar to Next greater element 6 | int answer[] = new int[n]; 7 | Stack s = new Stack<>(); 8 | s.push(0); // Push Index 0 9 | 10 | for (int i=1;i set = new HashSet<>(); // Store different frequencies 10 | for (int i=0;i<26;i++) { 11 | if (freq[i]==0) 12 | continue; 13 | 14 | if (!set.add(freq[i])) { 15 | while (freq[i]!=0 && !set.add(freq[i])) { 16 | freq[i]--; 17 | ans++; 18 | } 19 | } 20 | } 21 | 22 | return ans; 23 | } 24 | } -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/349-intersection-of-two-arrays.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] intersection(int[] nums1, int[] nums2) { 3 | 4 | // Stores all values inside nums2 5 | HashSet vals = new HashSet<>(); 6 | for (int i=0,len=nums2.length;i intersections = new HashSet<>(); 11 | for (int i=0,len=nums1.length;ival) 22 | return searchBST(root.left,val); 23 | else 24 | return searchBST(root.right,val); 25 | } 26 | } -------------------------------------------------------------------------------- /55-jump-game/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int dp[] = new int[nums.length]; 4 | Arrays.fill(dp,-1); 5 | return helper(nums,0,dp); 6 | } 7 | 8 | private boolean helper(int[] nums,int index,int[] dp) { 9 | if (index>=nums.length) 10 | return false; 11 | 12 | if (index==nums.length-1) 13 | return true; 14 | 15 | if (dp[index]!=-1) { 16 | return dp[index]==1; 17 | } 18 | 19 | for (int i=1;i<=nums[index];i++) { 20 | if (helper(nums,index+i,dp)) { 21 | dp[index]=1; 22 | return true; 23 | } 24 | } 25 | 26 | dp[index]=0; 27 | return false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /633-sum-of-square-numbers/README.md: -------------------------------------------------------------------------------- 1 |

633. Sum of Square Numbers

Medium


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

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: c = 5
 7 | Output: true
 8 | Explanation: 1 * 1 + 2 * 2 = 5
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: c = 3
14 | Output: false
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 0 <= c <= 231 - 1
  • 22 |
23 |
-------------------------------------------------------------------------------- /118-pascals-triangle/118-pascals-triangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> generate(int numRows) { 3 | List> ans = new ArrayList<>(); 4 | for (int i=1;i<=numRows;i++) { 5 | List row = new ArrayList<>(); 6 | if (i==1) 7 | row.add(1); 8 | else { 9 | for (int j=0;j q = new LinkedList<>(); 7 | q.add(0); 8 | int farthest=0; // Farthest index we reached till now 9 | 10 | while (!q.isEmpty()) { 11 | int curr = q.poll(); 12 | if (curr==n-1) 13 | return true; 14 | 15 | int start = Math.max(curr+minJump,farthest); 16 | int end = Math.min(curr+maxJump,n-1); 17 | for (int i=start;i<=end;i++) { 18 | if (s.charAt(i)=='0') 19 | q.add(i); 20 | } 21 | farthest=end+1; 22 | } 23 | 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /400-nth-digit/400-nth-digit.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findNthDigit(int n) { 3 | long digits = 9; 4 | int first = 1; 5 | int length = 1; 6 | while (n > length*digits) { 7 | n -= length*digits; 8 | length++; 9 | first *= 10; 10 | digits *= 10; 11 | } 12 | 13 | 14 | 15 | // First now points to first kth digit number (1,10,100,1000....etc) 16 | // where nth digit lies in a k digit number 17 | 18 | first = first + (n-1)/length; 19 | 20 | // First now points to the number which contains the nth digit 21 | 22 | String num = Integer.toString(first); 23 | char digit = num.charAt((n-1)%length); 24 | 25 | return digit-'0'; 26 | } 27 | } -------------------------------------------------------------------------------- /729-my-calendar-i/729-my-calendar-i.java: -------------------------------------------------------------------------------- 1 | class MyCalendar { 2 | TreeMap map = new TreeMap<>(); 3 | 4 | public MyCalendar() { 5 | 6 | } 7 | 8 | public boolean book(int start, int end) { 9 | Integer floor = map.floorKey(start); 10 | Integer ceil = map.ceilingKey(start); 11 | if (floor!=null) { 12 | if (map.get(floor)>end || map.get(floor)>start) 13 | return false; 14 | } 15 | if (ceil!=null) { 16 | if (end>ceil) 17 | return false; 18 | } 19 | map.put(start,end); 20 | return true; 21 | } 22 | } 23 | 24 | /** 25 | * Your MyCalendar object will be instantiated and called as such: 26 | * MyCalendar obj = new MyCalendar(); 27 | * boolean param_1 = obj.book(start,end); 28 | */ -------------------------------------------------------------------------------- /202-happy-number/202-happy-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isHappy(int n) { 3 | if (n==1) 4 | return true; 5 | 6 | HashSet visited = new HashSet<>(); 7 | visited.add(n); 8 | 9 | int current = n; 10 | while(true) { 11 | current = getDigitSquareSum(current); 12 | if (current==1) 13 | return true; 14 | 15 | if (!visited.add(current)) 16 | break; 17 | } 18 | 19 | return false; 20 | } 21 | 22 | private int getDigitSquareSum(int n) { 23 | int result = 0; 24 | while (n!=0) { 25 | int rem = n%10; 26 | n = n/10; 27 | result += rem*rem; 28 | } 29 | return result; 30 | } 31 | } -------------------------------------------------------------------------------- /226-invert-binary-tree/226-invert-binary-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode invertTree(TreeNode root) { 18 | if (root==null) 19 | return null; 20 | 21 | TreeNode left = root.left; 22 | TreeNode right = root.right; 23 | 24 | root.left = invertTree(right); 25 | root.right = invertTree(left); 26 | 27 | return root; 28 | } 29 | } -------------------------------------------------------------------------------- /73-set-matrix-zeroes/73-set-matrix-zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void setZeroes(int[][] matrix) { 3 | int m = matrix.length; 4 | int n = matrix[0].length; 5 | 6 | // Determine which rows and columns to update 7 | boolean[] rows = new boolean[m]; 8 | boolean[] cols = new boolean[n]; 9 | 10 | for (int i=0;i> groupAnagrams(String[] strs) { 3 | List> list = new ArrayList<>(); 4 | HashMap> map = new HashMap<>(); 5 | 6 | for(String i : strs){ 7 | char[] ch = i.toCharArray(); 8 | Arrays.sort(ch); 9 | String s = new String(ch); 10 | 11 | if(map.containsKey(s)){ 12 | map.get(s).add(i); 13 | } 14 | else{ 15 | List temp = new ArrayList<>(); 16 | temp.add(i); 17 | map.put(s,temp); 18 | } 19 | } 20 | 21 | for(String i : map.keySet()){ 22 | list.add(map.get(i)); 23 | } 24 | return list; 25 | } 26 | } -------------------------------------------------------------------------------- /64-minimum-path-sum/64-minimum-path-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPathSum(int[][] grid) { 3 | int m = grid.length; 4 | int n = grid[0].length; 5 | 6 | // Update grid to store maximum values- dp 7 | for (int i=0;i map = new HashMap<>(); 4 | for (int num: arr) { 5 | map.put(num,map.getOrDefault(num,0)+1); 6 | } 7 | 8 | List l=new ArrayList<>(); 9 | for (Map.Entry e: map.entrySet()) { 10 | l.add(e.getValue()); 11 | } 12 | 13 | Collections.sort(l,Collections.reverseOrder()); 14 | 15 | int count = 0; 16 | int target = arr.length/2; 17 | int i = 0; 18 | while (target>0 && !l.isEmpty()) { 19 | int curr = l.get(i++); 20 | count++; 21 | target -= curr; 22 | } 23 | 24 | return count; 25 | } 26 | } -------------------------------------------------------------------------------- /141-linked-list-cycle/141-linked-list-cycle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode(int x) { 7 | * val = x; 8 | * next = null; 9 | * } 10 | * } 11 | */ 12 | public class Solution { 13 | public boolean hasCycle(ListNode head) { 14 | if (head==null) 15 | return false; 16 | 17 | // Using floyd cycle detection algorithm 18 | ListNode slow = head; 19 | ListNode fast = head; 20 | 21 | while (fast!=null && fast.next!=null) { 22 | slow = slow.next; 23 | fast = fast.next.next; 24 | 25 | if (slow==fast) { 26 | return true; 27 | } 28 | } 29 | 30 | return false; 31 | } 32 | } -------------------------------------------------------------------------------- /119-pascals-triangle-ii/119-pascals-triangle-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List getRow(int rowIndex) { 3 | List> temp = new ArrayList<>(); 4 | for (int i=0;i<=rowIndex;i++) { 5 | List row = new ArrayList<>(); 6 | if (i==0) 7 | row.add(1); 8 | else { 9 | List x = temp.get(i-1); 10 | for (int j=0;j<=i;j++) { 11 | if (j==0) 12 | row.add(x.get(0)); 13 | else if (j==i) 14 | row.add(x.get(j-1)); 15 | else 16 | row.add(x.get(j-1)+x.get(j)); 17 | } 18 | } 19 | temp.add(row); 20 | } 21 | 22 | return temp.get(rowIndex); 23 | } 24 | } -------------------------------------------------------------------------------- /189-rotate-array/189-rotate-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[] nums, int k) { 3 | k = k%(nums.length); // Reduce k if k>=length of array 4 | 5 | if (k==0) 6 | return; 7 | 8 | // Reverse the complete array 9 | reverseArray(nums,0,nums.length-1); 10 | 11 | // Reverse the first k elements and then reverse the remaining elements 12 | reverseArray(nums,0,k-1); 13 | reverseArray(nums,k,nums.length-1); 14 | } 15 | 16 | public void reverseArray(int[] nums,int startIndex,int endIndex) { 17 | while(startIndex5. Longest Palindromic Substring

Medium


Given a string s, return the longest palindromic substring in s.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: s = "babad"
 7 | Output: "bab"
 8 | Explanation: "aba" is also a valid answer.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: s = "cbbd"
14 | Output: "bb"
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 1 <= s.length <= 1000
  • 22 |
  • s consist of only digits and English letters.
  • 23 |
24 |
-------------------------------------------------------------------------------- /Maximum difference of zeros and ones in binary string - GFG/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int maxSubstring(String S) { 3 | // Understand 0 as 1 4 | // and 1 as -1 5 | // Find maximum subarray sum in array 6 | // Kadane algorithm 7 | 8 | int maxDiff = -1; 9 | 10 | int runningSum = 0; 11 | for (int i=0;i0) 19 | runningSum += val; 20 | else 21 | runningSum = val; 22 | 23 | maxDiff = Math.max(runningSum,maxDiff); 24 | } 25 | 26 | return maxDiff; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /260-single-number-iii/260-single-number-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] singleNumber(int[] nums) { 3 | int num1=0,num2=0; 4 | int xor=0; // represents xor of all numbers 5 | for (int i=0;i>1; 14 | pos++; 15 | } 16 | 17 | // Mask with pos bit set to 1 18 | int mask = 1<0) 22 | num1 = num1^nums[i]; 23 | } 24 | 25 | num2 = num1^xor; 26 | 27 | return new int[]{num1,num2}; 28 | } 29 | } -------------------------------------------------------------------------------- /386-lexicographical-numbers/README.md: -------------------------------------------------------------------------------- 1 |

386. Lexicographical Numbers

Medium


Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

2 | 3 |

You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

4 | 5 |

 

6 |

Example 1:

7 |
Input: n = 13
 8 | Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]
 9 | 

Example 2:

10 |
Input: n = 2
11 | Output: [1,2]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= n <= 5 * 104
  • 18 |
19 |
-------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode deleteDuplicates(ListNode head) { 13 | if (head==null || head.next==null) 14 | return head; 15 | 16 | ListNode curr = head; 17 | while (curr.next!=null) { 18 | if (curr.next.val==curr.val) { 19 | curr.next=curr.next.next; 20 | } 21 | else { 22 | curr=curr.next; 23 | } 24 | } 25 | 26 | return head; 27 | } 28 | } -------------------------------------------------------------------------------- /1695-maximum-erasure-value/1695-maximum-erasure-value.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximumUniqueSubarray(int[] nums) { 3 | // Map to store number and its last index in array 4 | HashMap hm = new HashMap<>(); 5 | 6 | int start=0; 7 | int score=0; 8 | int runningSum=0; 9 | for (int end=0,size=nums.length;end=nums.length) 10 | return Integer.MAX_VALUE; 11 | 12 | if (index==nums.length-1) 13 | return 0; 14 | 15 | if (dp[index]!=-1) 16 | return dp[index]; 17 | 18 | int curr = nums[index]; 19 | int minMoves = Integer.MAX_VALUE; 20 | for (int i=1;i<=curr;i++) { 21 | int h = helper(nums,index+i,dp); 22 | if (h!=Integer.MAX_VALUE) 23 | minMoves = Math.min(minMoves,1+h); 24 | } 25 | 26 | return dp[index]=minMoves; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /701-insert-into-a-binary-search-tree/701-insert-into-a-binary-search-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode insertIntoBST(TreeNode root, int val) { 18 | if (root==null) 19 | return new TreeNode(val); 20 | 21 | if (root.val>val) 22 | root.left = insertIntoBST(root.left,val); 23 | else 24 | root.right = insertIntoBST(root.right,val); 25 | 26 | return root; 27 | } 28 | } -------------------------------------------------------------------------------- /343-integer-break/343-integer-break.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int integerBreak(int n) { 3 | 4 | // dp[i] represnets the maximum product for integer i 5 | int dp[] = new int[n+1]; 6 | Arrays.fill(dp,Integer.MIN_VALUE); 7 | 8 | for (int i=2;i<=n;i++) { 9 | for (int j=1;j> subsets(int[] nums) { 3 | List> list= new ArrayList<>(); 4 | 5 | // No of subsets possible: 2^N where N is size of array 6 | int n = nums.length; 7 | 8 | int subsets = 1< getSubset(int i,int nums[]) { 17 | List a = new ArrayList<>(); 18 | 19 | int j=0; 20 | while (i>0) { 21 | int lastBit = (i&1); 22 | if (lastBit==1) { 23 | a.add(nums[j]); 24 | } 25 | j++; 26 | i = i>>1; 27 | } 28 | 29 | return a; 30 | } 31 | } -------------------------------------------------------------------------------- /797-all-paths-from-source-to-target/797-all-paths-from-source-to-target.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> allPathsSourceTarget(int[][] graph) { 3 | int n = graph.length; 4 | List> ans = new ArrayList<>(); 5 | List path = new ArrayList<>(); 6 | path.add(0); 7 | dfs(graph,ans,0,n-1,path); 8 | return ans; 9 | } 10 | 11 | private void dfs(int[][] graph,List> ans,int src, 12 | int dst,List path) { 13 | if (src==dst) { 14 | ans.add(new ArrayList<>(path)); 15 | return; 16 | } 17 | 18 | for (int neighbor: graph[src]) { 19 | path.add(neighbor); 20 | dfs(graph,ans,neighbor,dst,path); 21 | path.remove(path.size()-1); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/111-minimum-depth-of-binary-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public int minDepth(TreeNode root) { 18 | if (root==null) 19 | return 0; 20 | 21 | if (root.left==null) 22 | return 1+minDepth(root.right); 23 | else if (root.right==null) 24 | return 1+minDepth(root.left); 25 | 26 | return 1 + Math.min(minDepth(root.left),minDepth(root.right)); 27 | } 28 | } -------------------------------------------------------------------------------- /1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int mod = (int)1e9+7; 3 | public int numRollsToTarget(int n, int k, int target) { 4 | int dp[][] = new int[n+1][target+1]; 5 | for (int i=0;i400. Nth Digit

Medium


Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 3
 7 | Output: 3
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: n = 11
13 | Output: 0
14 | Explanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 1 <= n <= 231 - 1
  • 22 |
23 |
-------------------------------------------------------------------------------- /409-longest-palindrome/409-longest-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestPalindrome(String s) { 3 | int freq[] = new int[52]; 4 | for (char ch : s.toCharArray()) { 5 | if (Character.isUpperCase(ch)) { 6 | freq[ch-'A']++; 7 | } 8 | else { 9 | freq[26+ch-'a']++; 10 | } 11 | } 12 | 13 | int ans = 0; 14 | boolean containsOdd = false; 15 | 16 | for (int i=0;i<52;i++) { 17 | if (freq[i]%2==0) { 18 | // Even 19 | ans = ans + freq[i]; 20 | } 21 | else { 22 | ans = ans + freq[i] - 1; 23 | containsOdd=true; 24 | } 25 | } 26 | 27 | ans = ans + (containsOdd ? 1 : 0); 28 | return ans; 29 | } 30 | } -------------------------------------------------------------------------------- /59-spiral-matrix-ii/README.md: -------------------------------------------------------------------------------- 1 |

59. Spiral Matrix II

Medium


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

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 3
 7 | Output: [[1,2,3],[8,9,4],[7,6,5]]
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: n = 1
13 | Output: [[1]]
14 | 
15 | 16 |

 

17 |

Constraints:

18 | 19 |
    20 |
  • 1 <= n <= 20
  • 21 |
22 |
-------------------------------------------------------------------------------- /209-minimum-size-subarray-sum/209-minimum-size-subarray-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minSubArrayLen(int target, int[] nums) { 3 | int n = nums.length; 4 | 5 | int start=0; 6 | int end=0; 7 | 8 | int minLen = Integer.MAX_VALUE; 9 | int runningSum=0; 10 | while (end=target) { 16 | while (start<=end && runningSum>=target) { 17 | minLen=Math.min(minLen,end-start+1); 18 | runningSum-=nums[start]; 19 | start++; 20 | } 21 | end++; 22 | } 23 | } 24 | 25 | return minLen==Integer.MAX_VALUE ? 0 : minLen; 26 | } 27 | } -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[][] matrix) { 3 | int n = matrix[0].length; 4 | 5 | // Finding tranpose of matrix 6 | for (int i=0;i539. Minimum Time Difference

Medium


Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list. 2 |

 

3 |

Example 1:

4 |
Input: timePoints = ["23:59","00:00"]
 5 | Output: 1
 6 | 

Example 2:

7 |
Input: timePoints = ["00:00","23:59","00:00"]
 8 | Output: 0
 9 | 
10 |

 

11 |

Constraints:

12 | 13 |
    14 |
  • 2 <= timePoints.length <= 2 * 104
  • 15 |
  • timePoints[i] is in the format "HH:MM".
  • 16 |
17 |
-------------------------------------------------------------------------------- /216-combination-sum-iii/216-combination-sum-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> combinationSum3(int k, int n) { 3 | List> ans = new ArrayList<>(); 4 | helper(ans,k,n,1,new ArrayList<>()); 5 | return ans; 6 | } 7 | 8 | private void helper(List> ans,int k,int target, 9 | int start,List temp) { 10 | if (k==0 && target==0) { 11 | ans.add(temp); 12 | return; 13 | } 14 | 15 | if (k==0 || target==0) { 16 | return; 17 | } 18 | 19 | for (int i=start;i<=9;i++) { 20 | if (target-i>=0) { 21 | temp.add(i); 22 | helper(ans,k-1,target-i,i+1,new ArrayList<>(temp)); 23 | temp.remove(temp.size()-1); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /31-next-permutation/31-next-permutation.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void nextPermutation(int[] nums) { 3 | int temp; 4 | int index=nums.length-1; 5 | while (index>0 && nums[index]<=nums[index-1]) 6 | index--; 7 | index=index-1; //Index is -1 in case of descending order array 8 | 9 | if (index>=0) { 10 | int j=nums.length-1; 11 | while (nums[index]>=nums[j]) 12 | j--; 13 | swap(nums,index,j); 14 | } 15 | 16 | // Reverse array after index i.e index+1 17 | int start=index+1; 18 | int end=nums.length-1; 19 | while (start67. Add Binary

Easy


Given two binary strings a and b, return their sum as a binary string.

2 | 3 |

 

4 |

Example 1:

5 |
Input: a = "11", b = "1"
 6 | Output: "100"
 7 | 

Example 2:

8 |
Input: a = "1010", b = "1011"
 9 | Output: "10101"
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= a.length, b.length <= 104
  • 16 |
  • a and b consist only of '0' or '1' characters.
  • 17 |
  • Each string does not contain leading zeros except for the zero itself.
  • 18 |
19 |
-------------------------------------------------------------------------------- /90-subsets-ii/README.md: -------------------------------------------------------------------------------- 1 |

90. Subsets II

Medium


Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

2 | 3 |

The solution set must not contain duplicate subsets. Return the solution in any order.

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [1,2,2]
 8 | Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
 9 | 

Example 2:

10 |
Input: nums = [0]
11 | Output: [[],[0]]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= nums.length <= 10
  • 18 |
  • -10 <= nums[i] <= 10
  • 19 |
20 |
-------------------------------------------------------------------------------- /47-permutations-ii/README.md: -------------------------------------------------------------------------------- 1 |

47. Permutations II

Medium


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

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: nums = [1,1,2]
 7 | Output:
 8 | [[1,1,2],
 9 |  [1,2,1],
10 |  [2,1,1]]
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [1,2,3]
16 | Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= nums.length <= 8
  • 24 |
  • -10 <= nums[i] <= 10
  • 25 |
26 |
-------------------------------------------------------------------------------- /767-reorganize-string/README.md: -------------------------------------------------------------------------------- 1 |

767. Reorganize String

Medium


Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

2 | 3 |

Return any possible rearrangement of s or return "" if not possible.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "aab"
 8 | Output: "aba"
 9 | 

Example 2:

10 |
Input: s = "aaab"
11 | Output: ""
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= s.length <= 500
  • 18 |
  • s consists of lowercase English letters.
  • 19 |
20 |
-------------------------------------------------------------------------------- /179-largest-number/README.md: -------------------------------------------------------------------------------- 1 |

179. Largest Number

Medium


Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

2 | 3 |

Since the result may be very large, so you need to return a string instead of an integer.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [10,2]
 9 | Output: "210"
10 | 
11 | 12 |

Example 2:

13 | 14 |
Input: nums = [3,30,34,5,9]
15 | Output: "9534330"
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • 1 <= nums.length <= 100
  • 23 |
  • 0 <= nums[i] <= 109
  • 24 |
25 |
-------------------------------------------------------------------------------- /357-count-numbers-with-unique-digits/README.md: -------------------------------------------------------------------------------- 1 |

357. Count Numbers with Unique Digits

Medium


Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 2
 7 | Output: 91
 8 | Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: n = 0
14 | Output: 1
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 0 <= n <= 8
  • 22 |
23 |
-------------------------------------------------------------------------------- /71-simplify-path/71-simplify-path.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String simplifyPath(String path) { 3 | String[] tokens = path.split("/"); 4 | Stack s = new Stack<>(); 5 | 6 | for (int i=0;i> subsetsWithDup(int[] nums) { 3 | // No of subsets possible: 2^N where N is size of array 4 | int n = nums.length; 5 | 6 | int subsets = 1<> res = new HashSet<>(); 8 | 9 | for (int i=0;i(res); 13 | } 14 | 15 | public List getSubset(int i,int nums[]) { 16 | List a = new ArrayList<>(); 17 | 18 | int j=0; 19 | while (i>0) { 20 | int lastBit = (i&1); 21 | if (lastBit==1) { 22 | a.add(nums[j]); 23 | } 24 | j++; 25 | i = i>>1; 26 | } 27 | Collections.sort(a); 28 | return a; 29 | } 30 | } -------------------------------------------------------------------------------- /204-count-primes/README.md: -------------------------------------------------------------------------------- 1 |

204. Count Primes

Medium


Given an integer n, return the number of prime numbers that are strictly less than n.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 10
 7 | Output: 4
 8 | Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: n = 0
14 | Output: 0
15 | 
16 | 17 |

Example 3:

18 | 19 |
Input: n = 1
20 | Output: 0
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 |
    27 |
  • 0 <= n <= 5 * 106
  • 28 |
29 |
-------------------------------------------------------------------------------- /453-minimum-moves-to-equal-array-elements/453-minimum-moves-to-equal-array-elements.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minMoves(int[] nums) { 3 | // Incrementing n-1 elements of array by 1 to make equal array elements 4 | // This is similar to 5 | // Decrementing 1 element of array by 1 to make all elements equal 6 | 7 | // Decrement each element to reach the smallest element in array 8 | // Moves required for each index will be (value-smallest) 9 | // Summing for all 10 | // (nums[0]-smallest) + (nums[1]-smallest) + (nums[2]-smallest) + ........... 11 | // Equivalent to (Sum of array - n*smallest) 12 | 13 | int min = nums[0]; 14 | int sum = 0; 15 | for (int num: nums) { 16 | min = Math.min(min,num); 17 | sum+=num; 18 | } 19 | 20 | return sum-nums.length*min; 21 | } 22 | } -------------------------------------------------------------------------------- /1291-sequential-digits/README.md: -------------------------------------------------------------------------------- 1 |

1291. Sequential Digits

Medium


An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

2 | 3 |

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

4 | 5 |

 

6 |

Example 1:

7 |
Input: low = 100, high = 300
 8 | Output: [123,234]
 9 | 

Example 2:

10 |
Input: low = 1000, high = 13000
11 | Output: [1234,2345,3456,4567,5678,6789,12345]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 10 <= low <= high <= 10^9
  • 18 |
19 |
20 | -------------------------------------------------------------------------------- /17-letter-combinations-of-a-phone-number/17-letter-combinations-of-a-phone-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String[] keys = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; 3 | 4 | public List letterCombinations(String digits) { 5 | List ans = new ArrayList<>(); 6 | if (digits.length()!=0) 7 | helper(ans,digits,0,""); 8 | return ans; 9 | } 10 | 11 | //i is iterator for the string digits 12 | private void helper(List ans,String digits,int i,String temp) { 13 | if (i==digits.length()) { 14 | ans.add(temp); 15 | return; 16 | } 17 | 18 | int digit = digits.charAt(i)-'0'; 19 | String key = keys[digit]; 20 | 21 | for (int go=0;go spiralOrder(int[][] matrix) { 3 | int rows = matrix.length; 4 | int cols = matrix[0].length; 5 | List ans = new ArrayList<>(); 6 | 7 | int rowBegin=0,rowEnd=rows-1; 8 | int colBegin=0,colEnd=cols-1; 9 | 10 | while (rowBegin<=rowEnd && colBegin<=colEnd) { 11 | for (int c=colBegin;c<=colEnd;c++) 12 | ans.add(matrix[rowBegin][c]); 13 | for (int r=++rowBegin;r<=rowEnd;r++) 14 | ans.add(matrix[r][colEnd]); 15 | for (int c=--colEnd;c>=colBegin && rowBegin<=rowEnd;c--) 16 | ans.add(matrix[rowEnd][c]); 17 | for (int r=--rowEnd;r>=rowBegin && colBegin<=colEnd;r--) 18 | ans.add(matrix[r][colBegin]); 19 | colBegin++; 20 | } 21 | return ans; 22 | } 23 | } -------------------------------------------------------------------------------- /617-merge-two-binary-trees/617-merge-two-binary-trees.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { 18 | if (root1==null) 19 | return root2; 20 | 21 | if (root2==null) 22 | return root1; 23 | 24 | root1.val = root1.val+root2.val; 25 | root1.left = mergeTrees(root1.left,root2.left); 26 | root1.right = mergeTrees(root1.right,root2.right); 27 | 28 | return root1; 29 | } 30 | } -------------------------------------------------------------------------------- /1498-number-of-subsequences-that-satisfy-the-given-sum-condition/1498-number-of-subsequences-that-satisfy-the-given-sum-condition.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numSubseq(int[] nums, int target) { 3 | Arrays.sort(nums); 4 | 5 | int start = 0; 6 | int end = nums.length-1; 7 | int count = 0; 8 | int mod = 1000000007; 9 | 10 | int power[] = new int[nums.length]; // Store powers of 2 11 | power[0] = 1; 12 | for (int i=1;i343. Integer Break

Medium


Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.

2 | 3 |

Return the maximum product you can get.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: n = 2
 9 | Output: 1
10 | Explanation: 2 = 1 + 1, 1 × 1 = 1.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: n = 10
16 | Output: 36
17 | Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 2 <= n <= 58
  • 25 |
26 |
-------------------------------------------------------------------------------- /493-reverse-pairs/README.md: -------------------------------------------------------------------------------- 1 |

493. Reverse Pairs

Hard


Given an integer array nums, return the number of reverse pairs in the array.

2 | 3 |

A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j].

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [1,3,2,3,1]
 8 | Output: 2
 9 | 

Example 2:

10 |
Input: nums = [2,4,3,5,1]
11 | Output: 3
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= nums.length <= 5 * 104
  • 18 |
  • -231 <= nums[i] <= 231 - 1
  • 19 |
20 |
--------------------------------------------------------------------------------