Skip to content

kaidul/LeetCode_problems_solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Solutions to LeetCode Programming Problems

  1. 01 Matrix
  2. 132 Pattern
  3. 24 Game
  4. 3 Sum Closest
  5. 3 Sum Smaller
  6. 3 Sum
  7. 4 Sum II
  8. 4 Sum
  9. Add Binary
  10. Add One Row to Tree
  11. Add Strings
  12. Add Two Numbers II
  13. Add Two Numbers
  14. Add and Search Word Data structure design
  15. Add digits
  16. Additive Number
  17. Alien Dictionary
  18. All O one Data Structure
  19. All Paths From Source to Target
  20. All Possible Full Binary Trees
  21. Anagrams
  22. Arithmetic Slices II - Subsequence
  23. Arithmetic Slices
  24. Arranging Coins
  25. Array Nesting
  26. Array Partition I
  27. Assign Cookies
  28. Average of Levels in Binary Tree
  29. Balanced Binary Tree
  30. Base 7
  31. Baseball Game
  32. Basic Calculator II
  33. Basic Calculator
  34. Battleships in a Board
  35. Beautiful Arrangement II
  36. Beautiful Arrangement
  37. Best Meeting Point
  38. Best Time to Buy and Sell Stock III
  39. Best Time to Buy and Sell Stock II
  40. Best Time to Buy and Sell Stock IV
  41. Best Time to Buy and Sell Stock with Cooldown
  42. Best Time to Buy and Sell Stock with Transaction Fee
  43. Best Time to Buy and Sell Stock
  44. Binary Gap
  45. Binary Number with Alternating Bits
  46. Binary Search Tree Iterator
  47. Binary Tree Inorder Traversal
  48. Binary Tree Level Order Traversal II
  49. Binary Tree Level Order Traversal
  50. Binary Tree Longest Consecutive Sequence
  51. Binary Tree Maximum Path Sum
  52. Binary Tree Postorder Traversal
  53. Binary Tree Preorder Traversal
  54. Binary Tree Tilt
  55. Binary Tree Upside Down
  56. Binary Tree Vertical Order Traversal
  57. Binary Tree Zigzag Level Order Traversal
  58. Binary Watch
  59. Binary tree Right Side View
  60. Binary tree paths
  61. Bitwise AND of Numbers Range
  62. Bomb Enemy
  63. Brick Wall
  64. Bulb Switcher II
  65. Bulb Switcher
  66. Bulls and Cows
  67. Burst Balloons
  68. Can I Win
  69. Can Place Flowers
  70. Candy
  71. Climbing Stairs
  72. Clone Graph
  73. Closest Binary Search Tree Value II
  74. Closest Binary Search Tree Value
  75. Coin Change 2
  76. Coin Change
  77. Combination Sum III
  78. Combination Sum II
  79. Combination Sum IV
  80. Combination Sum
  81. Combinations
  82. Combine Two Tables
  83. Compare Version Numbers
  84. Complex Number Multiplication
  85. Concatenated Words
  86. Consecutive Numbers
  87. Construct Binary Tree from Inorder and Postorder Traversal
  88. Construct Binary Tree from Inorder and Preorder Traversal
  89. Construct Binary Tree from String
  90. Construct String from Binary Tree
  91. Construct the Rectangle
  92. Container With Most Water
  93. Contains Duplicate III
  94. Contains Duplicate II
  95. Contains Duplicate
  96. Contiguous Array
  97. Continuous Subarray Sum
  98. Convert BST to Greater Tree
  99. Convert Sorted Array to Binary Search Tree
  100. Convert Sorted List to Binary Search Tree
  101. Convert a Number to Hexadecimal
  102. Convex Polygon
  103. Copy List with Random Pointer
  104. Count Binary Substrings
  105. Count Complete Tree Nodes
  106. Count Numbers with Unique Digits
  107. Count Univalue Subtrees
  108. Count and Say
  109. Count of Range Sum
  110. Count of Smaller Numbers After Self
  111. Count primes
  112. Counting Bits
  113. Course Schedule II
  114. Course Schedule
  115. Create Maximum Number
  116. Customers Who Never Order
  117. Cut Off Trees for Golf Event
  118. Daily Temperatures
  119. Data Stream as Disjoint Intervals
  120. Decode String
  121. Decode Ways II
  122. Decode Ways
  123. Degree of an Array
  124. Delete Duplicate Emails
  125. Delete Node in a BST
  126. Delete Node in a Linked List
  127. Delete Operation for Two Strings
  128. Department Highest Salary
  129. Design Hit Counter
  130. Design Phone Directory
  131. Design Search Autocomplete System
  132. Design Snake Game
  133. Design Tic-Tac-Toe
  134. Design Twitter
  135. Detect Capital
  136. Diagonal Traverse
  137. Diameter of Binary Tree
  138. Different Ways to Add Parentheses
  139. Distinct Subsequences
  140. Distribute Candies
  141. Divide Two Integers
  142. Dungeon Game
  143. Duplicate Emails
  144. Edit Distance
  145. Elimination Game
  146. Employee Importance
  147. Employees Earning More Than Their Managers
  148. Encode String with Shortest Length
  149. Encode and Decode Strings
  150. Encode and Decode TinyURL
  151. Equal Tree Partition
  152. Evaluate Division
  153. Evaluate Reverse Polish Notation
  154. Excel Sheet Column Number
  155. Excel Sheet Column Title
  156. Exclusive Time of Functions
  157. Expression Add Operators
  158. Factor Combinations
  159. Factorial Trailing Zeroes
  160. Find All Anagrams in a String
  161. Find All Duplicates in an Array
  162. Find All Numbers Disappeared in an Array
  163. Find Bottom Left Tree Value
  164. Find Duplicate File in System
  165. Find Duplicate Subtrees
  166. Find K Closest Elements
  167. Find K Pairs with Smallest Sums
  168. Find Largest Value in Each Tree Row
  169. Find Leaves of Binary Tree
  170. Find Median from Data Stream
  171. Find Minimum in Rotated Sorted Array II
  172. Find Minimum in Rotated Sorted Array
  173. Find Peak Element
  174. Find Permutation
  175. Find Pivot Index
  176. Find Right Interval
  177. Find the Celebrity
  178. Find the Difference
  179. Find the Duplicate Number
  180. First Bad Version
  181. First Missing Positive
  182. First Unique Character in a String
  183. Fizz Buzz
  184. Flatten 2D Vector
  185. Flatten Binary Tree to Linked List
  186. Flatten Nested List Iterator
  187. Flip Game II
  188. Flip Game
  189. Fraction to Recurring Decimal
  190. Freedom Trail
  191. Friend Circles
  192. Friends Of Appropriate Ages
  193. Frog Jump
  194. Game of Life
  195. Gas Station
  196. Generalized Abbreviation
  197. Generate Parentheses
  198. Goat Latin
  199. Graph Valid Tree
  200. Gray Code
  201. Group Anagrams
  202. Group Shifted Strings
  203. Groups of Special-Equivalent Strings
  204. Guess Number Higher or Lower II
  205. Guess Number Higher or Lower
  206. H-Index II
  207. H-Index
  208. Hamming Distance
  209. Happy Numbers
  210. Heaters
  211. House Robber III
  212. House Robber II
  213. House Robber
  214. Image Smoother
  215. Implement Magic Dictionary
  216. Implement Stack using Queues
  217. Implement Trie (Prefix Tree)
  218. Implement strStr()
  219. Increasing Order Search Tree
  220. Increasing Subsequences
  221. Increasing Triplet Subsequence
  222. Inorder Successor in BST
  223. Insert Delete GetRandom O(1)-Duplicates allowed
  224. Insert Delete GetRandom O(1)
  225. Insert Interval
  226. Insertion Sort List
  227. Integer Break
  228. Integer Replacement
  229. Integer to English Words
  230. Integer to Roman
  231. Interleaving String
  232. Intersection of Two Arrays II
  233. Intersection of Two Arrays
  234. Intersection of Two Linked Lists
  235. Invert Binary Tree
  236. Is Graph Bipartite?
  237. Is Subsequence
  238. Island Perimeter
  239. Isomorphic Strings
  240. Judge Route Circle
  241. Jump Game II
  242. Jump Game
  243. K Empty Slots
  244. K-diff Pairs in an Array
  245. Keyboard Row
  246. Kill Process
  247. Knight Probability in Chessboard
  248. Kth Largest Element in an Array
  249. Kth Smallest Element in a BST
  250. Kth Smallest Element in a Sorted Matrix
  251. Kth Smallest Number in Multiplication Table
  252. LFU Cache
  253. LRU Cache
  254. Largest BST Subtree
  255. Largest Divisible Subset
  256. Largest Number
  257. Largest Palindrome Product
  258. Largest Plus Sign
  259. Largest Rectangle in Histogram
  260. Length of Last Word
  261. Letter Case Permutation
  262. Letter Combinations of a Phone Number
  263. Lexicographical Numbers
  264. License Key Formatting
  265. Line Reflection
  266. Linked List Cycle II
  267. Linked List Cycle
  268. Linked List Random Node
  269. Logger Rate Limiter
  270. Lonely Pixel II
  271. Lonely Pixel I
  272. Longest Absolute File Path
  273. Longest Common Prefix
  274. Longest Consecutive Sequence
  275. Longest Continuous Increasing Subsequence
  276. Longest Harmonious Subsequence
  277. Longest Increasing Path in a Matrix
  278. Longest Increasing Subsequence
  279. Longest Palindrome
  280. Longest Palindromic Subsequence
  281. Longest Palindromic Substring
  282. Longest Repeating Character Replacement
  283. Longest Substrin with At Most K Distinct Characters
  284. Longest Substring Without Repeating Characters
  285. Longest Substring with At Least K Repeating Characters
  286. Longest Substring with At Most Two Distinct Characters
  287. Longest Uncommon Subsequence II
  288. Longest Uncommon Subsequence I
  289. Longest Univalue Path
  290. Longest Valid Parenthesis
  291. Longest Word in Dictionary through Deleting
  292. Lowest Common Ancestor Binary Search Tree
  293. Lowest Common Ancestor Binary Tree
  294. Magical String
  295. Majority Element II
  296. Majority Element
  297. Map Sum Pairs
  298. Matchsticks to Square
  299. Max Area of Island
  300. Max Consecutive Ones II
  301. Max Consecutive Ones
  302. Max Points on a Line
  303. Max Sum of Rectangle No Larger Than K
  304. Maximal Rectangle
  305. Maximal Square
  306. Maximum Average Subarray II
  307. Maximum Average Subarray I
  308. Maximum Binary Tree
  309. Maximum Depth of Binary Tree
  310. Maximum Distance in Arrays
  311. Maximum Gap
  312. Maximum Length of Pair Chain
  313. Maximum Product Subarray
  314. Maximum Product of Three Numbers
  315. Maximum Product of Word Lengths
  316. Maximum Size Subarray Sum Equals k
  317. Maximum Subarray
  318. Maximum Sum of 3 Non-Overlapping Subarrays
  319. Maximum Swap
  320. Maximum Width of Binary Tree
  321. Maximum XOR of Two Numbers in an Array
  322. Median of Two Sorted Arrays
  323. Meeting Rooms II
  324. Meeting Rooms
  325. Merge Intervals
  326. Merge Sorted Array
  327. Merge Two Binary Trees
  328. Merge Two Sorted Lists
  329. Merge k Sorted Lists
  330. Min Stack
  331. Minesweeper
  332. Mini Parser
  333. Minimum Absolute Difference in BST
  334. Minimum Depth of Binary Tree
  335. Minimum Factorization
  336. Minimum Genetic Mutation
  337. Minimum Height Trees
  338. Minimum Moves to Equal Array Elements II
  339. Minimum Moves to Equal Array Elements
  340. Minimum Number of Arrows to Burst Balloons
  341. Minimum Path Sum
  342. Minimum Size Subarray Sum
  343. Minimum Swaps To Make Sequences Increasing
  344. Minimum Time Difference
  345. Minimum Window Substring
  346. Missing Number
  347. Missing Ranges
  348. Monotonic Array
  349. Most Frequent Subtree Sum
  350. Move zeros
  351. Moving Average from Data Stream
  352. Multiply Strings
  353. N Queens
  354. N-Queens II
  355. Nested List Weight Sum
  356. Next Closest Time
  357. Next Greater Element III
  358. Next Greater Element II
  359. Next Greater Element I
  360. Next Permutation
  361. Nim Game
  362. Non-decreasing Array
  363. Non-negative Integers without Consecutive Ones
  364. Non-overlapping Intervals
  365. Nth Digit
  366. Number Complement
  367. Number Of Corner Rectangles
  368. Number of 1 Bits
  369. Number of Boomerangs
  370. Number of Connected Components in an Undirected Graph
  371. Number of Digit One
  372. Number of Distinct Islands
  373. Number of Islands II
  374. Number of Islands
  375. Number of Longest Increasing Subsequence
  376. Number of Segments in a String
  377. Odd Even Linked List
  378. One Edit Distance
  379. Ones and Zeroes
  380. Optimal Division
  381. Output Contest Matches
  382. Pacific Atlantic Water Flow
  383. Paint House II
  384. Paint House
  385. Palindrome Linked List
  386. Palindrome Number
  387. Palindrome Pairs
  388. Palindrome Partitioning II
  389. Palindrome Partitioning
  390. Palindrome Permutation II
  391. Palindrome Permutation
  392. Palindromic Substrings
  393. Partition Equal Subset Sum
  394. Partition List
  395. Partition to K Equal Sum Subsets
  396. Pascal's Triangle II
  397. Pascal's Triangle
  398. Patching array
  399. Path Sum III
  400. Path Sum II
  401. Path Sum
  402. Peeking Iterator
  403. Perfect Number
  404. Perfect Rectangle
  405. Perfect Squares
  406. Permutation Sequence
  407. Permutation in String
  408. Permutations II
  409. Permutations
  410. Plus One Linked List
  411. Plus One
  412. Poor Pigs
  413. Populating Next Right Pointers in Each Node II
  414. Populating Next Right Pointers in Each Node
  415. Pow(x, n)
  416. Power of Four
  417. Power of Three
  418. Power of Two
  419. Predict the Winner
  420. Prefix and Suffix Search
  421. Product of Array Except Self
  422. Queue Reconstruction by Height
  423. Random Pick Index
  424. Range Addition
  425. Range Sum Query 2D Immutable
  426. Range Sum Query 2D-Mutable
  427. Range Sum Query Immutable
  428. Range Sum Query-Mutable
  429. Rank Scores
  430. Ransom Note
  431. Read N Characters Given Read4 II-Call multiple times
  432. Read N Characters Given Read4
  433. Rearrange String k Distance Apart
  434. Reconstruct Itinerary
  435. Reconstruct Original Digits from English
  436. Recover Binary Search Tree
  437. Rectangle Area
  438. Rectangle Overlap
  439. Redundant Connection II
  440. Redundant Connection
  441. Regular Expression Matching
  442. Relative Ranks
  443. Remove Boxes
  444. Remove Duplicate Letters
  445. Remove Duplicates from Sorted Array II
  446. Remove Duplicates from Sorted Array
  447. Remove Duplicates from Sorted List II
  448. Remove Duplicates from Sorted List
  449. Remove Element
  450. Remove Invalid Parentheses
  451. Remove K Digits
  452. Remove Linked List Elements
  453. Remove Nth Node From End of List
  454. Reorder List
  455. Repeated DNA Sequences
  456. Repeated String Match
  457. Repeated Substring Pattern
  458. Replace Words
  459. Reshape the Matrix
  460. Restore IP Addresses
  461. Reverse Bits
  462. Reverse Integer
  463. Reverse Linked List II
  464. Reverse Linked List
  465. Reverse Nodes in k-Group
  466. Reverse Pairs
  467. Reverse String II
  468. Reverse String
  469. Reverse Vowels of a String
  470. Reverse Words in a String III
  471. Reverse Words in a String II
  472. Reverse Words in a String
  473. Rising Temperature
  474. Roman to Integer
  475. Rotate Array
  476. Rotate Function
  477. Rotate Image
  478. Rotate List
  479. Rotate String
  480. Russian Doll Envelopes
  481. Same Tree
  482. Scramble String
  483. Search Insert Position
  484. Search a 2D Matrix II
  485. Search a 2D Matrix
  486. Search for a Range
  487. Search in Rotated Sorted Array II
  488. Search in Rotated Sorted Array
  489. Second Highest Salary
  490. Second Minimum Node In a Binary Tree
  491. Self Crossing
  492. Sequence Reconstruction
  493. Serialize and Deserialize BST
  494. Serialize and Deserialize Binary Tree
  495. Set Matrix Zeroes
  496. Set Mismatch
  497. Shortest Distance from All Buildings
  498. Shortest Distance to a Character
  499. Shortest Palindrome
  500. Shortest Unsorted Continuous Subarray
  501. Shortest Word Distance III
  502. Shortest Word Distance II
  503. Shortest Word Distance
  504. Shuffle an Array
  505. Simplify Path
  506. Single Element in a Sorted Array
  507. Single Number III
  508. Single Number II
  509. Single Number
  510. Sliding Window Maximum
  511. Sliding Window Median
  512. Smallest Good Base
  513. Smallest Rectangle Enclosing Black Pixels
  514. Sort Characters By Frequency
  515. Sort Colors
  516. Sort List
  517. Sort Transformed Array
  518. Sparse Matrix Multiplication
  519. Spiral Matrix II
  520. Spiral Matrix
  521. Split Array Largest Sum
  522. Split Array into Consecutive Subsequences
  523. Sqrt(x)
  524. Stickers to Spell Word
  525. String Compression
  526. String to Integer (atoi)
  527. Strobogrammatic Number III
  528. Strobogrammatic Number II
  529. Strobogrammatic Number
  530. Student Attendance Record II
  531. Student Attendance Record I
  532. Subarray Product Less Than K
  533. Subarray Sum Equals K
  534. Subdomain Visit Count
  535. Subsets II
  536. Subsets
  537. Substring with Concatenation of All Words
  538. Subtree of Another Tree
  539. Sudoku Solver
  540. Sum Root to Leaf Numbers
  541. Sum of Left Leaves
  542. Sum of Two Integers
  543. Summary Ranges
  544. Super Pow
  545. Super Ugly Number
  546. Super Washing Machines
  547. Surrounded Regions
  548. Swap Nodes in Pairs
  549. Symmetric Tree
  550. Target Sum
  551. Task Scheduler
  552. Teemo Attacking
  553. Tenth Line
  554. Ternary Expression Parser
  555. Text Justification
  556. The Skyline Problem
  557. Third Maximum Number
  558. Top K Frequent Elements
  559. Top K Frequent Words
  560. Total Hamming Distance
  561. Trapping Rain Water
  562. Triangle
  563. Trim a Binary Search Tree
  564. Two Sum II-Input array is sorted
  565. Two Sum III-Data structure design
  566. Two Sum IV - Input is a BST
  567. Two Sum
  568. UTF-8 Validation
  569. Ugly Number II
  570. Ugly Number
  571. Unique Binary Search Trees II
  572. Unique Binary Search Trees
  573. Unique Paths II
  574. Unique Paths
  575. Unique Substrings in Wraparound String
  576. Unique Word Abbreviation
  577. Valid Anagram
  578. Valid Number
  579. Valid Palindrome II
  580. Valid Palindrome
  581. Valid Parentheses
  582. Valid Parenthesis String
  583. Valid Perfect Square
  584. Valid Phone Numbers
  585. Valid Square
  586. Valid Sudoku
  587. Valid Triangle Number
  588. Valid Word Abbreviation
  589. Valid Word Square
  590. Validate Binary Search Tree
  591. Validate IP Address
  592. Verify Preorder Sequence in Binary Search Tree
  593. Verify Preorder Serialization of a Binary Tree
  594. Walls and Gates
  595. Water and Jug Problem
  596. Wiggle Sort II
  597. Wiggle Sort
  598. Wiggle Subsequence
  599. Wildcard Matching
  600. Word Break II
  601. Word Break
  602. Word Frequency
  603. Word Ladder II
  604. Word Ladder
  605. Word Pattern II
  606. Word Pattern
  607. Word Search II
  608. Word Search
  609. Word Squares
  610. ZigZag Conversion
  611. Zigzag Iterator
  612. Zuma Game

About

Solutions to all problems of Leetcode online judge written in C++ and Java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published