Skip to content

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

Notifications You must be signed in to change notification settings

kaidul/LeetCode_problems_solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Solutions to LeetCode Programming Problems

Solutions to all Leetcode programming problems as of 13th January, 2019 (657/657).

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

Releases

No releases published

Packages

No packages published