/LeetCodeNet

LeetCode problems with detailed explanation and different solutions.

Primary LanguageC#Apache License 2.0Apache-2.0

LeetCodeNet

LeetCode problems with clean code, detailed explanations and different easy-understandable solutions. All problems are grouped by patterns, so you can train in solving of specific type of problems.

Level: Easy

Pattern: without

  • #9: Palindrome Number (Math)
  • #13: Roman to Integer (Math)
  • #20: Valid Parentheses (String)
  • #21: Merge Two Sorted Lists (Linked List)
  • #66: Plus One (Array)
  • #118: Pascal's Triangle (DP)
  • #155: Min Stack (DP)
  • #202: Happy Number (Math)
  • #206: Reverse Linked List (Linked list)
  • #225: Implement Stack using Queues (Design)
  • #232: Implement Queue using Stacks (Design)
  • #237: Delete Node in a Linked List (Linked list)
  • #303: Range Sum Query - Immutable (Design)
  • #412: FizzBuzz (Math, Design)
  • #414: Third Maximum Number (Array)
  • #485: Max Consecutive Ones (Array)
  • #566: Reshape the Matrix (Array)
  • #844: Backspace String Compare (Array, Stack)
  • #867: Transpose Matrix (Array)
  • #976: Largest Perimeter Triangle (Math)
  • #1232: Check If It Is a Straight Line (Math)
  • #1281: Subtract the Product and Sum of Digits of an Integer (Math)
  • #1295: Find Numbers with Even Number of Digits (Math, Array)
  • #1299: Replace Elements with Greatest Element on Right Side (Array)
  • #1431: Kids With the Greatest Number of Candies (Array)
  • #1502: Can Make Arithmetic Progression From Sequence (Math, Array)
  • #1523: Count Odd Numbers in an Interval Range (Array)
  • #1539^ Kth missing positive number (Array)
  • #1572: Matrix Diagonal Sum (Array)
  • #1588: Sum of All Odd Length Subarrays (Array)
  • #1603: Design Parking System (Design)
  • #1672: Richest Customer Wealth (Array)
  • #1678: Goal Parser Interpretation (String)
  • #1732: Find the Highest Altitude (Array)
  • #1768: Merge Strings Alternately (String)
  • #1822: Sign of the Product of an Array (Math)
  • #1974: Minimum Time to Type Word Using Special Typewriter (String)
  • #2643: Row With Maximum Ones (Array)
  • #2660: Determine the Winner of a Bowling Game (Array)
  • #2716: Minimize String Length (String)
  • #2733: Neither Minimum nor Maximum (Array)
  • #2739: Total Distance Traveled (Math)

Pattern: Sorting

  • #14: Longest Common Prefix (String)
  • #217: Contains Duplicate (Array)
  • #448: Find All Numbers Disappeared in an Array (Array)
  • #1046: Last Stone Weight (Array, PriorityQueue)
  • #1051: Height Checker (Array, Bucket)
  • #1491: Average Salary Excluding the Minimum and Maximum Salary (Array)

Pattern: Prefix sum

  • #724: Find Pivot Index (Array)
  • #1480: Running Sum of 1d Array (Array)
  • #2670: Find the Distinct Difference Array (Array)

Pattern: Breadth-First search (BFS)

  • #104: Maximum Depth of Binary Tree (Tree)
  • #112: Path Sum (Tree)
  • #144: Binary Tree Preorder Traversal (Tree)
  • #145: Binary Tree Postorder Traversal (Tree)
  • #226: Invert Binary Tree (Tree)
  • #404: Sum of Left Leaves (Tree)
  • #617: Merge Two Binary Trees (Tree)
  • #637: Average of Levels in Binary Tree (Tree)
  • #733: Flood Fill (Array)

Pattern: Depth-First search (DFS)

  • #94: Binary Tree Inorder Traversal (Tree)
  • #101: Symmetric Tree (Tree)
  • #589: N-ary Tree Preorder Traversal (Tree)

Pattern: Binary tree

  • #235: Lowest Common Ancestor of a Binary Search Tree (Tree)
  • #700: Search in a Binary Search Tree (Tree)

Pattern: Two pointers

  • #26: Remove Duplicates from Sorted Array (Array)
  • #27: Remove Element (Array)
  • #83: Remove Duplicates from Sorted List (Linked List)
  • #125: Valid Palindrome (String)
  • #169: Majority Element (Array)
  • #203: Remove Linked List Elements (Linked List)
  • #283: Move Zeroes (Array)
  • #344: Reverse String (String)
  • #345: Reverse Vowels of a String (String)
  • #387: First Unique Character in a String (String)
  • #350: Intersection of Two Arrays II (Array)
  • #392: Is Subsequence (String)
  • #557: Reverse Words in a String III (String)
  • #696: Count Binary Substrings (String)
  • #905: Sort Array By Parity (Array)
  • #941: Valid Mountain Array (Array)
  • #977: Squares of a Sorted Array (Array)
  • #1089: Duplicate Zeroes (Array)
  • #1790: Check if One String Swap Can Make Strings Equal (String)
  • #2697: Lexicographically Smallest Palindrome (String)
  • #2717: Semi-Ordered Permutation (Array)

Pattern: Two pointers: slow/fast

  • #141: Linked List Cycle (Linked List)
  • #234: Palindrome Linked List (Linked List)
  • #876: Middle of the LInked List (Linked List)

Pattern: Hash table

  • #1: Two Sum (Array)
  • #205: Isomorphic Strings (String)
  • #242: Valid Anagram (String)
  • #350: Intersection of Two Arrays II (Array)
  • #383: Ransom note (String)
  • #389: Find the Difference (String)
  • #409: Longest Palindrome (String)
  • #705: Design HashSet (Design)
  • #706: Design HashMap (Design)
  • #953: Verifying an Alien Dictionary (String)
  • #1346: Check If N and Its Double Exist (Array)
  • #1394: Find Lucky Integer in an Array (Array)
  • #2049: Finding 3-Digit Even Numbers (Array)

Pattern: Monotonic stack

  • #496: Next Greater Element I (Array)

Pattern: Char manipulation

  • #709: To Lower Case (String)
  • #1309: Decrypt String from Alphabet to Integer Mapping (String)
  • #1844: Replace All Digits with Characters (String)

Pattern: Bit manipulation

  • #136: Single number (Array)
  • #190: Reverse bits (Bits)
  • #191: Number of 1 Bits (Bits)
  • #231: Power of Two (Bits)
  • #268: Missing Number (Array)
  • #461: Hamming Distance (Bits)
  • #1290: Convert Binary Number in a Linked List to Integer (Linked List)
  • #1342: Number of Steps to Reduce a Number to Zero (Bits)
  • #1356: Sort Integers by The Number of 1 Bits (Array)

Pattern: KMP algorithm

  • #28: Implement strStr (String)

Pattern: Divide and conquer

  • #108: Convert Sorted Array to Binary Search Tree (Tree)

Pattern: Binary search

  • #35: Search Insert Position (Array)
  • #69: Sqrt(x) (Math)
  • #278: First Bad Version (Array)
  • #367: Valid Perfect Square (Math)
  • #374: Guess Number Higher or Lower (Array)
  • #653: Two Sum IV - Input is a BST (Tree)
  • #704: Binary Search (Array)
  • #744: Find Smallest Letter Greater Than Target (Array)
  • #1337: The K Weakest Rows in a Matrix (Array)
  • #1351: Count Negative Numbers in a Sorted Matrix (Array)
  • #1385: Find the Distance Value Between Two Arrays (Array)
  • #1608: Special Array With X Elements Greater Than or Equal X (Array)

Pattern: Dynamic programming

  • #70: Climbing stairs (Bottom-up)
  • #746: Min Cost Climbing Stairs (Bottom-up)
  • #509: Fibonacci Number (Bottom-up)
  • #605: Can Place Flowers (Bottom-up)

Pattern: Kadane's algorithm

  • #121: Best Time to Buy and Sell Stock (DP)

Pattern: Greedy

  • #2696: Minimum String Length After Removing Substrings (String)

Level: Medium

Pattern: without

  • #2: Add Two Numbers (Linked list)
  • #7: Reverse Integer (Math)
  • #38: Count and say (String)
  • #54: Spiral Matrix (Array)
  • #71: Simplify Path (String)
  • #382: Linked List Random Node (Linked list, Design)
  • #394: Decode String (String, Stack)
  • #848: Shifting Letters (String)
  • #1328: Break a Palindrome (String)
  • #1472: Design Browser History (Linked List, Design)
  • #1980: Find Unique Binary String (Array)
  • #2348: Number of Zero-Filled Subarrays (Math, Array)
  • #2671: Frequency Tracker (Design)
  • #2672: Number of Adjacent Elements With the Same Color (Array)
  • #2718: Sum of Matrix After Queries (Array)
  • #2734: Lexicographically Smallest String After Substring Operation (String)

Pattern: Sorting

  • #347: Top K Frequent Elements (Array)
  • #692: Top K Frequent Words (Array, Bucket)
  • #2300: Successful Pairs of Spells and Potions (Array)
  • #2740: Find the Value of the Partition (Array)

Pattern: Binary search

  • #33: Search in Rotated Sorted Array (Array)
  • #34: Find First and Last Position of Element in Sorted Array (Array)
  • #74: Search a 2D Matrix (Array)
  • #153: Find Minimum in Rotated Sorted Array (Array)
  • #852: Peak Index in a Mountain Array (Array)

Pattern: Two pointers

  • #5: Longest Palindromic Substring (String)
  • #88: Merge Sorted Array (Array)
  • #142: Linked List Cycle II (Linked List)
  • #167: Two Sum II - Input Array Is Sorted (Array)
  • #633: Sum of Square Numbers (Math)
  • #881: Boats to Save People (Array)
  • #946: Validate Stack Sequences (Array)
  • #1004: Max Consecutive Ones III (Array)
  • #1855: Maximum Distance Between a Pair of Values (Array)
  • #2390: Removing Stars From a String (String)

Pattern: Two pointers: slow/fast

  • #109: Convert Sorted List to Binary Search Tree (Tree, Linked list)

Pattern: Hash table

  • #299: Bulls and Cows (Array)
  • #2661: First Completely Painted Row or Column (Array)

Pattern: Sliding window

  • #3: Longest Substring Without Repeating Characters (String)
  • #424: Longest Repeating Character Replacement (String)
  • #438: Find All Anagrams in a String (String)
  • #567: Permutation in String (String)
  • #1456: Maximum Number of Vowels in a Substring of Given Length (String)

Pattern: Prefix sum

  • #2439: Minimize Maximum of Array (Array)

Pattern: Kadane's algorithm

  • #53: Maximum Subarray (Array)

Pattern: Backtracking

  • #46: Permutations (Array)
  • #211: Design Add and Search Words Data Structure (Prefix Tree, Design)
  • #784: Letter Case Permutation (String)
  • #2698: Find the Punishment Number of an Integer (Math)

Pattern: Binary tree

  • #98: Validate Binary Search Tree (Tree)

Pattern: Breadth-First search (BFS)

  • #102: Binary Tree Level Order Traversal (Tree)
  • #133: Clone Graph (Graph)
  • #958: Check Completeness of a Binary Tree (Tree)
  • #1466: Reorder Routes to Make All Paths Lead to the City Zero (Graph)
  • #2583: Kth Largest Sum in a Binary Tree (Tree)

Pattern: Depth-First search (DFS)

  • #129: Sum Root to Leaf Numbers (Tree)
  • #200: Number of Islands (Array)
  • #207: Course Schedule (Tree, Topological sort)
  • #994: Rotting Oranges (Array)
  • #1020: Number of Enclaves (Array)

Pattern: Bit manipulation

  • #2405: Optimal Partition of String (String)

Pattern: Prefix Tree

  • #208: Implement Trie (Design)

Pattern: Dynamic programming

  • #62: Unique Paths (Bottom-up, Array)
  • #63: Minimum Path Sum (Bottom-up, Array)
  • #516: Longest Palindromic Subsequence (Bottom-up, String)
  • #983: Minimum Cost For Tickets (Bottom-up, Array)

Pattern: Union-Find

  • #1319: Number of Operations to Make Network Connected (Graph)
  • #2316: Count Unreachable Pairs of Nodes in an Undirected Graph (Graph)

Level: Hard

Pattern: without

  • #23: Merge k Sorted Lists (Linked list)