Skip to content

This repository contain my solutions and my explanations to the problems on LeetCode. All the solutions are written in C++. 大部分题目还没被加进目录(页面最下或者click Readme),我还在努力中

BLBT1/MyLeetcodeSolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

多多 LeetCode 各类算法思想的分享与总结

想和我讨论题目的小伙伴, 欢迎发送至我的邮箱: anqiwaATumichDOTedu

我会在每个题后加上我认为的难度评级



分类目录

Binary Search

  • lower_bound(): next smallest element >= target

  • upper_bound(): next smallest element > target

35. Search Insert Position (E-)

74. Search a 2D Matrix (M-)

34. Find First and Last Position of Element in Sorted Array (M+)

*658. Find K Closest Elements (H-)

*4. Median of Two Sorted Arrays (H)

69. Sqrt(x) (E+)

367. Valid Perfect Square (E)

162. Find Peak Element (M+)

*1901. Find a Peak Element II (H)

702. Search in a Sorted Array of Unknown Size (M-)

540. Single Element in a Sorted Array (M+)

*33. Search in Rotated Sorted Array (M+)

*81. Search in Rotated Sorted Array II (M+)

153. Find Minimum in Rotated Sorted Array (M)

*154. Find Minimum in Rotated Sorted Array II (M+)

240. Search a 2D Matrix II (M)

*222.Count Complete Tree Nodes (H-)

*302. Smallest Rectangle Enclosing Black Pixels (H-)

*29. Divide Two Integers (M+)

*475. Heaters(M+)

275. H-Index II (M)

*1095. Find in Mountain Array (M+)

*483. Smallest Good Base (H+)

*870. Advantage Shuffle (M+)

1533. Find the Index of the Large Integer (M)

*2563. Count the Number of Fair Pairs (M+)

2300. Successful Pairs of Spells and Potions (E+)



Two Pointers

11. Container With Most Water (M-)

167. Two Sum II - Input Array Is Sorted (E)

633. Sum of Square Numbers (M)

680. Valid Palindrome II (E+)

15. 3Sum (M)

16. 3Sum Closest (M-)

18. 4Sum

259. 3Sum Smaller (M)

923. 3Sum With Multiplicity (H)

30. Substring with Concatenation of All Words

26. Remove Duplicates from Sorted Array

80. Remove Duplicates from Sorted Array II

88. Merge Sorted Array (E)

524. Longest Word in Dictionary through Deleting

283. Move Zeroes (M-)

713. Subarray Product Less Than K

1234. Replace the Substring for Balanced String

1498. Number of Subsequences That Satisfy the Given Sum Condition

1574. Shortest Subarray to be Removed to Make Array Sorted

141. Linked List Cycle (E+)

142. Linked List Cycle II (H-)

360. Sort Transformed Array (H-)

611. Valid Triangle Number (M+)

75. Sort Colors (M-)

905. Sort Array By Parity (E)

1570. Dot Product of Two Sparse Vectors (E+)

27. Remove Element (E)

1580. Put Boxes Into the Warehouse II

1687. Delivering Boxes from Storage to Ports

1989. Maximum Number of People That Can Be Caught in Tag

2422. Merge Operations to Turn Array Into a Palindrome

2354. Number of Excellent Pairs (H-)

*443. String Compression (M)

2215. Find the Difference of Two Arrays (M-)



Linked List

206. Reverse Linked List (E+)

*92. Reverse Linked List II (M)

*25. Reverse Nodes in k-Group (M+)

*2074. Reverse Nodes in Even Length Groups (H-)

2. Add Two Numbers (M-)

445. Add Two Numbers II (M-)

21. Merge Two Sorted Lists (E-)

23. Merge k Sorted Lists (M+)

24. Swap Nodes in Pairs (M)

160. Intersection of Two Linked Lists (M)

234. Palindrome Linked List (M)

203. Remove Linked List Elements (E-)

83. Remove Duplicates from Sorted List (E)

82. Remove Duplicates from Sorted List II (M)

19. Remove Nth Node From End of List (M-)

86. Partition List

*328. odd even linked list (M+)

*1171. Remove Zero Sum Consecutive Nodes from Linked List (H-)

876. Middle of the Linked List (E)

138. Copy List with Random Pointer

61. Rotate List

369. Plus One Linked List (M-)

430. Flatten a Multilevel Doubly Linked List

457. Circular Array Loop

1721. Swapping Nodes in a Linked List (M+)

147. Insertion Sort List

382. Linked List Random Node (E+)



Tree

100. Same Tree (E)

872. Leaf-Similar Trees (E+)

104. Maximum Depth of Binary Tree (E)

*110. Balanced Binary Tree (M-)

101. Symmetric Tree (M-)

*543. Diameter of Binary Tree (M-)

112. Path Sum (E+)

113. Path Sum II (M)

*437. Path Sum III (H-)

1110. Delete Nodes And Return Forest (M)

226. Invert Binary Tree (E+)

617. Merge Two Binary Trees (M-)

572. Subtree of Another Tree (M)

404. Sum of Left Leaves (M-)

508. Most Frequent Subtree Sum (M-)

*250. Count Univalue Subtrees (M)

563. Binary Tree Tilt (M)

951. Flip Equivalent Binary Trees (M)

366. Find Leaves of Binary Tree (M-)

*834. Sum of Distances in Tree (H)

*1443. Minimum Time to Collect All Apples in a Tree (M+)

2477. Minimum Fuel Cost to Report to the Capital (M)

*427. Construct Quad Tree (M-)

742. Closest Leaf in a Binary Tree

814. Binary Tree Pruning

298. Binary Tree Longest Consecutive Sequence

545. Boundary of Binary Tree

919. Complete Binary Tree Inserter

1161. Maximum Level Sum of a Binary Tree

662. Maximum Width of Binary Tree

979. Distribute Coins in Binary Tree

1522. Diameter of N-Ary Tree

BFS

200. Number of Islands (M-)

*127. Word Ladder (H-)

*126. Word Ladder II (H)

490. The Maze (M)

*934. Shortest Bridge (H-)

994. Rotting Oranges (M+)

*1162. As Far from Land as Possible (M+)

130. Surrounded Regions (M)

*529. Minesweeper (M+)

339. Nested List Weight Sum (M-)

1091. Shortest Path in Binary Matrix (M+)

*675. Cut Off Trees for Golf Event (M+)

*1293. Shortest Path in a Grid with Obstacles Elimination (H)

*785. Is Graph Bipartite? (M+)

815. Bus Routes (H-)

1311. Get Watched Videos by Your Friends (M)

*1345. Jump Game IV (H-)

*909. Snakes and Ladders (M+)

1129. Shortest Path with Alternating Colors (M+)

1559. Detect Cycles in 2D Grid

928. Minimize Malware Spread II

**1263. Minimum Moves to Move a Box to Their Target Location (H++)

*433. Minimum Genetic Mutation (M)



DFS

*695. Max Area of Island (E+)

*547. Number of Provinces (M-)

*417. Pacific Atlantic Water Flow (M+)

*694. Number of Distinct Islands (H)

46. Permutations (M)

47. Permutations II (M+)

77. Combinations (M)

*37. Sudoku Solver (H-)

*51. N-Queens (H-)

40. Combination Sum II (M)

39. Combination Sum (M-)

*489. Robot Room Cleaner (H)

79. Word Search (M)

131. Palindrome Partitioning (M+)

*291. Word Pattern II (H-)

*399. Evaluate Division (H-)

1306. Jump Game III (M-)

*22. Generate Parentheses (M-)

*17. Letter Combinations of a Phone Number (M-)

*386. Lexicographical Numbers (M)

419. Battleships in a Board (M)

841. Keys and Rooms (M-)

886. Possible Bipartition (M)

797. All Paths From Source to Target (E)

*980. Unique Paths III (M+)

*491. Non-decreasing Subsequences (M+)

*93. Restore IP Addresses (M+)

282. Expression Add Operators

425. Word Squares

351. Android Unlock Patterns



Union_Find

547.friend circles/ number of provinces (M)

648.redundant connection (M-)

1971. Find if Path Exists in Graph (E+)

323. Number of Connected Components in an Undirected Graph (M-)

1061. Lexicographically Smallest Equivalent String (M)



Graph

*332. Reconstruct Itinerary (H)

*2359. Find Closest Node to Given Two Nodes (M)

*753. Cracking the Safe (H+)



Recursion

87. Scramble String

133. Clone Graph

780. Reaching Points

390. Elimination Game

1088. Confusing Number II

991. Broken Calculator

2571. Minimum Operations to Reduce an Integer to 0 (M)

Dynamic Programming

509. Fibonacci Number (E)

746. Min Cost Climbing Stairs (E)

*823. Binary Trees With Factors (M+)

*413. Arithmetic Slices (H-)

*221. Maximal Square (H-)

818. Race Car

前缀和, 差分,扫描线

1480. Running Sum of 1d Array (E-)

*560. Subarray Sum Equals K (M+)

*528. Random Pick with Weight (M+)

238. Product of Array Except Self

*974. Subarray Sums Divisible by K (M+)

*523. Continuous Subarray Sum (H-)

*525. Contiguous Array (M+)

930. Binary Subarrays With Sum (M)

303. Range Sum Query - Immutable (E)

*304. Range Sum Query 2D - Immutable (M+)

*325. Maximum Size Subarray Sum Equals k (M+)

2256. Minimum Average Difference (E+)

*2389. Longest Subsequence With Limited Sum (M+)

862. Shortest Subarray with Sum at Least K

363. Max Sum of Rectangle No Larger Than K

1124. Longest Well-Performing Interval

1314. Matrix Block Sum

1094. Car Pooling

724. Find Pivot Index



Stack

682. Baseball Game (E)

*1249. Minimum Remove to Make Valid Parentheses (M-)

232. Implement Queue using Stacks(E)

1047. Remove All Adjacent Duplicates In String (E)



Priority Queue

703. Kth Largest Element in a Stream (M)

1046. Last Stone Weight (E)

2512. Reward Top K Students (M)

632. Smallest Range Covering Elements from K Lists

1675. Minimize Deviation in Array

23. Merge k Sorted Lists


Greedy

455. Assign Cookies (E+)

605. Can Place Flowers (E)

*55. Jump Game (M-)

*45. Jump Game II (M)

*134. Gas Station (H)

*229. Majority Element II (H)

*659. Split Array into Consecutive Subsequences (H-)

*484. Find Permutation (H-)

*280. Wiggle Sort (M+)

2178. Maximum Split of Positive Even Integers (M+)

*624. Maximum Distance in Arrays (M+)

*2271. Maximum White Tiles Covered by a Carpet (M+)

*665. Non-decreasing Array (M+)

*670. Maximum Swap (M+)

*330. Patching Array (H)

*517. Super Washing Machines (H+)

*2551. Put Marbles in Bags (H)

2279. Maximum Bags With Full Capacity of Rocks (E)

1328. Break a Palindrome (M)

2214. Minimum Health to Beat Game (E+)

781. Rabbits in Forest

*881. Boats to Save People (M)

910. Smallest Range II

916. Word Subsets

968. Binary Tree Cameras

2244. Minimum Rounds to Complete All Tasks (E+)

1833. Maximum Ice Cream Bars (E)

*2306. Naming a Company (M+)


Hashmap

1. Two Sum (E)

170. Two Sum III - Data structure design (E)

49. Group Anagrams (M-)

*128. Longest Consecutive Sequence (H-)

594. Longest Harmonious Subsequence (M-)

*149. Max Points on a Line (M+)

*380. Insert Delete GetRandom O(1) (M-)

217. Contains Duplicate (E)

166. Fraction to Recurring Decimal (M+)

392. Is Subsequence (H-)

*792. Number of Matching Subsequences (H-)

409. Longest Palindrome (E)

244. Shortest Word Distance II (M-)

811. Subdomain Visit Count (M-)

*447. Number of Boomerangs (M-)

*356. Line Reflection (M)

890. Find and Replace Pattern (E+)

939. Minimum Area Rectangle (M)

1074. Number of Submatrices That Sum to Target

*705. Design HashSet (M)

706. Design HashMap (M)

2342. Max Sum of a Pair With Equal Sum of Digits (M-)

*697. Degree of an Array (M-)

414. Third Maximum Number (E)

1338. Reduce Array Size to The Half (M-)

1055. Shortest Way to Form String (M)

345. Reverse Vowels of a String (M-)

2131. Longest Palindrome by Concatenating Two Letter Words (M-)

1704. Determine if String Halves Are Alike (E)

1657. Determine if Two Strings Are Close(M-)

1165. Single-Row Keyboard (E)

290. Word Pattern (M-)

997. Find the Town Judge (E)



Trie(Prefix Tree)

1032. Stream of char (M+)

336. Palindrome Pairs



Math

31. Next Permutation (H)

204. Count Primes (M+)

1290. Convert Binary Number in a Linked List to Integer (E)

1217. Minimum Cost to Move Chips to The Same Position (M)

1260. Shift 2D Grid (H)

*48. Rotate Image (M+)

12. Integer to Roman (E+)

*1071. Greatest Common Divisor of Strings (M)

453. Minimum Moves to Equal Array Elements

462. Minimum Moves to Equal Array Elements II

  1. Add Two Integers (H+)



String

*844. Backspace String Compare (M+)

415. Add Strings (M-)

408. Valid Word Abbreviation (E)

242. Valid Anagram (E-)

205. Isomorphic Strings (E)

647. Palindromic Substrings (M)

*696. Count Binary Substrings (M+)

409. Longest Palindrome (E)

*6. Zigzag Conversion (M-)

*388. Longest Absolute File Path (H-)

68. Text Justification (H)

13. Roman to Integer (E)

*418. Sentence Screen Fitting (M+)

*423. Reconstruct Original Digits from English (H)

*616/758. Add Bold Tag in String (H-)

520. Detect Capital (E)

564. Find the Closest Palindrome

722. Remove Comments

736. Parse Lisp Expression

527. Word Abbreviation

434. Number of Segments in a String (E)

389. Find the Difference (E)

953. Verifying an Alien Dictionary(E)

2259. Remove Digit From Number to Maximize Result (E+)



Bit Manipulation



Design

346. Moving Average from Data Stream (E)

359. Logger Rate Limiter (E)

380. Insert Delete GetRandom O(1) (M)

*381. Insert Delete GetRandom O(1) - Duplicates allowed (H)

362. Design Hit Counter (M-)

*631. Design Excel Sum Formula (H)

*295. Find Median from Data Stream (M)

353. Design Snake Game

1166. Design File System

716. Max Stack

155. Min Stack

588. Design In-Memory File System

1472. Design Browser History

1656. Design an Ordered Stream

1396. Design Underground System

901. Online Stock Span

981. Time Based Key-Value Store

1146. Snapshot Array

622. Design Circular Queue

348. Design Tic-Tac-Toe

355. Design Twitter

1603. Design Parking System



Sorting

912. Sort an Array (E)

*493. Reverse Pairs (H-)

324. Wiggle Sort II

1228. Missing Number In Arithmetic Progression

904. Fruit Into Baskets

869. Reordered Power of 2

1710. Maximum Units on a Truck

757. Set Intersection Size At Least Two

1366. Rank Teams by Votes

1356. Sort Integers by The Number of 1 Bits

179. Largest Number

148. Sort List

164. Maximum Gap

581. Shortest Unsorted Continuous Subarray

*274. H-Index (M)

275. H-Index II

406. Queue Reconstruction by Height

731. My Calendar II

826. Most Profit Assigning Work

1268. Search Suggestions System

1402. Reducing Dishes

1520. Maximum Number of Non-Overlapping Substrings

969. Pancake Sorting

1859. Sorting the Sentence

853. Car Fleet (M+)

*539. Minimum Time Difference (M-)

*899. Orderly Queue (H-)

*869. Reordered Power of 2 (M)



Bit Manipulation

231. Power of Two (E)

191. Number of 1 Bits (E)



Other

*54. Spiral Matrix (M+)

59. Spiral Matrix II (M)

118. Pascal's Triangle (E)

566. Reshape the Matrix(E)

36. Valid Sudoku (E+)

163. Missing Ranges (E)

*989. Add to Array-Form of Integer (M)

67. Add Binary (E+)

About

This repository contain my solutions and my explanations to the problems on LeetCode. All the solutions are written in C++. 大部分题目还没被加进目录(页面最下或者click Readme),我还在努力中

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published