Skip to content

Jasonlee1995/LeetCode_Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 

Repository files navigation

LeetCode Answer

  • Recent Update : 26 May 2024
  • LeetCode Algorithm site : https://leetcode.com/problemset/algorithms/
  • Python 3 Solution
  • Following solutions may not be optimal
  • Leave issues
    • if you cannot understand the solution
    • if solution doesn't work

Solution List

Number Problem Difficulty Links
1 Two Sum Easy Problem, Solution
2 Add Two Numbers Medium Problem, Solution
7 Reverse Integer Easy Problem, Solution
9 Palindrome Number Easy Problem, Solution
13 Roman to Integer Easy Problem, Solution
14 Longest Common Prefix Easy Problem, Solution
20 Valid Parentheses Easy Problem, Solution
21 Merge Two Sorted Lists Easy Problem, Solution
26 Remove Duplicates from Sorted Array Easy Problem, Solution
27 Remove Element Easy Problem, Solution
28 Implement strStr() Easy Problem, Solution
35 Search Insert Position Easy Problem, Solution
53 Maximum Subarray Easy Problem, Solution
58 Length of Last Word Easy Problem, Solution
66 Plus One Easy Problem, Solution
67 Add Binary Easy Problem, Solution
69 Sqrt(x) Easy Problem, Solution
70 Climbing Stairs Easy Problem, Solution
83 Remove Duplicates from Sorted List Easy Problem, Solution
88 Merge Sorted Array Easy Problem, Solution
94 Binary Tree Inorder Traversal Easy Problem, Solution
100 Same Tree Easy Problem, Solution
101 Symmetric Tree Easy Problem, Solution
104 Maximum Depth of Binary Tree Easy Problem, Solution
108 Convert Sorted Array to Binary Search Tree Easy Problem, Solution
110 Balanced Binary Tree Easy Problem, Solution
111 Minimum Depth of Binary Tree Easy Problem, Solution
112 Path Sum Easy Problem, Solution
118 Pascal's Triangle Easy Problem, Solution
119 Pascal's Triangle II Easy Problem, Solution
121 Best Time to Buy and Sell Stock Easy Problem, Solution
122 Best Time to Buy and Sell Stock II Easy Problem, Solution
125 Valid Palindrome Easy Problem, Solution
136 Single Number Easy Problem, Solution
141 Linked List Cycle Easy Problem, Solution
144 Binary Tree Preorder Traversal Easy Problem, Solution
145 Binary Tree Postorder Traversal Easy Problem, Solution
155 Min Stack Easy Problem, Solution
160 Intersection of Two Linked Lists Easy Problem, Solution
167 Two Sum II - Input array is sorted Easy Problem, Solution
168 Excel Sheet Column Title Easy Problem, Solution
169 Majority Element Easy Problem, Solution
171 Excel Sheet Column Number Easy Problem, Solution
172 Factorial Trailing Zeroes Easy Problem, Solution
190 Reverse Bits Easy Problem, Solution
191 Number of 1 Bits Easy Problem, Solution
202 Happy Number Easy Problem, Solution
203 Remove Linked List Elements Easy Problem, Solution
204 Count Primes Easy Problem, Solution
205 Isomorphic Strings Easy Problem, Solution
206 Reverse Linked List Easy Problem, Solution
217 Contains Duplicate Easy Problem, Solution
219 Contains Duplicate II Easy Problem, Solution
222 Count Complete Tree Nodes Easy Problem, Solution
225 Implement Stack using Queues Easy Problem, Solution
226 Invert Binary Tree Easy Problem, Solution
228 Summary Ranges Easy Problem, Solution
231 Power of Two Easy Problem, Solution
232 Implement Queue using Stacks Easy Problem, Solution
234 Palindrome Linked List Easy Problem, Solution
235 Lowest Common Ancestor of a Binary Search Tree Easy Problem, Solution
237 Delete Node in a Linked List Easy Problem, Solution
242 Valid Anagram Easy Problem, Solution
257 Binary Tree Paths Easy Problem, Solution
258 Add Digits Easy Problem, Solution
263 Ugly Number Easy Problem, Solution
268 Missing Number Easy Problem, Solution
278 First Bad Version Easy Problem, Solution
283 Move Zeroes Easy Problem, Solution
290 Word Pattern Easy Problem, Solution
292 Nim Game Easy Problem, Solution
303 Range Sum Query - Immutable Easy Problem, Solution
326 Power of Three Easy Problem, Solution
338 Counting Bits Easy Problem, Solution
342 Power of Four Easy Problem, Solution
344 Reverse String Easy Problem, Solution
345 Reverse Vowels of a String Easy Problem, Solution
349 Intersection of Two Arrays Easy Problem, Solution
350 Intersection of Two Arrays II Easy Problem, Solution
367 Valid Perfect Square Easy Problem, Solution
374 Guess Number Higher or Lower Easy Problem, Solution
383 Ransom Note Easy Problem, Solution
387 First Unique Character in a String Easy Problem, Solution
389 Find the Difference Easy Problem, Solution
392 Is Subsequence Easy Problem, Solution
401 Binary Watch Easy Problem, Solution
404 Sum of Left Leaves Easy Problem, Solution
405 Convert a Number to Hexadecimal Easy Problem, Solution
409 Longest Palindrome Easy Problem, Solution
412 Fizz Buzz Easy Problem, Solution
414 Third Maximum Number Easy Problem, Solution
415 Add Strings Easy Problem, Solution
434 Number of Segments in a String Easy Problem, Solution
441 Arranging Coins Easy Problem, Solution
448 Find All Numbers Disappeared in an Array Easy Problem, Solution
453 Minimum Moves to Equal Array Elements Easy Problem, Solution
455 Assign Cookies Easy Problem, Solution
459 Repeated Substring Pattern Easy Problem, Solution
461 Hamming Distance Easy Problem, Solution
463 Island Perimeter Easy Problem, Solution
476 Number Complement Easy Problem, Solution
482 License Key Formatting Easy Problem, Solution
485 Max Consecutive Ones Easy Problem, Solution
492 Construct the Rectangle Easy Problem, Solution
495 Teemo Attacking Easy Problem, Solution
496 Next Greater Element I Easy Problem, Solution
500 Keyboard Row Easy Problem, Solution
501 Find Mode in Binary Search Tree Easy Problem, Solution
504 Base 7 Easy Problem, Solution
506 Relative Ranks Easy Problem, Solution
507 Perfect Number Easy Problem, Solution
509 Fibonacci Number Easy Problem, Solution
520 Detect Capital Easy Problem, Solution
521 Longest Uncommon Subsequence I Easy Problem, Solution
530 Minimum Absolute Difference in BST Easy Problem, Solution
541 Reverse String II Easy Problem, Solution
543 Diameter of Binary Tree Easy Problem, Solution
551 Student Attendance Record I Easy Problem, Solution
557 Reverse Words in a String III Easy Problem, Solution
559 Maximum Depth of N-ary Tree Easy Problem, Solution
561 Array Partition I Easy Problem, Solution
563 Binary Tree Tilt Easy Problem, Solution
566 Reshape the Matrix Easy Problem, Solution
572 Subtree of Another Tree Easy Problem, Solution
575 Distribute Candies Easy Problem, Solution
589 N-ary Tree Preorder Traversal Easy Problem, Solution
590 N-ary Tree Postorder Traversal Easy Problem, Solution
594 Longest Harmonious Subsequence Easy Problem, Solution
598 Range Addition II Easy Problem, Solution
599 Minimum Index Sum of Two Lists Easy Problem, Solution
605 Can Place Flowers Easy Problem, Solution
606 Construct String from Binary Tree Easy Problem, Solution
617 Merge Two Binary Trees Easy Problem, Solution
628 Maximum Product of Three Numbers Easy Problem, Solution
637 Average of Levels in Binary Tree Easy Problem, Solution
643 Maximum Average Subarray I Easy Problem, Solution
645 Set Mismatch Easy Problem, Solution
653 Two Sum IV - Input is a BST Easy Problem, Solution
657 Robot Return to Origin Easy Problem, Solution
661 Image Smoother Easy Problem, Solution
671 Second Minimum Node In a Binary Tree Easy Problem, Solution
674 Longest Continuous Increasing Subsequence Easy Problem, Solution
680 Valid Palindrome II Easy Problem, Solution
682 Baseball Game Easy Problem, Solution
693 Binary Number with Alternating Bits Easy Problem, Solution
696 Count Binary Substrings Easy Problem, Solution
697 Degree of an Array Easy Problem, Solution
700 Search in a Binary Search Tree Easy Problem, Solution
703 Kth Largest Element in a Stream Easy Problem, Solution
704 Binary Search Easy Problem, Solution
705 Design HashSet Easy Problem, Solution
706 Design HashMap Easy Problem, Solution
709 To Lower Case Easy Problem, Solution
717 1-bit and 2-bit Characters Easy Problem, Solution
724 Find Pivot Index Easy Problem, Solution
728 Self Dividing Numbers Easy Problem, Solution
733 Flood Fill Easy Problem, Solution
744 Find Smallest Letter Greater Than Target Easy Problem, Solution
746 Min Cost Climbing Stairs Easy Problem, Solution
747 Largest Number At Least Twice of Others Easy Problem, Solution
748 Shortest Completing Word Easy Problem, Solution
762 Prime Number of Set Bits in Binary Representation Easy Problem, Solution
766 Toeplitz Matrix Easy Problem, Solution
771 Jewels and Stones Easy Problem, Solution
783 Minimum Distance Between BST Nodes Easy Problem, Solution
796 Rotate String Easy Problem, Solution
804 Unique Morse Code Words Easy Problem, Solution
806 Number of Lines To Write String Easy Problem, Solution
812 Largest Triangle Area Easy Problem, Solution
819 Most Common Word Easy Problem, Solution
821 Shortest Distance to a Character Easy Problem, Solution
824 Goat Latin Easy Problem, Solution
830 Positions of Large Groups Easy Problem, Solution
832 Flipping an Image Easy Problem, Solution
836 Rectangle Overlap Easy Problem, Solution
844 Backspace String Compare Easy Problem, Solution
852 Peak Index in a Mountain Array Easy Problem, Solution
859 Buddy Strings Easy Problem, Solution
860 Lemonade Change Easy Problem, Solution
867 Transpose Matrix Easy Problem, Solution
868 Binary Gap Easy Problem, Solution
872 Leaf-Similar Trees Easy Problem, Solution
876 Middle of the Linked List Easy Problem, Solution
883 Projection Area of 3D Shapes Easy Problem, Solution
884 Uncommon Words from Two Sentences Easy Problem, Solution
888 Fair Candy Swap Easy Problem, Solution
892 Surface Area of 3D Shapes Easy Problem, Solution
896 Monotonic Array Easy Problem, Solution
897 Increasing Order Search Tree Easy Problem, Solution
905 Sort Array By Parity Easy Problem, Solution
908 Smallest Range I Easy Problem, Solution
914 X of a Kind in a Deck of Cards Easy Problem, Solution
917 Reverse Only Letters Easy Problem, Solution
922 Sort Array By Parity II Easy Problem, Solution
925 Long Pressed Name Easy Problem, Solution
929 Unique Email Addresses Easy Problem, Solution
933 Number of Recent Calls Easy Problem, Solution
937 Reorder Data in Log Files Easy Problem, Solution
938 Range Sum of BST Easy Problem, Solution
941 Valid Mountain Array Easy Problem, Solution
942 DI String Match Easy Problem, Solution
944 Delete Columns to Make Sorted Easy Problem, Solution
953 Verifying an Alien Dictionary Easy Problem, Solution
961 N-Repeated Element in Size 2N Array Easy Problem, Solution
965 Univalued Binary Tree Easy Problem, Solution
976 Largest Perimeter Triangle Easy Problem, Solution
977 Squares of a Sorted Array Easy Problem, Solution
989 Add to Array-Form of Integer Easy Problem, Solution
993 Cousins in Binary Tree Easy Problem, Solution
997 Find the Town Judge Easy Problem, Solution
999 Available Captures for Rook Easy Problem, Solution
1002 Find Common Characters Easy Problem, Solution
1005 Maximize Sum Of Array After K Negations Easy Problem, Solution
1009 Complement of Base 10 Integer Easy Problem, Solution
1013 Partition Array Into Three Parts With Equal Sum Easy Problem, Solution
1018 Binary Prefix Divisible By 5 Easy Problem, Solution
1021 Remove Outermost Parentheses Easy Problem, Solution
1022 Sum of Root To Leaf Binary Numbers Easy Problem, Solution
1025 Divisor Game Easy Problem, Solution
1030 Matrix Cells in Distance Order Easy Problem, Solution
1037 Valid Boomerang Easy Problem, Solution
1046 Last Stone Weight Easy Problem, Solution
1047 Remove All Adjacent Duplicates In String Easy Problem, Solution
1051 Height Checker Easy Problem, Solution
1071 Greatest Common Divisor of Strings Easy Problem, Solution
1078 Occurrences After Bigram Easy Problem, Solution
1089 Duplicate Zeros Easy Problem, Solution
1103 Distribute Candies to People Easy Problem, Solution
1108 Defanging an IP Address Easy Problem, Solution
1122 Relative Sort Array Easy Problem, Solution
1128 Number of Equivalent Domino Pairs Easy Problem, Solution
1137 N-th Tribonacci Number Easy Problem, Solution
1154 Day of the Year Easy Problem, Solution
1160 Find Words That Can Be Formed by Characters Easy Problem, Solution
1175 Prime Arrangements Easy Problem, Solution
1184 Distance Between Bus Stops Easy Problem, Solution
1185 Day of the Week Easy Problem, Solution
1189 Maximum Number of Balloons Easy Problem, Solution
1200 Minimum Absolute Difference Easy Problem, Solution
1207 Unique Number of Occurrences Easy Problem, Solution
1217 Minimum Cost to Move Chips to The Same Position Easy Problem, Solution
1221 Split a String in Balanced Strings Easy Problem, Solution
1232 Check If It Is a Straight Line Easy Problem, Solution
1252 Cells with Odd Values in a Matrix Easy Problem, Solution
1260 Shift 2D Grid Easy Problem, Solution
1266 Minimum Time Visiting All Points Easy Problem, Solution
1275 Find Winner on a Tic Tac Toe Game Easy Problem, Solution
1281 Subtract the Product and Sum of Digits of an Integer Easy Problem, Solution
1287 Element Appearing More Than 25% In Sorted Array Easy Problem, Solution
1290 Convert Binary Number in a Linked List to Integer Easy Problem, Solution
1295 Find Numbers with Even Number of Digits Easy Problem, Solution
1299 Replace Elements with Greatest Element on Right Side Easy Problem, Solution
1304 Find N Unique Integers Sum up to Zero Easy Problem, Solution
1309 Decrypt String from Alphabet to Integer Mapping Easy Problem, Solution
1313 Decompress Run-Length Encoded List Easy Problem, Solution
1317 Convert Integer to the Sum of Two No-Zero Integers Easy Problem, Solution
1323 Maximum 69 Number Easy Problem, Solution
1331 Rank Transform of an Array Easy Problem, Solution
1332 Remove Palindromic Subsequences Easy Problem, Solution
1337 The K Weakest Rows in a Matrix Easy Problem, Solution
1342 Number of Steps to Reduce a Number to Zero Easy Problem, Solution
1346 Check If N and Its Double Exist Easy Problem, Solution
1351 Count Negative Numbers in a Sorted Matrix Easy Problem, Solution
1360 Number of Days Between Two Dates Easy Problem, Solution
1365 How Many Numbers Are Smaller Than the Current Number Easy Problem, Solution
1370 Increasing Decreasing String Easy Problem, Solution
1374 Generate a String With Characters That Have Odd Counts Easy Problem, Solution
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree Easy Problem, Solution
1380 Lucky Numbers in a Matrix Easy Problem, Solution
1385 Find the Distance Value Between Two Arrays Easy Problem, Solution
1389 Create Target Array in the Given Order Easy Problem, Solution
1394 Find Lucky Integer in an Array Easy Problem, Solution
1399 Count Largest Group Easy Problem, Solution
1403 Minimum Subsequence in Non-Increasing Order Easy Problem, Solution
1408 String Matching in an Array Easy Problem, Solution
1413 Minimum Value to Get Positive Step by Step Sum Easy Problem, Solution
1417 Reformat The String Easy Problem, Solution
1422 Maximum Score After Splitting a String Easy Problem, Solution
1431 Kids With the Greatest Number of Candies Easy Problem, Solution
1436 Destination City Easy Problem, Solution
1437 Check If All 1's Are at Least Length K Places Away Easy Problem, Solution
1446 Consecutive Characters Easy Problem, Solution
1450 Number of Students Doing Homework at a Given Time Easy Problem, Solution
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence Easy Problem, Solution
1460 Make Two Arrays Equal by Reversing Subarrays Easy Problem, Solution
1464 Maximum Product of Two Elements in an Array Easy Problem, Solution
1470 Shuffle the Array Easy Problem, Solution
1475 Final Prices With a Special Discount in a Shop Easy Problem, Solution
1480 Running Sum of 1d Array Easy Problem, Solution
1486 XOR Operation in an Array Easy Problem, Solution
1491 Average Salary Excluding the Minimum and Maximum Salary Easy Problem, Solution
1496 Path Crossing Easy Problem, Solution
1502 Can Make Arithmetic Progression From Sequence Easy Problem, Solution
1507 Reformat Date Easy Problem, Solution
1512 Number of Good Pairs Easy Problem, Solution
1518 Water Bottles Easy Problem, Solution
1523 Count Odd Numbers in an Interval Range Easy Problem, Solution
1528 Shuffle String Easy Problem, Solution
1534 Count Good Triplets Easy Problem, Solution
1539 Kth Missing Positive Number Easy Problem, Solution
1544 Make The String Great Easy Problem, Solution
1550 Three Consecutive Odds Easy Problem, Solution
1556 Thousand Separator Easy Problem, Solution
1560 Most Visited Sector in a Circular Track Easy Problem, Solution
1566 Detect Pattern of Length M Repeated K or More Times Easy Problem, Solution
1572 Matrix Diagonal Sum Easy Problem, Solution
1576 Replace All ?'s to Avoid Consecutive Repeating Characters Easy Problem, Solution
1582 Special Positions in a Binary Matrix Easy Problem, Solution
1588 Sum of All Odd Length Subarrays Easy Problem, Solution
1592 Rearrange Spaces Between Words Easy Problem, Solution
1598 Crawler Log Folder Easy Problem, Solution
1603 Design Parking System Easy Problem, Solution
1608 Special Array With X Elements Greater Than or Equal X Easy Problem, Solution
1614 Maximum Nesting Depth of the Parentheses Easy Problem, Solution
1619 Mean of Array After Removing Some Elements Easy Problem, Solution
1624 Largest Substring Between Two Equal Characters Easy Problem, Solution
1629 Slowest Key Easy Problem, Solution
1636 Sort Array by Increasing Frequency Easy Problem, Solution
1637 Widest Vertical Area Between Two Points Containing No Points Easy Problem, Solution
1640 Check Array Formation Through Concatenation Easy Problem, Solution
1646 Get Maximum in Generated Array Easy Problem, Solution
1652 Defuse the Bomb Easy Problem, Solution
1656 Design an Ordered Stream Easy Problem, Solution
1662 Check If Two String Arrays are Equivalent Easy Problem, Solution
1668 Maximum Repeating Substring Easy Problem, Solution
1672 Richest Customer Wealth Easy Problem, Solution
1678 Goal Parser Interpretation Easy Problem, Solution
1684 Count the Number of Consistent Strings Easy Problem, Solution
1688 Count of Matches in Tournament Easy Problem, Solution
1694 Reformat Phone Number Easy Problem, Solution
1700 Number of Students Unable to Eat Lunch Easy Problem, Solution
1704 Determine if String Halves Are Alike Easy Problem, Solution
1710 Maximum Units on a Truck Easy Problem, Solution
1716 Calculate Money in Leetcode Bank Easy Problem, Solution
1720 Decode XORed Array Easy Problem, Solution
1725 Number Of Rectangles That Can Form The Largest Square Easy Problem, Solution
1732 Find the Highest Altitude Easy Problem, Solution
1736 Latest Time by Replacing Hidden Digits Easy Problem, Solution
1742 Maximum Number of Balls in a Box Easy Problem, Solution
1748 Sum of Unique Elements Easy Problem, Solution
1752 Check if Array Is Sorted and Rotated Easy Problem, Solution
1758 Minimum Changes To Make Alternating Binary String Easy Problem, Solution
1763 Longest Nice Substring Easy Problem, Solution
1768 Merge Strings Alternately Easy Problem, Solution
1773 Count Items Matching a Rule Easy Problem, Solution
1779 Find Nearest Point That Has the Same X or Y Coordinate Easy Problem, Solution
1784 Check if Binary String Has at Most One Segment of Ones Easy Problem, Solution
1790 Check if One String Swap Can Make Strings Equal Easy Problem, Solution
1791 Find Center of Star Graph Easy Problem, Solution
1796 Second Largest Digit in a String Easy Problem, Solution
1800 Maximum Ascending Subarray Sum Easy Problem, Solution
1805 Number of Different Integers in a String Easy Problem, Solution
1812 Determine Color of a Chessboard Square Easy Problem, Solution
1816 Truncate Sentence Easy Problem, Solution
1822 Sign of the Product of an Array Easy Problem, Solution
1827 Minimum Operations to Make the Array Increasing Easy Problem, Solution
1832 Check if the Sentence Is Pangram Easy Problem, Solution
1837 Sum of Digits in Base K Easy Problem, Solution
1844 Replace All Digits with Characters Easy Problem, Solution
1848 Minimum Distance to the Target Element Easy Problem, Solution
1854 Maximum Population Year Easy Problem, Solution
1859 Sorting the Sentence Easy Problem, Solution
1863 Sum of All Subset XOR Totals Easy Problem, Solution
1869 Longer Contiguous Segments of Ones than Zeros Easy Problem, Solution
1876 Substrings of Size Three with Distinct Characters Easy Problem, Solution
1880 Check if Word Equals Summation of Two Words Easy Problem, Solution
1886 Determine Whether Matrix Can Be Obtained By Rotation Easy Problem, Solution
1893 Check if All the Integers in a Range Are Covered Easy Problem, Solution
1897 Redistribute Characters to Make All Strings Equal Easy Problem, Solution
1903 Largest Odd Number in String Easy Problem, Solution
1909 Remove One Element to Make the Array Strictly Increasing Easy Problem, Solution
1913 Maximum Product Difference Between Two Pairs Easy Problem, Solution
1920 Build Array from Permutation Easy Problem, Solution
1925 Count Square Sum Triples Easy Problem, Solution
1929 Concatenation of Array Easy Problem, Solution
1935 Maximum Number of Words You Can Type Easy Problem, Solution
1941 Check if All Characters Have Equal Number of Occurrences Easy Problem, Solution
1945 Sum of Digits of String After Convert Easy Problem, Solution
1952 Three Divisors Easy Problem, Solution
1957 Delete Characters to Make Fancy String Easy Problem, Solution
1961 Check If String Is a Prefix of Array Easy Problem, Solution
1967 Number of Strings That Appear as Substrings in Word Easy Problem, Solution
1971 Find if Path Exists in Graph Easy Problem, Solution
1974 Minimum Time to Type Word Using Special Typewriter Easy Problem, Solution
1979 Find Greatest Common Divisor of Array Easy Problem, Solution
1984 Minimum Difference Between Highest and Lowest of K Scores Easy Problem, Solution
1991 Find the Middle Index in Array Easy Problem, Solution
1995 Count Special Quadruplets Easy Problem, Solution
2000 Reverse Prefix of Word Easy Problem, Solution
2006 Count Number of Pairs With Absolute Difference K Easy Problem, Solution
2011 Final Value of Variable After Performing Operations Easy Problem, Solution
2016 Maximum Difference Between Increasing Elements Easy Problem, Solution
2022 Convert 1D Array Into 2D Array Easy Problem, Solution
2027 Minimum Moves to Convert String Easy Problem, Solution
2032 Two Out of Three Easy Problem, Solution
2037 Minimum Number of Moves to Seat Everyone Easy Problem, Solution
2042 Check if Numbers Are Ascending in a Sentence Easy Problem, Solution
2047 Number of Valid Words in a Sentence Easy Problem, Solution
2053 Kth Distinct String in an Array Easy Problem, Solution
2057 Smallest Index With Equal Value Easy Problem, Solution
2062 Count Vowel Substrings of a String Easy Problem, Solution

Format : |num|problem|difficult|Problem, Solution|

Releases

No releases published

Packages

No packages published

Languages