├── .gitignore ├── README.md ├── src ├── 0001-Two-Sum │ ├── two_sum.c │ ├── two_sum.cpp │ ├── two_sum.go │ ├── two_sum.java │ ├── two_sum.js │ └── two_sum.py ├── 0002-Add-Two-Numbers │ ├── Add_Two_Numbers.cpp │ ├── Add_Two_Numbers.go │ └── Add_Two_Numbers.py ├── 0003-Longest-Substring-Without-Repeating-Characters │ ├── 0003.cpp │ ├── 0003.go │ └── 0003.py ├── 0004-Median-of-Two-Sorted-Arrays │ ├── 0004.cpp │ └── 0004.py ├── 0005-Longest-Palindromic-Substring │ ├── 0005.cpp │ ├── 0005.go │ └── 0005.py ├── 0006-ZigZag-Conversion │ ├── 0006.cpp │ ├── 0006.go │ └── 0006.py ├── 0007-Reverse-Integer │ ├── 0007.cpp │ ├── 0007.go │ └── 0007.py ├── 0008-String-to-Integer-(atoi) │ ├── 0008.cpp │ ├── 0008.go │ └── 0008.py ├── 0009-Palindrome-Number │ ├── 0009.cpp │ ├── 0009.go │ ├── 0009.js │ └── 0009.py ├── 0010-Regular-Expression-Matching │ ├── 0010.cpp │ ├── 0010.go │ └── 0010.py ├── 0011-Container-With-Most-Water │ ├── 0011.cpp │ ├── 0011.go │ └── 0011.py ├── 0012-Integer-to-Roman │ ├── 0012.cpp │ ├── 0012.go │ └── 0012.py ├── 0013-Roman-to-Integer │ ├── 0013.cpp │ ├── 0013.go │ ├── 0013.java │ ├── 0013.js │ └── 0013.py ├── 0014-Longest-Common-Prefix │ ├── 0014.cpp │ ├── 0014.go │ └── 0014.py ├── 0015-3Sum │ ├── 0015.cpp │ ├── 0015.go │ └── 0015.py ├── 0016-3Sum-Closest │ ├── 0016.cpp │ └── 0016.py ├── 0017-Letter-Combinations-of-a-Phone-Number │ ├── 0017.cpp │ └── 0017.py ├── 0018-4Sum │ ├── 0018.cpp │ └── 0018.py ├── 0019-Remove-Nth-Node-From-End-of-List │ ├── 0019.cpp │ └── 0019.py ├── 0020-Valid-Parentheses │ ├── 0020.cpp │ ├── 0020.go │ ├── 0020.java │ └── 0020.py ├── 0021-Merge-Two-Sorted-Lists │ ├── 0021.cpp │ └── 0021.py ├── 0022-Generate-Parentheses │ ├── 0022.cpp │ └── 0022.py ├── 0023-Merge-k-Sorted-Lists │ ├── 0023.cpp │ └── 0023.py ├── 0024-Swap-Nodes-in-Pairs │ ├── 0024.cpp │ └── 0024.py ├── 0025-Reverse-Nodes-in-k-Group │ ├── 0025.cpp │ └── 0025.py ├── 0026-Remove-Duplicates-from-Sorted-Array │ ├── 0026.cpp │ ├── 0026.go │ ├── 0026.js │ └── 0026.py ├── 0027-Remove-Element │ ├── 0027.cpp │ ├── 0027.go │ └── 0027.py ├── 0028-Implement-strStr() │ ├── 0028.cpp │ └── 0028.py ├── 0029-Divide-Two-Integers │ ├── 0029.cpp │ └── 0029.py ├── 0030-Substring-with-Concatenation-of-All-Words │ ├── 0030.cpp │ └── 0030.py ├── 0031-Next-Permutation │ ├── 0031.cpp │ └── 0031.py ├── 0032-Longest-Valid-Parentheses │ ├── 0032.cpp │ └── 0032.py ├── 0033-Search-in-Rotated-Sorted-Array │ ├── 0033.cpp │ ├── 0033.go │ └── 0033.py ├── 0034-Find-First-and-Last-Position-of-Element-in-Sorted-Array │ ├── 0034.cpp │ └── 0034.py ├── 0035-Search-Insert-Position │ ├── 0035.cpp │ ├── 0035.go │ └── 0035.py ├── 0036-Valid-Sudoku │ ├── 0036.cpp │ └── 0036.py ├── 0037-Sudoku-Solver │ ├── 0037.cpp │ └── 0037.py ├── 0038-Count-and-Say │ ├── 0038.cpp │ └── 0038.py ├── 0039-Combination-Sum │ ├── 0039.cpp │ └── 0039.py ├── 0040-Combination-Sum-II │ ├── 0040.cpp │ └── 0040.py ├── 0041-First-Missing-Positive │ ├── 0041.cpp │ └── 0041.py ├── 0042-Trapping-Rain-Water │ ├── 0042.cpp │ └── 0042.py ├── 0043-Multiply-Strings │ ├── 0043.cpp │ └── 0043.py ├── 0044-Wildcard-Matching │ ├── 0044.cpp │ └── 0044.py ├── 0045-Jump-Game-II │ ├── 0045.cpp │ └── 0045.py ├── 0046-Permutations │ ├── 0046.cpp │ ├── 0046.java │ └── 0046.py ├── 0047-Permutations-II │ ├── 0047.cpp │ ├── 0047.java │ └── 0047.py ├── 0048-Rotate-Image │ ├── 0048.cpp │ ├── 0048.go │ └── 0048.py ├── 0049-Group-Anagrams │ ├── 0049.cpp │ ├── 0049.go │ └── 0049.py ├── 0050-Pow(x,n) │ ├── 0050.cpp │ └── 0050.py ├── 0051-N-Queens │ ├── 0051.cpp │ └── 0051.py ├── 0052-N-Queens-II │ ├── 0052.cpp │ └── 0052.py ├── 0053-Maximum-Subarray │ ├── 0053.cpp │ └── 0053.py ├── 0054-Spiral-Matrix │ ├── 0054.cpp │ └── 0054.py ├── 0055-Jump-Game │ ├── 0055.cpp │ ├── 0055.go │ └── 0055.py ├── 0056-Merge-Intervals │ ├── 0056.cpp │ └── 0056.py ├── 0057-Insert-Interval │ └── 0057.cpp ├── 0058-Length-of-Last-Word │ ├── 0058.cpp │ ├── 0058.js │ ├── 0058.py │ └── 0058.rs ├── 0059-Spiral-Matrix-II │ ├── 0059.cpp │ └── 0059.py ├── 0060-Permutation-Sequence │ ├── 0060.cpp │ └── 0060.py ├── 0061-Rotate-List │ ├── 0061.cpp │ └── 0061.py ├── 0062-Unique-Paths │ ├── 0062.cpp │ └── 0062.py ├── 0063-Unique-Paths-II │ ├── 0063.cpp │ └── 0063.py ├── 0064-Minimum-Path-Sum │ ├── 0064.cpp │ └── 0064.py ├── 0065-Valid-Number │ ├── 0065.cpp │ └── 0065.py ├── 0066-Plus-One │ ├── 0066.cpp │ ├── 0066.py │ └── 0066.rs ├── 0067-Add-Binary │ ├── 0067.cpp │ └── 0067.py ├── 0068-Text-Justification │ ├── 0068.cpp │ └── 0068.py ├── 0069-Sqrt(x) │ ├── 0069.cpp │ ├── 0069.go │ └── 0069.py ├── 0070-Climbing-Stairs │ ├── 0070.cpp │ ├── 0070.go │ └── 0070.py ├── 0071-Simplify-Path │ ├── 0071.cpp │ └── 0071.py ├── 0072-Edit-Distance │ ├── 0072.cpp │ └── 0072.py ├── 0073-Set-Matrix-Zeroes │ ├── 0073.cpp │ └── 0073.py ├── 0074-Search-a-2D-Matrix │ ├── 0074.cpp │ └── 0074.py ├── 0075-Sort-Colors │ ├── 0075.cpp │ ├── 0075.go │ └── 0075.py ├── 0076-Minimum-Window-Substring │ ├── 0076.cpp │ └── 0076.py ├── 0077-Combinations │ ├── 0077.cpp │ └── 0077.py ├── 0078-Subsets │ ├── 0078.cpp │ └── 0078.py ├── 0079-Word-Search │ ├── 0079.cpp │ └── 0079.py ├── 0080-Remove-Duplicates-from-Sorted-Array-II │ ├── 0080.cpp │ └── 0080.py ├── 0081-Search-in-Rotated-Sorted-Array-II │ ├── 0081.cpp │ └── 0081.py ├── 0082-Remove-Duplicates-from-Sorted-List-II │ ├── 0082.cpp │ └── 0082.py ├── 0083-Remove-Duplicates-from-Sorted-List │ ├── 0083.cpp │ └── 0083.py ├── 0084-Largest-Rectangle-in-Histogram │ ├── 0084.cpp │ └── 0084.py ├── 0085-Maximal-Rectangle │ ├── 0085.cpp │ └── 0085.py ├── 0086-Partition-List │ ├── 0086.cpp │ └── 0086.py ├── 0087-Scramble-String │ ├── 0087.cpp │ └── 0087.py ├── 0088-Merge-Sorted-Array │ ├── 0088.cpp │ └── 0088.py ├── 0089-Gray-Code │ ├── 0089.cpp │ └── 0089.py ├── 0090-Subsets-II │ ├── 0090.cpp │ └── 0090.py ├── 0091-Decode-Ways │ ├── 0091.cpp │ └── 0091.py ├── 0092-Reverse-Linked-List-II │ ├── 0092.cpp │ └── 0092.py ├── 0093-Restore-IP-Addresses │ ├── 0093.cpp │ └── 0093.py ├── 0094-Binary-Tree-Inorder-Traversal │ ├── 0094.cpp │ └── 0094.py ├── 0095-Unique-Binary-Search-Trees-II │ ├── 0095.cpp │ └── 0095.py ├── 0096-Unique-Binary-Search-Trees │ ├── 0096.cpp │ └── 0096.py ├── 0097-Interleaving-String │ ├── 0097.cpp │ └── 0097.py ├── 0098-Validate-Binary-Search-Tree │ ├── 0098.cpp │ └── 0098.py ├── 0099-Recover-Binary-Search-Tree │ ├── 0099.cpp │ └── 0099.py ├── 0100-Same-Tree │ ├── 0100.cpp │ └── 0100.py ├── 0101-Symmetric-Tree │ ├── 0101.cpp │ └── 0101.py ├── 0102-Binary-Tree-Level-Order-Traversal │ ├── 0102.cpp │ └── 0102.py ├── 0103-Binary-Tree-Zigzag-Level-Order-Traversal │ ├── 0103.cpp │ └── 0103.py ├── 0104-Maximum-Depth-of-Binary-Tree │ ├── 0104.cpp │ └── 0104.py ├── 0105-Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal │ ├── 0105.cpp │ └── 0105.py ├── 0106-Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal │ ├── 0106.cpp │ └── 0106.py ├── 0107-Binary-Tree-Level-Order-Traversal-II │ ├── 0107.cpp │ └── 0107.py ├── 0108-Convert-Sorted-Array-to-Binary-Search-Tree │ ├── 0108.cpp │ └── 0108.py ├── 0109-Convert-Sorted-List-to-Binary-Search-Tree │ ├── 0109.cpp │ └── 0109.py ├── 0110-Balanced-Binary-Tree │ ├── 0110.cpp │ └── 0110.py ├── 0111-Minimum-Depth-of-Binary-Tree │ ├── 0111.cpp │ └── 0111.py ├── 0112-Path-Sum │ ├── 0112.cpp │ └── 0112.py ├── 0113-Path-Sum-II │ ├── 0113.cpp │ └── 0113.py ├── 0114-Flatten-Binary-Tree-to-Linked-List │ ├── 0114.cpp │ └── 0114.py ├── 0115-Distinct-Subsequences │ ├── 0115.cpp │ └── 0115.py ├── 0116-Populating-Next-Right-Pointers-in-Each-Node │ ├── 116.cpp │ └── 116.py ├── 0117-Populating-Next-Right-Pointers-in-Each-Node-II │ ├── 0117.cpp │ └── 0117.py ├── 0118-Pascal's-Triangle │ ├── 0118.cpp │ └── 0118.py ├── 0119-Pascal's-Triangle-II │ ├── 0119.cpp │ └── 0119.py ├── 0120-Triangle │ ├── 0120.cpp │ └── 0120.py ├── 0121-Best-Time-to-Buy-and-Sell-Stock │ ├── 0121.cpp │ ├── 0121.go │ └── 0121.py ├── 0122-Best-Time-to-Buy-and-Sell-Stock-II │ ├── 0122.cpp │ └── 0122.py ├── 0123-Best-Time-to-Buy-and-Sell-Stock-III │ ├── 0123.cpp │ └── 0123.py ├── 0124-Binary-Tree-Maximum-Path-Sum │ ├── 0124.cpp │ └── 0124.py ├── 0125-Valid-Palindrome │ ├── 0125.cpp │ ├── 0125.go │ └── 0125.py ├── 0126-Word-Ladder-II │ ├── 0126.cpp │ └── 0126.py ├── 0127-Word-Ladder │ ├── 0127.cpp │ └── 0127.py ├── 0128-Longest-Consecutive-Sequence │ ├── 0128.cpp │ ├── 0128.go │ └── 0128.py ├── 0129-Sum-Root-to-Leaf-Numbers │ ├── 0129.cpp │ └── 0129.py ├── 0130-Surrounded-Regions │ ├── 0130.cpp │ └── 0130.py ├── 0131-Palindrome-Partitioning │ ├── 0131.cpp │ └── 0131.py ├── 0132-Palindrome-Partitioning-II │ ├── 0132.cpp │ └── 0132.py ├── 0133-Clone-Graph │ ├── 0133.cpp │ └── 0133.py ├── 0134-Gas-Station │ ├── 0134.cpp │ └── 0134.py ├── 0135-Candy │ ├── 0135.cpp │ └── 0135.py ├── 0136-Single-Number │ ├── 0136.cpp │ ├── 0136.go │ └── 0136.py ├── 0137-Single-Number-II │ ├── 0137.cpp │ ├── 0137.go │ └── 0137.py ├── 0138-Copy-List-with-Random-Pointer │ ├── 0138.cpp │ └── 0138.py ├── 0139-Word-Break │ ├── 0139.cpp │ └── 0139.py ├── 0140-Word-Break-II │ ├── 0140.cpp │ └── 0140.py ├── 0141-Linked-List-Cycle │ ├── 0141.cpp │ └── 0141.py ├── 0142-Linked-List-Cycle-II │ ├── 0142.cpp │ └── 0142.py ├── 0143-Reorder-List │ ├── 0143.cpp │ └── 0143.py ├── 0144-Binary-Tree-Preorder-Traversal │ ├── 0144.cpp │ └── 0144.py ├── 0145-Binary-Tree-Postorder-Traversal │ ├── 0145.cpp │ └── 0145.py ├── 0146-LRU-Cache │ ├── 0146.cpp │ └── 0146.py ├── 0147-Insertion-Sort-List │ ├── 0147.cpp │ └── 0147.py ├── 0148-Sort-List │ ├── 0148.cpp │ └── 0148.py ├── 0149-Max-Points-on-a-Line │ ├── 0149.cpp │ └── 0149.py ├── 0150-Evaluate-Reverse-Polish-Notation │ ├── 0150.cpp │ └── 0150.py ├── 0151-Reverse-Words-in-a-String │ ├── 0151.cpp │ └── 0151.py ├── 0152-Maximum-Product-Subarray │ ├── 0152.cpp │ ├── 0152.go │ └── 0152.py ├── 0153-Find-Minimum-in-Rotated-Sorted-Array │ ├── 0153.cpp │ ├── 0153.go │ └── 0153.py ├── 0154-Find-Minimum-in-Rotated-Sorted-Array-II │ ├── 0154.cpp │ └── 0154.py ├── 0155-Min-Stack │ ├── 0155.cpp │ └── 0155.py ├── 0160-Intersection-of-Two-Linked-Lists │ ├── 0160.cpp │ └── 0160.py ├── 0162-Find-Peak-Element │ ├── 0162.cpp │ ├── 0162.go │ ├── 0162.py │ └── 0162.rs ├── 0165-Compare-Version-Numbers │ ├── 0165.cpp │ └── 0165.py ├── 0166-Fraction-to-Recurring-Decimal │ ├── 0166.cpp │ └── 0166.py ├── 0167-Two-Sum-II-Input-array-is-sorted │ ├── 0167.cpp │ └── 0167.py ├── 0168-Excel-Sheet-Column-Title │ ├── 0168.cpp │ └── 0168.py ├── 0169-Majority-Element │ ├── 0169.cpp │ ├── 0169.go │ ├── 0169.py │ └── 0169.rs ├── 0171-Excel-Sheet-Column-Number │ ├── 0171.cpp │ └── 0171.py ├── 0172-Factorial-Trailing-Zeroes │ ├── 0172.cpp │ └── 0172.py ├── 0173-Binary-Search-Tree-Iterator │ ├── 0173.cpp │ └── 0173.py ├── 0174-Dungeon-Game │ ├── 0174.cpp │ └── 0174.py ├── 0179-Largest-Number │ ├── 0179.cpp │ └── 0179.py ├── 0187-Repeated-DNA-Sequences │ ├── 0187.cpp │ └── 0187.py ├── 0188-Best-Time-to-Buy-and-Sell-Stock-IV │ ├── 0188.cpp │ └── 0188.py ├── 0189-Rotate-Array │ ├── 0189.cpp │ └── 0189.py ├── 0190-Reverse-Bits │ ├── 0190.cpp │ ├── 0190.go │ └── 0190.py ├── 0191-Number-of-1-Bits │ ├── 0191.cpp │ ├── 0191.go │ └── 0191.py ├── 0198-House-Robber │ ├── 0198.cpp │ ├── 0198.go │ └── 0198.py ├── 0199-Binary-Tree-Right-Side-View │ ├── 0199.cpp │ └── 0199.py ├── 0200-Number-of-Islands │ ├── 0200.cpp │ ├── 0200.go │ ├── 0200.java │ ├── 0200.js │ └── 0200.py ├── 0201-Bitwise-AND-of-Numbers-Range │ ├── 0201.cpp │ └── 0201.py ├── 0202-Happy-Number │ ├── 0202.cpp │ └── 0202.py ├── 0203-Remove-Linked-List-Elements │ ├── 0203.cpp │ └── 0203.py ├── 0204-Count-Primes │ ├── 0204.cpp │ └── 0204.py ├── 0205-Isomorphic-Strings │ ├── 0205.cpp │ └── 0205.py ├── 0206-Reverse-Linked-List │ ├── 0206.cpp │ ├── 0206.go │ └── 0206.py ├── 0207-Course-Schedule │ ├── 0207.cpp │ ├── 0207.go │ ├── 0207.js │ └── 0207.py ├── 0208-Implement-Trie-(Prefix-Tree) │ ├── 0208.cpp │ ├── 0208.go │ ├── 0208.js │ └── 0208.py ├── 0209-Minimum-Size-Subarray-Sum │ ├── 0209.cpp │ └── 0209.py ├── 0210-Course-Schedule-II │ ├── 0210.cpp │ ├── 0210.go │ ├── 0210.js │ └── 0210.py ├── 0211-Add-and-Search-Word-Data-structure-design │ ├── 0211.cpp │ ├── 0211.py │ └── 0211.rs ├── 0212-Word-Search-II │ ├── 0212.cpp │ ├── 0212.go │ ├── 0212.js │ └── 0212.py ├── 0213-House-Robber-II │ ├── 0213.cpp │ └── 0213.py ├── 0215-Kth-Largest-Element-in-an-Array │ ├── 0215.cpp │ └── 0215.py ├── 0216-Combination-Sum-III │ ├── 0216.cpp │ └── 0216.py ├── 0217-Contains-Duplicate │ ├── 0217.cpp │ ├── 0217.go │ └── 0217.py ├── 0218-The-Skyline-Problem │ ├── 0218.cpp │ ├── 0218.go │ ├── 0218.js │ └── 0218.py ├── 0219-Contains-Duplicate-II │ ├── 0219.cpp │ ├── 0219.go │ └── 0219.py ├── 0220-Contains-Duplicate-III │ ├── 0220.cpp │ └── 0220.py ├── 0221-Maximal-Square │ ├── 0221.cpp │ ├── 0221.go │ ├── 0221.js │ └── 0221.py ├── 0222-Count-Complete-Tree-Nodes │ ├── 0222.cpp │ └── 0222.py ├── 0223-Rectangle-Area │ ├── 0223.cpp │ └── 0223.py ├── 0224-Basic-Calculator │ ├── 0224.cpp │ ├── 0224.go │ ├── 0224.js │ └── 0224.py ├── 0226-Invert-Binary-Tree │ ├── 0226.cpp │ └── 0226.py ├── 0228-Summary-Ranges │ ├── 0228.cpp │ └── 0228.py ├── 0229-Majority-Element-II │ ├── 0229.cpp │ ├── 0229.py │ └── 0229.rs ├── 0230-Kth-Smallest-Element-in-a-BST │ ├── 0230.cpp │ └── 0230.py ├── 0231-Power-of-Two │ ├── 0231.go │ ├── 231.cpp │ └── 231.py ├── 0234-Palindrome-Linked-List │ ├── 0234.cpp │ └── 0234.py ├── 0235-Lowest-Common-Ancestor-of-a-Binary-Search-Tree │ ├── 0235.cpp │ └── 0235.py ├── 0236-Lowest-Common-Ancestor-of-a-Binary-Tree │ ├── 0236.cpp │ └── 0236.py ├── 0237-Delete-Node-in-a-Linked-List │ ├── 0237.cpp │ └── 0237.py ├── 0238-Product-of-Array-Except-Self │ ├── 0238.cpp │ ├── 0238.go │ └── 0238.py ├── 0239-Sliding-Window-Maximum │ ├── 0239.cpp │ └── 0239.py ├── 0240-Search-a-2D-Matrix-II │ ├── 0240.cpp │ └── 0240.py ├── 0241-Different-Ways-to-Add-Parentheses │ ├── 0241.cpp │ └── 0241.py ├── 0242-Valid-Anagram │ ├── 0242.cpp │ ├── 0242.go │ └── 0242.py ├── 0253-Meeting-Rooms-II │ ├── 0253.cpp │ ├── 0253.go │ └── 0253.py ├── 0257-Binary-Tree-Paths │ ├── 0257.cpp │ └── 0257.py ├── 0260-Single-Number-III │ ├── 0260.cpp │ ├── 0260.java │ └── 0260.py ├── 0263-Ugly-Number │ ├── 0263.cpp │ ├── 0263.go │ └── 0263.py ├── 0264-Ugly-Number-II │ ├── 0264.cpp │ └── 0264.py ├── 0268-Missing-Number │ ├── 0268.cpp │ ├── 0268.go │ └── 0268.py ├── 0274-H-Index │ ├── 0274.cpp │ ├── 0274.go │ └── 0274.py ├── 0275-H-Index-II │ ├── 0275.cpp │ ├── 0275.go │ └── 0275.py ├── 0278-First-Bad-Version │ ├── 0278.cpp │ └── 0278.py ├── 0279-Perfect-Squares │ ├── 0279.cpp │ └── 0279.py ├── 0283-Move-Zeroes │ ├── 0283.cpp │ └── 0283.py ├── 0287-Find-the-Duplicate-Number │ ├── 0287.cpp │ └── 0287.py ├── 0289-Game-of-Life │ ├── 0289.cpp │ └── 0289.py ├── 0290-Word-Pattern │ ├── 0290.cpp │ └── 0290.py ├── 0297-Serialize-and-Deserialize-Binary-Tree │ ├── 0297.cpp │ ├── 0297.js │ └── 0297.py ├── 0300-Longest-Increasing-Subsequence │ ├── 0300.cpp │ ├── 0300.py │ └── 0300.rs ├── 0303-Range-Sum-Query-Immutable │ ├── 0303.cpp │ └── 0303.py ├── 0307-Range-Sum-Query-Mutable │ ├── 0307.cpp │ ├── 0307.go │ ├── 0307.js │ └── 0307.py ├── 0309-Best-Time-to-Buy-and-Sel-Stock-with-Cooldown │ ├── 0309.cpp │ └── 0309.py ├── 0310-Insert-Delete-GetRandom-O(1) │ └── 0310.cpp ├── 0316-Remove-Duplicate-Letters │ ├── 0316.cpp │ └── 0316.py ├── 0319-Bulb-Switcher │ ├── 0319.cpp │ ├── 0319.go │ └── 0319.py ├── 0322-Coin-Change │ ├── 0322.cpp │ ├── 0322.go │ ├── 0322.java │ ├── 0322.js │ └── 0322.py ├── 0325-Maximum-Size-Subarray-Sum-Equals-k │ ├── 0325.cpp │ └── 0325.py ├── 0326-Power-of-Three │ ├── 0326.cpp │ ├── 0326.go │ └── 0326.rs ├── 0328-Odd-Even-Linked-List │ ├── 0328.cpp │ └── 0328.py ├── 0331-Verify-Preorder-Serialization-of-a-Binary-Tree │ ├── 0331.cpp │ └── 0331.py ├── 0337-House-Robber-III │ ├── 0337.cpp │ └── 0337.py ├── 0341-Flatten-Nested-List-Iterator │ └── 0341.py ├── 0343-Integer-Break │ ├── 0343.cpp │ └── 0343.py ├── 0344-Reverse-String │ ├── 0344.cpp │ ├── 0344.go │ └── 0344.py ├── 0345-Reverse-Vowels-of-a-String │ ├── 0345.cpp │ └── 0345.py ├── 0347-Top-K-Frequent-Elements │ ├── 0347.cpp │ ├── 0347.go │ └── 0347.py ├── 0349-Intersection-of-Two-Arrays │ ├── 0349.cpp │ └── 0349.py ├── 0350-Intersection-of-Two-Arrays-II │ ├── 0350.cpp │ └── 0350.py ├── 0352-Data-Stream-as-Disjoint-Intervals │ └── 0352.cpp ├── 0354-Russian-Doll-Envelopes │ ├── 0354.cpp │ └── 0354.py ├── 0365-Water-and-Jug-Problem │ ├── 0365.cpp │ ├── 0365.go │ ├── 0365.java │ ├── 0365.js │ └── 0365.py ├── 0371-Sum-of-Two-Integers │ ├── 0371.cpp │ ├── 0371.py │ └── 0371.rs ├── 0377-Combination-Sum-IV │ ├── 0377.cpp │ └── 0377.py ├── 0384-Shuffle-an-Array │ ├── 0384.cpp │ └── 0384.rs ├── 0384-shuffle-an-array │ ├── 0384.cpp │ └── 0384.rs ├── 0389-Find-the-Difference │ ├── 0389.cpp │ └── 0389.py ├── 0392-Is-Subsequence │ ├── 0392.cpp │ └── 0392.py ├── 0401-Binary-Watch │ ├── 0401.cpp │ └── 0401.py ├── 0404-Sum-of-Left-Leaves │ ├── 0404.cpp │ └── 0404.py ├── 0409-Longest-Palindrome │ ├── 0409.cpp │ ├── 0409.go │ ├── 0409.java │ ├── 0409.js │ └── 0409.py ├── 0416-Partition-Equal-Subset-Sum │ ├── 0416.cpp │ ├── 0416.go │ ├── 0416.java │ ├── 0416.js │ └── 0416.py ├── 0423-Reconstruct-Original-Digits-from-English │ ├── 0423.cpp │ └── 0423.rs ├── 0423-reconstruct-original-digits-from-english │ ├── 0423.cpp │ └── 0423.rs ├── 0424-Longest-Repeating-Character-Replacement │ ├── 0424.cpp │ ├── 0424.go │ ├── 0424.js │ └── 0424.py ├── 0435-Non-overlapping-Intervals │ ├── 0435.cpp │ ├── 0435.go │ └── 0435.py ├── 0437-Path-Sum-III │ ├── 0437.cpp │ └── 0437.py ├── 0438-Find-All-Anagrams-in-a-String │ ├── 0438.cpp │ ├── 0438.py │ └── 0438.rs ├── 0445-Add-Two-Numbers-II │ ├── 0445.cpp │ └── 0445.py ├── 0446-Arithmetic-Slices-II-Subsequence │ └── 0446.cpp ├── 0447-Number-of-Boomerangs │ ├── 0447.cpp │ ├── 0447.py │ └── 0447.rs ├── 0450-Delete-Node-in-a-BST │ ├── 0450.cpp │ └── 0450.py ├── 0451-Sort-Characters-By-Frequency │ ├── 0451.cpp │ └── 0451.py ├── 0452-Minimum-Number-of-Arrows-to-Burst-Balloons │ └── 0452.cpp ├── 0453-Minimum-Moves-to-Equal-Array-Elements │ ├── 0453.cpp │ ├── 0453.py │ └── 0453.rs ├── 0454-4Sum-II │ ├── 0454.cpp │ └── 0454.py ├── 0455-Assign-Cookies │ ├── 0455.cpp │ └── 0455.py ├── 0458-Poor-Pigs │ ├── 0458.cpp │ ├── 0458.py │ └── 0458.rs ├── 0459-Repeated-Substring-Pattern │ ├── 0459.cpp │ ├── 0459.go │ ├── 0459.java │ ├── 0459.js │ └── 0459.py ├── 0462-Minimum-Moves-to-Equal-Array-Elements-II │ ├── 0462.cpp │ └── 0462.py ├── 0473-Matchsticks-to-Square │ ├── 0473.cpp │ ├── 0473.go │ ├── 0473.java │ ├── 0473.js │ └── 0473.py ├── 0474-Ones-and-Zeroes │ ├── 0474.cpp │ └── 0474.py ├── 0486-Predict-the-Winner │ ├── 0486.cpp │ └── 0486.py ├── 0492-Construct-the-Rectangle │ ├── 0492.cpp │ └── 0492.rs ├── 0494-Target-Sum │ ├── 0494.cpp │ └── 0494.py ├── 0496-Next-Greater-Element-I │ ├── 0496.cpp │ └── 0496.py ├── 0503-Next-Greater-Element-II │ ├── 0503.cpp │ └── 0503.py ├── 0520-Detect-Capital │ └── 0520.cpp ├── 0524-Longest-Word-in-Dictionary-through-Deleting │ ├── 0524.cpp │ ├── 0524.go │ ├── 0524.java │ ├── 0524.js │ └── 0524.rs ├── 0525-Contiguous-Array │ ├── 0525.cpp │ └── 0525.py ├── 0528-Random-Pick-with-Weight │ ├── 0528.cpp │ └── 0528.rs ├── 0530-Minimum-Absolute-Difference-in-BST │ ├── 0530.cpp │ └── 0530.py ├── 0543-Diameter-of-Binary-Tree │ ├── 0543.cpp │ └── 0543.py ├── 0547-Friend-Circles │ ├── 0547.cpp │ └── 0547.py ├── 0559-Maximum-Depth-of-N-ary-Tree │ └── 0559.cpp ├── 0559-maximum-depth-of-n-ary-tree │ └── 0559.cpp ├── 0560-Subarray-Sum-Equals-K │ ├── 0560.cpp │ └── 0560.py ├── 0567-Permutation-in-String │ └── 0567.cpp ├── 0583-Delete-Operation-for-Two-Strings │ ├── 0583.cpp │ ├── 0583.go │ ├── 0583.java │ ├── 0583.js │ ├── 0583.py │ └── 0583.rs ├── 0587-Erect-the-Fence │ └── 0587.cpp ├── 0594-Longest-Harmonious-Subsequence │ ├── 0594.cpp │ └── 0594.rs ├── 0594-longest-harmonious-subsequence │ ├── 0594.cpp │ └── 0594.rs ├── 0605-Can-Place-Flowers │ └── 0605.cpp ├── 0637-Average-of-Levels-in-Binary-Tree │ ├── 0637.cpp │ └── 0637.py ├── 0650-2-Keys-Keyboard │ ├── 0650.cpp │ └── 0650.py ├── 0652-Find-Duplicate-Subtrees │ ├── 0652.cpp │ ├── 0652.go │ ├── 0652.js │ └── 0652.py ├── 0653-Two-Sum-IV-Input-is-a-BST │ ├── 0653.cpp │ └── 0653.py ├── 0654-Maximum-Binary-Tree │ ├── 0654.cpp │ └── 0654.py ├── 0678-Valid-Parenthesis-String │ ├── 0678.cpp │ ├── 0678.go │ ├── 0678.java │ ├── 0678.js │ ├── 0678.py │ └── 0678.rs ├── 0684-Redundant-Connection │ ├── 0684.cpp │ └── 0684.py ├── 0687-Longest-Univalue-Path │ ├── 0687.cpp │ └── 0687.py ├── 0695-Max-Area-of-Island │ ├── 0695.cpp │ ├── 0695.go │ ├── 0695.java │ ├── 0695.js │ └── 0695.py ├── 0697-Degree-of-an-Array │ └── 0697.cpp ├── 0698-Partition-to-K-Equal-Sum-Subsets │ ├── 0698.cpp │ ├── 0698.go │ ├── 0698.java │ ├── 0698.js │ └── 0698.py ├── 0700-Search-in-a-Binary-Search-Tree │ ├── 0700.cpp │ └── 0700.rs ├── 0733-Flood-Fill │ ├── 0733.cpp │ └── 0733.py ├── 0739-Daily-Temperatures │ ├── 0739.cpp │ ├── 0739.go │ └── 0739.py ├── 0742-Closest-Leaf-in-a-Binary-Tree │ ├── 0742.cpp │ └── 0742.py ├── 0776-Toeplitz-Matrix │ └── 0776.cpp ├── 0783-Minimum-Distance-Between-BST-Nodes │ └── 0783.cpp ├── 0788-Rotated-Digits │ ├── 0788.cpp │ └── 0788.py ├── 0790-Domino-and-Tromino-Tiling │ └── 0790.cpp ├── 0793-Preimage-Size-of-Factorial-Zeroes-Function │ ├── 0793.cpp │ ├── 0793.go │ ├── 0793.js │ └── 0793.py ├── 0795-Number-of-Subarrays-with-Bounded-Maximum │ └── 0795.cpp ├── 0813-Largest-Sum-of-Averages │ └── 0813.cpp ├── 0820-Short-Encoding-of-Words │ ├── 0820.cpp │ ├── 0820.go │ ├── 0820.java │ ├── 0820.js │ └── 0820.py ├── 0824-Goat-Latin │ ├── 0824.cpp │ ├── 0824.go │ ├── 0824.java │ ├── 0824.js │ └── 0824.py ├── 0825-Friends-Of-Appropriate-Ages │ ├── 0825.cpp │ ├── 0825.go │ ├── 0825.java │ ├── 0825.js │ └── 0825.py ├── 0826-Most-Profit-Assigning-Work │ ├── 0826.cpp │ ├── 0826.go │ ├── 0826.java │ ├── 0826.js │ └── 0826.py ├── 0827-Making-A-Large-Island │ ├── 0827.cpp │ ├── 0827.go │ ├── 0827.java │ ├── 0827.js │ └── 0827.py ├── 0828-Unique-Letter-String │ ├── 0828.cpp │ ├── 0828.go │ ├── 0828.java │ ├── 0828.js │ └── 0828.py ├── 0829-Consecutive-Numbers-Sum │ ├── 0829.cpp │ ├── 0829.go │ ├── 0829.java │ ├── 0829.js │ └── 0829.py ├── 0832-Flipping-an-Image │ ├── 0832.cpp │ └── 0832.py ├── 0834-Sum-of-Distances-in-Tree │ ├── 0834.cpp │ └── 0834.py ├── 0836-Rectangle-Overlap │ ├── 0836.cpp │ ├── 0836.go │ ├── 0836.java │ ├── 0836.js │ └── 0836.py ├── 0844-Backspace-String-Compare │ ├── 0844.cpp │ └── 0844.py ├── 0845-Longest-Mountain-in-Array │ ├── 0845.cpp │ └── 0845.py ├── 0846-Hand-of-Straights │ ├── 0846.cpp │ └── 0846.py ├── 0847-Shortest-Path-Visiting-All-Nodes │ ├── 0847.cpp │ ├── 0847.go │ ├── 0847.js │ └── 0847.py ├── 0852-Peak-Index-in-a-Mountain-Array │ ├── 0852.cpp │ └── 0852.py ├── 0857-Minimum-Cost-to-Hire-K-Workers │ ├── 0857.cpp │ ├── 0857.go │ ├── 0857.java │ ├── 0857.js │ └── 0857.py ├── 0859-Buddy-Strings │ ├── 0859.cpp │ └── 0859.rs ├── 0859-buddy-strings │ ├── 0859.cpp │ └── 0859.rs ├── 0872-Leaf-Similar-Trees │ ├── 0872.cpp │ └── 0872.py ├── 0873-Length-of-Longest-Fibonacci-Subsequence │ ├── 0873.cpp │ └── 0873.py ├── 0874-Walking-Robot-Simulation │ ├── 0874.cpp │ └── 0874.py ├── 0876-Middle-of-the-Linked-List │ ├── 0876.cpp │ ├── 0876.go │ ├── 0876.java │ ├── 0876.js │ └── 0876.py ├── 0878-Nth-Magical-Number │ └── 0878.cpp ├── 0891-Sum-of-Subsequence-Widths │ ├── 0891.cpp │ ├── 0891.go │ ├── 0891.js │ └── 0891.py ├── 0892-Surface-Area-of-3D-Shapes │ ├── 0892.cpp │ ├── 0892.go │ ├── 0892.java │ ├── 0892.js │ └── 0892.py ├── 0895-Maximum-Frequency-Stack │ └── 0895.cpp ├── 0901-Online-Stock-Span │ ├── 0901.cpp │ └── 0901.py ├── 0902-Numbers-At-Most-N-Given-Digit-Set │ ├── 0902.cpp │ └── 0902.py ├── 0904-Fruit-Into-Baskets │ └── 0904.cpp ├── 0907-Sum-of-Subarray-Minimums │ ├── 0907.cpp │ └── 0907.py ├── 0914-X-of-a-Kind-in-a-Deck-of-Cards │ ├── 0914.cpp │ ├── 0914.go │ ├── 0914.java │ ├── 0914.js │ └── 0914.py ├── 0917-Reverse-Only-Letters │ ├── 0917.cpp │ └── 0917.py ├── 0918-Maximum-Sum-Circular-Subarray │ ├── 0918.cpp │ └── 0918.py ├── 0919-Complete-Binary-Tree-Inserter │ ├── 0919.cpp │ └── 0919.py ├── 0920-Number-of-Music-Playlists │ ├── 0920.cpp │ └── 0920.py ├── 0921-Minimum-Add-to-Make-Parentheses-Valid │ ├── 0921.cpp │ └── 0921.py ├── 0922-Sort-Array-By-Parity-II │ ├── 0922.cpp │ └── 0922.py ├── 0923-3Sum-With-Multiplicity │ ├── 0923.cpp │ └── 0923.py ├── 0925-Long-Pressed-Name │ ├── 0925.cpp │ └── 0925.py ├── 0926-Flip-String-to-Monotone-Increasing │ ├── 0926.cpp │ └── 0926.py ├── 0927-Three-Equal-Parts │ ├── 0927.cpp │ └── 0927.py ├── 0929-Unique-Email-Addresses │ ├── 0929.cpp │ └── 0929.py ├── 0930-Binary-Subarrays-With-Sum │ ├── 0930.cpp │ └── 0930.py ├── 0931-Minimum-Falling-Path-Sum │ ├── 0931.cpp │ └── 0931.py ├── 0932-Beautiful-Array │ ├── 0932.cpp │ └── 0932.py ├── 0933-Number-of-Recent-Calls │ ├── 0933.cpp │ └── 0933.py ├── 0934-Shortest-Bridge │ ├── 0934.cpp │ └── 0934.py ├── 0935-Knight-Dialer │ ├── 0935.cpp │ └── 0935.py ├── 0936-Stamping-The-Sequence │ ├── 0936.cpp │ ├── 0936.go │ ├── 0936.js │ └── 0936.py ├── 0937-Reorder-Log-Files │ ├── 0937.cpp │ └── 0937.py ├── 0938-Range-Sum-of-BST │ ├── 0938.cpp │ └── 0938.py ├── 0939-Minimum-Area-Rectangle │ ├── 0939.cpp │ └── 0939.py ├── 0940-Distinct-Subsequences-II │ ├── 0940.cpp │ └── 0940.py ├── 0941-Valid-Mountain-Array │ ├── 0941.cpp │ └── 0941.py ├── 0942-DI-String-Match │ ├── 0942.cpp │ └── 0942.py ├── 0943-Find-the-Shortest-Superstring │ ├── 0943.cpp │ └── 0943.py ├── 0944-Delete-Columns-to-Make-Sorted │ ├── 0944.cpp │ └── 0944.py ├── 0945-Minimum-Increment-to-Make-Array-Unique │ ├── 0945.cpp │ └── 0945.py ├── 0946-Validate-Stack-Sequences │ ├── 0946.cpp │ ├── 0946.go │ ├── 0946.java │ ├── 0946.js │ └── 0946.py ├── 0947-Most-Stones-Removed-with-Same-Row-or-Column │ ├── 0947.cpp │ └── 0947.py ├── 0948-Bag-of-Tokens │ ├── 0948.cpp │ └── 0948.py ├── 0949-Largest-Time-for-Given-Digits │ ├── 0949.cpp │ └── 0949.py ├── 0950-Reveal-Cards-In-Increasing-Order │ ├── 0950.cpp │ └── 0950.py ├── 0951-Flip-Equivalent-Binary-Trees │ ├── 0951.cpp │ └── 0951.py ├── 0953-Verifying-an-Alien-Dictionary │ ├── 0953.cpp │ └── 0953.py ├── 0954-Array-of-Doubled-Pairs │ ├── 0954.cpp │ └── 0954.py ├── 0955-Delete-Columns-to-Make-Sorted-II │ ├── 0955.cpp │ └── 0955.py ├── 0956-Tallest-Billboard │ ├── 0956.cpp │ └── 0956.py ├── 0957-Prison-Cells-After-N-Days │ ├── 0957.cpp │ └── 0957.py ├── 0958-Check-Completeness-of-a-Binary-Tree │ ├── 0958.cpp │ └── 0958.py ├── 0959-Regions-Cut-By-Slashes │ ├── 0959.cpp │ └── 0959.py ├── 0960-Delete-Columns-to-Make-Sorted-III │ ├── 0960.cpp │ └── 0960.py ├── 0961-N-Repeated-Element-in-Size-2N-Array │ ├── 0961.cpp │ └── 0961.py ├── 0962-Maximum-Width-Ramp │ ├── 0962.cpp │ └── 0962.py ├── 0963-Minimum-Area-Rectangle-II │ ├── 0963.cpp │ └── 0963.py ├── 0965-Univalued-Binary-Tree │ ├── 0965.cpp │ └── 0965.py ├── 0966-Vowel-Spellchecker │ ├── 0966.cpp │ └── 0966.py ├── 0967-Numbers-With-Same-Consecutive-Differences │ ├── 0967.cpp │ └── 0967.py ├── 0969-Pancake-Sorting │ ├── 0969.cpp │ └── 0969.py ├── 0970-Powerful-Integers │ ├── 0970.cpp │ └── 0970.py ├── 0971-Flip-Binary-Tree-To-Match-Preorder-Traversal │ ├── 0971.cpp │ └── 0971.py ├── 0972-Equal-Rational-Numbers │ ├── 0972.cpp │ └── 0972.py ├── 0973-K-Closest-Points-to-Origin │ ├── 0973.cpp │ └── 0973.py ├── 0974-Subarray-Sums-Divisible-by-K │ ├── 0974.cpp │ └── 0974.py ├── 0975-Odd-Even-Jump │ ├── 0975.cpp │ ├── 0975.go │ ├── 0975.js │ └── 0975.py ├── 0976-Largest-Perimeter-Triangle │ ├── 0976.cpp │ └── 0976.py ├── 0977-Squares-of-a-Sorted-Array │ ├── 0977.cpp │ └── 0977.py ├── 0978-Longest-Turbulent-Subarray │ ├── 0978.cpp │ └── 0978.py ├── 0979-Distribute-Coins-in-Binary-Tree │ ├── 0979.cpp │ └── 0979.py ├── 0980-Unique-Paths-III │ ├── 0980.cpp │ └── 0980.py ├── 0981-Time-Based-Key-Value-Store │ ├── 0981.cpp │ └── 0981.py ├── 0982-Triples-with-Bitwise-AND-Equal-To-Zero │ ├── 0982.cpp │ └── 0982.py ├── 0983-Minimum-Cost-For-Tickets │ ├── 0983.cpp │ └── 0983.py ├── 0984-String-Without-AAA-or-BBB │ ├── 0984.cpp │ └── 0984.py ├── 0985-Sum-of-Even-Numbers-After-Queries │ ├── 0985.cpp │ └── 0985.py ├── 0986-Interval-List-Intersections │ ├── 0986.cpp │ └── 0986.py ├── 0987-Vertical-Order-Traversal-of-a-Binary-Tree │ ├── 0987.cpp │ └── 0987.py ├── 0988-Smallest-String-Starting-From-Leaf │ ├── 0988.cpp │ └── 0988.py ├── 0989-Add-to-Array-Form-of-Integer │ ├── 0989.cpp │ └── 0989.py ├── 0990-Satisfiability-of-Equality-Equations │ ├── 0990.cpp │ └── 0990.py ├── 0991-Broken-Calculator │ ├── 0991.cpp │ └── 0991.py ├── 0992-Subarrays-with-K-Different-Integers │ ├── 0992.cpp │ └── 0992.py ├── 0993-Cousins-in-Binary-Tree │ ├── 0993.cpp │ └── 0993.py ├── 0994-Rotting-Oranges │ ├── 0994.cpp │ ├── 0994.go │ ├── 0994.java │ ├── 0994.js │ └── 0994.py ├── 0995-Minimum-Number-of-K-Consecutive-Bit-Flips │ ├── 0995.cpp │ └── 0995.py ├── 0996-Number-of-Squareful-Arrays │ ├── 0996.cpp │ └── 0996.py ├── 0997-Find-the-Town-Judge │ ├── 0997.cpp │ └── 0997.py ├── 0998-Maximum-Binary-Tree-II │ ├── 0998.cpp │ └── 0998.py ├── 0999-Available-Captures-for-Rook │ ├── 0999.cpp │ └── 0999.py ├── 1000-Minimum-Cost-to-Merge-Stones │ ├── 1000.cpp │ └── 1000.java ├── 1001-Grid-Illumination │ ├── 1001.cpp │ └── 1001.py ├── 1002-Find-Common-Characters │ ├── 1002.cpp │ └── 1002.py ├── 1003-Check-If-Word-Is-Valid-After-Substitutions │ ├── 1003.cpp │ └── 1003.py ├── 1004-Max-Consecutive-Ones-III │ ├── 1004.cpp │ └── 1004.py ├── 1005-Maximize-Sum-Of-Array-After-K-Negations │ ├── 1005.cpp │ └── 1005.py ├── 1006-Clumsy-Factorial │ ├── 1006.cpp │ └── 1006.py ├── 1007-Minimum-Domino-Rotations-For-Equal-Row │ ├── 1007.cpp │ └── 1007.py ├── 1008-Construct-Binary-Search-Tree-from-Preorder-Traversal │ ├── 1008.cpp │ └── 1008.py ├── 1009-Complement-of-Base-10-Integer │ ├── 1009.cpp │ └── 1009.py ├── 1010-Pairs-of-Songs-With-Total-Durations-Divisible-by-60 │ ├── 1010.cpp │ └── 1010.py ├── 1011-Capacity-To-Ship-Packages-Within-D-Days │ ├── 1011.cpp │ └── 1011.py ├── 1012-Numbers-With-Repeated-Digits │ ├── 1012.cpp │ └── 1012.py ├── 1013-Partition-Array-Into-Three-Parts-With-Equal-Sum │ ├── 1013.cpp │ └── 1013.py ├── 1014-Best-Sightseeing-Pair │ ├── 1014.cpp │ └── 1014.py ├── 1015-Smallest-Integer-Divisible-by-K │ ├── 1015.cpp │ └── 1015.py ├── 1017-Convert-to-Base-2 │ ├── 1017.cpp │ └── 1017.py ├── 1018-Binary-Prefix-Divisible-By-5 │ ├── 1018.cpp │ └── 1018.py ├── 1019-Next-Greater-Node-In-Linked-List │ ├── 1019.cpp │ └── 1019.py ├── 1020-Number-of-Enclaves │ ├── 1020.cpp │ └── 1020.py ├── 1021-Remove-Outermost-Parentheses │ ├── 1021.cpp │ └── 1021.py ├── 1022-Sum-of-Root-To-Leaf-Binary-Numbers │ ├── 1022.cpp │ └── 1022.py ├── 1023-Camelcase-Matching │ ├── 1023.cpp │ ├── 1023.go │ ├── 1023.js │ └── 1023.py ├── 1024-Video-Stitching │ ├── 1024.cpp │ ├── 1024.go │ ├── 1024.java │ ├── 1024.js │ └── 1024.py ├── 1025-Divisor-Game │ ├── 1025.cpp │ └── 1025.py ├── 1026-Maximum-Difference-Between-Node-and-Ancestor │ ├── 1026.cpp │ └── 1026.py ├── 1027-Longest-Arithmetic-Sequence │ ├── 1027.cpp │ ├── 1027.go │ ├── 1027.js │ └── 1027.py ├── 1033-Moving-Stones-Until-Consecutive │ ├── 1033.cpp │ └── 1033.py ├── 1034-Coloring-A-Border │ ├── 1034.cpp │ └── 1034.py ├── 1035-Uncrossed-Lines │ ├── 1035.cpp │ └── 1035.py ├── 1037-Valid-Boomerang │ ├── 1037.cpp │ └── 1037.py ├── 1038-Binary-Search-Tree-to-Greater-Sum-Tree │ ├── 1038.cpp │ └── 1038.py ├── 1039-Minimum-Score-Triangulation-of-Polygon │ ├── 1039.cpp │ └── 1039.py ├── 1041-Robot-Bounded-In-Circle │ ├── 1041.cpp │ ├── 1041.go │ └── 1041.py ├── 1042-Flower-Planting-With-No-Adjacent │ ├── 1042.cpp │ ├── 1042.go │ └── 1042.py ├── 1043-Partition-Array-for-Maximum-Sum │ ├── 1043.cpp │ ├── 1043.go │ └── 1043.py ├── 1046-Last-Stone-Weight │ ├── 1046.cpp │ ├── 1046.go │ ├── 1046.js │ └── 1046.py ├── 1047-Remove-All-Adjacent-Duplicates-In-String │ ├── 1047.cpp │ ├── 1047.go │ ├── 1047.js │ └── 1047.py ├── 1048-Longest-String-Chain │ ├── 1048.cpp │ ├── 1048.go │ ├── 1048.js │ └── 1048.py ├── 1049-Last-Stone-Weight-II │ ├── 1049.cpp │ ├── 1049.go │ ├── 1049.js │ └── 1049.py ├── 1051-Height-Checker │ ├── 1051.cpp │ └── 1051.py ├── 1052-Grumpy-Bookstore-Owner │ ├── 1052.cpp │ └── 1052.py ├── 1053-Previous-Permutation-With-One-Swap │ ├── 1053.cpp │ └── 1053.py ├── 1054-Distant-Barcodes │ ├── 1054.cpp │ └── 1054.py ├── 1061-Lexicographically-Smallest-Equivalent-String │ └── 1061.cpp ├── 1064-Fixed-Point │ ├── 1064.cpp │ └── 1064.py ├── 1065-Index-Pairs-of-a-String │ ├── 1065.cpp │ └── 1065.py ├── 1066-Campus-Bikes-II │ ├── 1066.cpp │ └── 1066.py ├── 1067-Digit-Count-in-Range │ ├── 1067.cpp │ └── 1067.py ├── 1071-Greatest-Common-Divisor-of-Strings │ ├── 1071.cpp │ ├── 1071.go │ ├── 1071.java │ ├── 1071.js │ └── 1071.py ├── 1072-Flip-Columns-For-Maximum-Number-of-Equal-Rows │ ├── 1072.cpp │ ├── 1072.go │ ├── 1072.java │ ├── 1072.js │ └── 1072.py ├── 1073-Adding-Two-Negabinary-Numbers │ ├── 1073.cpp │ ├── 1073.go │ ├── 1073.java │ ├── 1073.js │ └── 1073.py ├── 1074-Number-of-Submatrices-That-Sum-to-Target │ ├── 1074.cpp │ ├── 1074.go │ ├── 1074.java │ ├── 1074.js │ └── 1074.py ├── 1078-Occurrences-After-Bigram │ ├── 1078.cpp │ └── 1078.py ├── 1079-Letter-Tile-Possibilities │ ├── 1079.cpp │ └── 1079.py ├── 1080-Insufficient-Nodes-in-Root-to-Leaf-Paths │ ├── 1080.cpp │ └── 1080.py ├── 1081-Smallest-Subsequence-of-Distinct-Characters │ ├── 1081.cpp │ └── 1081.py ├── 1085-Sum-of-Digits-in-the-Minimum-Number │ ├── 1085.cpp │ └── 1085.py ├── 1086-High-Five │ ├── 1086.cpp │ └── 1086.py ├── 1087-Brace-Expansion │ ├── 1087.cpp │ └── 1087.py ├── 1089-Duplicate-Zeros │ ├── 1089.cpp │ └── 1089.py ├── 1090-Largest-Values-From-Labels │ ├── 1090.cpp │ └── 1090.py ├── 1091-Shortest-Path-in-Binary-Matrix │ ├── 1091.cpp │ ├── 1091.go │ ├── 1091.js │ └── 1091.py ├── 1093-Statistics-from-a-Large-Sample │ ├── 1093.cpp │ ├── 1093.go │ ├── 1093.js │ └── 1093.py ├── 1094-Car-Pooling │ ├── 1094.cpp │ ├── 1094.go │ ├── 1094.js │ └── 1094.py ├── 1095-Find-in-Mountain-Array │ ├── 1095.cpp │ ├── 1095.go │ ├── 1095.js │ └── 1095.py ├── 1096-Brace-Expansion-II │ ├── 1096.cpp │ ├── 1096.go │ └── 1096.py ├── 1099-Two-Sum-Less-Than-K │ ├── 1099.cpp │ ├── 1099.go │ ├── 1099.js │ └── 1099.py ├── 1100-Find-K-Length-Substrings-With-No-Repeated-Characters │ ├── 1100.cpp │ ├── 1100.go │ ├── 1100.js │ └── 1100.py ├── 1101-The-Earliest-Moment-When-Everyone-Become-Friends │ ├── 1101.cpp │ ├── 1101.go │ ├── 1101.js │ └── 1101.py ├── 1102-Path-With-Maximum-Minimum-Value │ ├── 1102.cpp │ ├── 1102.go │ └── 1102.py ├── 1103-Distribute-Candies-to-People │ ├── 1103.cpp │ ├── 1103.go │ ├── 1103.java │ ├── 1103.js │ └── 1103.py ├── 1104-Path-In-Zigzag-Labelled-Binary-Tree │ ├── 1104.cpp │ ├── 1104.go │ └── 1104.py ├── 1105-Filling-Bookcase-Shelves │ ├── 1105.cpp │ ├── 1105.go │ └── 1105.py ├── 1106-Parsing-A-Boolean-Expression │ ├── 1106.cpp │ ├── 1106.go │ └── 1106.py ├── 1108-Defanging-an-IP-Address │ ├── 1108.cpp │ ├── 1108.go │ └── 1108.py ├── 1109-Corporate-Flight-Bookings │ ├── 1109.cpp │ ├── 1109.go │ └── 1109.py ├── 1110-Delete-Nodes-And-Return-Forest │ ├── 1110.cpp │ ├── 1110.go │ └── 1110.py ├── 1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings │ ├── 1111.cpp │ ├── 1111.go │ └── 1111.py ├── 1118-Number-of-Days-in-a-Month │ ├── 1118.cpp │ ├── 1118.go │ └── 1118.py ├── 1119-Remove-Vowels-from-a-String │ ├── 1119.cpp │ ├── 1119.go │ └── 1119.py ├── 1120-Maximum-Average-Subtree │ ├── 1120.cpp │ ├── 1120.go │ └── 1120.py ├── 1121-Divide-Array-Into-Increasing-Sequences │ ├── 1121.cpp │ ├── 1121.go │ └── 1121.py ├── 1122-Relative-Sort-Array │ ├── 1122.cpp │ ├── 1122.go │ └── 1122.py ├── 1123-Lowest-Common-Ancestor-of-Deepest-Leaves │ ├── 1123.cpp │ ├── 1123.go │ └── 1123.py ├── 1124-Longest-Well-Performing-Interval │ ├── 1124.cpp │ ├── 1124.go │ └── 1124.py ├── 1125-Smallest-Sufficient-Team │ ├── 1125.cpp │ ├── 1125.go │ └── 1125.py ├── 1128-Number-of-Equivalent-Domino-Pairs │ ├── 1128.cpp │ ├── 1128.go │ ├── 1128.js │ └── 1128.py ├── 1129-Shortest-Path-with-Alternating-Colors │ ├── 1129.cpp │ ├── 1129.go │ ├── 1129.js │ └── 1129.py ├── 1130-Minimum-Cost-Tree-From-Leaf-Values │ ├── 1130.cpp │ ├── 1130.go │ ├── 1130.js │ └── 1130.py ├── 1131-Maximum-of-Absolute-Value-Expression │ ├── 1131.cpp │ ├── 1131.go │ ├── 1131.js │ └── 1131.py ├── 1133-Largest-Unique-Number │ ├── 1133.cpp │ ├── 1133.go │ ├── 1133.js │ └── 1133.py ├── 1134-Armstrong-Number │ ├── 1134.cpp │ ├── 1134.go │ ├── 1134.js │ └── 1134.py ├── 1135-Connecting-Cities-With-Minimum-Cost │ ├── 1135.cpp │ ├── 1135.go │ ├── 1135.js │ └── 1135.py ├── 1136-Parallel-Courses │ ├── 1136.cpp │ ├── 1136.go │ ├── 1136.js │ └── 1136.py ├── 1137-N-th-Tribonacci-Number │ ├── 1137.cpp │ ├── 1137.go │ ├── 1137.js │ └── 1137.py ├── 1138-Alphabet-Board-Path │ ├── 1138.cpp │ ├── 1138.go │ ├── 1138.js │ └── 1138.py ├── 1139-Largest-1-Bordered-Square │ ├── 1139.cpp │ ├── 1139.go │ ├── 1139.js │ └── 1139.py ├── 1140-Stone-Game-II │ ├── 1140.cpp │ ├── 1140.go │ ├── 1140.js │ └── 1140.py ├── 1143-Longest-Common-Subsequence │ ├── 1143.cpp │ ├── 1143.go │ ├── 1143.js │ └── 1143.py ├── 1144-Decrease-Elements-To-Make-Array-Zigzag │ ├── 1144.cpp │ ├── 1144.go │ ├── 1144.js │ └── 1144.py ├── 1145-Binary-Tree-Coloring-Game │ ├── 1145.cpp │ ├── 1145.go │ ├── 1145.js │ └── 1145.py ├── 1146-Snapshot-Array │ ├── 1146.cpp │ ├── 1146.go │ ├── 1146.js │ └── 1146.py ├── 1147-Longest-Chunked-Palindrome-Decomposition │ ├── 1147.cpp │ ├── 1147.go │ ├── 1147.js │ └── 1147.py ├── 1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array │ ├── 1150.cpp │ ├── 1150.go │ ├── 1150.js │ └── 1150.py ├── 1151-Minimum-Swaps-to-Group-All-1's-Together │ ├── 1151.cpp │ ├── 1151.go │ ├── 1151.js │ └── 1151.py ├── 1152-Analyze-User-Website-Visit-Pattern │ ├── 1152.cpp │ ├── 1152.go │ ├── 1152.js │ └── 1152.py ├── 1153-String-Transforms-Into-Another-String │ ├── 1153.cpp │ ├── 1153.go │ ├── 1153.js │ └── 1153.py ├── 1154-Day-of-the-Year │ ├── 1154.cpp │ ├── 1154.go │ ├── 1154.js │ └── 1154.py ├── 1155-Number-of-Dice-Rolls-With-Target-Sum │ ├── 1155.cpp │ ├── 1155.go │ ├── 1155.js │ └── 1155.py ├── 1156-Swap-For-Longest-Repeated-Character-Substring │ ├── 1156.cpp │ ├── 1156.go │ ├── 1156.js │ └── 1156.py ├── 1157-Online-Majority-Element-In-Subarray │ ├── 1157.cpp │ ├── 1157.go │ ├── 1157.js │ └── 1157.py ├── 1160-Find-Words-That-Can-Be-Formed-by-Characters │ ├── 1160.cpp │ ├── 1160.go │ ├── 1160.js │ └── 1160.py ├── 1161-Maximum-Level-Sum-of-a-Binary-Tree │ ├── 1161.cpp │ ├── 1161.go │ ├── 1161.js │ └── 1161.py ├── 1162-As-Far-from-Land-as-Possible │ ├── 1162.cpp │ ├── 1162.go │ ├── 1162.js │ └── 1162.py ├── 1165-Single-Row-Keyboard │ ├── 1165.cpp │ ├── 1165.go │ ├── 1165.js │ └── 1165.py ├── 1166-Design-File-System │ ├── 1166.cpp │ ├── 1166.go │ ├── 1166.js │ └── 1166.py ├── 1167-Minimum-Cost-to-Connect-Sticks │ ├── 1167.cpp │ ├── 1167.go │ ├── 1167.js │ └── 1167.py ├── 1168-Optimize-Water-Distribution-in-a-Village │ ├── 1168.cpp │ ├── 1168.go │ ├── 1168.js │ └── 1168.py ├── 1169-Invalid-Transactions │ ├── 1169.cpp │ ├── 1169.go │ ├── 1169.js │ └── 1169.py ├── 1170-Compare-Strings-by-Frequency-of-the-Smallest-Character │ ├── 1170.cpp │ ├── 1170.go │ ├── 1170.js │ └── 1170.py ├── 1171-Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List │ ├── 1171.cpp │ ├── 1171.go │ ├── 1171.js │ └── 1171.py ├── 1172-Dinner-Plate-Stacks │ ├── 1172.cpp │ ├── 1172.go │ ├── 1172.js │ └── 1172.py ├── 1175-Prime-Arrangements │ ├── 1175.cpp │ ├── 1175.go │ ├── 1175.js │ └── 1175.py ├── 1176-Diet-Plan-Performance │ ├── 1176.cpp │ ├── 1176.go │ ├── 1176.js │ └── 1176.py ├── 1184-Distance-Between-Bus-Stops │ ├── 1184.cpp │ ├── 1184.go │ ├── 1184.js │ └── 1184.py ├── 1185-Day-of-the-Week │ ├── 1185.cpp │ ├── 1185.go │ ├── 1185.js │ └── 1185.py ├── 1186-Maximum-Subarray-Sum-with-One-Deletion │ ├── 1186.cpp │ ├── 1186.go │ ├── 1186.js │ └── 1186.py ├── 1187-Make-Array-Strictly-Increasing │ ├── 1187.cpp │ ├── 1187.go │ ├── 1187.js │ └── 1187.py ├── 1189-Maximum-Number-of-Balloons │ ├── 1189.cpp │ ├── 1189.go │ ├── 1189.js │ └── 1189.py ├── 1190-Reverse-Substrings-Between-Each-Pair-of-Parentheses │ ├── 1190.cpp │ ├── 1190.go │ ├── 1190.js │ └── 1190.py ├── 1191-K-Concatenation-Maximum-Sum │ ├── 1191.cpp │ ├── 1191.go │ ├── 1191.js │ └── 1191.py ├── 1192-Critical-Connections-in-a-Network │ ├── 1192.cpp │ ├── 1192.go │ ├── 1192.js │ └── 1192.py ├── 1196-How-Many-Apples-Can-You-Put-into-the-Basket │ ├── 1196.cpp │ ├── 1196.go │ ├── 1196.js │ └── 1196.py ├── 1197-Minimum-Knight-Moves │ ├── 1197.cpp │ ├── 1197.go │ ├── 1197.js │ └── 1197.py ├── 1198-Find-Smallest-Common-Element-in-All-Rows │ ├── 1198.cpp │ ├── 1198.go │ ├── 1198.js │ └── 1198.py ├── 1199-Minimum-Time-to-Build-Blocks │ ├── 1199.cpp │ ├── 1199.go │ ├── 1199.js │ └── 1199.py ├── 1200-Minimum-Absolute-Difference │ ├── 1200.cpp │ ├── 1200.go │ ├── 1200.js │ └── 1200.py ├── 1201-Ugly-Number-III │ ├── 1201.cpp │ ├── 1201.go │ ├── 1201.js │ └── 1201.py ├── 1202-Smallest-String-With-Swaps │ ├── 1202.cpp │ ├── 1202.go │ ├── 1202.js │ └── 1202.py ├── 1207-Unique-Number-of-Occurrences │ ├── 1207.cpp │ ├── 1207.go │ ├── 1207.js │ └── 1207.py ├── 1208-Get-Equal-Substrings-Within-Budget │ ├── 1208.cpp │ ├── 1208.go │ ├── 1208.js │ └── 1208.py ├── 1209-Remove-All-Adjacent-Duplicates-in-String-II │ ├── 1209.cpp │ ├── 1209.go │ ├── 1209.js │ └── 1209.py ├── 1210-Minimum-Moves-to-Reach-Target-with-Rotations │ ├── 1210.cpp │ ├── 1210.go │ ├── 1210.js │ └── 1210.py ├── 1213-Intersection-of-Three-Sorted-Arrays │ ├── 1213.cpp │ ├── 1213.go │ ├── 1213.js │ └── 1213.py ├── 1214-Two-Sum-BSTs │ ├── 1214.cpp │ ├── 1214.go │ ├── 1214.js │ └── 1214.py ├── 1215-Stepping-Numbers │ ├── 1215.cpp │ ├── 1215.go │ ├── 1215.js │ └── 1215.py ├── 1216-Valid-Palindrome-III │ ├── 1216.cpp │ ├── 1216.go │ ├── 1216.js │ └── 1216.py ├── 1217-Play-with-Chips │ ├── 1217.cpp │ ├── 1217.go │ ├── 1217.js │ └── 1217.py ├── 1218-Longest-Arithmetic-Subsequence-of-Given-Difference │ ├── 1218.cpp │ ├── 1218.go │ ├── 1218.js │ └── 1218.py ├── 1219-Path-with-Maximum-Gold │ ├── 1219.cpp │ ├── 1219.go │ ├── 1219.js │ └── 1219.py ├── 1220-Count-Vowels-Permutation │ ├── 1220.cpp │ ├── 1220.go │ ├── 1220.js │ └── 1220.py ├── 1221-Split-a-String-in-Balanced-Strings │ ├── 1221.cpp │ ├── 1221.go │ ├── 1221.js │ └── 1221.py ├── 1222-Queens-That-Can-Attack-the-King │ ├── 1222.cpp │ ├── 1222.go │ ├── 1222.js │ └── 1222.py ├── 1223-Dice-Roll-Simulation │ ├── 1223.cpp │ ├── 1223.go │ ├── 1223.js │ └── 1223.py ├── 1224-Maximum-Equal-Frequency │ ├── 1224.cpp │ ├── 1224.go │ ├── 1224.js │ └── 1224.py ├── 1228-Missing-Number-In-Arithmetic-Progression │ ├── 1228.cpp │ ├── 1228.go │ ├── 1228.js │ └── 1228.py ├── 1229-Meeting-Scheduler │ ├── 1229.cpp │ ├── 1229.go │ ├── 1229.js │ └── 1229.py ├── 1230-Toss-Strange-Coins │ ├── 1230.cpp │ ├── 1230.go │ ├── 1230.js │ └── 1230.py ├── 1231-Divide-Chocolate │ ├── 1231.cpp │ ├── 1231.go │ ├── 1231.js │ └── 1231.py ├── 1232-Check-If-It-Is-a-Straight-Line │ ├── 1232.cpp │ ├── 1232.go │ ├── 1232.js │ └── 1232.py ├── 1233-Remove-Sub-Folders-from-the-Filesystem │ ├── 1233.cpp │ ├── 1233.go │ ├── 1233.js │ └── 1233.py ├── 1234-Replace-the-Substring-for-Balanced-String │ ├── 1234.cpp │ ├── 1234.go │ ├── 1234.js │ └── 1234.py ├── 1235-Maximum-Profit-in-Job-Scheduling │ ├── 1235.cpp │ ├── 1235.go │ ├── 1235.js │ └── 1235.py ├── 1237-Find-Positive-Integer-Solution-for-a-Given-Equation │ ├── 1237.cpp │ ├── 1237.js │ └── 1237.py ├── 1238-Circular-Permutation-in-Binary-Representation │ ├── 1238.cpp │ ├── 1238.go │ ├── 1238.js │ └── 1238.py ├── 1239-Maximum-Length-of-a-Concatenated-String-with-Unique-Characters │ ├── 1239.cpp │ ├── 1239.go │ ├── 1239.js │ └── 1239.py ├── 1240-Tiling-a-Rectangle-with-the-Fewest-Squares │ ├── 1240.cpp │ ├── 1240.go │ ├── 1240.js │ └── 1240.py ├── 1243-Array-Transformation │ ├── 1243.cpp │ ├── 1243.go │ ├── 1243.java │ ├── 1243.js │ └── 1243.py ├── 1244-Design-A-Leaderboard │ ├── 1244.cpp │ ├── 1244.go │ ├── 1244.java │ ├── 1244.js │ └── 1244.py ├── 1245-Tree-Diameter │ ├── 1245.cpp │ ├── 1245.go │ ├── 1245.java │ ├── 1245.js │ └── 1245.py ├── 1246-Palindrome-Removal │ ├── 1246.cpp │ ├── 1246.go │ ├── 1246.java │ ├── 1246.js │ └── 1246.py ├── 1247-Minimum-Swaps-to-Make-Strings-Equal │ ├── 1247.cpp │ ├── 1247.go │ ├── 1247.java │ ├── 1247.js │ └── 1247.py ├── 1248-Count-Number-of-Nice-Subarrays │ ├── 1248.cpp │ ├── 1248.go │ ├── 1248.java │ ├── 1248.js │ └── 1248.py ├── 1249-Minimum-Remove-to-Make-Valid-Parentheses │ ├── 1249.cpp │ ├── 1249.go │ ├── 1249.java │ ├── 1249.js │ └── 1249.py ├── 1250-Check-If-It-Is-a-Good-Array │ ├── 1250.cpp │ ├── 1250.go │ ├── 1250.java │ ├── 1250.js │ └── 1250.py ├── 1252-Cells-with-Odd-Values-in-a-Matrix │ ├── 1252.cpp │ ├── 1252.go │ ├── 1252.java │ ├── 1252.js │ └── 1252.py ├── 1253-Reconstruct-a-2-Row-Binary-Matrix │ ├── 1253.cpp │ ├── 1253.go │ ├── 1253.java │ ├── 1253.js │ └── 1253.py ├── 1254-Number-of-Closed-Islands │ ├── 1254.cpp │ ├── 1254.go │ ├── 1254.java │ ├── 1254.js │ └── 1254.py ├── 1255-Maximum-Score-Words-Formed-by-Letters │ ├── 1255.cpp │ ├── 1255.go │ ├── 1255.java │ ├── 1255.js │ └── 1255.py ├── 1256-Encode-Number │ ├── 1256.cpp │ ├── 1256.go │ ├── 1256.java │ ├── 1256.js │ └── 1256.py ├── 1257-Smallest-Common-Region │ ├── 1257.cpp │ ├── 1257.go │ ├── 1257.java │ ├── 1257.js │ └── 1257.py ├── 1258-Synonymous-Sentences │ ├── 1258.cpp │ ├── 1258.go │ ├── 1258.java │ ├── 1258.js │ └── 1258.py ├── 1259-Handshakes-That-Don't-Cross │ ├── 1259.cpp │ ├── 1259.go │ ├── 1259.java │ └── 1259.py ├── 1260-Shift-2D-Grid │ ├── 1260.cpp │ ├── 1260.go │ ├── 1260.java │ ├── 1260.js │ └── 1260.py ├── 1261-Find-Elements-in-a-Contaminated-Binary-Tree │ ├── 1261.cpp │ ├── 1261.go │ ├── 1261.java │ ├── 1261.js │ └── 1261.py ├── 1262-Greatest-Sum-Divisible-by-Three │ ├── 1262.cpp │ ├── 1262.go │ ├── 1262.java │ ├── 1262.js │ └── 1262.py ├── 1263-Minimum-Moves-to-Move-a-Box-to-Their-Target-Location │ ├── 1263.cpp │ ├── 1263.go │ ├── 1263.java │ ├── 1263.js │ └── 1263.py ├── 1266-Minimum-Time-Visiting-All-Points │ ├── 1266.cpp │ ├── 1266.go │ ├── 1266.java │ ├── 1266.js │ └── 1266.py ├── 1267-Count-Servers-that-Communicate │ ├── 1267.cpp │ ├── 1267.go │ ├── 1267.java │ ├── 1267.js │ └── 1267.py ├── 1268-Search-Suggestions-System │ ├── 1268.cpp │ ├── 1268.go │ ├── 1268.java │ ├── 1268.js │ └── 1268.py ├── 1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps │ ├── 1269.cpp │ ├── 1269.go │ ├── 1269.java │ ├── 1269.js │ └── 1269.py ├── 1271-Hexspeak │ ├── 1271.cpp │ ├── 1271.go │ ├── 1271.java │ ├── 1271.js │ └── 1271.py ├── 1272-Remove-Interval │ ├── 1272.cpp │ ├── 1272.go │ ├── 1272.java │ ├── 1272.js │ └── 1272.py ├── 1273-Delete-Tree-Nodes │ ├── 1273.cpp │ ├── 1273.go │ ├── 1273.java │ ├── 1273.js │ └── 1273.py ├── 1274-Number-of-Ships-in-a-Rectangle │ ├── 1274.cpp │ ├── 1274.java │ ├── 1274.js │ └── 1274.py ├── 1275-Find-Winner-on-a-Tic-Tac-Toe-Game │ ├── 1275.cpp │ ├── 1275.go │ ├── 1275.java │ ├── 1275.js │ └── 1275.py ├── 1276-Number-of-Burgers-with-No-Waste-of-Ingredients │ ├── 1276.cpp │ ├── 1276.go │ ├── 1276.java │ ├── 1276.js │ └── 1276.py ├── 1277-Count-Square-Submatrices-with-All-Ones │ ├── 1277.cpp │ ├── 1277.go │ ├── 1277.java │ ├── 1277.js │ └── 1277.py ├── 1278-Palindrome-Partitioning-III │ ├── 1278.cpp │ ├── 1278.go │ ├── 1278.java │ ├── 1278.js │ └── 1278.py ├── 1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer │ ├── 1281.cpp │ ├── 1281.go │ ├── 1281.java │ ├── 1281.js │ └── 1281.py ├── 1282-Group-the-People-Given-the-Group-Size-They-Belong-To │ ├── 1282.cpp │ ├── 1282.go │ ├── 1282.java │ ├── 1282.js │ └── 1282.py ├── 1283-Find-the-Smallest-Divisor-Given-a-Threshold │ ├── 1283.cpp │ ├── 1283.go │ ├── 1283.java │ ├── 1283.js │ └── 1283.py ├── 1284-Minimum-Number-of-Flips-to-Convert-Binary-Matrix-to-Zero-Matrix │ ├── 1284.cpp │ ├── 1284.go │ ├── 1284.java │ ├── 1284.js │ └── 1284.py ├── 1286-Iterator-for-Combination │ ├── 1286.cpp │ ├── 1286.go │ ├── 1286.java │ ├── 1286.js │ └── 1286.py ├── 1287-Element-Appearing-More-Than-25%-In-Sorted-Array │ ├── 1287.cpp │ ├── 1287.go │ ├── 1287.java │ ├── 1287.js │ └── 1287.py ├── 1288-Remove-Covered-Intervals │ ├── 1288.cpp │ ├── 1288.go │ ├── 1288.java │ ├── 1288.js │ └── 1288.py ├── 1289-Minimum-Falling-Path-Sum-II │ ├── 1289.cpp │ ├── 1289.go │ ├── 1289.java │ ├── 1289.js │ └── 1289.py ├── 1290-Convert-Binary-Number-in-a-Linked-List-to-Integer │ ├── 1290.cpp │ ├── 1290.go │ ├── 1290.java │ ├── 1290.js │ └── 1290.py ├── 1291-Sequential-Digits │ ├── 1291.cpp │ ├── 1291.go │ ├── 1291.java │ ├── 1291.js │ └── 1291.py ├── 1292-Maximum-Side-Length-of-a-Square-with-Sum-Less-than-or-Equal-to-Threshold │ ├── 1292.cpp │ ├── 1292.go │ ├── 1292.java │ ├── 1292.js │ └── 1292.py ├── 1293-Shortest-Path-in-a-Grid-with-Obstacles-Elimination │ ├── 1293.cpp │ ├── 1293.go │ ├── 1293.java │ ├── 1293.js │ └── 1293.py ├── 1295-Find-Numbers-with-Even-Number-of-Digits │ ├── 1295.cpp │ ├── 1295.go │ ├── 1295.java │ ├── 1295.js │ └── 1295.py ├── 1296-Divide-Array-in-Sets-of-K-Consecutive-Numbers │ ├── 1296.cpp │ ├── 1296.go │ ├── 1296.java │ ├── 1296.js │ └── 1296.py ├── 1297-Maximum-Number-of-Occurrences-of-a-Substring │ ├── 1297.cpp │ ├── 1297.go │ ├── 1297.java │ ├── 1297.js │ └── 1297.py ├── 1298-Maximum-Candies-You-Can-Get-from-Boxes │ ├── 1298.cpp │ ├── 1298.go │ ├── 1298.java │ ├── 1298.js │ └── 1298.py ├── 1299-Replace-Elements-with-Greatest-Element-on-Right-Side │ ├── 1299.cpp │ ├── 1299.go │ ├── 1299.java │ ├── 1299.js │ └── 1299.py ├── 1300-Sum-of-Mutated-Array-Closest-to-Target │ ├── 1300.cpp │ ├── 1300.go │ ├── 1300.java │ ├── 1300.js │ └── 1300.py ├── 1301-Number-of-Paths-with-Max-Score │ ├── 1301.cpp │ ├── 1301.go │ ├── 1301.java │ ├── 1301.js │ └── 1301.py ├── 1302-Deepest-Leaves-Sum │ ├── 1302.cpp │ ├── 1302.go │ ├── 1302.java │ ├── 1302.js │ └── 1302.py ├── 1304-Find-N-Unique-Integers-Sum-up-to-Zero │ ├── 1304.cpp │ ├── 1304.go │ ├── 1304.java │ ├── 1304.js │ └── 1304.py ├── 1305-All-Elements-in-Two-Binary-Search-Trees │ ├── 1305.cpp │ ├── 1305.go │ ├── 1305.java │ ├── 1305.js │ └── 1305.py ├── 1306-Jump-Game-III │ ├── 1306.cpp │ ├── 1306.go │ ├── 1306.java │ ├── 1306.js │ └── 1306.py ├── 1309-Decrypt-String-from-Alphabet-to-Integer-Mapping │ ├── 1309.cpp │ ├── 1309.go │ ├── 1309.java │ ├── 1309.js │ └── 1309.py ├── 1310-XOR-Queries-of-a-Subarray │ ├── 1310.cpp │ ├── 1310.go │ ├── 1310.java │ ├── 1310.js │ └── 1310.py ├── 1311-Get-Watched-Videos-by-Your-Friends │ ├── 1311.cpp │ ├── 1311.go │ ├── 1311.java │ ├── 1311.js │ └── 1311.py ├── 1313-Decompress-Run-Length-Encoded-List │ ├── 1313.cpp │ ├── 1313.go │ ├── 1313.java │ ├── 1313.js │ └── 1313.py ├── 1314-Matrix-Block-Sum │ ├── 1314.cpp │ ├── 1314.go │ ├── 1314.java │ ├── 1314.js │ └── 1314.py ├── 1315-Sum-of-Nodes-with-Even-Valued-Grandparent │ ├── 1315.cpp │ ├── 1315.go │ ├── 1315.java │ ├── 1315.js │ └── 1315.py ├── 1316-Distinct-Echo-Substrings │ ├── 1316.cpp │ ├── 1316.go │ ├── 1316.java │ ├── 1316.js │ └── 1316.py ├── 1317-Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers │ ├── 1317.cpp │ ├── 1317.go │ ├── 1317.java │ ├── 1317.js │ └── 1317.py ├── 1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c │ ├── 1318.cpp │ ├── 1318.go │ ├── 1318.java │ ├── 1318.js │ └── 1318.py ├── 1319-Number-of-Operations-to-Make-Network-Connected │ ├── 1319.cpp │ ├── 1319.go │ ├── 1319.java │ ├── 1319.js │ └── 1319.py ├── 1320-Minimum-Distance-to-Type-a-Word-Using-Two-Fingers │ ├── 1320.cpp │ ├── 1320.go │ ├── 1320.java │ ├── 1320.js │ └── 1320.py ├── 1323-Maximum-69-Number │ ├── 1323.cpp │ ├── 1323.go │ ├── 1323.java │ ├── 1323.js │ └── 1323.py ├── 1324-Print-Words-Vertically │ ├── 1324.cpp │ ├── 1324.go │ ├── 1324.java │ ├── 1324.js │ └── 1324.py ├── 1325-Delete-Leaves-With-a-Given-Value │ ├── 1325.cpp │ ├── 1325.go │ ├── 1325.java │ ├── 1325.js │ └── 1325.py ├── 1326-Minimum-Number-of-Taps-to-Open-to-Water-a-Garden │ ├── 1326.cpp │ ├── 1326.go │ ├── 1326.java │ ├── 1326.js │ └── 1326.py ├── 1328-Break-a-Palindrome │ ├── 1328.cpp │ ├── 1328.go │ ├── 1328.java │ ├── 1328.js │ └── 1328.py ├── 1329-Sort-the-Matrix-Diagonally │ ├── 1329.cpp │ ├── 1329.go │ ├── 1329.java │ ├── 1329.js │ └── 1329.py ├── 1330-Reverse-Subarray-To-Maximize-Array-Value │ ├── 1330.cpp │ ├── 1330.go │ ├── 1330.java │ ├── 1330.js │ └── 1330.py ├── 1331-Rank-Transform-of-an-Array │ ├── 1331.cpp │ ├── 1331.go │ ├── 1331.java │ ├── 1331.js │ └── 1331.py ├── 1332-Remove-Palindromic-Subsequences │ ├── 1332.cpp │ ├── 1332.go │ ├── 1332.java │ ├── 1332.js │ └── 1332.py ├── 1333-Filter-Restaurants-by-Vegan-Friendly,-Price-and-Distance │ ├── 1333.cpp │ ├── 1333.go │ ├── 1333.java │ ├── 1333.js │ └── 1333.py ├── 1334-Find-the-City-With-the-Smallest-Number-of-Neighbors-at-a-Threshold-Distance │ ├── 1334.cpp │ ├── 1334.go │ ├── 1334.java │ ├── 1334.js │ └── 1334.py ├── 1335-Minimum-Difficulty-of-a-Job-Schedule │ ├── 1335.cpp │ ├── 1335.go │ ├── 1335.java │ ├── 1335.js │ └── 1335.py ├── 1337-The-K-Weakest-Rows-in-a-Matrix │ ├── 1337.cpp │ ├── 1337.go │ ├── 1337.java │ ├── 1337.js │ └── 1337.py ├── 1338-Reduce-Array-Size-to-The-Half │ ├── 1338.cpp │ ├── 1338.go │ ├── 1338.java │ ├── 1338.js │ └── 1338.py ├── 1339-Maximum-Product-of-Splitted-Binary-Tree │ ├── 1339.cpp │ ├── 1339.go │ ├── 1339.java │ ├── 1339.js │ └── 1339.py ├── 1340-Jump-Game-V │ ├── 1340.cpp │ ├── 1340.go │ ├── 1340.java │ ├── 1340.js │ └── 1340.py ├── 1342-Number-of-Steps-to-Reduce-a-Number-to-Zero │ ├── 1342.cpp │ ├── 1342.go │ ├── 1342.java │ ├── 1342.js │ └── 1342.py ├── 1343-Number-of-Sub-arrays-of-Size-K-and-Average-Greater-than-or-Equal-to-Threshold │ ├── 1343.cpp │ ├── 1343.go │ ├── 1343.java │ ├── 1343.js │ └── 1343.py ├── 1344-Angle-Between-Hands-of-a-Clock │ ├── 1344.cpp │ ├── 1344.go │ ├── 1344.java │ ├── 1344.js │ └── 1344.py ├── 1345-Jump-Game-IV │ ├── 1345.cpp │ ├── 1345.go │ ├── 1345.java │ ├── 1345.js │ └── 1345.py ├── 1346-Check-If-N-and-Its-Double-Exist │ ├── 1346.cpp │ ├── 1346.go │ ├── 1346.java │ ├── 1346.js │ └── 1346.py ├── 1347-Minimum-Number-of-Steps-to-Make-Two-Strings-Anagram │ ├── 1347.cpp │ ├── 1347.go │ ├── 1347.java │ ├── 1347.js │ └── 1347.py ├── 1348-Tweet-Counts-Per-Frequency │ ├── 1348.cpp │ ├── 1348.go │ ├── 1348.java │ ├── 1348.js │ └── 1348.py ├── 1349-Maximum-Students-Taking-Exam │ ├── 1349.cpp │ ├── 1349.go │ ├── 1349.java │ ├── 1349.js │ └── 1349.py ├── 1351-Count-Negative-Numbers-in-a-Sorted-Matrix │ ├── 1351.cpp │ ├── 1351.go │ ├── 1351.java │ ├── 1351.js │ └── 1351.py ├── 1352-Product-of-the-Last-K-Numbers │ ├── 1352.cpp │ ├── 1352.go │ ├── 1352.java │ ├── 1352.js │ └── 1352.py ├── 1353-Maximum-Number-of-Events-That-Can-Be-Attended │ ├── 1353.cpp │ ├── 1353.go │ ├── 1353.java │ ├── 1353.js │ └── 1353.py ├── 1354-Construct-Target-Array-With-Multiple-Sums │ ├── 1354.cpp │ ├── 1354.go │ ├── 1354.java │ ├── 1354.js │ └── 1354.py ├── 1356-Sort-Integers-by-The-Number-of-1-Bits │ ├── 1356.cpp │ ├── 1356.go │ ├── 1356.java │ ├── 1356.js │ └── 1356.py ├── 1357-Apply-Discount-Every-n-Orders │ ├── 1357.cpp │ ├── 1357.go │ ├── 1357.java │ ├── 1357.js │ └── 1357.py ├── 1358-Number-of-Substrings-Containing-All-Three-Characters │ ├── 1358.cpp │ ├── 1358.go │ ├── 1358.java │ ├── 1358.js │ └── 1358.py ├── 1359-Count-All-Valid-Pickup-and-Delivery-Options │ ├── 1359.cpp │ ├── 1359.go │ ├── 1359.java │ ├── 1359.js │ └── 1359.py ├── 1360-Number-of-Days-Between-Two-Dates │ ├── 1360.cpp │ ├── 1360.go │ ├── 1360.java │ ├── 1360.js │ └── 1360.py ├── 1361-Validate-Binary-Tree-Nodes │ ├── 1361.cpp │ ├── 1361.go │ ├── 1361.java │ ├── 1361.js │ └── 1361.py ├── 1362-Closest-Divisors │ ├── 1362.cpp │ ├── 1362.go │ ├── 1362.java │ ├── 1362.js │ └── 1362.py ├── 1363-Largest-Multiple-of-Three │ ├── 1363.cpp │ ├── 1363.go │ ├── 1363.java │ ├── 1363.js │ └── 1363.py ├── 1365-How-Many-Numbers-Are-Smaller-Than-the-Current-Number │ ├── 1365.cpp │ ├── 1365.go │ ├── 1365.java │ ├── 1365.js │ └── 1365.py ├── 1366-Rank-Teams-by-Votes │ ├── 1366.cpp │ ├── 1366.go │ ├── 1366.java │ ├── 1366.js │ └── 1366.py ├── 1367-Linked-List-in-Binary-Tree │ ├── 1367.cpp │ ├── 1367.go │ ├── 1367.java │ ├── 1367.js │ └── 1367.py ├── 1368-Minimum-Cost-to-Make-at-Least-One-Valid-Path-in-a-Grid │ ├── 1368.cpp │ ├── 1368.go │ ├── 1368.java │ ├── 1368.js │ └── 1368.py ├── 1370-Increasing-Decreasing-String │ ├── 1370.cpp │ ├── 1370.go │ ├── 1370.java │ ├── 1370.js │ └── 1370.py ├── 1371-Find-the-Longest-Substring-Containing-Vowels-in-Even-Counts │ ├── 1371.cpp │ ├── 1371.go │ ├── 1371.java │ ├── 1371.js │ └── 1371.py ├── 1372-Longest-ZigZag-Path-in-a-Binary-Tree │ ├── 1372.cpp │ ├── 1372.go │ ├── 1372.java │ ├── 1372.js │ └── 1372.py ├── 1373-Maximum-Sum-BST-in-Binary-Tree │ ├── 1373.cpp │ ├── 1373.go │ ├── 1373.java │ ├── 1373.js │ └── 1373.py ├── 1374-Generate-a-String-With-Characters-That-Have-Odd-Counts │ ├── 1374.cpp │ ├── 1374.go │ ├── 1374.java │ ├── 1374.js │ └── 1374.py ├── 1375-Bulb-Switcher-III │ ├── 1375.cpp │ ├── 1375.go │ ├── 1375.java │ ├── 1375.js │ └── 1375.py ├── 1376-Time-Needed-to-Inform-All-Employees │ ├── 1376.cpp │ ├── 1376.go │ ├── 1376.java │ ├── 1376.js │ └── 1376.py ├── 1377-Frog-Position-After-T-Seconds │ ├── 1377.cpp │ ├── 1377.go │ ├── 1377.java │ ├── 1377.js │ └── 1377.py ├── 1380-Lucky-Numbers-in-a-Matrix │ ├── 1380.cpp │ ├── 1380.go │ ├── 1380.java │ ├── 1380.js │ └── 1380.py ├── 1381-Design-a-Stack-With-Increment-Operation │ ├── 1381.cpp │ ├── 1381.go │ ├── 1381.java │ ├── 1381.js │ └── 1381.py ├── 1382-Balance-a-Binary-Search-Tree │ ├── 1382.cpp │ ├── 1382.go │ ├── 1382.java │ ├── 1382.js │ └── 1382.py ├── 1383-Maximum-Performance-of-a-Team │ ├── 1383.cpp │ ├── 1383.go │ ├── 1383.java │ ├── 1383.js │ └── 1383.py ├── 1385-Find-the-Distance-Value-Between-Two-Arrays │ ├── 1385.cpp │ ├── 1385.go │ ├── 1385.java │ ├── 1385.js │ └── 1385.py ├── 1386-Cinema-Seat-Allocation │ ├── 1386.cpp │ ├── 1386.go │ ├── 1386.java │ ├── 1386.js │ └── 1386.py ├── 1387-Sort-Integers-by-The-Power-Value │ ├── 1387.cpp │ ├── 1387.go │ ├── 1387.java │ ├── 1387.js │ └── 1387.py ├── 1388-Pizza-With-3n-Slices │ ├── 1388.cpp │ ├── 1388.go │ ├── 1388.java │ ├── 1388.js │ └── 1388.py ├── 1389-Create-Target-Array-in-the-Given-Order │ ├── 1389.cpp │ ├── 1389.go │ ├── 1389.java │ ├── 1389.js │ └── 1389.py ├── 1390-Four-Divisors │ ├── 1390.cpp │ ├── 1390.go │ ├── 1390.java │ ├── 1390.js │ └── 1390.py ├── 1391-Check-if-There-is-a-Valid-Path-in-a-Grid │ ├── 1391.cpp │ ├── 1391.go │ ├── 1391.java │ ├── 1391.js │ └── 1391.py ├── 1392-Longest-Happy-Prefix │ ├── 1392.cpp │ ├── 1392.go │ ├── 1392.java │ ├── 1392.js │ └── 1392.py ├── 1394-Find-Lucky-Integer-in-an-Array │ ├── 1394.cpp │ ├── 1394.go │ ├── 1394.java │ ├── 1394.js │ └── 1394.py ├── 1395-Count-Number-of-Teams │ ├── 1395.cpp │ ├── 1395.go │ ├── 1395.java │ ├── 1395.js │ └── 1395.py ├── 1396-Design-Underground-System │ ├── 1396.cpp │ ├── 1396.go │ ├── 1396.java │ ├── 1396.js │ └── 1396.py ├── 1397-Find-All-Good-Strings │ ├── 1397.cpp │ ├── 1397.go │ ├── 1397.java │ ├── 1397.js │ └── 1397.py ├── 1399-Count-Largest-Group │ ├── 1399.cpp │ ├── 1399.go │ ├── 1399.java │ ├── 1399.js │ └── 1399.py ├── 1400-Construct-K-Palindrome-Strings │ ├── 1400.cpp │ ├── 1400.go │ ├── 1400.java │ ├── 1400.js │ └── 1400.py ├── 1401-Circle-and-Rectangle-Overlapping │ ├── 1401.cpp │ ├── 1401.go │ ├── 1401.java │ ├── 1401.js │ └── 1401.py ├── 1402-Reducing-Dishes │ ├── 1402.cpp │ ├── 1402.go │ ├── 1402.java │ ├── 1402.js │ └── 1402.py ├── 1403-Minimum-Subsequence-in-Non-Increasing-Order │ ├── 1403.cpp │ ├── 1403.go │ ├── 1403.java │ ├── 1403.js │ └── 1403.py ├── 1404-Number-of-Steps-to-Reduce-a-Number-in-Binary-Representation-to-One │ ├── 1404.cpp │ ├── 1404.go │ ├── 1404.java │ ├── 1404.js │ └── 1404.py ├── 1405-Longest-Happy-String │ ├── 1405.cpp │ ├── 1405.go │ ├── 1405.java │ ├── 1405.js │ └── 1405.py ├── 1406-Stone-Game-III │ ├── 1406.cpp │ ├── 1406.go │ ├── 1406.java │ ├── 1406.js │ └── 1406.py ├── 1408-String-Matching-in-an-Array │ ├── 1408.cpp │ ├── 1408.go │ ├── 1408.java │ ├── 1408.js │ └── 1408.py ├── 1409-Queries-on-a-Permutation-With-Key │ ├── 1409.cpp │ ├── 1409.go │ ├── 1409.java │ ├── 1409.js │ └── 1409.py ├── 1410-HTML-Entity-Parser │ ├── 1410.cpp │ ├── 1410.go │ ├── 1410.java │ ├── 1410.js │ └── 1410.py ├── 1411-Number-of-Ways-to-Paint-N×3-Grid │ ├── 1411.cpp │ ├── 1411.go │ ├── 1411.java │ ├── 1411.js │ └── 1411.py ├── 1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum │ ├── 1413.cpp │ ├── 1413.go │ ├── 1413.java │ ├── 1413.js │ └── 1413.py ├── 1414-Find-the-Minimum-Number-of-Fibonacci-Numbers-Whose-Sum-Is-K │ ├── 1414.cpp │ ├── 1414.go │ ├── 1414.java │ ├── 1414.js │ └── 1414.py ├── 1415-The-k-th-Lexicographical-String-of-All-Happy-Strings-of-Length-n │ ├── 1415.cpp │ ├── 1415.go │ ├── 1415.java │ ├── 1415.js │ └── 1415.py ├── 1416-Restore-The-Array │ ├── 1416.cpp │ ├── 1416.go │ ├── 1416.java │ ├── 1416.js │ └── 1416.py ├── 1417-Reformat-The-String │ ├── 1417.cpp │ ├── 1417.go │ ├── 1417.java │ ├── 1417.js │ └── 1417.py ├── 1418-Display-Table-of-Food-Orders-in-a-Restaurant │ ├── 1418.cpp │ ├── 1418.go │ ├── 1418.java │ ├── 1418.js │ └── 1418.py ├── 1419-Minimum-Number-of-Frogs-Croaking │ ├── 1419.cpp │ ├── 1419.go │ ├── 1419.java │ ├── 1419.js │ └── 1419.py ├── 1420-Build-Array-Where-You-Can-Find-The-Maximum-Exactly-K-Comparisons │ ├── 1420.cpp │ ├── 1420.go │ ├── 1420.java │ ├── 1420.js │ └── 1420.py ├── 1422-Maximum-Score-After-Splitting-a-String │ ├── 1422.cpp │ ├── 1422.go │ ├── 1422.java │ ├── 1422.js │ └── 1422.py ├── 1423-Maximum-Points-You-Can-Obtain-from-Cards │ ├── 1423.cpp │ ├── 1423.go │ ├── 1423.java │ ├── 1423.js │ └── 1423.py ├── 1424-Diagonal-Traverse-II │ ├── 1424.cpp │ ├── 1424.go │ ├── 1424.java │ ├── 1424.js │ └── 1424.py ├── 1425-Constrained-Subsequence-Sum │ ├── 1425.cpp │ ├── 1425.go │ ├── 1425.java │ ├── 1425.js │ └── 1425.py ├── 1431-Kids-With-the-Greatest-Number-of-Candies │ ├── 1431.cpp │ ├── 1431.go │ ├── 1431.java │ ├── 1431.js │ └── 1431.py ├── 1432-Max-Difference-You-Can-Get-From-Changing-an-Integer │ ├── 1432.cpp │ ├── 1432.go │ ├── 1432.java │ ├── 1432.js │ └── 1432.py ├── 1433-Check-If-a-String-Can-Break-Another-String │ ├── 1433.cpp │ ├── 1433.go │ ├── 1433.java │ ├── 1433.js │ └── 1433.py ├── 1434-Number-of-Ways-to-Wear-Different-Hats-to-Each-Other │ ├── 1434.cpp │ ├── 1434.go │ ├── 1434.java │ ├── 1434.js │ └── 1434.py ├── 1436-Destination-City │ ├── 1436.cpp │ ├── 1436.go │ ├── 1436.java │ ├── 1436.js │ └── 1436.py ├── 1437-Check-If-All-1's-Are-at-Least-Length-K-Places-Away │ ├── 1437.cpp │ ├── 1437.go │ ├── 1437.java │ ├── 1437.js │ └── 1437.py ├── 1438-Longest-Continuous-Subarray-With-Absolute-Diff-Less-Than-or-Equal-to-Limit │ ├── 1438.cpp │ ├── 1438.go │ ├── 1438.java │ ├── 1438.js │ └── 1438.py ├── 1439-Find-the-Kth-Smallest-Sum-of-a-Matrix-With-Sorted-Rows │ ├── 1439.cpp │ ├── 1439.go │ ├── 1439.java │ ├── 1439.js │ └── 1439.py ├── 1441-Build-an-Array-With-Stack-Operations │ ├── 1441.cpp │ ├── 1441.go │ ├── 1441.java │ ├── 1441.js │ └── 1441.py ├── 1442-Count-Triplets-That-Can-Form-Two-Arrays-of-Equal-XOR │ ├── 1442.cpp │ ├── 1442.go │ ├── 1442.java │ ├── 1442.js │ └── 1442.py ├── 1443-Minimum-Time-to-Collect-All-Apples-in-a-Tree │ ├── 1443.cpp │ ├── 1443.go │ ├── 1443.java │ ├── 1443.js │ └── 1443.py ├── 1444-Number-of-Ways-of-Cutting-a-Pizza │ ├── 1444.cpp │ ├── 1444.go │ ├── 1444.java │ ├── 1444.js │ └── 1444.py ├── 1470-Shuffle-the-Array │ └── 1470.cpp ├── 1472-Design-Browser-History │ └── 1472.cpp ├── 1523-Count-Odd-Numbers-in-an-Interval-Range │ └── 1523.cpp ├── 1546-Maximum-Number-of-Non-Overlapping-Subarrays-With-Sum-Equals-Target │ └── maximum_number_of_nonoverlapping_with_sum_equals_target.cpp ├── 1574-Shortest-Subarray-To-Be-Removed-To-Make-Array-Sorted │ └── 1574.cpp ├── 1604-Alert-Using-Same-Key-Card-Three-or-More-Times-in-a-One-Hour-Period │ └── 1604.cpp ├── 1616-Split-Two-Strings-to-Make-Palindrome │ └── 1616.cpp ├── 1626-Best-Team-With-No-Conflicts │ └── 1626.cpp ├── 1657-Determine-if-Two-Strings-Are-Close │ └── 1657.cpp ├── 1658-Minimum-Operations-to-Reduce-X-to-Zero │ └── 1658.cpp ├── 1664-Ways-to-Make-a-Fair-Array │ └── 1664.cpp ├── 1669-Merge-In-Between-Linked-Lists │ └── 1669.cpp ├── 1673-Find-the-Most-Competitive-Subsequence │ └── 1673.cpp ├── 1691-Maximum-Height-by-Stacking-Cuboids │ └── 1691.cpp ├── 1704-Determine-if-String-Halves-Are-Alike │ └── 1704.cpp ├── 1732-Find-the-Highest-Altitude │ └── 1732.cpp ├── 1739-Building-Boxes │ └── 1739.cpp ├── 1742-Maximum-Number-of-Balls-in-a-Box │ └── 1742.cpp ├── 1750-Minimum-Length-of-String-After-Deleting-Similar-Ends │ └── 1750.cpp ├── 1752-Check-if-Array-Is-Sorted-and-Rotated │ └── 1752.cpp ├── 1754-Largest-Merge-Of-Two-Strings │ └── 1754.cpp ├── 1758-Minimum-Changes-To-Make-Alternating-Binary-String │ └── 1758.cpp ├── 1759-Count-Number-of-Homogenous-Substrings │ └── 1759.cpp ├── 1779-Find-Nearest-Point-That-Has-the-Same-X-or-Y-Coordinate │ └── 1779.cpp ├── 1780-Check-if-Number-is-a-Sum-of-Powers-of-Three │ └── 1780.cpp ├── 1781-Sum-of-Beauty-of-All-Substrings │ └── 1781.cpp ├── 1796-Second-Largest-Digit-in-a-String │ └── 1796.cpp ├── 1798-Maximum-Number-of-Consecutive-Values-You-Can-Make │ └── 1798.cpp ├── 1801-Number-of-Orders-in-the-Backlog │ └── 1801.cpp ├── 1802-Maximum-Value-at-a-Given-Index-in-a-Bounded-Array │ └── 1802.cpp ├── 1805-Number-of-Different-Integers-in-a-String │ └── 1805.cpp ├── 1806-Minimum-Number-of-Operations-to-Reinitialize-a-Permutation │ └── 1806.cpp ├── 1807-Evaluate-the-Bracket-Pairs-of-a-String │ └── 1807.cpp ├── 1812-Determine-Color-of-a-Chessboard-Square │ └── 1812.cpp ├── 1813-Sentence-Similarity-III │ └── 1813.cpp ├── 1814-Count-Nice-Pairs-in-an-Array │ └── 1814.cpp ├── 1819-Number-of-Different-Subsequences-GCDs │ └── 1819.cpp ├── 1827-Minimum-Operations-to-Make-the-Array-Increasing │ └── 1827.cpp ├── 1832-Check-if-the-Sentence-is-Pangram │ ├── 1832.cpp │ └── 1832.py ├── 1833-Maximum-Ice-Cream-Bars │ └── 1833.cpp ├── 1834-Single-Threaded-CPU │ └── 1834.cpp ├── 1926-Nearest-Exit-from-Entrance-in-Maze │ └── 1926.cpp ├── 1962-Remove-Stones-to-Minimize-the-Total │ └── 1962.cpp ├── 2011-Final-Value-of-Variable-After-Performing-Operations │ └── 2011.cpp ├── 2027-Minimum-Moves-to-Convert-String │ └── 2027.cpp ├── 2032-Two-Out-of-Three │ └── 2032.cpp ├── 2037-Minimum-Number-of-Moves-to-Seat-Everyone │ └── 2037.cpp ├── 2042-Check-if-Numbers-Are-Ascending-in-a-Sentence │ └── 2042.cpp ├── 2180-Count-Integers-With-Even-Digit-Sum │ └── 2180.cpp ├── 2185-Counting-Words-With-a-Given-Prefix │ └── 2185.cpp ├── 2225-Find-Players-With-Zero-or-One-Losses │ └── 2225.cpp ├── 2244-Minimum-Rounds-to-Complete-All-Tasks │ └── 2244.cpp ├── 2256-Minimum-Average-Difference │ └── 2256.cpp ├── 2279-Maximum-Bags-With-Full-Capacity-of-Rocks │ └── 2279.cpp ├── 2287-Rearrange-Characters-to-Make-Target-String │ └── 2287.cpp ├── 2293-Min-Max-Game │ └── 2293.cpp ├── 2315-Count-Asterisks │ └── 2315.cpp ├── 2319-Check-if-Matrix-Is-X-Matrix │ └── 2319.cpp ├── 2325-Decode-the-Message │ └── 2325.cpp ├── 2331-Evaluate-Boolean-Binary-Tree │ └── 2331.cpp ├── 2341-Maximum-Number-of-Pairs-in-Array │ └── 2341.cpp ├── 2347-Best-Poker-Hand │ └── 2347.cpp ├── 2351-First-Letter-to-Appear-Twice │ └── 2351.cpp ├── 2357-Make-Array-Zero-by-Subtracting-Equal-Amounts │ └── 2357.cpp ├── 2389-Longest-Subsequence-With-Limited-Sum │ └── 2389.cpp ├── 2395-Find-Subarrays-With-Equal-Sum │ └── 2395.cpp ├── 2427-Number-of-Common-Factors │ └── 2427.cpp ├── 2439-Minimize-Maximum-of-Array │ └── 2439.cpp ├── 2469-Convert-the-Temperature │ └── 2469.cpp ├── 2470-Number-of-Subarrays-With-LCM-Equal-to-K │ └── 2470.cpp ├── 2471-Minimum-Number-of-Operations-to-Sort-a-Binary-Tree-by-Level │ └── 2471.cpp ├── 2477-Minimum-Fuel-Cost-to-Report-to-the-Capital │ └── 2477.cpp ├── 2549-Count-Distinct-Numbers-on-Board │ └── 2549.cpp ├── 2550-Count-Collisions-of-Monkeys-on-a-Polygon │ └── 2550.cpp ├── 2551-Put-Marbles-in-Bags │ └── 2551.cpp ├── addProb.py └── addProg.py ├── test ├── 0002-test.cpp ├── 0003-test.cpp ├── 0004-test.cpp ├── 0005-test.cpp ├── 0006-test.cpp ├── 0007-test.cpp ├── 0009-test.cpp ├── 0011-test.cpp ├── 0012-test.cpp ├── 0013-test.cpp ├── 0014-test.cpp ├── 0015-test.cpp ├── 0016-test.cpp ├── 0019-test.cpp ├── 0020-test.cpp ├── 0021-test.cpp ├── 0024-test.cpp ├── 0025-test.cpp ├── 0026-test.cpp ├── 0027-test.cpp ├── 0028-test.cpp ├── 0029-test.cpp ├── 0031-test.cpp ├── 0032-test.cpp ├── 0033-test.cpp ├── 0034-test.cpp ├── 0035-test.cpp ├── 0039-test.cpp ├── 0041-test.cpp ├── 0042-test.cpp ├── 0043-test.cpp ├── 0044-test.cpp ├── 0045-test.cpp ├── 0050-test.cpp ├── 0051-test.cpp ├── 0052-test.cpp ├── 0053-test.cpp ├── 0054-test.cpp ├── 0055-test.cpp ├── 0058-test.cpp ├── 0062-test.cpp ├── 0063-test.cpp ├── 0064-test.cpp ├── 0065-test.cpp ├── 0067-test.cpp ├── 0069-test.cpp ├── 0070-test.cpp ├── 0071-test.cpp ├── 0072-test.cpp ├── 0074-test.cpp ├── 0075-test.cpp ├── 0076-test.cpp ├── 0079-test.cpp ├── 0080-test.cpp ├── 0081-test.cpp ├── 0082-test.cpp ├── 0083-test.cpp ├── 0084-test.cpp ├── 0085-test.cpp ├── 0086-test.cpp ├── 0087-test.cpp ├── 0088-test.cpp ├── 0091-test.cpp ├── 0092-test.cpp ├── 0096-test.cpp ├── 0097-test.cpp ├── 0120-test.cpp ├── 0121-test.cpp ├── 0122-test.cpp ├── 0123-test.cpp ├── 0125-test.cpp ├── 0127-test.cpp └── LinkedListUtils.cpp └── util └── ListNode.h /.gitignore: -------------------------------------------------------------------------------- 1 | *vscode* -------------------------------------------------------------------------------- /src/0001-Two-Sum/two_sum.js: -------------------------------------------------------------------------------- 1 | var twoSum = function (nums, target) { 2 | for (let i = 0; i < nums.length; ++i) { 3 | for (let j = i + 1; j < nums.length; ++j) { 4 | if (nums[i] + nums[j] == target) { 5 | return [i, j]; 6 | } 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /src/0009-Palindrome-Number/0009.go: -------------------------------------------------------------------------------- 1 | import "strconv" 2 | func isPalindrome(x int) bool { 3 | if x < 0 { 4 | return false 5 | } 6 | 7 | s := strconv.Itoa(x) 8 | for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { 9 | if s[i] != s[j] { 10 | return false 11 | } 12 | } 13 | return true 14 | } -------------------------------------------------------------------------------- /src/0009-Palindrome-Number/0009.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, x): 3 | """ 4 | :type x: int 5 | :rtype: bool 6 | """ 7 | x = str(x) 8 | return x == x[::-1] -------------------------------------------------------------------------------- /src/0026-Remove-Duplicates-from-Sorted-Array/0026.go: -------------------------------------------------------------------------------- 1 | package removeduplicatesfromsortedarray 2 | 3 | func removeDuplicates(nums []int) int { 4 | for i := 0; i < len(nums); { 5 | if i > 0 && nums[i] == nums[i-1] { 6 | nums = append(nums[:i], nums[i+1:]...) 7 | } else { 8 | i++ 9 | } 10 | } 11 | return len(nums) 12 | } 13 | -------------------------------------------------------------------------------- /src/0026-Remove-Duplicates-from-Sorted-Array/0026.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @return {number} 4 | */ 5 | var removeDuplicates = function (nums) { 6 | nums.forEach((element, i) => { 7 | if (element == nums[i + 1]) { 8 | nums.splice(i + 1, 1) 9 | removeDuplicates(nums); 10 | } 11 | }); 12 | return nums.length; 13 | }; 14 | -------------------------------------------------------------------------------- /src/0027-Remove-Element/0027.go: -------------------------------------------------------------------------------- 1 | package removeelement 2 | 3 | func removeElement(nums []int, val int) int { 4 | for i := 0; i < len(nums); { 5 | if nums[i] == val { 6 | nums = append(nums[:i], nums[i+1:]...) 7 | } else { 8 | i++ 9 | } 10 | } 11 | return len(nums) 12 | } 13 | -------------------------------------------------------------------------------- /src/0035-Search-Insert-Position/0035.go: -------------------------------------------------------------------------------- 1 | package searchinsertposition 2 | 3 | func searchInsert(nums []int, target int) int { 4 | lo, hi, mid := 0, len(nums)-1, 0 5 | for lo <= hi { 6 | mid = lo + (hi-lo)/2 7 | if target <= nums[mid] { 8 | hi = mid - 1 9 | } else { 10 | lo = mid + 1 11 | } 12 | } 13 | return lo 14 | } 15 | -------------------------------------------------------------------------------- /src/0037-Sudoku-Solver/0037.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0037-Sudoku-Solver/0037.cpp -------------------------------------------------------------------------------- /src/0043-Multiply-Strings/0043.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def multiply(self, num1: str, num2: str) -> str: 3 | res, m, n = 0, len(num1), len(num2) 4 | 5 | for i in range(1, m + 1): 6 | for j in range(1, n + 1): 7 | res += int(num1[-i]) * int(num2[-j]) * 10 ** (i + j - 2) 8 | return str(res) -------------------------------------------------------------------------------- /src/0048-Rotate-Image/0048.go: -------------------------------------------------------------------------------- 1 | package rotateimage 2 | 3 | func rotate(matrix [][]int) { 4 | n, m := len(matrix), len(matrix[0]) 5 | for i := 0; i < n; i++ { 6 | for j := i; j < m; j++ { 7 | matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] 8 | } 9 | for j, k := 0, m-1; j < k; j, k = j+1, k-1 { 10 | matrix[i][j], matrix[i][k] = matrix[i][k], matrix[i][j] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/0055-Jump-Game/0055.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func canJump(nums []int) bool { 4 | power := nums[0] - 1 5 | for i := 1; i < len(nums); i++ { 6 | if power < 0 { 7 | return false 8 | } 9 | new_power := nums[i] - 1 10 | power-- 11 | if new_power > power { 12 | power = new_power 13 | } 14 | } 15 | return true 16 | } 17 | -------------------------------------------------------------------------------- /src/0058-Length-of-Last-Word/0058.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lengthOfLastWord(self, s): 3 | """ 4 | :type s: str 5 | :rtype: int 6 | """ 7 | return len(s.strip().split(' ')[-1]) -------------------------------------------------------------------------------- /src/0058-Length-of-Last-Word/0058.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn length_of_last_word(s: String) -> i32 { 3 | s.split_whitespace().last().unwrap().len() as i32 4 | } 5 | } -------------------------------------------------------------------------------- /src/0066-Plus-One/0066.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn plus_one(digits: Vec) -> Vec { 3 | let mut digits = digits; 4 | for i in (0..digits.len()).rev() { 5 | digits[i] = (digits[i] + 1) % 10; 6 | if digits[i] != 0 { 7 | return digits; 8 | } 9 | } 10 | digits.insert(0, 1); 11 | digits 12 | } 13 | } -------------------------------------------------------------------------------- /src/0069-Sqrt(x)/0069.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | int mySqrt(int x) 6 | { 7 | long res = x; 8 | while (res * res > x) 9 | { 10 | res = (res + x / res) / 2; 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/0069-Sqrt(x)/0069.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func mySqrt(x int) int { 4 | if x < 2 { 5 | return x 6 | } 7 | lo, hi, mid, ans := 0, x, 0, 0 8 | for lo <= hi { 9 | mid = lo + (hi-lo)/2 10 | if mid*mid <= x { 11 | lo = mid + 1 12 | ans = mid 13 | } else { 14 | hi = mid - 1 15 | } 16 | } 17 | return ans 18 | } 19 | -------------------------------------------------------------------------------- /src/0069-Sqrt(x)/0069.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mySqrt(self, x): 3 | """ 4 | :type x: int 5 | :rtype: int 6 | """ 7 | res = x 8 | while res**2 > x: 9 | res = (res + x//res)//2 10 | 11 | return res -------------------------------------------------------------------------------- /src/0070-Climbing-Stairs/0070.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int climbStairs(int n) { 4 | long long a = 1, b = 1, c; 5 | for (int i = 0; i < n; i++) { 6 | c = a; 7 | a = b; 8 | b += c; 9 | } 10 | return a; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/0070-Climbing-Stairs/0070.go: -------------------------------------------------------------------------------- 1 | package climbingstairs 2 | 3 | func climbStairs(n int) int { 4 | if n < 4 { 5 | return n 6 | } 7 | a, b := 2, 3 8 | for i := 4; i < n+1; i++ { 9 | temp := b 10 | b = a + b 11 | a = temp 12 | } 13 | return b 14 | } 15 | -------------------------------------------------------------------------------- /src/0070-Climbing-Stairs/0070.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def climbStairs(self, n: int) -> int: 3 | a = b = 1 4 | for _ in range(n): 5 | a, b = b, a + b 6 | return a -------------------------------------------------------------------------------- /src/0075-Sort-Colors/0075.go: -------------------------------------------------------------------------------- 1 | package sortcolors 2 | 3 | func sortColors(nums []int) { 4 | lo, mid, hi := 0, 0, len(nums)-1 5 | for mid <= hi { 6 | if nums[mid] == 2 { 7 | nums[mid], nums[hi] = nums[hi], nums[mid] 8 | hi-- 9 | } else if nums[mid] == 0 { 10 | nums[lo], nums[mid] = nums[mid], nums[lo] 11 | lo++ 12 | mid++ 13 | } else { 14 | mid++ 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/0089-Gray-Code/0089.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def grayCode(self, n): 3 | """ 4 | :type n: int 5 | :rtype: List[int] 6 | """ 7 | if n == 0: 8 | return [0] 9 | 10 | res = list() 11 | for i in range(1 << n): 12 | res.append(i ^ (i>>1)) 13 | return res -------------------------------------------------------------------------------- /src/0121-Best-Time-to-Buy-and-Sell-Stock/0121.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func maxProfit(prices []int) int { 4 | ans, mx := 0, prices[len(prices)-1] 5 | for i := len(prices) - 2; i >= 0; i-- { 6 | ans = max(ans, mx-prices[i]) 7 | mx = max(mx, prices[i]) 8 | } 9 | return ans 10 | } 11 | 12 | func max(a, b int) int { 13 | if a > b { 14 | return a 15 | } 16 | return b 17 | } 18 | -------------------------------------------------------------------------------- /src/0125-Valid-Palindrome/0125.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, s): 3 | """ 4 | :type s: str 5 | :rtype: bool 6 | """ 7 | s_filter = ''.join(filter(str.isalnum, s)).lower() 8 | return s_filter[::-1] == s_filter 9 | 10 | if __name__ == "__main__": 11 | s = "A man, a plan, a canal: Panama" 12 | print(Solution().isPalindrome(s)) -------------------------------------------------------------------------------- /src/0136-Single-Number/0136.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func singleNumber(nums []int) int { 4 | ans := 0 5 | for _, val := range nums { 6 | ans ^= val 7 | } 8 | return ans 9 | } 10 | -------------------------------------------------------------------------------- /src/0136-Single-Number/0136.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | from operator import xor 3 | class Solution: 4 | def singleNumber(self, nums): 5 | """ 6 | :type nums: List[int] 7 | :rtype: int 8 | """ 9 | return reduce(xor, nums) 10 | 11 | if __name__ == "__main__": 12 | nums = [2,2,1] 13 | print(Solution().singleNumber(nums)) -------------------------------------------------------------------------------- /src/0137-Single-Number-II/0137.go: -------------------------------------------------------------------------------- 1 | package singlenumberii 2 | 3 | func singleNumber(nums []int) int { 4 | ans := 0 5 | for bit := 1; bit != 0; bit <<= 1 { 6 | count := 0 7 | for _, num := range nums { 8 | if num&bit != 0 { 9 | count++ 10 | } 11 | } 12 | if count%3 == 1 { 13 | ans |= bit 14 | } 15 | } 16 | return ans 17 | } 18 | -------------------------------------------------------------------------------- /src/0137-Single-Number-II/0137.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | return (3*sum(set(nums)) - sum(nums))//2 8 | 9 | if __name__ == "__main__": 10 | nums = [2,2,3,2] 11 | print(Solution().singleNumber(nums)) -------------------------------------------------------------------------------- /src/0151-Reverse-Words-in-a-String/0151.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseWords(self, s: str) -> str: 3 | return ' '.join([i for i in s.split()][::-1]) -------------------------------------------------------------------------------- /src/0153-Find-Minimum-in-Rotated-Sorted-Array/0153.go: -------------------------------------------------------------------------------- 1 | package findminimuminrotatedsortedarray 2 | 3 | func findMin(nums []int) int { 4 | var mid int 5 | lo, hi := 0, len(nums)-1 6 | for lo < hi { 7 | mid = lo + (hi-lo)/2 8 | if nums[mid] > nums[hi] { 9 | lo = mid + 1 10 | } else { 11 | hi = mid 12 | } 13 | } 14 | return nums[lo] 15 | } 16 | -------------------------------------------------------------------------------- /src/0168-Excel-Sheet-Column-Title/0168.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, n): 3 | """ 4 | :type n: int 5 | :rtype: str 6 | """ 7 | res = '' 8 | while n: 9 | n -= 1 10 | res += chr(ord('A')+n%26) 11 | n //= 26 12 | 13 | return res[::-1] -------------------------------------------------------------------------------- /src/0169-Majority-Element/0169.go: -------------------------------------------------------------------------------- 1 | package majorityelement 2 | 3 | func majorityElement(nums []int) int { 4 | mp := make(map[int]int, 0) 5 | ans, mx := -1, -1 6 | for _, v := range nums { 7 | mp[v]++ 8 | if mp[v] > mx { 9 | mx = mp[v] 10 | ans = v 11 | } 12 | } 13 | return ans 14 | } 15 | -------------------------------------------------------------------------------- /src/0169-Majority-Element/0169.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn majority_element(nums: Vec) -> i32 { 3 | let mut cnt = 0; 4 | let mut res = 0; 5 | for num in nums.into_iter() { 6 | if cnt == 0 { 7 | res = num; 8 | } 9 | cnt += if res == num {1} else {-1} 10 | } 11 | res 12 | } 13 | } -------------------------------------------------------------------------------- /src/0171-Excel-Sheet-Column-Number/0171.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | class Solution: 3 | def titleToNumber(self, s): 4 | """ 5 | :type s: str 6 | :rtype: int 7 | """ 8 | return reduce(lambda x, y : x * 26 + y, [ord(c) - 64 for c in s]) -------------------------------------------------------------------------------- /src/0172-Factorial-Trailing-Zeroes/0172.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | int trailingZeroes(int n) 6 | { 7 | int res = 0; 8 | while (n) res += (n /= 5); 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/0172-Factorial-Trailing-Zeroes/0172.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def trailingZeroes(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | return 0 if n == 0 else n // 5 + self.trailingZeroes(n // 5) -------------------------------------------------------------------------------- /src/0179-Largest-Number/0179.py: -------------------------------------------------------------------------------- 1 | class compare(str): 2 | def __lt__(x, y): 3 | return x+y > y+x 4 | 5 | class Solution: 6 | def largestNumber(self, nums: List[int]) -> str: 7 | if not nums: 8 | return "" 9 | nums = sorted(list(map(str, nums)), key=compare) 10 | return '0' if nums[0] == '0' else "".join(nums) -------------------------------------------------------------------------------- /src/0190-Reverse-Bits/0190.go: -------------------------------------------------------------------------------- 1 | package reversebits 2 | 3 | func reverseBits(num uint32) uint32 { 4 | var ans uint32 = 0 5 | for i := 0; i < 32; i++ { 6 | val := num & (1 << i) 7 | if val != 0 { 8 | ans |= (1 << (31 - i)) 9 | } 10 | } 11 | return ans 12 | } 13 | -------------------------------------------------------------------------------- /src/0190-Reverse-Bits/0190.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @param n, an integer 3 | # @return an integer 4 | def reverseBits(self, n): 5 | res = 0 6 | for _ in range(32): 7 | res = (res << 1) + (n & 1) 8 | n >>= 1 9 | return res -------------------------------------------------------------------------------- /src/0191-Number-of-1-Bits/0191.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 5 | class Solution 6 | { 7 | public: 8 | int hammingWeight(uint32_t n) 9 | { 10 | bitset<32> bin(n); 11 | return bin.count(); 12 | } 13 | }; -------------------------------------------------------------------------------- /src/0191-Number-of-1-Bits/0191.go: -------------------------------------------------------------------------------- 1 | package numberof1bits 2 | 3 | func hammingWeight(num uint32) int { 4 | ans := 0 5 | for num != 0 { 6 | ans++ 7 | num &= (num - 1) 8 | } 9 | return ans 10 | } 11 | -------------------------------------------------------------------------------- /src/0191-Number-of-1-Bits/0191.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def hammingWeight(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | return bin(n).count("1") -------------------------------------------------------------------------------- /src/0198-House-Robber/0198.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rob(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | pre, cur = 0, 0 8 | for i in nums: 9 | pre, cur = cur, max(pre + i, cur) 10 | 11 | return cur 12 | 13 | if __name__ == '__main__': 14 | nums = [2,7,9,3,1] 15 | print(Solution().rob(nums)) -------------------------------------------------------------------------------- /src/0201-Bitwise-AND-of-Numbers-Range/0201.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rangeBitwiseAnd(self, m, n): 3 | """ 4 | :type m: int 5 | :type n: int 6 | :rtype: int 7 | """ 8 | b = (m ^ n).bit_length() 9 | return m >> b << b -------------------------------------------------------------------------------- /src/0210-Course-Schedule-II/0210.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0210-Course-Schedule-II/0210.go -------------------------------------------------------------------------------- /src/0215-Kth-Largest-Element-in-an-Array/0215.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKthLargest(self, nums, k): 3 | """ 4 | :type nums: List[int] 5 | :type k: int 6 | :rtype: int 7 | """ 8 | return sorted(nums)[-k] -------------------------------------------------------------------------------- /src/0217-Contains-Duplicate/0217.go: -------------------------------------------------------------------------------- 1 | package containsduplicate 2 | 3 | func containsDuplicate(nums []int) bool { 4 | mp := make(map[int]bool) 5 | for _, val := range nums { 6 | if _, ok := mp[val]; ok == true { 7 | return true 8 | } 9 | mp[val] = true 10 | } 11 | return false 12 | } 13 | -------------------------------------------------------------------------------- /src/0219-Contains-Duplicate-II/0219.go: -------------------------------------------------------------------------------- 1 | package containsduplicateii 2 | 3 | func containsNearbyDuplicate(nums []int, k int) bool { 4 | mp := make(map[int]int, 0) 5 | for i, v := range nums { 6 | if val, ok := mp[v]; ok { 7 | if i-val <= k { 8 | return true 9 | } 10 | } 11 | mp[v] = i 12 | } 13 | return false 14 | } 15 | -------------------------------------------------------------------------------- /src/0223-Rectangle-Area/0223.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def computeArea(self, A: int, B: int, C: int, D: int, E: int, F: int, G: int, H: int) -> int: 3 | x = min(C, G) - max(A, E) 4 | y = min(D, H) - max(B, F) 5 | return (C - A) * (D - B) + (G - E) * (H - F) - max(x, 0)*max(y, 0) -------------------------------------------------------------------------------- /src/0231-Power-of-Two/0231.go: -------------------------------------------------------------------------------- 1 | package poweroftwo 2 | 3 | func isPowerOfTwo(n int) bool { 4 | if n <= 0 { 5 | return false 6 | } 7 | val := n & (n - 1) 8 | if val == 0 { 9 | return true 10 | } 11 | return false 12 | } 13 | -------------------------------------------------------------------------------- /src/0231-Power-of-Two/231.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfTwo(int n) { 4 | return n < 0 ? false : __builtin_popcountll(n) == 1; 5 | } 6 | }; -------------------------------------------------------------------------------- /src/0231-Power-of-Two/231.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfTwo(self, n: int) -> bool: 3 | return False if n < 0 else bin(n).count('1') == 1 -------------------------------------------------------------------------------- /src/0236-Lowest-Common-Ancestor-of-a-Binary-Tree/0236.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0236-Lowest-Common-Ancestor-of-a-Binary-Tree/0236.cpp -------------------------------------------------------------------------------- /src/0236-Lowest-Common-Ancestor-of-a-Binary-Tree/0236.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0236-Lowest-Common-Ancestor-of-a-Binary-Tree/0236.py -------------------------------------------------------------------------------- /src/0238-Product-of-Array-Except-Self/0238.go: -------------------------------------------------------------------------------- 1 | package productofarrayexceptself 2 | 3 | func productExceptSelf(nums []int) []int { 4 | ans := make([]int, len(nums), len(nums)) 5 | ans[0] = 1 6 | for i := 1; i < len(nums); i++ { 7 | ans[i] = ans[i-1] * nums[i-1] 8 | } 9 | r := 1 10 | for i := len(nums) - 1; i >= 0; i-- { 11 | ans[i] *= r 12 | r *= nums[i] 13 | } 14 | return ans 15 | } 16 | -------------------------------------------------------------------------------- /src/0242-Valid-Anagram/0242.go: -------------------------------------------------------------------------------- 1 | package validanagram 2 | 3 | func isAnagram(s string, t string) bool { 4 | if len(s) != len(t) { 5 | return false 6 | } 7 | mp := make(map[rune]int, 0) 8 | for _, v := range s { 9 | mp[v]++ 10 | } 11 | for _, v := range t { 12 | mp[v]-- 13 | if mp[v] < 0 { 14 | return false 15 | } 16 | } 17 | return true 18 | } 19 | -------------------------------------------------------------------------------- /src/0253-Meeting-Rooms-II/0253.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minMeetingRooms(self, intervals): 3 | if not intervals: 4 | return 0 5 | tmp = sorted(x for i, j in intervals for x in [[i, 1], [j, -1]]) 6 | res, n = 0, 0 7 | for _, v in tmp: 8 | n += v 9 | res = max(res, n) 10 | return res -------------------------------------------------------------------------------- /src/0263-Ugly-Number/0263.go: -------------------------------------------------------------------------------- 1 | package uglynumber 2 | 3 | func isUgly(n int) bool { 4 | if n == 0 { 5 | return false 6 | } 7 | fact := [3]int{2, 3, 5} 8 | for i := 0; i < len(fact); i++ { 9 | for n%fact[i] == 0 { 10 | n /= fact[i] 11 | } 12 | } 13 | if n == 1 { 14 | return true 15 | } 16 | return false 17 | } 18 | -------------------------------------------------------------------------------- /src/0263-Ugly-Number/0263.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isUgly(self, num: int) -> bool: 3 | for p in [2, 3, 5]: 4 | while num and num%p == 0: 5 | num //= p 6 | return num == 1 -------------------------------------------------------------------------------- /src/0268-Missing-Number/0268.go: -------------------------------------------------------------------------------- 1 | package missingnumber 2 | 3 | func missingNumber(nums []int) int { 4 | ans := 0 5 | for idx, val := range nums { 6 | ans ^= idx 7 | ans ^= val 8 | } 9 | return ans ^ len(nums) 10 | } 11 | -------------------------------------------------------------------------------- /src/0268-Missing-Number/0268.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: int 6 | """ 7 | n = len(nums) 8 | return n*(n+1)// 2 - sum(nums) 9 | 10 | if __name__ == "__main__": 11 | nums = [3,0,1] 12 | print(Solution().missingNumber(nums)) -------------------------------------------------------------------------------- /src/0274-H-Index/0274.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int hIndex(vector& citations) 5 | { 6 | int n = citations.size(); 7 | vector cnt(n + 1, 0); 8 | for (int c : citations) cnt[min(c, n)]++; 9 | 10 | int i = n; 11 | for (int total = cnt[n]; i > total; total += cnt[i]) --i; 12 | return i; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/0274-H-Index/0274.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hIndex(self, citations: List[int]) -> int: 3 | n = len(citations) 4 | cnt = [0] * (n + 1) 5 | for c in citations: 6 | cnt[min(n, c)] += 1 7 | 8 | i, total = n, cnt[-1] 9 | while total < i: 10 | i -= 1 11 | total += cnt[i] 12 | return i -------------------------------------------------------------------------------- /src/0278-First-Bad-Version/0278.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int firstBadVersion(int n) { 5 | int l = 0, r = n; 6 | while (l < r) 7 | { 8 | int mid = (r - l)/2 + l; 9 | if (isBadVersion(mid)) r = mid; 10 | else l = mid + 1; 11 | } 12 | return l; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/0278-First-Bad-Version/0278.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstBadVersion(self, n): 3 | """ 4 | :type n: int 5 | :rtype: int 6 | """ 7 | l, r = 0, n 8 | while l < r: 9 | mid = (l + r) >> 1 10 | if isBadVersion(mid): 11 | r = mid 12 | else: 13 | l = mid + 1 14 | return l -------------------------------------------------------------------------------- /src/0279-Perfect-Squares/0279.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0279-Perfect-Squares/0279.cpp -------------------------------------------------------------------------------- /src/0319-Bulb-Switcher/0319.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | int bulbSwitch(int n) 6 | { 7 | return sqrt(n); 8 | } 9 | }; -------------------------------------------------------------------------------- /src/0319-Bulb-Switcher/0319.go: -------------------------------------------------------------------------------- 1 | package bulbswitcher 2 | 3 | import "math" 4 | 5 | func bulbSwitch(n int) int { 6 | return int(math.Sqrt(float64(n))) 7 | } 8 | -------------------------------------------------------------------------------- /src/0319-Bulb-Switcher/0319.py: -------------------------------------------------------------------------------- 1 | import math 2 | class Solution: 3 | def bulbSwitch(self, n: int) -> int: 4 | return int(math.sqrt(n)) -------------------------------------------------------------------------------- /src/0326-Power-of-Three/0326.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) { 4 | return n > 0 && 1162261467 % n == 0; 5 | } 6 | }; -------------------------------------------------------------------------------- /src/0326-Power-of-Three/0326.go: -------------------------------------------------------------------------------- 1 | package powerofthree 2 | 3 | func isPowerOfThree(n int) bool { 4 | if n < 1 { 5 | return false 6 | } 7 | for n%3 == 0 { 8 | n /= 3 9 | } 10 | return n == 1 11 | } 12 | -------------------------------------------------------------------------------- /src/0326-Power-of-Three/0326.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn is_power_of_three(n: i32) -> bool { 3 | n > 0 && 1162261467 % n == 0 4 | } 5 | } -------------------------------------------------------------------------------- /src/0331-Verify-Preorder-Serialization-of-a-Binary-Tree/0331.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isValidSerialization(self, preorder: str) -> bool: 3 | nodes = preorder.split(",") 4 | dif = 1 5 | for node in nodes: 6 | dif -= 1 7 | if dif < 0: 8 | return False 9 | if node != "#": 10 | dif += 2 11 | return dif == 0 -------------------------------------------------------------------------------- /src/0344-Reverse-String/0344.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func reverseString(s []byte) { 4 | for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { 5 | s[i], s[j] = s[j], s[i] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/0344-Reverse-String/0344.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseString(self, s): 3 | """ 4 | :type s: str 5 | :rtype: str 6 | """ 7 | return s[::-1] 8 | 9 | if __name__ == "__main__": 10 | s = "hello" 11 | print(Solution().reverseString(s)) -------------------------------------------------------------------------------- /src/0365-Water-and-Jug-Problem/0365.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canMeasureWater(int x, int y, int z) { 4 | if (x + y < z) return false; 5 | if (x == 0 || y == 0) return z == 0 || x + y == z; 6 | return z % gcd(x, y) == 0; 7 | } 8 | }; -------------------------------------------------------------------------------- /src/0365-Water-and-Jug-Problem/0365.go: -------------------------------------------------------------------------------- 1 | func canMeasureWater(x int, y int, z int) bool { 2 | if x + y < z { 3 | return false 4 | } 5 | 6 | if x == 0 || y == 0 { 7 | return z == 0 || x + y == z 8 | } 9 | return z % gcd(x, y) == 0 10 | } 11 | 12 | func gcd(a, b int) int { 13 | if b == 0 { 14 | return a 15 | } 16 | return gcd(b, a % b) 17 | } -------------------------------------------------------------------------------- /src/0365-Water-and-Jug-Problem/0365.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canMeasureWater(int x, int y, int z) { 3 | if (x + y < z) return false; 4 | if (x == 0 || y == 0) return z == 0 || x + y == z; 5 | return z % gcd(x, y) == 0; 6 | } 7 | 8 | private int gcd(int a, int b) { 9 | return b == 0 ? a : gcd(b, a % b); 10 | } 11 | } -------------------------------------------------------------------------------- /src/0365-Water-and-Jug-Problem/0365.js: -------------------------------------------------------------------------------- 1 | var canMeasureWater = function(x, y, z) { 2 | let gcd = function(a, b) { 3 | return b == 0 ? a : gcd(b, a % b); 4 | } 5 | 6 | if (x + y < z) return false; 7 | if (x == 0 || y == 0) return z == 0 || x + y == z; 8 | return z % gcd(x, y) == 0; 9 | }; -------------------------------------------------------------------------------- /src/0365-Water-and-Jug-Problem/0365.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canMeasureWater(self, x: int, y: int, z: int) -> bool: 3 | if x + y < z: 4 | return False 5 | if x == 0 or y == 0: 6 | return z == 0 or x + y == z 7 | return z % math.gcd(x, y) == 0 -------------------------------------------------------------------------------- /src/0371-Sum-of-Two-Integers/0371.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int getSum(int a, int b) 5 | { 6 | if (!b) return a; 7 | long long sum = a ^ b, carry = (a & b & 0xffffffff) << 1; 8 | return getSum(sum, carry); 9 | } 10 | }; -------------------------------------------------------------------------------- /src/0371-Sum-of-Two-Integers/0371.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getSum(self, a: int, b: int) -> int: 3 | mask = 0xffffffff 4 | while b & mask: 5 | a, b = a ^ b, (a & b) << 1 6 | 7 | return a & mask if b > mask else a -------------------------------------------------------------------------------- /src/0371-Sum-of-Two-Integers/0371.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn get_sum(mut a: i32, mut b: i32) -> i32 { 3 | while b != 0 { 4 | let c = (a & b) << 1; 5 | a = a ^ b; 6 | b = c; 7 | } 8 | a 9 | } 10 | } -------------------------------------------------------------------------------- /src/0409-Longest-Palindrome/0409.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestPalindrome(string s) { 4 | int cnt[128] = {}; 5 | for (char c : s) cnt[c]++; 6 | 7 | int res = 0; 8 | for (int v : cnt) res += v / 2 * 2; 9 | return res == s.size() ? res : res + 1; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/0409-Longest-Palindrome/0409.go: -------------------------------------------------------------------------------- 1 | func longestPalindrome(s string) int { 2 | cnt := make([]int, 128) 3 | for _, c := range s { 4 | cnt[c]++ 5 | } 6 | 7 | res := 0 8 | for _, i := range cnt { 9 | res += i / 2 * 2 10 | } 11 | if res == len(s) { 12 | return res 13 | } 14 | return res + 1 15 | } -------------------------------------------------------------------------------- /src/0409-Longest-Palindrome/0409.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestPalindrome(String s) { 3 | int[] cnt = new int[128]; 4 | for (char c : s.toCharArray()) cnt[c]++; 5 | 6 | int res = 0; 7 | for (int i : cnt) res += i / 2 * 2; 8 | return res == s.length() ? res : res + 1; 9 | } 10 | } -------------------------------------------------------------------------------- /src/0409-Longest-Palindrome/0409.js: -------------------------------------------------------------------------------- 1 | var longestPalindrome = function(s) { 2 | let cnt = new Array(128).fill(0); 3 | for (let c of s) cnt[c.charCodeAt()]++; 4 | 5 | let res = 0; 6 | for (let i of cnt) res += Math.floor(i / 2) * 2; 7 | return res == s.length ? res : res + 1; 8 | }; -------------------------------------------------------------------------------- /src/0409-Longest-Palindrome/0409.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestPalindrome(self, s: str) -> int: 3 | cnt = collections.Counter(s) 4 | res = sum(i // 2 * 2 for i in cnt.values()) 5 | return res + 1 if res < len(s) else res -------------------------------------------------------------------------------- /src/0451-Sort-Characters-By-Frequency/0451.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string frequencySort(string s) { 4 | vector v(127); 5 | for (auto i : s) v[i] += i; 6 | sort(v.begin(), v.end(), 7 | [](const auto& s1, const auto& s2) { return s1.size() > s2.size(); }); 8 | stringstream res; 9 | for (auto i : v) res << i; 10 | return res.str(); 11 | } 12 | }; -------------------------------------------------------------------------------- /src/0451-Sort-Characters-By-Frequency/0451.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def frequencySort(self, s): 3 | """ 4 | :type s: str 5 | :rtype: str 6 | """ 7 | return ''.join(c*-n for n,c in sorted((-s.count(c),c)for c in set(s))) 8 | 9 | 10 | if __name__ == "__main__": 11 | s = "abcc" 12 | print(Solution().frequencySort(s)) -------------------------------------------------------------------------------- /src/0453-Minimum-Moves-to-Equal-Array-Elements/0453.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minMoves(vector& nums) { 4 | int minNum = *min_element(nums.begin(), nums.end()); 5 | int res = 0; 6 | for (int num : nums) { 7 | res += num - minNum; 8 | } 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/0453-Minimum-Moves-to-Equal-Array-Elements/0453.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minMoves(self, nums: List[int]) -> int: 3 | min_num = min(nums) 4 | res = 0 5 | for num in nums: 6 | res += num - min_num 7 | return res -------------------------------------------------------------------------------- /src/0453-Minimum-Moves-to-Equal-Array-Elements/0453.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn min_moves(nums: Vec) -> i32 { 3 | let min_num = nums.iter().min().unwrap(); 4 | let mut res = 0; 5 | for num in nums.iter() { 6 | res += num - min_num; 7 | } 8 | res 9 | } 10 | } -------------------------------------------------------------------------------- /src/0458-Poor-Pigs/0458.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | int poorPigs(int buckets, int minutesToTest, int minutesToTest) 6 | { 7 | int b = minutesToTest / minutesToTest + 1; 8 | int k = 0, n = 1; 9 | while (n < buckets) ++k, n *= b; 10 | return k; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/0458-Poor-Pigs/0458.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int: 3 | b = minutesToTest // minutesToDie + 1 4 | k, n = 0, 1 5 | while n < buckets: 6 | k += 1 7 | n *= b 8 | return k -------------------------------------------------------------------------------- /src/0458-Poor-Pigs/0458.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn poor_pigs(buckets: i32, minutes_to_die: i32, minutes_to_test: i32) -> i32 { 3 | let states = minutes_to_test / minutes_to_die + 1; 4 | ((buckets as f32).log2() / (states as f32).log2()).ceil() as i32 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/0459-Repeated-Substring-Pattern/0459.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool repeatedSubstringPattern(string s) 5 | { 6 | return (s + s).substr(1, s.size() * 2 - 2).find(s) != -1; 7 | } 8 | }; -------------------------------------------------------------------------------- /src/0459-Repeated-Substring-Pattern/0459.go: -------------------------------------------------------------------------------- 1 | func repeatedSubstringPattern(s string) bool { 2 | t := s + s 3 | return strings.Contains(t[1:len(t)-1], s) 4 | } -------------------------------------------------------------------------------- /src/0459-Repeated-Substring-Pattern/0459.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean repeatedSubstringPattern(String s) { 3 | return (s + s).substring(1, 2 * s.length() - 1).contains(s); 4 | } 5 | } -------------------------------------------------------------------------------- /src/0459-Repeated-Substring-Pattern/0459.js: -------------------------------------------------------------------------------- 1 | var repeatedSubstringPattern = function(s) { 2 | return (s + s).slice(1, -1).indexOf(s) != -1; 3 | }; -------------------------------------------------------------------------------- /src/0459-Repeated-Substring-Pattern/0459.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedSubstringPattern(self, s: str) -> bool: 3 | return s in (2 * s)[1:-1] -------------------------------------------------------------------------------- /src/0462-Minimum-Moves-to-Equal-Array-Elements-II/0462.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minMoves2(self, nums: List[int]) -> int: 3 | nums.sort() 4 | return sum(nums[~i] - nums[i] for i in range(len(nums) // 2)) -------------------------------------------------------------------------------- /src/0492-Construct-the-Rectangle/0492.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector constructRectangle(int area) { 4 | int w = sqrt(area); 5 | while (area % w) { 6 | --w; 7 | } 8 | return {area / w, w}; 9 | } 10 | }; -------------------------------------------------------------------------------- /src/0492-Construct-the-Rectangle/0492.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn construct_rectangle(area: i32) -> Vec { 3 | let mut w = (area as f32).sqrt() as i32; 4 | while area % w != 0 { 5 | w -= 1; 6 | } 7 | vec![area / w, w] 8 | } 9 | } -------------------------------------------------------------------------------- /src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.go -------------------------------------------------------------------------------- /src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.java -------------------------------------------------------------------------------- /src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0524-Longest-Word-in-Dictionary-through-Deleting/0524.js -------------------------------------------------------------------------------- /src/0559-Maximum-Depth-of-N-ary-Tree/0559.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDepth(Node* root) { 4 | if (root == nullptr) { 5 | return 0; 6 | } 7 | int res = 0; 8 | for (auto c : root->children) { 9 | res = max(res, maxDepth(c)); 10 | } 11 | return res + 1; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/0559-maximum-depth-of-n-ary-tree/0559.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDepth(Node* root) { 4 | if (root == nullptr) { 5 | return 0; 6 | } 7 | int res = 0; 8 | for (auto c : root->children) { 9 | res = max(res, maxDepth(c)); 10 | } 11 | return res + 1; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/0583-Delete-Operation-for-Two-Strings/0583.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0583-Delete-Operation-for-Two-Strings/0583.go -------------------------------------------------------------------------------- /src/0583-Delete-Operation-for-Two-Strings/0583.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0583-Delete-Operation-for-Two-Strings/0583.java -------------------------------------------------------------------------------- /src/0583-Delete-Operation-for-Two-Strings/0583.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0583-Delete-Operation-for-Two-Strings/0583.js -------------------------------------------------------------------------------- /src/0583-Delete-Operation-for-Two-Strings/0583.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0583-Delete-Operation-for-Two-Strings/0583.py -------------------------------------------------------------------------------- /src/0594-Longest-Harmonious-Subsequence/0594.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLHS(vector& nums) { 4 | unordered_map cnt; 5 | int res = 0; 6 | for (int num : nums) cnt[num]++; 7 | for (auto& [k, v] : cnt) { 8 | if (cnt.count(k + 1)) { 9 | res = max(res, v + cnt[k + 1]); 10 | } 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/0594-longest-harmonious-subsequence/0594.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLHS(vector& nums) { 4 | unordered_map cnt; 5 | int res = 0; 6 | for (int num : nums) cnt[num]++; 7 | for (auto& [k, v] : cnt) { 8 | if (cnt.count(k + 1)) { 9 | res = max(res, v + cnt[k + 1]); 10 | } 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/0650-2-Keys-Keyboard/0650.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSteps(self, n: int) -> int: 3 | i, res = 2, 0 4 | while n > 1: 5 | while n % i == 0: 6 | res += i 7 | n //= i 8 | i += 1 9 | return res -------------------------------------------------------------------------------- /src/0653-Two-Sum-IV-Input-is-a-BST/0653.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool findTarget(TreeNode* root, int k) 5 | { 6 | if (!root) return false; 7 | if (seen.count(k - root->val)) return true; 8 | seen.insert(root->val); 9 | return findTarget(root->left, k) or findTarget(root->right, k); 10 | } 11 | private: 12 | unordered_set seen; 13 | }; -------------------------------------------------------------------------------- /src/0678-Valid-Parenthesis-String/0678.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0678-Valid-Parenthesis-String/0678.go -------------------------------------------------------------------------------- /src/0678-Valid-Parenthesis-String/0678.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0678-Valid-Parenthesis-String/0678.java -------------------------------------------------------------------------------- /src/0678-Valid-Parenthesis-String/0678.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0678-Valid-Parenthesis-String/0678.js -------------------------------------------------------------------------------- /src/0678-Valid-Parenthesis-String/0678.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0678-Valid-Parenthesis-String/0678.py -------------------------------------------------------------------------------- /src/0700-Search-in-a-Binary-Search-Tree/0700.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode *searchBST(TreeNode *root, int val) { 4 | if (root == nullptr) { 5 | return nullptr; 6 | } 7 | if (val == root->val) { 8 | return root; 9 | } 10 | return searchBST(val < root->val ? root->left : root->right, val); 11 | } 12 | }; -------------------------------------------------------------------------------- /src/0790-Domino-and-Tromino-Tiling/0790.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numTilings(int n) { 4 | if (n == 1) return 1; 5 | int mod = 1e9 + 7; 6 | long long a = 1, b = 1, c = 2; 7 | for (int i = 3; i <= n; ++i) { 8 | long long d = (c * 2 + a) % mod; 9 | a = b; 10 | b = c; 11 | c = d; 12 | } 13 | return c; 14 | } 15 | }; -------------------------------------------------------------------------------- /src/0793-Preimage-Size-of-Factorial-Zeroes-Function/0793.go: -------------------------------------------------------------------------------- 1 | func preimageSizeFZF(K int) int { 2 | x := 1 3 | for x < K { 4 | x = x * 5 + 1 5 | } 6 | 7 | for x > 1 { 8 | K %= x 9 | if x - 1 == K { 10 | return 0 11 | } 12 | x = (x - 1) / 5 13 | } 14 | return 5 15 | } -------------------------------------------------------------------------------- /src/0793-Preimage-Size-of-Factorial-Zeroes-Function/0793.js: -------------------------------------------------------------------------------- 1 | var preimageSizeFZF = function(K) { 2 | let x = 1; 3 | while (x < K) x = x * 5 + 1; 4 | while (x > 1) { 5 | K %= x; 6 | if (x - 1 == K) return 0; 7 | x = Math.floor((x - 1) / 5); 8 | } 9 | return 5; 10 | }; -------------------------------------------------------------------------------- /src/0793-Preimage-Size-of-Factorial-Zeroes-Function/0793.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def preimageSizeFZF(self, K: 'int') -> 'int': 3 | x = 1 4 | while x < K: 5 | x = x * 5 + 1 6 | 7 | while x > 1: 8 | K %= x 9 | if x - 1 == K: 10 | return 0 11 | x = (x - 1) // 5 12 | return 5 -------------------------------------------------------------------------------- /src/0795-Number-of-Subarrays-with-Bounded-Maximum/0795.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numSubarrayBoundedMax(vector &nums, int left, int right) { 4 | int n = nums.size(), res = 0, i0 = -1, i1 = -1; 5 | for (int i = 0; i < n; ++i) { 6 | if (nums[i] > right) i0 = i; 7 | if (nums[i] >= left) i1 = i; 8 | res += i1 - i0; 9 | } 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/0824-Goat-Latin/0824.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toGoatLatin(self, S: str) -> str: 3 | res, vowels = [], set("aeiouAEIOU") 4 | S = S.split(" ") 5 | for i, w in enumerate(S): 6 | if w[0] not in vowels: 7 | w = w[1:] + w[0] 8 | res.append(w + "ma" + (i + 1) * "a") 9 | return " ".join(res) -------------------------------------------------------------------------------- /src/0828-Unique-Letter-String/0828.go: -------------------------------------------------------------------------------- 1 | func uniqueLetterString(S string) int { 2 | res, f, mod := 0, 0, 1000000007 3 | m := make([]int, 26) 4 | n := make([]int, 26) 5 | for i, v := range S { 6 | t := int(v) - 65 7 | f = f + 1 + i - 2 * m[t] + n[t] 8 | res = (res + f) % mod 9 | n[t], m[t] = m[t], i + 1 10 | } 11 | return res 12 | } -------------------------------------------------------------------------------- /src/0828-Unique-Letter-String/0828.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueLetterString(self, S: str) -> int: 3 | res, mod, f = 0, 10**9 + 7, 0 4 | m, n = [0]*26, [0]*26 5 | for i, v in enumerate(S): 6 | t = ord(v) - 65 7 | f = f + 1 + i - 2 * m[t] + n[t] 8 | res = (res + f) % mod 9 | n[t], m[t] = m[t], i + 1 10 | return res -------------------------------------------------------------------------------- /src/0836-Rectangle-Overlap/0836.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isRectangleOverlap(vector& r1, vector& r2) { 4 | return r1[0] < r2[2] && r1[1] < r2[3] && r1[2] > r2[0] && r1[3] > r2[1]; 5 | } 6 | }; -------------------------------------------------------------------------------- /src/0836-Rectangle-Overlap/0836.go: -------------------------------------------------------------------------------- 1 | func isRectangleOverlap(r1 []int, r2 []int) bool { 2 | return r1[0] < r2[2] && r1[1] < r2[3] && r1[2] > r2[0] && r1[3] > r2[1] 3 | } -------------------------------------------------------------------------------- /src/0836-Rectangle-Overlap/0836.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isRectangleOverlap(int[] r1, int[] r2) { 3 | return r1[0] < r2[2] && r1[1] < r2[3] && r1[2] > r2[0] && r1[3] > r2[1]; 4 | } 5 | } -------------------------------------------------------------------------------- /src/0836-Rectangle-Overlap/0836.js: -------------------------------------------------------------------------------- 1 | var isRectangleOverlap = function(r1, r2) { 2 | return r1[0] < r2[2] && r1[1] < r2[3] && r1[2] > r2[0] && r1[3] > r2[1]; 3 | }; -------------------------------------------------------------------------------- /src/0836-Rectangle-Overlap/0836.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isRectangleOverlap(self, r1: List[int], r2: List[int]) -> bool: 3 | return r1[0] < r2[2] and r1[1] < r2[3] and r1[2] > r2[0] and r1[3] > r2[1] -------------------------------------------------------------------------------- /src/0876-Middle-of-the-Linked-List/0876.go: -------------------------------------------------------------------------------- 1 | func middleNode(head *ListNode) *ListNode { 2 | fast, slow := head, head 3 | for fast.Next != nil && fast.Next.Next != nil { 4 | fast = fast.Next.Next; 5 | slow = slow.Next; 6 | } 7 | 8 | if fast.Next != nil && fast.Next.Next == nil { 9 | return slow.Next 10 | } 11 | return slow 12 | } -------------------------------------------------------------------------------- /src/0876-Middle-of-the-Linked-List/0876.js: -------------------------------------------------------------------------------- 1 | var middleNode = function(head) { 2 | let fast = head, slow = head; 3 | while (fast.next != null && fast.next.next != null) { 4 | fast = fast.next.next; 5 | slow = slow.next; 6 | } 7 | 8 | if (fast.next != null && fast.next.next == null) return slow.next; 9 | return slow; 10 | }; -------------------------------------------------------------------------------- /src/0876-Middle-of-the-Linked-List/0876.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def middleNode(self, head: ListNode) -> ListNode: 3 | fast, slow = head, head 4 | while fast.next and fast.next.next: 5 | fast = fast.next.next 6 | slow = slow.next 7 | 8 | if fast.next and not fast.next.next: 9 | return slow.next 10 | return slow -------------------------------------------------------------------------------- /src/0891-Sum-of-Subsequence-Widths/0891.go: -------------------------------------------------------------------------------- 1 | func sumSubseqWidths(A []int) int { 2 | sort.Ints(A) 3 | res, n, mod := 0, len(A), 1000000007 4 | for i := 0; i < n; i++ { 5 | res *= 2 6 | res -= A[i] 7 | res += A[n - i - 1] 8 | res %= mod 9 | } 10 | return (res + mod) % mod 11 | } -------------------------------------------------------------------------------- /src/0891-Sum-of-Subsequence-Widths/0891.js: -------------------------------------------------------------------------------- 1 | var sumSubseqWidths = function(A) { 2 | A.sort((a, b) => a - b); 3 | let res = 0, mod = 1e9 + 7, n = A.length; 4 | for (let i = 0; i < n; i++) { 5 | res <<= 1; 6 | res -= A[i]; 7 | res += A[n - i - 1]; 8 | res %= mod; 9 | } 10 | return (res + mod)%mod; 11 | }; -------------------------------------------------------------------------------- /src/0891-Sum-of-Subsequence-Widths/0891.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumSubseqWidths(self, A: List[int]) -> int: 3 | return sum(((1 << i) - (1 << len(A) - i - 1)) * a for i, a in enumerate(sorted(A))) % (10**9 + 7) -------------------------------------------------------------------------------- /src/0914-X-of-a-Kind-in-a-Deck-of-Cards/0914.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasGroupsSizeX(self, deck: List[int]) -> bool: 3 | return functools.reduce(math.gcd, collections.Counter(deck).values()) >= 2 -------------------------------------------------------------------------------- /src/0944-Delete-Columns-to-Make-Sorted/0944.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minDeletionSize(self, A): 3 | """ 4 | :type A: List[str] 5 | :rtype: int 6 | """ 7 | return sum(list(a) != sorted(a) for a in zip(*A)) 8 | 9 | if __name__ == "__main__": 10 | A = ["cba","daf","ghi"] 11 | print(Solution().minDeletionSize(A)) -------------------------------------------------------------------------------- /src/0946-Validate-Stack-Sequences/0946.go: -------------------------------------------------------------------------------- 1 | func validateStackSequences(pushed []int, popped []int) bool { 2 | i, j := 0, 0 3 | 4 | for _, v := range pushed { 5 | pushed[i] = v 6 | i++ 7 | for i > 0 && pushed[i - 1] == popped[j] { 8 | i-- 9 | j++ 10 | } 11 | } 12 | 13 | return i == 0 14 | } -------------------------------------------------------------------------------- /src/0946-Validate-Stack-Sequences/0946.js: -------------------------------------------------------------------------------- 1 | var validateStackSequences = function(pushed, popped) { 2 | let i = 0, j = 0; 3 | 4 | for (let num of pushed) { 5 | pushed[i] = num; 6 | i++; 7 | while (i > 0 && pushed[i - 1] == popped[j]) i--, j++; 8 | } 9 | 10 | return i == 0; 11 | }; -------------------------------------------------------------------------------- /src/0946-Validate-Stack-Sequences/0946.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool: 3 | i = j = 0 4 | 5 | for x in pushed: 6 | pushed[i] = x 7 | i += 1 8 | while i > 0 and pushed[i - 1] == popped[j]: 9 | i, j = i - 1, j + 1 10 | 11 | return i == 0 -------------------------------------------------------------------------------- /src/0961-N-Repeated-Element-in-Size-2N-Array/0961.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedNTimes(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | for i in range(len(A)): 8 | if A[i - 1] == A[i] or A[i - 2] == A[i]: 9 | return A[i] -------------------------------------------------------------------------------- /src/0965-Univalued-Binary-Tree/0965.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | bool isUnivalTree(TreeNode* r, int v = -1) 6 | { 7 | return r == nullptr || ((v == -1 || r->val == v) && 8 | isUnivalTree(r->left, r->val) && isUnivalTree(r->right, r->val)); 9 | } 10 | }; -------------------------------------------------------------------------------- /src/0969-Pancake-Sorting/0969.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def pancakeSort(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: List[int] 6 | """ 7 | res = list() 8 | for i in range(len(A), 1, -1): 9 | idx = A.index(i) 10 | A = A[:idx:-1] + A[:idx] 11 | res += [idx + 1, i] 12 | 13 | return res -------------------------------------------------------------------------------- /src/0973-K-Closest-Points-to-Origin/0973.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | class Solution: 3 | def kClosest(self, points, K): 4 | """ 5 | :type points: List[List[int]] 6 | :type K: int 7 | :rtype: List[List[int]] 8 | """ 9 | return heapq.nsmallest(K, points, lambda p: p[0]**2 + p[1]**2) -------------------------------------------------------------------------------- /src/0976-Largest-Perimeter-Triangle/0976.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestPerimeter(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: int 6 | """ 7 | A.sort(reverse=True) 8 | for i in range(len(A)-2): 9 | if A[i+2] + A[i+1] > A[i]: 10 | return A[i] + A[i+1] + A[i+2] 11 | 12 | return 0 -------------------------------------------------------------------------------- /src/0977-Squares-of-a-Sorted-Array/0977.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortedSquares(self, A): 3 | """ 4 | :type A: List[int] 5 | :rtype: List[int] 6 | """ 7 | return sorted([i**2 for i in A]) -------------------------------------------------------------------------------- /src/0987-Vertical-Order-Traversal-of-a-Binary-Tree/0987.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/0987-Vertical-Order-Traversal-of-a-Binary-Tree/0987.py -------------------------------------------------------------------------------- /src/0989-Add-to-Array-Form-of-Integer/0989.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addToArrayForm(self, A: 'List[int]', K: 'int') -> 'List[int]': 3 | for i in range(len(A))[::-1]: 4 | A[i], K = (A[i] + K) % 10, (A[i] + K) // 10 5 | return [int(i) for i in str(K)] + A if K else A -------------------------------------------------------------------------------- /src/0991-Broken-Calculator/0991.cpp: -------------------------------------------------------------------------------- 1 | static int x = [](){std::ios::sync_with_stdio(false);cin.tie(0);return 0;}(); 2 | class Solution 3 | { 4 | public: 5 | int brokenCalc(int X, int Y) 6 | { 7 | if (X >= Y) return X - Y; 8 | return 1 + brokenCalc(X, Y % 2 ? Y + 1: Y / 2); 9 | } 10 | }; -------------------------------------------------------------------------------- /src/0991-Broken-Calculator/0991.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def brokenCalc(self, X: 'int', Y: 'int') -> 'int': 3 | if X >= Y: 4 | return X - Y 5 | return 1 + self.brokenCalc(X, Y + 1 if Y % 2 else Y // 2) -------------------------------------------------------------------------------- /src/0997-Find-the-Town-Judge/0997.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findJudge(self, N: int, trust: List[List[int]]) -> int: 3 | count = [0] * (N + 1) 4 | for i, j in trust: 5 | count[i] -= 1 6 | count[j] += 1 7 | for i in range(1, N + 1): 8 | if count[i] == N - 1: 9 | return i 10 | return -1 -------------------------------------------------------------------------------- /src/1001-Grid-Illumination/1001.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1001-Grid-Illumination/1001.py -------------------------------------------------------------------------------- /src/1002-Find-Common-Characters/1002.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def commonChars(self, A: List[str]) -> List[str]: 4 | return list(reduce(collections.Counter.__and__, map(collections.Counter, A)).elements()) -------------------------------------------------------------------------------- /src/1004-Max-Consecutive-Ones-III/1004.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestOnes(self, A: List[int], K: int) -> int: 3 | n = len(A) 4 | zeros = res = l = 0 5 | for r in range(n): 6 | zeros += 1 - A[r] 7 | if zeros > K: 8 | zeros -= 1 - A[l] 9 | l += 1 10 | res = r - l + 1 11 | return res -------------------------------------------------------------------------------- /src/1005-Maximize-Sum-Of-Array-After-K-Negations/1005.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestSumAfterKNegations(self, A: List[int], K: int) -> int: 3 | A.sort() 4 | i = 0 5 | while i < len(A) and i < K and A[i] < 0: 6 | A[i] = -A[i] 7 | i += 1 8 | return sum(A) - (K - i)%2*min(A)*2 -------------------------------------------------------------------------------- /src/1006-Clumsy-Factorial/1006.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def clumsy(self, N: int) -> int: 3 | if N <= 2: 4 | return N 5 | if N <= 4: 6 | return N + 3 7 | 8 | if (N - 4) % 4 == 0: 9 | return N + 1 10 | elif (N - 4) % 4 <= 2: 11 | return N + 2 12 | else: 13 | return N - 1 -------------------------------------------------------------------------------- /src/1007-Minimum-Domino-Rotations-For-Equal-Row/1007.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minDominoRotations(self, A: List[int], B: List[int]) -> int: 3 | for i in range(1,7): 4 | if all(i == a or i == b for a,b in zip(A,B)): 5 | return min(len(A)-A.count(i),len(B)-B.count(i)) 6 | 7 | return -1 -------------------------------------------------------------------------------- /src/1009-Complement-of-Base-10-Integer/1009.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | int bitwiseComplement(int N) 6 | { 7 | int X = 1; 8 | while (X < N) 9 | { 10 | X = (X << 1) + 1; 11 | } 12 | return X ^ N; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1009-Complement-of-Base-10-Integer/1009.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bitwiseComplement(self, N: int) -> int: 3 | X = 1 4 | while X < N: 5 | X = (X << 1) + 1 6 | 7 | return N ^ X -------------------------------------------------------------------------------- /src/1010-Pairs-of-Songs-With-Total-Durations-Divisible-by-60/1010.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def numPairsDivisibleBy60(self, time: List[int]) -> int: 4 | cnt = Counter() 5 | res = 0 6 | for t in time: 7 | res += cnt[-t % 60]#trick 8 | cnt[t % 60] += 1 9 | return res -------------------------------------------------------------------------------- /src/1011-Capacity-To-Ship-Packages-Within-D-Days/1011.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1011-Capacity-To-Ship-Packages-Within-D-Days/1011.py -------------------------------------------------------------------------------- /src/1014-Best-Sightseeing-Pair/1014.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScoreSightseeingPair(self, A: List[int]) -> int: 3 | sell, buy = 0, float('-inf') 4 | for i, val in enumerate(A): 5 | sell = max(sell, val - i + buy) 6 | buy = max(buy, val + i) 7 | return sell -------------------------------------------------------------------------------- /src/1015-Smallest-Integer-Divisible-by-K/1015.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestRepunitDivByK(self, K: int) -> int: 3 | if K % 2 == 0 or K % 5 == 0: 4 | return -1 5 | 6 | r = 0 7 | for N in range(1, K + 1): 8 | r = (r * 10 + 1) % K 9 | if r == 0: 10 | return N -------------------------------------------------------------------------------- /src/1018-Binary-Prefix-Divisible-By-5/1018.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def prefixesDivBy5(self, A: List[int]) -> List[bool]: 3 | for i in range(1, len(A)): 4 | A[i] += A[i - 1] * 2 % 5 5 | return [a % 5 == 0 for a in A] -------------------------------------------------------------------------------- /src/1021-Remove-Outermost-Parentheses/1021.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeOuterParentheses(self, S: str) -> str: 3 | res, opened = "", 0 4 | for c in S: 5 | if c == '(' and opened > 0: 6 | res += c 7 | if c == ')' and opened > 1: 8 | res += c 9 | opened += 1 if c == '(' else -1 10 | return res -------------------------------------------------------------------------------- /src/1022-Sum-of-Root-To-Leaf-Binary-Numbers/1022.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1022-Sum-of-Root-To-Leaf-Binary-Numbers/1022.cpp -------------------------------------------------------------------------------- /src/1022-Sum-of-Root-To-Leaf-Binary-Numbers/1022.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1022-Sum-of-Root-To-Leaf-Binary-Numbers/1022.py -------------------------------------------------------------------------------- /src/1025-Divisor-Game/1025.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | bool divisorGame(int N) 6 | { 7 | return (N & 1) == 0; 8 | } 9 | }; -------------------------------------------------------------------------------- /src/1025-Divisor-Game/1025.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divisorGame(self, N: int) -> bool: 3 | return N % 2 == 0 -------------------------------------------------------------------------------- /src/1026-Maximum-Difference-Between-Node-and-Ancestor/1026.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxAncestorDiff(self, root: TreeNode, mn=float('inf'), mx=0) -> int: 3 | return max(self.maxAncestorDiff(root.left, min(mn, root.val), max(mx, root.val)), \ 4 | self.maxAncestorDiff(root.right, min(mn, root.val), max(mx, root.val))) \ 5 | if root else mx - mn -------------------------------------------------------------------------------- /src/1033-Moving-Stones-Until-Consecutive/1033.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numMovesStones(self, a: int, b: int, c: int) -> List[int]: 3 | nums = sorted([a, b, c]) 4 | d1, d2 = nums[1] - nums[0], nums[2] - nums[1] 5 | if d1 + d2 == 2: 6 | return [0, 0] 7 | return [1 if min(d1, d2) <= 2 else 2, d1 + d2 - 2] -------------------------------------------------------------------------------- /src/1037-Valid-Boomerang/1037.cpp: -------------------------------------------------------------------------------- 1 | static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }(); 2 | class Solution 3 | { 4 | public: 5 | bool isBoomerang(vector>& p) 6 | { 7 | return (p[0][0] - p[1][0]) * (p[0][1] - p[2][1]) != (p[0][0] - p[2][0]) * (p[0][1] - p[1][1]); 8 | } 9 | }; -------------------------------------------------------------------------------- /src/1037-Valid-Boomerang/1037.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isBoomerang(self, p: List[List[int]]) -> bool: 3 | return (p[0][0] - p[1][0])*(p[0][1] - p[2][1]) != (p[0][0] - p[2][0]) * (p[0][1] - p[1][1]) -------------------------------------------------------------------------------- /src/1038-Binary-Search-Tree-to-Greater-Sum-Tree/1038.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | pre = 0 3 | def bstToGst(self, root: TreeNode) -> TreeNode: 4 | if root.right: 5 | self.bstToGst(root.right) 6 | 7 | root.val = self.pre = self.pre + root.val 8 | if root.left: 9 | self.bstToGst(root.left) 10 | return root -------------------------------------------------------------------------------- /src/1046-Last-Stone-Weight/1046.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | class Solution: 3 | def lastStoneWeight(self, stones: List[int]) -> int: 4 | stones.sort() 5 | while len(stones) > 1: 6 | t1 = stones.pop() 7 | t2 = stones.pop() 8 | if t1 != t2: 9 | bisect.insort_left(stones, t1 - t2) 10 | return stones[0] if stones else 0 -------------------------------------------------------------------------------- /src/1047-Remove-All-Adjacent-Duplicates-In-String/1047.go: -------------------------------------------------------------------------------- 1 | func removeDuplicates(S string) string { 2 | res := make([]rune, 0) 3 | for _, c := range S { 4 | if (len(res) > 0 && res[len(res)-1] == c) { 5 | res = res[:len(res)-1] 6 | } else { 7 | res = append(res, c) 8 | } 9 | } 10 | return string(res) 11 | } -------------------------------------------------------------------------------- /src/1047-Remove-All-Adjacent-Duplicates-In-String/1047.js: -------------------------------------------------------------------------------- 1 | var removeDuplicates = function(S) { 2 | let res = []; 3 | for (let c of S) { 4 | if (res.length > 0 && c == res[res.length - 1]) res.pop(); 5 | else res.push(c); 6 | } 7 | return res.join(''); 8 | }; -------------------------------------------------------------------------------- /src/1047-Remove-All-Adjacent-Duplicates-In-String/1047.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeDuplicates(self, S: str) -> str: 3 | res = list() 4 | for c in S: 5 | if len(res) and res[-1] == c: 6 | res.pop() 7 | else: 8 | res.append(c) 9 | return "".join(res) -------------------------------------------------------------------------------- /src/1048-Longest-String-Chain/1048.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestStrChain(self, words: List[str]) -> int: 3 | words.sort(key=len) 4 | mem = collections.defaultdict(int) 5 | for w in words: 6 | mem[w] = max(mem[w[:i] + w[i + 1:]] + 1 for i in range(len(w))) 7 | return max(mem.values()) -------------------------------------------------------------------------------- /src/1051-Height-Checker/1051.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def heightChecker(self, heights: List[int]) -> int: 3 | return sum(h1 != h2 for h1, h2 in zip(heights, sorted(heights))) -------------------------------------------------------------------------------- /src/1064-Fixed-Point/1064.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fixedPoint(self, A: List[int]) -> int: 3 | l, r = 0, len(A)-1 4 | while l <= r: 5 | mid = l + r >> 1 6 | if A[mid] - mid == 0: 7 | return mid 8 | elif A[mid] - mid < 0: 9 | l = mid + 1 10 | else: 11 | r = mid - 1 12 | return -1 -------------------------------------------------------------------------------- /src/1071-Greatest-Common-Divisor-of-Strings/1071.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | string gcdOfStrings(string s1, string s2) 5 | { 6 | return (s1 + s2 == s2 + s1) ? s1.substr(0, gcd(size(s1), size(s2))) : ""; 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1071-Greatest-Common-Divisor-of-Strings/1071.go: -------------------------------------------------------------------------------- 1 | func gcdOfStrings(s1 string, s2 string) string { 2 | if s1 + s2 == s2 + s1 { 3 | return s1[:gcd(len(s1), len(s2))] 4 | } 5 | return "" 6 | } 7 | 8 | func gcd(a, b int) int { 9 | if b > 0 { 10 | return gcd(b, a % b) 11 | } 12 | return a 13 | } -------------------------------------------------------------------------------- /src/1071-Greatest-Common-Divisor-of-Strings/1071.java: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public String gcdOfStrings(String s1, String s2) 4 | { 5 | return (s1 + s2).compareTo(s2 + s1) == 0 ? s1.substring(0, gcd(s1.length(), s2.length())) : ""; 6 | } 7 | 8 | private int gcd(int a, int b) { 9 | return b > 0 ? gcd(b, a % b) : a; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1071-Greatest-Common-Divisor-of-Strings/1071.js: -------------------------------------------------------------------------------- 1 | var gcdOfStrings = function(s1, s2) { 2 | let gcd = function(a, b) { 3 | return b ? gcd(b, a % b) : a; 4 | } 5 | return s1 + s2 == s2 + s1 ? s1.substring(0, gcd(s1.length, s2.length)) : ""; 6 | }; -------------------------------------------------------------------------------- /src/1071-Greatest-Common-Divisor-of-Strings/1071.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def gcdOfStrings(self, s1: str, s2: str) -> str: 3 | return s1[:math.gcd(len(s1), len(s2))] if s1 + s2 == s2 + s1 else "" -------------------------------------------------------------------------------- /src/1072-Flip-Columns-For-Maximum-Number-of-Equal-Rows/1072.js: -------------------------------------------------------------------------------- 1 | var maxEqualRowsAfterFlips = function(matrix) { 2 | let m = new Map(), res = 0; 3 | 4 | for (let row of matrix) { 5 | let s = ""; 6 | for (let r of row) s += (r ^ row[0]); 7 | m.set(s, (m.get(s) || 0) + 1); 8 | res = Math.max(res, m.get(s)); 9 | } 10 | return res; 11 | }; -------------------------------------------------------------------------------- /src/1072-Flip-Columns-For-Maximum-Number-of-Equal-Rows/1072.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxEqualRowsAfterFlips(self, A: List[List[int]]) -> int: 3 | return max(collections.Counter(tuple(x ^ r[0] for x in r) for r in A).values()) -------------------------------------------------------------------------------- /src/1085-Sum-of-Digits-in-the-Minimum-Number/1085.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int sumOfDigits(vector& A) 5 | { 6 | int min_A = *min_element(A.begin(), A.end()); 7 | int res = 0; 8 | while (min_A) 9 | { 10 | res += min_A%10; 11 | min_A /= 10; 12 | } 13 | return !(res & 1); 14 | } 15 | }; -------------------------------------------------------------------------------- /src/1085-Sum-of-Digits-in-the-Minimum-Number/1085.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfDigits(self, A: List[int]) -> int: 3 | ret = sum([int(i) for i in str(min(A))]) 4 | return 0 if ret & 1 else 1 -------------------------------------------------------------------------------- /src/1089-Duplicate-Zeros/1089.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | void duplicateZeros(vector& arr) 5 | { 6 | int n = arr.size(), j = n + count(arr.begin(), arr.end(), 0); 7 | for (int i = n - 1; i >= 0; --i) 8 | { 9 | if (--j < n) arr[j] = arr[i]; 10 | if (arr[i] == 0 and --j < n) arr[j] = 0; 11 | } 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1099-Two-Sum-Less-Than-K/1099.js: -------------------------------------------------------------------------------- 1 | var twoSumLessThanK = function(A, K) { 2 | var res = -1, n = A.length; 3 | A.sort(); 4 | var l = 0, r = n - 1; 5 | while (l < r) { 6 | var t = (A[l] + A[r]); 7 | if (t >= K) r--; 8 | else { 9 | res = Math.max(res, t); 10 | l++; 11 | } 12 | } 13 | return res; 14 | } -------------------------------------------------------------------------------- /src/1100-Find-K-Length-Substrings-With-No-Repeated-Characters/1100.js: -------------------------------------------------------------------------------- 1 | var numKLenSubstrNoRepeats = function(S, K) { 2 | var res = 0, low = -1; 3 | var usedChar = {}; 4 | for (var i = 0; i < S.length; ++i) { 5 | if (usedChar[S[i]] && usedChar[S[i]] >= low) low = usedChar[S[i]]; 6 | if (i - low >= K) res++; 7 | usedChar[S[i]] = i; 8 | } 9 | return res; 10 | } -------------------------------------------------------------------------------- /src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def pathInZigZagTree(self, label: int) -> List[int]: 3 | res = list() 4 | while 1: 5 | res.append(label) 6 | if label == 1: 7 | break 8 | label >>= 1 9 | label = label ^ (1 << (label.bit_length() - 1)) - 1 10 | return res[::-1] -------------------------------------------------------------------------------- /src/1108-Defanging-an-IP-Address/1108.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | string defangIPaddr(string address) 5 | { 6 | return regex_replace(address, regex("[.]"), "[.]"); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1108-Defanging-an-IP-Address/1108.go: -------------------------------------------------------------------------------- 1 | func defangIPaddr(address string) string { 2 | return strings.Replace(address, ".", "[.]", -1) 3 | } -------------------------------------------------------------------------------- /src/1108-Defanging-an-IP-Address/1108.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def defangIPaddr(self, address: str) -> str: 3 | return address.replace('.', '[.]') -------------------------------------------------------------------------------- /src/1109-Corporate-Flight-Bookings/1109.go: -------------------------------------------------------------------------------- 1 | func corpFlightBookings(bookings [][]int, n int) []int { 2 | res := make([]int, n + 1) 3 | for _, book := range bookings { 4 | res[book[0]-1] += book[2] 5 | res[book[1]] -= book[2] 6 | } 7 | for i := 1; i <= n; i++ { 8 | res[i] += res[i-1] 9 | } 10 | return res[:n] 11 | } -------------------------------------------------------------------------------- /src/1109-Corporate-Flight-Bookings/1109.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]: 3 | res = [0] * (n + 1) 4 | for i, j, k in bookings: 5 | res[i-1] += k 6 | res[j] -= k 7 | for i in range(1, len(res)): 8 | res[i] += res[i-1] 9 | return res[:-1] -------------------------------------------------------------------------------- /src/1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector maxDepthAfterSplit(string seq) 5 | { 6 | vector res(seq.size(), 0); 7 | for (int i = 0; i < seq.size(); ++i) 8 | { 9 | res[i] = i & 1 ^ (seq[i] == ')'); 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111.go: -------------------------------------------------------------------------------- 1 | func maxDepthAfterSplit(seq string) []int { 2 | res := make([]int, len(seq)) 3 | for i, v := range []byte(seq) { 4 | if v == '(' { 5 | res[i] = i & 1 6 | } else { 7 | res[i] = 1 - i & 1 8 | } 9 | } 10 | return res 11 | } -------------------------------------------------------------------------------- /src/1111-Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepthAfterSplit(self, seq: str) -> List[int]: 3 | return [i & 1 ^ (seq[i] == ')') for i, c in enumerate(seq)] -------------------------------------------------------------------------------- /src/1118-Number-of-Days-in-a-Month/1118.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int numberOfDays(int Y, int M) 5 | { 6 | int D[] = {31,28,31,30,31,30,31,31,30,31,30,31}; 7 | if (Y % 400 == 0 or Y % 4 == 0 and Y % 100 != 0) D[1]++; 8 | return D[M - 1]; 9 | } 10 | }; -------------------------------------------------------------------------------- /src/1118-Number-of-Days-in-a-Month/1118.go: -------------------------------------------------------------------------------- 1 | func numberOfDays(Y int, M int) int { 2 | D := []int{31,28,31,30,31,30,31,31,30,31,30,31} 3 | if Y % 400 == 0 || Y % 4 == 0 && Y % 100 != 0 { 4 | D[1]++; 5 | } 6 | return D[M - 1]; 7 | } -------------------------------------------------------------------------------- /src/1118-Number-of-Days-in-a-Month/1118.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfDays(self, Y: int, M: int) -> int: 3 | D = [31,28,31,30,31,30,31,31,30,31,30,31] 4 | if Y % 400 == 0 or Y % 4 == 0 and Y % 100 != 0: 5 | D[1] += 1 6 | return D[M - 1] -------------------------------------------------------------------------------- /src/1119-Remove-Vowels-from-a-String/1119.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | string removeVowels(string S) 5 | { 6 | return regex_replace(S, regex("a|e|i|o|u"), ""); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1119-Remove-Vowels-from-a-String/1119.go: -------------------------------------------------------------------------------- 1 | func removeVowels(S string) string { 2 | reg := regexp.MustCompile(`(a|e|i|o|u)`) 3 | return reg.ReplaceAllString(S, "") 4 | } -------------------------------------------------------------------------------- /src/1119-Remove-Vowels-from-a-String/1119.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeVowels(self, S: str) -> str: 3 | return re.sub(r'[aeiou]', '', S) -------------------------------------------------------------------------------- /src/1121-Divide-Array-Into-Increasing-Sequences/1121.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canDivideIntoSubsequences(self, nums: List[int], K: int) -> bool: 3 | return len(nums) >= K * max(collections.Counter(nums).values()) -------------------------------------------------------------------------------- /src/1122-Relative-Sort-Array/1122.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]: 3 | order = {v: i for i, v in enumerate(arr2)} 4 | return sorted(arr1 , key=lambda a: order.get(a, 1000 + a)) -------------------------------------------------------------------------------- /src/1128-Number-of-Equivalent-Domino-Pairs/1128.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int numEquivDominoPairs(vector>& dominoes) 5 | { 6 | unordered_map cnt; 7 | int res = 0; 8 | for (auto& d : dominoes) 9 | { 10 | res += cnt[min(d[0], d[1]) * 10 + max(d[0], d[1])]++; 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1128-Number-of-Equivalent-Domino-Pairs/1128.js: -------------------------------------------------------------------------------- 1 | var numEquivDominoPairs = function(dominoes) { 2 | var cnt = Array(100), res = 0; 3 | cnt.fill(0); 4 | for (let d of dominoes) { 5 | res += cnt[Math.min(d[0], d[1])*10 + Math.max(d[0], d[1])]++; 6 | } 7 | return res; 8 | }; -------------------------------------------------------------------------------- /src/1128-Number-of-Equivalent-Domino-Pairs/1128.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int: 3 | return sum(v*(v - 1)//2 for v in collections.Counter(tuple(sorted(d)) for d in dominoes).values()) -------------------------------------------------------------------------------- /src/1133-Largest-Unique-Number/1133.go: -------------------------------------------------------------------------------- 1 | func largestUniqueNumber(A []int) int { 2 | sort.Ints(A) 3 | for len(A) > 1 && A[len(A)-1] == A[len(A)-2] { 4 | bk := A[len(A)-1] 5 | for len(A) > 0 && A[len(A)-1] == bk { 6 | A = A[:len(A)-1] 7 | } 8 | } 9 | if len(A) > 0 { 10 | return A[len(A)-1] 11 | } 12 | return -1 13 | } -------------------------------------------------------------------------------- /src/1133-Largest-Unique-Number/1133.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestUniqueNumber(self, A: List[int]) -> int: 3 | cnt = collections.Counter(A) 4 | sCnt = sorted(cnt.items(), key=lambda a:(a[1], -a[0])) 5 | if sCnt[0][1] != 1: 6 | return -1 7 | return sCnt[0][0] -------------------------------------------------------------------------------- /src/1134-Armstrong-Number/1134.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool isArmstrong(int N) 5 | { 6 | string Nstr = to_string(N); 7 | int n = Nstr.size(), res = 0; 8 | for (auto c : Nstr) res += pow(c - '0', n); 9 | return res == N; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1134-Armstrong-Number/1134.go: -------------------------------------------------------------------------------- 1 | func isArmstrong(N int) bool { 2 | str := strconv.Itoa(N) 3 | n := len(str) 4 | var res float64 = 0 5 | for _, v := range []byte(str) { 6 | t, _ := strconv.ParseFloat(string(v), 64) 7 | res += math.Pow(t, float64(n)) 8 | } 9 | return int(res) == N 10 | } -------------------------------------------------------------------------------- /src/1134-Armstrong-Number/1134.js: -------------------------------------------------------------------------------- 1 | var isArmstrong = function(N) { 2 | var str = N.toString(); 3 | var res = 0, n = str.length; 4 | for (let c of str) { 5 | res += Math.pow(parseInt(c), n); 6 | } 7 | return res == N; 8 | }; -------------------------------------------------------------------------------- /src/1134-Armstrong-Number/1134.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isArmstrong(self, N: int) -> bool: 3 | n = len(str(N)) 4 | return sum(pow(int(d), n) for d in str(N)) == N -------------------------------------------------------------------------------- /src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.js: -------------------------------------------------------------------------------- 1 | var movesToMakeZigzag = function(nums) { 2 | var res = [0, 0]; 3 | nums.unshift(Number.MAX_VALUE); 4 | nums.push(Number.MAX_VALUE); 5 | for (var i = 1; i < nums.length - 1; ++i) { 6 | res[i % 2] += Math.max(0, nums[i] - Math.min(nums[i-1], nums[i+1]) + 1); 7 | } 8 | return Math.min(res[0], res[1]); 9 | }; -------------------------------------------------------------------------------- /src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def movesToMakeZigzag(self, nums: List[int]) -> int: 3 | nums = [float("inf")] + nums + [float("inf")] 4 | res = [0, 0] 5 | for i in range(1, len(nums) - 1): 6 | res[i % 2] += max(0, nums[i] - min(nums[i - 1], nums[i + 1]) + 1) 7 | return min(res) -------------------------------------------------------------------------------- /src/1145-Binary-Tree-Coloring-Game/1145.js: -------------------------------------------------------------------------------- 1 | var btreeGameWinningMove = function(root, n, x) { 2 | var tl, tr; 3 | function dfs(node) { 4 | if (node == null) return 0; 5 | var l = dfs(node.left), r = dfs(node.right); 6 | if (node.val == x) tl = l, tr = r; 7 | return l + r + 1; 8 | } 9 | dfs(root); 10 | return Math.max(tl, tr, n - tl - tr - 1) > n/2; 11 | }; -------------------------------------------------------------------------------- /src/1147-Longest-Chunked-Palindrome-Decomposition/1147.go: -------------------------------------------------------------------------------- 1 | func longestDecomposition(text string) int { 2 | var n = len(text); 3 | for i := 1; i <= n/2; i++ { 4 | if text[:i] == text[n-i:] { 5 | return 2 + longestDecomposition(text[i:n-i]) 6 | } 7 | } 8 | if n == 0 { 9 | return 0 10 | } 11 | return 1 12 | } -------------------------------------------------------------------------------- /src/1147-Longest-Chunked-Palindrome-Decomposition/1147.js: -------------------------------------------------------------------------------- 1 | var longestDecomposition = function(text) { 2 | var n = text.length; 3 | for (var i = 1; i <= n/2; ++i) { 4 | if (text.substr(0,i) == text.substr(n-i)) 5 | return 2 + longestDecomposition(text.substr(i,n-2*i)); 6 | } 7 | return n == 0 ? 0 : 1; 8 | }; -------------------------------------------------------------------------------- /src/1147-Longest-Chunked-Palindrome-Decomposition/1147.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestDecomposition(self, text: str) -> int: 3 | n = len(text) 4 | for i in range(1, n//2 + 1): 5 | if text[:i] == text[n-i:]: 6 | return 2 + self.longestDecomposition(text[i:n-i]) 7 | return 0 if n == 0 else 1 -------------------------------------------------------------------------------- /src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool isMajorityElement(vector& nums, int target) 5 | { 6 | int cnt = 0; 7 | for (auto i : nums) if (i == target) cnt++; 8 | return cnt > nums.size() / 2; 9 | } 10 | }; -------------------------------------------------------------------------------- /src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.go: -------------------------------------------------------------------------------- 1 | func isMajorityElement(nums []int, target int) bool { 2 | cnt := 0 3 | for _, v := range nums { 4 | if target == v { 5 | cnt++ 6 | } 7 | } 8 | return cnt > len(nums)/2 9 | } -------------------------------------------------------------------------------- /src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.js: -------------------------------------------------------------------------------- 1 | var isMajorityElement = function(nums, target) { 2 | var cnt = 0; 3 | for (let i of nums) if (target == i) cnt++; 4 | return cnt > nums.length/2; 5 | }; -------------------------------------------------------------------------------- /src/1150-Check-If-a-Number-Is-Majority-Element-in-a-Sorted-Array/1150.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isMajorityElement(self, nums: List[int], target: int) -> bool: 3 | return collections.Counter(nums)[target] > len(nums)/2 -------------------------------------------------------------------------------- /src/1153-String-Transforms-Into-Another-String/1153.js: -------------------------------------------------------------------------------- 1 | var canConvert = function(str1, str2) { 2 | var s2 = new Set(str2); 3 | if (s2.size == 26) return str1 == str2; 4 | var d = {}; 5 | for (var i = 0; i < str1.length; ++i) { 6 | if (d[str1[i]]) { 7 | if (d[str1[i]] != str2[i]) return false; 8 | } else d[str1[i]] = str2[i]; 9 | } 10 | return true; 11 | }; -------------------------------------------------------------------------------- /src/1154-Day-of-the-Year/1154.js: -------------------------------------------------------------------------------- 1 | var dayOfYear = function(date) { 2 | var date = date.split("-"); 3 | var Y = Number(date[0]), M = Number(date[1]) - 1; 4 | var days = [31,28,31,30,31,30,31,31,30,31,30,31], res = Number(date[2]); 5 | if (Y % 400 == 0 || Y % 4 == 0 && Y % 100 != 0) days[1]++; 6 | for (var i = 0; i < M; ++i) res += days[i]; 7 | return res; 8 | }; -------------------------------------------------------------------------------- /src/1154-Day-of-the-Year/1154.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | class Solution: 3 | def dayOfYear(self, date: str) -> int: 4 | Y, M, D = list(map(int, date.split("-"))) 5 | return int(datetime.date(Y, M, D).strftime("%j")) -------------------------------------------------------------------------------- /src/1160-Find-Words-That-Can-Be-Formed-by-Characters/1160.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countCharacters(self, words: List[str], chars: str) -> int: 3 | return len(''.join(filter(lambda x : len(collections.Counter(x) - collections.Counter(chars)) == 0, words))) -------------------------------------------------------------------------------- /src/1165-Single-Row-Keyboard/1165.js: -------------------------------------------------------------------------------- 1 | var calculateTime = function(keyboard, word) { 2 | var d = {}; 3 | for (var i = 0; i < keyboard.length; ++i) { 4 | d[keyboard[i]] = i; 5 | } 6 | 7 | var res = 0, pre = 0; 8 | for (let c of word) { 9 | res += Math.abs(d[c] - pre); 10 | pre = d[c]; 11 | } 12 | return res; 13 | }; -------------------------------------------------------------------------------- /src/1165-Single-Row-Keyboard/1165.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def calculateTime(self, keyboard: str, word: str) -> int: 3 | d = dict() 4 | for i, v in enumerate(keyboard): 5 | d[v] = i 6 | 7 | res, pre = 0, 0 8 | for c in word: 9 | res += abs(d[c] - pre) 10 | pre = d[c] 11 | return res -------------------------------------------------------------------------------- /src/1167-Minimum-Cost-to-Connect-Sticks/1167.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1167-Minimum-Cost-to-Connect-Sticks/1167.js -------------------------------------------------------------------------------- /src/1167-Minimum-Cost-to-Connect-Sticks/1167.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | class Solution: 3 | def connectSticks(self, sticks: List[int]) -> int: 4 | heapq.heapify(sticks) 5 | res = 0 6 | while len(sticks) > 1: 7 | a, b = heapq.heappop(sticks), heapq.heappop(sticks) 8 | res += a + b 9 | heapq.heappush(sticks, a + b) 10 | return res -------------------------------------------------------------------------------- /src/1170-Compare-Strings-by-Frequency-of-the-Smallest-Character/1170.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]: 3 | w = sorted([i.count(min(i)) for i in words]) 4 | return [len(w) - bisect.bisect_right(w, i.count(min(i))) for i in queries] -------------------------------------------------------------------------------- /src/1176-Diet-Plan-Performance/1176.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int: 3 | T = sum(calories[:k]) 4 | res = (T > upper) - (T < lower) 5 | for i in range(k, len(calories)): 6 | T += calories[i] - calories[i - k] 7 | res += (T > upper) - (T < lower) 8 | return res -------------------------------------------------------------------------------- /src/1184-Distance-Between-Bus-Stops/1184.js: -------------------------------------------------------------------------------- 1 | var distanceBetweenBusStops = function(d, l, r) { 2 | if (l > r) { 3 | var t = l; 4 | l = r, r = t; 5 | } 6 | var k = 0, v = 0; 7 | for (var i = 0; i < d.length; ++i) { 8 | if (i < l || i >= r) k += d[i]; 9 | else v += d[i]; 10 | } 11 | return Math.min(k, v); 12 | }; -------------------------------------------------------------------------------- /src/1184-Distance-Between-Bus-Stops/1184.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distanceBetweenBusStops(self, dis: List[int], l: int, r: int) -> int: 3 | if l > r: 4 | l, r = r, l 5 | k, v = sum(dis[l:r]), sum(dis) 6 | return min(k, v - k) -------------------------------------------------------------------------------- /src/1185-Day-of-the-Week/1185.go: -------------------------------------------------------------------------------- 1 | func dayOfTheWeek(d int, m int, y int) string { 2 | weeks := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} 3 | if (m < 3) { 4 | m += 12 5 | y-- 6 | } 7 | return weeks[(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7] 8 | } -------------------------------------------------------------------------------- /src/1185-Day-of-the-Week/1185.js: -------------------------------------------------------------------------------- 1 | var dayOfTheWeek = function(d, m, y) { 2 | var weeks = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; 3 | if (m < 3) { 4 | m += 12; y--; 5 | } 6 | return weeks[(d+2*m+Math.floor(3*(m+1)/5)+y+Math.floor(y/4)-Math.floor(y/100)+Math.floor(y/400)+1)%7]; 7 | }; -------------------------------------------------------------------------------- /src/1185-Day-of-the-Week/1185.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | class Solution: 3 | def dayOfTheWeek(self, day: int, month: int, year: int) -> str: 4 | return ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")[datetime.date(year, month, day).weekday()] -------------------------------------------------------------------------------- /src/1189-Maximum-Number-of-Balloons/1189.js: -------------------------------------------------------------------------------- 1 | var maxNumberOfBalloons = function(text) { 2 | var cnt = {}; 3 | for (let c of text) { 4 | cnt[c] = cnt[c] || 0; 5 | cnt[c]++; 6 | } 7 | return Math.min(cnt.b, cnt.a, cnt.l/2, cnt.o/2, cnt.n) | 0; 8 | }; -------------------------------------------------------------------------------- /src/1189-Maximum-Number-of-Balloons/1189.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxNumberOfBalloons(self, text: str) -> int: 3 | cnt = collections.Counter(text) 4 | return min(cnt['b'], cnt['a'], cnt['l']//2, cnt['o']//2, cnt['n']) -------------------------------------------------------------------------------- /src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.go: -------------------------------------------------------------------------------- 1 | func maxNumberOfApples(arr []int) int { 2 | sort.Ints(arr) 3 | res, t := 0, 0 4 | for _, v := range arr { 5 | t += v 6 | if t > 5000 { 7 | break 8 | } 9 | res++ 10 | } 11 | return res 12 | } -------------------------------------------------------------------------------- /src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.js: -------------------------------------------------------------------------------- 1 | var maxNumberOfApples = function(arr) { 2 | arr.sort(function sortNumber(a,b) { 3 | return a - b; 4 | }); 5 | var res = 0, t = 0; 6 | for (let i of arr) { 7 | t += i; 8 | if (t > 5000) break; 9 | res++; 10 | } 11 | return res; 12 | }; -------------------------------------------------------------------------------- /src/1196-How-Many-Apples-Can-You-Put-into-the-Basket/1196.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxNumberOfApples(self, arr: List[int]) -> int: 3 | arr.sort() 4 | res, t = 0, 0 5 | for v in arr: 6 | t += v 7 | if t > 5000: 8 | break 9 | res += 1 10 | return res -------------------------------------------------------------------------------- /src/1197-Minimum-Knight-Moves/1197.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int minKnightMoves(int x, int y) 5 | { 6 | x = abs(x), y = abs(y); 7 | if (x + y == 1) return 3; 8 | int res = max({(x + 1)/2, (y + 1)/2, (x + y + 2)/3}); 9 | res += (res ^ x ^ y) & 1; 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1197-Minimum-Knight-Moves/1197.js: -------------------------------------------------------------------------------- 1 | var minKnightMoves = function(x, y) { 2 | x = Math.abs(x), y = Math.abs(y); 3 | if (x + y == 1) return 3; 4 | var res = Math.max(Math.max(Math.ceil(x/2), Math.ceil(y/2)), Math.ceil((x + y)/3)); 5 | res += (res ^ x ^ y) & 1; 6 | return res; 7 | }; -------------------------------------------------------------------------------- /src/1197-Minimum-Knight-Moves/1197.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minKnightMoves(self, x: int, y: int) -> int: 3 | x, y = abs(x), abs(y) 4 | if x + y == 1: 5 | return 3 6 | res = max(max((x + 1)//2, (y + 1)//2), (x + y + 2)//3) 7 | res += (res ^ x ^ y) & 1 8 | return res -------------------------------------------------------------------------------- /src/1198-Find-Smallest-Common-Element-in-All-Rows/1198.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | class Solution: 3 | def smallestCommonElement(self, mat: List[List[int]]) -> int: 4 | res = reduce(operator. __and__, map(set, mat)) 5 | return min(res) if res else -1 -------------------------------------------------------------------------------- /src/1199-Minimum-Time-to-Build-Blocks/1199.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | class Solution: 3 | def minBuildTime(self, blocks: List[int], split: int) -> int: 4 | heapq.heapify(blocks) 5 | while len(blocks) > 1: 6 | _, y = heapq.heappop(blocks), heapq.heappop(blocks) 7 | heapq.heappush(blocks, y + split) 8 | return blocks[0] -------------------------------------------------------------------------------- /src/1202-Smallest-String-With-Swaps/1202.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1202-Smallest-String-With-Swaps/1202.js -------------------------------------------------------------------------------- /src/1207-Unique-Number-of-Occurrences/1207.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool uniqueOccurrences(vector& arr) 5 | { 6 | unordered_map m; 7 | unordered_set s; 8 | for (int n : arr) ++m[n]; 9 | for (auto& it : m) s.insert(it.second); 10 | return m.size() == s.size(); 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1207-Unique-Number-of-Occurrences/1207.go: -------------------------------------------------------------------------------- 1 | func uniqueOccurrences(arr []int) bool { 2 | m := make(map[int]int) 3 | for _, i := range arr { 4 | m[i]++ 5 | } 6 | s := make(map[int]int) 7 | for _, v := range m { 8 | s[v] = 1 9 | } 10 | return len(s) == len(m) 11 | } -------------------------------------------------------------------------------- /src/1207-Unique-Number-of-Occurrences/1207.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueOccurrences(self, arr: List[int]) -> bool: 3 | cnt = collections.Counter(arr) 4 | return len(cnt) == len(set(cnt.values())) -------------------------------------------------------------------------------- /src/1213-Intersection-of-Three-Sorted-Arrays/1213.js: -------------------------------------------------------------------------------- 1 | var arraysIntersection = function(arr1, arr2, arr3) { 2 | let d = new Array(2001); 3 | d.fill(0); 4 | for (let x of arr1) d[x]++; 5 | for (let x of arr2) d[x]++; 6 | 7 | let res = []; 8 | for (let x of arr3) { 9 | if (d[x] == 2) res.push(x); 10 | } 11 | return res; 12 | }; -------------------------------------------------------------------------------- /src/1213-Intersection-of-Three-Sorted-Arrays/1213.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]: 3 | return sorted(set(arr1) & set(arr2) & set(arr3)) -------------------------------------------------------------------------------- /src/1217-Play-with-Chips/1217.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int minCostToMoveChips(vector& chips) 5 | { 6 | int res[2] = {0}; 7 | for (int c : chips) res[c%2]++; 8 | return min(res[0], res[1]); 9 | } 10 | }; -------------------------------------------------------------------------------- /src/1217-Play-with-Chips/1217.go: -------------------------------------------------------------------------------- 1 | func minCostToMoveChips(chips []int) int { 2 | res := make([]int, 2) 3 | for _, v := range chips { 4 | res[v%2]++ 5 | } 6 | return min(res[0], res[1]) 7 | } 8 | 9 | func min(a, b int) int { 10 | if a < b { 11 | return a 12 | } 13 | return b 14 | } -------------------------------------------------------------------------------- /src/1217-Play-with-Chips/1217.js: -------------------------------------------------------------------------------- 1 | var minCostToMoveChips = function(chips) { 2 | let res = [0, 0]; 3 | for (let c of chips) res[c%2]++; 4 | return Math.min(res[0], res[1]); 5 | }; -------------------------------------------------------------------------------- /src/1217-Play-with-Chips/1217.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostToMoveChips(self, chips: List[int]) -> int: 3 | res = [0, 0] 4 | for c in chips: 5 | res[c % 2] += 1 6 | return min(res) -------------------------------------------------------------------------------- /src/1218-Longest-Arithmetic-Subsequence-of-Given-Difference/1218.js: -------------------------------------------------------------------------------- 1 | var longestSubsequence = function(arr, dif) { 2 | let mem = {}, res = 1; 3 | for (let i of arr) { 4 | if (mem[i - dif]) mem[i] = mem[i - dif] + 1; 5 | else mem[i] = 1; 6 | res = Math.max(res, mem[i]); 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1218-Longest-Arithmetic-Subsequence-of-Given-Difference/1218.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestSubsequence(self, arr: List[int], dif: int) -> int: 3 | mem, res = {}, 1 4 | for i in arr: 5 | if i - dif in mem: 6 | mem[i] = mem[i-dif] + 1 7 | else: 8 | mem[i] = 1 9 | res = max(res, mem[i]) 10 | return res -------------------------------------------------------------------------------- /src/1220-Count-Vowels-Permutation/1220.go: -------------------------------------------------------------------------------- 1 | func countVowelPermutation(n int) int { 2 | var a, e, i, o, u, mod uint32 3 | a, e, i, o, u, mod = 1, 1, 1, 1, 1, 1000000007 4 | for k := 1; k < n; k++ { 5 | a, e, i, o, u = (e + i + u)%mod, (a + i)%mod, (e + o)%mod, i, (i + o)%mod 6 | } 7 | return int((a + e + i + o + u) % mod) 8 | } -------------------------------------------------------------------------------- /src/1220-Count-Vowels-Permutation/1220.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countVowelPermutation(self, n: int) -> int: 3 | a, e, i, o, u = 1, 1, 1, 1, 1 4 | for _ in range(n - 1): 5 | a, e, i, o, u = e + i + u, a + i, e + o, i, i + o 6 | return (a + e + i + o + u) % (10**9 + 7) -------------------------------------------------------------------------------- /src/1221-Split-a-String-in-Balanced-Strings/1221.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int balancedStringSplit(string s) 5 | { 6 | int L = 0, res = 0; 7 | for (char c : s) 8 | { 9 | if (c == 'L') L++; 10 | else L--; 11 | if (L == 0) res++; 12 | } 13 | return res; 14 | } 15 | }; -------------------------------------------------------------------------------- /src/1221-Split-a-String-in-Balanced-Strings/1221.go: -------------------------------------------------------------------------------- 1 | func balancedStringSplit(s string) int { 2 | L, res := 0, 0 3 | for _, v := range s { 4 | if v == 'L' { 5 | L++ 6 | } else { 7 | L-- 8 | } 9 | if L == 0 { 10 | res++ 11 | } 12 | } 13 | return res 14 | } -------------------------------------------------------------------------------- /src/1221-Split-a-String-in-Balanced-Strings/1221.js: -------------------------------------------------------------------------------- 1 | var balancedStringSplit = function(s) { 2 | var res = L = 0; 3 | for (let c of s) { 4 | if (c == 'L') L++; 5 | else L--; 6 | if (L == 0) res++; 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1221-Split-a-String-in-Balanced-Strings/1221.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def balancedStringSplit(self, s: str) -> int: 3 | res = L = 0 4 | for i in s: 5 | if i == 'L': 6 | L += 1 7 | else: 8 | L -= 1 9 | if L == 0: 10 | res += 1 11 | return res -------------------------------------------------------------------------------- /src/1228-Missing-Number-In-Arithmetic-Progression/1228.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int missingNumber(vector& arr) 5 | { 6 | return (arr[0] + arr[arr.size()-1])*(arr.size() + 1)/2 - 7 | accumulate(arr.begin(), arr.end(), 0); 8 | } 9 | }; -------------------------------------------------------------------------------- /src/1228-Missing-Number-In-Arithmetic-Progression/1228.go: -------------------------------------------------------------------------------- 1 | func missingNumber(arr []int) int { 2 | A := 0 3 | for _, v := range arr{ 4 | A += v 5 | } 6 | return (arr[0] + arr[len(arr)-1])*(len(arr) + 1)/2 - A 7 | } -------------------------------------------------------------------------------- /src/1228-Missing-Number-In-Arithmetic-Progression/1228.js: -------------------------------------------------------------------------------- 1 | var missingNumber = function(arr) { 2 | let A = 0; 3 | for (let a of arr) A += a; 4 | return Math.floor((arr[0] + arr[arr.length - 1]) * (arr.length + 1)/2) - A; 5 | }; -------------------------------------------------------------------------------- /src/1228-Missing-Number-In-Arithmetic-Progression/1228.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, A: List[int]) -> int: 3 | return (A[0] + A[-1]) * (len(A) + 1) // 2 - sum(A) -------------------------------------------------------------------------------- /src/1230-Toss-Strange-Coins/1230.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1230-Toss-Strange-Coins/1230.js -------------------------------------------------------------------------------- /src/1230-Toss-Strange-Coins/1230.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def probabilityOfHeads(self, prob: List[float], target: int) -> float: 3 | dp = [1] + [0] * target 4 | for p in prob: 5 | for k in range(target, -1, -1): 6 | dp[k] = (dp[k - 1] if k else 0) * p + dp[k] * (1 - p) 7 | return dp[-1] -------------------------------------------------------------------------------- /src/1232-Check-If-It-Is-a-Straight-Line/1232.go: -------------------------------------------------------------------------------- 1 | func checkStraightLine(c [][]int) bool { 2 | for i := 2; i < len(c); i++ { 3 | if (c[i][0] - c[0][0]) * (c[i][1] - c[1][1]) != (c[i][0] - c[1][0]) * (c[i][1] - c[0][1]) { 4 | return false 5 | } 6 | } 7 | return true 8 | } -------------------------------------------------------------------------------- /src/1232-Check-If-It-Is-a-Straight-Line/1232.js: -------------------------------------------------------------------------------- 1 | var checkStraightLine = function(c) { 2 | for (let i = 2; i < c.length; i++) { 3 | if ((c[i][0] - c[0][0]) * (c[i][1] - c[1][1]) != 4 | (c[i][0] - c[1][0]) * (c[i][1] - c[0][1])) 5 | return false; 6 | } 7 | return true; 8 | }; -------------------------------------------------------------------------------- /src/1232-Check-If-It-Is-a-Straight-Line/1232.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkStraightLine(self, c: List[List[int]]) -> bool: 3 | return all((x - c[0][0]) * (y - c[1][1]) == (x - c[1][0]) * (y - c[0][1]) for x, y in c[2:]) -------------------------------------------------------------------------------- /src/1233-Remove-Sub-Folders-from-the-Filesystem/1233.js: -------------------------------------------------------------------------------- 1 | var removeSubfolders = function(folder) { 2 | folder.sort(); 3 | let res = [], l = 2, parent = ''; 4 | for (let f of folder) { 5 | if (f.substr(0, l) != parent) { 6 | l = f.length + 1; 7 | parent = f + '/'; 8 | res.push(f); 9 | } 10 | } 11 | return res; 12 | }; -------------------------------------------------------------------------------- /src/1233-Remove-Sub-Folders-from-the-Filesystem/1233.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeSubfolders(self, folder: List[str]) -> List[str]: 3 | folder.sort() 4 | res, l, parent = [], 2, '' 5 | for f in folder: 6 | if f[:l] != parent: 7 | l, parent = len(f) + 1, f + '/' 8 | res.append(f) 9 | return res -------------------------------------------------------------------------------- /src/1237-Find-Positive-Integer-Solution-for-a-Given-Equation/1237.js: -------------------------------------------------------------------------------- 1 | var findSolution = function(customfunction, z) { 2 | let res = [], y = 1000; 3 | for (let x = 1; x <= 1000; x++) { 4 | while (y > 1 && customfunction.f(x, y) > z) { 5 | y--; 6 | } 7 | if (customfunction.f(x, y) == z) res.push([x, y]); 8 | } 9 | return res; 10 | }; -------------------------------------------------------------------------------- /src/1238-Circular-Permutation-in-Binary-Representation/1238.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector circularPermutation(int n, int start) 5 | { 6 | vector res; 7 | for (int i = 0; i < (1 << n); i++) res.push_back(start^i^(i >> 1)); 8 | return res; 9 | } 10 | }; -------------------------------------------------------------------------------- /src/1238-Circular-Permutation-in-Binary-Representation/1238.go: -------------------------------------------------------------------------------- 1 | func circularPermutation(n int, start int) []int { 2 | res, e := make([]int, 0), int(1 << uint(n)) 3 | for i := 0; i < e; i++ { 4 | res = append(res, start^i^(i >> 1)) 5 | } 6 | return res 7 | } -------------------------------------------------------------------------------- /src/1238-Circular-Permutation-in-Binary-Representation/1238.js: -------------------------------------------------------------------------------- 1 | var circularPermutation = function(n, start) { 2 | let res = []; 3 | for (let i = 0; i < (1 << n); i++) res.push(start^i^(i >> 1)); 4 | return res; 5 | }; -------------------------------------------------------------------------------- /src/1238-Circular-Permutation-in-Binary-Representation/1238.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def circularPermutation(self, n: int, start: int) -> List[int]: 3 | return [start^i^(i >> 1) for i in range(1 << n)] -------------------------------------------------------------------------------- /src/1247-Minimum-Swaps-to-Make-Strings-Equal/1247.js: -------------------------------------------------------------------------------- 1 | var minimumSwap = function(s1, s2) { 2 | let x = 0, y = 0, n = s1.length; 3 | for (let i = 0; i < n; i++) { 4 | if (s1[i] != s2[i]) { 5 | if (s1[i] == 'x') x++; 6 | else y++; 7 | } 8 | } 9 | if ((x + y) & 1) return -1; 10 | return Math.floor(x / 2) + Math.floor(y / 2) + 2 * (x % 2); 11 | }; -------------------------------------------------------------------------------- /src/1250-Check-If-It-Is-a-Good-Array/1250.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool isGoodArray(vector& nums) 5 | { 6 | return accumulate(nums.begin(), nums.end(), nums[0], gcd) == 1; 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1250-Check-If-It-Is-a-Good-Array/1250.go: -------------------------------------------------------------------------------- 1 | func isGoodArray(nums []int) bool { 2 | x, y := nums[0], 0 3 | for _, a := range nums { 4 | for a > 0 { 5 | y, x = x % a, a 6 | a = y 7 | } 8 | } 9 | return x == 1 10 | } -------------------------------------------------------------------------------- /src/1250-Check-If-It-Is-a-Good-Array/1250.java: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public boolean isGoodArray(int[] nums) 4 | { 5 | int x = nums[0], y; 6 | for (int a : nums) { 7 | while (a > 0) { 8 | y = x % a; 9 | x = a; 10 | a = y; 11 | } 12 | } 13 | return x == 1; 14 | } 15 | } -------------------------------------------------------------------------------- /src/1250-Check-If-It-Is-a-Good-Array/1250.js: -------------------------------------------------------------------------------- 1 | var isGoodArray = function(nums) { 2 | let x = nums[0], y; 3 | for (let a of nums) { 4 | while (a > 0) { 5 | y = x % a; 6 | x = a; 7 | a = y; 8 | } 9 | } 10 | return x == 1; 11 | }; -------------------------------------------------------------------------------- /src/1250-Check-If-It-Is-a-Good-Array/1250.py: -------------------------------------------------------------------------------- 1 | from math import gcd 2 | from functools import reduce 3 | class Solution: 4 | def isGoodArray(self, nums: List[int]) -> bool: 5 | return reduce(gcd, nums) == 1 -------------------------------------------------------------------------------- /src/1256-Encode-Number/1256.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | string encode(int num) 5 | { 6 | string res; 7 | num++; 8 | while (num) 9 | { 10 | res = string(num&1 ? "1" : "0") + res; 11 | num >>= 1; 12 | } 13 | return res.substr(1); 14 | } 15 | }; -------------------------------------------------------------------------------- /src/1256-Encode-Number/1256.go: -------------------------------------------------------------------------------- 1 | func encode(num int) string { 2 | res := "" 3 | num++ 4 | for num > 0 { 5 | res = strconv.Itoa(num & 1) + res 6 | num >>= 1 7 | } 8 | return res[1:] 9 | } -------------------------------------------------------------------------------- /src/1256-Encode-Number/1256.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String encode(int num) { 3 | return Integer.toBinaryString(num + 1).substring(1); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1256-Encode-Number/1256.js: -------------------------------------------------------------------------------- 1 | var encode = function(num) { 2 | let res = ""; 3 | num++; 4 | while (num) { 5 | res = (num & 1 ? "1" : "0") + res; 6 | num >>= 1; 7 | } 8 | return res.substring(1); 9 | }; -------------------------------------------------------------------------------- /src/1256-Encode-Number/1256.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def encode(self, num: int) -> str: 3 | return bin(num + 1)[3:] -------------------------------------------------------------------------------- /src/1259-Handshakes-That-Don't-Cross/1259.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfWays(self, n: int) -> int: 3 | res = 1 4 | for i in range(1, n // 2 + 1): 5 | res *= n - i + 1 6 | res //= i 7 | return res // (n // 2 + 1) % (10**9 + 7) -------------------------------------------------------------------------------- /src/1260-Shift-2D-Grid/1260.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: 3 | n, m = len(grid), len(grid[0]) 4 | res = [[0] * m for _ in range(n)] 5 | for i in range(n): 6 | for j in range(m): 7 | t = j + k 8 | res[(i + t//m)%n][t % m] = grid[i][j] 9 | return res -------------------------------------------------------------------------------- /src/1262-Greatest-Sum-Divisible-by-Three/1262.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSumDivThree(int[] nums) { 3 | int[] res = new int[3]; 4 | for (int a : nums) { 5 | int[] tmp = res.clone(); 6 | for (int i : tmp) { 7 | res[(i + a)%3] = Math.max(res[(i + a)%3], i + a); 8 | } 9 | } 10 | return res[0]; 11 | } 12 | } -------------------------------------------------------------------------------- /src/1262-Greatest-Sum-Divisible-by-Three/1262.js: -------------------------------------------------------------------------------- 1 | var maxSumDivThree = function(nums) { 2 | let dp = [0, 0, 0]; 3 | for (let a of nums) { 4 | let dp2 = dp.slice(); 5 | for (let i of dp2) { 6 | dp[(i + a)%3] = Math.max(dp[(i + a)%3], i + a); 7 | } 8 | } 9 | return dp[0]; 10 | }; -------------------------------------------------------------------------------- /src/1262-Greatest-Sum-Divisible-by-Three/1262.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSumDivThree(self, nums: List[int]) -> int: 3 | dp = [0, 0, 0] 4 | for a in nums: 5 | for i in dp[:]: 6 | dp[(i + a) % 3] = max(dp[(i + a) % 3], i + a) 7 | return dp[0] -------------------------------------------------------------------------------- /src/1266-Minimum-Time-Visiting-All-Points/1266.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int minTimeToVisitAllPoints(vector>& p) 5 | { 6 | int res = 0; 7 | for (int i = 1; i < p.size(); i++) 8 | { 9 | res += max(abs(p[i][0] - p[i-1][0]), abs(p[i][1] - p[i-1][1])); 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1266-Minimum-Time-Visiting-All-Points/1266.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minTimeToVisitAllPoints(int[][] p) { 3 | int res = 0; 4 | for (int i = 1; i < p.length; i++) { 5 | res += Math.max(Math.abs(p[i][0] - p[i-1][0]), Math.abs(p[i][1] - p[i-1][1])); 6 | } 7 | return res; 8 | } 9 | } -------------------------------------------------------------------------------- /src/1266-Minimum-Time-Visiting-All-Points/1266.js: -------------------------------------------------------------------------------- 1 | var minTimeToVisitAllPoints = function(p) { 2 | let res = 0; 3 | for (let i = 1; i < p.length; i++) { 4 | res += Math.max(Math.abs(p[i][0] - p[i-1][0]), Math.abs(p[i][1] - p[i-1][1])); 5 | } 6 | return res; 7 | }; -------------------------------------------------------------------------------- /src/1266-Minimum-Time-Visiting-All-Points/1266.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minTimeToVisitAllPoints(self, p: List[List[int]]) -> int: 3 | return sum(max(abs(p[i][0] - p[i - 1][0]), abs(p[i][1] - p[i - 1][1])) for i in range(1, len(p))) -------------------------------------------------------------------------------- /src/1267-Count-Servers-that-Communicate/1267.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countServers(self, A: List[List[int]]) -> int: 3 | r, c = list(map(sum, A)), list(map(sum, zip(*A))) 4 | return sum(r[i] + c[j] > 2 for i in range(len(A)) for j in range(len(A[0])) if A[i][j]) -------------------------------------------------------------------------------- /src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numWays(self, steps: int, arrLen: int) -> int: 3 | A, mod = [0, 1], 10**9 + 7 4 | for t in range(steps): 5 | A[1:] = [sum(A[i - 1:i + 2]) % mod for i in range(1, min(arrLen + 1, t + 3))] 6 | return A[1] % mod -------------------------------------------------------------------------------- /src/1271-Hexspeak/1271.js: -------------------------------------------------------------------------------- 1 | var toHexspeak = function(num) { 2 | let data = Number(num).toString(16).toUpperCase(), res = ""; 3 | for (let i of data) { 4 | if (i > '1' && i <= '9') return "ERROR"; 5 | if (i == '0') res += 'O'; 6 | else if (i == '1') res += 'I'; 7 | else res += i; 8 | } 9 | return res; 10 | }; -------------------------------------------------------------------------------- /src/1276-Number-of-Burgers-with-No-Waste-of-Ingredients/1276.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector numOfBurgers(int t, int c) 5 | { 6 | return t % 2 == 0 && c * 2 <= t && t <= c * 4 ? vector({t / 2 - c, c * 2 - t / 2}) : vector(); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1276-Number-of-Burgers-with-No-Waste-of-Ingredients/1276.go: -------------------------------------------------------------------------------- 1 | func numOfBurgers(t int, c int) []int { 2 | if t % 2 == 0 && c * 2 <= t && t <= c * 4 { 3 | return []int{t / 2 - c, c * 2 - t / 2} 4 | } 5 | return []int{} 6 | } -------------------------------------------------------------------------------- /src/1276-Number-of-Burgers-with-No-Waste-of-Ingredients/1276.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List numOfBurgers(int t, int c) { 3 | return t % 2 == 0 && c * 2 <= t && t <= c * 4 ? Arrays.asList(t / 2 - c, c * 2 - t / 2) : new ArrayList(); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1276-Number-of-Burgers-with-No-Waste-of-Ingredients/1276.js: -------------------------------------------------------------------------------- 1 | var numOfBurgers = function(t, c) { 2 | return t % 2 == 0 && c * 2 <= t && t <= c * 4 ? [t / 2 - c, c * 2 - t / 2] : []; 3 | }; -------------------------------------------------------------------------------- /src/1276-Number-of-Burgers-with-No-Waste-of-Ingredients/1276.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numOfBurgers(self, t: int, c: int) -> List[int]: 3 | return [t // 2 - c, c * 2 - t // 2] if t % 2 == 0 and c * 2 <= t <= c * 4 else [] -------------------------------------------------------------------------------- /src/1277-Count-Square-Submatrices-with-All-Ones/1277.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSquares(self, A: List[List[int]]) -> int: 3 | res = 0 4 | for i in range(len(A)): 5 | for j in range(len(A[0])): 6 | if i and j and A[i][j]: 7 | A[i][j] = min(A[i - 1][j], A[i][j - 1], A[i - 1][j - 1]) + 1 8 | res += A[i][j] 9 | return res -------------------------------------------------------------------------------- /src/1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int subtractProductAndSum(int n) 5 | { 6 | int sum = 0, product = 1; 7 | while (n) 8 | { 9 | sum += n % 10; 10 | product *= n % 10; 11 | n /= 10; 12 | } 13 | return product - sum; 14 | } 15 | }; -------------------------------------------------------------------------------- /src/1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281.go: -------------------------------------------------------------------------------- 1 | func subtractProductAndSum(n int) int { 2 | sum, product := 0, 1 3 | for n > 0 { 4 | sum += n % 10 5 | product *= n % 10 6 | n /= 10 7 | } 8 | return product - sum 9 | } -------------------------------------------------------------------------------- /src/1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int subtractProductAndSum(int n) { 3 | int sum = 0, product = 1; 4 | while (n > 0) { 5 | sum += n % 10; 6 | product *= n % 10; 7 | n /= 10; 8 | } 9 | return product - sum; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} n 3 | * @return {number} 4 | */ 5 | var subtractProductAndSum = function(n) { 6 | let sum = 0, product = 1; 7 | while (n > 0) { 8 | sum += n % 10; 9 | product *= n % 10; 10 | n = Math.floor(n / 10); 11 | } 12 | return product - sum; 13 | }; -------------------------------------------------------------------------------- /src/1281-Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | class Solution: 3 | def subtractProductAndSum(self, n: int) -> int: 4 | A = list(map(int, str(n))) 5 | return reduce(operator.mul, A) - sum(A) -------------------------------------------------------------------------------- /src/1282-Group-the-People-Given-the-Group-Size-They-Belong-To/1282.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def groupThePeople(self, a: List[int]) -> List[List[int]]: 3 | data = collections.defaultdict(list) 4 | for i, v in enumerate(a): 5 | data[v].append(i) 6 | return [v[i:i+k] for k, v in data.items() for i in range(0, len(v), k)] -------------------------------------------------------------------------------- /src/1283-Find-the-Smallest-Divisor-Given-a-Threshold/1283.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestDivisor(self, A: List[int], t: int) -> int: 3 | l, r = 1, 10**6 4 | while l < r: 5 | m = l + r >> 1 6 | if sum((i + m - 1) // m for i in A) > t: 7 | l = m + 1 8 | else: 9 | r = m 10 | return l -------------------------------------------------------------------------------- /src/1287-Element-Appearing-More-Than-25%-In-Sorted-Array/1287.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findSpecialInteger(self, arr: List[int]) -> int: 3 | n = len(arr) 4 | for i in range(0, n, n//4 + 1): 5 | if bisect.bisect(arr, arr[i]) - bisect.bisect_left(arr, arr[i]) > n//4 : 6 | return arr[i] -------------------------------------------------------------------------------- /src/1288-Remove-Covered-Intervals/1288.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeCoveredIntervals(int[][] A) { 3 | int res = 0, r = 0; 4 | Arrays.sort(A, (a, b) -> a[0] != b[0] ? a[0] - b[0] : b[1] - a[1]); 5 | for (int[] v : A) { 6 | if (v[1] > r) ++res; 7 | r = Math.max(r, v[1]); 8 | } 9 | return res; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1288-Remove-Covered-Intervals/1288.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[][]} intervals 3 | * @return {number} 4 | */ 5 | var removeCoveredIntervals = function(A) { 6 | let res = 0, r = 0; 7 | A.sort((a, b) => a[0] != b[0] ? a[0] - b[0] : b[1] - a[1]); 8 | for (let v of A) { 9 | if (v[1] > r) res++; 10 | r = Math.max(r, v[1]); 11 | } 12 | return res; 13 | }; -------------------------------------------------------------------------------- /src/1288-Remove-Covered-Intervals/1288.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeCoveredIntervals(self, A: List[List[int]]) -> int: 3 | res = r = 0 4 | for _, j in sorted(A, key=lambda a: [a[0], -a[1]]): 5 | res += j > r 6 | r = max(r, j) 7 | return res -------------------------------------------------------------------------------- /src/1289-Minimum-Falling-Path-Sum-II/1289.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minFallingPathSum(self, A: List[List[int]]) -> int: 3 | r, c = len(A), len(A[0]) 4 | for i in range(1, r): 5 | r = heapq.nsmallest(2, A[i - 1]) 6 | for j in range(c): 7 | A[i][j] += r[1] if A[i - 1][j] == r[0] else r[0] 8 | return min(A[-1]) -------------------------------------------------------------------------------- /src/1290-Convert-Binary-Number-in-a-Linked-List-to-Integer/1290.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int getDecimalValue(ListNode* head) 5 | { 6 | int res = 0; 7 | while (head != nullptr) 8 | { 9 | res = (res << 1) | head->val; 10 | head = head->next; 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1290-Convert-Binary-Number-in-a-Linked-List-to-Integer/1290.go: -------------------------------------------------------------------------------- 1 | func getDecimalValue(head *ListNode) int { 2 | res := 0 3 | for head != nil { 4 | res = (res << 1) | head.Val 5 | head = head.Next 6 | } 7 | return res 8 | } -------------------------------------------------------------------------------- /src/1290-Convert-Binary-Number-in-a-Linked-List-to-Integer/1290.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int getDecimalValue(ListNode head) { 3 | int res = 0; 4 | while (head != null) { 5 | res = (res << 1) | head.val; 6 | head = head.next; 7 | } 8 | return res; 9 | } 10 | } -------------------------------------------------------------------------------- /src/1290-Convert-Binary-Number-in-a-Linked-List-to-Integer/1290.js: -------------------------------------------------------------------------------- 1 | var getDecimalValue = function(head) { 2 | let res = 0; 3 | while (head != null) { 4 | res = (res << 1) | head.val; 5 | head = head.next; 6 | } 7 | return res; 8 | }; -------------------------------------------------------------------------------- /src/1290-Convert-Binary-Number-in-a-Linked-List-to-Integer/1290.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getDecimalValue(self, head: ListNode) -> int: 3 | res = 0 4 | while head: 5 | res = (res << 1) | head.val 6 | head = head.next 7 | return res -------------------------------------------------------------------------------- /src/1295-Find-Numbers-with-Even-Number-of-Digits/1295.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int findNumbers(vector& nums) 5 | { 6 | int res = 0; 7 | for (int n : nums) 8 | { 9 | int x = 0; 10 | while (n) n /= 10, x++; 11 | if (x % 2 == 0) ++res; 12 | } 13 | return res; 14 | } 15 | }; -------------------------------------------------------------------------------- /src/1295-Find-Numbers-with-Even-Number-of-Digits/1295.go: -------------------------------------------------------------------------------- 1 | func findNumbers(nums []int) int { 2 | res := 0 3 | for _, v := range nums { 4 | x := 0 5 | for v != 0 { 6 | v /= 10 7 | x++ 8 | } 9 | if x % 2 == 0 { 10 | res++ 11 | } 12 | } 13 | return res 14 | } -------------------------------------------------------------------------------- /src/1295-Find-Numbers-with-Even-Number-of-Digits/1295.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findNumbers(int[] nums) { 3 | int res = 0; 4 | for (int i = 0; i < nums.length; i++) { 5 | double value = (double) nums[i]; 6 | double x = Math.log(value) / Math.log(10); 7 | if (((int)(x+1)) % 2 == 0) res++; 8 | } 9 | return res; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1295-Find-Numbers-with-Even-Number-of-Digits/1295.js: -------------------------------------------------------------------------------- 1 | var findNumbers = function(nums) { 2 | let res = 0; 3 | for (let n of nums) { 4 | let x = 0; 5 | while (n) { 6 | n = Math.floor(n / 10); 7 | x++; 8 | } 9 | if (x % 2 == 0) res++; 10 | } 11 | return res; 12 | }; -------------------------------------------------------------------------------- /src/1295-Find-Numbers-with-Even-Number-of-Digits/1295.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findNumbers(self, nums: List[int]) -> int: 3 | return sum(map(lambda n: len(str(n)) % 2 == 0, nums)) -------------------------------------------------------------------------------- /src/1297-Maximum-Number-of-Occurrences-of-a-Substring/1297.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: 3 | cnt = collections.Counter([s[i:i + minSize] for i in range(len(s) - minSize + 1)]) 4 | for k, v in cnt.most_common(): 5 | if len(set(k)) <= maxLetters: 6 | return v 7 | return 0 -------------------------------------------------------------------------------- /src/1299-Replace-Elements-with-Greatest-Element-on-Right-Side/1299.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector replaceElements(vector& arr) 5 | { 6 | int max_right = -1; 7 | for (int i = arr.size() - 1; i >= 0; i--) 8 | { 9 | max_right = max(arr[i], exchange(arr[i], max_right)); 10 | } 11 | return arr; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1299-Replace-Elements-with-Greatest-Element-on-Right-Side/1299.go: -------------------------------------------------------------------------------- 1 | func replaceElements(arr []int) []int { 2 | max_right := -1 3 | for i := len(arr) - 1; i >= 0; i-- { 4 | max_right, arr[i] = max(arr[i], max_right), max_right 5 | } 6 | return arr 7 | } 8 | 9 | func max(a, b int) int { 10 | if a > b { 11 | return a 12 | } 13 | return b 14 | } -------------------------------------------------------------------------------- /src/1299-Replace-Elements-with-Greatest-Element-on-Right-Side/1299.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] replaceElements(int[] arr) { 3 | int max_right = -1; 4 | for (int i = arr.length - 1; i >= 0; i--) { 5 | max_right = Math.max(arr[i], arr[i] = max_right); 6 | } 7 | return arr; 8 | } 9 | } -------------------------------------------------------------------------------- /src/1299-Replace-Elements-with-Greatest-Element-on-Right-Side/1299.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} arr 3 | * @return {number[]} 4 | */ 5 | var replaceElements = function(arr) { 6 | let max_right = -1; 7 | for (let i = arr.length - 1; i >= 0; i--) { 8 | max_right = Math.max(arr[i], arr[i] = max_right); 9 | } 10 | return arr; 11 | }; -------------------------------------------------------------------------------- /src/1299-Replace-Elements-with-Greatest-Element-on-Right-Side/1299.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def replaceElements(self, arr: List[int]) -> List[int]: 3 | max_right = -1 4 | for i in range(len(arr) - 1, -1, -1): 5 | arr[i], max_right = max_right, max(max_right, arr[i]) 6 | return arr -------------------------------------------------------------------------------- /src/1300-Sum-of-Mutated-Array-Closest-to-Target/1300.js: -------------------------------------------------------------------------------- 1 | var findBestValue = function(arr, target) { 2 | arr.sort((a, b) => b - a); 3 | let maxv = arr[0]; 4 | while (arr != false && target >= arr[arr.length-1]*arr.length) { 5 | target -= arr.pop(); 6 | } 7 | return arr != false ? Math.floor(target/arr.length + 0.49) : maxv; 8 | }; -------------------------------------------------------------------------------- /src/1300-Sum-of-Mutated-Array-Closest-to-Target/1300.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findBestValue(self, A: List[int], target: int) -> int: 3 | A.sort(reverse=True) 4 | maxA = A[0] 5 | while A and target >= A[-1] * len(A): 6 | target -= A.pop() 7 | return int(target/len(A) + 0.49) if A else maxA -------------------------------------------------------------------------------- /src/1302-Deepest-Leaves-Sum/1302.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deepestLeavesSum(self, root: TreeNode) -> int: 3 | l = [root] 4 | while l: 5 | pre, l = l, [child for p in l for child in [p.left, p.right] if child] 6 | return sum(node.val for node in pre) -------------------------------------------------------------------------------- /src/1304-Find-N-Unique-Integers-Sum-up-to-Zero/1304.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector sumZero(int n) 5 | { 6 | vector res; 7 | for (int i = 1 - n; i < n; i += 2) res.push_back(i); 8 | return res; 9 | } 10 | }; -------------------------------------------------------------------------------- /src/1304-Find-N-Unique-Integers-Sum-up-to-Zero/1304.go: -------------------------------------------------------------------------------- 1 | func sumZero(n int) []int { 2 | res := []int{} 3 | for i := 1 - n; i < n; i += 2 { 4 | res = append(res, i) 5 | } 6 | return res 7 | } -------------------------------------------------------------------------------- /src/1304-Find-N-Unique-Integers-Sum-up-to-Zero/1304.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] sumZero(int n) { 3 | int[] res = new int[n]; 4 | for (int i = 1 - n, j = 0; i < n; i += 2, j++) res[j] = i; 5 | return res; 6 | } 7 | } -------------------------------------------------------------------------------- /src/1304-Find-N-Unique-Integers-Sum-up-to-Zero/1304.js: -------------------------------------------------------------------------------- 1 | var sumZero = function(n) { 2 | let res = new Array(n); 3 | for (let i = 1 - n, j = 0; i < n; i += 2, j++) res[j] = i; 4 | return res; 5 | }; -------------------------------------------------------------------------------- /src/1304-Find-N-Unique-Integers-Sum-up-to-Zero/1304.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumZero(self, n: int) -> List[int]: 3 | return list(range(1 - n, n, 2)) -------------------------------------------------------------------------------- /src/1309-Decrypt-String-from-Alphabet-to-Integer-Mapping/1309.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def freqAlphabets(self, s: str) -> str: 3 | return ''.join(chr(int(i[:2]) + 96) for i in re.findall(r'\d\d#|\d', s)) -------------------------------------------------------------------------------- /src/1310-XOR-Queries-of-a-Subarray/1310.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]: 3 | A = [0] 4 | for a in arr: 5 | A.append(A[-1] ^ a) 6 | return [A[l] ^ A[r + 1] for l, r in queries] -------------------------------------------------------------------------------- /src/1313-Decompress-Run-Length-Encoded-List/1313.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector decompressRLElist(vector& nums) 5 | { 6 | vector res; 7 | for (int i = 0; i < nums.size(); i += 2) 8 | { 9 | res.insert(res.end(), nums[i], nums[i + 1]); 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1313-Decompress-Run-Length-Encoded-List/1313.go: -------------------------------------------------------------------------------- 1 | func decompressRLElist(nums []int) []int { 2 | res := []int{} 3 | 4 | for i := 0; i < len(nums); i += 2 { 5 | for j := 0; j < nums[i]; j++ { 6 | res = append(res, nums[i + 1]) 7 | } 8 | } 9 | return res; 10 | } -------------------------------------------------------------------------------- /src/1313-Decompress-Run-Length-Encoded-List/1313.js: -------------------------------------------------------------------------------- 1 | var decompressRLElist = function(nums) { 2 | let res = []; 3 | for (let i = 0; i < nums.length; i += 2) { 4 | for (let j = 0; j < nums[i]; j++) { 5 | res.push(nums[i + 1]); 6 | } 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1313-Decompress-Run-Length-Encoded-List/1313.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decompressRLElist(self, nums: List[int]) -> List[int]: 3 | return [x for a, b in zip(nums[0::2], nums[1::2]) for x in [b] * a] -------------------------------------------------------------------------------- /src/1315-Sum-of-Nodes-with-Even-Valued-Grandparent/1315.js: -------------------------------------------------------------------------------- 1 | var sumEvenGrandparent = function(root) { 2 | let dfs = function(node, p, gp) { 3 | if (node == null) return 0; 4 | return dfs(node.left, node.val, p) + 5 | dfs(node.right, node.val, p) + 6 | (gp % 2 == 0 ? node.val : 0); 7 | } 8 | return dfs(root, 1, 1); 9 | }; -------------------------------------------------------------------------------- /src/1316-Distinct-Echo-Substrings/1316.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1316-Distinct-Echo-Substrings/1316.go -------------------------------------------------------------------------------- /src/1316-Distinct-Echo-Substrings/1316.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1316-Distinct-Echo-Substrings/1316.java -------------------------------------------------------------------------------- /src/1316-Distinct-Echo-Substrings/1316.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1316-Distinct-Echo-Substrings/1316.js -------------------------------------------------------------------------------- /src/1317-Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317.go: -------------------------------------------------------------------------------- 1 | func getNoZeroIntegers(n int) []int { 2 | for a := 1; a < n; a++ { 3 | b := n - a 4 | if !strings.Contains(strconv.Itoa(a), "0") && !strings.Contains(strconv.Itoa(b), "0") { 5 | return []int{a, b} 6 | } 7 | } 8 | return []int{} 9 | } -------------------------------------------------------------------------------- /src/1317-Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] getNoZeroIntegers(int n) { 3 | for (int a = 1; a < n; a++) { 4 | int b = n - a; 5 | if (!String.valueOf(a).contains("0") && !String.valueOf(b).contains("0")) 6 | return new int[]{a, b}; 7 | } 8 | return new int[]{}; 9 | } 10 | } -------------------------------------------------------------------------------- /src/1317-Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317.js: -------------------------------------------------------------------------------- 1 | var getNoZeroIntegers = function(n) { 2 | for (let a = 1; a < n; a++) { 3 | let b = n - a; 4 | if ((b+"").indexOf("0") == -1 && (a+"").indexOf("0") == -1) { 5 | return [a, b]; 6 | } 7 | } 8 | return []; 9 | }; -------------------------------------------------------------------------------- /src/1317-Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getNoZeroIntegers(self, n: int) -> List[int]: 3 | return next([a, n-a] for a in range(1, n) if '0' not in f'{a}{n-a}') -------------------------------------------------------------------------------- /src/1318-Minimum-Flips-to-Make-a-OR-b-Equal-to-c/1318.js: -------------------------------------------------------------------------------- 1 | var minFlips = function(a, b, c) { 2 | let res = 0; 3 | while (a || b || c) { 4 | if (c & 1) res += (a & 1) || (b & 1) ? 0 : 1; 5 | else res += (a & 1) + (b & 1); 6 | a >>= 1, b >>= 1, c >>= 1; 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1323-Maximum-69-Number/1323.go: -------------------------------------------------------------------------------- 1 | func maximum69Number (num int) int { 2 | res, _ := strconv.Atoi(strings.Replace(strconv.Itoa(num), "6", "9", 1)) 3 | return res 4 | } -------------------------------------------------------------------------------- /src/1323-Maximum-69-Number/1323.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximum69Number (int num) { 3 | return Integer.valueOf(String.valueOf(num).replaceFirst("6", "9")); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1323-Maximum-69-Number/1323.js: -------------------------------------------------------------------------------- 1 | var maximum69Number = function(num) { 2 | return Number((num + "").replace(/6/, "9")); 3 | }; -------------------------------------------------------------------------------- /src/1323-Maximum-69-Number/1323.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximum69Number (self, num: int) -> int: 3 | return int(str(num).replace('6', '9', 1)) -------------------------------------------------------------------------------- /src/1324-Print-Words-Vertically/1324.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def printVertically(self, s: str) -> List[str]: 3 | return [''.join(a).rstrip() for a in itertools.zip_longest(*s.split(), fillvalue=' ')] -------------------------------------------------------------------------------- /src/1325-Delete-Leaves-With-a-Given-Value/1325.go: -------------------------------------------------------------------------------- 1 | func removeLeafNodes(root *TreeNode, target int) *TreeNode { 2 | if root == nil { 3 | return nil 4 | } 5 | 6 | root.Left = removeLeafNodes(root.Left, target) 7 | root.Right = removeLeafNodes(root.Right, target) 8 | if root.Val == target && root.Left == root.Right { 9 | return nil 10 | } 11 | return root 12 | } -------------------------------------------------------------------------------- /src/1325-Delete-Leaves-With-a-Given-Value/1325.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public TreeNode removeLeafNodes(TreeNode root, int target) { 3 | if (root == null) return null; 4 | root.left = removeLeafNodes(root.left, target); 5 | root.right = removeLeafNodes(root.right, target); 6 | return root.val == target && root.left == root.right ? null : root; 7 | } 8 | } -------------------------------------------------------------------------------- /src/1325-Delete-Leaves-With-a-Given-Value/1325.js: -------------------------------------------------------------------------------- 1 | var removeLeafNodes = function(root, target) { 2 | if (root == null) return null; 3 | root.left = removeLeafNodes(root.left, target); 4 | root.right = removeLeafNodes(root.right, target); 5 | return root.val == target && root.left == root.right ? null : root; 6 | }; -------------------------------------------------------------------------------- /src/1326-Minimum-Number-of-Taps-to-Open-to-Water-a-Garden/1326.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1326-Minimum-Number-of-Taps-to-Open-to-Water-a-Garden/1326.js -------------------------------------------------------------------------------- /src/1328-Break-a-Palindrome/1328.go: -------------------------------------------------------------------------------- 1 | func breakPalindrome(palindrome string) string { 2 | p := []byte(palindrome) 3 | for i := 0; i < len(p)/2; i++ { 4 | if p[i] != 'a' { 5 | p[i] = 'a' 6 | return string(p) 7 | } 8 | } 9 | if len(p) < 2 { 10 | return "" 11 | } 12 | p[len(p) - 1] = 'b' 13 | return string(p) 14 | } -------------------------------------------------------------------------------- /src/1328-Break-a-Palindrome/1328.js: -------------------------------------------------------------------------------- 1 | var breakPalindrome = function(p) { 2 | let n = Math.floor(p.length/2); 3 | for (let i = 0; i < n; i++) { 4 | if (p[i] != 'a') { 5 | return p.slice(0, i) + 'a' + p.slice(i + 1); 6 | } 7 | } 8 | return p.length > 1 ? p.slice(0, p.length - 1) + 'b' : ""; 9 | }; -------------------------------------------------------------------------------- /src/1328-Break-a-Palindrome/1328.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def breakPalindrome(self, p: str) -> str: 3 | for i in range(len(p) // 2): 4 | if p[i] != 'a': 5 | return p[:i] + 'a' + p[i + 1:] 6 | return p[:-1] + 'b' if p[:-1] else '' -------------------------------------------------------------------------------- /src/1331-Rank-Transform-of-an-Array/1331.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayRankTransform(self, arr: List[int]) -> List[int]: 3 | return map({a: i + 1 for i, a in enumerate(sorted(set(arr)))}.get, arr) -------------------------------------------------------------------------------- /src/1332-Remove-Palindromic-Subsequences/1332.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int removePalindromeSub(string s) 5 | { 6 | return 2 - (s == string(s.rbegin(), s.rend())) - s.empty(); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1332-Remove-Palindromic-Subsequences/1332.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removePalindromeSub(String s) { 3 | return s.isEmpty() ? 0 : (s.equals(new StringBuilder(s).reverse().toString()) ? 1 : 2); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1332-Remove-Palindromic-Subsequences/1332.js: -------------------------------------------------------------------------------- 1 | var removePalindromeSub = function(s) { 2 | return s.length == 0 ? 0 : s == s.split("").reverse().join("") ? 1 : 2; 3 | }; -------------------------------------------------------------------------------- /src/1332-Remove-Palindromic-Subsequences/1332.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removePalindromeSub(self, s: str) -> int: 3 | return 2 - (s == s[::-1]) - (s == "") -------------------------------------------------------------------------------- /src/1333-Filter-Restaurants-by-Vegan-Friendly,-Price-and-Distance/1333.js: -------------------------------------------------------------------------------- 1 | var filterRestaurants = function(restaurants, veganFriendly, maxPrice, maxDistance) { 2 | return restaurants 3 | .filter(s => s[2] >= veganFriendly && s[3] <= maxPrice && s[4] <= maxDistance) 4 | .sort((a, b) => b[1] - a[1] || b[0] - a[0]) 5 | .map(s => s[0]); 6 | }; -------------------------------------------------------------------------------- /src/1333-Filter-Restaurants-by-Vegan-Friendly,-Price-and-Distance/1333.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]: 3 | restaurants.sort(key=lambda x: (-x[1], -x[0])) 4 | return [i for i, _, v, p, d in restaurants if v >= veganFriendly and p <= maxPrice and d <= maxDistance] -------------------------------------------------------------------------------- /src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int numberOfSteps (int num) 5 | { 6 | return num == 0 ? 0 : 1 + numberOfSteps(num & 1 ? num - 1 : num >> 1); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.go -------------------------------------------------------------------------------- /src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numberOfSteps (int num) { 3 | return num == 0 ? 0 : 1 + numberOfSteps(num % 2 == 1 ? num - 1 : num >> 1); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.js: -------------------------------------------------------------------------------- 1 | var numberOfSteps = function(num) { 2 | return num == 0 ? 0 : 1 + numberOfSteps(num & 1 ? num - 1 : num >> 1); 3 | }; -------------------------------------------------------------------------------- /src/1342-Number-of-Steps-to-Reduce-a-Number-to-Zero/1342.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfSteps (self, num: int) -> int: 3 | return 0 if not num else 1 + self.numberOfSteps(num >> 1 if num % 2 == 0 else num - 1) -------------------------------------------------------------------------------- /src/1344-Angle-Between-Hands-of-a-Clock/1344.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | double angleClock(int hour, int minutes) 5 | { 6 | double t = abs((hour*30 + minutes/2.0) - minutes*6); 7 | return min(t, 360 - t); 8 | } 9 | }; -------------------------------------------------------------------------------- /src/1344-Angle-Between-Hands-of-a-Clock/1344.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double angleClock(int hour, int minutes) { 3 | double t = Math.abs((hour*30 + minutes/2.0) - minutes*6); 4 | return Math.min(t, 360 - t); 5 | } 6 | } -------------------------------------------------------------------------------- /src/1344-Angle-Between-Hands-of-a-Clock/1344.js: -------------------------------------------------------------------------------- 1 | var angleClock = function(hour, minutes) { 2 | let t = Math.abs((hour*30 + minutes/2.0) - minutes*6); 3 | return Math.min(t, 360 - t); 4 | }; -------------------------------------------------------------------------------- /src/1344-Angle-Between-Hands-of-a-Clock/1344.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def angleClock(self, hour: int, minutes: int) -> float: 3 | t = abs((hour*30 + minutes/2) - minutes*6) 4 | return min(t, 360 - t) -------------------------------------------------------------------------------- /src/1346-Check-If-N-and-Its-Double-Exist/1346.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | bool checkIfExist(vector& arr) 5 | { 6 | unordered_set seen; 7 | for (int i : arr) 8 | { 9 | if (seen.count(2*i) || (i % 2 == 0 && seen.count(i / 2))) return true; 10 | seen.insert(i); 11 | } 12 | return false; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1346-Check-If-N-and-Its-Double-Exist/1346.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkIfExist(int[] arr) { 3 | Set seen = new HashSet(); 4 | for (int i : arr) { 5 | if (seen.contains(i * 2) || (i % 2 == 0 && seen.contains(i / 2))) return true; 6 | seen.add(i); 7 | } 8 | return false; 9 | } 10 | } -------------------------------------------------------------------------------- /src/1346-Check-If-N-and-Its-Double-Exist/1346.js: -------------------------------------------------------------------------------- 1 | var checkIfExist = function(arr) { 2 | let seen = new Map(); 3 | for (let i of arr) { 4 | if (seen.has(i * 2) || (i % 2 == 0 && seen.has(Math.floor(i / 2)))) return true; 5 | seen.set(i, 1); 6 | } 7 | return false; 8 | }; -------------------------------------------------------------------------------- /src/1346-Check-If-N-and-Its-Double-Exist/1346.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfExist(self, arr: List[int]) -> bool: 3 | seen = set() 4 | for i in arr: 5 | if 2 * i in seen or i % 2 == 0 and i // 2 in seen: 6 | return True 7 | seen.add(i) 8 | return False -------------------------------------------------------------------------------- /src/1347-Minimum-Number-of-Steps-to-Make-Two-Strings-Anagram/1347.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSteps(self, s: str, t: str) -> int: 3 | cnt1, cnt2 = map(collections.Counter, (s, t)) 4 | return sum((cnt1 - cnt2).values()) -------------------------------------------------------------------------------- /src/1351-Count-Negative-Numbers-in-a-Sorted-Matrix/1351.go: -------------------------------------------------------------------------------- 1 | func countNegatives(grid [][]int) int { 2 | r, c := len(grid), len(grid[0]) 3 | res, m, n := 0, r - 1, 0 4 | 5 | for m >= 0 && n < c { 6 | if grid[m][n] < 0 { 7 | res += c - n 8 | m-- 9 | } else { 10 | n++ 11 | } 12 | } 13 | return res 14 | } -------------------------------------------------------------------------------- /src/1351-Count-Negative-Numbers-in-a-Sorted-Matrix/1351.js: -------------------------------------------------------------------------------- 1 | var countNegatives = function(grid) { 2 | let r = grid.length, c = grid[0].length; 3 | let res = 0, m = r - 1, n = 0; 4 | 5 | while (m >= 0 && n < c) { 6 | if (grid[m][n] < 0) { 7 | res += c - n; 8 | m--; 9 | } else n++; 10 | } 11 | return res; 12 | }; -------------------------------------------------------------------------------- /src/1356-Sort-Integers-by-The-Number-of-1-Bits/1356.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector sortByBits(vector& arr) 5 | { 6 | sort(arr.begin(), arr.end(),[](const int& a, const int& b){ 7 | int ca = __builtin_popcount(a), cb = __builtin_popcount(b); 8 | return ca == cb ? a < b : ca < cb; 9 | }); 10 | return arr; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1356-Sort-Integers-by-The-Number-of-1-Bits/1356.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] sortByBits(int[] arr) { 3 | return Arrays.stream(arr).boxed().sorted(Comparator.comparingInt(i -> Integer.bitCount(i) * 10000 + i)).mapToInt(i -> i).toArray(); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1356-Sort-Integers-by-The-Number-of-1-Bits/1356.js: -------------------------------------------------------------------------------- 1 | var sortByBits = function(arr) { 2 | let bin = function(x) { 3 | let res = 0; 4 | while (x) { 5 | x = x & (x - 1); 6 | res++; 7 | } 8 | return res; 9 | } 10 | arr.sort((a, b) => (bin(a) * 10000 + a) - (bin(b) * 10000 + b)); 11 | return arr; 12 | }; -------------------------------------------------------------------------------- /src/1356-Sort-Integers-by-The-Number-of-1-Bits/1356.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortByBits(self, arr: List[int]) -> List[int]: 3 | return sorted(arr, key=lambda v: [bin(v).count('1'), v]) -------------------------------------------------------------------------------- /src/1359-Count-All-Valid-Pickup-and-Delivery-Options/1359.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int countOrders(int n) 5 | { 6 | long long res = 1, mod = 1e9 + 7; 7 | for (int i = 1; i <= n; ++i) 8 | res = res * (i * 2 - 1) * i % mod; 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1359-Count-All-Valid-Pickup-and-Delivery-Options/1359.go: -------------------------------------------------------------------------------- 1 | func countOrders(n int) int { 2 | var res, mod int64 3 | res, mod = 1, 1000000007 4 | 5 | for i := 1; i <= n; i++ { 6 | res = res * int64((i * 2 - 1) * i) % mod 7 | } 8 | return int(res) 9 | } -------------------------------------------------------------------------------- /src/1359-Count-All-Valid-Pickup-and-Delivery-Options/1359.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countOrders(int n) { 3 | long res = 1, mod = (long)1e9 + 7; 4 | for (int i = 1; i <= n; ++i) 5 | res = res * (i * 2 - 1) * i % mod; 6 | return (int)res; 7 | } 8 | } -------------------------------------------------------------------------------- /src/1359-Count-All-Valid-Pickup-and-Delivery-Options/1359.js: -------------------------------------------------------------------------------- 1 | var countOrders = function(n) { 2 | let res = 1, mod = 1000000007; 3 | 4 | for (let i = 1; i <= n; i++) { 5 | res = res * (2 * i - 1) * i % mod; 6 | } 7 | return res; 8 | }; -------------------------------------------------------------------------------- /src/1359-Count-All-Valid-Pickup-and-Delivery-Options/1359.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countOrders(self, n: int) -> int: 3 | return (math.factorial(n * 2) >> n) % (10**9 + 7) -------------------------------------------------------------------------------- /src/1362-Closest-Divisors/1362.go: -------------------------------------------------------------------------------- 1 | func closestDivisors(num int) []int { 2 | for i := int(math.Sqrt(float64(num + 2))); i > 0; i-- { 3 | if (num + 1) % i == 0 { 4 | return []int{i, (num + 1) / i} 5 | } 6 | if (num + 2) % i == 0 { 7 | return []int{i, (num + 2) / i} 8 | } 9 | } 10 | return []int{} 11 | } -------------------------------------------------------------------------------- /src/1362-Closest-Divisors/1362.js: -------------------------------------------------------------------------------- 1 | var closestDivisors = function(num) { 2 | for (let a = Math.floor(Math.sqrt(num + 2)); a > 0; a--) { 3 | if ((num + 1) % a == 0) return [a, Math.floor((num + 1) / a)]; 4 | if ((num + 2) % a == 0) return [a, Math.floor((num + 2) / a)]; 5 | } 6 | return []; 7 | }; -------------------------------------------------------------------------------- /src/1365-How-Many-Numbers-Are-Smaller-Than-the-Current-Number/1365.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 3 | cnt = collections.Counter(nums) 4 | for i in range(1, 101): 5 | cnt[i] += cnt[i - 1] 6 | 7 | return [cnt[x - 1] for x in nums] -------------------------------------------------------------------------------- /src/1366-Rank-Teams-by-Votes/1366.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rankTeams(self, votes: List[str]) -> str: 3 | cnt = {v: [0] * len(votes[0]) + [v] for v in votes[0]} 4 | for vote in votes: 5 | for i, v in enumerate(vote): 6 | cnt[v][i] -= 1 7 | return "".join(sorted(votes[0], key=lambda x: cnt[x])) -------------------------------------------------------------------------------- /src/1374-Generate-a-String-With-Characters-That-Have-Odd-Counts/1374.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | string generateTheString(int n) 5 | { 6 | return string(n - 1, 'a') + (n % 2 ? 'a' : 'b'); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1374-Generate-a-String-With-Characters-That-Have-Odd-Counts/1374.go: -------------------------------------------------------------------------------- 1 | func generateTheString(n int) string { 2 | res := []byte{} 3 | for i := 0; i < n - 1; i++ { 4 | res = append(res, 'a') 5 | } 6 | 7 | if n % 2 == 1 { 8 | res = append(res, 'a') 9 | } else { 10 | res = append(res, 'b') 11 | } 12 | return string(res) 13 | } -------------------------------------------------------------------------------- /src/1374-Generate-a-String-With-Characters-That-Have-Odd-Counts/1374.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String generateTheString(int n) { 3 | return "a".repeat(n - 1) + (n % 2 == 1 ? "a" : "b"); 4 | } 5 | } -------------------------------------------------------------------------------- /src/1374-Generate-a-String-With-Characters-That-Have-Odd-Counts/1374.js: -------------------------------------------------------------------------------- 1 | var generateTheString = function(n) { 2 | return 'a'.repeat(n - 1) + (n % 2 ? 'a' : 'b'); 3 | }; -------------------------------------------------------------------------------- /src/1374-Generate-a-String-With-Characters-That-Have-Odd-Counts/1374.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generateTheString(self, n: int) -> str: 3 | return 'a'*(n - 1) + ('a' if n % 2 else 'b') -------------------------------------------------------------------------------- /src/1375-Bulb-Switcher-III/1375.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int numTimesAllBlue(vector& light) 5 | { 6 | int res = 0, maxv = 0; 7 | for (int i = 0; i < light.size(); i++) 8 | { 9 | maxv = max(maxv, light[i]); 10 | if (maxv == i + 1) res++; 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1375-Bulb-Switcher-III/1375.go: -------------------------------------------------------------------------------- 1 | func numTimesAllBlue(light []int) int { 2 | res, maxv := 0, 0 3 | for i := 0; i < len(light); i++ { 4 | maxv = max(maxv, light[i]) 5 | if maxv == i + 1 { 6 | res++ 7 | } 8 | } 9 | return res 10 | 11 | } 12 | 13 | func max(a, b int) int { 14 | if a > b { 15 | return a 16 | } 17 | return b 18 | } -------------------------------------------------------------------------------- /src/1375-Bulb-Switcher-III/1375.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numTimesAllBlue(int[] light) { 3 | int res = 0, maxv = 0; 4 | for (int i = 0; i < light.length; i++) { 5 | maxv = Math.max(maxv, light[i]); 6 | if (maxv == i + 1) res++; 7 | } 8 | return res; 9 | } 10 | } -------------------------------------------------------------------------------- /src/1375-Bulb-Switcher-III/1375.js: -------------------------------------------------------------------------------- 1 | var numTimesAllBlue = function(light) { 2 | let res = 0, maxv = 0; 3 | for (let i = 0; i < light.length; i++) { 4 | maxv = Math.max(maxv, light[i]); 5 | if (maxv == i + 1) res++; 6 | } 7 | return res; 8 | }; -------------------------------------------------------------------------------- /src/1375-Bulb-Switcher-III/1375.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numTimesAllBlue(self, light: List[int]) -> int: 3 | res, maxv = 0, 0 4 | for i, v in enumerate(light): 5 | maxv = max(v, maxv) 6 | if maxv == i + 1: res += 1 7 | return res -------------------------------------------------------------------------------- /src/1380-Lucky-Numbers-in-a-Matrix/1380.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def luckyNumbers(self, A: List[List[int]]) -> List[int]: 3 | return list({min(row) for row in A} & {max(col) for col in zip(*A)}) -------------------------------------------------------------------------------- /src/1389-Create-Target-Array-in-the-Given-Order/1389.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector createTargetArray(vector& nums, vector& index) { 4 | vector res; 5 | for (int i = 0; i < nums.size(); i++) 6 | res.insert(res.begin() + index[i], nums[i]); 7 | return res; 8 | } 9 | }; -------------------------------------------------------------------------------- /src/1389-Create-Target-Array-in-the-Given-Order/1389.go: -------------------------------------------------------------------------------- 1 | func createTargetArray(nums []int, index []int) []int { 2 | res := make([]int, len(nums)) 3 | for i, v := range index { 4 | copy(res[v + 1:i + 1], res[v:i]) 5 | res[v] = nums[i] 6 | } 7 | return res 8 | } -------------------------------------------------------------------------------- /src/1389-Create-Target-Array-in-the-Given-Order/1389.js: -------------------------------------------------------------------------------- 1 | var createTargetArray = function(nums, index) { 2 | let res = []; 3 | for (let i = 0; i < nums.length; i++) { 4 | res.splice(index[i], 0, nums[i]); 5 | } 6 | return res; 7 | }; -------------------------------------------------------------------------------- /src/1389-Create-Target-Array-in-the-Given-Order/1389.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: 3 | res = [] 4 | for i in range(len(nums)): 5 | res.insert(index[i], nums[i]) 6 | return res -------------------------------------------------------------------------------- /src/1392-Longest-Happy-Prefix/1392.go: -------------------------------------------------------------------------------- 1 | func longestPrefix(s string) string { 2 | n := len(s) 3 | i, j := 0, -1 4 | f := make([]int, n + 1) 5 | f[0] = -1 6 | 7 | for i < n { 8 | for j != -1 && s[i] != s[j] { 9 | j = f[j] 10 | } 11 | i++ 12 | j++ 13 | f[i] = j 14 | } 15 | return s[:f[n]] 16 | } -------------------------------------------------------------------------------- /src/1392-Longest-Happy-Prefix/1392.js: -------------------------------------------------------------------------------- 1 | var longestPrefix = function(s) { 2 | let n = s.length, i = 0, j; 3 | let f = new Array(n + 1).fill(0); 4 | f[0] = j = -1; 5 | 6 | while (i < n) { 7 | while (j != -1 && s.charAt(i) != s.charAt(j)) j = f[j]; 8 | ++i; ++j; 9 | f[i] = j; 10 | } 11 | return s.substring(0, f[n]); 12 | }; -------------------------------------------------------------------------------- /src/1394-Find-Lucky-Integer-in-an-Array/1394.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLucky(vector& arr) { 4 | int cnt[501] = {}; 5 | for (int i : arr) cnt[i]++; 6 | 7 | for (int i = 500; i; i--) { 8 | if (cnt[i] == i) return i; 9 | } 10 | return -1; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1394-Find-Lucky-Integer-in-an-Array/1394.go: -------------------------------------------------------------------------------- 1 | func findLucky(arr []int) int { 2 | cnt := make([]int, 501) 3 | for _, i := range arr { 4 | cnt[i]++ 5 | } 6 | 7 | for i := 500; i > 0; i-- { 8 | if cnt[i] == i { 9 | return i 10 | } 11 | } 12 | return -1 13 | } -------------------------------------------------------------------------------- /src/1394-Find-Lucky-Integer-in-an-Array/1394.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findLucky(int[] arr) { 3 | int[] cnt = new int[501]; 4 | for (int i : arr) cnt[i]++; 5 | 6 | for (int i = 500; i > 0; i--) { 7 | if (cnt[i] == i) return i; 8 | } 9 | return -1; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1394-Find-Lucky-Integer-in-an-Array/1394.js: -------------------------------------------------------------------------------- 1 | var findLucky = function(arr) { 2 | let cnt = new Array(501).fill(0); 3 | for (let i of arr) cnt[i]++; 4 | 5 | for (let i = 500; i > 0; i--) { 6 | if (cnt[i] == i) return i; 7 | } 8 | return -1; 9 | }; -------------------------------------------------------------------------------- /src/1394-Find-Lucky-Integer-in-an-Array/1394.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findLucky(self, arr: List[int]) -> int: 3 | return max([k for k, v in collections.Counter(arr).items() if k == v] + [-1]) -------------------------------------------------------------------------------- /src/1399-Count-Largest-Group/1399.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countLargestGroup(self, n: int) -> int: 3 | cnt, mx, res = collections.defaultdict(int), 0, 0 4 | for i in range(1, n + 1): 5 | t = sum([int(j) for j in str(i)]) 6 | cnt[t] += 1 7 | mx = max(mx, cnt[t]) 8 | 9 | return sum([i == mx for i in cnt.values()]) -------------------------------------------------------------------------------- /src/1400-Construct-K-Palindrome-Strings/1400.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canConstruct(string s, int k) { 4 | bitset<26> odds; 5 | for (char& c : s) odds.flip(c - 'a'); 6 | return odds.count() <= k && k <= s.length(); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/1400-Construct-K-Palindrome-Strings/1400.go: -------------------------------------------------------------------------------- 1 | func canConstruct(s string, k int) bool { 2 | odds, n := 0, len(s) 3 | cnt := make([]int, 26) 4 | for i := 0; i < n; i++ { 5 | cnt[s[i] - 'a'] ^= 1 6 | if cnt[s[i] - 'a'] > 0 { 7 | odds++ 8 | } else { 9 | odds-- 10 | } 11 | } 12 | return odds <= k && k <= n 13 | } -------------------------------------------------------------------------------- /src/1400-Construct-K-Palindrome-Strings/1400.js: -------------------------------------------------------------------------------- 1 | var canConstruct = function(s, k) { 2 | let odds = 0, n = s.length, count = new Array(26).fill(0); 3 | for (let i = 0; i < n; ++i) { 4 | count[s.charCodeAt(i) - 97] ^= 1; 5 | odds += count[s.charCodeAt(i) - 97] > 0 ? 1 : -1; 6 | } 7 | return odds <= k && k <= n; 8 | }; -------------------------------------------------------------------------------- /src/1400-Construct-K-Palindrome-Strings/1400.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canConstruct(self, s: str, k: int) -> bool: 3 | return sum([v % 2 for v in collections.Counter(s).values()]) <= k <= len(s) -------------------------------------------------------------------------------- /src/1401-Circle-and-Rectangle-Overlapping/1401.js: -------------------------------------------------------------------------------- 1 | var checkOverlap = function(r, xc, yc, x1, y1, x2, y2) { 2 | let x = (x1 + x2) / 2, y = (y1 + y2) / 2; 3 | let h = [x2 - x, y2 - y]; 4 | let v = [Math.abs(x - xc), Math.abs(y - yc)]; 5 | let u = [Math.max(v[0] - h[0], 0), Math.max(v[1] - h[1], 0)]; 6 | return r * r >= u[0] * u[0] + u[1] * u[1]; 7 | }; -------------------------------------------------------------------------------- /src/1401-Circle-and-Rectangle-Overlapping/1401.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkOverlap(self, r: int, xc: int, yc: int, x1: int, y1: int, x2: int, y2: int) -> bool: 3 | x, y = (x1 + x2) / 2, (y1 + y2) / 2 4 | h = [x2 - x, y2 - y] 5 | v = [abs(x - xc), abs(y - yc)] 6 | u = [max(v[0] - h[0], 0), max(v[1] - h[1], 0)] 7 | return r**2 >= (u[0]**2 + u[1]**2) -------------------------------------------------------------------------------- /src/1402-Reducing-Dishes/1402.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSatisfaction(vector& s) { 4 | sort(s.begin(), s.end()); 5 | int res = 0, total = 0, n = s.size(); 6 | 7 | for (int i = n - 1; i >= 0 && s[i] > -total; --i) { 8 | total += s[i]; 9 | res += total; 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1402-Reducing-Dishes/1402.go: -------------------------------------------------------------------------------- 1 | func maxSatisfaction(s []int) int { 2 | sort.Ints(s) 3 | res, total, n := 0, 0, len(s) 4 | 5 | for i := n - 1; i >= 0 && s[i] > -total; i-- { 6 | total += s[i] 7 | res += total 8 | } 9 | return res 10 | } -------------------------------------------------------------------------------- /src/1402-Reducing-Dishes/1402.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSatisfaction(int[] s) { 3 | Arrays.sort(s); 4 | int res = 0, total = 0, n = s.length; 5 | 6 | for (int i = n - 1; i >= 0 && s[i] > -total; --i) { 7 | total += s[i]; 8 | res += total; 9 | } 10 | return res; 11 | } 12 | } -------------------------------------------------------------------------------- /src/1402-Reducing-Dishes/1402.js: -------------------------------------------------------------------------------- 1 | var maxSatisfaction = function(s) { 2 | s.sort((a, b) => a - b); 3 | let res = 0, total = 0, n = s.length; 4 | 5 | for (let i = n - 1; i >= 0 && s[i] > -total; --i) { 6 | total += s[i]; 7 | res += total; 8 | } 9 | return res; 10 | }; -------------------------------------------------------------------------------- /src/1402-Reducing-Dishes/1402.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSatisfaction(self, s: List[int]) -> int: 3 | res = total = 0 4 | s.sort() 5 | 6 | while s and s[-1] + total > 0: 7 | total += s.pop() 8 | res += total 9 | return res -------------------------------------------------------------------------------- /src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSubsequence(self, nums: List[int]) -> List[int]: 3 | nums.sort(reverse=True) 4 | res, cur, t = [], 0, sum(nums) / 2 5 | 6 | for i in nums: 7 | cur += i 8 | res.append(i) 9 | if cur > t: return res 10 | return res -------------------------------------------------------------------------------- /src/1404-Number-of-Steps-to-Reduce-a-Number-in-Binary-Representation-to-One/1404.go: -------------------------------------------------------------------------------- 1 | func numSteps(s string) int { 2 | res, add, n := 0, 0, len(s) 3 | 4 | for i := n - 1; i > 0; i-- { 5 | res++ 6 | if int(s[i] - '0') + add == 1 { 7 | add = 1 8 | res++ 9 | } 10 | } 11 | return res + add 12 | } -------------------------------------------------------------------------------- /src/1404-Number-of-Steps-to-Reduce-a-Number-in-Binary-Representation-to-One/1404.js: -------------------------------------------------------------------------------- 1 | var numSteps = function(s) { 2 | let res = 0, add = 0, n = s.length; 3 | 4 | for (let i = n - 1; i > 0; i--) { 5 | res++; 6 | if (s.charCodeAt(i) - 48 + add == 1) { 7 | add = 1; 8 | res++; 9 | } 10 | } 11 | return res + add; 12 | }; -------------------------------------------------------------------------------- /src/1404-Number-of-Steps-to-Reduce-a-Number-in-Binary-Representation-to-One/1404.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSteps(self, s: str) -> int: 3 | res, add, n = 0, 0, len(s) 4 | for i in range(n - 1, 0, -1): 5 | res += 1 6 | if (1 if s[i] == '1' else 0) + add == 1: # 当前为奇数,需要加1和移位 7 | add = 1 8 | res += 1 9 | return res + add -------------------------------------------------------------------------------- /src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.go: -------------------------------------------------------------------------------- 1 | func numOfWays(n int) int { 2 | var aba, abc, mod int64 3 | aba, abc, mod = 6, 6, 1000000007 4 | for i := 0; i < n - 1; i++ { 5 | aba, abc = (aba * 3 + abc * 2) % mod, (aba * 2 + abc * 2) % mod 6 | } 7 | return int((aba + abc) % mod) 8 | } -------------------------------------------------------------------------------- /src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.js: -------------------------------------------------------------------------------- 1 | var numOfWays = function(n) { 2 | let aba = 6, abc = 6, t_aba, t_abc, mod = 1000000007; 3 | for (let i = 0; i < n - 1; i++) { 4 | t_aba = aba * 3 + abc * 2; 5 | t_abc = aba * 2 + abc * 2; 6 | aba = t_aba % mod; 7 | abc = t_abc % mod; 8 | } 9 | return (aba + abc) % mod; 10 | }; -------------------------------------------------------------------------------- /src/1411-Number-of-Ways-to-Paint-N×3-Grid/1411.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numOfWays(self, n: int) -> int: 3 | aba, abc, mod = 6, 6, 10**9 + 7 4 | for i in range(n - 1): 5 | aba, abc = aba * 3 + abc * 2, aba * 2 + abc * 2 6 | return (aba + abc) % mod -------------------------------------------------------------------------------- /src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minStartValue(vector& nums) { 4 | int pref = 0, min_pref = 0; 5 | for (int i : nums) { 6 | pref += i; 7 | min_pref = min(min_pref, pref); 8 | } 9 | return 1 - min_pref; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.go: -------------------------------------------------------------------------------- 1 | func minStartValue(nums []int) int { 2 | pref, min_pref := 0, 0 3 | for _, i := range nums { 4 | pref += i 5 | min_pref = min(min_pref, i) 6 | } 7 | return 1 - min_pref 8 | } 9 | 10 | func min(a, b int) int { 11 | if a < b { 12 | return a 13 | } 14 | return b 15 | } -------------------------------------------------------------------------------- /src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minStartValue(int[] nums) { 3 | int pref = 0, min_pref = 0; 4 | for (int i : nums) { 5 | pref += i; 6 | min_pref = Math.min(min_pref, pref); 7 | } 8 | return 1 - min_pref; 9 | } 10 | } -------------------------------------------------------------------------------- /src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.js: -------------------------------------------------------------------------------- 1 | var minStartValue = function(nums) { 2 | let pref = 0, min_pref = 0; 3 | for (let i of nums) { 4 | pref += i; 5 | min_pref = Math.min(min_pref, pref); 6 | } 7 | return 1 - min_pref; 8 | }; -------------------------------------------------------------------------------- /src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minStartValue(self, nums: List[int]) -> int: 3 | pref, min_pref = 0, 0 4 | for i in nums: 5 | pref += i 6 | min_pref = min(min_pref, pref) 7 | return 1 - min_pref -------------------------------------------------------------------------------- /src/1414-Find-the-Minimum-Number-of-Fibonacci-Numbers-Whose-Sum-Is-K/1414.go: -------------------------------------------------------------------------------- 1 | func findMinFibonacciNumbers(k int) int { 2 | res, a, b := 0, 1, 1 3 | for b <= k { 4 | a, b = b, a + b 5 | } 6 | 7 | for a > 0 { 8 | if a <= k { 9 | k -= a 10 | res++ 11 | } 12 | a, b = b - a, a 13 | } 14 | return res 15 | } -------------------------------------------------------------------------------- /src/1422-Maximum-Score-After-Splitting-a-String/1422.js: -------------------------------------------------------------------------------- 1 | var maxScore = function(s) { 2 | let zeros = 0, ones = 0, res = -1000, n = s.length; 3 | for (let i = 0; i < n; i++) { 4 | if (s.charAt(i) == '1') ones++; 5 | else zeros++; 6 | if (i != n - 1) res = Math.max(res, zeros - ones); 7 | } 8 | return res + ones; 9 | }; -------------------------------------------------------------------------------- /src/1422-Maximum-Score-After-Splitting-a-String/1422.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScore(self, s: str) -> int: 3 | zeros, ones, res, n = 0, 0, float("-inf"), len(s) 4 | for i in range(n): 5 | if s[i] == '1': ones += 1 6 | else: zeros += 1 7 | if i != n - 1: res = max(res, zeros - ones) 8 | return res + ones -------------------------------------------------------------------------------- /src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.js: -------------------------------------------------------------------------------- 1 | var maxScore = function(cardPoints, k) { 2 | let res = 0, cur = 0, n = cardPoints.length; 3 | for (let i = n - k; i < n + k; i++) { 4 | cur += cardPoints[i % n]; 5 | if (i >= n) cur -= cardPoints[i - k]; 6 | res = Math.max(res, cur); 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScore(self, cardPoints: List[int], k: int) -> int: 3 | res = cur = 0 4 | for i in range(-k, k): 5 | cur += cardPoints[i] 6 | if i >= 0: 7 | cur -= cardPoints[i - k] 8 | res = max(cur, res) 9 | return res -------------------------------------------------------------------------------- /src/1424-Diagonal-Traverse-II/1424.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]: 3 | res = [] 4 | for i, r in enumerate(nums): 5 | for j, a in enumerate(r): 6 | if len(res) <= i + j: 7 | res.append([]) 8 | res[i + j].append(a) 9 | return [a for r in res for a in r[::-1]] -------------------------------------------------------------------------------- /src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.java -------------------------------------------------------------------------------- /src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js: -------------------------------------------------------------------------------- 1 | var kidsWithCandies = function(candies, extraCandies) { 2 | let m = 0, res = []; 3 | for (let i of candies) m = Math.max(m, i); 4 | 5 | for (let i of candies) { 6 | res.push(extraCandies + i >= m); 7 | } 8 | return res; 9 | }; -------------------------------------------------------------------------------- /src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: 3 | m = max(candies) 4 | return [i + extraCandies >= m for i in candies] -------------------------------------------------------------------------------- /src/1434-Number-of-Ways-to-Wear-Different-Hats-to-Each-Other/1434.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luliyucoordinate/Leetcode/bcc04d49969654cb44f79218a7ef2fd5c1e5449a/src/1434-Number-of-Ways-to-Wear-Different-Hats-to-Each-Other/1434.py -------------------------------------------------------------------------------- /src/1436-Destination-City/1436.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string destCity(vector>& paths) { 4 | unordered_set s; 5 | for (auto& path : paths) s.insert(path[0]); 6 | for (auto& path : paths) { 7 | if (!s.count(path[1])) return path[1]; 8 | } 9 | return ""; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1436-Destination-City/1436.go: -------------------------------------------------------------------------------- 1 | func destCity(paths [][]string) string { 2 | s := make(map[string]int) 3 | for _, path := range paths { 4 | s[path[0]] = 1 5 | } 6 | for _, path := range paths { 7 | if _, ok := s[path[1]]; !ok { 8 | return path[1] 9 | } 10 | } 11 | return "" 12 | } -------------------------------------------------------------------------------- /src/1436-Destination-City/1436.js: -------------------------------------------------------------------------------- 1 | var destCity = function(paths) { 2 | let s = {}; 3 | for (let path of paths) s[path[0]] = 1; 4 | for (let path of paths) { 5 | if (!(path[1] in s)) return path[1] 6 | } 7 | return ""; 8 | }; -------------------------------------------------------------------------------- /src/1436-Destination-City/1436.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def destCity(self, paths: List[List[str]]) -> str: 3 | A, B = map(set, zip(*paths)) 4 | return (B - A).pop() -------------------------------------------------------------------------------- /src/1437-Check-If-All-1's-Are-at-Least-Length-K-Places-Away/1437.go: -------------------------------------------------------------------------------- 1 | func kLengthApart(nums []int, k int) bool { 2 | for pre, i := -k - 1, 0; i < len(nums); i++ { 3 | if nums[i] == 1 { 4 | if i - pre <= k { 5 | return false 6 | } 7 | pre = i 8 | } 9 | } 10 | return true 11 | } -------------------------------------------------------------------------------- /src/1437-Check-If-All-1's-Are-at-Least-Length-K-Places-Away/1437.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean kLengthApart(int[] nums, int k) { 3 | for(int pre = -k - 1, i = 0; i < nums.length; i++) { 4 | if (nums[i] == 1) { 5 | if (i - pre <= k) return false; 6 | pre = i; 7 | } 8 | } 9 | return true; 10 | } 11 | } -------------------------------------------------------------------------------- /src/1437-Check-If-All-1's-Are-at-Least-Length-K-Places-Away/1437.js: -------------------------------------------------------------------------------- 1 | var kLengthApart = function(nums, k) { 2 | for (let pre = -k - 1, i = 0; i < nums.length; i++) { 3 | if (nums[i] == 1) { 4 | if (i - pre <= k) return false; 5 | pre = i; 6 | } 7 | } 8 | return true; 9 | }; -------------------------------------------------------------------------------- /src/1437-Check-If-All-1's-Are-at-Least-Length-K-Places-Away/1437.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kLengthApart(self, nums: List[int], k: int) -> bool: 3 | pre = -k - 1 4 | for i, v in enumerate(nums): 5 | if v == 1: 6 | if i - pre <= k: return False 7 | pre = i 8 | return True -------------------------------------------------------------------------------- /src/1470-Shuffle-the-Array/1470.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector shuffle(vector& nums, int n) { 4 | vector res(n * 2); 5 | for (int i = 0, j = n; i < n; i++, j++) { 6 | res[i << 1] = nums[i]; 7 | res[(i << 1) + 1] = nums[j]; 8 | } 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1523-Count-Odd-Numbers-in-an-Interval-Range/1523.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOdds(int low, int high) { 4 | return (high - low) / 2 + (low & 1 || high & 1 ? 1 : 0); 5 | } 6 | }; -------------------------------------------------------------------------------- /src/1732-Find-the-Highest-Altitude/1732.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestAltitude(vector& gain) { 4 | int res = 0, cur = 0; 5 | for (auto& x : gain) { 6 | cur += x; 7 | res = max(res, cur); 8 | } 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /src/1739-Building-Boxes/1739.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumBoxes(int n) { 4 | int x = cbrt(6L * n); 5 | int res = x * (x + 1) / 2; 6 | int max_n = x * (x + 1ll) * (x + 2ll) / 6ll; 7 | if (max_n > n) { 8 | max_n -= res; 9 | res -= x; 10 | } 11 | return res + ceil((-1 + sqrt(1 + 8 * (n - max_n))) / 2); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /src/1752-Check-if-Array-Is-Sorted-and-Rotated/1752.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool check(vector& nums) { 4 | int n = nums.size(); 5 | for (int i = 0, ring = 0; i < n; i++) { 6 | if (nums[i] > nums[(i + 1) % n]) { 7 | ring++; 8 | } 9 | if (ring > 1) return false; 10 | } 11 | return true; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1758-Minimum-Changes-To-Make-Alternating-Binary-String/1758.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(string s) { 4 | int n = s.size(); 5 | int res = 0; 6 | for (int i = 0; i < n; i++) { 7 | if (s[i] != ('0' + i % 2)) { 8 | res++; 9 | } 10 | } 11 | return min(res, n - res); 12 | } 13 | }; -------------------------------------------------------------------------------- /src/1780-Check-if-Number-is-a-Sum-of-Powers-of-Three/1780.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPowersOfThree(int n) { 4 | while (n) { 5 | if (n % 3 == 2) { 6 | return false; 7 | } 8 | n /= 3; 9 | } 10 | return true; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1798-Maximum-Number-of-Consecutive-Values-You-Can-Make/1798.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int getMaximumConsecutive(vector& coins) { 4 | sort(coins.begin(), coins.end()); 5 | int res = 1; 6 | for (auto& c : coins) { 7 | if (c > res) break; 8 | res += c; 9 | } 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/1806-Minimum-Number-of-Operations-to-Reinitialize-a-Permutation/1806.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int reinitializePermutation(int n) { 4 | if (n == 2) { 5 | return 1; 6 | } 7 | int s = 1, p = 2; 8 | while (p != 1) { 9 | s++; 10 | p = p * 2 % (n - 1); 11 | } 12 | return s; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/1812-Determine-Color-of-a-Chessboard-Square/1812.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool squareIsWhite(string coordinates) { 4 | return (coordinates[0] - 'a' + coordinates[1] - '1') & 1; 5 | } 6 | }; -------------------------------------------------------------------------------- /src/1827-Minimum-Operations-to-Make-the-Array-Increasing/1827.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& nums) { 4 | int res = 0; 5 | int p = 0; 6 | for (auto& num : nums) { 7 | if (num <= p) { 8 | p++; 9 | res += p - num; 10 | } else { 11 | p = num; 12 | } 13 | } 14 | return res; 15 | } 16 | }; -------------------------------------------------------------------------------- /src/1832-Check-if-the-Sentence-is-Pangram/1832.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkIfPangram(string sentence) { 4 | int cnt[26] = {}; 5 | for (auto c : sentence) { 6 | cnt[c - 'a']++; 7 | } 8 | bool res = true; 9 | for (int i = 0; i < 26; i++) { 10 | res &= (cnt[i] >= 1); 11 | } 12 | return res; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/1832-Check-if-the-Sentence-is-Pangram/1832.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfPangram(self, sentence: str) -> bool: 3 | if set(sentence) == set('abcdefghijklmnopqrstuvwxyz'): return True 4 | else: return False 5 | 6 | -------------------------------------------------------------------------------- /src/2011-Final-Value-of-Variable-After-Performing-Operations/2011.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int finalValueAfterOperations(vector& operations) { 4 | int res = 0; 5 | for (auto& op : operations) { 6 | if (op[1] == '+') 7 | res++; 8 | else 9 | res--; 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/2027-Minimum-Moves-to-Convert-String/2027.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumMoves(string s) { 4 | int n = s.size(); 5 | int res = 0, i = 0; 6 | while (i < n) { 7 | if (s[i] == 'X') { 8 | res++; 9 | i += 3; 10 | } else { 11 | i++; 12 | } 13 | } 14 | return res; 15 | } 16 | }; -------------------------------------------------------------------------------- /src/2180-Count-Integers-With-Even-Digit-Sum/2180.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countEven(int num) { 4 | int res = num / 10 * 5 - 1; 5 | int s = 0; 6 | for (int x = num / 10; x > 0; x /= 10) { 7 | s += x % 10; 8 | } 9 | res += (num % 10 + 2 - (s & 1)) >> 1; 10 | return res; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /src/2185-Counting-Words-With-a-Given-Prefix/2185.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int prefixCount(vector& words, string pref) { 4 | return count_if(words.begin(), words.end(), [&](auto& s) { 5 | return s.compare(0, pref.size(), pref) == 0; 6 | }); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/2244-Minimum-Rounds-to-Complete-All-Tasks/2244.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumRounds(vector& tasks) { 4 | unordered_map cnt; 5 | for (auto& task : tasks) cnt[task]++; 6 | int res = 0; 7 | for (auto& [k, v] : cnt) { 8 | if (v == 1) return -1; 9 | res += (v + 2) / 3; 10 | } 11 | return res; 12 | } 13 | }; -------------------------------------------------------------------------------- /src/2315-Count-Asterisks/2315.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countAsterisks(string s) { 4 | int res = 0, n = s.size(); 5 | for (int i = 0; i < n; i++) { 6 | if (s[i] == '|') { 7 | do { 8 | i++; 9 | } while (i < n && s[i] != '|'); 10 | } else if (s[i] == '*') 11 | res++; 12 | } 13 | return res; 14 | } 15 | }; -------------------------------------------------------------------------------- /src/2331-Evaluate-Boolean-Binary-Tree/2331.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool evaluateTree(TreeNode* root) { 4 | if (root->val == 0) return false; 5 | if (root->val == 1) return true; 6 | if (root->val == 2) 7 | return evaluateTree(root->left) || evaluateTree(root->right); 8 | return evaluateTree(root->left) && evaluateTree(root->right); 9 | } 10 | }; -------------------------------------------------------------------------------- /src/2341-Maximum-Number-of-Pairs-in-Array/2341.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector numberOfPairs(vector& nums) { 4 | int a[101] = {}; 5 | for (auto x : nums) { 6 | a[x]++; 7 | } 8 | int res = 0; 9 | for (int i = 0; i <= 100; i++) { 10 | res += a[i] / 2; 11 | } 12 | return {res, (int)nums.size() - res * 2}; 13 | } 14 | }; -------------------------------------------------------------------------------- /src/2351-First-Letter-to-Appear-Twice/2351.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char repeatedCharacter(string s) { 4 | int cnt[26] = {}; 5 | for (auto c : s) { 6 | auto x = c - 'a'; 7 | if (cnt[x]) return c; 8 | cnt[x]++; 9 | } 10 | return ' '; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/2357-Make-Array-Zero-by-Subtracting-Equal-Amounts/2357.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumOperations(vector& nums) { 4 | int cnt[101] = {}; 5 | for (auto& num : nums) { 6 | cnt[num]++; 7 | } 8 | int res = 0; 9 | for (int i = 1; i <= 100; i++) res += cnt[i] ? 1 : 0; 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/2395-Find-Subarrays-With-Equal-Sum/2395.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool findSubarrays(vector& nums) { 4 | unordered_set s; 5 | for (int i = 0; i < nums.size() - 1; i++) { 6 | auto x = nums[i] + nums[i + 1]; 7 | if (s.count(x)) return true; 8 | s.insert(x); 9 | } 10 | return false; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/2427-Number-of-Common-Factors/2427.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int commonFactors(int a, int b) { 4 | int c = gcd(a, b), res = 0, i = 1; 5 | for (; i * i < c; i++) { 6 | if (c % i == 0) { 7 | res += 2; 8 | } 9 | } 10 | if (i * i == c) res++; 11 | return res; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /src/2439-Minimize-Maximum-of-Array/2439.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimizeArrayValue(vector& nums) { 4 | long long sum = 0; 5 | int n = nums.size(), res = 0; 6 | for (int i = 0; i < n; i++) { 7 | sum += nums[i]; 8 | res = max(res, int((sum + i) / (i + 1))); 9 | } 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /src/2469-Convert-the-Temperature/2469.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector convertTemperature(double celsius) { 4 | return {celsius + 273.15, celsius * 1.8 + 32}; 5 | } 6 | }; -------------------------------------------------------------------------------- /src/2549-Count-Distinct-Numbers-on-Board/2549.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int distinctIntegers(int n) { return n == 1 ? 1 : n - 1; } 4 | }; -------------------------------------------------------------------------------- /src/addProg.py: -------------------------------------------------------------------------------- 1 | with open("README.md") as f: 2 | data = f.readlines() 3 | 4 | with open("new.md", 'w') as f: 5 | for i, l in enumerate(data): 6 | if i < 6: 7 | continue 8 | sl = l.split('|') 9 | sl.insert(len(sl) - 2, " ") 10 | f.write("|".join(sl)) 11 | -------------------------------------------------------------------------------- /test/0050-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/0050-Pow(x,n)/0050.cpp" 5 | 6 | TEST(test, test1) 7 | { 8 | ASSERT_EQ(1024.00000, Solution().myPow(2.00000, 10)); 9 | } 10 | 11 | GTEST_API_ int main(int argc, char **argv) 12 | { 13 | testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | -------------------------------------------------------------------------------- /test/0058-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/0058-Length-of-Last-Word/0058.cpp" 5 | 6 | TEST(test, test1) 7 | { 8 | ASSERT_EQ(5, Solution().lengthOfLastWord("Hello World")); 9 | } 10 | 11 | GTEST_API_ int main(int argc, char **argv) 12 | { 13 | testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | -------------------------------------------------------------------------------- /test/0062-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/0062-Unique-Paths/0062.cpp" 5 | 6 | TEST(test, test1) 7 | { 8 | ASSERT_EQ(1, Solution().uniquePaths(1, 2)); 9 | } 10 | 11 | GTEST_API_ int main(int argc, char **argv) 12 | { 13 | testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | -------------------------------------------------------------------------------- /test/0067-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/0067-Add-Binary/0067.cpp" 5 | 6 | TEST(test, test1) 7 | { 8 | ASSERT_EQ("100", Solution().addBinary("11", "1")); 9 | } 10 | 11 | GTEST_API_ int main(int argc, char **argv) 12 | { 13 | testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | -------------------------------------------------------------------------------- /test/0096-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../src/0096-Unique-Binary-Search-Trees/0096.cpp" 5 | 6 | TEST(test, test1) 7 | { 8 | ASSERT_EQ(5, Solution().numTrees(3)); 9 | } 10 | 11 | GTEST_API_ int main(int argc, char **argv) 12 | { 13 | testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | --------------------------------------------------------------------------------