Skip to content
/ LeetCode Public

LeetCode problems solutions. A journal of my problem-solving journey.

License

Notifications You must be signed in to change notification settings

squxq/LeetCode

Repository files navigation

LeetCode Problem Solutions

Welcome to my LeetCode Problem Solutions repository! This is a record of my journey as I solve various LeetCode problems to improve my coding skills and deepen my understanding of algorithms and data structures. In this repository, you'll find solutions to a wide range of LeetCode problems, along with explanations and code implementations.

Table of Contents

Introduction

LeetCode is a popular platform for practicing coding and algorithmic problem-solving. This repository serves as my personal collection of LeetCode problem solutions, which I use to track my progress, learn from my mistakes, and share my solutions with others who may find them helpful.

Repository Structure

This repository is organized as follows:

  • problems: This directory contains subdirectories for each problem category. Within each category subdirectory, you will find individual problem solutions, each in its own directory.

    • Example: problems/array/merge-sorted-array contains solutions for the "Merge Sorted Array" problem.
  • resources: This directory includes any relevant resources, notes, or templates that I use during problem-solving sessions.

  • scripts: Some problems may require auxiliary scripts or utilities. You can find those in this directory.

Problem Solving Approach

My approach to solving LeetCode problems typically involves the following steps:

  1. Understanding the Problem: I carefully read and understand the problem statement, making note of any special requirements, constraints, or edge cases.

  2. Planning and Pseudocode: Before jumping into coding, I plan my approach, sketch out a pseudocode solution, and identify key data structures and algorithms to use.

  3. Coding: I implement the solution in my preferred programming language, ensuring clean, well-documented code.

  4. Testing: I thoroughly test my solution using sample test cases, edge cases, and custom test cases to verify its correctness.

  5. Optimization: If necessary, I optimize my initial solution for better performance or memory usage. I also consider alternative approaches and compare their efficiency.

  6. Explanation: I provide explanations of my solutions, including time and space complexity analysis, to help others understand the thought process behind the code.

  7. Documentation: I update this README.md file with links to the solved problems and their corresponding explanations.

List of Problems

# Title Topic Solution Difficulty
88 Merge Sorted Array Algorithms TypeScript Easy
27 Remove Element Algorithms TypeScript Easy
26 Remove Duplicates from Sorted Array Algorithms TypeScript Easy
80 Remove Duplicates from Sorted Array II Algorithms TypeScript Medium
169 Majority Element Algorithms TypeScript Easy
274 H-Index Algorithms TypeScript Medium
13 Roman to Integer Algorithms TypeScript Easy
58 Length of Last Word Algorithms TypeScript Easy
189 Rotate Array Algorithms TypeScript Medium
121 Best Time to Buy and Sell Stock Algorithms TypeScript Easy
28 Find the Index of the First Occurrence in a String Algorithms TypeScript Easy
14 Longest Common Prefix Algorithms TypeScript Easy
55 Jump Game Algorithms TypeScript Medium
1768 Merge Strings Alternately Algorithms TypeScript Easy
1071 Greatest Common Divisor of Strings Algorithms TypeScript Easy
1431 Kids With the Greatest Number of Candies Algorithms TypeScript Easy
605 Can Place Flowers Algorithms TypeScript Easy
345 Reverse Vowels of a String Algorithms TypeScript Easy
2215 Find the Difference of Two Arrays Algorithms TypeScript Easy
649 Dota2 Senate Algorithms TypeScript Medium
1631 Path With Minimum Effort Algorithms TypeScript Medium
319 Bulb Switcher Algorithms TypeScript Medium
1584 Min Cost to Connect All Points Algorithms TypeScript Medium
287 Find the Duplicate Number Algorithms TypeScript Medium
1337 The K Weakest Rows in a Matrix Algorithms TypeScript Easy
258 Add Digits Algorithms TypeScript Easy
1491 Average Salary Excluding the Minimum and Maximum Salary Algorithms TypeScript Easy
1822 Sign of the Product of an Array Algorithms TypeScript Easy
1572 Matrix Diagonal Sum Algorithms TypeScript Easy
703 Kth Largest Element in a Stream Algorithms TypeScript Easy
1603 Design Parking System Algorithms TypeScript Easy
1658 Minimum Operations to Reduce X to Zero Algorithms TypeScript Medium
118 Pascal's Triangle Algorithms TypeScript Easy
844 Backspace String Compare Algorithms TypeScript Easy
119 Pascal's Triangle II Algorithms TypeScript Easy
700 Search in a Binary Search Tree Algorithms TypeScript Easy
108 Convert Sorted Array to Binary Search Tree Algorithms TypeScript Easy
530 Minimum Absolute Difference in BST Algorithms TypeScript Easy
501 Find Mode in Binary Search Tree Algorithms TypeScript Easy
653 Two Sum IV - Input is a BST Algorithms TypeScript Easy
783 Minimum Distance Between BST Nodes Algorithms TypeScript Easy
897 Increasing Order Search Tree Algorithms TypeScript Easy
938 Range Sum of BST Algorithms TypeScript Easy
1382 Balance a Binary Search Tree Algorithms TypeScript Medium
1305 All Elements in Two Binary Search Trees Algorithms TypeScript Medium
230 Kth Smallest Element in a BST Algorithms TypeScript Medium
96 Unique Binary Search Trees Algorithms TypeScript Medium
701 Insert into a Binary Search Tree Algorithms TypeScript Medium
94 Binary Tree Inorder Traversal Algorithms TypeScript Easy
100 Same Tree Algorithms TypeScript Easy
101 Symmetric Tree Algorithms TypeScript Easy
104 Maximum Depth of Binary Tree Algorithms TypeScript Easy
110 Balanced Binary Tree Algorithms TypeScript Easy
111 Minimum Depth of Binary Tree Algorithms TypeScript Easy
112 Path Sum Algorithms TypeScript Easy
144 Binary Tree Preorder Traversal Algorithms TypeScript Easy
145 Binary Tree Postorder Traversal Algorithms TypeScript Easy
222 Count Complete Tree Nodes Algorithms TypeScript Easy
226 Invert Binary Tree Algorithms TypeScript Easy
257 Binary Tree Paths Algorithms TypeScript Easy
404 Sum of Left Leaves Algorithms TypeScript Easy
543 Diameter of Binary Tree Algorithms TypeScript Easy
67 Add Binary Algorithms TypeScript Easy
559 Maximum Depth of N-ary Tree Algorithms TypeScript Easy
563 Binary Tree Tilt Algorithms TypeScript Easy
572 Subtree of Another Tree Algorithms TypeScript Easy
1662 Check If Two String Arrays are Equivalent Algorithms TypeScript Easy
1160 Find Words That Can Be Formed by Characters Algorithms TypeScript Easy
1266 Minimum Time Visiting All Points Algorithms TypeScript Easy
2264 Largest 3-Same-Digit Number in String Algorithms TypeScript Easy
1688 Count of Matches in Tournament Algorithms TypeScript Easy
1716 Calculate Money in Leetcode Bank Algorithms TypeScript Easy
1903 Largest Odd Number in String Algorithms TypeScript Easy
606 Construct String from Binary Tree Algorithms TypeScript Easy
867 Transpose Matrix Algorithms TypeScript Easy
1287 Element Appearing More Than 25% In Sorted Array Algorithms TypeScript Easy
1464 Maximum Product of Two Elements in an Array Algorithms TypeScript Easy
1582 Special Positions in a Binary Matrix Algorithms TypeScript Easy
151 Reverse Words in a String Algorithms TypeScript Medium
443 String Compression Algorithms TypeScript Medium
2482 Difference Between Ones and Zeros in Row and Column Algorithms TypeScript Medium
1436 Destination City Algorithms TypeScript Easy
242 Valid Anagram Algorithms TypeScript Easy
2353 Design a Food Rating System Algorithms TypeScript Medium
1913 Maximum Product Difference Between Two Pairs Algorithms TypeScript Easy
661 Image Smoother Algorithms TypeScript Easy
2706 Buy Two Chocolates Algorithms TypeScript Easy
1637 Widest Vertical Area Between Two Points Containing No Points Algorithms TypeScript Medium
1422 Maximum Score After Splitting a String Algorithms TypeScript Easy
1496 Path Crossing Algorithms TypeScript Easy
1758 Minimum Changes To Make Alternating Binary String Algorithms TypeScript Easy
91 Decode Ways Algorithms TypeScript Medium
1155 Number of Dice Rolls With Target Sum Algorithms TypeScript Medium
1578 Minimum Time to Make Rope Colorful Algorithms TypeScript Medium
1531 String Compression II Algorithms TypeScript Hard
1335 Minimum Difficulty of a Job Schedule Algorithms TypeScript Hard
1897 Redistribute Characters to Make All Strings Equal Algorithms TypeScript Easy
1624 Largest Substring Between Two Equal Characters Algorithms TypeScript Easy
455 Assign Cookies Algorithms TypeScript Easy
2610 Convert an Array Into a 2D Array With Conditions Algorithms TypeScript Medium
2125 Number of Laser Beams in a Bank Algorithms TypeScript Medium
2870 Minimum Number of Operations to Make Array Empty Algorithms TypeScript Medium
300 Longest Increasing Subsequence Algorithms TypeScript Medium
1235 Maximum Profit in Job Scheduling Algorithms TypeScript Hard
446 Arithmetic Slices II - Subsequence Algorithms TypeScript Hard
238 Product of Array Except Self Algorithms TypeScript Medium
872 Leaf-Similar Trees Algorithms TypeScript Easy
2385 Amount of Time for Binary Tree to Be Infected Algorithms TypeScript Medium
1026 Maximum Difference Between Node and Ancestor Algorithms TypeScript Medium
1704 Determine if String Halves Are Alike Algorithms TypeScript Easy
334 Increasing Triplet Subsequence Algorithms TypeScript Medium
1347 Minimum Number of Steps to Make Two Strings Anagram Algorithms TypeScript Medium
3005 Count Elements With Maximum Frequency Algorithms TypeScript Easy
1657 Determine if Two Strings Are Close Algorithms TypeScript Medium
2225 Find Players With Zero or One Losses Algorithms TypeScript Medium
380 Insert Delete GetRandom O(1) Algorithms TypeScript Medium
1207 Unique Number of Occurrences Algorithms TypeScript Easy
70 Climbing Stairs Algorithms TypeScript Easy
931 Minimum Falling Path Sum Algorithms TypeScript Medium
907 Sum of Subarray Minimums Algorithms TypeScript Medium
198 House Robber Algorithms TypeScript Medium
645 Set Mismatch Algorithms TypeScript Easy
1239 Maximum Length of a Concatenated String with Unique Characters Algorithms TypeScript Medium
1457 Pseudo-Palindromic Paths in a Binary Tree Algorithms TypeScript Medium
1143 Longest Common Subsequence Algorithms TypeScript Medium
576 Out of Boundary Paths Algorithms TypeScript Medium
... ... ... ... ...

In this table:

  • # represents the problem number.
  • Title contains a link to the problem's directory.
  • Topic categorizes the problems into the domain they represent (e.g. Algorithms, Database, Shell).
  • Solution indicates the programming language used for the solution.
  • Difficulty denotes the difficulty level of the problem (e.g., Easy, Medium, Hard).

You can add more rows to the table as you solve additional problems and provide links to the corresponding problem directories.

Contributing

While this repository primarily serves as a record of my LeetCode problem-solving journey, contributions, feedback, and discussions are welcome! If you have suggestions for improving my solutions or spot any errors, please feel free to open an issue or submit a pull request.

License

This repository is licensed under the MIT License. You are welcome to use, modify, and distribute the code in this repository, but please provide attribution by linking back to this repository.

About

LeetCode problems solutions. A journal of my problem-solving journey.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published