├── .github ├── .DS_Store └── images │ ├── composer_fly_150.gif │ └── composer_fly_first.png ├── .gitignore ├── 1-two-sum ├── 2022-04-24 20.32.16 - Accepted - runtime 7220ms - memory 14.9MB.py ├── 2022-04-24 20.33.20 - Accepted - runtime 86ms - memory 15.3MB.py ├── 2022-04-24 20.33.33 - Accepted - runtime 69ms - memory 15.2MB.py ├── 2022-04-24 20.33.39 - Accepted - runtime 66ms - memory 15.1MB.py ├── 2022-04-24 20.59.59 - Accepted - runtime 107ms - memory 15.4MB.py ├── 2022-04-24 21.00.39 - Accepted - runtime 69ms - memory 15.3MB.py ├── 2022-06-14 17.49.42 - Accepted - runtime 109ms - memory 15.4MB.py ├── 2022-06-14 17.49.56 - Accepted - runtime 132ms - memory 15.4MB.py ├── 2022-12-30 22.14.34 - Accepted - runtime 56ms - memory 15.4MB.py ├── 2024-02-16 13.41.13 - Accepted - runtime 8ms - memory 14.1MB.cpp └── 2024-03-08 19.17.13 - Accepted - runtime 51ms - memory 17.9MB.py ├── 10-regular-expression-matching └── 2024-03-10 18.10.28 - Accepted - runtime 82ms - memory 16.6MB.py ├── 100-same-tree ├── 2022-06-24 17.00.11 - Accepted - runtime 62ms - memory 13.8MB.py ├── 2023-01-10 19.53.33 - Accepted - runtime 32ms - memory 14MB.py ├── 2024-02-18 16.55.55 - Accepted - runtime 0ms - memory 11.5MB.cpp └── 2024-02-26 15.58.30 - Accepted - runtime 5ms - memory 11.5MB.cpp ├── 1005-univalued-binary-tree ├── 2024-01-27 19.51.54 - Accepted - runtime 37ms - memory 16.7MB.py ├── 2024-02-20 13.15.32 - Accepted - runtime 5ms - memory 11.7MB.cpp └── 2024-02-20 13.16.00 - Accepted - runtime 3ms - memory 11.8MB.cpp ├── 101-symmetric-tree ├── 2022-06-24 19.53.57 - Accepted - runtime 73ms - memory 13.7MB.py ├── 2023-03-13 14.00.04 - Accepted - runtime 31ms - memory 14MB.py ├── 2023-03-13 14.11.32 - Accepted - runtime 35ms - memory 13.8MB.py ├── 2024-02-18 17.33.01 - Accepted - runtime 5ms - memory 17.7MB.cpp └── 2024-02-18 17.44.52 - Accepted - runtime 5ms - memory 17.3MB.cpp ├── 1013-fibonacci-number ├── 2022-07-06 13.09.08 - Accepted - runtime 1330ms - memory 13.8MB.py ├── 2022-07-06 13.09.40 - Accepted - runtime 48ms - memory 13.9MB.py ├── 2022-07-06 13.09.52 - Accepted - runtime 59ms - memory 13.9MB.py └── 2022-07-06 13.11.54 - Accepted - runtime 56ms - memory 14MB.py ├── 1019-squares-of-a-sorted-array ├── 2022-09-26 15.20.03 - Accepted - runtime 478ms - memory 16.2MB.py └── 2024-03-26 00.09.06 - Accepted - runtime 160ms - memory 18.7MB.py ├── 102-binary-tree-level-order-traversal ├── 2023-03-01 20.47.47 - Accepted - runtime 39ms - memory 14.8MB.py ├── 2023-03-01 20.57.47 - Accepted - runtime 34ms - memory 14.2MB.py └── 2023-03-01 20.58.21 - Accepted - runtime 36ms - memory 14.2MB.py ├── 1025-minimum-cost-for-tickets ├── 2023-03-29 11.30.05 - Accepted - runtime 47ms - memory 13.8MB.py └── 2023-03-29 11.36.18 - Accepted - runtime 35ms - memory 13.8MB.py ├── 103-binary-tree-zigzag-level-order-traversal └── 2023-02-19 21.06.38 - Accepted - runtime 44ms - memory 14.1MB.py ├── 1030-smallest-string-starting-from-leaf ├── 2024-04-17 09.40.41 - Accepted - runtime 44ms - memory 18.3MB.py └── 2024-04-17 09.42.52 - Accepted - runtime 40ms - memory 17.9MB.py ├── 1031-add-to-array-form-of-integer └── 2023-02-15 22.11.41 - Accepted - runtime 330ms - memory 14.9MB.py ├── 1034-subarrays-with-k-different-integers └── 2024-03-30 20.18.33 - Accepted - runtime 401ms - memory 20.5MB.py ├── 1039-find-the-town-judge ├── 2024-02-22 17.56.01 - Accepted - runtime 665ms - memory 21.6MB.py └── 2024-02-22 18.03.13 - Accepted - runtime 102ms - memory 64.4MB.cpp ├── 104-maximum-depth-of-binary-tree ├── 2022-06-26 12.17.58 - Accepted - runtime 43ms - memory 16.4MB.py ├── 2022-06-26 12.19.31 - Accepted - runtime 71ms - memory 16.5MB.py ├── 2024-02-18 21.46.33 - Accepted - runtime 12ms - memory 17.4MB.cpp └── 2024-02-18 21.47.06 - Accepted - runtime 3ms - memory 17.6MB.cpp ├── 1041-available-captures-for-rook └── 2023-03-06 23.13.43 - Accepted - runtime 35ms - memory 13.9MB.py ├── 1044-find-common-characters └── 2024-04-30 21.07.17 - Accepted - runtime 49ms - memory 16.7MB.py ├── 1058-lexicographically-smallest-equivalent-string └── 2023-01-14 22.15.48 - Accepted - runtime 34ms - memory 13.9MB.py ├── 1065-binary-string-with-substrings-representing-1-to-n └── 2024-04-30 20.57.38 - Accepted - runtime 32ms - memory 16.4MB.py ├── 1073-number-of-enclaves └── 2023-04-07 11.10.14 - Accepted - runtime 1188ms - memory 19.5MB.py ├── 1079-sum-of-root-to-leaf-binary-numbers ├── 2024-01-07 22.47.06 - Accepted - runtime 34ms - memory 17.6MB.py ├── 2024-01-07 23.02.17 - Accepted - runtime 42ms - memory 17.6MB.py └── 2024-02-20 13.52.18 - Accepted - runtime 0ms - memory 15.8MB.cpp ├── 108-convert-sorted-array-to-binary-search-tree ├── 2022-06-27 17.49.31 - Accepted - runtime 172ms - memory 15.6MB.py ├── 2022-06-27 17.49.43 - Accepted - runtime 166ms - memory 15.6MB.py ├── 2022-06-27 18.06.40 - Accepted - runtime 150ms - memory 15.8MB.py └── 2022-06-27 22.31.28 - Accepted - runtime 121ms - memory 15.6MB.py ├── 1092-maximum-difference-between-node-and-ancestor └── 2024-01-11 21.21.54 - Accepted - runtime 46ms - memory 19MB.py ├── 11-container-with-most-water └── 2023-01-31 20.56.29 - Accepted - runtime 757ms - memory 27.5MB.py ├── 111-minimum-depth-of-binary-tree ├── 2022-06-28 23.50.08 - Accepted - runtime 748ms - memory 55MB.py ├── 2022-06-28 23.53.42 - Accepted - runtime 1710ms - memory 58.4MB.py └── 2022-06-28 23.53.50 - Accepted - runtime 1121ms - memory 58.4MB.py ├── 1112-find-words-that-can-be-formed-by-characters └── 2023-01-26 14.41.00 - Accepted - runtime 177ms - memory 14.4MB.py ├── 112-path-sum ├── 2022-07-08 22.14.15 - Accepted - runtime 4177ms - memory 15.1MB.py ├── 2022-07-08 22.18.51 - Accepted - runtime 43ms - memory 15MB.py ├── 2022-07-09 10.59.17 - Accepted - runtime 77ms - memory 15.1MB.py ├── 2022-07-10 18.10.26 - Accepted - runtime 53ms - memory 15.1MB.py ├── 2022-10-07 20.24.27 - Accepted - runtime 47ms - memory 15MB.py └── 2024-02-18 21.58.37 - Accepted - runtime 9ms - memory 19.7MB.cpp ├── 1127-last-stone-weight ├── 2023-04-24 21.21.11 - Accepted - runtime 42ms - memory 13.9MB.py └── 2023-04-24 21.21.20 - Accepted - runtime 41ms - memory 13.9MB.py ├── 1137-height-checker └── 2024-04-04 18.32.28 - Accepted - runtime 44ms - memory 16.4MB.py ├── 114-flatten-binary-tree-to-linked-list ├── 2022-07-27 22.30.13 - Accepted - runtime 68ms - memory 15.2MB.py ├── 2022-07-27 22.30.24 - Accepted - runtime 62ms - memory 15.3MB.py ├── 2022-07-27 22.30.30 - Accepted - runtime 44ms - memory 15.3MB.py ├── 2022-07-27 22.43.40 - Accepted - runtime 89ms - memory 15.4MB.py └── 2024-02-25 19.50.20 - Accepted - runtime 11ms - memory 15.6MB.cpp ├── 118-pascals-triangle └── 2022-07-19 22.45.40 - Accepted - runtime 39ms - memory 14MB.py ├── 119-pascals-triangle-ii └── 2023-04-29 09.00.00 - Accepted - runtime 44ms - memory 16.2MB.py ├── 1195-distribute-candies-to-people └── 2022-07-11 00.23.50 - Accepted - runtime 52ms - memory 14MB.py ├── 12-integer-to-roman ├── 2022-07-17 14.56.54 - Accepted - runtime 114ms - memory 14MB.py └── 2022-07-17 14.58.19 - Accepted - runtime 85ms - memory 13.8MB.py ├── 1203-print-in-order ├── 2022-09-30 16.40.12 - Accepted - runtime 4172ms - memory 14.4MB.py ├── 2022-09-30 16.43.22 - Accepted - runtime 109ms - memory 14.5MB.py ├── 2022-09-30 16.44.01 - Accepted - runtime 3460ms - memory 14.4MB.py └── 2022-09-30 17.06.59 - Accepted - runtime 100ms - memory 14.4MB.py ├── 1205-defanging-an-ip-address └── 2022-07-11 00.27.40 - Accepted - runtime 47ms - memory 13.9MB.py ├── 121-best-time-to-buy-and-sell-stock ├── 2022-06-22 14.07.15 - Accepted - runtime 1551ms - memory 24.9MB.py ├── 2022-06-22 14.44.17 - Accepted - runtime 1889ms - memory 25MB.py ├── 2022-06-22 14.44.26 - Accepted - runtime 997ms - memory 25MB.py ├── 2022-06-22 14.44.33 - Accepted - runtime 2002ms - memory 25MB.py ├── 2022-06-22 14.44.42 - Accepted - runtime 1496ms - memory 25MB.py └── 2022-06-22 14.44.50 - Accepted - runtime 1453ms - memory 25.2MB.py ├── 1217-relative-sort-array └── 2022-07-19 17.44.13 - Accepted - runtime 48ms - memory 14MB.py ├── 1221-element-appearing-more-than-25-in-sorted-array └── 2024-01-04 15.55.37 - Accepted - runtime 81ms - memory 18.8MB.py ├── 1224-minimum-falling-path-sum-ii └── 2024-04-26 09.44.19 - Accepted - runtime 215ms - memory 20.1MB.py ├── 1231-replace-elements-with-greatest-element-on-right-side └── 2023-11-28 21.49.20 - Accepted - runtime 592ms - memory 18.4MB.py ├── 1236-n-th-tribonacci-number └── 2024-04-24 12.22.18 - Accepted - runtime 38ms - memory 16.5MB.py ├── 1241-decompress-run-length-encoded-list └── 2022-08-01 21.03.28 - Accepted - runtime 82ms - memory 14.4MB.py ├── 1243-sum-of-nodes-with-even-valued-grandparent └── 2024-04-30 21.44.42 - Accepted - runtime 71ms - memory 19.4MB.py ├── 125-valid-palindrome ├── 2022-06-22 13.41.26 - Accepted - runtime 89ms - memory 15.2MB.py └── 2022-12-16 17.15.52 - Accepted - runtime 51ms - memory 15.4MB.py ├── 1250-longest-common-subsequence ├── 2024-03-12 18.58.26 - Accepted - runtime 373ms - memory 16.6MB.py ├── 2024-03-12 18.58.37 - Accepted - runtime 363ms - memory 16.5MB.py ├── 2024-03-12 20.02.07 - Accepted - runtime 369ms - memory 16.7MB.py ├── 2024-03-13 01.01.50 - Accepted - runtime 371ms - memory 16.5MB.py ├── 2024-03-14 12.15.09 - Accepted - runtime 372ms - memory 16.5MB.py ├── 2024-03-14 12.17.37 - Accepted - runtime 366ms - memory 16.6MB.py └── 2024-03-14 13.03.08 - Accepted - runtime 368ms - memory 16.6MB.py ├── 1254-deepest-leaves-sum └── 2024-04-15 15.21.32 - Accepted - runtime 108ms - memory 19.5MB.py ├── 1256-rank-transform-of-an-array └── 2024-04-15 15.25.23 - Accepted - runtime 234ms - memory 35.9MB.py ├── 1267-remove-zero-sum-consecutive-nodes-from-linked-list └── 2024-03-12 15.01.50 - Accepted - runtime 36ms - memory 16.9MB.py ├── 128-longest-consecutive-sequence └── 2022-07-05 18.22.25 - Accepted - runtime 740ms - memory 28MB.py ├── 1287-distance-between-bus-stops └── 2024-04-21 18.13.37 - Accepted - runtime 50ms - memory 17.6MB.py ├── 129-sum-root-to-leaf-numbers ├── 2023-03-14 15.07.37 - Accepted - runtime 32ms - memory 13.8MB.py ├── 2023-03-14 15.11.48 - Accepted - runtime 29ms - memory 13.8MB.py ├── 2023-03-14 15.13.26 - Accepted - runtime 32ms - memory 14MB.py ├── 2024-04-15 08.29.06 - Accepted - runtime 31ms - memory 16.5MB.py └── 2024-04-15 08.36.50 - Accepted - runtime 26ms - memory 16.5MB.py ├── 1297-maximum-number-of-balloons └── 2024-04-01 16.15.39 - Accepted - runtime 32ms - memory 16.6MB.py ├── 13-roman-to-integer ├── 2022-04-18 22.32.40 - Accepted - runtime 52ms - memory 13.9MB.py ├── 2024-02-16 19.45.57 - Accepted - runtime 8ms - memory 12.7MB.cpp └── 2024-02-16 20.01.46 - Accepted - runtime 20ms - memory 12.9MB.cpp ├── 1306-minimum-absolute-difference └── 2022-09-26 18.06.25 - Accepted - runtime 716ms - memory 28.9MB.py ├── 1319-unique-number-of-occurrences └── 2024-01-17 19.12.57 - Accepted - runtime 27ms - memory 17.4MB.py ├── 133-clone-graph ├── 2023-03-05 19.02.28 - Accepted - runtime 48ms - memory 14.5MB.py ├── 2023-03-05 19.19.39 - Accepted - runtime 39ms - memory 14.4MB.py └── 2023-04-08 23.57.51 - Accepted - runtime 41ms - memory 14.3MB.py ├── 134-gas-station └── 2023-01-07 16.38.42 - Accepted - runtime 704ms - memory 18.9MB.py ├── 1341-split-a-string-in-balanced-strings └── 2024-01-04 16.06.52 - Accepted - runtime 36ms - memory 17.4MB.py ├── 135-candy └── 2023-01-19 18.47.39 - Accepted - runtime 157ms - memory 16.8MB.py ├── 1354-find-players-with-zero-or-one-losses └── 2024-01-15 18.28.43 - Accepted - runtime 1354ms - memory 71.2MB.py ├── 136-single-number ├── 2022-06-23 22.04.47 - Accepted - runtime 292ms - memory 16.8MB.py ├── 2022-06-23 22.04.55 - Accepted - runtime 277ms - memory 16.8MB.py ├── 2022-06-23 22.06.06 - Accepted - runtime 304ms - memory 16.8MB.py └── 2022-06-23 22.06.14 - Accepted - runtime 178ms - memory 16.7MB.py ├── 1362-airplane-seat-assignment-probability └── 2024-04-15 14.42.55 - Accepted - runtime 40ms - memory 16.6MB.py ├── 1371-minimum-remove-to-make-valid-parentheses └── 2024-04-06 10.44.22 - Accepted - runtime 63ms - memory 17.9MB.py ├── 1378-cells-with-odd-values-in-a-matrix ├── 2022-09-20 20.06.43 - Accepted - runtime 85ms - memory 13.9MB.py └── 2022-09-20 20.11.45 - Accepted - runtime 75ms - memory 14MB.py ├── 1392-find-the-difference-of-two-arrays └── 2023-05-04 18.39.42 - Accepted - runtime 187ms - memory 16.7MB.py ├── 1393-maximum-value-of-k-coins-from-piles └── 2023-04-15 14.32.05 - Accepted - runtime 4459ms - memory 141.1MB.py ├── 1395-minimum-time-visiting-all-points └── 2022-07-27 01.07.04 - Accepted - runtime 112ms - memory 14MB.py ├── 14-longest-common-prefix ├── 2022-04-18 22.41.04 - Accepted - runtime 37ms - memory 13.9MB.py ├── 2024-02-16 20.12.12 - Accepted - runtime 31ms - memory 16.6MB.py ├── 2024-02-16 20.14.08 - Accepted - runtime 29ms - memory 16.7MB.py └── 2024-02-16 22.04.32 - Accepted - runtime 0ms - memory 11.2MB.cpp ├── 1406-subtract-the-product-and-sum-of-digits-of-an-integer └── 2022-08-01 20.49.05 - Accepted - runtime 52ms - memory 13.9MB.py ├── 141-linked-list-cycle ├── 2022-06-29 00.09.52 - Accepted - runtime 67ms - memory 17.6MB.py └── 2024-03-07 03.03.12 - Accepted - runtime 40ms - memory 19.6MB.py ├── 1411-convert-binary-number-in-a-linked-list-to-integer └── 2022-08-02 00.37.17 - Accepted - runtime 40ms - memory 13.8MB.py ├── 142-linked-list-cycle-ii ├── 2023-01-01 00.36.09 - Accepted - runtime 58ms - memory 17.3MB.py ├── 2023-01-01 00.36.51 - Accepted - runtime 55ms - memory 17.9MB.py └── 2023-01-01 13.23.32 - Accepted - runtime 48ms - memory 17.2MB.py ├── 1421-find-numbers-with-even-number-of-digits └── 2024-04-30 21.28.04 - Accepted - runtime 63ms - memory 16.7MB.py ├── 143-reorder-list └── 2024-03-23 18.30.04 - Accepted - runtime 54ms - memory 24.6MB.py ├── 1430-find-the-k-beauty-of-a-number └── 2024-04-30 21.22.07 - Accepted - runtime 39ms - memory 16.4MB.py ├── 144-binary-tree-preorder-traversal ├── 2022-07-06 22.09.37 - Accepted - runtime 67ms - memory 13.8MB.py ├── 2023-01-09 21.13.30 - Accepted - runtime 28ms - memory 13.9MB.py └── 2024-02-18 22.05.34 - Accepted - runtime 4ms - memory 9.9MB.cpp ├── 1444-number-of-steps-to-reduce-a-number-to-zero └── 2022-08-01 21.11.31 - Accepted - runtime 46ms - memory 13.9MB.py ├── 1448-maximum-69-number ├── 2022-09-20 19.23.41 - Accepted - runtime 65ms - memory 13.9MB.py └── 2022-09-20 19.24.20 - Accepted - runtime 30ms - memory 13.9MB.py ├── 145-binary-tree-postorder-traversal ├── 2022-07-07 11.11.06 - Accepted - runtime 61ms - memory 13.9MB.py └── 2024-02-18 22.08.10 - Accepted - runtime 0ms - memory 9.8MB.cpp ├── 1458-sort-integers-by-the-number-of-1-bits └── 2024-01-05 23.14.48 - Accepted - runtime 58ms - memory 17.5MB.py ├── 1469-minimum-number-of-steps-to-make-two-strings-anagram ├── 2024-01-13 19.48.39 - Accepted - runtime 99ms - memory 17.9MB.py └── 2024-01-13 19.53.03 - Accepted - runtime 108ms - memory 17.8MB.py ├── 1474-longest-zigzag-path-in-a-binary-tree └── 2023-04-20 00.06.58 - Accepted - runtime 456ms - memory 63MB.py ├── 1476-count-negative-numbers-in-a-sorted-matrix └── 2023-03-06 21.09.16 - Accepted - runtime 126ms - memory 15.1MB.py ├── 148-sort-list └── 2024-01-05 22.36.53 - Accepted - runtime 137ms - memory 33.1MB.py ├── 1482-how-many-numbers-are-smaller-than-the-current-number └── 2022-07-23 11.56.03 - Accepted - runtime 88ms - memory 14MB.py ├── 1486-find-the-distance-value-between-two-arrays └── 2023-03-01 20.07.03 - Accepted - runtime 108ms - memory 14MB.py ├── 1498-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree └── 2022-08-01 20.46.14 - Accepted - runtime 977ms - memory 24MB.py ├── 15-3sum └── 2022-04-18 23.07.44 - Accepted - runtime 803ms - memory 18.1MB.py ├── 1505-create-target-array-in-the-given-order └── 2022-08-01 21.48.26 - Accepted - runtime 66ms - memory 13.8MB.py ├── 1528-kids-with-the-greatest-number-of-candies ├── 2022-08-01 16.35.54 - Accepted - runtime 56ms - memory 13.9MB.py └── 2023-04-17 12.13.29 - Accepted - runtime 45ms - memory 13.7MB.py ├── 153-find-minimum-in-rotated-sorted-array └── 2023-01-06 21.16.10 - Accepted - runtime 90ms - memory 14.2MB.py ├── 1532-reformat-the-string └── 2024-04-09 21.20.47 - Accepted - runtime 36ms - memory 16.5MB.py ├── 1537-maximum-score-after-splitting-a-string └── 2024-02-08 23.35.57 - Accepted - runtime 39ms - memory 16.7MB.py ├── 1538-maximum-points-you-can-obtain-from-cards ├── 2022-06-26 11.58.51 - Accepted - runtime 864ms - memory 28.8MB.py └── 2022-06-26 11.59.00 - Accepted - runtime 491ms - memory 28.8MB.py ├── 1561-rearrange-words-in-a-sentence └── 2024-04-10 14.44.48 - Accepted - runtime 29ms - memory 18.8MB.py ├── 1567-maximum-number-of-vowels-in-a-substring-of-given-length └── 2023-05-05 11.09.34 - Accepted - runtime 154ms - memory 17.3MB.py ├── 1574-maximum-product-of-two-elements-in-an-array └── 2022-09-20 19.26.46 - Accepted - runtime 140ms - memory 14MB.py ├── 1580-shuffle-the-array └── 2022-08-01 16.16.04 - Accepted - runtime 120ms - memory 14.1MB.py ├── 1582-design-browser-history └── 2024-03-01 00.25.51 - Accepted - runtime 178ms - memory 19.2MB.py ├── 1584-average-salary-excluding-the-minimum-and-maximum-salary └── 2023-05-02 00.39.10 - Accepted - runtime 50ms - memory 16.3MB.py ├── 160-intersection-of-two-linked-lists └── 2023-11-26 19.51.42 - Accepted - runtime 121ms - memory 31.5MB.py ├── 1603-running-sum-of-1d-array └── 2022-08-01 16.06.22 - Accepted - runtime 69ms - memory 14.1MB.py ├── 1604-least-number-of-unique-integers-after-k-removals ├── 2024-02-16 13.01.54 - Accepted - runtime 341ms - memory 36.9MB.py └── 2024-02-16 13.16.39 - Accepted - runtime 534ms - memory 39.5MB.py ├── 1610-xor-operation-in-an-array └── 2022-08-02 00.34.35 - Accepted - runtime 50ms - memory 13.8MB.py ├── 1626-can-make-arithmetic-progression-from-sequence └── 2024-05-05 20.05.40 - Accepted - runtime 39ms - memory 16.9MB.py ├── 1635-number-of-good-pairs └── 2022-08-01 16.30.28 - Accepted - runtime 65ms - memory 13.8MB.py ├── 1646-kth-missing-positive-number └── 2023-03-06 21.02.21 - Accepted - runtime 47ms - memory 14.2MB.py ├── 165-compare-version-numbers └── 2024-05-03 09.37.53 - Accepted - runtime 38ms - memory 16.6MB.py ├── 1651-shuffle-string └── 2022-08-01 22.11.03 - Accepted - runtime 81ms - memory 13.9MB.py ├── 1666-make-the-string-great └── 2024-04-05 10.23.05 - Accepted - runtime 46ms - memory 16.6MB.py ├── 1677-matrix-diagonal-sum └── 2023-05-08 11.29.50 - Accepted - runtime 115ms - memory 16.6MB.py ├── 168-excel-sheet-column-title └── 2024-03-13 23.44.19 - Accepted - runtime 40ms - memory 16.7MB.py ├── 169-majority-element └── 2022-07-18 19.44.23 - Accepted - runtime 177ms - memory 15.5MB.py ├── 1693-sum-of-all-odd-length-subarrays ├── 2022-09-20 14.43.46 - Accepted - runtime 129ms - memory 13.8MB.py └── 2022-09-20 14.46.02 - Accepted - runtime 72ms - memory 13.9MB.py ├── 17-letter-combinations-of-a-phone-number ├── 2022-12-31 20.31.16 - Accepted - runtime 36ms - memory 13.9MB.py └── 2022-12-31 22.41.38 - Accepted - runtime 29ms - memory 13.9MB.py ├── 1708-design-parking-system └── 2022-08-01 16.33.48 - Accepted - runtime 232ms - memory 14.4MB.py ├── 171-excel-sheet-column-number └── 2024-03-31 19.39.05 - Accepted - runtime 36ms - memory 16.4MB.py ├── 1731-even-odd-tree ├── 2024-02-29 13.33.14 - Accepted - runtime 262ms - memory 66.3MB.py └── 2024-02-29 13.36.51 - Accepted - runtime 225ms - memory 39.3MB.py ├── 1737-maximum-nesting-depth-of-the-parentheses └── 2024-04-04 09.19.17 - Accepted - runtime 33ms - memory 16.5MB.py ├── 175-combine-two-tables └── 2023-05-13 10.04.02 - Accepted - runtime 845ms - memory 0B.sql ├── 1751-slowest-key └── 2024-04-21 18.01.05 - Accepted - runtime 60ms - memory 16.8MB.py ├── 1762-furthest-building-you-can-reach ├── 2022-06-23 16.23.20 - Accepted - runtime 745ms - memory 28.6MB.py └── 2024-02-17 15.57.37 - Accepted - runtime 78ms - memory 57.2MB.cpp ├── 1765-merge-in-between-linked-lists └── 2024-03-21 00.55.26 - Accepted - runtime 188ms - memory 21.2MB.py ├── 1777-determine-if-two-strings-are-close ├── 2024-01-14 22.58.46 - Accepted - runtime 125ms - memory 18.5MB.py └── 2024-01-14 22.59.33 - Accepted - runtime 130ms - memory 18.1MB.py ├── 1781-check-if-two-string-arrays-are-equivalent └── 2022-09-20 14.26.50 - Accepted - runtime 68ms - memory 13.8MB.py ├── 1786-count-the-number-of-consistent-strings └── 2022-09-20 14.25.13 - Accepted - runtime 586ms - memory 16.1MB.py ├── 1791-richest-customer-wealth └── 2022-08-01 16.11.46 - Accepted - runtime 101ms - memory 13.9MB.py ├── 1797-goal-parser-interpretation └── 2022-08-01 17.33.04 - Accepted - runtime 69ms - memory 13.9MB.py ├── 1802-number-of-students-unable-to-eat-lunch ├── 2024-04-08 11.32.01 - Accepted - runtime 50ms - memory 16.5MB.py └── 2024-04-08 11.33.08 - Accepted - runtime 31ms - memory 16.7MB.py ├── 1817-calculate-money-in-leetcode-bank └── 2024-04-06 19.30.29 - Accepted - runtime 32ms - memory 16.6MB.py ├── 1823-determine-if-string-halves-are-alike ├── 2022-09-26 14.23.33 - Accepted - runtime 57ms - memory 13.8MB.py ├── 2024-01-12 16.42.16 - Accepted - runtime 34ms - memory 17.2MB.py └── 2024-01-12 16.43.47 - Accepted - runtime 38ms - memory 17.2MB.py ├── 1833-find-the-highest-altitude ├── 2022-09-20 19.53.45 - Accepted - runtime 63ms - memory 13.9MB.py └── 2022-09-20 19.55.56 - Accepted - runtime 68ms - memory 13.8MB.py ├── 1839-decode-xored-array └── 2022-08-01 21.10.08 - Accepted - runtime 322ms - memory 15.8MB.py ├── 1848-sum-of-unique-elements ├── 2022-09-26 17.13.11 - Accepted - runtime 81ms - memory 13.9MB.py └── 2022-09-26 17.15.28 - Accepted - runtime 65ms - memory 13.8MB.py ├── 1850-minimum-length-of-string-after-deleting-similar-ends ├── 2024-03-05 15.31.22 - Accepted - runtime 104ms - memory 17.3MB.py └── 2024-03-05 15.33.09 - Accepted - runtime 58ms - memory 17.4MB.py ├── 1894-merge-strings-alternately └── 2023-04-21 17.18.50 - Accepted - runtime 35ms - memory 13.9MB.py ├── 1899-count-items-matching-a-rule └── 2022-08-02 00.29.15 - Accepted - runtime 363ms - memory 20.2MB.py ├── 19-remove-nth-node-from-end-of-list ├── 2022-04-23 09.22.14 - Accepted - runtime 60ms - memory 13.9MB.py ├── 2022-04-23 09.28.17 - Accepted - runtime 61ms - memory 13.9MB.py ├── 2022-04-23 09.29.22 - Accepted - runtime 32ms - memory 13.9MB.py ├── 2022-04-23 09.29.47 - Accepted - runtime 36ms - memory 13.8MB.py ├── 2022-04-23 09.29.54 - Accepted - runtime 47ms - memory 13.8MB.py ├── 2022-04-23 09.30.00 - Accepted - runtime 74ms - memory 13.9MB.py └── 2022-04-23 09.30.09 - Accepted - runtime 29ms - memory 13.9MB.py ├── 190-reverse-bits ├── 2022-06-29 10.30.40 - Accepted - runtime 71ms - memory 13.8MB.py ├── 2022-06-29 10.31.10 - Accepted - runtime 8ms - memory 6MB.cpp ├── 2022-06-29 10.31.49 - Accepted - runtime 7ms - memory 5.3MB.c └── 2022-08-20 17.15.16 - Accepted - runtime 10ms - memory 5.9MB.cpp ├── 191-number-of-1-bits └── 2022-06-29 13.14.48 - Accepted - runtime 31ms - memory 13.8MB.py ├── 1927-maximum-ascending-subarray-sum └── 2023-01-21 23.55.15 - Accepted - runtime 77ms - memory 13.8MB.py ├── 1944-truncate-sentence └── 2022-09-20 14.24.51 - Accepted - runtime 45ms - memory 13.8MB.py ├── 1950-sign-of-the-product-of-an-array └── 2023-05-02 15.06.30 - Accepted - runtime 74ms - memory 16.4MB.py ├── 1961-maximum-ice-cream-bars ├── 2023-01-06 18.14.06 - Accepted - runtime 1148ms - memory 27.9MB.py └── 2023-01-06 18.16.40 - Accepted - runtime 2817ms - memory 27.9MB.py ├── 1962-single-threaded-cpu ├── 2022-12-29 23.23.08 - Accepted - runtime 1862ms - memory 63.5MB.py ├── 2022-12-30 11.00.36 - Accepted - runtime 2007ms - memory 63.5MB.py └── 2022-12-30 11.01.51 - Accepted - runtime 1998ms - memory 63.6MB.py ├── 1965-sum-of-digits-in-base-k └── 2022-09-26 14.48.50 - Accepted - runtime 56ms - memory 13.9MB.py ├── 1970-sorting-the-sentence └── 2022-08-02 00.31.50 - Accepted - runtime 33ms - memory 13.8MB.py ├── 1978-minimum-adjacent-swaps-to-reach-the-kth-smallest-number └── 2024-01-06 15.44.59 - Accepted - runtime 471ms - memory 17.4MB.py ├── 198-house-robber ├── 2022-12-17 19.05.19 - Accepted - runtime 39ms - memory 13.9MB.py ├── 2022-12-17 19.21.25 - Accepted - runtime 66ms - memory 14MB.py ├── 2022-12-17 19.21.35 - Accepted - runtime 33ms - memory 13.8MB.py └── 2024-01-21 18.13.48 - Accepted - runtime 44ms - memory 16.6MB.py ├── 1983-maximum-population-year ├── 2023-01-04 00.18.07 - Accepted - runtime 62ms - memory 13.9MB.py ├── 2023-01-04 00.39.21 - Accepted - runtime 59ms - memory 13.9MB.py └── 2023-01-04 01.13.58 - Accepted - runtime 58ms - memory 13.8MB.py ├── 1993-sum-of-all-subset-xor-totals ├── 2022-09-20 19.42.40 - Accepted - runtime 169ms - memory 13.8MB.py └── 2022-09-20 19.45.26 - Accepted - runtime 63ms - memory 14MB.py ├── 2-add-two-numbers ├── 2022-06-22 18.27.40 - Accepted - runtime 121ms - memory 14MB.py ├── 2024-02-17 17.55.23 - Accepted - runtime 23ms - memory 76.9MB.cpp ├── 2024-02-17 18.03.04 - Accepted - runtime 39ms - memory 76MB.cpp └── 2024-02-17 18.03.27 - Accepted - runtime 19ms - memory 75.9MB.cpp ├── 20-valid-parentheses ├── 2022-04-23 09.58.48 - Accepted - runtime 43ms - memory 13.9MB.py ├── 2023-04-10 08.24.46 - Accepted - runtime 37ms - memory 13.9MB.py ├── 2023-04-10 23.39.46 - Accepted - runtime 40ms - memory 13.8MB.py ├── 2023-04-10 23.39.59 - Accepted - runtime 22ms - memory 13.8MB.py ├── 2024-02-16 22.46.20 - Accepted - runtime 2ms - memory 8MB.cpp ├── 2024-02-16 22.46.33 - Accepted - runtime 3ms - memory 8MB.cpp └── 2024-02-16 22.53.29 - Accepted - runtime 0ms - memory 7.7MB.cpp ├── 200-number-of-islands ├── 2022-07-15 15.01.49 - Accepted - runtime 469ms - memory 16.2MB.py ├── 2022-12-18 15.13.54 - Accepted - runtime 1356ms - memory 16.2MB.py ├── 2022-12-18 15.14.08 - Accepted - runtime 1331ms - memory 16.3MB.py ├── 2022-12-18 15.14.37 - Accepted - runtime 1307ms - memory 16.2MB.py ├── 2022-12-18 15.18.16 - Accepted - runtime 427ms - memory 16.2MB.py ├── 2022-12-18 15.18.27 - Accepted - runtime 434ms - memory 16.2MB.py ├── 2022-12-18 15.18.39 - Accepted - runtime 1300ms - memory 16.3MB.py ├── 2024-03-07 16.17.13 - Accepted - runtime 326ms - memory 19MB.py ├── 2024-03-07 16.18.25 - Accepted - runtime 71ms - memory 17.4MB.py ├── 2024-03-09 15.11.57 - Accepted - runtime 314ms - memory 18.9MB.py └── 2024-04-19 09.50.52 - Accepted - runtime 307ms - memory 18.9MB.py ├── 201-bitwise-and-of-numbers-range └── 2024-02-21 10.54.59 - Accepted - runtime 3ms - memory 8.8MB.cpp ├── 202-happy-number └── 2022-06-30 14.39.41 - Accepted - runtime 96ms - memory 13.9MB.py ├── 203-remove-linked-list-elements ├── 2022-06-29 14.21.15 - Accepted - runtime 83ms - memory 17.8MB.py ├── 2022-06-29 14.24.06 - Accepted - runtime 81ms - memory 27MB.py └── 2022-06-29 14.24.16 - Accepted - runtime 98ms - memory 26.9MB.py ├── 2044-number-of-wonderful-substrings └── 2024-04-30 09.08.22 - Accepted - runtime 1426ms - memory 17.5MB.py ├── 2048-build-array-from-permutation └── 2022-08-01 16.03.14 - Accepted - runtime 214ms - memory 14.1MB.py ├── 205-isomorphic-strings ├── 2024-04-02 11.17.24 - Accepted - runtime 60ms - memory 17.3MB.py └── 2024-04-02 11.22.09 - Accepted - runtime 52ms - memory 16.8MB.py ├── 2058-concatenation-of-array └── 2022-08-01 16.03.49 - Accepted - runtime 142ms - memory 14.3MB.py ├── 206-reverse-linked-list ├── 2022-06-29 13.23.56 - Accepted - runtime 49ms - memory 20.5MB.py ├── 2022-11-25 22.26.51 - Accepted - runtime 77ms - memory 20.4MB.py ├── 2022-11-27 19.33.04 - Accepted - runtime 45ms - memory 20.5MB.py ├── 2023-04-02 15.45.56 - Accepted - runtime 42ms - memory 20.5MB.py ├── 2024-01-21 21.30.48 - Accepted - runtime 39ms - memory 17.8MB.py ├── 2024-01-21 21.32.39 - Accepted - runtime 29ms - memory 17.6MB.py ├── 2024-02-17 16.13.35 - Accepted - runtime 0ms - memory 11.9MB.cpp ├── 2024-03-08 18.12.39 - Accepted - runtime 38ms - memory 17.8MB.py ├── 2024-03-09 15.14.43 - Accepted - runtime 37ms - memory 17.7MB.py ├── 2024-03-09 15.15.43 - Accepted - runtime 33ms - memory 17.6MB.py └── 2024-03-21 21.46.14 - Accepted - runtime 31ms - memory 17.6MB.py ├── 208-implement-trie-prefix-tree └── 2024-03-08 19.48.43 - Accepted - runtime 114ms - memory 31.4MB.py ├── 2083-three-divisors └── 2024-01-05 23.21.34 - Accepted - runtime 34ms - memory 17.3MB.py ├── 21-merge-two-sorted-lists ├── 2022-04-24 22.29.26 - Accepted - runtime 42ms - memory 14MB.py ├── 2022-04-24 22.30.38 - Accepted - runtime 40ms - memory 13.9MB.py ├── 2022-04-24 22.35.54 - Accepted - runtime 91ms - memory 13.9MB.py ├── 2022-04-24 22.36.04 - Accepted - runtime 38ms - memory 14MB.py ├── 2024-02-17 01.34.39 - Accepted - runtime 8ms - memory 18.7MB.cpp └── 2024-02-17 01.43.55 - Accepted - runtime 3ms - memory 18.2MB.cpp ├── 2103-find-all-groups-of-farmland └── 2024-04-20 10.15.12 - Accepted - runtime 1211ms - memory 28.7MB.py ├── 2116-count-number-of-pairs-with-absolute-difference-k └── 2022-09-20 14.27.22 - Accepted - runtime 456ms - memory 14MB.py ├── 2121-find-if-path-exists-in-graph └── 2024-04-21 09.28.47 - Accepted - runtime 1606ms - memory 108.8MB.py ├── 2128-reverse-prefix-of-word └── 2024-05-01 09.31.24 - Accepted - runtime 34ms - memory 16.5MB.py ├── 2137-final-value-of-variable-after-performing-operations └── 2022-08-01 16.09.56 - Accepted - runtime 96ms - memory 13.8MB.py ├── 215-kth-largest-element-in-an-array └── 2022-06-22 18.12.39 - Accepted - runtime 1327ms - memory 14.7MB.py ├── 2154-minimum-moves-to-convert-string └── 2024-01-06 18.28.41 - Accepted - runtime 34ms - memory 17.3MB.py ├── 217-contains-duplicate └── 2022-06-29 13.33.09 - Accepted - runtime 722ms - memory 26.1MB.py ├── 2181-smallest-index-with-equal-value └── 2022-09-26 17.46.15 - Accepted - runtime 90ms - memory 13.8MB.py ├── 219-contains-duplicate-ii └── 2022-06-29 13.49.16 - Accepted - runtime 588ms - memory 27.2MB.py ├── 2195-time-needed-to-buy-tickets └── 2024-04-09 09.56.41 - Accepted - runtime 47ms - memory 16.8MB.py ├── 22-generate-parentheses ├── 2022-07-11 23.32.50 - Accepted - runtime 68ms - memory 14.2MB.py └── 2022-07-13 03.51.05 - Accepted - runtime 73ms - memory 14.1MB.py ├── 2204-find-subsequence-of-length-k-with-the-largest-sum └── 2024-01-24 21.21.44 - Accepted - runtime 50ms - memory 16.8MB.py ├── 2219-maximum-number-of-words-found-in-sentences └── 2022-08-01 16.17.28 - Accepted - runtime 52ms - memory 13.8MB.py ├── 222-count-complete-tree-nodes ├── 2024-02-18 22.16.50 - Accepted - runtime 23ms - memory 29.2MB.cpp └── 2024-02-18 22.19.10 - Accepted - runtime 24ms - memory 29.1MB.cpp ├── 2231-find-first-palindromic-string-in-the-array └── 2022-09-20 20.00.13 - Accepted - runtime 111ms - memory 13.9MB.py ├── 2238-a-number-after-a-double-reversal └── 2022-07-21 16.18.20 - Accepted - runtime 46ms - memory 13.9MB.py ├── 224-basic-calculator └── 2024-04-10 00.28.35 - Accepted - runtime 272ms - memory 18.1MB.py ├── 2243-check-if-all-as-appears-before-all-bs └── 2022-07-21 16.16.47 - Accepted - runtime 58ms - memory 14MB.py ├── 2248-minimum-cost-of-buying-candies-with-discount └── 2022-07-21 16.14.47 - Accepted - runtime 79ms - memory 13.8MB.py ├── 225-implement-stack-using-queues └── 2022-07-18 12.55.34 - Accepted - runtime 38ms - memory 14MB.py ├── 2254-check-if-every-row-and-column-contains-all-numbers └── 2022-07-21 16.13.49 - Accepted - runtime 1170ms - memory 14.4MB.py ├── 226-invert-binary-tree ├── 2022-06-30 14.48.00 - Accepted - runtime 58ms - memory 13.9MB.py ├── 2022-06-30 14.51.01 - Accepted - runtime 52ms - memory 13.7MB.py ├── 2024-01-14 23.33.43 - Accepted - runtime 29ms - memory 17.5MB.py ├── 2024-02-17 16.02.51 - Accepted - runtime 5ms - memory 11.3MB.cpp └── 2024-02-18 17.48.32 - Accepted - runtime 5ms - memory 11.4MB.cpp ├── 2260-divide-a-string-into-groups-of-size-k └── 2022-07-21 16.10.25 - Accepted - runtime 60ms - memory 14MB.py ├── 2264-minimum-sum-of-four-digit-number-after-splitting-digits └── 2022-07-21 16.09.50 - Accepted - runtime 48ms - memory 13.9MB.py ├── 227-basic-calculator-ii └── 2024-03-31 22.27.01 - Accepted - runtime 130ms - memory 107.7MB.py ├── 2274-keep-multiplying-found-values-by-two └── 2022-07-21 16.06.16 - Accepted - runtime 80ms - memory 14MB.py ├── 228-summary-ranges └── 2023-04-30 00.03.40 - Accepted - runtime 43ms - memory 16.3MB.py ├── 2283-sort-even-and-odd-indices-independently └── 2022-07-21 10.57.31 - Accepted - runtime 114ms - memory 13.8MB.py ├── 2288-count-operations-to-obtain-zero ├── 2022-09-26 17.17.47 - Accepted - runtime 298ms - memory 13.8MB.py └── 2022-09-26 17.22.57 - Accepted - runtime 229ms - memory 13.9MB.py ├── 2294-minimum-time-to-complete-trips └── 2023-03-07 23.25.17 - Accepted - runtime 1858ms - memory 28.3MB.py ├── 23-merge-k-sorted-lists ├── 2023-03-12 11.19.48 - Accepted - runtime 81ms - memory 18.4MB.py └── 2023-03-13 14.17.22 - Accepted - runtime 103ms - memory 18.4MB.py ├── 2304-cells-in-a-range-on-an-excel-sheet └── 2022-08-01 21.40.30 - Accepted - runtime 80ms - memory 13.8MB.py ├── 2308-divide-array-into-equal-pairs └── 2022-07-21 16.04.41 - Accepted - runtime 146ms - memory 14.1MB.py ├── 231-power-of-two ├── 2022-06-30 21.54.52 - Accepted - runtime 92ms - memory 13.9MB.py └── 2022-06-30 21.56.09 - Accepted - runtime 49ms - memory 14MB.py ├── 232-implement-queue-using-stacks └── 2022-12-16 23.03.17 - Accepted - runtime 33ms - memory 14MB.py ├── 2331-intersection-of-multiple-arrays └── 2023-11-27 21.02.15 - Accepted - runtime 65ms - memory 17MB.py ├── 2337-remove-digit-from-number-to-maximize-result ├── 2023-11-26 19.09.22 - Accepted - runtime 38ms - memory 16.2MB.py └── 2023-11-26 19.12.59 - Accepted - runtime 48ms - memory 16.4MB.py ├── 2338-minimum-consecutive-cards-to-pick-up ├── 2023-11-26 20.11.38 - Accepted - runtime 670ms - memory 35.7MB.py ├── 2023-11-26 20.22.08 - Accepted - runtime 706ms - memory 35.7MB.py ├── 2023-11-26 20.22.19 - Accepted - runtime 710ms - memory 35.7MB.py ├── 2023-11-26 20.22.34 - Accepted - runtime 701ms - memory 35.9MB.py └── 2023-11-26 20.22.52 - Accepted - runtime 699ms - memory 35.7MB.py ├── 234-palindrome-linked-list ├── 2022-06-29 13.25.53 - Accepted - runtime 859ms - memory 46.5MB.py ├── 2024-03-22 13.00.58 - Accepted - runtime 308ms - memory 36.4MB.py └── 2024-03-22 13.01.45 - Accepted - runtime 41ms - memory 17.3MB.py ├── 2347-count-nodes-equal-to-average-of-subtree ├── 2024-02-19 20.58.58 - Accepted - runtime 45ms - memory 16.8MB.py └── 2024-02-19 21.08.46 - Accepted - runtime 10ms - memory 14.4MB.cpp ├── 2362-minimum-rounds-to-complete-all-tasks ├── 2023-01-05 00.06.52 - Accepted - runtime 1381ms - memory 29.1MB.py ├── 2023-01-05 00.09.11 - Accepted - runtime 958ms - memory 28.3MB.py └── 2023-01-05 00.09.41 - Accepted - runtime 1646ms - memory 28.4MB.py ├── 2365-percentage-of-letter-in-string ├── 2022-09-26 14.58.00 - Accepted - runtime 57ms - memory 13.9MB.py └── 2022-09-26 14.58.50 - Accepted - runtime 58ms - memory 13.9MB.py ├── 2366-maximum-bags-with-full-capacity-of-rocks └── 2022-12-27 22.00.12 - Accepted - runtime 883ms - memory 22.3MB.py ├── 237-delete-node-in-a-linked-list ├── 2022-06-29 14.30.04 - Accepted - runtime 68ms - memory 14.3MB.py └── 2024-05-05 10.11.40 - Accepted - runtime 32ms - memory 16.8MB.py ├── 2372-rearrange-characters-to-make-target-string └── 2023-01-26 14.33.08 - Accepted - runtime 33ms - memory 13.8MB.py ├── 238-product-of-array-except-self └── 2024-03-15 15.28.11 - Accepted - runtime 172ms - memory 23.8MB.py ├── 2383-add-two-integers └── 2022-08-01 16.04.05 - Accepted - runtime 51ms - memory 13.8MB.py ├── 2384-root-equals-sum-of-children ├── 2022-08-01 16.11.01 - Accepted - runtime 44ms - memory 13.8MB.py └── 2024-01-07 22.37.24 - Accepted - runtime 33ms - memory 17.4MB.py ├── 239-sliding-window-maximum └── 2024-03-29 17.34.06 - Accepted - runtime 1089ms - memory 33MB.py ├── 2391-strong-password-checker-ii └── 2022-07-28 21.45.30 - Accepted - runtime 44ms - memory 13.8MB.py ├── 2392-successful-pairs-of-spells-and-potions └── 2023-04-02 15.37.36 - Accepted - runtime 1793ms - memory 37.1MB.py ├── 24-swap-nodes-in-pairs ├── 2024-02-21 11.22.10 - Accepted - runtime 4ms - memory 9.5MB.cpp └── 2024-02-21 11.23.31 - Accepted - runtime 2ms - memory 9.6MB.cpp ├── 240-search-a-2d-matrix-ii └── 2022-07-24 20.18.11 - Accepted - runtime 349ms - memory 20.4MB.py ├── 2401-count-asterisks └── 2022-07-28 21.35.18 - Accepted - runtime 52ms - memory 14MB.py ├── 2406-decode-the-message └── 2022-07-28 21.56.07 - Accepted - runtime 65ms - memory 13.7MB.py ├── 2413-smallest-number-in-infinite-set └── 2023-04-26 16.14.25 - Accepted - runtime 122ms - memory 17.1MB.py ├── 2416-evaluate-boolean-binary-tree └── 2024-02-01 23.03.43 - Accepted - runtime 37ms - memory 16.9MB.py ├── 242-valid-anagram ├── 2022-07-02 19.14.14 - Accepted - runtime 87ms - memory 15.1MB.py └── 2022-07-28 13.49.37 - Accepted - runtime 98ms - memory 15.1MB.py ├── 2421-maximum-number-of-pairs-in-array ├── 2022-07-30 01.49.55 - Accepted - runtime 47ms - memory 13.8MB.py ├── 2022-07-30 01.50.06 - Accepted - runtime 60ms - memory 13.9MB.py ├── 2022-07-30 01.50.12 - Accepted - runtime 52ms - memory 13.9MB.py ├── 2022-07-30 01.50.21 - Accepted - runtime 39ms - memory 13.9MB.py ├── 2022-07-30 01.51.39 - Accepted - runtime 59ms - memory 13.9MB.py └── 2024-04-01 14.50.09 - Accepted - runtime 42ms - memory 16.5MB.py ├── 2427-first-letter-to-appear-twice └── 2022-07-28 21.31.06 - Accepted - runtime 35ms - memory 13.8MB.py ├── 2433-best-poker-hand └── 2022-07-28 21.29.29 - Accepted - runtime 50ms - memory 13.9MB.py ├── 2442-number-of-arithmetic-triplets ├── 2022-09-17 14.00.13 - Accepted - runtime 2826ms - memory 13.9MB.py ├── 2022-09-17 14.17.00 - Accepted - runtime 0ms - memory 8.7MB.cpp └── 2022-09-20 14.49.29 - Accepted - runtime 76ms - memory 13.9MB.py ├── 2444-longest-ideal-subsequence └── 2024-04-25 09.55.54 - Accepted - runtime 288ms - memory 17.5MB.py ├── 2469-longest-subsequence-with-limited-sum └── 2022-12-25 22.31.26 - Accepted - runtime 317ms - memory 14.2MB.py ├── 2470-removing-stars-from-a-string ├── 2023-04-11 23.34.17 - Accepted - runtime 659ms - memory 15.5MB.py ├── 2023-04-11 23.34.27 - Accepted - runtime 661ms - memory 15.4MB.py ├── 2023-04-11 23.35.49 - Accepted - runtime 600ms - memory 15.2MB.py ├── 2023-04-11 23.36.19 - Accepted - runtime 266ms - memory 15.6MB.py └── 2023-04-11 23.36.31 - Accepted - runtime 222ms - memory 15.5MB.py ├── 2473-max-sum-of-a-pair-with-equal-sum-of-digits ├── 2024-04-01 15.32.51 - Accepted - runtime 828ms - memory 31.3MB.py └── 2024-04-01 15.43.14 - Accepted - runtime 826ms - memory 31.2MB.py ├── 2479-meeting-rooms-iii ├── 2024-04-13 16.05.34 - Accepted - runtime 1191ms - memory 62.3MB.py ├── 2024-04-13 16.06.00 - Accepted - runtime 1157ms - memory 62.5MB.py └── 2024-04-13 16.07.03 - Accepted - runtime 268ms - memory 38.1MB.py ├── 2487-optimal-partition-of-string ├── 2023-04-05 23.26.07 - Accepted - runtime 248ms - memory 14.5MB.py ├── 2023-04-05 23.26.17 - Accepted - runtime 249ms - memory 14.6MB.py ├── 2023-04-05 23.26.27 - Accepted - runtime 248ms - memory 14.7MB.py └── 2023-04-05 23.28.29 - Accepted - runtime 68ms - memory 14.7MB.py ├── 2491-smallest-even-multiple └── 2022-09-30 16.06.11 - Accepted - runtime 66ms - memory 13.9MB.py ├── 2493-reverse-odd-levels-of-binary-tree ├── 2022-10-03 14.32.24 - Accepted - runtime 3777ms - memory 20.5MB.py ├── 2022-10-03 14.58.11 - Accepted - runtime 941ms - memory 20.7MB.py ├── 2022-10-03 14.59.35 - Accepted - runtime 3961ms - memory 20.7MB.py ├── 2022-10-03 14.59.55 - Accepted - runtime 3860ms - memory 20.7MB.py ├── 2022-10-03 15.00.13 - Accepted - runtime 943ms - memory 20.5MB.py ├── 2022-10-03 15.01.54 - Accepted - runtime 3772ms - memory 20.4MB.py ├── 2022-10-03 15.02.20 - Accepted - runtime 3840ms - memory 20.6MB.py ├── 2022-10-03 15.02.47 - Accepted - runtime 949ms - memory 20.6MB.py ├── 2022-10-03 15.02.58 - Accepted - runtime 3805ms - memory 20.5MB.py ├── 2022-10-03 15.03.40 - Accepted - runtime 3804ms - memory 20.5MB.py ├── 2022-10-03 15.03.51 - Accepted - runtime 3698ms - memory 20.6MB.py ├── 2022-10-03 15.04.03 - Accepted - runtime 946ms - memory 20.4MB.py ├── 2022-10-03 15.05.18 - Accepted - runtime 3913ms - memory 20.7MB.py ├── 2022-10-03 15.05.28 - Accepted - runtime 3958ms - memory 20.7MB.py ├── 2022-10-03 15.05.40 - Accepted - runtime 4119ms - memory 20.7MB.py ├── 2022-10-03 15.05.50 - Accepted - runtime 4019ms - memory 20.6MB.py ├── 2022-10-03 15.06.00 - Accepted - runtime 4013ms - memory 20.6MB.py ├── 2022-10-03 15.06.10 - Accepted - runtime 4028ms - memory 20.6MB.py ├── 2022-10-03 15.06.23 - Accepted - runtime 3852ms - memory 20.5MB.py ├── 2022-10-03 15.06.35 - Accepted - runtime 3609ms - memory 20.5MB.py ├── 2022-10-03 15.06.44 - Accepted - runtime 952ms - memory 20.6MB.py └── 2022-10-03 22.36.25 - Accepted - runtime 3892ms - memory 20.5MB.py ├── 2502-sort-the-people └── 2022-09-27 11.27.35 - Accepted - runtime 292ms - memory 14.6MB.py ├── 2507-number-of-common-factors └── 2024-01-06 18.19.17 - Accepted - runtime 33ms - memory 17.2MB.py ├── 2524-largest-positive-integer-that-exists-with-its-negative └── 2024-05-02 09.12.42 - Accepted - runtime 105ms - memory 16.8MB.py ├── 2527-count-subarrays-with-fixed-bounds └── 2024-03-31 12.06.30 - Accepted - runtime 720ms - memory 31MB.py ├── 2532-remove-letter-to-equalize-frequency ├── 2024-04-05 15.05.03 - Accepted - runtime 32ms - memory 16.7MB.py └── 2024-04-05 15.05.17 - Accepted - runtime 29ms - memory 16.7MB.py ├── 2556-convert-the-temperature └── 2024-02-02 19.19.00 - Accepted - runtime 28ms - memory 16.5MB.py ├── 2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level └── 2024-04-07 23.13.58 - Accepted - runtime 404ms - memory 47.4MB.py ├── 257-binary-tree-paths ├── 2022-07-01 16.16.49 - Accepted - runtime 56ms - memory 13.9MB.py ├── 2024-01-13 20.12.32 - Accepted - runtime 40ms - memory 17.3MB.py └── 2024-02-18 17.59.55 - Accepted - runtime 0ms - memory 17.4MB.cpp ├── 2571-find-the-pivot-integer └── 2024-03-13 12.58.11 - Accepted - runtime 42ms - memory 16.7MB.py ├── 2573-remove-nodes-from-linked-list ├── 2024-02-25 19.28.14 - Accepted - runtime 258ms - memory 164.4MB.cpp └── 2024-05-06 10.34.18 - Accepted - runtime 377ms - memory 62.4MB.py ├── 258-add-digits ├── 2022-07-02 22.43.02 - Accepted - runtime 28ms - memory 13.9MB.py ├── 2022-07-02 22.45.15 - Accepted - runtime 3ms - memory 5.6MB.c ├── 2022-07-02 22.45.23 - Accepted - runtime 3ms - memory 5.5MB.c ├── 2022-07-02 22.45.29 - Accepted - runtime 4ms - memory 5.4MB.c ├── 2022-07-02 22.45.40 - Accepted - runtime 4ms - memory 5.5MB.c └── 2023-04-26 15.51.22 - Accepted - runtime 36ms - memory 13.9MB.py ├── 26-remove-duplicates-from-sorted-array ├── 2022-04-25 10.18.41 - Accepted - runtime 168ms - memory 15.5MB.py ├── 2022-04-25 10.18.49 - Accepted - runtime 188ms - memory 15.7MB.py ├── 2022-04-25 10.20.50 - Accepted - runtime 97ms - memory 15.4MB.py └── 2024-02-17 12.24.26 - Accepted - runtime 11ms - memory 21.1MB.cpp ├── 263-ugly-number └── 2023-04-30 00.09.10 - Accepted - runtime 54ms - memory 16.4MB.py ├── 2634-minimum-common-value └── 2024-03-09 15.00.41 - Accepted - runtime 335ms - memory 42.6MB.py ├── 2663-distribute-money-to-maximum-children └── 2024-04-08 23.37.51 - Accepted - runtime 44ms - memory 16.7MB.py ├── 268-missing-number ├── 2022-07-01 10.25.51 - Accepted - runtime 143ms - memory 15.2MB.py ├── 2024-02-20 10.35.25 - Accepted - runtime 16ms - memory 20.3MB.cpp └── 2024-02-20 10.36.25 - Accepted - runtime 15ms - memory 20.3MB.cpp ├── 27-remove-element ├── 2022-04-25 12.32.43 - Accepted - runtime 44ms - memory 14MB.py ├── 2022-04-25 12.32.51 - Accepted - runtime 42ms - memory 13.9MB.py ├── 2022-04-25 12.33.28 - Accepted - runtime 47ms - memory 13.9MB.py ├── 2022-04-25 12.33.34 - Accepted - runtime 36ms - memory 13.9MB.py └── 2024-02-17 12.44.13 - Accepted - runtime 0ms - memory 10.4MB.cpp ├── 2722-prime-in-diagonal └── 2024-01-05 23.09.49 - Accepted - runtime 646ms - memory 29.3MB.py ├── 278-first-bad-version └── 2022-07-17 16.26.10 - Accepted - runtime 22ms - memory 13.9MB.py ├── 279-perfect-squares ├── 2022-11-22 23.19.39 - Accepted - runtime 37ms - memory 13.9MB.py ├── 2022-11-22 23.22.56 - Accepted - runtime 70ms - memory 13.9MB.py ├── 2022-11-22 23.23.41 - Accepted - runtime 47ms - memory 13.9MB.py └── 2022-11-22 23.54.47 - Accepted - runtime 50ms - memory 14MB.py ├── 2793-count-the-number-of-complete-components └── 2024-04-26 17.02.35 - Accepted - runtime 496ms - memory 17MB.py ├── 28-find-the-index-of-the-first-occurrence-in-a-string ├── 2022-04-25 16.30.49 - Accepted - runtime 52ms - memory 13.9MB.py └── 2024-02-17 12.48.04 - Accepted - runtime 0ms - memory 7.5MB.cpp ├── 2812-find-the-maximum-achievable-number └── 2024-02-02 19.17.17 - Accepted - runtime 45ms - memory 16.5MB.py ├── 2820-return-length-of-arguments-passed └── 2024-02-11 14.21.02 - Accepted - runtime 55ms - memory 48.7MB.js ├── 283-move-zeroes └── 2022-07-01 18.36.22 - Accepted - runtime 262ms - memory 15.6MB.py ├── 2859-add-two-promises └── 2024-04-01 14.36.19 - Accepted - runtime 55ms - memory 50.4MB.js ├── 2860-sort-by └── 2024-04-17 22.44.39 - Accepted - runtime 128ms - memory 66.2MB.js ├── 287-find-the-duplicate-number ├── 2023-01-11 20.37.21 - Accepted - runtime 593ms - memory 30.2MB.py ├── 2024-02-15 22.16.06 - Accepted - runtime 463ms - memory 32.8MB.py └── 2024-03-24 21.04.20 - Accepted - runtime 438ms - memory 32.7MB.py ├── 2871-double-a-number-represented-as-a-linked-list ├── 2024-05-07 10.18.31 - Accepted - runtime 323ms - memory 20.2MB.py └── 2024-05-07 10.29.41 - Accepted - runtime 235ms - memory 19.4MB.py ├── 2876-number-of-employees-who-met-the-target └── 2024-04-01 14.43.54 - Accepted - runtime 47ms - memory 16.5MB.py ├── 2881-split-strings-by-separator └── 2024-04-06 11.03.49 - Accepted - runtime 91ms - memory 16.5MB.py ├── 2887-sort-vowels-in-a-string └── 2024-04-06 11.00.30 - Accepted - runtime 131ms - memory 18.8MB.py ├── 29-divide-two-integers └── 2023-04-02 15.57.24 - Accepted - runtime 40ms - memory 13.9MB.py ├── 290-word-pattern ├── 2022-07-18 20.19.03 - Accepted - runtime 42ms - memory 14MB.py ├── 2022-07-18 20.32.42 - Accepted - runtime 53ms - memory 13.9MB.py └── 2023-01-06 02.01.38 - Accepted - runtime 53ms - memory 14MB.py ├── 2903-insert-greatest-common-divisors-in-linked-list └── 2024-04-17 22.49.19 - Accepted - runtime 54ms - memory 19.6MB.py ├── 292-nim-game └── 2024-04-01 15.51.32 - Accepted - runtime 37ms - memory 16.5MB.py ├── 3-longest-substring-without-repeating-characters └── 2022-10-07 20.32.16 - Accepted - runtime 118ms - memory 13.9MB.py ├── 300-longest-increasing-subsequence ├── 2024-04-27 18.35.54 - Accepted - runtime 1107ms - memory 17MB.py └── 2024-04-27 18.39.01 - Accepted - runtime 1105ms - memory 17MB.py ├── 303-range-sum-query-immutable ├── 2024-03-14 00.10.11 - Accepted - runtime 794ms - memory 19.9MB.py └── 2024-03-14 00.11.29 - Accepted - runtime 65ms - memory 20.1MB.py ├── 3055-maximum-odd-binary-number ├── 2024-03-01 15.35.35 - Accepted - runtime 37ms - memory 16.5MB.py └── 2024-03-01 15.38.05 - Accepted - runtime 0ms - memory 9.2MB.cpp ├── 3062-create-a-dataframe-from-list └── 2024-02-23 23.55.23 - Accepted - runtime 670ms - memory 64.9MB.pd.py ├── 3064-reshape-data-concatenate └── 2024-04-01 14.37.48 - Accepted - runtime 788ms - memory 65.8MB.pd.py ├── 3065-display-the-first-three-rows └── 2024-04-01 14.31.56 - Accepted - runtime 628ms - memory 65.7MB.pd.py ├── 3066-create-a-new-column └── 2024-04-01 14.38.48 - Accepted - runtime 719ms - memory 65.3MB.pd.py ├── 3067-modify-columns └── 2024-04-01 14.35.25 - Accepted - runtime 776ms - memory 65.5MB.pd.py ├── 3094-minimum-number-of-operations-to-make-array-empty └── 2024-01-04 23.34.25 - Accepted - runtime 528ms - memory 32.1MB.py ├── 310-minimum-height-trees └── 2024-04-23 10.17.55 - Accepted - runtime 520ms - memory 42.1MB.py ├── 315-count-of-smaller-numbers-after-self └── 2022-07-23 11.44.06 - Accepted - runtime 4141ms - memory 41.8MB.py ├── 3172-divisible-and-non-divisible-sums-difference └── 2024-02-02 19.21.58 - Accepted - runtime 37ms - memory 16.6MB.py ├── 319-bulb-switcher ├── 2023-04-27 09.52.23 - Accepted - runtime 40ms - memory 16.2MB.py ├── 2023-04-27 09.52.33 - Accepted - runtime 39ms - memory 16.4MB.py ├── 2023-04-27 09.52.40 - Accepted - runtime 50ms - memory 16.4MB.py └── 2023-04-27 09.53.18 - Accepted - runtime 55ms - memory 16.3MB.py ├── 3194-find-words-containing-character └── 2024-02-02 19.20.05 - Accepted - runtime 75ms - memory 16.7MB.py ├── 32-longest-valid-parentheses └── 2024-04-16 11.12.23 - Accepted - runtime 46ms - memory 17.4MB.py ├── 3213-count-subarrays-where-max-element-appears-at-least-k-times └── 2024-03-29 12.15.06 - Accepted - runtime 896ms - memory 31.4MB.py ├── 3225-length-of-longest-subarray-with-at-most-k-frequency ├── 2024-03-28 12.07.07 - Accepted - runtime 1276ms - memory 31.1MB.py └── 2024-03-28 22.35.20 - Accepted - runtime 1249ms - memory 31.2MB.py ├── 3242-count-elements-with-maximum-frequency └── 2024-03-08 12.18.45 - Accepted - runtime 38ms - memory 16.6MB.py ├── 3249-minimum-number-of-operations-to-make-array-xor-equal-to-k └── 2024-04-29 09.50.45 - Accepted - runtime 591ms - memory 30.8MB.py ├── 326-power-of-three └── 2022-07-20 23.19.49 - Accepted - runtime 121ms - memory 13.8MB.py ├── 328-odd-even-linked-list └── 2024-05-07 11.26.00 - Accepted - runtime 40ms - memory 18.6MB.py ├── 3351-maximize-happiness-of-selected-children └── 2024-05-09 09.59.41 - Accepted - runtime 813ms - memory 43.6MB.py ├── 338-counting-bits └── 2022-07-01 10.23.04 - Accepted - runtime 200ms - memory 20.8MB.py ├── 34-find-first-and-last-position-of-element-in-sorted-array ├── 2022-07-25 20.05.02 - Accepted - runtime 139ms - memory 15.5MB.py ├── 2024-02-21 11.30.45 - Accepted - runtime 3ms - memory 16MB.cpp └── 2024-02-21 11.31.27 - Accepted - runtime 4ms - memory 16.1MB.cpp ├── 342-power-of-four └── 2022-07-20 23.20.04 - Accepted - runtime 59ms - memory 13.9MB.py ├── 344-reverse-string ├── 2022-06-30 22.10.25 - Accepted - runtime 399ms - memory 18.4MB.py └── 2022-06-30 22.11.34 - Accepted - runtime 274ms - memory 18.3MB.py ├── 345-reverse-vowels-of-a-string └── 2022-06-30 22.19.27 - Accepted - runtime 128ms - memory 14.7MB.py ├── 349-intersection-of-two-arrays ├── 2022-07-18 19.54.32 - Accepted - runtime 46ms - memory 14.1MB.py └── 2024-03-10 14.20.48 - Accepted - runtime 42ms - memory 16.8MB.py ├── 35-search-insert-position ├── 2022-06-15 20.57.03 - Accepted - runtime 92ms - memory 14.6MB.py ├── 2022-06-15 20.57.16 - Accepted - runtime 67ms - memory 14.7MB.py ├── 2022-06-15 20.57.22 - Accepted - runtime 82ms - memory 14.7MB.py ├── 2022-06-15 20.57.29 - Accepted - runtime 115ms - memory 14.7MB.py ├── 2022-06-15 21.09.32 - Accepted - runtime 90ms - memory 14.8MB.py ├── 2024-02-17 13.15.34 - Accepted - runtime 0ms - memory 11.9MB.cpp └── 2024-02-17 13.16.29 - Accepted - runtime 0ms - memory 12.1MB.cpp ├── 350-intersection-of-two-arrays-ii └── 2024-04-01 16.06.51 - Accepted - runtime 48ms - memory 16.7MB.py ├── 36-valid-sudoku ├── 2023-02-09 12.01.46 - Accepted - runtime 89ms - memory 13.9MB.py └── 2024-02-21 11.36.47 - Accepted - runtime 7ms - memory 22.9MB.cpp ├── 367-valid-perfect-square └── 2024-04-01 18.36.26 - Accepted - runtime 33ms - memory 16.5MB.py ├── 371-sum-of-two-integers └── 2024-04-15 15.06.30 - Accepted - runtime 37ms - memory 16.5MB.py ├── 374-guess-number-higher-or-lower ├── 2022-07-15 20.04.23 - Accepted - runtime 57ms - memory 13.8MB.py ├── 2022-07-16 01.28.04 - Accepted - runtime 37ms - memory 13.8MB.py └── 2023-03-07 23.57.02 - Accepted - runtime 27ms - memory 13.8MB.py ├── 38-count-and-say └── 2024-04-19 00.22.45 - Accepted - runtime 44ms - memory 16.6MB.py ├── 380-insert-delete-getrandom-o1 └── 2024-01-17 19.17.35 - Accepted - runtime 467ms - memory 64.7MB.py ├── 382-linked-list-random-node └── 2024-03-01 00.28.30 - Accepted - runtime 63ms - memory 19.3MB.py ├── 383-ransom-note ├── 2022-06-30 22.24.43 - Accepted - runtime 50ms - memory 14.2MB.py └── 2022-06-30 22.25.01 - Accepted - runtime 58ms - memory 14.3MB.py ├── 387-first-unique-character-in-a-string ├── 2022-07-11 14.13.30 - Accepted - runtime 313ms - memory 14.3MB.py ├── 2022-07-11 14.14.59 - Accepted - runtime 6275ms - memory 14.1MB.py ├── 2022-08-20 16.43.27 - Accepted - runtime 84ms - memory 14.2MB.py ├── 2022-08-20 16.43.37 - Accepted - runtime 7503ms - memory 14.3MB.py ├── 2022-08-20 16.43.51 - Accepted - runtime 90ms - memory 14MB.py ├── 2023-01-10 22.10.30 - Accepted - runtime 62ms - memory 14.2MB.py └── 2024-02-05 22.46.30 - Accepted - runtime 415ms - memory 16.7MB.py ├── 389-find-the-difference ├── 2022-10-12 19.27.01 - Accepted - runtime 58ms - memory 13.8MB.py ├── 2024-02-17 23.19.32 - Accepted - runtime 2ms - memory 7.9MB.cpp └── 2024-02-17 23.19.54 - Accepted - runtime 5ms - memory 7.9MB.cpp ├── 392-is-subsequence ├── 2024-02-15 22.32.55 - Accepted - runtime 34ms - memory 16.5MB.py └── 2024-02-17 23.05.21 - Accepted - runtime 0ms - memory 7.5MB.cpp ├── 394-decode-string └── 2024-04-04 09.53.47 - Accepted - runtime 37ms - memory 16.5MB.py ├── 401-binary-watch └── 2024-05-05 20.11.33 - Accepted - runtime 37ms - memory 16.5MB.py ├── 402-remove-k-digits └── 2024-04-11 11.14.34 - Accepted - runtime 50ms - memory 18.1MB.py ├── 404-sum-of-left-leaves ├── 2024-04-01 19.12.22 - Accepted - runtime 37ms - memory 16.7MB.py └── 2024-04-14 09.45.14 - Accepted - runtime 40ms - memory 16.8MB.py ├── 405-convert-a-number-to-hexadecimal └── 2024-04-01 19.18.10 - Accepted - runtime 27ms - memory 16.5MB.py ├── 409-longest-palindrome └── 2024-03-31 19.47.34 - Accepted - runtime 30ms - memory 16.5MB.py ├── 41-first-missing-positive └── 2024-03-26 12.25.07 - Accepted - runtime 272ms - memory 35.2MB.py ├── 412-fizz-buzz └── 2022-06-30 21.15.15 - Accepted - runtime 55ms - memory 15.2MB.py ├── 414-third-maximum-number └── 2022-07-01 22.05.17 - Accepted - runtime 123ms - memory 15.6MB.py ├── 415-add-strings └── 2022-07-03 09.19.58 - Accepted - runtime 60ms - memory 14MB.py ├── 42-trapping-rain-water └── 2024-04-12 09.55.48 - Accepted - runtime 98ms - memory 18.4MB.py ├── 434-number-of-segments-in-a-string └── 2022-07-10 22.41.12 - Accepted - runtime 75ms - memory 13.9MB.py ├── 441-arranging-coins ├── 2024-04-01 15.48.23 - Accepted - runtime 427ms - memory 16.4MB.py └── 2024-04-01 15.48.52 - Accepted - runtime 44ms - memory 16.4MB.py ├── 442-find-all-duplicates-in-an-array └── 2024-03-25 17.12.30 - Accepted - runtime 268ms - memory 25.2MB.py ├── 443-string-compression └── 2024-04-04 09.32.21 - Accepted - runtime 55ms - memory 16.8MB.py ├── 445-add-two-numbers-ii └── 2024-02-28 23.29.49 - Accepted - runtime 59ms - memory 16.6MB.py ├── 448-find-all-numbers-disappeared-in-an-array └── 2024-04-01 19.21.36 - Accepted - runtime 258ms - memory 26.9MB.py ├── 451-sort-characters-by-frequency ├── 2024-02-07 16.15.36 - Accepted - runtime 64ms - memory 17.8MB.py └── 2024-02-07 16.15.53 - Accepted - runtime 37ms - memory 17.8MB.py ├── 452-minimum-number-of-arrows-to-burst-balloons └── 2024-03-18 16.29.28 - Accepted - runtime 999ms - memory 62.7MB.py ├── 455-assign-cookies ├── 2022-07-03 20.14.52 - Accepted - runtime 252ms - memory 15.5MB.py └── 2024-01-27 20.15.39 - Accepted - runtime 145ms - memory 18.6MB.py ├── 459-repeated-substring-pattern └── 2024-03-31 20.04.41 - Accepted - runtime 40ms - memory 16.7MB.py ├── 46-permutations └── 2024-04-25 22.57.18 - Accepted - runtime 36ms - memory 16.5MB.py ├── 461-hamming-distance └── 2024-04-01 19.30.11 - Accepted - runtime 28ms - memory 16.5MB.py ├── 463-island-perimeter ├── 2024-04-01 19.32.09 - Accepted - runtime 387ms - memory 17MB.py └── 2024-04-18 08.45.52 - Accepted - runtime 407ms - memory 16.9MB.py ├── 476-number-complement └── 2023-05-13 10.07.07 - Accepted - runtime 39ms - memory 16.1MB.py ├── 482-license-key-formatting └── 2024-03-31 20.09.43 - Accepted - runtime 42ms - memory 19.6MB.py ├── 485-max-consecutive-ones └── 2024-04-01 19.36.48 - Accepted - runtime 268ms - memory 16.8MB.py ├── 49-group-anagrams ├── 2023-01-28 18.50.16 - Accepted - runtime 106ms - memory 17.7MB.py ├── 2024-02-06 13.40.41 - Accepted - runtime 136ms - memory 21MB.py └── 2024-02-06 13.42.17 - Accepted - runtime 80ms - memory 20.2MB.py ├── 496-next-greater-element-i └── 2022-09-26 17.35.26 - Accepted - runtime 168ms - memory 14.2MB.py ├── 5-longest-palindromic-substring ├── 2022-11-27 19.08.05 - Accepted - runtime 390ms - memory 14MB.py ├── 2022-11-27 19.20.15 - Accepted - runtime 750ms - memory 13.8MB.py ├── 2022-11-27 19.26.11 - Accepted - runtime 1620ms - memory 14MB.py ├── 2022-11-28 10.32.44 - Accepted - runtime 1300ms - memory 14MB.py ├── 2022-12-16 14.17.05 - Accepted - runtime 575ms - memory 13.8MB.py ├── 2023-01-19 18.12.07 - Accepted - runtime 544ms - memory 13.8MB.py ├── 2023-03-03 14.57.53 - Accepted - runtime 4224ms - memory 37.3MB.kt └── 2024-02-18 12.02.26 - Accepted - runtime 7ms - memory 12.9MB.cpp ├── 50-powx-n └── 2022-07-06 13.14.25 - Accepted - runtime 53ms - memory 14MB.py ├── 500-keyboard-row └── 2022-07-21 17.04.16 - Accepted - runtime 28ms - memory 13.9MB.py ├── 504-base-7 └── 2024-04-01 19.43.04 - Accepted - runtime 34ms - memory 16.4MB.py ├── 506-relative-ranks └── 2024-05-08 10.23.23 - Accepted - runtime 60ms - memory 17.7MB.py ├── 513-find-bottom-left-tree-value ├── 2024-02-28 19.11.58 - Accepted - runtime 693ms - memory 19.4MB.py ├── 2024-02-28 19.14.16 - Accepted - runtime 28ms - memory 18.2MB.py └── 2024-02-28 19.19.57 - Accepted - runtime 13ms - memory 20.2MB.cpp ├── 514-freedom-trail └── 2024-04-27 14.47.26 - Accepted - runtime 71ms - memory 16.5MB.py ├── 515-find-largest-value-in-each-tree-row ├── 2024-01-22 00.05.58 - Accepted - runtime 41ms - memory 18.3MB.py └── 2024-01-22 00.13.33 - Accepted - runtime 42ms - memory 18.2MB.py ├── 516-longest-palindromic-subsequence └── 2023-04-14 12.17.20 - Accepted - runtime 1179ms - memory 13.9MB.py ├── 520-detect-capital ├── 2022-07-21 17.06.47 - Accepted - runtime 48ms - memory 13.9MB.py ├── 2023-01-05 20.48.46 - Accepted - runtime 67ms - memory 13.7MB.py └── 2023-01-05 20.50.30 - Accepted - runtime 65ms - memory 13.9MB.py ├── 521-longest-uncommon-subsequence-i └── 2024-03-31 20.55.28 - Accepted - runtime 22ms - memory 16.5MB.py ├── 525-contiguous-array └── 2024-03-16 14.29.53 - Accepted - runtime 609ms - memory 22.2MB.py ├── 528-swapping-nodes-in-a-linked-list ├── 2023-05-15 15.35.57 - Accepted - runtime 1845ms - memory 66.8MB.py ├── 2024-02-24 00.30.15 - Accepted - runtime 372ms - memory 40.5MB.py └── 2024-02-24 00.41.36 - Accepted - runtime 364ms - memory 183.8MB.cpp ├── 53-maximum-subarray └── 2022-06-23 16.36.47 - Accepted - runtime 1257ms - memory 27.9MB.py ├── 54-spiral-matrix ├── 2023-01-28 19.23.56 - Accepted - runtime 32ms - memory 13.9MB.py ├── 2023-01-31 19.06.09 - Accepted - runtime 25ms - memory 13.9MB.py ├── 2023-01-31 19.10.29 - Accepted - runtime 37ms - memory 13.9MB.py └── 2023-05-09 12.38.05 - Accepted - runtime 32ms - memory 16.2MB.py ├── 541-reverse-string-ii └── 2024-03-31 23.45.22 - Accepted - runtime 44ms - memory 16.7MB.py ├── 543-diameter-of-binary-tree ├── 2024-02-18 22.50.50 - Accepted - runtime 7ms - memory 18.8MB.cpp └── 2024-02-28 00.27.21 - Accepted - runtime 6ms - memory 18.9MB.cpp ├── 551-student-attendance-record-i └── 2024-03-31 23.50.21 - Accepted - runtime 32ms - memory 16.6MB.py ├── 557-reverse-words-in-a-string-iii ├── 2023-01-27 12.53.59 - Accepted - runtime 43ms - memory 14.6MB.py ├── 2024-02-18 00.20.23 - Accepted - runtime 23ms - memory 16.7MB.cpp └── 2024-02-18 00.22.14 - Accepted - runtime 10ms - memory 13MB.cpp ├── 561-array-partition └── 2023-01-27 13.06.41 - Accepted - runtime 341ms - memory 16.6MB.py ├── 57-insert-interval └── 2024-03-18 00.35.25 - Accepted - runtime 62ms - memory 20MB.py ├── 572-subtree-of-another-tree └── 2024-01-07 19.33.08 - Accepted - runtime 72ms - memory 17.6MB.py ├── 58-length-of-last-word ├── 2022-06-15 21.46.06 - Accepted - runtime 36ms - memory 13.8MB.py ├── 2024-02-17 13.21.12 - Accepted - runtime 0ms - memory 7.6MB.cpp └── 2024-04-01 15.53.26 - Accepted - runtime 32ms - memory 16.8MB.py ├── 599-minimum-index-sum-of-two-lists └── 2024-04-01 00.27.29 - Accepted - runtime 141ms - memory 17.1MB.py ├── 6-zigzag-conversion └── 2024-03-31 18.49.00 - Accepted - runtime 48ms - memory 16.5MB.py ├── 605-can-place-flowers └── 2023-03-20 10.45.08 - Accepted - runtime 182ms - memory 14.3MB.py ├── 606-construct-string-from-binary-tree └── 2024-01-07 22.32.07 - Accepted - runtime 41ms - memory 18.6MB.py ├── 61-rotate-list └── 2022-07-18 16.08.07 - Accepted - runtime 58ms - memory 13.8MB.py ├── 617-merge-two-binary-trees ├── 2024-02-02 00.33.11 - Accepted - runtime 63ms - memory 17MB.py └── 2024-02-02 00.34.59 - Accepted - runtime 48ms - memory 17.1MB.py ├── 62-unique-paths ├── 2022-08-01 12.55.38 - Accepted - runtime 55ms - memory 13.9MB.py └── 2022-08-01 12.55.49 - Accepted - runtime 68ms - memory 13.8MB.py ├── 621-task-scheduler └── 2024-03-19 12.48.51 - Accepted - runtime 374ms - memory 17MB.py ├── 623-add-one-row-to-tree ├── 2024-04-16 12.14.31 - Accepted - runtime 53ms - memory 17.8MB.py └── 2024-04-16 12.16.27 - Accepted - runtime 46ms - memory 17.9MB.py ├── 630-course-schedule-iii ├── 2022-06-23 13.07.08 - Accepted - runtime 1542ms - memory 20.2MB.py ├── 2022-06-23 13.07.18 - Accepted - runtime 963ms - memory 19.3MB.py └── 2022-06-23 14.46.58 - Accepted - runtime 955ms - memory 20.1MB.py ├── 633-sum-of-square-numbers └── 2024-04-15 15.14.41 - Accepted - runtime 127ms - memory 16.5MB.py ├── 64-minimum-path-sum ├── 2023-03-27 15.21.32 - Accepted - runtime 91ms - memory 15.6MB.py └── 2023-03-27 15.38.59 - Accepted - runtime 96ms - memory 15.6MB.py ├── 645-set-mismatch ├── 2022-10-23 15.13.18 - Accepted - runtime 526ms - memory 15.8MB.py ├── 2022-10-23 15.18.00 - Accepted - runtime 501ms - memory 15.4MB.py └── 2022-10-23 15.18.20 - Accepted - runtime 463ms - memory 15.4MB.py ├── 647-palindromic-substrings └── 2024-02-10 13.34.43 - Accepted - runtime 415ms - memory 16.5MB.py ├── 65-valid-number └── 2024-04-05 10.55.01 - Accepted - runtime 38ms - memory 16.6MB.py ├── 653-two-sum-iv-input-is-a-bst └── 2024-01-07 18.59.04 - Accepted - runtime 57ms - memory 19.7MB.py ├── 654-maximum-binary-tree └── 2024-02-08 22.21.01 - Accepted - runtime 128ms - memory 17.1MB.py ├── 657-robot-return-to-origin └── 2024-04-01 00.31.58 - Accepted - runtime 102ms - memory 16.6MB.py ├── 66-plus-one ├── 2022-06-15 23.39.23 - Accepted - runtime 72ms - memory 13.9MB.py └── 2024-02-17 14.25.06 - Accepted - runtime 0ms - memory 10.3MB.cpp ├── 665-non-decreasing-array └── 2022-06-25 22.48.17 - Accepted - runtime 193ms - memory 15.2MB.py ├── 67-add-binary └── 2022-06-20 19.33.28 - Accepted - runtime 36ms - memory 13.9MB.py ├── 678-valid-parenthesis-string └── 2024-04-07 14.11.33 - Accepted - runtime 39ms - memory 16.6MB.py ├── 686-repeated-string-match └── 2024-03-12 16.07.58 - Accepted - runtime 41ms - memory 16.7MB.py ├── 69-sqrtx └── 2022-06-20 19.34.51 - Accepted - runtime 59ms - memory 13.9MB.py ├── 695-max-area-of-island ├── 2022-07-15 14.42.17 - Accepted - runtime 427ms - memory 14.4MB.py ├── 2022-07-15 14.47.48 - Accepted - runtime 344ms - memory 14.8MB.py ├── 2022-07-16 01.20.04 - Accepted - runtime 250ms - memory 14.2MB.py ├── 2022-07-16 01.20.31 - Accepted - runtime 307ms - memory 14MB.py ├── 2022-07-16 01.23.13 - Accepted - runtime 301ms - memory 14.1MB.py ├── 2022-07-16 01.23.36 - Accepted - runtime 382ms - memory 14MB.py └── 2022-07-16 01.23.48 - Accepted - runtime 249ms - memory 14.1MB.py ├── 696-count-binary-substrings └── 2024-04-08 17.06.30 - Accepted - runtime 99ms - memory 18.3MB.py ├── 7-reverse-integer ├── 2022-06-29 10.37.22 - Accepted - runtime 56ms - memory 14MB.py └── 2023-01-06 21.21.32 - Accepted - runtime 48ms - memory 13.9MB.py ├── 70-climbing-stairs ├── 2022-06-23 16.51.25 - Accepted - runtime 38ms - memory 13.8MB.py ├── 2022-06-23 16.53.01 - Accepted - runtime 71ms - memory 14MB.py ├── 2022-06-23 16.53.10 - Accepted - runtime 52ms - memory 13.9MB.py └── 2022-06-23 16.53.19 - Accepted - runtime 62ms - memory 13.9MB.py ├── 71-simplify-path ├── 2023-04-12 13.30.05 - Accepted - runtime 32ms - memory 13.7MB.py └── 2023-04-13 23.23.56 - Accepted - runtime 29ms - memory 13.8MB.py ├── 713-subarray-product-less-than-k ├── 2024-03-27 19.58.59 - Accepted - runtime 508ms - memory 19.2MB.py └── 2024-03-28 11.16.26 - Accepted - runtime 530ms - memory 19.4MB.py ├── 728-self-dividing-numbers └── 2022-09-26 14.17.53 - Accepted - runtime 121ms - memory 13.9MB.py ├── 73-set-matrix-zeroes └── 2024-03-10 18.21.20 - Accepted - runtime 116ms - memory 17.5MB.py ├── 739-daily-temperatures └── 2024-01-31 21.29.56 - Accepted - runtime 898ms - memory 32.4MB.py ├── 742-to-lower-case └── 2022-09-20 14.25.24 - Accepted - runtime 61ms - memory 13.8MB.py ├── 747-min-cost-climbing-stairs └── 2022-07-10 15.01.01 - Accepted - runtime 108ms - memory 14MB.py ├── 753-open-the-lock └── 2024-04-22 09.48.00 - Accepted - runtime 389ms - memory 18.1MB.py ├── 775-n-ary-tree-preorder-traversal ├── 2022-07-07 11.52.59 - Accepted - runtime 70ms - memory 16.4MB.py ├── 2022-07-07 11.54.29 - Accepted - runtime 80ms - memory 16.1MB.py ├── 2022-07-07 11.57.42 - Accepted - runtime 60ms - memory 16MB.py ├── 2022-07-07 11.57.57 - Accepted - runtime 99ms - memory 16MB.py ├── 2022-07-07 11.58.14 - Accepted - runtime 68ms - memory 16MB.py └── 2024-01-07 18.49.27 - Accepted - runtime 55ms - memory 19.3MB.py ├── 776-n-ary-tree-postorder-traversal └── 2022-07-07 11.14.19 - Accepted - runtime 130ms - memory 16.1MB.py ├── 782-jewels-and-stones └── 2022-08-01 16.26.49 - Accepted - runtime 55ms - memory 13.8MB.py ├── 783-search-in-a-binary-search-tree └── 2022-09-26 14.36.07 - Accepted - runtime 170ms - memory 16.5MB.py ├── 789-kth-largest-element-in-a-stream └── 2023-05-23 14.50.31 - Accepted - runtime 109ms - memory 20.4MB.py ├── 79-word-search └── 2024-04-03 12.06.52 - Accepted - runtime 39ms - memory 16.7MB.py ├── 792-binary-search ├── 2022-07-21 16.44.05 - Accepted - runtime 416ms - memory 15.6MB.py ├── 2023-04-01 23.42.27 - Accepted - runtime 238ms - memory 15.5MB.py └── 2024-03-12 15.08.10 - Accepted - runtime 187ms - memory 18.1MB.py ├── 8-string-to-integer-atoi └── 2024-03-31 18.54.54 - Accepted - runtime 40ms - memory 16.5MB.py ├── 802-k-th-smallest-prime-fraction └── 2024-05-10 09.34.39 - Accepted - runtime 2437ms - memory 121.5MB.py ├── 803-cheapest-flights-within-k-stops └── 2024-02-23 15.09.35 - Accepted - runtime 83ms - memory 18.2MB.py ├── 807-custom-sort-string ├── 2024-03-11 12.29.55 - Accepted - runtime 46ms - memory 16.4MB.py └── 2024-03-11 12.30.10 - Accepted - runtime 30ms - memory 16.5MB.py ├── 812-rotate-string ├── 2024-04-05 19.29.38 - Accepted - runtime 44ms - memory 16.5MB.py └── 2024-04-05 19.29.53 - Accepted - runtime 45ms - memory 16.4MB.py ├── 816-design-hashset └── 2024-02-24 22.10.17 - Accepted - runtime 102ms - memory 21.7MB.py ├── 82-remove-duplicates-from-sorted-list-ii ├── 2024-02-24 23.31.33 - Accepted - runtime 41ms - memory 16.5MB.py ├── 2024-02-24 23.40.55 - Accepted - runtime 45ms - memory 16.5MB.py └── 2024-02-24 23.43.39 - Accepted - runtime 5ms - memory 14.1MB.cpp ├── 822-unique-morse-code-words └── 2022-09-20 14.28.25 - Accepted - runtime 76ms - memory 14MB.py ├── 83-remove-duplicates-from-sorted-list └── 2022-06-20 19.42.44 - Accepted - runtime 70ms - memory 13.8MB.py ├── 832-binary-tree-pruning ├── 2024-01-08 15.38.29 - Accepted - runtime 43ms - memory 17.4MB.py ├── 2024-01-08 15.38.39 - Accepted - runtime 38ms - memory 17.4MB.py ├── 2024-01-08 15.41.14 - Accepted - runtime 30ms - memory 17.2MB.py ├── 2024-01-08 15.42.34 - Accepted - runtime 33ms - memory 17.2MB.py └── 2024-01-08 15.42.47 - Accepted - runtime 35ms - memory 17.4MB.py ├── 837-most-common-word └── 2024-04-05 19.36.42 - Accepted - runtime 43ms - memory 16.5MB.py ├── 841-shortest-distance-to-a-character └── 2022-09-26 17.43.01 - Accepted - runtime 167ms - memory 13.9MB.py ├── 85-maximal-rectangle ├── 2024-04-13 09.44.22 - Accepted - runtime 227ms - memory 18.1MB.py └── 2024-04-13 09.49.05 - Accepted - runtime 210ms - memory 17.9MB.py ├── 851-goat-latin └── 2024-04-05 19.46.35 - Accepted - runtime 42ms - memory 16.5MB.py ├── 857-positions-of-large-groups └── 2024-04-07 00.24.09 - Accepted - runtime 38ms - memory 16.6MB.py ├── 863-sum-of-distances-in-tree └── 2024-04-28 10.41.42 - Accepted - runtime 767ms - memory 44.5MB.py ├── 88-merge-sorted-array └── 2022-06-23 21.43.40 - Accepted - runtime 41ms - memory 13.9MB.py ├── 9-palindrome-number ├── 2022-04-24 19.57.39 - Accepted - runtime 104ms - memory 13.9MB.py ├── 2023-03-05 12.50.17 - Accepted - runtime 74ms - memory 13.8MB.py └── 2024-02-16 14.56.24 - Accepted - runtime 17ms - memory 10.6MB.cpp ├── 904-leaf-similar-trees ├── 2024-01-04 16.11.54 - Accepted - runtime 46ms - memory 17.5MB.py └── 2024-01-04 16.18.33 - Accepted - runtime 35ms - memory 17.4MB.py ├── 907-koko-eating-bananas ├── 2023-03-08 10.32.09 - Accepted - runtime 829ms - memory 15.5MB.py └── 2023-03-08 10.32.52 - Accepted - runtime 466ms - memory 15.4MB.py ├── 908-middle-of-the-linked-list ├── 2022-09-26 15.00.52 - Accepted - runtime 74ms - memory 13.9MB.py ├── 2022-09-26 15.16.05 - Accepted - runtime 59ms - memory 13.8MB.py └── 2024-03-07 14.21.03 - Accepted - runtime 38ms - memory 16.4MB.py ├── 917-boats-to-save-people ├── 2023-04-03 21.20.24 - Accepted - runtime 451ms - memory 20.8MB.py ├── 2024-05-04 10.01.24 - Accepted - runtime 350ms - memory 23.4MB.py └── 2024-05-04 10.04.41 - Accepted - runtime 358ms - memory 23.3MB.py ├── 92-reverse-linked-list-ii ├── 2022-07-21 22.46.11 - Accepted - runtime 49ms - memory 14MB.py └── 2024-02-17 16.28.17 - Accepted - runtime 0ms - memory 9.4MB.cpp ├── 926-find-and-replace-pattern └── 2022-07-29 20.00.13 - Accepted - runtime 67ms - memory 14MB.py ├── 932-monotonic-array ├── 2024-02-20 19.40.30 - Accepted - runtime 751ms - memory 31.1MB.py └── 2024-02-20 19.48.57 - Accepted - runtime 109ms - memory 98.9MB.cpp ├── 933-increasing-order-search-tree ├── 2024-02-01 23.14.31 - Accepted - runtime 20ms - memory 16.6MB.py └── 2024-02-01 23.20.40 - Accepted - runtime 34ms - memory 16.6MB.py ├── 94-binary-tree-inorder-traversal └── 2022-06-23 18.59.13 - Accepted - runtime 37ms - memory 13.9MB.py ├── 941-sort-array-by-parity ├── 2024-02-17 23.57.04 - Accepted - runtime 63ms - memory 17.3MB.py ├── 2024-02-18 00.01.22 - Accepted - runtime 7ms - memory 18.6MB.cpp ├── 2024-02-18 00.04.53 - Accepted - runtime 7ms - memory 19MB.cpp └── 2024-02-18 00.05.19 - Accepted - runtime 10ms - memory 18.9MB.cpp ├── 948-sort-an-array └── 2023-03-01 19.43.28 - Accepted - runtime 690ms - memory 22.2MB.py ├── 961-long-pressed-name └── 2024-04-06 12.16.00 - Accepted - runtime 46ms - memory 16.7MB.py ├── 962-flip-string-to-monotone-increasing └── 2024-04-06 12.25.38 - Accepted - runtime 123ms - memory 17.2MB.py ├── 966-binary-subarrays-with-sum └── 2024-03-14 12.11.05 - Accepted - runtime 237ms - memory 20.2MB.py ├── 969-number-of-recent-calls └── 2023-01-18 16.18.17 - Accepted - runtime 452ms - memory 19.4MB.py ├── 975-range-sum-of-bst ├── 2022-08-01 21.33.20 - Accepted - runtime 601ms - memory 23.1MB.py ├── 2024-01-08 14.37.44 - Accepted - runtime 135ms - memory 24.7MB.py └── 2024-02-20 13.09.29 - Accepted - runtime 86ms - memory 63MB.cpp ├── 98-validate-binary-search-tree ├── 2024-03-10 18.42.00 - Accepted - runtime 54ms - memory 18.5MB.py └── 2024-03-10 18.42.13 - Accepted - runtime 39ms - memory 18.4MB.py ├── 981-delete-columns-to-make-sorted └── 2023-01-06 20.36.30 - Accepted - runtime 90ms - memory 14.7MB.py ├── 983-validate-stack-sequences └── 2023-04-13 11.17.47 - Accepted - runtime 71ms - memory 14.1MB.py ├── 985-bag-of-tokens └── 2024-03-04 22.08.36 - Accepted - runtime 53ms - memory 16.8MB.py ├── 987-reveal-cards-in-increasing-order └── 2024-04-10 09.44.24 - Accepted - runtime 39ms - memory 16.7MB.py ├── 990-verifying-an-alien-dictionary └── 2023-02-02 17.45.03 - Accepted - runtime 44ms - memory 14.1MB.py └── LICENSE /.github/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blocage/leetcode-algorithms/00354837880ca299b3841ca9bbbe515cab195450/.github/.DS_Store -------------------------------------------------------------------------------- /.github/images/composer_fly_150.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blocage/leetcode-algorithms/00354837880ca299b3841ca9bbbe515cab195450/.github/images/composer_fly_150.gif -------------------------------------------------------------------------------- /.github/images/composer_fly_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blocage/leetcode-algorithms/00354837880ca299b3841ca9bbbe515cab195450/.github/images/composer_fly_first.png -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 20.32.16 - Accepted - runtime 7220ms - memory 14.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | _len = len(nums) 4 | for i in range(_len): 5 | for j in range(i + 1, _len): 6 | if nums[i] + nums[j] == target: return [i, j] -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 20.33.20 - Accepted - runtime 86ms - memory 15.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | hashmap = {} 4 | for i in range(len(nums)): 5 | hashmap[nums[i]] = i 6 | for i in range(len(nums)): 7 | complement = target - nums[i] 8 | if complement in hashmap and hashmap[complement] != i: 9 | return [i, hashmap[complement]] -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 20.33.33 - Accepted - runtime 69ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | hashmap = {} 4 | for i in range(len(nums)): 5 | complement = target - nums[i] 6 | if complement in hashmap: 7 | return [i, hashmap[complement]] 8 | hashmap[nums[i]] = i -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 20.33.39 - Accepted - runtime 66ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | hashmap = {} 4 | for i in range(len(nums)): 5 | complement = target - nums[i] 6 | if complement in hashmap: 7 | return [i, hashmap[complement]] 8 | hashmap[nums[i]] = i -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 20.59.59 - Accepted - runtime 107ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | remainders = {} 4 | for i in range(len(nums)): 5 | remainder = target - nums[i] 6 | if remainder in remainders: 7 | return [remainders[remainder], i] 8 | remainders[target - remainder] = i -------------------------------------------------------------------------------- /1-two-sum/2022-04-24 21.00.39 - Accepted - runtime 69ms - memory 15.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | remainders = {} 4 | for i in range(len(nums)): 5 | remainder = target - nums[i] 6 | if remainder in remainders: 7 | return [remainders[remainder], i] 8 | remainders[nums[i]] = i -------------------------------------------------------------------------------- /1-two-sum/2022-06-14 17.49.42 - Accepted - runtime 109ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | d = {} 4 | for ind, i in enumerate(nums): 5 | rem = target - i 6 | if i in d: 7 | return [ind, d[i]] 8 | d[rem] = ind -------------------------------------------------------------------------------- /1-two-sum/2022-06-14 17.49.56 - Accepted - runtime 132ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | d = {} 4 | for ind, i in enumerate(nums): 5 | rem = target - i 6 | if i in d: 7 | return [ind, d[i]] 8 | d[rem] = ind -------------------------------------------------------------------------------- /1-two-sum/2022-12-30 22.14.34 - Accepted - runtime 56ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | D = {} 4 | for ind, i in enumerate(nums): 5 | if i in D: 6 | return [D[i], ind] 7 | D[target - i] = ind 8 | 9 | return [-1] -------------------------------------------------------------------------------- /1-two-sum/2024-03-08 19.17.13 - Accepted - runtime 51ms - memory 17.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def twoSum(self, nums: List[int], target: int) -> List[int]: 3 | d = {} 4 | for ind, i in enumerate(nums): 5 | if i in d: 6 | return [d[i], ind] 7 | 8 | d[target - i] = ind 9 | 10 | return 1 11 | -------------------------------------------------------------------------------- /10-regular-expression-matching/2024-03-10 18.10.28 - Accepted - runtime 82ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | from re import match, sub 2 | class Solution: 3 | def isMatch(self, s: str, p: str) -> bool: 4 | p = sub(r'\*+', '*', p) 5 | m = match(p, s) 6 | if not m: 7 | return m 8 | 9 | return m.group(0) == s -------------------------------------------------------------------------------- /1013-fibonacci-number/2022-07-06 13.09.08 - Accepted - runtime 1330ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fib(self, n: int) -> int: 3 | if not n: 4 | return 0 5 | elif n == 1: 6 | return 1 7 | return self.fib(n - 1) + self.fib(n - 2) -------------------------------------------------------------------------------- /1013-fibonacci-number/2022-07-06 13.09.40 - Accepted - runtime 48ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fib(self, n: int) -> int: 3 | a,b = 0, 1 4 | for i in range(n): 5 | a, b = b, a + b 6 | return a -------------------------------------------------------------------------------- /1013-fibonacci-number/2022-07-06 13.09.52 - Accepted - runtime 59ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fib(self, n: int) -> int: 3 | a,b = 0, 1 4 | for i in range(n): 5 | a, b = b, a + b 6 | return a -------------------------------------------------------------------------------- /1013-fibonacci-number/2022-07-06 13.11.54 - Accepted - runtime 56ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | import functools 3 | 4 | @functools.cache 5 | def fib(self, n: int) -> int: 6 | if n in (0,1):return n 7 | return self.fib(n - 1) + self.fib(n - 2) -------------------------------------------------------------------------------- /1019-squares-of-a-sorted-array/2022-09-26 15.20.03 - Accepted - runtime 478ms - memory 16.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortedSquares(self, nums: List[int]) -> List[int]: 3 | return sorted(f ** 2 for f in nums) -------------------------------------------------------------------------------- /1019-squares-of-a-sorted-array/2024-03-26 00.09.06 - Accepted - runtime 160ms - memory 18.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortedSquares(self, nums: List[int]) -> List[int]: 3 | return sorted(f ** 2 for f in nums) 4 | -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/2023-03-01 20.57.47 - Accepted - runtime 34ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def levelOrder(self, root: Optional[TreeNode]) -> list[list[int]]: 3 | res, l = [], [root] 4 | while root and l: 5 | res.append([f.val for f in l]) 6 | pairs = [(f.left, f.right) for f in l] 7 | l = [node for pair in pairs for node in pair if node] 8 | 9 | return res -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/2023-03-01 20.58.21 - Accepted - runtime 36ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def levelOrder(self, root: Optional[TreeNode]) -> list[list[int]]: 3 | if not root: 4 | return [] 5 | res, l = [], [root] 6 | while l: 7 | res.append([f.val for f in l]) 8 | pairs = [(f.left, f.right) for f in l] 9 | l = [node for pair in pairs for node in pair if node] 10 | 11 | return res -------------------------------------------------------------------------------- /1031-add-to-array-form-of-integer/2023-02-15 22.11.41 - Accepted - runtime 330ms - memory 14.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addToArrayForm(self, num: List[int], k: int) -> List[int]: 3 | return list(map(int,str(int(''.join(map(str, num))) + k))) -------------------------------------------------------------------------------- /1039-find-the-town-judge/2024-02-22 17.56.01 - Accepted - runtime 665ms - memory 21.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findJudge(self, n: int, trust: List[List[int]]) -> int: 3 | if not trust: return 1 if n == 1 else -1 4 | d, k = defaultdict(int), defaultdict(int) 5 | for i in trust: 6 | k[i[0]] += 1 7 | d[i[1]] += 1 8 | 9 | for r,v in d.items(): 10 | if v == n - 1 and k[r] == 0: return r 11 | 12 | return -1 13 | -------------------------------------------------------------------------------- /1039-find-the-town-judge/2024-02-22 18.03.13 - Accepted - runtime 102ms - memory 64.4MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findJudge(int n, vector>& trust) { 4 | vector s(n + 1, 0); 5 | for (int i=0; i < trust.size(); i++){ 6 | s[trust[i][0]]--; 7 | s[trust[i][1]]++; 8 | } 9 | for (int i=1; i <= n; i++){ 10 | if (s[i] == n - 1) return i; 11 | } 12 | return -1; 13 | } 14 | }; -------------------------------------------------------------------------------- /1065-binary-string-with-substrings-representing-1-to-n/2024-04-30 20.57.38 - Accepted - runtime 32ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def queryString(self, s: str, n: int) -> bool: 3 | return all(f'{f:b}'in s for f in range(1,n + 1)) -------------------------------------------------------------------------------- /11-container-with-most-water/2023-01-31 20.56.29 - Accepted - runtime 757ms - memory 27.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxArea(self, height: List[int]) -> int: 3 | left, right = 0, len(height) - 1 4 | res = 0 5 | while left < right: 6 | res = max(res, min(height[left], height[right]) * (right - left)) 7 | if height[left] > height[right]: 8 | right -= 1 9 | else: 10 | left += 1 11 | 12 | return res -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/2022-06-28 23.53.42 - Accepted - runtime 1710ms - memory 58.4MB.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def minDepth(self, root): 9 | if not root: return 0 10 | d = list(map(self.minDepth, (root.left, root.right))) 11 | return 1 + (min(d) or max(d)) -------------------------------------------------------------------------------- /111-minimum-depth-of-binary-tree/2022-06-28 23.53.50 - Accepted - runtime 1121ms - memory 58.4MB.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def minDepth(self, root): 9 | if not root: return 0 10 | d = list(map(self.minDepth, (root.left, root.right))) 11 | return 1 + (min(d) or max(d)) -------------------------------------------------------------------------------- /112-path-sum/2022-07-08 22.18.51 - Accepted - runtime 43ms - memory 15MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool: 3 | if not root:return False 4 | if not(root.left or root.right) and root.val == target:return True 5 | target -= root.val 6 | return self.hasPathSum(root.left, target) or self.hasPathSum(root.right, target) -------------------------------------------------------------------------------- /112-path-sum/2022-07-09 10.59.17 - Accepted - runtime 77ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool: 3 | if not root:return False 4 | if not(root.left or root.right) and target == root.val:return True 5 | target -= root.val 6 | return self.hasPathSum(root.left,target)or self.hasPathSum(root.right,target) -------------------------------------------------------------------------------- /112-path-sum/2022-07-10 18.10.26 - Accepted - runtime 53ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool: 3 | if not root:return False 4 | if not (root.left or root.right) and target == root.val:return True 5 | target -= root.val 6 | return self.hasPathSum(root.left,target)or self.hasPathSum(root.right,target) -------------------------------------------------------------------------------- /112-path-sum/2022-10-07 20.24.27 - Accepted - runtime 47ms - memory 15MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool: 3 | if not root:return False 4 | if not (root.left or root.right) and target == root.val:return True 5 | target -= root.val 6 | return self.hasPathSum(root.left,target)or self.hasPathSum(root.right,target) -------------------------------------------------------------------------------- /1127-last-stone-weight/2023-04-24 21.21.11 - Accepted - runtime 42ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lastStoneWeight(self, stones: List[int]) -> int: 3 | h = [-f for f in stones] 4 | heapq.heapify(h) 5 | while len(h) > 1: 6 | heapq.heappush(h, heapq.heappop(h) - heapq.heappop(h)) 7 | return -h[0] -------------------------------------------------------------------------------- /1127-last-stone-weight/2023-04-24 21.21.20 - Accepted - runtime 41ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lastStoneWeight(self, stones: List[int]) -> int: 3 | h = [-f for f in stones] 4 | heapq.heapify(h) 5 | while len(h) > 1: 6 | heapq.heappush(h, heapq.heappop(h) - heapq.heappop(h)) 7 | return -h[0] -------------------------------------------------------------------------------- /1137-height-checker/2024-04-04 18.32.28 - Accepted - runtime 44ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def heightChecker(self, heights: List[int]) -> int: 3 | s = sorted(heights) 4 | return sum(s[f] != heights[f] for f in range(len(heights))) -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/2022-07-27 22.30.13 - Accepted - runtime 68ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def flatten(self, root: Optional[TreeNode]) -> None: 3 | curr = root 4 | while curr: 5 | if curr.left: 6 | p = curr.left 7 | while p.right:p = p.right 8 | p.right = curr.right 9 | curr.right = curr.left 10 | curr.left = None 11 | 12 | curr = curr.right -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/2022-07-27 22.30.24 - Accepted - runtime 62ms - memory 15.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def flatten(self, root: Optional[TreeNode]) -> None: 3 | curr = root 4 | while curr: 5 | if curr.left: 6 | p = curr.left 7 | while p.right:p = p.right 8 | p.right = curr.right 9 | curr.right = curr.left 10 | curr.left = None 11 | 12 | curr = curr.right -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/2022-07-27 22.30.30 - Accepted - runtime 44ms - memory 15.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def flatten(self, root: Optional[TreeNode]) -> None: 3 | curr = root 4 | while curr: 5 | if curr.left: 6 | p = curr.left 7 | while p.right:p = p.right 8 | p.right = curr.right 9 | curr.right = curr.left 10 | curr.left = None 11 | 12 | curr = curr.right -------------------------------------------------------------------------------- /118-pascals-triangle/2022-07-19 22.45.40 - Accepted - runtime 39ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generate(self, n: int) -> List[List[int]]: 3 | l = [[1]] 4 | for i in range(1, n):l.append([1 if not f or f==i else l[-1][f]+l[-1][f-1] for f in range(i+1)]) 5 | return l 6 | 7 | -------------------------------------------------------------------------------- /119-pascals-triangle-ii/2023-04-29 09.00.00 - Accepted - runtime 44ms - memory 16.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getRow(self, rowIndex: int) -> List[int]: 3 | l = [[1]] 4 | for i in range(1, rowIndex + 1): 5 | t = [1] 6 | for j in range(1, len(l[i - 1])): 7 | t.append(sum(l[i - 1][j-1 : j+1])) 8 | t += [1] 9 | l.append(t) 10 | return l[rowIndex] -------------------------------------------------------------------------------- /1195-distribute-candies-to-people/2022-07-11 00.23.50 - Accepted - runtime 52ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distributeCandies(self, candies: int, num_people: int) -> List[int]: 3 | res = [0] * num_people 4 | n = 0 5 | while True: 6 | for i in range(num_people): 7 | c = min(num_people * n + i + 1, candies) 8 | res[i] += c 9 | candies -= c 10 | if candies <= 0: return res 11 | n += 1 -------------------------------------------------------------------------------- /1205-defanging-an-ip-address/2022-07-11 00.27.40 - Accepted - runtime 47ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def defangIPaddr(self, address: str) -> str: 3 | return address.replace('.', '[.]') -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/2022-06-22 14.07.15 - Accepted - runtime 1551ms - memory 24.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | res = 0 4 | ko = prices[0] 5 | for i in range(1, len(prices)): 6 | if (a := prices[i] - ko) > res: 7 | res = a 8 | if ko > prices[i]: 9 | ko = prices[i] 10 | return res -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/2022-06-22 14.44.17 - Accepted - runtime 1889ms - memory 25MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | res = 0 4 | ko = prices[0] 5 | for i in range(1, len(prices)): 6 | if (a := prices[i] - ko) > res: 7 | res = a 8 | if ko > prices[i]: 9 | ko = prices[i] 10 | return res -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/2022-06-22 14.44.26 - Accepted - runtime 997ms - memory 25MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | res = 0 4 | ko = prices[0] 5 | for i in range(1, len(prices)): 6 | if (a := prices[i] - ko) > res: 7 | res = a 8 | if ko > prices[i]: 9 | ko = prices[i] 10 | return res -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/2022-06-22 14.44.33 - Accepted - runtime 2002ms - memory 25MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProfit(self, prices: List[int]) -> int: 3 | res = 0 4 | ko = prices[0] 5 | for i in range(1, len(prices)): 6 | if (a := prices[i] - ko) > res: 7 | res = a 8 | if ko > prices[i]: 9 | ko = prices[i] 10 | return res -------------------------------------------------------------------------------- /1217-relative-sort-array/2022-07-19 17.44.13 - Accepted - runtime 48ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: 3 | return sorted(arr1, key=lambda x:arr2.index(x) if x in arr2 else x * 1000) -------------------------------------------------------------------------------- /1221-element-appearing-more-than-25-in-sorted-array/2024-01-04 15.55.37 - Accepted - runtime 81ms - memory 18.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findSpecialInteger(self, arr: List[int]) -> int: 3 | from collections import Counter 4 | return Counter(arr).most_common(1)[0][0] 5 | -------------------------------------------------------------------------------- /1224-minimum-falling-path-sum-ii/2024-04-26 09.44.19 - Accepted - runtime 215ms - memory 20.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minFallingPathSum(self, grid: List[List[int]]) -> int: 3 | r = [(0, -1)] 4 | for row in grid: 5 | r = heapq.nsmallest(2, ((a + r[i == r[0][1]][0], i) for i, a in enumerate(row))) 6 | return r[0][0] 7 | -------------------------------------------------------------------------------- /1231-replace-elements-with-greatest-element-on-right-side/2023-11-28 21.49.20 - Accepted - runtime 592ms - memory 18.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def replaceElements(self, arr: List[int]) -> List[int]: 3 | res = [-1] 4 | g = 0 5 | for i in arr[::-1]: 6 | if i > g: 7 | g = i 8 | res.append(g) 9 | res.pop() 10 | 11 | return res[::-1] -------------------------------------------------------------------------------- /1236-n-th-tribonacci-number/2024-04-24 12.22.18 - Accepted - runtime 38ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def tribonacci(self, n: int) -> int: 3 | l = [0, 1, 1] 4 | for i in range(35): 5 | l.append(sum(l[-3:])) 6 | 7 | return l[n] -------------------------------------------------------------------------------- /1241-decompress-run-length-encoded-list/2022-08-01 21.03.28 - Accepted - runtime 82ms - memory 14.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decompressRLElist(self, nums: List[int]) -> List[int]: 3 | l = [] 4 | for a,b in zip(nums[::2], nums[1::2]): 5 | l += [b] * a 6 | 7 | return l -------------------------------------------------------------------------------- /125-valid-palindrome/2022-06-22 13.41.26 - Accepted - runtime 89ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, s: str) -> bool: 3 | s = ''.join(f for f in s.lower() if f.isalnum()) 4 | return s == s[::-1] -------------------------------------------------------------------------------- /125-valid-palindrome/2022-12-16 17.15.52 - Accepted - runtime 51ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, s: str) -> bool: 3 | s = ''.join(f for f in s.upper() if f.isalnum()) 4 | l, r = 0, len(s) - 1 5 | while r > l: 6 | if s[l] != s[r]: 7 | return False 8 | l += 1 9 | r -= 1 10 | 11 | return True -------------------------------------------------------------------------------- /1250-longest-common-subsequence/2024-03-12 20.02.07 - Accepted - runtime 369ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonSubsequence(self, text1: str, text2: str) -> int: 3 | m, n = map(len, (text1, text2)) 4 | dp = [0] * (n + 1) 5 | for i in text1: 6 | a = b = 0 7 | for j, c in enumerate(text2): 8 | a, b = dp[j + 1], a 9 | dp[j + 1] = b + 1 if c == i else max(dp[j], a) 10 | 11 | return dp[-1] -------------------------------------------------------------------------------- /1250-longest-common-subsequence/2024-03-14 12.15.09 - Accepted - runtime 372ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonSubsequence(self, text1: str, text2: str) -> int: 3 | n, m = len(text1), len(text2) 4 | dp = [0] * (m + 1) 5 | for i in text1: 6 | a = b = 0 7 | for j, c in enumerate(text2): 8 | a, b = dp[j + 1], a 9 | dp[j + 1] = 1 + b if i == c else max(dp[j], a) 10 | 11 | return dp[-1] -------------------------------------------------------------------------------- /1250-longest-common-subsequence/2024-03-14 12.17.37 - Accepted - runtime 366ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonSubsequence(self, text1: str, text2: str) -> int: 3 | n, m = len(text1), len(text2) 4 | dp = [0] * (m + 1) 5 | for i in text1: 6 | a = b = 0 7 | for j, c in enumerate(text2): 8 | a, b = dp[j + 1], a 9 | dp[j + 1] = 1 + b if i == c else max(dp[j], a) 10 | 11 | return dp[-1] -------------------------------------------------------------------------------- /1250-longest-common-subsequence/2024-03-14 13.03.08 - Accepted - runtime 368ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonSubsequence(self, text1: str, text2: str) -> int: 3 | n, m = map(len, (text1, text2)) 4 | dp = [0] * (m + 1) 5 | for i in text1: 6 | a = b = 0 7 | for j, c in enumerate(text2): 8 | a, b = dp[j + 1], a 9 | dp[j + 1] = 1 + b if c == i else max(dp[j], a) 10 | 11 | return dp[-1] -------------------------------------------------------------------------------- /1256-rank-transform-of-an-array/2024-04-15 15.25.23 - Accepted - runtime 234ms - memory 35.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayRankTransform(self, arr: List[int]) -> List[int]: 3 | d = {} 4 | for ind, i in enumerate(sorted(set(arr)), 1): 5 | d[i] = ind 6 | 7 | return [d[f] for f in arr] -------------------------------------------------------------------------------- /1287-distance-between-bus-stops/2024-04-21 18.13.37 - Accepted - runtime 50ms - memory 17.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distanceBetweenBusStops(self, d: List[int], s: int, t: int) -> int: 3 | a,b = sorted((s,t)) 4 | return min(sum(d[a:b]), sum(d) - sum(d[a:b])) -------------------------------------------------------------------------------- /129-sum-root-to-leaf-numbers/2023-03-14 15.11.48 - Accepted - runtime 29ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sum(self, node: Optional[TreeNode], s: int = 0) -> int: 3 | if not node: return 0 4 | if not node.left and not node.right: return s * 10 + node.val 5 | return self.sum(node.left, s * 10 + node.val) + self.sum(node.right, s * 10 + node.val) 6 | 7 | def sumNumbers(self, root: Optional[TreeNode]) -> int: 8 | return self.sum(root) -------------------------------------------------------------------------------- /129-sum-root-to-leaf-numbers/2023-03-14 15.13.26 - Accepted - runtime 32ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sum(self, node: Optional[TreeNode], s: int = 0) -> int: 3 | if not node: return 0 4 | s = s * 10 + node.val 5 | if not node.left and not node.right: return s 6 | return self.sum(node.left, s) + self.sum(node.right, s) 7 | 8 | def sumNumbers(self, root: Optional[TreeNode]) -> int: 9 | return self.sum(root) -------------------------------------------------------------------------------- /1297-maximum-number-of-balloons/2024-04-01 16.15.39 - Accepted - runtime 32ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxNumberOfBalloons(self, text: str) -> int: 3 | c = Counter(text) 4 | return min(c['b'], c['a'], c['l'] // 2, c['o'] // 2, c['n']) -------------------------------------------------------------------------------- /1306-minimum-absolute-difference/2022-09-26 18.06.25 - Accepted - runtime 716ms - memory 28.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]: 3 | arr.sort() 4 | min_difference = min(b - a for a,b in zip(arr, arr[1:])) 5 | return [[a,b] for a,b in zip(arr, arr[1:]) if b - a == min_difference] -------------------------------------------------------------------------------- /1319-unique-number-of-occurrences/2024-01-17 19.12.57 - Accepted - runtime 27ms - memory 17.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueOccurrences(self, arr: List[int]) -> bool: 3 | k = Counter(arr).values() 4 | return len(k) == len(set(k)) -------------------------------------------------------------------------------- /133-clone-graph/2023-03-05 19.02.28 - Accepted - runtime 48ms - memory 14.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def cloneGraph(self, node: 'Node') -> 'Node': 3 | from copy import deepcopy 4 | return deepcopy(node) -------------------------------------------------------------------------------- /134-gas-station/2023-01-07 16.38.42 - Accepted - runtime 704ms - memory 18.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: 3 | curr = total = start = 0 4 | for i in range(len(gas)): 5 | total += gas[i] - cost[i] 6 | curr += gas[i] - cost[i] 7 | if curr < 0: 8 | curr = 0 9 | start = i + 1 10 | 11 | return -1 if total < 0 else start -------------------------------------------------------------------------------- /1341-split-a-string-in-balanced-strings/2024-01-04 16.06.52 - Accepted - runtime 36ms - memory 17.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def balancedStringSplit(self, s: str) -> int: 3 | c = r = 0 4 | for i in s: 5 | c += 1 if i == 'L' else -1 6 | if c == 0: 7 | r += 1 8 | 9 | return r -------------------------------------------------------------------------------- /1354-find-players-with-zero-or-one-losses/2024-01-15 18.28.43 - Accepted - runtime 1354ms - memory 71.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findWinners(self, matches: List[List[int]]) -> List[List[int]]: 3 | w = [] 4 | l = [] 5 | for a,b in matches: 6 | w.append(a) 7 | l.append(b) 8 | 9 | w, l = map(Counter, (w, l)) 10 | return [sorted(w.keys() - l.keys()), sorted([a for a,b in l.items() if b == 1])] -------------------------------------------------------------------------------- /136-single-number/2022-06-23 22.04.47 - Accepted - runtime 292ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def singleNumber(self, nums: List[int]) -> int: 4 | return Counter(nums).most_common()[-1][0] -------------------------------------------------------------------------------- /136-single-number/2022-06-23 22.04.55 - Accepted - runtime 277ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def singleNumber(self, nums: List[int]) -> int: 4 | return Counter(nums).most_common()[-1][0] -------------------------------------------------------------------------------- /136-single-number/2022-06-23 22.06.06 - Accepted - runtime 304ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | xor = 0 4 | for num in nums: 5 | xor ^= num 6 | 7 | return xor -------------------------------------------------------------------------------- /136-single-number/2022-06-23 22.06.14 - Accepted - runtime 178ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: List[int]) -> int: 3 | xor = 0 4 | for num in nums: 5 | xor ^= num 6 | 7 | return xor -------------------------------------------------------------------------------- /1362-airplane-seat-assignment-probability/2024-04-15 14.42.55 - Accepted - runtime 40ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def nthPersonGetsNthSeat(self, n: int) -> float: 3 | return 1 if n == 1 else 0.5 -------------------------------------------------------------------------------- /1378-cells-with-odd-values-in-a-matrix/2022-09-20 20.06.43 - Accepted - runtime 85ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: 3 | l = [[0] * m for f in range(n)] 4 | for r, c in indices: 5 | for i in l:i[r] += 1 6 | l[c] = [f+1 for f in l[c]] 7 | 8 | return sum(sum(i%2 for i in f)for f in l) 9 | -------------------------------------------------------------------------------- /1378-cells-with-odd-values-in-a-matrix/2022-09-20 20.11.45 - Accepted - runtime 75ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int: 3 | columns, rows = [0] * n, [0] * m 4 | for r,c in indices: 5 | rows[r] += 1 6 | columns[c] += 1 7 | return sum((r + c) % 2 for c in columns for r in rows) -------------------------------------------------------------------------------- /1392-find-the-difference-of-two-arrays/2023-05-04 18.39.42 - Accepted - runtime 187ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]: 3 | a, b = set(nums1), set(nums2) 4 | return a.difference(b), b.difference(a) -------------------------------------------------------------------------------- /1395-minimum-time-visiting-all-points/2022-07-27 01.07.04 - Accepted - runtime 112ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: 3 | r = 0 4 | for i in range(len(points) - 1): 5 | x,y = points[i] 6 | X,Y = points[i + 1] 7 | r += max(abs(x - X), abs(y - Y)) 8 | 9 | return r -------------------------------------------------------------------------------- /14-longest-common-prefix/2022-04-18 22.41.04 - Accepted - runtime 37ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonPrefix(self, strs: List[str]) -> str: 3 | res = '' 4 | check = 0 5 | while(check < len(min(strs,key=len)) and len(set(f[check]for f in strs)) == 1): 6 | res += strs[0][check] 7 | check += 1 8 | 9 | return res -------------------------------------------------------------------------------- /14-longest-common-prefix/2024-02-16 20.12.12 - Accepted - runtime 31ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonPrefix(self, strs: List[str]) -> str: 3 | ind = 0 4 | while ind < len(strs[0]): 5 | c = strs[0][ind] 6 | for i in strs: 7 | if len(i) <= ind or i[ind] != c: return strs[0][:ind] 8 | ind += 1 9 | 10 | return strs[0][:ind] 11 | -------------------------------------------------------------------------------- /14-longest-common-prefix/2024-02-16 20.14.08 - Accepted - runtime 29ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonPrefix(self, strs: List[str]) -> str: 3 | ind = 0 4 | m = len(min(strs, key=len)) 5 | while ind < m: 6 | c = strs[0][ind] 7 | for i in strs: 8 | if i[ind] != c: return strs[0][:ind] 9 | ind += 1 10 | 11 | return strs[0][:ind] 12 | -------------------------------------------------------------------------------- /14-longest-common-prefix/2024-02-16 22.04.32 - Accepted - runtime 0ms - memory 11.2MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string longestCommonPrefix(vector& s) { 4 | sort(s.begin(), s.end()); 5 | int n = s.size(); 6 | string res = "", a = s[0], b = s[n - 1]; 7 | for (int i = 0;i < min(a.size(), b.size()); i++){ 8 | if(a[i] != b[i]) return res; 9 | res += a[i]; 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /1406-subtract-the-product-and-sum-of-digits-of-an-integer/2022-08-01 20.49.05 - Accepted - runtime 52ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def subtractProductAndSum(self, n: int) -> int: 3 | return eval('*'.join(str(n))) - eval('+'.join(str(n))) -------------------------------------------------------------------------------- /141-linked-list-cycle/2022-06-29 00.09.52 - Accepted - runtime 67ms - memory 17.6MB.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, x): 4 | # self.val = x 5 | # self.next = None 6 | 7 | class Solution: 8 | def hasCycle(self, head: Optional[ListNode]) -> bool: 9 | while head: 10 | if hasattr(head, 'visited'): 11 | return True 12 | head.visited = True 13 | head = head.next 14 | return False -------------------------------------------------------------------------------- /1411-convert-binary-number-in-a-linked-list-to-integer/2022-08-02 00.37.17 - Accepted - runtime 40ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, val=0, next=None): 4 | # self.val = val 5 | # self.next = next 6 | class Solution: 7 | def getDecimalValue(self, head: ListNode) -> int: 8 | r = '' 9 | while head: 10 | r += str(head.val) 11 | head = head.next 12 | 13 | return int(r, 2) -------------------------------------------------------------------------------- /1421-find-numbers-with-even-number-of-digits/2024-04-30 21.28.04 - Accepted - runtime 63ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findNumbers(self, nums: List[int]) -> int: 3 | return sum(len(str(f)) % 2 == 0 for f in nums) -------------------------------------------------------------------------------- /1430-find-the-k-beauty-of-a-number/2024-04-30 21.22.07 - Accepted - runtime 39ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divisorSubstrings(self, num: int, k: int) -> int: 3 | t = str(num) 4 | return sum(num % int(t[f:f + k]) == 0 for f in range(len(t) - k + 1)if int(t[f:f + k])) -------------------------------------------------------------------------------- /1444-number-of-steps-to-reduce-a-number-to-zero/2022-08-01 21.11.31 - Accepted - runtime 46ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfSteps(self, n: int) -> int: 3 | r = 0 4 | while n: 5 | r += 1 6 | if n % 2:n -= 1 7 | else:n //= 2 8 | 9 | return r -------------------------------------------------------------------------------- /1448-maximum-69-number/2022-09-20 19.23.41 - Accepted - runtime 65ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximum69Number(self, num: int) -> int: 3 | l = list(str(num)) 4 | if '6' in l: 5 | l[l.index('6')] = '9' 6 | return ''.join(l) -------------------------------------------------------------------------------- /1448-maximum-69-number/2022-09-20 19.24.20 - Accepted - runtime 30ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximum69Number(self, num: int) -> int: 3 | return int(str(num).replace('6','9',1)) -------------------------------------------------------------------------------- /1458-sort-integers-by-the-number-of-1-bits/2024-01-05 23.14.48 - Accepted - runtime 58ms - memory 17.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortByBits(self, arr: List[int]) -> List[int]: 3 | return sorted(arr, key=lambda x:(f'{x:b}'.count('1'), x)) -------------------------------------------------------------------------------- /1469-minimum-number-of-steps-to-make-two-strings-anagram/2024-01-13 19.48.39 - Accepted - runtime 99ms - memory 17.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSteps(self, s: str, t: str) -> int: 3 | a = collections.Counter(t).items() 4 | b = collections.Counter(s) 5 | r = 0 6 | for i,j in a: 7 | r += max(j - b[i], 0) 8 | 9 | return r -------------------------------------------------------------------------------- /1469-minimum-number-of-steps-to-make-two-strings-anagram/2024-01-13 19.53.03 - Accepted - runtime 108ms - memory 17.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSteps(self, s: str, t: str) -> int: 3 | a, b = map(collections.Counter, (s, t)) 4 | return sum((a - b).values()) -------------------------------------------------------------------------------- /1474-longest-zigzag-path-in-a-binary-tree/2023-04-20 00.06.58 - Accepted - runtime 456ms - memory 63MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestZigZag(self, root): 3 | def dfs(root): 4 | if not root: return [-1, -1, -1] 5 | left, right = dfs(root.left), dfs(root.right) 6 | return [left[1] + 1, right[0] + 1, max(left[1] + 1, right[0] + 1, left[2], right[2])] 7 | return dfs(root)[-1] -------------------------------------------------------------------------------- /1476-count-negative-numbers-in-a-sorted-matrix/2023-03-06 21.09.16 - Accepted - runtime 126ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countNegatives(self, grid: List[List[int]]) -> int: 3 | return sum(sum(i < 0 for i in f) for f in grid) -------------------------------------------------------------------------------- /1482-how-many-numbers-are-smaller-than-the-current-number/2022-07-23 11.56.03 - Accepted - runtime 88ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 3 | k = sorted(nums) 4 | return [k.index(f)for f in nums] -------------------------------------------------------------------------------- /1486-find-the-distance-value-between-two-arrays/2023-03-01 20.07.03 - Accepted - runtime 108ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int: 3 | return sum(all(abs(f - i) > d for f in arr2) for i in arr1) -------------------------------------------------------------------------------- /1505-create-target-array-in-the-given-order/2022-08-01 21.48.26 - Accepted - runtime 66ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: 3 | l = [] 4 | for a,b in zip(nums, index): 5 | l.insert(b, a) 6 | return l -------------------------------------------------------------------------------- /1528-kids-with-the-greatest-number-of-candies/2022-08-01 16.35.54 - Accepted - runtime 56ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kidsWithCandies(self, candies: List[int], e: int) -> List[bool]: 3 | m = max(candies) 4 | return [f+e >= m for f in candies] -------------------------------------------------------------------------------- /1528-kids-with-the-greatest-number-of-candies/2023-04-17 12.13.29 - Accepted - runtime 45ms - memory 13.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kidsWithCandies(self, candies: List[int], t: int) -> List[bool]: 3 | r = max(candies) 4 | return [f + t >= r for f in candies] 5 | -------------------------------------------------------------------------------- /153-find-minimum-in-rotated-sorted-array/2023-01-06 21.16.10 - Accepted - runtime 90ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMin(self, nums: List[int]) -> int: 3 | return min(nums) -------------------------------------------------------------------------------- /1532-reformat-the-string/2024-04-09 21.20.47 - Accepted - runtime 36ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reformat(self, s: str) -> str: 3 | a = b = '' 4 | for i in s: 5 | if i.isalpha():a += i 6 | else:b += i 7 | if abs(len(a) - len(b)) > 1: return '' 8 | a, b = sorted((a,b),key=len) 9 | r = ''.join(i+j for i,j in zip(b,a)) 10 | if len(a) != len(b): 11 | r += b[-1] 12 | return r 13 | -------------------------------------------------------------------------------- /1537-maximum-score-after-splitting-a-string/2024-02-08 23.35.57 - Accepted - runtime 39ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScore(self, s: str) -> int: 3 | return max(s[:f + 1].count('0') + s[f + 1:].count('1') for f in range(len(s) - 1)) -------------------------------------------------------------------------------- /1538-maximum-points-you-can-obtain-from-cards/2022-06-26 11.58.51 - Accepted - runtime 864ms - memory 28.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxScore(self, cardPoints, k): 3 | frontSum, backSum = [0], [0] 4 | for n in cardPoints: 5 | frontSum.append(frontSum[-1]+n) 6 | for n in cardPoints[::-1]: 7 | backSum.append(backSum[-1]+n) 8 | allCombinations = [frontSum[i]+backSum[k-i] for i in range(k+1)] 9 | return max(allCombinations) -------------------------------------------------------------------------------- /1538-maximum-points-you-can-obtain-from-cards/2022-06-26 11.59.00 - Accepted - runtime 491ms - memory 28.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def maxScore(self, cardPoints, k): 3 | frontSum, backSum = [0], [0] 4 | for n in cardPoints: 5 | frontSum.append(frontSum[-1]+n) 6 | for n in cardPoints[::-1]: 7 | backSum.append(backSum[-1]+n) 8 | allCombinations = [frontSum[i]+backSum[k-i] for i in range(k+1)] 9 | return max(allCombinations) -------------------------------------------------------------------------------- /1561-rearrange-words-in-a-sentence/2024-04-10 14.44.48 - Accepted - runtime 29ms - memory 18.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrangeWords(self, text: str) -> str: 3 | return " ".join(sorted(text.split(), key=len)).capitalize() -------------------------------------------------------------------------------- /1574-maximum-product-of-two-elements-in-an-array/2022-09-20 19.26.46 - Accepted - runtime 140ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProduct(self, nums: List[int]) -> int: 3 | nums.sort() 4 | return (nums[-1] - 1) * (nums[-2] - 1) -------------------------------------------------------------------------------- /1580-shuffle-the-array/2022-08-01 16.16.04 - Accepted - runtime 120ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shuffle(self, nums: List[int], n: int) -> List[int]: 3 | res = [] 4 | for a,b in zip(nums[:n], nums[n:]): 5 | res.append(a) 6 | res.append(b) 7 | 8 | return res -------------------------------------------------------------------------------- /1584-average-salary-excluding-the-minimum-and-maximum-salary/2023-05-02 00.39.10 - Accepted - runtime 50ms - memory 16.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def average(self, salary: List[int]) -> float: 3 | salary.sort() 4 | return sum(salary[1:-1]) / len(salary[1:-1]) -------------------------------------------------------------------------------- /1603-running-sum-of-1d-array/2022-08-01 16.06.22 - Accepted - runtime 69ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def runningSum(self, nums: List[int]) -> List[int]: 3 | for i in range(1, len(nums)): 4 | nums[i] += nums[i - 1] 5 | 6 | return nums 7 | -------------------------------------------------------------------------------- /1604-least-number-of-unique-integers-after-k-removals/2024-02-16 13.01.54 - Accepted - runtime 341ms - memory 36.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: 3 | c = Counter(arr) 4 | r = 0 5 | for a,b in sorted(c.items(), key=lambda x: x[1]): 6 | if b <= k: 7 | k -= b 8 | else: 9 | r += 1 10 | 11 | return r -------------------------------------------------------------------------------- /1604-least-number-of-unique-integers-after-k-removals/2024-02-16 13.16.39 - Accepted - runtime 534ms - memory 39.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: 3 | c = Counter(arr) 4 | s = sorted(arr, key = lambda x:(c[x], x)) 5 | return len(set(s[k:])) -------------------------------------------------------------------------------- /1610-xor-operation-in-an-array/2022-08-02 00.34.35 - Accepted - runtime 50ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorOperation(self, n: int, start: int) -> int: 3 | r = start 4 | for i in range(1, n): 5 | r ^= start + 2 * i 6 | 7 | return r -------------------------------------------------------------------------------- /1626-can-make-arithmetic-progression-from-sequence/2024-05-05 20.05.40 - Accepted - runtime 39ms - memory 16.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canMakeArithmeticProgression(self, arr: List[int]) -> bool: 3 | arr.sort() 4 | t, prev = arr[0] - arr[1], arr[1] 5 | for i in arr[2:]: 6 | if prev - i != t: return False 7 | prev = i 8 | return True -------------------------------------------------------------------------------- /1635-number-of-good-pairs/2022-08-01 16.30.28 - Accepted - runtime 65ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numIdenticalPairs(self, nums: List[int]) -> int: 3 | l = len(nums) 4 | return sum(nums[i] == nums[j] for i in range(l) for j in range(i + 1, l)) -------------------------------------------------------------------------------- /1646-kth-missing-positive-number/2023-03-06 21.02.21 - Accepted - runtime 47ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKthPositive(self, arr: List[int], k: int) -> int: 3 | l = set(arr) 4 | res = 1 5 | while k: 6 | if res not in l: 7 | k -= 1 8 | res += 1 9 | 10 | return res - 1 -------------------------------------------------------------------------------- /1651-shuffle-string/2022-08-01 22.11.03 - Accepted - runtime 81ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def restoreString(self, s: str, d: List[int]) -> str: 3 | *a, = s 4 | for i in range(len(s)): 5 | a[d[i]] = s[i] 6 | 7 | return ''.join(a) -------------------------------------------------------------------------------- /1666-make-the-string-great/2024-04-05 10.23.05 - Accepted - runtime 46ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def makeGood(self, s: str) -> str: 3 | for i in range(len(s) - 1): 4 | if s[i] != s[i + 1] and len(set((s[i] + s[i + 1]).lower())) == 1: 5 | return self.makeGood(s[:i] + s[i + 2:]) 6 | return s -------------------------------------------------------------------------------- /1677-matrix-diagonal-sum/2023-05-08 11.29.50 - Accepted - runtime 115ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def diagonalSum(self, mat: List[List[int]]) -> int: 3 | l = len(mat) 4 | s = 0 5 | for i in range(l): 6 | s += mat[i][i] + mat[i][~i] 7 | if l % 2 and l // 2 == i: 8 | s -= mat[i][i] 9 | 10 | return s -------------------------------------------------------------------------------- /168-excel-sheet-column-title/2024-03-13 23.44.19 - Accepted - runtime 40ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, n: int) -> str: 3 | r = "" 4 | while n > 0: 5 | r += chr(ord('A') + (n - 1) % 26) 6 | n = (n - 1) // 26 7 | 8 | return r[::-1] 9 | -------------------------------------------------------------------------------- /169-majority-element/2022-07-18 19.44.23 - Accepted - runtime 177ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def majorityElement(self, nums: List[int]) -> int: 3 | return collections.Counter(nums).most_common(1)[0][0] -------------------------------------------------------------------------------- /1693-sum-of-all-odd-length-subarrays/2022-09-20 14.43.46 - Accepted - runtime 129ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOddLengthSubarrays(self, arr: List[int]) -> int: 3 | i = 1 4 | res = 0 5 | l = len(arr) 6 | while i <= l: 7 | res += sum(sum(arr[f:i+f])for f in range(l - i + 1)) 8 | i += 2 9 | return res -------------------------------------------------------------------------------- /1693-sum-of-all-odd-length-subarrays/2022-09-20 14.46.02 - Accepted - runtime 72ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOddLengthSubarrays(self, arr: list[int]) -> int: 3 | res = 0 4 | times = 0 5 | l = len(arr) 6 | for i in range(l): 7 | times = times-(i+1)//2+(l-i+1)//2 8 | res += times*arr[i] 9 | return res -------------------------------------------------------------------------------- /171-excel-sheet-column-number/2024-03-31 19.39.05 - Accepted - runtime 36ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def titleToNumber(self, t: str) -> int: 3 | res = 0 4 | for i in t:res = res * 26 + (ord(i) - 65 + 1) 5 | return res -------------------------------------------------------------------------------- /1737-maximum-nesting-depth-of-the-parentheses/2024-04-04 09.19.17 - Accepted - runtime 33ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, s: str) -> int: 3 | curr = res = 0 4 | for i in s: 5 | if i == '(': 6 | curr += 1 7 | elif i == ')': 8 | res = max(res, curr) 9 | curr -= 1 10 | return res -------------------------------------------------------------------------------- /175-combine-two-tables/2023-05-13 10.04.02 - Accepted - runtime 845ms - memory 0B.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | 3 | 4 | SELECT A.firstName, A.lastName, S.city, S.state FROM PERSON A 5 | LEFT JOIN ADDRESS S ON 6 | A.personId = S.personId -------------------------------------------------------------------------------- /1751-slowest-key/2024-04-21 18.01.05 - Accepted - runtime 60ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def slowestKey(self, rls: List[int], k: str) -> str: 3 | res = (rls[0], k[0]) 4 | for i in range(1, len(rls)): 5 | res = max(res, (rls[i] - rls[i - 1], k[i])) 6 | 7 | return res[1] -------------------------------------------------------------------------------- /1777-determine-if-two-strings-are-close/2024-01-14 22.58.46 - Accepted - runtime 125ms - memory 18.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def closeStrings(self, a: str, b: str) -> bool: 3 | A, B = map(lambda x: sorted(Counter(x).values()), (a, b)) 4 | return A == B and set(a) == set(b) -------------------------------------------------------------------------------- /1777-determine-if-two-strings-are-close/2024-01-14 22.59.33 - Accepted - runtime 130ms - memory 18.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def closeStrings(self, a: str, b: str) -> bool: 3 | A, B = map(Counter, (a, b)) 4 | return sorted(A.values()) == sorted(B.values()) and A.keys() == B.keys() -------------------------------------------------------------------------------- /1781-check-if-two-string-arrays-are-equivalent/2022-09-20 14.26.50 - Accepted - runtime 68ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayStringsAreEqual(self, word1: list[str], word2: list[str]) -> bool: 3 | return ''.join(word1) == ''.join(word2) -------------------------------------------------------------------------------- /1786-count-the-number-of-consistent-strings/2022-09-20 14.25.13 - Accepted - runtime 586ms - memory 16.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countConsistentStrings(self, allowed: str, words: List[str]) -> int: 3 | return sum(all(f in allowed for f in word) for word in words) -------------------------------------------------------------------------------- /1791-richest-customer-wealth/2022-08-01 16.11.46 - Accepted - runtime 101ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumWealth(self, accounts: List[List[int]]) -> int: 3 | return max(sum(f)for f in accounts) -------------------------------------------------------------------------------- /1797-goal-parser-interpretation/2022-08-01 17.33.04 - Accepted - runtime 69ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def interpret(self, command: str) -> str: 3 | return command.replace('()','o').replace('(','').replace(')','') -------------------------------------------------------------------------------- /1802-number-of-students-unable-to-eat-lunch/2024-04-08 11.33.08 - Accepted - runtime 31ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countStudents(self, s: List[int], sa: List[int]) -> int: 3 | c = Counter(s) 4 | n, k = len(s), 0 5 | while k < n and c[sa[k]]: 6 | c[sa[k]] -= 1 7 | k += 1 8 | return n - k 9 | -------------------------------------------------------------------------------- /1817-calculate-money-in-leetcode-bank/2024-04-06 19.30.29 - Accepted - runtime 32ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def totalMoney(self, n: int) -> int: 3 | w = n // 7 4 | money = w * 28 5 | money += (7 * w *( w - 1))//2 6 | 7 | if (n % 7): 8 | extra_days = n % 7 9 | money_to_add = w + 1 10 | for i in range(extra_days): 11 | money += money_to_add 12 | money_to_add += 1 13 | 14 | return money -------------------------------------------------------------------------------- /1823-determine-if-string-halves-are-alike/2022-09-26 14.23.33 - Accepted - runtime 57ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def halvesAreAlike(self, s: str) -> bool: 3 | l = len(s := s.upper()) // 2 4 | return sum((a in 'AEIOU') - (b in 'AEIOU')for a,b in zip(s[:l], s[l:])) == 0 -------------------------------------------------------------------------------- /1823-determine-if-string-halves-are-alike/2024-01-12 16.42.16 - Accepted - runtime 34ms - memory 17.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def halvesAreAlike(self, s: str) -> bool: 3 | s = s.lower() 4 | k = len(s) // 2 5 | A = B = 0 6 | for a,b in zip(s[:k], s[k:]): 7 | A += a in 'aeiou' 8 | B += b in 'aeiou' 9 | return A == B -------------------------------------------------------------------------------- /1823-determine-if-string-halves-are-alike/2024-01-12 16.43.47 - Accepted - runtime 38ms - memory 17.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def halvesAreAlike(self, s: str) -> bool: 3 | l = len(s := s.upper()) // 2 4 | return sum((a in 'AEIOU') - (b in 'AEIOU')for a,b in zip(s[:l], s[l:])) == 0 -------------------------------------------------------------------------------- /1833-find-the-highest-altitude/2022-09-20 19.53.45 - Accepted - runtime 63ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestAltitude(self, gain: list[int]) -> int: 3 | a = r = 0 4 | for i in gain: 5 | a += i 6 | r = max(a, r) 7 | return r -------------------------------------------------------------------------------- /1833-find-the-highest-altitude/2022-09-20 19.55.56 - Accepted - runtime 68ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestAltitude(self, gain: list[int]) -> int: 3 | return max(accumulate(gain, initial=0)) -------------------------------------------------------------------------------- /1839-decode-xored-array/2022-08-01 21.10.08 - Accepted - runtime 322ms - memory 15.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decode(self, encoded: List[int], first: int) -> List[int]: 3 | res = [first] 4 | for i in encoded:res.append(i ^ res[-1]) 5 | return res -------------------------------------------------------------------------------- /1848-sum-of-unique-elements/2022-09-26 17.13.11 - Accepted - runtime 81ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfUnique(self, nums: List[int]) -> int: 3 | return sum(f for f in nums if nums.count(f) == 1) -------------------------------------------------------------------------------- /1848-sum-of-unique-elements/2022-09-26 17.15.28 - Accepted - runtime 65ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfUnique(self, nums: List[int]) -> int: 3 | return sum(v for v,c in collections.Counter(nums).items()if c == 1) -------------------------------------------------------------------------------- /1850-minimum-length-of-string-after-deleting-similar-ends/2024-03-05 15.31.22 - Accepted - runtime 104ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumLength(self, s: str) -> int: 3 | while len(s) > 1 and s[0] == s[-1]: 4 | s = s.strip(s[0]) 5 | return len(s) -------------------------------------------------------------------------------- /1894-merge-strings-alternately/2023-04-21 17.18.50 - Accepted - runtime 35ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mergeAlternately(self, a: str, b: str) -> str: 3 | a, b = list(a)[::-1], list(b)[::-1] 4 | res = '' 5 | while a or b: 6 | if a: 7 | res += a.pop() 8 | if b: 9 | res += b.pop() 10 | 11 | return res -------------------------------------------------------------------------------- /1899-count-items-matching-a-rule/2022-08-02 00.29.15 - Accepted - runtime 363ms - memory 20.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: 3 | return sum(i['tcn'.index(ruleKey[0])] == ruleValue for i in items) -------------------------------------------------------------------------------- /190-reverse-bits/2022-06-29 10.31.49 - Accepted - runtime 7ms - memory 5.3MB.c: -------------------------------------------------------------------------------- 1 | uint32_t reverseBits(uint32_t num) { 2 | num = ((num & 0x55555555) << 1) | ((num & 0xAAAAAAAA) >> 1); 3 | num = ((num & 0x33333333) << 2) | ((num & 0xCCCCCCCC) >> 2); 4 | num = ((num & 0x0F0F0F0F) << 4) | ((num & 0xF0F0F0F0) >> 4); 5 | num = ((num & 0x00FF00FF) << 8) | ((num & 0xFF00FF00) >> 8); 6 | num = ((num & 0x0000FFFF) << 16) | ((num & 0xFFFF0000) >> 16); 7 | 8 | return num; 9 | } -------------------------------------------------------------------------------- /191-number-of-1-bits/2022-06-29 13.14.48 - Accepted - runtime 31ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hammingWeight(self, n: int) -> int: 3 | return f'{n:b}'.count('1') -------------------------------------------------------------------------------- /1944-truncate-sentence/2022-09-20 14.24.51 - Accepted - runtime 45ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def truncateSentence(self, s: str, k: int) -> str: 3 | return ' '.join(s.split()[:k]) -------------------------------------------------------------------------------- /1950-sign-of-the-product-of-an-array/2023-05-02 15.06.30 - Accepted - runtime 74ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arraySign(self, nums: List[int]) -> int: 3 | s = 1 4 | for i in nums: 5 | if i == 0: 6 | return 0 7 | i = 1 if i > 0 else -1 8 | s *= i 9 | return s -------------------------------------------------------------------------------- /1961-maximum-ice-cream-bars/2023-01-06 18.14.06 - Accepted - runtime 1148ms - memory 27.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxIceCream(self, costs: List[int], coins: int) -> int: 3 | res = 0 4 | for i in sorted(costs): 5 | if i > coins: 6 | return res 7 | res += 1 8 | coins -= i 9 | return res -------------------------------------------------------------------------------- /1961-maximum-ice-cream-bars/2023-01-06 18.16.40 - Accepted - runtime 2817ms - memory 27.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxIceCream(self, costs: List[int], coins: int) -> int: 3 | return sum((coins := coins - f) >= 0 for f in sorted(costs)) -------------------------------------------------------------------------------- /1965-sum-of-digits-in-base-k/2022-09-26 14.48.50 - Accepted - runtime 56ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumBase(self, n: int, k: int) -> int: 3 | return self.sumBase(n // k, k) + n % k if n else 0 -------------------------------------------------------------------------------- /1970-sorting-the-sentence/2022-08-02 00.31.50 - Accepted - runtime 33ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortSentence(self, s: str) -> str: 3 | a = s.split() 4 | for i in a[:]: 5 | a[int(i[-1]) - 1] = i[:-1] 6 | 7 | return ' '.join(a) -------------------------------------------------------------------------------- /198-house-robber/2022-12-17 19.05.19 - Accepted - runtime 39ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rob(self, nums: list[int]) -> int: 3 | res = [0] 4 | for i in nums: 5 | res = [max(res), res[0] + i] 6 | 7 | return max(res) -------------------------------------------------------------------------------- /198-house-robber/2022-12-17 19.21.25 - Accepted - runtime 66ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rob(self, nums: list[int]) -> int: 3 | a = b = 0 4 | for i in nums: 5 | a, b = max(a, b), a + i 6 | 7 | return max(a, b) -------------------------------------------------------------------------------- /198-house-robber/2022-12-17 19.21.35 - Accepted - runtime 33ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rob(self, nums: list[int]) -> int: 3 | a = b = 0 4 | for i in nums: 5 | a, b = max(a, b), a + i 6 | 7 | return max(a, b) -------------------------------------------------------------------------------- /198-house-robber/2024-01-21 18.13.48 - Accepted - runtime 44ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rob(self, nums: List[int]) -> int: 3 | a = b = 0 4 | for i in nums: 5 | a, b = max(a, b), a + i 6 | 7 | return max(a, b) -------------------------------------------------------------------------------- /1983-maximum-population-year/2023-01-04 01.13.58 - Accepted - runtime 58ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumPopulation(self, logs: List[List[int]]) -> int: 3 | pop = [0] * 101 4 | res = 0 5 | for a,b in logs: 6 | pop[a - 1950] += 1 7 | pop[b - 1950] -= 1 8 | 9 | for i in range(101): 10 | pop[i] += pop[i - 1] 11 | if pop[i] > pop[res]: 12 | res = i 13 | 14 | return res + 1950 -------------------------------------------------------------------------------- /1993-sum-of-all-subset-xor-totals/2022-09-20 19.42.40 - Accepted - runtime 169ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def subsetXORSum(self, nums: List[int]) -> int: 3 | r = 0 4 | for i in range(1, len(nums) + 1): 5 | for f in itertools.combinations(nums, r=i): 6 | k = 0 7 | for n in f: 8 | k ^= n 9 | r += k 10 | return r -------------------------------------------------------------------------------- /1993-sum-of-all-subset-xor-totals/2022-09-20 19.45.26 - Accepted - runtime 63ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def subsetXORSum(self, nums: List[int]) -> int: 3 | return eval('|'.join(map(str,nums))) * int(pow(2, len(nums)-1)) -------------------------------------------------------------------------------- /20-valid-parentheses/2023-04-10 23.39.46 - Accepted - runtime 40ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isValid(self, s: str) -> bool: 3 | m = {'(': ')', '{': '}', '[': ']'} 4 | stack = [] 5 | for i in s: 6 | if i in m.keys(): 7 | stack.append(i) 8 | else: 9 | if not stack or i != m[stack.pop()]: 10 | return False 11 | 12 | return not stack -------------------------------------------------------------------------------- /20-valid-parentheses/2023-04-10 23.39.59 - Accepted - runtime 22ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isValid(self, s: str) -> bool: 3 | m = {'(': ')', '{': '}', '[': ']'} 4 | stack = [] 5 | for i in s: 6 | if i in m.keys(): 7 | stack.append(i) 8 | else: 9 | if not stack or i != m[stack.pop()]: 10 | return False 11 | 12 | return not stack -------------------------------------------------------------------------------- /201-bitwise-and-of-numbers-range/2024-02-21 10.54.59 - Accepted - runtime 3ms - memory 8.8MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int rangeBitwiseAnd(int left, int right) { 4 | while (right > left) right &= right - 1; 5 | return left & right; 6 | } 7 | }; -------------------------------------------------------------------------------- /202-happy-number/2022-06-30 14.39.41 - Accepted - runtime 96ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isHappy(self, n: int) -> bool: 3 | for i in range(100): 4 | n = sum(map(lambda x:int(x)**2, str(n))) 5 | if n == 1: 6 | return True 7 | return False 8 | -------------------------------------------------------------------------------- /2044-number-of-wonderful-substrings/2024-04-30 09.08.22 - Accepted - runtime 1426ms - memory 17.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wonderfulSubstrings(self, word: str) -> int: 3 | count = [1] + [0] * 1024 4 | res = cur = 0 5 | for i in word: 6 | cur ^= 1 << (ord(i) - 97) 7 | res += count[cur] 8 | res += sum(count[cur ^ (1 << f)] for f in range(10)) 9 | count[cur] += 1 10 | 11 | return res -------------------------------------------------------------------------------- /2048-build-array-from-permutation/2022-08-01 16.03.14 - Accepted - runtime 214ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def buildArray(self, nums: List[int]) -> List[int]: 3 | l = len(nums) 4 | res = [0] * l 5 | for i in range(l): 6 | res[i] = nums[nums[i]] 7 | 8 | return res 9 | -------------------------------------------------------------------------------- /205-isomorphic-strings/2024-04-02 11.17.24 - Accepted - runtime 60ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isIsomorphic(self, s: str, t: str) -> bool: 3 | a, b = map(Counter, (s, t)) 4 | for i in range(len(s)): 5 | if a[s[i]] != b[t[i]]: 6 | return False 7 | 8 | a, b = map(lambda x: [len(list(i)) for f,i in groupby(x)], (s, t)) 9 | return a == b -------------------------------------------------------------------------------- /205-isomorphic-strings/2024-04-02 11.22.09 - Accepted - runtime 52ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isIsomorphic(self, s: str, t: str) -> bool: 3 | a, b = Counter(), Counter() 4 | for i in range(len(s)): 5 | if a[s[i]] != b[t[i]]: 6 | return False 7 | a[s[i]] = i + 1 8 | b[t[i]] = i + 1 9 | 10 | return True 11 | -------------------------------------------------------------------------------- /2058-concatenation-of-array/2022-08-01 16.03.49 - Accepted - runtime 142ms - memory 14.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getConcatenation(self, nums: List[int]) -> List[int]: 3 | return nums + nums -------------------------------------------------------------------------------- /206-reverse-linked-list/2022-11-27 19.33.04 - Accepted - runtime 45ms - memory 20.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: 3 | if not (head and head.next): 4 | return head 5 | 6 | new_head = self.reverseList(head.next) 7 | head.next.next = head 8 | head.next = None 9 | 10 | return new_head -------------------------------------------------------------------------------- /206-reverse-linked-list/2023-04-02 15.45.56 - Accepted - runtime 42ms - memory 20.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: 3 | if not head or not head.next: 4 | return head 5 | 6 | new_head = self.reverseList(head.next) 7 | head.next.next = head 8 | head.next = None 9 | 10 | return new_head -------------------------------------------------------------------------------- /2083-three-divisors/2024-01-05 23.21.34 - Accepted - runtime 34ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isThree(self, n: int) -> bool: 3 | k = 1 4 | for i in range(2, n + 1): 5 | if n % i == 0: 6 | k += 1 7 | if k > 3: 8 | return False 9 | return k == 3 -------------------------------------------------------------------------------- /2116-count-number-of-pairs-with-absolute-difference-k/2022-09-20 14.27.22 - Accepted - runtime 456ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countKDifference(self, nums: list[int], k: int) -> int: 3 | r = 0 4 | l = len(nums) 5 | for i in range(l): 6 | for j in range(i, l): 7 | if i == j:continue 8 | r += abs(nums[i] - nums[j]) == k 9 | 10 | return r -------------------------------------------------------------------------------- /2128-reverse-prefix-of-word/2024-05-01 09.31.24 - Accepted - runtime 34ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reversePrefix(self, word: str, ch: str) -> str: 3 | t = word.find(ch) 4 | return word[:t + 1][::-1] + word[t + 1:] -------------------------------------------------------------------------------- /2137-final-value-of-variable-after-performing-operations/2022-08-01 16.09.56 - Accepted - runtime 96ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def finalValueAfterOperations(self, operations: List[str]) -> int: 3 | x = 0 4 | for i in operations: 5 | x += 1 if '+' in i else -1 6 | 7 | return x -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/2022-06-22 18.12.39 - Accepted - runtime 1327ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKthLargest(self, nums: List[int], k: int) -> int: 3 | for i in range(k - 1): 4 | nums.remove(max(nums)) 5 | 6 | return max(nums) -------------------------------------------------------------------------------- /2154-minimum-moves-to-convert-string/2024-01-06 18.28.41 - Accepted - runtime 34ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumMoves(self, s: str) -> int: 3 | r = i = 0 4 | l = len(s) 5 | while i < l: 6 | if s[i] == 'X': 7 | r += 1 8 | i += 3 9 | else: 10 | i += 1 11 | return r -------------------------------------------------------------------------------- /217-contains-duplicate/2022-06-29 13.33.09 - Accepted - runtime 722ms - memory 26.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def containsDuplicate(self, nums: List[int]) -> bool: 3 | return not len(nums) == len(set(nums)) -------------------------------------------------------------------------------- /2181-smallest-index-with-equal-value/2022-09-26 17.46.15 - Accepted - runtime 90ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestEqual(self, nums: List[int]) -> int: 3 | for i in range(len(nums)): 4 | if i % 10 == nums[i]: 5 | return i 6 | 7 | return -1 -------------------------------------------------------------------------------- /219-contains-duplicate-ii/2022-06-29 13.49.16 - Accepted - runtime 588ms - memory 27.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: 3 | d = {} 4 | for i, val in enumerate(nums): 5 | if val in d and i - d[val] <= k: 6 | return True 7 | d[val] = i 8 | 9 | return False -------------------------------------------------------------------------------- /22-generate-parentheses/2022-07-11 23.32.50 - Accepted - runtime 68ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generateParenthesis(self, n: int) -> List[str]: 3 | if n == 0: return [''] 4 | ans = [] 5 | for c in range(n): 6 | for left in self.generateParenthesis(c): 7 | for right in self.generateParenthesis(n-1-c): 8 | ans.append('({}){}'.format(left, right)) 9 | return ans -------------------------------------------------------------------------------- /22-generate-parentheses/2022-07-13 03.51.05 - Accepted - runtime 73ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generateParenthesis(self, n: int) -> List[str]: 3 | def solve(p: str, left: int, right: int, res: List[str] = []) -> List[str]: 4 | if left:solve(p + '(', left - 1, right) 5 | if right > left:solve(p + ')', left, right - 1) 6 | if not right:res += p, 7 | return res 8 | 9 | return solve('', n, n) -------------------------------------------------------------------------------- /2204-find-subsequence-of-length-k-with-the-largest-sum/2024-01-24 21.21.44 - Accepted - runtime 50ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSubsequence(self, nums: List[int], k: int) -> List[int]: 3 | return [f[1] for f in sorted(sorted(enumerate(nums), key=lambda x:x[1])[-k:])] -------------------------------------------------------------------------------- /2219-maximum-number-of-words-found-in-sentences/2022-08-01 16.17.28 - Accepted - runtime 52ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mostWordsFound(self, sentences: List[str]) -> int: 3 | return max(f.count(' ')+1 for f in sentences) -------------------------------------------------------------------------------- /2231-find-first-palindromic-string-in-the-array/2022-09-20 20.00.13 - Accepted - runtime 111ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstPalindrome(self, words: List[str]) -> str: 3 | for word in words: 4 | if word == word[::-1]: 5 | return word 6 | return '' -------------------------------------------------------------------------------- /2238-a-number-after-a-double-reversal/2022-07-21 16.18.20 - Accepted - runtime 46ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSameAfterReversals(self, num: int) -> bool: 3 | a = int(str(num)[::-1]) 4 | return str(a)[::-1] == str(num) -------------------------------------------------------------------------------- /224-basic-calculator/2024-04-10 00.28.35 - Accepted - runtime 272ms - memory 18.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def calculate(self, s: str) -> int: 3 | from re import compile, findall 4 | regex = compile(r'\([^\(\)]+\)') 5 | while a := findall(regex, s): 6 | for i in a: 7 | s = s.replace(i, str(eval(i))) 8 | 9 | 10 | return eval(s) -------------------------------------------------------------------------------- /2243-check-if-all-as-appears-before-all-bs/2022-07-21 16.16.47 - Accepted - runtime 58ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkString(self, s: str) -> bool: 3 | return ''.join(sorted(s)) == s 4 | -------------------------------------------------------------------------------- /2248-minimum-cost-of-buying-candies-with-discount/2022-07-21 16.14.47 - Accepted - runtime 79ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCost(self, cost: List[int]) -> int: 3 | heapq._heapify_max(cost) 4 | res = 0 5 | for i in range(1, len(cost) + 1): 6 | if i % 3:res += heapq._heappop_max(cost) 7 | else:heapq._heappop_max(cost) 8 | 9 | return res -------------------------------------------------------------------------------- /2254-check-if-every-row-and-column-contains-all-numbers/2022-07-21 16.13.49 - Accepted - runtime 1170ms - memory 14.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkValid(self, matrix: List[List[int]]) -> bool: 3 | a = [*range(1, len(matrix) + 1)] 4 | return all(sorted(f)==a for f in matrix) and all(sorted(f)==a for f in zip(*matrix)) -------------------------------------------------------------------------------- /226-invert-binary-tree/2022-06-30 14.48.00 - Accepted - runtime 58ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def invert(self, node: TreeNode) -> TreeNode: 3 | node.left, node.right = node.right, node.left 4 | for node in (node.left, node.right): 5 | if node:self.invert(node) 6 | 7 | def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: 8 | if not root: return None 9 | self.invert(root) 10 | 11 | return root -------------------------------------------------------------------------------- /226-invert-binary-tree/2022-06-30 14.51.01 - Accepted - runtime 52ms - memory 13.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: 3 | if root: 4 | root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) 5 | return root -------------------------------------------------------------------------------- /2260-divide-a-string-into-groups-of-size-k/2022-07-21 16.10.25 - Accepted - runtime 60ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divideString(self, s: str, k: int, fill: str) -> List[str]: 3 | import textwrap 4 | return [f'{f:{fill}<{k}}' for f in textwrap.wrap(s, k)] -------------------------------------------------------------------------------- /2264-minimum-sum-of-four-digit-number-after-splitting-digits/2022-07-21 16.09.50 - Accepted - runtime 48ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumSum(self, num: int) -> int: 3 | a,b,c,d = sorted(str(num)) 4 | return int(a + c) + int(b + d) -------------------------------------------------------------------------------- /227-basic-calculator-ii/2024-03-31 22.27.01 - Accepted - runtime 130ms - memory 107.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def calculate(self, s: str) -> int: 3 | return int(eval(s.replace('/', '//'))) 4 | -------------------------------------------------------------------------------- /2274-keep-multiplying-found-values-by-two/2022-07-21 16.06.16 - Accepted - runtime 80ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findFinalValue(self, nums: List[int], original: int) -> int: 3 | while original in nums: 4 | original *= 2 5 | return original -------------------------------------------------------------------------------- /2283-sort-even-and-odd-indices-independently/2022-07-21 10.57.31 - Accepted - runtime 114ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortEvenOdd(self, nums: List[int]) -> List[int]: 3 | a, b = sorted(nums[::2]), sorted(nums[1::2])[::-1] 4 | c = [] 5 | t = 0 6 | while a or b: 7 | if t % 2 == 0 and a:c.append(a.pop(0)) 8 | else:c.append(b.pop(0)) 9 | t += 1 10 | return c -------------------------------------------------------------------------------- /2288-count-operations-to-obtain-zero/2022-09-26 17.17.47 - Accepted - runtime 298ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countOperations(self, num1: int, num2: int) -> int: 3 | r = 0 4 | while num1 and num2: 5 | if num1 > num2: 6 | num1 -= num2 7 | else: 8 | num2 -= num1 9 | r += 1 10 | 11 | return r -------------------------------------------------------------------------------- /2288-count-operations-to-obtain-zero/2022-09-26 17.22.57 - Accepted - runtime 229ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countOperations(self, num1: int, num2: int) -> int: 3 | operations = 0 4 | while num1 and num2: 5 | if num1 > num2: 6 | num1 -= num2 7 | else: 8 | num2 -= num1 9 | operations += 1 10 | 11 | return operations -------------------------------------------------------------------------------- /2294-minimum-time-to-complete-trips/2023-03-07 23.25.17 - Accepted - runtime 1858ms - memory 28.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumTime(self, time: List[int], totalTrips: int) -> int: 3 | lo, hi = 1, min(time) * totalTrips 4 | 5 | while lo < hi: 6 | mid = (lo + hi) // 2 7 | if sum(mid // f for f in time) >= totalTrips:hi = mid 8 | else:lo = mid + 1 9 | 10 | return lo 11 | -------------------------------------------------------------------------------- /2304-cells-in-a-range-on-an-excel-sheet/2022-08-01 21.40.30 - Accepted - runtime 80ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def cellsInRange(self, s: str) -> List[str]: 3 | return [f'{chr(i)}{j}'for i in range(ord(s[0]), ord(s[3]) + 1)for j in range(int(s[1]), int(s[4]) + 1)] -------------------------------------------------------------------------------- /2308-divide-array-into-equal-pairs/2022-07-21 16.04.41 - Accepted - runtime 146ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divideArray(self, nums: List[int]) -> bool: 3 | nums.sort() 4 | s, e = 0, 2 5 | l = len(nums) 6 | if l % 2: return False 7 | while e <= l: 8 | a,b = nums[s:e] 9 | if a != b: return False 10 | s += 2 11 | e += 2 12 | 13 | return True 14 | -------------------------------------------------------------------------------- /231-power-of-two/2022-06-30 21.54.52 - Accepted - runtime 92ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfTwo(self, n: int) -> bool: 3 | for i in range(32): 4 | if 2 ** i == n: 5 | return True 6 | return False -------------------------------------------------------------------------------- /231-power-of-two/2022-06-30 21.56.09 - Accepted - runtime 49ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfTwo(self, n: int) -> bool: 3 | return n and not (n & n - 1) -------------------------------------------------------------------------------- /2331-intersection-of-multiple-arrays/2023-11-27 21.02.15 - Accepted - runtime 65ms - memory 17MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersection(self, nums: List[List[int]]) -> List[int]: 3 | l = list(map(set, nums)) 4 | t = l[0] 5 | for i in l[1:]: 6 | t = t.intersection(i) 7 | return sorted(t) 8 | -------------------------------------------------------------------------------- /2337-remove-digit-from-number-to-maximize-result/2023-11-26 19.09.22 - Accepted - runtime 38ms - memory 16.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDigit(self, number: str, digit: str) -> str: 3 | l = [number[1:]] if number[0] == digit else [] 4 | for i in range(1, len(number)): 5 | if number[i] == digit: 6 | l.append(number[:i] + number[i + 1: ]) 7 | return max(l) -------------------------------------------------------------------------------- /2337-remove-digit-from-number-to-maximize-result/2023-11-26 19.12.59 - Accepted - runtime 48ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDigit(self, number: str, digit: str) -> str: 3 | l = number[1:] if number[0] == digit else '' 4 | for i in range(1, len(number)): 5 | if number[i] == digit: 6 | l = max(l, number[:i] + number[i + 1: ]) 7 | return l -------------------------------------------------------------------------------- /2338-minimum-consecutive-cards-to-pick-up/2023-11-26 20.11.38 - Accepted - runtime 670ms - memory 35.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCardPickup(self, cards: List[int]) -> int: 3 | res, pos = 10**6+1, {} 4 | for i, c in enumerate(cards): 5 | if c in pos: 6 | res = min(res, i - pos[c] + 1) 7 | pos[c] = i 8 | 9 | return res % (10**6+1) or -1 -------------------------------------------------------------------------------- /2338-minimum-consecutive-cards-to-pick-up/2023-11-26 20.22.08 - Accepted - runtime 706ms - memory 35.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCardPickup(self, cards: List[int]) -> int: 3 | res, r = 10e7, {} 4 | for i in range(len(cards)): 5 | if cards[i] in r: 6 | res = min(res, i - r[cards[i]] + 1) 7 | r[cards[i]] = i 8 | 9 | return res if res != 10e7 else -1 -------------------------------------------------------------------------------- /2338-minimum-consecutive-cards-to-pick-up/2023-11-26 20.22.19 - Accepted - runtime 710ms - memory 35.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCardPickup(self, cards: List[int]) -> int: 3 | res, r = 10e7, {} 4 | for i in range(len(cards)): 5 | if cards[i] in r: 6 | res = min(res, i - r[cards[i]] + 1) 7 | r[cards[i]] = i 8 | 9 | return res if res != 10e7 else -1 -------------------------------------------------------------------------------- /2338-minimum-consecutive-cards-to-pick-up/2023-11-26 20.22.34 - Accepted - runtime 701ms - memory 35.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCardPickup(self, cards: List[int]) -> int: 3 | res, r = 10e7, {} 4 | for i in range(len(cards)): 5 | if cards[i] in r: 6 | res = min(res, i - r[cards[i]] + 1) 7 | r[cards[i]] = i 8 | 9 | return res if res != 10e7 else -1 -------------------------------------------------------------------------------- /2338-minimum-consecutive-cards-to-pick-up/2023-11-26 20.22.52 - Accepted - runtime 699ms - memory 35.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCardPickup(self, cards: List[int]) -> int: 3 | res, r = 10e7, {} 4 | for i in range(len(cards)): 5 | if cards[i] in r: 6 | res = min(res, i - r[cards[i]] + 1) 7 | r[cards[i]] = i 8 | 9 | return res if res != 10e7 else -1 -------------------------------------------------------------------------------- /234-palindrome-linked-list/2022-06-29 13.25.53 - Accepted - runtime 859ms - memory 46.5MB.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, val=0, next=None): 4 | # self.val = val 5 | # self.next = next 6 | class Solution: 7 | def isPalindrome(self, head: Optional[ListNode]) -> bool: 8 | nodes = [] 9 | while head: 10 | nodes.append(head.val) 11 | head = head.next 12 | return nodes == nodes[::-1] -------------------------------------------------------------------------------- /234-palindrome-linked-list/2024-03-22 13.00.58 - Accepted - runtime 308ms - memory 36.4MB.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, val=0, next=None): 4 | # self.val = val 5 | # self.next = next 6 | class Solution: 7 | def isPalindrome(self, head: Optional[ListNode]) -> bool: 8 | s = [] 9 | while head: 10 | s.append(head.val) 11 | head = head.next 12 | return s == s[::-1] -------------------------------------------------------------------------------- /234-palindrome-linked-list/2024-03-22 13.01.45 - Accepted - runtime 41ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | with open('user.out', 'w') as f: 4 | while True: 5 | line = sys.stdin.readline().strip()[1:-1] 6 | if not line: 7 | break 8 | f.write('true\n' if line == line[::-1] else 'false\n') 9 | 10 | exit(0) -------------------------------------------------------------------------------- /2362-minimum-rounds-to-complete-all-tasks/2023-01-05 00.09.11 - Accepted - runtime 958ms - memory 28.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumRounds(self, tasks: List[int]) -> int: 3 | c = Counter(tasks).values() 4 | return -1 if 1 in c else sum((a + 2) // 3 for a in c) -------------------------------------------------------------------------------- /2362-minimum-rounds-to-complete-all-tasks/2023-01-05 00.09.41 - Accepted - runtime 1646ms - memory 28.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumRounds(self, tasks: List[int]) -> int: 3 | c = Counter(tasks).values() 4 | return -1 if 1 in c else sum((f + 2) // 3 for f in c) -------------------------------------------------------------------------------- /2365-percentage-of-letter-in-string/2022-09-26 14.58.00 - Accepted - runtime 57ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def percentageLetter(self, s: str, letter: str) -> int: 3 | return int(s.count(letter) / len(s) * 100) -------------------------------------------------------------------------------- /2365-percentage-of-letter-in-string/2022-09-26 14.58.50 - Accepted - runtime 58ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def percentageLetter(self, s: str, letter: str) -> int: 3 | return s.count(letter) * 100 // len(s) -------------------------------------------------------------------------------- /2366-maximum-bags-with-full-capacity-of-rocks/2022-12-27 22.00.12 - Accepted - runtime 883ms - memory 22.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumBags(self, capacity: List[int], rocks: List[int], r: int) -> int: 3 | res = 0 4 | for i in sorted(a - b for a,b in zip(capacity, rocks)): 5 | r -= i 6 | if r < 0: 7 | return res 8 | res += 1 9 | 10 | return res -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/2022-06-29 14.30.04 - Accepted - runtime 68ms - memory 14.3MB.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, x): 4 | # self.val = x 5 | # self.next = None 6 | 7 | class Solution: 8 | def deleteNode(self, node): 9 | node.val = node.next.val 10 | node.next = node.next.next -------------------------------------------------------------------------------- /2372-rearrange-characters-to-make-target-string/2023-01-26 14.33.08 - Accepted - runtime 33ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rearrangeCharacters(self, s: str, t: str) -> int: 3 | s = collections.Counter(s) 4 | t = collections.Counter(t) 5 | res = 1E6 6 | for i, c in t.items(): 7 | if i not in s: 8 | return 0 9 | res = min(res, s[i] // c) 10 | 11 | return res -------------------------------------------------------------------------------- /238-product-of-array-except-self/2024-03-15 15.28.11 - Accepted - runtime 172ms - memory 23.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def productExceptSelf(self, nums: List[int]) -> List[int]: 3 | ans, suf, pre = [1] * len(nums), 1, 1 4 | for i in range(len(nums)): 5 | ans[i] *= pre 6 | pre *= nums[i] 7 | ans[~i] *= suf 8 | suf *= nums[~i] 9 | 10 | return ans -------------------------------------------------------------------------------- /2383-add-two-integers/2022-08-01 16.04.05 - Accepted - runtime 51ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sum(self, num1: int, num2: int) -> int: 3 | return num1 + num2 -------------------------------------------------------------------------------- /2384-root-equals-sum-of-children/2022-08-01 16.11.01 - Accepted - runtime 44ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def checkTree(self, root: Optional[TreeNode]) -> bool: 9 | return root.val == root.left.val + root.right.val -------------------------------------------------------------------------------- /2384-root-equals-sum-of-children/2024-01-07 22.37.24 - Accepted - runtime 33ms - memory 17.4MB.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def checkTree(self, root: Optional[TreeNode]) -> bool: 9 | return root.val == root.left.val + root.right.val -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/2022-07-24 20.18.11 - Accepted - runtime 349ms - memory 20.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: 3 | return any(target in f for f in matrix) -------------------------------------------------------------------------------- /2401-count-asterisks/2022-07-28 21.35.18 - Accepted - runtime 52ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countAsterisks(self, s: str) -> int: 3 | return ''.join(s.split('|')[::2]).count('*') -------------------------------------------------------------------------------- /2406-decode-the-message/2022-07-28 21.56.07 - Accepted - runtime 65ms - memory 13.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decodeMessage(self, key: str, message: str) -> str: 3 | from string import ascii_lowercase as ass 4 | k = ' ' 5 | for i in key: 6 | if i not in k:k+=i 7 | 8 | return message.translate(str.maketrans(k[1:],ass)) -------------------------------------------------------------------------------- /242-valid-anagram/2022-07-02 19.14.14 - Accepted - runtime 87ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAnagram(self, s: str, t: str) -> bool: 3 | return sorted(s) == sorted(t) -------------------------------------------------------------------------------- /242-valid-anagram/2022-07-28 13.49.37 - Accepted - runtime 98ms - memory 15.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAnagram(self, s: str, t: str) -> bool: 3 | return sorted(s) == sorted(t) -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2022-07-30 01.49.55 - Accepted - runtime 47ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | d = collections.Counter(nums) 4 | a=b=0 5 | for i in d.values(): 6 | a += i%2 7 | b += i // 2 8 | 9 | return b, a -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2022-07-30 01.50.06 - Accepted - runtime 60ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | d = collections.Counter(nums) 4 | a=b=0 5 | for i in d.values(): 6 | a += i%2 7 | b += i // 2 8 | 9 | return b, a -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2022-07-30 01.50.12 - Accepted - runtime 52ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | d = collections.Counter(nums) 4 | a=b=0 5 | for i in d.values(): 6 | a += i%2 7 | b += i // 2 8 | 9 | return b, a -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2022-07-30 01.50.21 - Accepted - runtime 39ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | d = collections.Counter(nums) 4 | a=b=0 5 | for i in d.values(): 6 | a += i%2 7 | b += i // 2 8 | 9 | return b, a -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2022-07-30 01.51.39 - Accepted - runtime 59ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | d = collections.Counter(nums) 4 | a=b=0 5 | for i in d.values(): 6 | a += i%2 7 | b += i // 2 8 | 9 | return b, a -------------------------------------------------------------------------------- /2421-maximum-number-of-pairs-in-array/2024-04-01 14.50.09 - Accepted - runtime 42ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums: List[int]) -> List[int]: 3 | c = Counter(nums).values() 4 | a = b = 0 5 | for i in c: 6 | i, j = divmod(i, 2) 7 | a += i 8 | b += j 9 | 10 | return [a, b] -------------------------------------------------------------------------------- /2427-first-letter-to-appear-twice/2022-07-28 21.31.06 - Accepted - runtime 35ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedCharacter(self, s: str) -> str: 3 | a = '' 4 | for i in s: 5 | if i in a:return i 6 | a += i 7 | return i -------------------------------------------------------------------------------- /2433-best-poker-hand/2022-07-28 21.29.29 - Accepted - runtime 50ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bestHand(self, ranks: List[int], suits: List[str]) -> str: 3 | if len(set(suits)) == 1: 4 | return 'Flush' 5 | a = collections.Counter(ranks).most_common(1)[0][1] 6 | if a >= 3: 7 | return 'Three of a Kind' 8 | elif a == 2: 9 | return 'Pair' 10 | else: 11 | return 'High Card' -------------------------------------------------------------------------------- /2442-number-of-arithmetic-triplets/2022-09-17 14.00.13 - Accepted - runtime 2826ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arithmeticTriplets(self, nums: List[int], diff: int) -> int: 3 | r = 0 4 | for k in range(l := len(nums)): 5 | for j in range(k): 6 | for i in range(j): 7 | if nums[k] - nums[j] == diff and nums[j] - nums[i] == diff: 8 | r += 1 9 | 10 | return r -------------------------------------------------------------------------------- /2442-number-of-arithmetic-triplets/2022-09-17 14.17.00 - Accepted - runtime 0ms - memory 8.7MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int arithmeticTriplets(vector& nums, int diff) { 4 | int cnt[201] = {}, res = 0; 5 | for (int n : nums) { 6 | if (n >= 2 * diff) 7 | res += cnt[n - diff] && cnt[n - 2 * diff]; 8 | cnt[n] = true; 9 | } 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /2442-number-of-arithmetic-triplets/2022-09-20 14.49.29 - Accepted - runtime 76ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arithmeticTriplets(self, nums: list[int], diff: int) -> int: 3 | visited = [0] * 201 4 | r = 0 5 | for i in nums: 6 | if i >= 2 * diff: 7 | r += visited[i - diff] and visited[i - 2 * diff] 8 | 9 | visited[i] = 1 10 | 11 | return r -------------------------------------------------------------------------------- /2444-longest-ideal-subsequence/2024-04-25 09.55.54 - Accepted - runtime 288ms - memory 17.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestIdealString(self, s: str, k: int) -> int: 3 | dp = [0] * 128 4 | for i in map(ord, s): 5 | dp[i] = max(dp[i - k: i + k + 1]) + 1 6 | 7 | return max(dp) -------------------------------------------------------------------------------- /2469-longest-subsequence-with-limited-sum/2022-12-25 22.31.26 - Accepted - runtime 317ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]: 3 | nums.sort() 4 | res = [] 5 | for i in queries: 6 | s = c = 0 7 | for j in nums: 8 | s += j 9 | if s > i: 10 | break 11 | c += 1 12 | res.append(c) 13 | 14 | return res -------------------------------------------------------------------------------- /2470-removing-stars-from-a-string/2023-04-11 23.34.17 - Accepted - runtime 659ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | res = '' 4 | for a,b in itertools.groupby(s): 5 | b = len(list(b)) 6 | if a == '*': 7 | res = res[:-b] 8 | else: 9 | res += a * b 10 | 11 | return res -------------------------------------------------------------------------------- /2470-removing-stars-from-a-string/2023-04-11 23.34.27 - Accepted - runtime 661ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | res = '' 4 | for a,b in itertools.groupby(s): 5 | b = len(list(b)) 6 | if a == '*': 7 | res = res[:-b] 8 | else: 9 | res += a * b 10 | 11 | return res -------------------------------------------------------------------------------- /2470-removing-stars-from-a-string/2023-04-11 23.35.49 - Accepted - runtime 600ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | res = '' 4 | for i in s: 5 | if i == '*': 6 | res = res[:-1] 7 | else: 8 | res += i 9 | 10 | return res -------------------------------------------------------------------------------- /2470-removing-stars-from-a-string/2023-04-11 23.36.19 - Accepted - runtime 266ms - memory 15.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | res = [] 4 | for i in s: 5 | if i == '*': 6 | res.pop() 7 | else: 8 | res += [i] 9 | 10 | return ''.join(res) -------------------------------------------------------------------------------- /2470-removing-stars-from-a-string/2023-04-11 23.36.31 - Accepted - runtime 222ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | res = [] 4 | for i in s: 5 | if i == '*': 6 | res.pop() 7 | else: 8 | res.append(i) 9 | 10 | return ''.join(res) -------------------------------------------------------------------------------- /2473-max-sum-of-a-pair-with-equal-sum-of-digits/2024-04-01 15.43.14 - Accepted - runtime 826ms - memory 31.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumSum(self, nums: List[int]) -> int: 3 | res = -1 4 | l = {} 5 | for i in nums: 6 | d = sum(map(int, str(i))) 7 | if d in l: 8 | res = max(res, i + l[d]) 9 | l[d] = max(l[d], i) 10 | else: 11 | l[d] = i 12 | 13 | return res -------------------------------------------------------------------------------- /2487-optimal-partition-of-string/2023-04-05 23.26.07 - Accepted - runtime 248ms - memory 14.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def partitionString(self, s: str) -> int: 3 | i, ans, flag = 0, 1, 0 4 | while i < len(s): 5 | val = ord(s[i]) - ord('a') 6 | if flag & (1 << val): 7 | flag = 0 8 | ans += 1 9 | flag |= 1 << val 10 | i += 1 11 | return ans -------------------------------------------------------------------------------- /2487-optimal-partition-of-string/2023-04-05 23.26.17 - Accepted - runtime 249ms - memory 14.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def partitionString(self, s: str) -> int: 3 | i, ans, flag = 0, 1, 0 4 | while i < len(s): 5 | val = ord(s[i]) - ord('a') 6 | if flag & (1 << val): 7 | flag = 0 8 | ans += 1 9 | flag |= 1 << val 10 | i += 1 11 | return ans -------------------------------------------------------------------------------- /2487-optimal-partition-of-string/2023-04-05 23.26.27 - Accepted - runtime 248ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def partitionString(self, s: str) -> int: 3 | i, ans, flag = 0, 1, 0 4 | while i < len(s): 5 | val = ord(s[i]) - ord('a') 6 | if flag & (1 << val): 7 | flag = 0 8 | ans += 1 9 | flag |= 1 << val 10 | i += 1 11 | return ans -------------------------------------------------------------------------------- /2487-optimal-partition-of-string/2023-04-05 23.28.29 - Accepted - runtime 68ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def partitionString(self, s: str) -> int: 3 | l = '' 4 | res = 1 5 | for i in s: 6 | if i in l: 7 | l = i 8 | res += 1 9 | 10 | else: 11 | l += i 12 | 13 | return res -------------------------------------------------------------------------------- /2491-smallest-even-multiple/2022-09-30 16.06.11 - Accepted - runtime 66ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestEvenMultiple(self, n: int) -> int: 3 | return n + n if n % 2 else n -------------------------------------------------------------------------------- /2502-sort-the-people/2022-09-27 11.27.35 - Accepted - runtime 292ms - memory 14.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: 3 | return [name for name,height in sorted(zip(names, heights), key=lambda x:-x[1])] -------------------------------------------------------------------------------- /2507-number-of-common-factors/2024-01-06 18.19.17 - Accepted - runtime 33ms - memory 17.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def commonFactors(self, a: int, b: int) -> int: 3 | return sum(a % f == 0 and b % f == 0 for f in range(1, max(a,b) + 1)) 4 | -------------------------------------------------------------------------------- /2524-largest-positive-integer-that-exists-with-its-negative/2024-05-02 09.12.42 - Accepted - runtime 105ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMaxK(self, nums: List[int]) -> int: 3 | s = set(nums) 4 | for i in sorted(nums, reverse=True): 5 | if -i in s: 6 | return i 7 | 8 | return -1 -------------------------------------------------------------------------------- /2527-count-subarrays-with-fixed-bounds/2024-03-31 12.06.30 - Accepted - runtime 720ms - memory 31MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: 3 | res = 0; m = M = last = -1 4 | for i in range(len(nums)): 5 | if not minK <= nums[i] <= maxK: last = i 6 | if nums[i] == minK: m = i 7 | if nums[i] == maxK: M = i 8 | res += max(0, min(m, M) - last) 9 | 10 | 11 | return res 12 | -------------------------------------------------------------------------------- /2532-remove-letter-to-equalize-frequency/2024-04-05 15.05.03 - Accepted - runtime 32ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def equalFrequency(self, word: str) -> bool: 3 | cnt = Counter(Counter(word).values()) 4 | if (len(cnt) == 1): 5 | return list(cnt.keys())[0] == 1 or list(cnt.values())[0] == 1 6 | if (len(cnt) == 2): 7 | f1, f2 = min(cnt.keys()), max(cnt.keys()) 8 | return (f1 + 1 == f2 and cnt[f2] == 1) or (f1 == 1 and cnt[f1] == 1) 9 | return False -------------------------------------------------------------------------------- /2556-convert-the-temperature/2024-02-02 19.19.00 - Accepted - runtime 28ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertTemperature(self, celsius: float) -> List[float]: 3 | return [round(celsius + 273.15, 5), round(celsius * 1.8 + 32, 5)] -------------------------------------------------------------------------------- /257-binary-tree-paths/2022-07-01 16.16.49 - Accepted - runtime 56ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def binaryTreePaths(self, root): 3 | if not root: return [] 4 | result= [ str(root.val)+"->" + path for path in self.binaryTreePaths(root.left)] 5 | result+= [ str(root.val)+"->" + path for path in self.binaryTreePaths(root.right)] 6 | return result or [str(root.val)] -------------------------------------------------------------------------------- /2571-find-the-pivot-integer/2024-03-13 12.58.11 - Accepted - runtime 42ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def pivotInteger(self, n: int) -> int: 3 | n *= (n + 1) / 2 4 | x = int(n ** .5) 5 | return x if x * x == n else -1 -------------------------------------------------------------------------------- /2573-remove-nodes-from-linked-list/2024-02-25 19.28.14 - Accepted - runtime 258ms - memory 164.4MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* removeNodes(ListNode* head) { 4 | if (head == NULL) return head; 5 | head -> next = removeNodes(head -> next); 6 | return head->next && head->next->val > head->val? head->next: head; 7 | } 8 | }; -------------------------------------------------------------------------------- /258-add-digits/2022-07-02 22.43.02 - Accepted - runtime 28ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addDigits(self, num: int) -> int: 3 | return 1 + (num - 1) % 9 if num else 0 -------------------------------------------------------------------------------- /258-add-digits/2022-07-02 22.45.15 - Accepted - runtime 3ms - memory 5.6MB.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int addDigits(int num){ 4 | return num ? 1 + (num - 1) % 9 : 0; 5 | } -------------------------------------------------------------------------------- /258-add-digits/2022-07-02 22.45.23 - Accepted - runtime 3ms - memory 5.5MB.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int addDigits(int num){ 4 | return num ? 1 + (num - 1) % 9 : 0; 5 | } -------------------------------------------------------------------------------- /258-add-digits/2022-07-02 22.45.29 - Accepted - runtime 4ms - memory 5.4MB.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int addDigits(int num){ 4 | return num ? 1 + (num - 1) % 9 : 0; 5 | } -------------------------------------------------------------------------------- /258-add-digits/2022-07-02 22.45.40 - Accepted - runtime 4ms - memory 5.5MB.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | int addDigits(int num){ 4 | return num ? 1 + (num - 1) % 9 : 0; 5 | } -------------------------------------------------------------------------------- /258-add-digits/2023-04-26 15.51.22 - Accepted - runtime 36ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addDigits(self, num: int) -> int: 3 | while len(str(num)) > 1: 4 | num = sum(map(int, str(num))) 5 | 6 | return num -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/2022-04-25 10.18.41 - Accepted - runtime 168ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | k = 0 4 | while k < len(nums) - 1: 5 | if nums[k] == nums[k + 1]: 6 | nums.pop(k) 7 | else: 8 | k += 1 9 | else: 10 | k += 1 11 | 12 | return k 13 | -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/2022-04-25 10.18.49 - Accepted - runtime 188ms - memory 15.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | k = 0 4 | while k < len(nums) - 1: 5 | if nums[k] == nums[k + 1]: 6 | nums.pop(k) 7 | else: 8 | k += 1 9 | else: 10 | k += 1 11 | 12 | return k 13 | -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/2022-04-25 10.20.50 - Accepted - runtime 97ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, nums: List[int]) -> int: 3 | k = 0; 4 | for i in range(1, len(nums)): 5 | if nums[i] != nums[k]: 6 | k += 1 7 | nums[k] = nums[i] 8 | 9 | return k + 1 10 | -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/2024-02-17 12.24.26 - Accepted - runtime 11ms - memory 21.1MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | int r = 0; 5 | for (int i=1;i < nums.size();i++) 6 | if (nums[i] != nums[r]) nums[++r] = nums[i]; 7 | return ++r; 8 | } 9 | }; -------------------------------------------------------------------------------- /263-ugly-number/2023-04-30 00.09.10 - Accepted - runtime 54ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isUgly(self, n: int) -> bool: 3 | if n < 2: 4 | return n == 1 5 | 6 | if n % 2 == 0: 7 | return self.isUgly(n // 2) 8 | 9 | elif n % 3 == 0: 10 | return self.isUgly(n // 3) 11 | 12 | elif n % 5 == 0: 13 | return self.isUgly(n // 5) 14 | -------------------------------------------------------------------------------- /2634-minimum-common-value/2024-03-09 15.00.41 - Accepted - runtime 335ms - memory 42.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getCommon(self, nums1: List[int], nums2: List[int]) -> int: 3 | return min((set(nums1) & set(nums2)) or [-1]) 4 | -------------------------------------------------------------------------------- /2663-distribute-money-to-maximum-children/2024-04-08 23.37.51 - Accepted - runtime 44ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distMoney(self, money: int, children: int) -> int: 3 | money -= children 4 | if money < 0: 5 | return -1 6 | if money // 7 == children and money % 7 == 0: 7 | return children 8 | if money // 7 == children - 1 and money % 7 == 3: 9 | return children - 2 10 | return min(children - 1, money // 7) -------------------------------------------------------------------------------- /268-missing-number/2022-07-01 10.25.51 - Accepted - runtime 143ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: List[int]) -> int: 3 | n = len(nums) 4 | return (n * (n + 1) // 2) - sum(nums) -------------------------------------------------------------------------------- /268-missing-number/2024-02-20 10.35.25 - Accepted - runtime 16ms - memory 20.3MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | int n = nums.size(); 5 | int sum = 0; 6 | for (int num : nums) sum += num; 7 | return (n * (n + 1) / 2) - sum; 8 | } 9 | }; -------------------------------------------------------------------------------- /268-missing-number/2024-02-20 10.36.25 - Accepted - runtime 15ms - memory 20.3MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | ios_base::sync_with_stdio(false); 5 | cin.tie(NULL); 6 | int n=nums.size(); 7 | int sum; 8 | sum=(n*(n+1))/2; 9 | int ans=sum-accumulate(nums.begin(),nums.end(),0); 10 | return ans; 11 | } 12 | }; -------------------------------------------------------------------------------- /27-remove-element/2022-04-25 12.32.43 - Accepted - runtime 44ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums: List[int], val: int) -> int: 3 | for i in nums.copy(): 4 | if i == val:nums.remove(i) 5 | return len(nums) -------------------------------------------------------------------------------- /27-remove-element/2022-04-25 12.32.51 - Accepted - runtime 42ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums: List[int], val: int) -> int: 3 | for i in nums.copy(): 4 | if i == val:nums.remove(i) 5 | return len(nums) -------------------------------------------------------------------------------- /27-remove-element/2022-04-25 12.33.28 - Accepted - runtime 47ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums: List[int], val: int) -> int: 3 | k = 0 4 | for i in nums.copy(): 5 | if i == val:nums.remove(i) 6 | else:k += 1 7 | return k -------------------------------------------------------------------------------- /27-remove-element/2022-04-25 12.33.34 - Accepted - runtime 36ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums: List[int], val: int) -> int: 3 | k = 0 4 | for i in nums.copy(): 5 | if i == val:nums.remove(i) 6 | else:k += 1 7 | return k -------------------------------------------------------------------------------- /27-remove-element/2024-02-17 12.44.13 - Accepted - runtime 0ms - memory 10.4MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int r = 0; 5 | for (int ind=0;ind < nums.size();){ 6 | if (nums[ind] == val)nums.erase(nums.begin()+ind); 7 | else{r++; ind++;} 8 | } 9 | return r; 10 | } 11 | }; -------------------------------------------------------------------------------- /278-first-bad-version/2022-07-17 16.26.10 - Accepted - runtime 22ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | # def isBadVersion(version: int) -> bool: 2 | 3 | class Solution: 4 | def firstBadVersion(self, n: int) -> int: 5 | left, right = 1, n 6 | while left < right: 7 | mid = left + (right - left) // 2 8 | if isBadVersion(mid): 9 | right = mid 10 | else: 11 | left = mid + 1 12 | return left -------------------------------------------------------------------------------- /28-find-the-index-of-the-first-occurrence-in-a-string/2022-04-25 16.30.49 - Accepted - runtime 52ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | return haystack.find(needle) -------------------------------------------------------------------------------- /28-find-the-index-of-the-first-occurrence-in-a-string/2024-02-17 12.48.04 - Accepted - runtime 0ms - memory 7.5MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int strStr(string haystack, string needle) { 4 | return haystack.find(needle); 5 | } 6 | }; -------------------------------------------------------------------------------- /2812-find-the-maximum-achievable-number/2024-02-02 19.17.17 - Accepted - runtime 45ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def theMaximumAchievableX(self, num: int, t: int) -> int: 3 | return num + t * 2 -------------------------------------------------------------------------------- /2820-return-length-of-arguments-passed/2024-02-11 14.21.02 - Accepted - runtime 55ms - memory 48.7MB.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {...(null|boolean|number|string|Array|Object)} args 3 | * @return {number} 4 | */ 5 | var argumentsLength = function(...args) { 6 | return args.length 7 | }; 8 | 9 | /** 10 | * argumentsLength(1, 2, 3); // 3 11 | */ -------------------------------------------------------------------------------- /283-move-zeroes/2022-07-01 18.36.22 - Accepted - runtime 262ms - memory 15.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def moveZeroes(self, nums: List[int]) -> None: 3 | r = 0 4 | for i in range(len(nums)): 5 | if nums[i]: 6 | nums[r], nums[i] = nums[i], nums[r] 7 | r += 1 -------------------------------------------------------------------------------- /2859-add-two-promises/2024-04-01 14.36.19 - Accepted - runtime 55ms - memory 50.4MB.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Promise} promise1 3 | * @param {Promise} promise2 4 | * @return {Promise} 5 | */ 6 | var addTwoPromises = async function(promise1, promise2) { 7 | return await promise1 + await promise2; 8 | }; 9 | 10 | /** 11 | * addTwoPromises(Promise.resolve(2), Promise.resolve(2)) 12 | * .then(console.log); // 4 13 | */ -------------------------------------------------------------------------------- /2860-sort-by/2024-04-17 22.44.39 - Accepted - runtime 128ms - memory 66.2MB.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Array} arr 3 | * @param {Function} fn 4 | * @return {Array} 5 | */ 6 | var sortBy = function(arr, fn) { 7 | return arr.sort((a, b) => fn(a) - fn(b)); 8 | }; -------------------------------------------------------------------------------- /287-find-the-duplicate-number/2023-01-11 20.37.21 - Accepted - runtime 593ms - memory 30.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicate(self, nums: List[int]) -> int: 3 | n = set() 4 | for i in nums: 5 | if i in n: 6 | return i 7 | n.add(i) -------------------------------------------------------------------------------- /287-find-the-duplicate-number/2024-02-15 22.16.06 - Accepted - runtime 463ms - memory 32.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicate(self, nums: List[int]) -> int: 3 | d = set() 4 | for i in nums: 5 | if i in d: return i 6 | d.add(i) 7 | 8 | 9 | return i -------------------------------------------------------------------------------- /287-find-the-duplicate-number/2024-03-24 21.04.20 - Accepted - runtime 438ms - memory 32.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicate(self, nums: List[int]) -> int: 3 | d = set() 4 | for i in nums: 5 | if i in d: return i 6 | d.add(i) 7 | 8 | 9 | return i -------------------------------------------------------------------------------- /2876-number-of-employees-who-met-the-target/2024-04-01 14.43.54 - Accepted - runtime 47ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int: 3 | return sum(f >= target for f in hours) -------------------------------------------------------------------------------- /2881-split-strings-by-separator/2024-04-06 11.03.49 - Accepted - runtime 91ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]: 3 | return filter(lambda x: x, separator.join(words).split(separator)) -------------------------------------------------------------------------------- /2887-sort-vowels-in-a-string/2024-04-06 11.00.30 - Accepted - runtime 131ms - memory 18.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortVowels(self, s: str) -> str: 3 | r = '' 4 | l = sorted(f for f in s if f in 'aeiouAEIOU') 5 | v = 0 6 | for i in s: 7 | if i in 'aeiouAEIOU': 8 | r += l[v] 9 | v += 1 10 | else: 11 | r += i 12 | 13 | return r -------------------------------------------------------------------------------- /29-divide-two-integers/2023-04-02 15.57.24 - Accepted - runtime 40ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | HI = 2 ** 31 - 1 2 | LO = -2 ** 31 3 | class Solution: 4 | def divide(self, dividend: int, divisor: int) -> int: 5 | s = int(dividend / divisor) 6 | return min(max(s, LO), HI) -------------------------------------------------------------------------------- /290-word-pattern/2022-07-18 20.19.03 - Accepted - runtime 42ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wordPattern(self, pattern: str, s: str) -> bool: 3 | D = {} 4 | B = s.split() 5 | if len(pattern) != len(B):return False 6 | for a,b in zip(pattern, B): 7 | if a in D: 8 | if D[a] != b:return False 9 | else:D[a] = b 10 | return len(D.values()) == len(set(D.values())) -------------------------------------------------------------------------------- /290-word-pattern/2022-07-18 20.32.42 - Accepted - runtime 53ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wordPattern(self, pattern: str, s: str) -> bool: 3 | return len(pattern) == len(s := s.split()) and list(map(pattern.index, pattern)) == list(map(s.index, s)) -------------------------------------------------------------------------------- /290-word-pattern/2023-01-06 02.01.38 - Accepted - runtime 53ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wordPattern(self, p: str, s: str) -> bool: 3 | s = s.split() 4 | return all(p.index(a) == s.index(b)for a,b in zip(p, s)) if len(s) == len(p) else False -------------------------------------------------------------------------------- /292-nim-game/2024-04-01 15.51.32 - Accepted - runtime 37ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canWinNim(self, n: int) -> bool: 3 | return n % 4 -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/2022-10-07 20.32.16 - Accepted - runtime 118ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLongestSubstring(self, s: str) -> int: 3 | visited = {} 4 | start = res = 0 5 | for i in range(len(s)): 6 | if s[i] in visited: 7 | start = max(start, visited[s[i]] + 1) 8 | visited[s[i]] = i 9 | res = max(res, i - start + 1) 10 | return res -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/2024-04-27 18.35.54 - Accepted - runtime 1107ms - memory 17MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLIS(self, nums: List[int]) -> int: 3 | dp = [1] * len(nums) 4 | for i in range(1, len(nums)): 5 | dp[i] = 1 + max([dp[f] for f in range(i)if nums[i] > nums[f]]or [0]) 6 | 7 | return max(dp) 8 | -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/2024-04-27 18.39.01 - Accepted - runtime 1105ms - memory 17MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLIS(self, nums: List[int]) -> int: 3 | dp = [1] * len(nums) 4 | r = 1 5 | for i in range(1, len(nums)): 6 | dp[i] = 1 + max([dp[f] for f in range(i)if nums[i] > nums[f]]or [0]) 7 | r = max(r, dp[i]) 8 | 9 | return r 10 | -------------------------------------------------------------------------------- /303-range-sum-query-immutable/2024-03-14 00.10.11 - Accepted - runtime 794ms - memory 19.9MB.py: -------------------------------------------------------------------------------- 1 | class NumArray: 2 | 3 | def __init__(self, nums: List[int]): 4 | self.s = nums 5 | 6 | def sumRange(self, left: int, right: int) -> int: 7 | return sum(self.s[left:right + 1]) 8 | 9 | 10 | # Your NumArray object will be instantiated and called as such: 11 | # obj = NumArray(nums) 12 | # param_1 = obj.sumRange(left,right) -------------------------------------------------------------------------------- /303-range-sum-query-immutable/2024-03-14 00.11.29 - Accepted - runtime 65ms - memory 20.1MB.py: -------------------------------------------------------------------------------- 1 | class NumArray: 2 | 3 | def __init__(self, nums: List[int]): 4 | self.s = [0] + list(accumulate(nums)) 5 | 6 | def sumRange(self, left: int, right: int) -> int: 7 | return self.s[right + 1] - self.s[left] 8 | 9 | 10 | # Your NumArray object will be instantiated and called as such: 11 | # obj = NumArray(nums) 12 | # param_1 = obj.sumRange(left,right) -------------------------------------------------------------------------------- /3055-maximum-odd-binary-number/2024-03-01 15.35.35 - Accepted - runtime 37ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumOddBinaryNumber(self, s: str) -> str: 3 | o = s.count("1") 4 | z = len(s) - o 5 | 6 | return "1" * (o - 1) + "0" * z + "1" -------------------------------------------------------------------------------- /3055-maximum-odd-binary-number/2024-03-01 15.38.05 - Accepted - runtime 0ms - memory 9.2MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string maximumOddBinaryNumber(string s) { 4 | int o = count(s.begin(), s.end(), '1'); 5 | int z = s.length() - o; 6 | 7 | return string(o - 1, '1') + string(z, '0') + "1"; 8 | } 9 | }; -------------------------------------------------------------------------------- /3062-create-a-dataframe-from-list/2024-02-23 23.55.23 - Accepted - runtime 670ms - memory 64.9MB.pd.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | def createDataframe(student_data: List[List[int]]) -> pd.DataFrame: 4 | return pd.DataFrame(student_data, columns=['student_id', 'age']) 5 | -------------------------------------------------------------------------------- /3064-reshape-data-concatenate/2024-04-01 14.37.48 - Accepted - runtime 788ms - memory 65.8MB.pd.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame: 4 | return pd.concat([df1, df2]) -------------------------------------------------------------------------------- /3065-display-the-first-three-rows/2024-04-01 14.31.56 - Accepted - runtime 628ms - memory 65.7MB.pd.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame: 4 | return employees.head(3) -------------------------------------------------------------------------------- /3066-create-a-new-column/2024-04-01 14.38.48 - Accepted - runtime 719ms - memory 65.3MB.pd.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame: 4 | employees['bonus'] = employees.salary * 2 5 | return employees -------------------------------------------------------------------------------- /3067-modify-columns/2024-04-01 14.35.25 - Accepted - runtime 776ms - memory 65.5MB.pd.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame: 4 | employees.salary *= 2 5 | return employees -------------------------------------------------------------------------------- /3094-minimum-number-of-operations-to-make-array-empty/2024-01-04 23.34.25 - Accepted - runtime 528ms - memory 32.1MB.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def minOperations(self, nums: List[int]) -> int: 4 | l = Counter(nums).values() 5 | if min(l) == 1: 6 | return -1 7 | return sum(f // 3 + (f % 3 > 0) for f in l) -------------------------------------------------------------------------------- /3172-divisible-and-non-divisible-sums-difference/2024-02-02 19.21.58 - Accepted - runtime 37ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def differenceOfSums(self, n: int, m: int) -> int: 3 | a = b = 0 4 | for i in range(1, n + 1): 5 | if i % m: 6 | a += i 7 | else: 8 | b += i 9 | 10 | return a - b -------------------------------------------------------------------------------- /319-bulb-switcher/2023-04-27 09.52.23 - Accepted - runtime 40ms - memory 16.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bulbSwitch(self, n: int) -> int: 3 | return int(n ** .5) -------------------------------------------------------------------------------- /319-bulb-switcher/2023-04-27 09.52.33 - Accepted - runtime 39ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bulbSwitch(self, n: int) -> int: 3 | return int(n ** .5) -------------------------------------------------------------------------------- /319-bulb-switcher/2023-04-27 09.52.40 - Accepted - runtime 50ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bulbSwitch(self, n: int) -> int: 3 | return int(n ** .5) -------------------------------------------------------------------------------- /319-bulb-switcher/2023-04-27 09.53.18 - Accepted - runtime 55ms - memory 16.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bulbSwitch(self, n: int) -> int: 3 | return int(math.sqrt(n)) -------------------------------------------------------------------------------- /3194-find-words-containing-character/2024-02-02 19.20.05 - Accepted - runtime 75ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findWordsContaining(self, words: List[str], x: str) -> List[int]: 3 | return [f for f in range(len(words)) if x in words[f]] 4 | -------------------------------------------------------------------------------- /32-longest-valid-parentheses/2024-04-16 11.12.23 - Accepted - runtime 46ms - memory 17.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestValidParentheses(self, s: str) -> int: 3 | dp, st = [0] * (len(s) + 1), [] 4 | for i in range(len(s)): 5 | if s[i] == '(':st.append(i) 6 | else: 7 | if st: 8 | p = st.pop() 9 | dp[i + 1] = dp[p] + i - p + 1 10 | 11 | return max(dp) -------------------------------------------------------------------------------- /3242-count-elements-with-maximum-frequency/2024-03-08 12.18.45 - Accepted - runtime 38ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxFrequencyElements(self, nums: List[int]) -> int: 3 | c = Counter(nums) 4 | m = c.most_common(1)[0][1] 5 | return sum(v for k,v in c.items() if v == m) 6 | -------------------------------------------------------------------------------- /3249-minimum-number-of-operations-to-make-array-xor-equal-to-k/2024-04-29 09.50.45 - Accepted - runtime 591ms - memory 30.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: List[int], k: int) -> int: 3 | return reduce(xor, nums, k).bit_count() -------------------------------------------------------------------------------- /326-power-of-three/2022-07-20 23.19.49 - Accepted - runtime 121ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | return False if n <= 0 else (math.log10(n) / math.log10(3)) % 1 == 0 4 | -------------------------------------------------------------------------------- /3351-maximize-happiness-of-selected-children/2024-05-09 09.59.41 - Accepted - runtime 813ms - memory 43.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumHappinessSum(self, happiness: List[int], k: int) -> int: 3 | happiness.sort() 4 | s = 0 5 | for i in range(k): 6 | t = max(happiness[~i] - i, 0) 7 | if not t: return s 8 | s += t 9 | return s -------------------------------------------------------------------------------- /338-counting-bits/2022-07-01 10.23.04 - Accepted - runtime 200ms - memory 20.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countBits(self, n: int) -> List[int]: 3 | return [f'{f:b}'.count('1')for f in range(n + 1)] -------------------------------------------------------------------------------- /34-find-first-and-last-position-of-element-in-sorted-array/2022-07-25 20.05.02 - Accepted - runtime 139ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchRange(self, nums: List[int], t: int) -> List[int]: 3 | return [nums.index(t), len(nums) - 1 - nums[::-1].index(t)] if t in nums else [-1, -1] -------------------------------------------------------------------------------- /342-power-of-four/2022-07-20 23.20.04 - Accepted - runtime 59ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfFour(self, n: int) -> bool: 3 | return False if n <= 0 else (math.log10(n) / math.log10(4)) % 1 == 0 -------------------------------------------------------------------------------- /344-reverse-string/2022-06-30 22.10.25 - Accepted - runtime 399ms - memory 18.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseString(self, s: List[str]) -> None: 3 | """ 4 | Do not return anything, modify s in-place instead. 5 | """ 6 | for i in range(len(s)): 7 | s.append(s.pop(~i)) 8 | -------------------------------------------------------------------------------- /344-reverse-string/2022-06-30 22.11.34 - Accepted - runtime 274ms - memory 18.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseString(self, s: List[str]) -> None: 3 | for i in range(len(s)//2): s[i], s[~i] = s[~i], s[i] 4 | -------------------------------------------------------------------------------- /345-reverse-vowels-of-a-string/2022-06-30 22.19.27 - Accepted - runtime 128ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseVowels(self, s: str) -> str: 3 | a = ''.join(f for f in s[::-1]if f.lower() in 'aeiou') 4 | f = 0 5 | res = '' 6 | for i in s: 7 | if i.lower()in 'aeiou':res += a[f];f+=1 8 | else:res += i 9 | 10 | return res -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/2022-07-18 19.54.32 - Accepted - runtime 46ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: 3 | return list(set(nums1) & set(nums2)) -------------------------------------------------------------------------------- /349-intersection-of-two-arrays/2024-03-10 14.20.48 - Accepted - runtime 42ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: 3 | return set(nums1) & set(nums2) -------------------------------------------------------------------------------- /35-search-insert-position/2022-06-15 20.57.03 - Accepted - runtime 92ms - memory 14.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | left, right = 0, len(nums) - 1 4 | 5 | while left <= right: 6 | middle = left + (right-left) // 2 7 | if nums[middle] == target: return middle 8 | if nums[middle] > target: right = middle - 1 9 | else: left = middle + 1 10 | return left -------------------------------------------------------------------------------- /35-search-insert-position/2022-06-15 20.57.16 - Accepted - runtime 67ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | left, right = 0, len(nums) - 1 4 | 5 | while left <= right: 6 | middle = left + (right-left) // 2 7 | if nums[middle] == target: return middle 8 | if nums[middle] > target: right = middle - 1 9 | else: left = middle + 1 10 | return left -------------------------------------------------------------------------------- /35-search-insert-position/2022-06-15 20.57.22 - Accepted - runtime 82ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | left, right = 0, len(nums) - 1 4 | 5 | while left <= right: 6 | middle = left + (right-left) // 2 7 | if nums[middle] == target: return middle 8 | if nums[middle] > target: right = middle - 1 9 | else: left = middle + 1 10 | return left -------------------------------------------------------------------------------- /35-search-insert-position/2022-06-15 20.57.29 - Accepted - runtime 115ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | left, right = 0, len(nums) - 1 4 | 5 | while left <= right: 6 | middle = left + (right-left) // 2 7 | if nums[middle] == target: return middle 8 | if nums[middle] > target: right = middle - 1 9 | else: left = middle + 1 10 | return left -------------------------------------------------------------------------------- /35-search-insert-position/2022-06-15 21.09.32 - Accepted - runtime 90ms - memory 14.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def searchInsert(self, nums: List[int], target: int) -> int: 3 | left, right = 0, len(nums) - 1 4 | while left <= right: 5 | mid = left + (right - left) // 2 6 | if nums[mid] == target:return mid 7 | elif nums[mid] > target: right = mid - 1 8 | else: left = mid + 1 9 | 10 | 11 | return left -------------------------------------------------------------------------------- /35-search-insert-position/2024-02-17 13.15.34 - Accepted - runtime 0ms - memory 11.9MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& nums, int target) { 4 | int low = 0, high = nums.size() - 1, mid; 5 | while (low <= high){ 6 | mid = low + (high - low) / 2; 7 | if(nums[mid] == target) return mid; 8 | else if(nums[mid] > target) high = mid - 1; 9 | else low = mid + 1; 10 | } 11 | return low; 12 | } 13 | }; -------------------------------------------------------------------------------- /350-intersection-of-two-arrays-ii/2024-04-01 16.06.51 - Accepted - runtime 48ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: 3 | a, b = map(Counter, (nums1, nums2)) 4 | res = [] 5 | for i in a: 6 | if i in b: 7 | res += [i] * min(a[i], b[i]) 8 | 9 | return res -------------------------------------------------------------------------------- /367-valid-perfect-square/2024-04-01 18.36.26 - Accepted - runtime 33ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPerfectSquare(self, num: int) -> bool: 3 | return num ** .5 % 1 == 0 -------------------------------------------------------------------------------- /371-sum-of-two-integers/2024-04-15 15.06.30 - Accepted - runtime 37ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getSum(self, a: int, b: int) -> int: 3 | return a + b -------------------------------------------------------------------------------- /38-count-and-say/2024-04-19 00.22.45 - Accepted - runtime 44ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countAndSay(self, n: int) -> str: 3 | t = 1 4 | res = '1' 5 | while t < n: 6 | tmp = '' 7 | for a,b in groupby(res): 8 | tmp += f'{len(list(b))}{a}' 9 | res = tmp 10 | t += 1 11 | return res -------------------------------------------------------------------------------- /383-ransom-note/2022-06-30 22.24.43 - Accepted - runtime 50ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canConstruct(self, ransomNote: str, magazine: str) -> bool: 3 | return all(ransomNote.count(f)<=magazine.count(f)for f in set(ransomNote)) -------------------------------------------------------------------------------- /383-ransom-note/2022-06-30 22.25.01 - Accepted - runtime 58ms - memory 14.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canConstruct(self, ransomNote: str, magazine: str) -> bool: 3 | return all(ransomNote.count(f)<=magazine.count(f)for f in set(ransomNote)) -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2022-07-11 14.13.30 - Accepted - runtime 313ms - memory 14.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | seen = '' 4 | for ind, i in enumerate(s): 5 | if i not in s[ind + 1:] + seen: 6 | return ind 7 | seen += i 8 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2022-07-11 14.14.59 - Accepted - runtime 6275ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | for ind,i in enumerate(s): 4 | if s.count(i) == 1:return ind 5 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2022-08-20 16.43.27 - Accepted - runtime 84ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | checked = '' 4 | for ind,i in enumerate(s): 5 | if i in checked: continue 6 | if s.count(i) == 1:return ind 7 | checked += i 8 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2022-08-20 16.43.37 - Accepted - runtime 7503ms - memory 14.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | checked = '' 4 | for ind,i in enumerate(s): 5 | if s.count(i) == 1:return ind 6 | checked += i 7 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2022-08-20 16.43.51 - Accepted - runtime 90ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | checked = '' 4 | for ind,i in enumerate(s): 5 | if i in checked: continue 6 | if s.count(i) == 1:return ind 7 | checked += i 8 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2023-01-10 22.10.30 - Accepted - runtime 62ms - memory 14.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | for i, c in collections.Counter(s).items(): 4 | if c == 1: 5 | return s.index(i) 6 | 7 | return -1 -------------------------------------------------------------------------------- /387-first-unique-character-in-a-string/2024-02-05 22.46.30 - Accepted - runtime 415ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | for i in range(len(s)): 4 | if s[i] not in s[i + 1:] + s[:i]: 5 | return i 6 | return -1 7 | -------------------------------------------------------------------------------- /389-find-the-difference/2022-10-12 19.27.01 - Accepted - runtime 58ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findTheDifference(self, s: str, t: str) -> str: 3 | return chr(sum(map(ord, t)) - sum(map(ord, s))) -------------------------------------------------------------------------------- /389-find-the-difference/2024-02-17 23.19.32 - Accepted - runtime 2ms - memory 7.9MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char findTheDifference(string s, string t) { 4 | char a = 0; 5 | for (int i = 0;i < s.size(); i++) a += t[i] - s[i]; 6 | return a + t[t.size() - 1]; 7 | } 8 | }; -------------------------------------------------------------------------------- /389-find-the-difference/2024-02-17 23.19.54 - Accepted - runtime 5ms - memory 7.9MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char findTheDifference(string s, string t) { 4 | char a = 0; 5 | for (int i = 0;i < s.size(); i++) a += t[i] - s[i]; 6 | return a + t[t.size() - 1]; 7 | } 8 | }; -------------------------------------------------------------------------------- /392-is-subsequence/2024-02-15 22.32.55 - Accepted - runtime 34ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSubsequence(self, s: str, t: str) -> bool: 3 | for i in t: 4 | if not s: 5 | return True 6 | if i == s[0]:s = s[1:] 7 | 8 | return not s -------------------------------------------------------------------------------- /392-is-subsequence/2024-02-17 23.05.21 - Accepted - runtime 0ms - memory 7.5MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSubsequence(string s, string t) { 4 | int a = 0, b = 0; 5 | while (a < s.size() && b < t.size())if (s[a] == t[b++]) a++; 6 | return a == s.size(); 7 | } 8 | }; -------------------------------------------------------------------------------- /394-decode-string/2024-04-04 09.53.47 - Accepted - runtime 37ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decodeString(self, s: str) -> str: 3 | from re import compile, sub, search 4 | regex = compile(r'(\d+)\[(\w+)\]') 5 | while search(regex, s): 6 | s = sub(regex, lambda x: int(x.group(1)) * x.group(2), s) 7 | return s -------------------------------------------------------------------------------- /401-binary-watch/2024-05-05 20.11.33 - Accepted - runtime 37ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def readBinaryWatch(self, turnedOn: int) -> List[str]: 3 | return [f'{h}:{m:02}' for h in range(12) for m in range(60) 4 | if (bin(h) + bin(m)).count('1') == turnedOn] -------------------------------------------------------------------------------- /402-remove-k-digits/2024-04-11 11.14.34 - Accepted - runtime 50ms - memory 18.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeKdigits(self, num: str, k: int) -> str: 3 | stack = [] 4 | for digit in num: 5 | while k > 0 and stack and stack[-1] > digit: 6 | k -= 1 7 | stack.pop() 8 | stack.append(digit) 9 | if k > 0: 10 | stack = stack[:-k] 11 | return "".join(stack).lstrip("0") or "0" -------------------------------------------------------------------------------- /405-convert-a-number-to-hexadecimal/2024-04-01 19.18.10 - Accepted - runtime 27ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toHex(self, num: int) -> str: 3 | return hex(num)[2:] if num >= 0 else hex(4294967296 + num)[2:] -------------------------------------------------------------------------------- /409-longest-palindrome/2024-03-31 19.47.34 - Accepted - runtime 30ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestPalindrome(self, s: str) -> int: 3 | odds = sum(v % 2 for v in Counter(s).values()) 4 | return len(s) - odds + bool(odds) -------------------------------------------------------------------------------- /41-first-missing-positive/2024-03-26 12.25.07 - Accepted - runtime 272ms - memory 35.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstMissingPositive(self, nums: List[int]) -> int: 3 | n = set(nums) 4 | res = 1 5 | while res in n:res += 1 6 | return res -------------------------------------------------------------------------------- /414-third-maximum-number/2022-07-01 22.05.17 - Accepted - runtime 123ms - memory 15.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def thirdMax(self, nums: List[int]) -> int: 3 | a = sorted(set(nums)) 4 | return a[-3] if len(a) > 2 else a[-1] -------------------------------------------------------------------------------- /415-add-strings/2022-07-03 09.19.58 - Accepted - runtime 60ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addStrings(self, num1: str, num2: str) -> str: 3 | return str(int(num1) + int(num2)) -------------------------------------------------------------------------------- /434-number-of-segments-in-a-string/2022-07-10 22.41.12 - Accepted - runtime 75ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSegments(self, s: str) -> int: 3 | return len(s.split()) -------------------------------------------------------------------------------- /441-arranging-coins/2024-04-01 15.48.23 - Accepted - runtime 427ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrangeCoins(self, n: int) -> int: 3 | r = 0 4 | while True: 5 | if n < r: 6 | return r - 1 7 | n -= r 8 | r += 1 -------------------------------------------------------------------------------- /441-arranging-coins/2024-04-01 15.48.52 - Accepted - runtime 44ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrangeCoins(self, n: int) -> int: 3 | return int((math.sqrt(8 * n + 1)-1)/2) -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/2024-03-25 17.12.30 - Accepted - runtime 268ms - memory 25.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicates(self, nums: List[int]) -> List[int]: 3 | return [k for k, v in Counter(nums).items() if v > 1] -------------------------------------------------------------------------------- /443-string-compression/2024-04-04 09.32.21 - Accepted - runtime 55ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def compress(self, chars: List[str]) -> int: 3 | res = 0 4 | r = [] 5 | for a,b in groupby(chars): 6 | b = len(list(b)) 7 | r.append(a) 8 | res += 1 9 | if b > 1: 10 | res += len(str(b)) 11 | r += list(str(b)) 12 | 13 | chars[:] = r 14 | return res -------------------------------------------------------------------------------- /448-find-all-numbers-disappeared-in-an-array/2024-04-01 19.21.36 - Accepted - runtime 258ms - memory 26.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDisappearedNumbers(self, nums: List[int]) -> List[int]: 3 | s = set(nums) 4 | return [f for f in range(1, len(nums) + 1) if f not in s] -------------------------------------------------------------------------------- /451-sort-characters-by-frequency/2024-02-07 16.15.36 - Accepted - runtime 64ms - memory 17.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def frequencySort(self, s: str) -> str: 3 | s = Counter(s) 4 | return ''.join(a*b for a,b in sorted(s.items(), key=lambda x:-x[1])) -------------------------------------------------------------------------------- /451-sort-characters-by-frequency/2024-02-07 16.15.53 - Accepted - runtime 37ms - memory 17.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def frequencySort(self, s: str) -> str: 3 | return ''.join(a*b for a,b in sorted(Counter(s).items(), key=lambda x:-x[1])) -------------------------------------------------------------------------------- /452-minimum-number-of-arrows-to-burst-balloons/2024-03-18 16.29.28 - Accepted - runtime 999ms - memory 62.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMinArrowShots(self, points: List[List[int]]) -> int: 3 | points.sort(key=lambda x: x[1]) 4 | res, b = 1, points[0][1] 5 | for s, e in points: 6 | if b < s: 7 | b = e 8 | res += 1 9 | 10 | return res -------------------------------------------------------------------------------- /455-assign-cookies/2022-07-03 20.14.52 - Accepted - runtime 252ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findContentChildren(self, g: List[int], s: List[int]) -> int: 3 | r = 0 4 | heapq.heapify(s) 5 | heapq.heapify(g) 6 | while s and g: 7 | a = heapq.heappop(g) 8 | while s: 9 | if a <= heapq.heappop(s): 10 | r += 1 11 | break 12 | 13 | return r 14 | -------------------------------------------------------------------------------- /459-repeated-substring-pattern/2024-03-31 20.04.41 - Accepted - runtime 40ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedSubstringPattern(self, s: str) -> bool: 3 | return (s + s)[1:-1].find(s) != -1 4 | -------------------------------------------------------------------------------- /46-permutations/2024-04-25 22.57.18 - Accepted - runtime 36ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def permute(self, nums: List[int]) -> List[List[int]]: 3 | return itertools.permutations(nums) -------------------------------------------------------------------------------- /461-hamming-distance/2024-04-01 19.30.11 - Accepted - runtime 28ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hammingDistance(self, x: int, y: int) -> int: 3 | if x > y: x, y = y, x 4 | x, y = map(lambda x: bin(x)[2:], (x, y)) 5 | x = x.zfill(l := len(y)) 6 | return sum(x[f] != y[f] for f in range(l)) -------------------------------------------------------------------------------- /476-number-complement/2023-05-13 10.07.07 - Accepted - runtime 39ms - memory 16.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findComplement(self, num: int) -> int: 3 | return int(f'{num:b}'.translate(str.maketrans({'1':'0', '0':'1'})), 2) -------------------------------------------------------------------------------- /482-license-key-formatting/2024-03-31 20.09.43 - Accepted - runtime 42ms - memory 19.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def licenseKeyFormatting(self, s: str, k: int) -> str: 3 | s = ''.join(f.upper() for f in s if f.isalnum())[::-1] 4 | return '-'.join(s[f: f + k] for f in range(0, len(s), k))[::-1] -------------------------------------------------------------------------------- /485-max-consecutive-ones/2024-04-01 19.36.48 - Accepted - runtime 268ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMaxConsecutiveOnes(self, nums: List[int]) -> int: 3 | cur = res = 1 4 | for i in range(1, len(nums)): 5 | if nums[i] and nums[i - 1]: 6 | cur += 1 7 | else: 8 | res = max(res, cur) 9 | cur = 1 10 | 11 | return max(res, cur) if any(nums) else 0 -------------------------------------------------------------------------------- /49-group-anagrams/2023-01-28 18.50.16 - Accepted - runtime 106ms - memory 17.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | d = {} 4 | for i in strs: 5 | t = ''.join(sorted(i)) 6 | if t in d: 7 | d[t].append(i) 8 | else: 9 | d[t] = [i] 10 | 11 | return d.values() -------------------------------------------------------------------------------- /49-group-anagrams/2024-02-06 13.40.41 - Accepted - runtime 136ms - memory 21MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | d = {} 4 | for i in strs: 5 | key = str(sorted(Counter(i).items())) 6 | d[key] = d.get(key, []) + [i] 7 | 8 | 9 | return d.values() -------------------------------------------------------------------------------- /49-group-anagrams/2024-02-06 13.42.17 - Accepted - runtime 80ms - memory 20.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupAnagrams(self, strs: List[str]) -> List[List[str]]: 3 | d = defaultdict(list) 4 | for i in strs: 5 | key = ''.join(sorted(i)) 6 | d[key].append(i) 7 | 8 | 9 | return d.values() -------------------------------------------------------------------------------- /5-longest-palindromic-substring/2023-03-03 14.57.53 - Accepted - runtime 4224ms - memory 37.3MB.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun longestPalindrome(s: String): String { 3 | 4 | var temp = "" 5 | 6 | for (i in s.length downTo 0) { 7 | for (j in 0 .. s.length - i) { 8 | temp = s.substring(j, j + i) 9 | if (temp.reversed() == temp) return temp 10 | } 11 | } 12 | 13 | return s.substring(0, 1) 14 | } 15 | } -------------------------------------------------------------------------------- /50-powx-n/2022-07-06 13.14.25 - Accepted - runtime 53ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def myPow(self, x: float, n: int) -> float: 3 | return math.pow(x, n) -------------------------------------------------------------------------------- /500-keyboard-row/2022-07-21 17.04.16 - Accepted - runtime 28ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findWords(self, words: List[str]) -> List[str]: 3 | l = ['qwertyuiop','asdfghjkl','zxcvbnm'] 4 | t = [] 5 | for word in words: 6 | if any(all(char in f for char in word.lower()) for f in l): 7 | t += word, 8 | 9 | return t -------------------------------------------------------------------------------- /506-relative-ranks/2024-05-08 10.23.23 - Accepted - runtime 60ms - memory 17.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findRelativeRanks(self, score: List[int]) -> List[str]: 3 | d = {} 4 | for ind, i in enumerate(sorted(score, reverse=True), 1): 5 | d[i] = ind 6 | return [ 7 | {1: 'Gold Medal', 2: 'Silver Medal', 3: 'Bronze Medal'}.get(d[f], str(d[f])) 8 | for f in score] -------------------------------------------------------------------------------- /515-find-largest-value-in-each-tree-row/2024-01-22 00.13.33 - Accepted - runtime 42ms - memory 18.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestValues(self, root: Optional[TreeNode]) -> List[int]: 3 | maxes = [] 4 | level = [root] 5 | while any(level): 6 | maxes.append(max(n.val for n in level)) 7 | level = [kid for node in level for kid in (node.left, node.right) if kid] 8 | 9 | return maxes -------------------------------------------------------------------------------- /520-detect-capital/2022-07-21 17.06.47 - Accepted - runtime 48ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCapitalUse(self, word: str) -> bool: 3 | return word.isupper() or word.istitle() or word.islower() -------------------------------------------------------------------------------- /520-detect-capital/2023-01-05 20.48.46 - Accepted - runtime 67ms - memory 13.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCapitalUse(self, word: str) -> bool: 3 | return word.islower() or word.isupper() or word.istitle() -------------------------------------------------------------------------------- /520-detect-capital/2023-01-05 20.50.30 - Accepted - runtime 65ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCapitalUse(self, word: str) -> bool: 3 | u = l = 0 4 | for i in word: 5 | if i.islower(): 6 | l += 1 7 | else: 8 | u += 1 9 | 10 | return not l or not u or u == 1 and word[0].isupper() -------------------------------------------------------------------------------- /521-longest-uncommon-subsequence-i/2024-03-31 20.55.28 - Accepted - runtime 22ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findLUSlength(self, a: str, b: str) -> int: 3 | return -1 if a == b else max(len(a), len(b)) -------------------------------------------------------------------------------- /525-contiguous-array/2024-03-16 14.29.53 - Accepted - runtime 609ms - memory 22.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findMaxLength(self, nums: List[int]) -> int: 3 | res = c = 0 4 | d = {0: 0} 5 | for ind, i in enumerate(nums, 1): 6 | if i == 0:c -= 1 7 | else:c += 1 8 | if c in d: 9 | res = max(res, ind - d[c]) 10 | else: 11 | d[c] = ind 12 | return res -------------------------------------------------------------------------------- /53-maximum-subarray/2022-06-23 16.36.47 - Accepted - runtime 1257ms - memory 27.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSubArray(self, nums: List[int]) -> int: 3 | current = res = nums[0] 4 | for i in range(1, len(nums)): 5 | current = max(current + nums[i], nums[i]) 6 | res = max(current, res) 7 | return res -------------------------------------------------------------------------------- /54-spiral-matrix/2023-01-28 19.23.56 - Accepted - runtime 32ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def spiralOrder(self, matrix: List[List[int]]) -> List[int]: 3 | return matrix and list(matrix.pop(0)) + self.spiralOrder(list(zip(*matrix))[::-1]) -------------------------------------------------------------------------------- /54-spiral-matrix/2023-01-31 19.06.09 - Accepted - runtime 25ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def spiralOrder(self, matrix: List[List[int]]) -> List[int]: 3 | return matrix and list(matrix.pop(0)) + self.spiralOrder(list(zip(*matrix))[::-1]) -------------------------------------------------------------------------------- /54-spiral-matrix/2023-01-31 19.10.29 - Accepted - runtime 37ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def spiralOrder(self, matrix: List[List[int]]) -> List[int]: 3 | res = [] 4 | while matrix: 5 | res.extend(matrix.pop(0)) 6 | matrix = list(zip(*matrix))[::-1] 7 | 8 | return res -------------------------------------------------------------------------------- /54-spiral-matrix/2023-05-09 12.38.05 - Accepted - runtime 32ms - memory 16.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def spiralOrder(self, matrix: List[List[int]]) -> List[int]: 3 | res = [] 4 | while matrix: 5 | res.extend(matrix[0]) 6 | matrix = list(zip(*matrix[1:]))[::-1] 7 | 8 | return res 9 | -------------------------------------------------------------------------------- /541-reverse-string-ii/2024-03-31 23.45.22 - Accepted - runtime 44ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseStr(self, s: str, k: int) -> str: 3 | s = list(s) 4 | for i in range(0, len(s), 2 * k):s[i:i + k] = s[i:i + k][::-1] 5 | return ''.join(s) -------------------------------------------------------------------------------- /551-student-attendance-record-i/2024-03-31 23.50.21 - Accepted - runtime 32ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkRecord(self, s: str) -> bool: 3 | return s.count('A') < 2 and 'LLL' not in s -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/2023-01-27 12.53.59 - Accepted - runtime 43ms - memory 14.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseWords(self, s: str) -> str: 3 | return ' '.join(f[::-1] for f in s.split()) -------------------------------------------------------------------------------- /561-array-partition/2023-01-27 13.06.41 - Accepted - runtime 341ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayPairSum(self, nums: List[int]) -> int: 3 | return sum(sorted(nums)[::2]) -------------------------------------------------------------------------------- /58-length-of-last-word/2022-06-15 21.46.06 - Accepted - runtime 36ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLastWord(self, s: str) -> int: 3 | return len(s.split()[-1]) -------------------------------------------------------------------------------- /58-length-of-last-word/2024-02-17 13.21.12 - Accepted - runtime 0ms - memory 7.6MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLastWord(string s) { 4 | int res = 0, high = s.size() - 1; 5 | while (high >= 0 && s[high] == ' ')high--; 6 | while (high >= 0 && s[high--] != ' ')res++; 7 | return res; 8 | } 9 | }; -------------------------------------------------------------------------------- /58-length-of-last-word/2024-04-01 15.53.26 - Accepted - runtime 32ms - memory 16.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLastWord(self, s: str) -> int: 3 | return len(s.split()[-1]) -------------------------------------------------------------------------------- /62-unique-paths/2022-08-01 12.55.38 - Accepted - runtime 55ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniquePaths(self, m: int, n: int) -> int: 3 | return factorial(m+n-2) // factorial(m-1) // factorial(n-1) -------------------------------------------------------------------------------- /62-unique-paths/2022-08-01 12.55.49 - Accepted - runtime 68ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniquePaths(self, m: int, n: int) -> int: 3 | return factorial(m+n-2) // factorial(m-1) // factorial(n-1) -------------------------------------------------------------------------------- /621-task-scheduler/2024-03-19 12.48.51 - Accepted - runtime 374ms - memory 17MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def leastInterval(self, tasks: List[str], n: int) -> int: 3 | c = defaultdict(int) 4 | count = 0 5 | for i in tasks: 6 | c[i] += 1 7 | count = max(count, c[i]) 8 | res = (count - 1) * (n + 1) 9 | for i in c: 10 | if c[i] == count: res += 1 11 | 12 | return max(res, len(tasks)) 13 | -------------------------------------------------------------------------------- /630-course-schedule-iii/2022-06-23 13.07.08 - Accepted - runtime 1542ms - memory 20.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def scheduleCourse(self, courses: List[List[int]]) -> int: 3 | courses.sort(key=lambda c: c[1]) 4 | A, curr = [], 0 5 | for dur, ld in courses: 6 | heapq.heappush(A,-dur) 7 | curr += dur 8 | if curr > ld: curr += heapq.heappop(A) 9 | return len(A) -------------------------------------------------------------------------------- /630-course-schedule-iii/2022-06-23 13.07.18 - Accepted - runtime 963ms - memory 19.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def scheduleCourse(self, courses: List[List[int]]) -> int: 3 | courses.sort(key=lambda c: c[1]) 4 | A, curr = [], 0 5 | for dur, ld in courses: 6 | heapq.heappush(A,-dur) 7 | curr += dur 8 | if curr > ld: curr += heapq.heappop(A) 9 | return len(A) -------------------------------------------------------------------------------- /630-course-schedule-iii/2022-06-23 14.46.58 - Accepted - runtime 955ms - memory 20.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def scheduleCourse(self, courses: List[List[int]]) -> int: 3 | valid_courses, curr = [], 0 4 | courses.sort(key=lambda x:x[1]) 5 | for dur, ld in courses: 6 | heapq.heappush(valid_courses, -dur) 7 | curr += dur 8 | if curr > ld: curr += heapq.heappop(valid_courses) 9 | 10 | return len(valid_courses) 11 | -------------------------------------------------------------------------------- /633-sum-of-square-numbers/2024-04-15 15.14.41 - Accepted - runtime 127ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def judgeSquareSum(self, c: int) -> bool: 3 | for i in range(int(c ** .5) + 1): 4 | j = (c - i * i) ** .5 5 | if j % 1 == 0: 6 | return True 7 | 8 | return False -------------------------------------------------------------------------------- /64-minimum-path-sum/2023-03-27 15.38.59 - Accepted - runtime 96ms - memory 15.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minPathSum(self, grid: List[List[int]]) -> int: 3 | for i in range(1, h := len(grid)):grid[i][0] += grid[i - 1][0] 4 | for i in range(1, w := len(grid[0])):grid[0][i] += grid[0][i - 1] 5 | for i in range(1, h): 6 | for j in range(1, w): 7 | grid[i][j] += min(grid[i - 1][j], grid[i][j - 1]) 8 | 9 | return grid[h - 1][w - 1] -------------------------------------------------------------------------------- /645-set-mismatch/2022-10-23 15.13.18 - Accepted - runtime 526ms - memory 15.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findErrorNums(self, nums: List[int]) -> List[int]: 3 | l = len(nums) 4 | a = l * (l + 1) // 2 5 | d = set() 6 | s = 0 7 | for i in nums: 8 | if i in d: 9 | k = i 10 | else: 11 | d.add(i) 12 | s += i 13 | 14 | return k, a - s 15 | -------------------------------------------------------------------------------- /645-set-mismatch/2022-10-23 15.18.00 - Accepted - runtime 501ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findErrorNums(self, nums: List[int]) -> List[int]: 3 | d = df = 0 4 | for ind, i in enumerate(nums, start = 1): 5 | d += ind - i 6 | df += ind * ind - i * i 7 | 8 | s = df // d 9 | return (s - d) // 2, (s + d) // 2 10 | -------------------------------------------------------------------------------- /645-set-mismatch/2022-10-23 15.18.20 - Accepted - runtime 463ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findErrorNums(self, nums: List[int]) -> List[int]: 3 | d = df = 0 4 | for ind, i in enumerate(nums, start = 1): 5 | d += ind - i 6 | df += ind * ind - i * i 7 | 8 | s = df // d 9 | return (s - d) // 2, (s + d) // 2 -------------------------------------------------------------------------------- /647-palindromic-substrings/2024-02-10 13.34.43 - Accepted - runtime 415ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSubstrings(self, s: str) -> int: 3 | c = 0 4 | for i in range(len(s)): 5 | for j in range(i, len(s)): 6 | t = s[i: j + 1] 7 | c += t == t[::-1] 8 | 9 | return c 10 | -------------------------------------------------------------------------------- /65-valid-number/2024-04-05 10.55.01 - Accepted - runtime 38ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isNumber(self, s: str) -> bool: 3 | try: 4 | float(s) 5 | return s.lower() not in ('inf', '-inf', '+inf', 'infinity', '-infinity', '+infinity', 'nan', '-nan') 6 | except: 7 | return False -------------------------------------------------------------------------------- /657-robot-return-to-origin/2024-04-01 00.31.58 - Accepted - runtime 102ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def judgeCircle(self, moves: str) -> bool: 3 | x = y = 0 4 | for i in moves: 5 | x += [[0, -1][i == 'L'], 1][i == 'R'] 6 | y += [[0, -1][i == 'D'], 1][i == 'U'] 7 | 8 | return not x and not y -------------------------------------------------------------------------------- /66-plus-one/2022-06-15 23.39.23 - Accepted - runtime 72ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def plusOne(self, digits: List[int]) -> List[int]: 3 | a = int(''.join(str(f)for f in digits)) + 1 4 | return list(str(a)) -------------------------------------------------------------------------------- /665-non-decreasing-array/2022-06-25 22.48.17 - Accepted - runtime 193ms - memory 15.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkPossibility(self, A): 3 | p, n = -1, len(A) 4 | for i in range(n - 1): 5 | if A[i] > A[i+1]: 6 | if p != -1: return False 7 | p = i 8 | 9 | return p in [-1, 0, n-2] or A[p-1] <= A[p+1] or A[p] <= A[p+2] -------------------------------------------------------------------------------- /67-add-binary/2022-06-20 19.33.28 - Accepted - runtime 36ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addBinary(self, a: str, b: str) -> str: 3 | return f'{int(a,2) + int(b,2):b}' -------------------------------------------------------------------------------- /678-valid-parenthesis-string/2024-04-07 14.11.33 - Accepted - runtime 39ms - memory 16.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkValidString(self, s: str) -> bool: 3 | a = b = 0 4 | for i in s: 5 | a = a - 1 if i == ')' else a + 1 6 | b = b + 1 if i == '(' else max(b - 1, 0) 7 | if a < 0: return False 8 | 9 | 10 | return b == 0 -------------------------------------------------------------------------------- /686-repeated-string-match/2024-03-12 16.07.58 - Accepted - runtime 41ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedStringMatch(self, a: str, b: str) -> int: 3 | t = ceil(len(b) / len(a)) 4 | return t * (b in a * t) or (t + 1) * (b in a * (t + 1)) or -1 -------------------------------------------------------------------------------- /69-sqrtx/2022-06-20 19.34.51 - Accepted - runtime 59ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mySqrt(self, x: int) -> int: 3 | return int(__import__('math').sqrt(x)) -------------------------------------------------------------------------------- /696-count-binary-substrings/2024-04-08 17.06.30 - Accepted - runtime 99ms - memory 18.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countBinarySubstrings(self, s: str) -> int: 3 | s = list(map(len, s.replace('10', '1 0').replace('01', '1 0').split())) 4 | return sum(min(a, b) for a, b in zip(s, s[1:])) -------------------------------------------------------------------------------- /7-reverse-integer/2022-06-29 10.37.22 - Accepted - runtime 56ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverse(self, x: int) -> int: 3 | if x < 0: 4 | num = int(str(x)[1:][::-1]) 5 | if num > 2147483648: 6 | return 0 7 | return -num 8 | else: 9 | num = int(str(x)[::-1]) 10 | if num > 2147483648: 11 | return 0 12 | return num -------------------------------------------------------------------------------- /7-reverse-integer/2023-01-06 21.21.32 - Accepted - runtime 48ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | _min = -(2 ** 31) 2 | _max = abs(_min) - 1 3 | class Solution: 4 | def reverse(self, x: int) -> int: 5 | neg = x < 0 6 | x = int(str(abs(x))[::-1]) 7 | if neg: 8 | x = -x 9 | return x if _min <= x <= _max else 0 -------------------------------------------------------------------------------- /70-climbing-stairs/2022-06-23 16.51.25 - Accepted - runtime 38ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | stairs = [0] * 45 3 | def climbStairs(self, n: int) -> int: 4 | arr = [0] * (n+1) 5 | for i in range(n+1): 6 | if i < 3: 7 | arr[i] = i 8 | else: 9 | arr[i] = arr[i-1] + arr[i-2] 10 | 11 | return arr[-1] -------------------------------------------------------------------------------- /71-simplify-path/2023-04-13 23.23.56 - Accepted - runtime 29ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def simplifyPath(self, path: str) -> str: 3 | curr = [] 4 | for i in path.split('/'): 5 | if i: 6 | if i == '.':pass 7 | elif i == '..': 8 | if curr:curr.pop() 9 | else:curr.append(i) 10 | 11 | return '/' + '/'.join(curr) -------------------------------------------------------------------------------- /728-self-dividing-numbers/2022-09-26 14.17.53 - Accepted - runtime 121ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def selfDividingNumbers(self, left: int, right: int) -> List[int]: 3 | return [f for f in range(left, right + 1)if '0'not in str(f) and all(f%int(i) == 0 for i in str(f))] -------------------------------------------------------------------------------- /739-daily-temperatures/2024-01-31 21.29.56 - Accepted - runtime 898ms - memory 32.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def dailyTemperatures(self, te: List[int]) -> List[int]: 3 | r = [0] * len(te) 4 | stack = [] 5 | for i, t in enumerate(te): 6 | while stack and stack[-1][1] < t: 7 | ind, temp = stack.pop() 8 | r[ind] = i - ind 9 | stack.append((i, t)) 10 | 11 | return r -------------------------------------------------------------------------------- /742-to-lower-case/2022-09-20 14.25.24 - Accepted - runtime 61ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toLowerCase(self, s: str) -> str: 3 | return s.lower() -------------------------------------------------------------------------------- /747-min-cost-climbing-stairs/2022-07-10 15.01.01 - Accepted - runtime 108ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostClimbingStairs(self, cost: List[int]) -> int: 3 | a, b = cost[0], cost[1] 4 | c = 0 5 | for i in range(2, len(cost)): 6 | c = cost[i] + min(a, b) 7 | a, b = b, c 8 | return min(a,b) -------------------------------------------------------------------------------- /775-n-ary-tree-preorder-traversal/2022-07-07 11.52.59 - Accepted - runtime 70ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def dfs(self, root, l): 3 | if not root:return 4 | if root:l.append(root.val) 5 | for child in root.children: 6 | self.dfs(child,l) 7 | 8 | 9 | def preorder(self, root: 'Node') -> List[int]: 10 | res = [] 11 | self.dfs(root, res) 12 | 13 | return res -------------------------------------------------------------------------------- /775-n-ary-tree-preorder-traversal/2022-07-07 11.54.29 - Accepted - runtime 80ms - memory 16.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def preorder(self, root: 'Node') -> List[int]: 3 | res = [] 4 | stack = [root] 5 | while stack: 6 | node = stack.pop() 7 | if node: 8 | res.append(node.val) 9 | stack.extend(node.children[::-1]) 10 | 11 | return res -------------------------------------------------------------------------------- /775-n-ary-tree-preorder-traversal/2022-07-07 11.57.42 - Accepted - runtime 60ms - memory 16MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def preorder(self, root: 'Node') -> List[int]: 3 | res = [] 4 | stack = [root] 5 | while stack: 6 | node = stack.pop() 7 | if node: 8 | res.append(node.val) 9 | stack.extend(reversed(node.children)) 10 | 11 | return res -------------------------------------------------------------------------------- /775-n-ary-tree-preorder-traversal/2022-07-07 11.57.57 - Accepted - runtime 99ms - memory 16MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def preorder(self, root: 'Node') -> List[int]: 3 | res = [] 4 | stack = [root] 5 | while stack: 6 | node = stack.pop() 7 | if node: 8 | res.append(node.val) 9 | stack.extend(reversed(node.children)) 10 | 11 | return res -------------------------------------------------------------------------------- /775-n-ary-tree-preorder-traversal/2022-07-07 11.58.14 - Accepted - runtime 68ms - memory 16MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def preorder(self, root: 'Node') -> List[int]: 3 | res = [] 4 | stack = [root] 5 | while stack: 6 | node = stack.pop() 7 | if node: 8 | res.append(node.val) 9 | stack.extend(reversed(node.children)) 10 | 11 | return res -------------------------------------------------------------------------------- /782-jewels-and-stones/2022-08-01 16.26.49 - Accepted - runtime 55ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numJewelsInStones(self, jewels: str, stones: str) -> int: 3 | return sum(f in jewels for f in stones) -------------------------------------------------------------------------------- /792-binary-search/2022-07-21 16.44.05 - Accepted - runtime 416ms - memory 15.6MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def search(self, nums: List[int], target: int) -> int: 3 | low = 0 4 | high = len(nums) - 1 5 | while low <= high: 6 | mid = low + (high - low) // 2 7 | if nums[mid] == target:return mid 8 | elif nums[mid] > target: 9 | high = mid - 1 10 | else: 11 | low = mid + 1 12 | 13 | return -1 -------------------------------------------------------------------------------- /792-binary-search/2023-04-01 23.42.27 - Accepted - runtime 238ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def search(self, nums: List[int], target: int) -> int: 3 | lo, hi = 0, len(nums) 4 | 5 | while lo < hi: 6 | mid = (lo + hi) // 2 7 | if nums[mid] == target: return mid 8 | elif nums[mid] > target: hi = mid 9 | else: lo = mid + 1 10 | 11 | return -1 -------------------------------------------------------------------------------- /8-string-to-integer-atoi/2024-03-31 18.54.54 - Accepted - runtime 40ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | from re import search 2 | class Solution: 3 | def myAtoi(self, s: str) -> int: 4 | m = search(r'^([\-\+]?\d+)', s.strip()) 5 | n = int(m.group(1)) if m else 0 6 | return min(max(n, -2147483648), 2147483647) 7 | -------------------------------------------------------------------------------- /802-k-th-smallest-prime-fraction/2024-05-10 09.34.39 - Accepted - runtime 2437ms - memory 121.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]: 3 | t = len(arr) 4 | l = [] 5 | for i in range(t): 6 | for j in range(t - 1, 0, -1): 7 | heapq.heappush(l, (arr[i]/arr[j], arr[i], arr[j])) 8 | 9 | for i in range(k): 10 | _, a, b = heapq.heappop(l) 11 | 12 | return a, b -------------------------------------------------------------------------------- /807-custom-sort-string/2024-03-11 12.29.55 - Accepted - runtime 46ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def customSortString(self, order: str, s: str) -> str: 3 | return ''.join(sorted(s, key=lambda x:order.find(x))) 4 | -------------------------------------------------------------------------------- /807-custom-sort-string/2024-03-11 12.30.10 - Accepted - runtime 30ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def customSortString(self, order: str, s: str) -> str: 3 | return ''.join(sorted(s, key=lambda x:order.find(x))) 4 | -------------------------------------------------------------------------------- /812-rotate-string/2024-04-05 19.29.38 - Accepted - runtime 44ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotateString(self, s: str, goal: str) -> bool: 3 | return any(s[f:] + s[:f] == goal for f in range(len(s))) -------------------------------------------------------------------------------- /812-rotate-string/2024-04-05 19.29.53 - Accepted - runtime 45ms - memory 16.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotateString(self, s: str, goal: str) -> bool: 3 | return any(s[f:] + s[:f] == goal for f in range(len(s))) -------------------------------------------------------------------------------- /822-unique-morse-code-words/2022-09-20 14.28.25 - Accepted - runtime 76ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueMorseRepresentations(self, words: list[str]) -> int: 3 | morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] 4 | return len(set(''.join(morse[ord(f) - 97]for f in word)for word in words)) -------------------------------------------------------------------------------- /837-most-common-word/2024-04-05 19.36.42 - Accepted - runtime 43ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: 3 | b = set(banned) 4 | c = Counter(filter(lambda x: x not in b, re.findall(r'\w+', paragraph.lower()))) 5 | return c.most_common(1)[0][0] -------------------------------------------------------------------------------- /841-shortest-distance-to-a-character/2022-09-26 17.43.01 - Accepted - runtime 167ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shortestToChar(self, s: str, c: str) -> List[int]: 3 | indices = [ind for ind,f in enumerate(s)if f == c] 4 | return [min(abs(ind - i)for i in indices)for ind,f in enumerate(s)] -------------------------------------------------------------------------------- /851-goat-latin/2024-04-05 19.46.35 - Accepted - runtime 42ms - memory 16.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toGoatLatin(self, sentence: str) -> str: 3 | return ' '.join(f[f[0] not in 'aeiouAEIOU':] + f[:f[0] not in 'aeiouAEIOU'] + 'ma' + 'a' * ind for ind, f in enumerate(sentence.split(), 1)) -------------------------------------------------------------------------------- /88-merge-sorted-array/2022-06-23 21.43.40 - Accepted - runtime 41ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: 3 | """ 4 | Do not return anything, modify nums1 in-place instead. 5 | """ 6 | for i in range(n): 7 | nums1.pop() 8 | nums1.extend(nums2) 9 | nums1.sort() 10 | -------------------------------------------------------------------------------- /9-palindrome-number/2022-04-24 19.57.39 - Accepted - runtime 104ms - memory 13.9MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | return str(x) == str(x)[::-1] -------------------------------------------------------------------------------- /9-palindrome-number/2023-03-05 12.50.17 - Accepted - runtime 74ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x: int) -> bool: 3 | return str(x) == str(x)[::-1] -------------------------------------------------------------------------------- /9-palindrome-number/2024-02-16 14.56.24 - Accepted - runtime 17ms - memory 10.6MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPalindrome(int x) { 4 | string s = to_string(x); 5 | string t = s; 6 | reverse(t.begin(), t.end()); 7 | return s == t; 8 | } 9 | }; -------------------------------------------------------------------------------- /907-koko-eating-bananas/2023-03-08 10.32.09 - Accepted - runtime 829ms - memory 15.5MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minEatingSpeed(self, piles: List[int], h: int) -> int: 3 | lo, hi = 1, max(piles) * h 4 | while lo < hi: 5 | mid = (lo + hi) // 2 6 | if sum(math.ceil(f / mid) for f in piles) <= h: 7 | hi = mid 8 | else: 9 | lo = mid + 1 10 | 11 | return lo -------------------------------------------------------------------------------- /907-koko-eating-bananas/2023-03-08 10.32.52 - Accepted - runtime 466ms - memory 15.4MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minEatingSpeed(self, piles: List[int], h: int) -> int: 3 | lo, hi = 1, max(piles) 4 | while lo < hi: 5 | mid = (lo + hi) // 2 6 | if sum(math.ceil(f / mid) for f in piles) <= h: 7 | hi = mid 8 | else: 9 | lo = mid + 1 10 | 11 | return lo -------------------------------------------------------------------------------- /908-middle-of-the-linked-list/2022-09-26 15.16.05 - Accepted - runtime 59ms - memory 13.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]: 3 | slow = fast = head 4 | while fast and fast.next: 5 | slow = slow.next 6 | fast = fast.next.next 7 | 8 | return slow -------------------------------------------------------------------------------- /917-boats-to-save-people/2023-04-03 21.20.24 - Accepted - runtime 451ms - memory 20.8MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numRescueBoats(self, people: List[int], limit: int) -> int: 3 | people.sort() 4 | lo, hi = 0, len(people) - 1 5 | res = 0 6 | while lo <= hi: 7 | res += 1 8 | if people[hi] + people[lo] <= limit: 9 | lo += 1 10 | hi -= 1 11 | else: 12 | hi -= 1 13 | 14 | return res -------------------------------------------------------------------------------- /917-boats-to-save-people/2024-05-04 10.04.41 - Accepted - runtime 358ms - memory 23.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numRescueBoats(self, people: List[int], limit: int) -> int: 3 | people.sort(reverse=True) 4 | l, r = 0, len(people) - 1 5 | while l <= r: 6 | if people[l] + people[r] <= limit: r -= 1 7 | l += 1 8 | return l -------------------------------------------------------------------------------- /926-find-and-replace-pattern/2022-07-29 20.00.13 - Accepted - runtime 67ms - memory 14MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findAndReplacePattern(self, w: List[str], p: str) -> List[str]: 3 | return [f for f in w if all(f.index(a)==p.index(b) for a,b in zip(f,p))] -------------------------------------------------------------------------------- /932-monotonic-array/2024-02-20 19.40.30 - Accepted - runtime 751ms - memory 31.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isMonotonic(self, nums: List[int]) -> bool: 3 | l = sorted(nums) 4 | return nums == l or nums[::-1] == l 5 | -------------------------------------------------------------------------------- /932-monotonic-array/2024-02-20 19.48.57 - Accepted - runtime 109ms - memory 98.9MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isMonotonic(vector& nums) { 4 | bool inc = true, dec = true; 5 | for (int i = 1; i < nums.size(); ++i){ 6 | inc &= nums[i - 1] <= nums[i]; 7 | dec &= nums[i - 1] >= nums[i]; 8 | } 9 | return inc || dec; 10 | } 11 | }; -------------------------------------------------------------------------------- /941-sort-array-by-parity/2024-02-17 23.57.04 - Accepted - runtime 63ms - memory 17.3MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortArrayByParity(self, nums: List[int]) -> List[int]: 3 | return sorted(nums, key=lambda x: x%2) -------------------------------------------------------------------------------- /941-sort-array-by-parity/2024-02-18 00.01.22 - Accepted - runtime 7ms - memory 18.6MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortArrayByParity(vector& nums) { 4 | int low = 0, high = nums.size() - 1; 5 | while (low < high){ 6 | while (low < high && nums[low] % 2 == 0) low++; 7 | while (low < high && nums[high] % 2)high--; 8 | swap(nums[low], nums[high]); 9 | } 10 | return nums; 11 | } 12 | }; -------------------------------------------------------------------------------- /941-sort-array-by-parity/2024-02-18 00.04.53 - Accepted - runtime 7ms - memory 19MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortArrayByParity(vector& nums) { 4 | int even=-1; 5 | for(int& x: nums) if(x % 2 == 0) swap(nums[++even], x); 6 | return nums; 7 | } 8 | }; -------------------------------------------------------------------------------- /941-sort-array-by-parity/2024-02-18 00.05.19 - Accepted - runtime 10ms - memory 18.9MB.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortArrayByParity(vector& nums) { 4 | int even=-1; 5 | for(int& x: nums) if(!(x&1)) swap(nums[++even], x); 6 | return nums; 7 | } 8 | }; -------------------------------------------------------------------------------- /948-sort-an-array/2023-03-01 19.43.28 - Accepted - runtime 690ms - memory 22.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortArray(self, nums: List[int]) -> List[int]: 3 | return sorted(nums) -------------------------------------------------------------------------------- /961-long-pressed-name/2024-04-06 12.16.00 - Accepted - runtime 46ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isLongPressedName(self, name: str, typed: str) -> bool: 3 | a,b = map(lambda x: list((A, len(list(B))) for A,B in groupby(x)), (name, typed)) 4 | if len(a) != len(b): 5 | return False 6 | for (i, j), (I, J) in zip(a, b): 7 | if i != I or j > J: 8 | return False 9 | return True -------------------------------------------------------------------------------- /962-flip-string-to-monotone-increasing/2024-04-06 12.25.38 - Accepted - runtime 123ms - memory 17.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minFlipsMonoIncr(self, s: str) -> int: 3 | a = b = 0 4 | for i in s: 5 | if i == '1': a += 1 6 | else: b += 1 7 | b = min(a, b) 8 | 9 | return b -------------------------------------------------------------------------------- /966-binary-subarrays-with-sum/2024-03-14 12.11.05 - Accepted - runtime 237ms - memory 20.2MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSubarraysWithSum(self, nums: List[int], goal: int) -> int: 3 | c = collections.Counter({0: 1}) 4 | psum = res = 0 5 | for i in nums: 6 | psum += i 7 | res += c[psum - goal] 8 | c[psum] += 1 9 | return res -------------------------------------------------------------------------------- /981-delete-columns-to-make-sorted/2023-01-06 20.36.30 - Accepted - runtime 90ms - memory 14.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minDeletionSize(self, strs: List[str]) -> int: 3 | return sum(f != tuple(sorted(f)) for f in zip(*strs)) -------------------------------------------------------------------------------- /983-validate-stack-sequences/2023-04-13 11.17.47 - Accepted - runtime 71ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: 3 | stack = [] 4 | i = 0 5 | for n in pushed: 6 | stack.append(n) 7 | while stack and stack[-1] == popped[i]: 8 | stack.pop() 9 | i += 1 10 | return not stack -------------------------------------------------------------------------------- /987-reveal-cards-in-increasing-order/2024-04-10 09.44.24 - Accepted - runtime 39ms - memory 16.7MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deckRevealedIncreasing(self, deck: List[int]) -> List[int]: 3 | d = deque() 4 | for x in sorted(deck)[::-1]: 5 | d.rotate() 6 | d.appendleft(x) 7 | return d -------------------------------------------------------------------------------- /990-verifying-an-alien-dictionary/2023-02-02 17.45.03 - Accepted - runtime 44ms - memory 14.1MB.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAlienSorted(self, words: List[str], order: str) -> bool: 3 | return words == sorted(words, key=lambda x:list(order.index(f) for f in x)) --------------------------------------------------------------------------------