Skip to content

kaidul/LeetCode_problems_solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Solutions to LeetCode Programming Problems

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