ELEMENTS OF LEETCODE - Python solutions explained
Solutions/answers to Leetcode questions in Python and C++. For information about the project see the section About The Project.
TABLE OF CONTENTS
Bit Manipulation:
Array:
- Knowledge base
- Part 1 (37-45)
- 37. Flatten a nested list
- 38. Reorder, evens first
- 39. (LC 75) Dutch national flag
- 40. (LC 66) Increment an arbitrary-precision integer
- 41. Multiply two arbitrary-precision integers
- 42. (LC 55) Jump Game (Advancing through an array)
- 43. (LC 26) Delete duplicates from a sorted array
- 44. (LC 121) Buy and sell a stock once
- 45. (LC 123) Buy and sell a stock twice
- Part 2 (46-55)
- 46. (LC 280) Computing an alternation
- 47. (LC 204) Enumerate all primes to n
- 48. Permute the elements of an array
- 49. (LC 31) Compute the next permutation
- 50. Sample offline data
- 51. Sample online data
- 52. (LC 384) Compute a random permutation
- 53. Generate nonuniform random numbers
- 54. (LC 36) Valid Sudoku
- 55. (LC 118) Compute rows in Pascal’s triangle
- Part 3 (56-65)
- 56. (LC 1) Two Sum
- 57. (LC 15) 3Sum
- 58. (LC 16) 3Sum Closest
- 59. (LC 989) Add to Array-Form of Integer
- 60. (LC 419) Battleships in a Board
- 61. (LC 121) Best Time to Buy and Sell Stock
- 62. (LC 309) Best Time to Buy and Sell Stock with Cooldown
- 63. (LC 122) Best Time to Buy and Sell Stock II
- 64. (LC 1014) Best Sightseeing Pair
- 65. (LC 605) Can Place Flowers
- Part 4 (66-75)
- 66. (LC 1109) Corporate Flight Bookings
- 67. (LC 697) Degree of an Array
- 68. (LC 498) Diagonal Traverse
- 69. (LC 888) Fair Candy Swap
- 70. (LC 442) Find All Duplicates in an Array
- 71. (LC 448) Find All Numbers Disappeared in an Array
- 72. (LC 724) Find Pivot Index
- 73. (LC 1275) Find Winner on a Tic Tac Toe Game
- 74. (LC 287) Find the Duplicate Number
- 75. (LC 412) Fizz Buzz
- Part 5 (76-85)
- 76. (LC 896) Monotonic Array
- 77. (LC 293) Flip Game
- 78. (LC 832) Flipping an Image
- 79. (LC 48) Rotate Image
- 80. (LC 334) Increasing Triplet Subsequence
- 81. (LC 56) Merge Intervals
- 82. (LC 57) Insert Interval
- 83. (LC 215) Kth Largest Element in an Array
- 84. (LC 747) Largest Number At Least Twice of Others
- 85. (LC 949) Largest Time for Given Digits
- Part 6 (86-95)
- 86. (LC 860) Lemonade Change
- 87. (LC 531) Lonely Pixel I
- 88. (LC 674) Longest Continuous Increasing Subsequence
- 89. (LC 128) Longest Consecutive Sequence
- 90. (LC 229) Majority Element II
- 91. (LC 643) Maximum Average Subarray I
- 92. (LC 624) Maximum Distance in Arrays
- 93. (LC 670) Maximum Swap
- 94. (LC 4) Median of Two Sorted Arrays
- 95. (LC 921) Minimum Add to Make Parentheses Valid
- Part 7 (96-105)
- 96. (LC 945) Minimum Increment to Make Array Unique
- 97. (LC 209) Minimum Size Subarray Sum
- 98. (LC 3) Longest Substring Without Repeating Characters
- 99. (LC 163) Missing Ranges
- 100. (LC 238) Product of Array Except Self
- 101. (LC 53) Maximum Subarray
- 102. (LC 152) Maximum Product Subarray
- 103. (LC 217) Contains Duplicate
- 104. (LC 33) Search in Rotated Sorted Array
- 105. (LC 11) Container With Most Water
- Extra (137)
Strings:
- Knowledge base
- Part 1 (106-115)
- 106. (LC 125) Test palindromicity (Valid Palindrome)
- 107. (LC 8) String to Integer
- 108. (LC 171) Excel Sheet Column Number
- 108.2 (LC 168) Excel Sheet Column Title
- 109. (LC 186) Reverse Words in a String II
- 110. (LC 17) Letter Combinations of a Phone Number
- 111. (LC 38) Count and Say (Look-and-say)
- 112. (LC 13) Roman to Integer
- 113. (LC 93) Restore IP Addresses
- 114. Write a string sinusoidally
- 115. Implement run-length encoding
- Part 2 (116-125)
- 116. (LC 443) String Compression
- 117. (LC 28) Find the Index of the First Occurrence in a String
- 118. (LC 424) Longest Repeating Character Replacement
- 119. (LC 76) Minimum Window Substring
- 120. (LC 242) Valid Anagram
- 121. (LC 49) Group Anagrams
- 122. (LC 20) Valid Parentheses
- 123. (LC 5) Longest Palindromic Substring
- 124. (LC 647) Palindromic Substrings
- 125. (LC 271) Encode and Decode Strings
- Part 3 (126-136)
- 126. (LC 67) Add Binary
- 127. (LC 415) Add Strings
- 128. (LC 58) Length of Last Word
- 129. (LC 14) Longest Common Prefix
- 130. (LC 43) Multiply Strings
- 131. (LC 496) Next Greater Element I
- 132. (LC 344) Reverse String
- 133. (LC 929) Unique Email Addresses
- 134. (LC 680) Valid Palindrome II
- 135. (LC 953) Verifying an Alien Dictionary
- 136. (LC 6) Zigzag Conversion
Two Pointers:
Sliding Window:
Linked List:
- Part 1 (152-160)
- 152. (LC 21) Merge Two Sorted Lists
- 153. (LC 206) Reverse Linked List
- 154. (LC 92) Reverse Linked List II
- 155. (LC 141) Linked List Cycle
- 156. (LC 142) Linked List Cycle II
- 157. (LC 160) Intersection of Two Linked Lists
- 158. Intersection of Two Linked Lists - lists may have cycles
- 159. (LC 143) Reorder List
- 160. (LC 237) Delete Node in a Linked List
- Part 2 (161-172)
- 161. (LC 19) Remove Nth Node From End of List
- 162. (LC 83) Remove Duplicates from Sorted List
- 163. (LC 61) Rotate List
- 164 (LC 328) Odd Even Linked List
- 165. (LC 234) Palindrome Linked List
- 166. (LC 86) Partition List
- 167. (LC 2) Add Two Numbers
- 168. (LC 138) Copy List with Random Pointer
- 169. (LC 146) LRU Cache
- 170. (LC 707) Design Linked List
- 171. (LC 23) Merge k Sorted Lists
- 172. (LC 25) Reverse Nodes in k-Group
Stack and Queue:
- Part 1 (173-180)
- Part 2 (181-190)
- 181. (LC 456) 132 Pattern
- 182. (LC 735) Asteroid Collision
- 183. (LC 394) Decode String
- 184. (LC 895) Maximum Frequency Stack
- 185. (LC 901) Online Stock Span
- 186. Implement queue
- 187. (LC 102) Binary Tree Level Order Traversal
- 188. (LC 622) Design Circular Queue
- 189. (LC 232) Implement Queue using Stacks
- 190. Implement a Queue with max API
About the Project: