post_href stringlengths 57 213 | python_solutions stringlengths 71 22.3k | slug stringlengths 3 77 | post_title stringlengths 1 100 | user stringlengths 3 29 | upvotes int64 -20 1.2k | views int64 0 60.9k | problem_title stringlengths 3 77 | number int64 1 2.48k | acceptance float64 0.14 0.91 | difficulty stringclasses 3
values | __index_level_0__ int64 0 34k |
|---|---|---|---|---|---|---|---|---|---|---|---|
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1461222/Python-or-Beats-97.97-Solutions-or-Time%3A-log(n)-or-Explained | class Solution:
def findMin(self, nums: List[int]) -> int:
if len(nums)==1:
return nums[0]
if nums[0]<nums[-1]:
return nums[0]
n = len(nums)
st = 0
end = n-1
while(st<=end):
mid = (st+end)//2
if mid!=0 and nums[mid-1]>nu... | find-minimum-in-rotated-sorted-array | Python | Beats 97.97% Solutions | Time: log(n) | Explained | g-divyanshu | 1 | 228 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,400 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1350850/Python-Solution-Beats-99.59-of-Python-submissions | class Solution:
def findMin(self, arr: List[int]) -> int:
low,high=0,len(arr)-1
if arr[low]<=arr[high]:return arr[low]
while low<=high:
if low==high:return low
mid=(low+high)//2
if mid<high and arr[mid+1]<arr[mid]:return arr[mid+1]
if mid>low a... | find-minimum-in-rotated-sorted-array | Python Solution Beats 99.59% of Python submissions | reaper_27 | 1 | 216 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,401 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1297873/Python-The-Good-The-Bad-The-Ugly-Solution | class Solution(object):
def findMin(self, nums):
left = 0;right=len(nums)-1
while left<right:
mid = (left+right)//2
if nums[mid]>nums[right]:
left=mid+1
else:
right=mid
return nums[left] | find-minimum-in-rotated-sorted-array | [Python] The Good, The Bad, The Ugly Solution | akashadhikari | 1 | 116 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,402 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1297873/Python-The-Good-The-Bad-The-Ugly-Solution | class Solution(object):
def findMin(self, nums):
return min(nums) | find-minimum-in-rotated-sorted-array | [Python] The Good, The Bad, The Ugly Solution | akashadhikari | 1 | 116 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,403 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/1297873/Python-The-Good-The-Bad-The-Ugly-Solution | class Solution(object):
def findMin(self, nums):
for i in range(1,len(nums)):
if nums[i] < nums[i-1]:
return nums[i]
return nums[0] | find-minimum-in-rotated-sorted-array | [Python] The Good, The Bad, The Ugly Solution | akashadhikari | 1 | 116 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,404 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2847961/Python-Solution | class Solution:
def findMin(self, nums: List[int]) -> int:
return min(nums) | find-minimum-in-rotated-sorted-array | Python Solution | abdulrahmanphy64 | 0 | 1 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,405 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2844486/Python-Easy-Solution-Simple-to-understand.-Beats-99.43-and-96.15-in-memory. | class Solution:
def findMin(self, nums: List[int]) -> int:
l=nums[0]
for i in nums:
if i<l:
l=i
return l | find-minimum-in-rotated-sorted-array | Python Easy Solution, Simple to understand. Beats 99.43% and 96.15% in memory. | user7478F | 0 | 3 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,406 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2842868/41ms-95-or-Easy-and-Simple-to-Read-or-Binary-Search-Approach-or-O(logn)-time-or-O(1)-space | class Solution:
def findMin(self, nums: List[int]) -> int:
left = 0
right = len(nums) - 1
while left <= right:
mid = (left + right) >> 1
if nums[mid] > nums[-1]:
left = mid + 1
else:
right = mid -1
return nums[left] | find-minimum-in-rotated-sorted-array | 41ms 95% | Easy and Simple to Read | Binary Search Approach | O(logn) time | O(1) space | advanced-bencoding | 0 | 1 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,407 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2831309/Python-3-9-lines-simple-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
prev_val = nums[0]
l, r = 0, len(nums) - 1
if nums[l] <= nums[r]: return nums[l]
while l < r:
m = (l + r) // 2
if nums[m] < prev_val: r = m
else: ... | find-minimum-in-rotated-sorted-array | Python 3 - 9 lines - simple solution | noob_in_prog | 0 | 4 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,408 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2818580/Python-or-3-ways(OneLine-solution) | class Solution:
def findMin(self, nums: List[int]) -> int:
# 1. one line sorting
# since we know the smallest number is the first item in the sorted list
return sorted(nums)[0]
# 2. it should follow the raising order, therefore, once the previous one(nums[i]) is greater ... | find-minimum-in-rotated-sorted-array | Python | 3 ways(OneLine solution) | vinafu0305 | 0 | 4 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,409 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2809851/Easy-Python-solution-beats-97 | class Solution:
def findMin(self, nums: List[int]) -> int:
if nums[0] <= nums[-1]:
return nums[0]
l, r = 0, len(nums)-1
while True:
m = (l+r)//2
if nums[l] > nums[l+1]: #only remain 2 elements, 2nd is smaller than 1st element => Found rotation point
... | find-minimum-in-rotated-sorted-array | Easy Python solution beats 97% | dominhnhut01 | 0 | 3 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,410 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2801081/Minimum-in-Rotated-Sorted-Array | class Solution:
def findMin(self, nums: List[int]) -> int:
self.nums = nums
left = 0
right = len(nums) - 1
ans = nums[0]
if len(nums) == 0:
return 0
elif len(nums) == 1:
return nums[0]
while(left <= right ): #while the left index is ... | find-minimum-in-rotated-sorted-array | Minimum in Rotated Sorted Array | AlhajiDot | 0 | 1 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,411 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2776165/Intuitive-Binary-Search-PYTHON3-SOLUTION-90-Faster | class Solution:
def findMin(self, nums: List[int]) -> int:
l, r = 0, len(nums) - 1
minimum = 999
if nums[-1] > nums[0]:
return nums[0]
while l <= r:
mid = (l + r) // 2
#mid is in left subarray
if nums[mid] >= nums[0]:
l... | find-minimum-in-rotated-sorted-array | Intuitive Binary Search - PYTHON3 SOLUTION 90% Faster | gjayakumar3 | 0 | 4 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,412 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2764882/Python-Binary-Search | class Solution:
def findMin(self, nums: List[int]) -> int:
N = len(nums)
left, right = 0 , len(nums) - 1
if len(nums) <= 3:
return min(nums)
while left<= right:
mid = (left + right ) // 2
if nums[left] < nums[right]:
return nums[lef... | find-minimum-in-rotated-sorted-array | Python Binary Search | vijay_2022 | 0 | 2 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,413 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2744726/Python3-Binary-Search-(with-comments) | class Solution:
def findMin(self, nums: List[int]) -> int:
l, r = 0, len(nums)-1
res = float('inf')
while l <= r:
mid = (l+r)//2
# left half sorted
if nums[l] <= nums[mid]:
res = min(res, nums[l])
l = mid+1
#... | find-minimum-in-rotated-sorted-array | Python3 Binary Search (with comments) | jonathanbrophy47 | 0 | 4 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,414 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2740850/Find-Minimum-in-Rotated-Sorted-Array-or-PYTHON-or-Accepted | class Solution:
def findMin(self, nums: List[int]) -> int:
l=0
h=len(nums)-1
while(l<h):
if nums[l] > nums[h]:
l+=1
else:
return nums[l]
return nums[l] | find-minimum-in-rotated-sorted-array | Find Minimum in Rotated Sorted Array | PYTHON | Accepted | saptarishimondal | 0 | 3 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,415 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2740038/Simple-Beginner-Friendly-Approach-or-One-Pass-or-no-built-in-function-or-O(LogN)-or-O(1) | class Solution:
def findMin(self, nums: List[int]) -> int:
left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
if left == mid:
return min(nums[left], nums[right])
elif nums[left] < nums[right]:
return nums[... | find-minimum-in-rotated-sorted-array | Simple Beginner Friendly Approach | One Pass | no built-in function | O(LogN) | O(1) | sonnylaskar | 0 | 3 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,416 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2730119/Binary-search-ffs | class Solution:
def findMin(self, nums: List[int]) -> int:
res = nums[0]
l, r = 0, len(nums) - 1
while l <= r:
# if already sorted
if nums[l] < nums[r]:
res = min(res, nums[l])
break
# if updates in l,r below ... | find-minimum-in-rotated-sorted-array | 😂 Binary search ffs | meechos | 0 | 7 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,417 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2729360/Python-Binary-Search-Simple-When-Drawn-Out | class Solution:
def findMin(self, nums: List[int]) -> int:
''' 0 1 2 3 4
Let's say we have: [3,4,5,1,2]
L M R
Mid (5) is larger than Right (2) which means right portion includes a rotation
so set the new Left to the right of current... | find-minimum-in-rotated-sorted-array | [Python] Binary Search Simple When Drawn Out | graceiscoding | 0 | 8 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,418 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2728690/Python3-or-deque-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
q = collections.deque()
q.extend(nums)
while q[0] > q[-1]:
_ = q.popleft()
return q[0] | find-minimum-in-rotated-sorted-array | Python3 | deque solution | puppydog91111 | 0 | 2 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,419 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2704222/Simplest-python3-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
N = len(nums)
left = 0
right = N - 1
while left < right:
mid = left + (right - left) // 2
if nums[mid] <= nums[right]: # pre-rotated section
right = mid
else:
... | find-minimum-in-rotated-sorted-array | Simplest python3 solution | sandeshnep | 0 | 2 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,420 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2672897/Simple-and-Straight-Forward-Solution | class Solution:
def findMin(self, nums: List[int]) -> int:
start = 0
end = len(nums)-1
while start<=end:
mid = start + (end-start)//2
if start==end:
return nums[start]
if nums[mid] >=nums[end]:
... | find-minimum-in-rotated-sorted-array | Simple and Straight Forward Solution | anusha_anil | 0 | 29 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,421 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2670495/Python-Solution-or-Binary-search | class Solution:
def findMin(self, nums: List[int]) -> int:
left = 0
right = len(nums)-1
if len(nums) == 1:
return nums[0]
while right > left:
mid = (right + left)//2
if nums[mid] > nums[right]:
left = ... | find-minimum-in-rotated-sorted-array | Python Solution | Binary search | maomao1010 | 0 | 45 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,422 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2656342/Python-Solution | class Solution:
def findMin(self, nums: List[int]) -> int:
res= nums[0]
l = 0
r = len(nums) - 1
while l <= r:
if nums[l] < nums[r]:
res = min(res, nums[l])
break
m = (l + r) // 2
res = min(res, nums[m])
... | find-minimum-in-rotated-sorted-array | Python Solution | brianshen333 | 0 | 1 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,423 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2631925/Python-Solution-or-Binary-Search-or-99-Faster | class Solution:
def findMin(self, nums: List[int]) -> int:
n=len(nums)
low=0
high=n-1
while low<=high:
mid=(low+high)//2
if nums[mid]<nums[high]:
high=mid
else:
low=mid+1
return nums[high] | find-minimum-in-rotated-sorted-array | Python Solution | Binary Search | 99% Faster | Siddharth_singh | 0 | 7 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,424 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2470840/Python-Simple-Binary-Search-Solution-With-Comments | class Solution:
def findMin(self, nums: List[int]) -> int:
# Edge case #
if len(nums) == 0:
return 0
# Binary Search #
res = nums[0]
left = 0
right = len(nums) - 1
while left <= right:
# If the left value is less than ... | find-minimum-in-rotated-sorted-array | Python Simple Binary Search Solution With Comments | PythonicLava | 0 | 123 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,425 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2452165/easy-python-code-or-binary-search-or-O(log-n) | class Solution:
def findMin(self, nums: List[int]) -> int:
l,r = 0,len(nums)-1
if nums[l]<=nums[r]:
return nums[l]
while(l<=r):
if r-l <= 1:
if nums[l] <= nums[r]:
return nums[l]
else:
return nums... | find-minimum-in-rotated-sorted-array | easy python code | binary search | O(log n) | dakash682 | 0 | 38 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,426 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2401410/Easy-to-understand-93-python3-iterative-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
n = len(nums)
def binarySearchMin(lo, hi) -> int:
while lo <= hi:
mid = (lo+hi)//2
prev = (mid-1)%n
nxt = (mid+1)%n
if nums[mid] < nums[pre... | find-minimum-in-rotated-sorted-array | Easy to understand 93% python3 iterative solution | destifo | 0 | 8 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,427 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2393123/PYTHON3-Simple-Binary-Search-Approach-(To-get-min-and-max-element) | class Solution:
def findMin(self, nums: List[int]) -> int:
l = 0
r = len(nums)-1
while(l<=r):
mid = (l+r)//2
if(nums[mid]<nums[l]):
r=mid
elif(nums[mid]>nums[r]):
l=mid+1
else:
return nums[l]
... | find-minimum-in-rotated-sorted-array | PYTHON3 - Simple Binary Search Approach (To get min and max element) | pkoder | 0 | 14 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,428 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2376771/40ms-Solution-in-3-Lines-that-Beat-96.14-So-Simple-No-Need-for-Explanation | class Solution:
def findMin(self, nums: List[int]) -> int:
for i in range(1, len(nums)):
if nums[i - 1] > nums[i]: return nums[i]
return nums[0] | find-minimum-in-rotated-sorted-array | 40ms Solution in 3 Lines that Beat 96.14%, So Simple No Need for Explanation | HappyLunchJazz | 0 | 32 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,429 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2375954/Python-3-or-2-Solutions-or-O(logn)-or-Simple-and-Fast | class Solution:
def findMin(self, nums: List[int]) -> int:
# T.C: O(n) S.C: O(1)
currmin = 99999
globalmin = 99999
for num in nums:
if num < currmin:
currmin = num
globalmin = min(currmin,globalmin)
return globalmin
... | find-minimum-in-rotated-sorted-array | Python 3 | 2 Solutions | O(logn) | Simple and Fast | chawlashivansh | 0 | 30 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,430 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2356223/Python-Simple-Python-Solution-Using-Binary-Search | class Solution:
def findMin(self, nums: List[int]) -> int:
low = 0
high = len(nums) - 1
while low < high:
mid = (low + high) // 2
if nums[mid] > nums[high]:
low = mid + 1
else:
high = mid
return nums[low] | find-minimum-in-rotated-sorted-array | [ Python ] ✅✅ Simple Python Solution Using Binary Search 🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 94 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,431 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2351634/6-line-O(LogN)-optimised-binary-search-solution-with-explanation | class Solution:
def findMin(self, nums: List[int]) -> int:
"""
the array after rotation will have 2( or 1) incremental part(s)
on binary search it would be the process of finding the first m in the right part
- if m is the in the right part already, r = m
- if m is n... | find-minimum-in-rotated-sorted-array | 6-line O(LogN) optimised binary search solution with explanation | zhenyulin | 0 | 31 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,432 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2350809/Python-Solution-or-Faster-than-88-or-Binary-Search | class Solution:
def findMin(self, nums: List[int]) -> int:
if len(nums) == 1:
return nums[0]
l = 0
r = len(nums) - 1
if nums[r] > nums[0]:
return nums[0]
while r >= l:
m = l + (r - l) // 2
if nums[m] > nums[m + 1]:
... | find-minimum-in-rotated-sorted-array | Python Solution | Faster than 88% | Binary Search | zip_demons | 0 | 34 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,433 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2314356/CPP-or-Java-or-Python-or-All-approaches-or-TC-O(n)-or | class Solution:
def findMin(self, nums: List[int]) -> int:
start, end = 0, len(nums)-1
while(start < end):
mid = start + (end - start)//2
if nums[start] < nums[end]: return nums[start]
elif nums[mid+1] < nums[mid]: return nums[mid+1]
elif nums... | find-minimum-in-rotated-sorted-array | CPP | Java | Python | All approaches | TC - O(n) | | devilmind116 | 0 | 31 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,434 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2258230/Python3-Clean-solution-with-comments | class Solution:
def findMin(self, nums: List[int]) -> int:
# Using Binary search concept...
low, high = 0, len(nums)-1
minv = inf
while low <= high:
mid = low + (high - low) // 2
minv = min(minv, nums[mid])
# Move on side where we can find... | find-minimum-in-rotated-sorted-array | [Python3] Clean solution with comments | Gp05 | 0 | 28 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,435 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2219077/Python-with-full-working-examples-explanation | class Solution: # we have to search for minimum element in a sorted array after rotation
def findMin(self, nums: List[int]) -> int: # Time: O(n) and Space:O(1)
res = nums[0]
l, r = 0, len(nums) - 1
while l <= r:
if nums[l] < nums[r]: # means the min element among th... | find-minimum-in-rotated-sorted-array | Python with full working examples explanation | DanishKhanbx | 0 | 21 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,436 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2181317/Python-O(Log-N)-very-simply-made-Binary-Search-solution-intuition-%2B-Code | class Solution:
def findMin(self, nums: List[int]) -> int:
res,left,right = 0,0,len(nums)-1
while(left <= right):
mid = (left + right) >> 1
if nums[mid] <= nums[mid-1]:
return nums[mid]
elif nums[mid] >= nums[right]:
left =... | find-minimum-in-rotated-sorted-array | Python O(Log N) very simply made Binary Search solution, intuition + Code | thota_datta | 0 | 87 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,437 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/2031726/Python-w-Explanation-or-O(logn) | class Solution:
def findMin(self, nums: List[int]) -> int:
# Binary search
lo = 0
hi = len(nums) - 1
global_min = inf
while lo <= hi:
mid = (lo + hi) // 2
# Update minimum if needed
global_min = min(nums[mid], global_min)
# Case... | find-minimum-in-rotated-sorted-array | Python w/ Explanation | O(logn) | user5622HA | 0 | 36 | find minimum in rotated sorted array | 153 | 0.485 | Medium | 2,438 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/2087295/Binary-Search-oror-Explained-oror-PYTHON | class Solution:
def findMin(self, a: List[int]) -> int:
def solve(l,h):
while l<h:
m=(l+h)//2
if a[m]<a[m-1]:
return a[m]
elif a[m]>a[h-1]:
l=m+1
... | find-minimum-in-rotated-sorted-array-ii | Binary Search || Explained || PYTHON | karan_8082 | 2 | 69 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,439 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/725072/Python3-binary-search | class Solution:
def findMin(self, nums: List[int]) -> int:
lo, hi = 0, len(nums)-1
while lo < hi:
mid = lo + hi >> 1
if nums[mid] < nums[hi]: hi = mid
elif nums[mid] == nums[hi]: hi -= 1 # duplicates
else: lo = mid + 1
return nums[lo] | find-minimum-in-rotated-sorted-array-ii | [Python3] binary search | ye15 | 1 | 76 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,440 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/2842989/Python-Binary-Search. | class Solution:
def findMin(self, nums: List[int]) -> int:
new=self.removedupli(nums)
print(new)
res=self.binary(new)
return res
def binary(self,nums):
l,r,ans=0,len(nums)-1,nums[0]
while l<=r:
if nums[l]<nums[r]:
ans=min(ans,nums[l])
... | find-minimum-in-rotated-sorted-array-ii | Python Binary Search. | jainatishay072 | 0 | 1 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,441 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/2800483/Python3-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
return(min(nums)) | find-minimum-in-rotated-sorted-array-ii | Python3 solution | SupriyaArali | 0 | 4 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,442 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/2311632/Attention-Simplest-one-line-solution | class Solution:
def findMin(self, nums: List[int]) -> int:
return min(nums) | find-minimum-in-rotated-sorted-array-ii | Attention ⚠️⚠️⚠️⚠️ Simplest one line solution | Akash2907 | 0 | 59 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,443 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/2150260/Python-easy-solution-with-explanation | class Solution:
def findMin(self, nums: List[int]) -> int:
# Go in loop from index 1 till end.
for i in range(1,len(nums)):
# Checking if 0th index element is greater than any other element in the list.
if(nums[0]>nums[i]):
# If yes then return that element.
... | find-minimum-in-rotated-sorted-array-ii | Python easy solution with explanation | yashkumarjha | 0 | 53 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,444 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1956511/Python-easy-to-read-and-understand-or-binary-search | class Solution:
def findMin(self, nums: List[int]) -> int:
n = len(nums)
if n == 1:
return nums[0]
start, end = 0, n-1
while start <= end:
mid = (start+end) // 2
prev, nxt = (mid-1+n)%n, (mid+1)%n
if nums[mid] < nums[prev] and nums[mid]... | find-minimum-in-rotated-sorted-array-ii | Python easy to read and understand | binary-search | sanial2001 | 0 | 70 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,445 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1956511/Python-easy-to-read-and-understand-or-binary-search | class Solution:
def findMin(self, nums: List[int]) -> int:
n = len(nums)
start, end = 0, n-1
while start <= end:
mid = (start+end) // 2
prev, nxt = (mid-1+n)%n, (mid+1)%n
if nums[mid] < nums[prev] and nums[mid] < nums[nxt]:
return nums[mid]... | find-minimum-in-rotated-sorted-array-ii | Python easy to read and understand | binary-search | sanial2001 | 0 | 70 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,446 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1537405/Python-Solution-very-Simple-and-really-intuitive-with-explanation. | class Solution:
def findMin(self, nums: List[int]) -> int:
is_rotated = False # set up a variable which tells us that the array was rotated
for i in range(len(nums)-1): # loop through the array till one less than the last index
if nums[i] > nums[i+1]... | find-minimum-in-rotated-sorted-array-ii | Python Solution very Simple and really intuitive with explanation. | anantinfinity9796 | 0 | 53 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,447 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1350957/Python-Solution-beats-99.48-Python-Submissons | class Solution:
def findMin(self, arr: List[int]) -> int:
low,high=0,len(arr)-1
if arr[0]<arr[-1]:return arr[0]
while low<=high:
if low==high:return arr[low]
mid=(low+high)//2
if arr[mid]==arr[low]==arr[high]:high-=1
elif arr[mid]==arr[high]:hi... | find-minimum-in-rotated-sorted-array-ii | Python Solution beats 99.48% Python Submissons | reaper_27 | 0 | 95 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,448 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1181396/One-line-code-solution-for-all-4-questions | class Solution:
def search(self, nums: List[int], target: int) -> int:
return nums.index(target) if target in nums else -1 | find-minimum-in-rotated-sorted-array-ii | One line code solution for all 4 questions | easyz2016 | 0 | 45 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,449 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1181396/One-line-code-solution-for-all-4-questions | class Solution:
def search(self, nums: List[int], target: int) -> bool:
return (target in nums) | find-minimum-in-rotated-sorted-array-ii | One line code solution for all 4 questions | easyz2016 | 0 | 45 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,450 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1181396/One-line-code-solution-for-all-4-questions | class Solution:
def findMin(self, nums: List[int]) -> int:
return sorted(nums)[0] | find-minimum-in-rotated-sorted-array-ii | One line code solution for all 4 questions | easyz2016 | 0 | 45 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,451 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1181396/One-line-code-solution-for-all-4-questions | class Solution:
def findMin(self, nums: List[int]) -> int:
return sorted(nums)[0] | find-minimum-in-rotated-sorted-array-ii | One line code solution for all 4 questions | easyz2016 | 0 | 45 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,452 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1143757/Very-easy-solution-with-one-function | class Solution:
def findMin(self, nums: List[int]) -> int:
return min(nums) | find-minimum-in-rotated-sorted-array-ii | Very easy solution with one function | vashisht7 | 0 | 68 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,453 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/957466/Simple-Python3-Solution-(Binary-Search) | class Solution:
def findMin(self, nums: List[int]) -> int:
if len(nums)==1:
return nums[0]
low,high = 0,len(nums)-1
if nums[low]<nums[high]:
return nums[low]
while low<=high:
while((low+1)<len(nums) and nums[low] == nums[low+1]):
lo... | find-minimum-in-rotated-sorted-array-ii | Simple Python3 Solution (Binary Search) | swap2001 | 0 | 81 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,454 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/759575/binary-search-with-special-handling-of-duplicated-values | class Solution:
def findMin(self, nums: List[int]) -> int:
start, end = 0, len(nums)-1
ans = float('inf')
while start <= end:
mid = (start+end)//2
# right part is sorted
if nums[mid] < nums[end]:
ans = min(ans, nums[mid])
en... | find-minimum-in-rotated-sorted-array-ii | binary search with special handling of duplicated values | ytb_algorithm | 0 | 67 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,455 |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/discuss/1385553/Half-length-pass-97-speed | class Solution:
def findMin(self, nums: List[int]) -> int:
len_nums = len(nums)
len_nums1, len_nums2 = len_nums - 1, len_nums - 2
for i in range(len_nums // 2):
if nums[i] > nums[i + 1]:
return nums[i + 1]
if nums[len_nums2 - i] > nums[len_nums1 - i]:... | find-minimum-in-rotated-sorted-array-ii | Half-length pass, 97% speed | EvgenySH | -2 | 153 | find minimum in rotated sorted array ii | 154 | 0.434 | Hard | 2,456 |
https://leetcode.com/problems/min-stack/discuss/825972/Python-3-greater-91-faster-using-namedtuple | class MinStack:
stackWithMinElements = collections.namedtuple("stackWithMinElements", ("element", "minimum"))
def __init__(self):
self.stack : List[self.stackWithMinElements] = []
def push(self, x: int) -> None:
self.stack.append(self.stackWithMinElements(
... | min-stack | Python 3 -> 91% faster using namedtuple | mybuddy29 | 5 | 554 | min stack | 155 | 0.519 | Medium | 2,457 |
https://leetcode.com/problems/min-stack/discuss/825972/Python-3-greater-91-faster-using-namedtuple | class MinStack:
def __init__(self):
self.stack = []
self.count = 0
def push(self, val: int) -> None:
topMin = val
if self.count > 0:
topMin = min(self.stack[-1][1], val)
self.stack.append((val, topMin))
self.count += 1
def pop(self) ... | min-stack | Python 3 -> 91% faster using namedtuple | mybuddy29 | 5 | 554 | min stack | 155 | 0.519 | Medium | 2,458 |
https://leetcode.com/problems/min-stack/discuss/1534170/python3-stack | class MinStack:
def __init__(self):
self.stack = []
def push(self, val: int) -> None:
if not self.stack:
self.stack.append((val,val)) # storing tuple of current value , min of curr and prev value of stack
else:
self.stack.append((val, min(val,self.stack[-1][1])... | min-stack | python3 - stack | Shubham_Muramkar | 4 | 372 | min stack | 155 | 0.519 | Medium | 2,459 |
https://leetcode.com/problems/min-stack/discuss/2252739/Python-~99.9-Faster-with-Explanation-and-Comments | class MinStack:
def __init__(self):
self.stack = []
self.min_val = 0
def push(self, val: int) -> None:
#When empty, set first element as min_val
if not self.stack:
self.min_val = val
cur_min = self.getMin()
if val < cur_min:
self.min_... | min-stack | Python ~99.9% Faster with Explanation and Comments | beochinh | 3 | 138 | min stack | 155 | 0.519 | Medium | 2,460 |
https://leetcode.com/problems/min-stack/discuss/1137100/Python3-Easy-Explanation-O(1)-Space-O(1)-Time | class MinStack:
def __init__(self):
self.Stack = []
self.minVal = None
def push(self, val: int) -> None:
if not self.Stack or self.minVal == None:
self.minVal = val
if not self.Stack:
self.Stack.appen... | min-stack | Python3 - Easy Explanation, O(1) Space, O(1) Time | piyushagg19 | 2 | 547 | min stack | 155 | 0.519 | Medium | 2,461 |
https://leetcode.com/problems/min-stack/discuss/2812426/Python-Solution-With-Explanation | class MinStack:
def __init__(self):
self.stack = []
self.minimums = deque()
def push(self, val: int) -> None:
self.stack.append(val)
if self.minimums and val <= self.minimums[0]:
self.minimums.appendleft(val)
return
self.minimums.append(v... | min-stack | Python Solution With Explanation | really_cool_person | 1 | 443 | min stack | 155 | 0.519 | Medium | 2,462 |
https://leetcode.com/problems/min-stack/discuss/2401340/Python-or-Easy-and-clean-solution-or-91-faster | class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, val: int) -> None:
self.stack.append(val)
val = min(val, self.minStack[-1] if self.minStack else val)
self.minStack.append(val)
def pop(self) -> None:
self.stack.pop()
... | min-stack | Python | Easy and clean solution | 91% faster | __Asrar | 1 | 157 | min stack | 155 | 0.519 | Medium | 2,463 |
https://leetcode.com/problems/min-stack/discuss/2086436/Python3-Runtime%3A-87ms-53.60 | class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, val):
newMinStack = {'min':val}
if len(self.minStack) > 0:
newMinStack['min'] = min(self.minStack[-1]['min'], val)
self.minStack.append(newMinStack)
self.s... | min-stack | Python3 Runtime: 87ms 53.60% | arshergon | 1 | 75 | min stack | 155 | 0.519 | Medium | 2,464 |
https://leetcode.com/problems/min-stack/discuss/2028324/Python-runtime-67.51-memory-71.24 | class MinStack:
def __init__(self):
self.stack = []
self.min = []
def push(self, val: int) -> None:
self.stack.append(val)
if self.min == [] or val <= self.min[-1]:
self.min.append(val)
def pop(self) -> None:
element = self.stack.pop()
... | min-stack | Python, runtime 67.51%, memory 71.24% | tsai00150 | 1 | 105 | min stack | 155 | 0.519 | Medium | 2,465 |
https://leetcode.com/problems/min-stack/discuss/1958359/Python-Clean-Code-Easy-Understanding | class MinStack:
def __init__(self):
self.arr = []
self.min = []
def push(self, val: int) -> None:
self.arr.append(val)
if len(self.min) == 0 or self.min[-1] >= val:
self.min.append(val)
def pop(self) -> None:
val = self.arr.pop()
if self.min[-1]... | min-stack | [Python] Clean Code, Easy Understanding | jamil117 | 1 | 110 | min stack | 155 | 0.519 | Medium | 2,466 |
https://leetcode.com/problems/min-stack/discuss/1893071/Python3-one-stack-and-two-stacks-runtime-O(1)-solutions-with-comments | class MinStack:
def __init__(self):
self.stack = []
def push(self, val: int) -> None:
if not self.stack:
self.stack.append((val, val))
else:
# at every push append the new pair with the new val with the smallest val in the list
self.stack.append((val, min(... | min-stack | Python3 one stack and two stacks runtime O(1) solutions with comments | v0vbs | 1 | 63 | min stack | 155 | 0.519 | Medium | 2,467 |
https://leetcode.com/problems/min-stack/discuss/1893071/Python3-one-stack-and-two-stacks-runtime-O(1)-solutions-with-comments | class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, val: int) -> None:
self.stack.append(val)
# if the new val is smallest than the curr smallest val in the list then we append it to the minStack
if not self.minStack or val <= self.minStack[... | min-stack | Python3 one stack and two stacks runtime O(1) solutions with comments | v0vbs | 1 | 63 | min stack | 155 | 0.519 | Medium | 2,468 |
https://leetcode.com/problems/min-stack/discuss/1540272/Python3-solution | class MinStack:
elem = namedtuple('elem', ['val', 'minval'])
def __init__(self):
self.s = [] # stack of elem
def push(self, val: int) -> None:
minval = min(val, self.s[-1].minval) if self.s else val
self.s.append(MinStack.elem(val=val, minval=minval))
def pop(self) -> Non... | min-stack | Python3 solution | dalechoi | 1 | 75 | min stack | 155 | 0.519 | Medium | 2,469 |
https://leetcode.com/problems/min-stack/discuss/1501564/52-ms-faster-than-96.96-of-Python3-online-submissions-by-tuple-and-list | class MinStack:
def __init__(self):
self.stack = []
def push(self, val: int) -> None:
if not self.stack:
self.stack.append((val,val))
else:
self.stack.append((val, min(val, self.stack[-1][1])))
def pop(self) -> None:
self.stack.pop()... | min-stack | 52 ms, faster than 96.96% of Python3 online submissions by tuple and list | zixin123 | 1 | 219 | min stack | 155 | 0.519 | Medium | 2,470 |
https://leetcode.com/problems/min-stack/discuss/1233506/Python3-simple-solution-beats-96-users | class MinStack:
def __init__(self):
self.stack = []
def push(self, val: int) -> None:
if self.stack:
if val <= self.stack[-1][1]:
self.stack.append((val,val))
else:
self.stack.append((val,(self.stack[-1][1])))
else:
sel... | min-stack | Python3 simple solution beats 96% users | EklavyaJoshi | 1 | 150 | min stack | 155 | 0.519 | Medium | 2,471 |
https://leetcode.com/problems/min-stack/discuss/572752/Python3-stack | class MinStack:
def __init__(self):
self.stack = []
def push(self, val: int) -> None:
if self.stack: self.stack.append((val, min(val, self.stack[-1][1])))
else: self.stack.append((val, val))
def pop(self) -> None:
self.stack.pop()
def top(self) -> int:
return ... | min-stack | [Python3] stack | ye15 | 1 | 119 | min stack | 155 | 0.519 | Medium | 2,472 |
https://leetcode.com/problems/min-stack/discuss/572752/Python3-stack | class MinStack:
def __init__(self):
self.stack = []
self.min = inf
def push(self, x: int) -> None:
if x <= self.min:
self.stack.append(self.min)
self.min = x
self.stack.append(x)
def pop(self) -> None:
if self.stack.pop() ==... | min-stack | [Python3] stack | ye15 | 1 | 119 | min stack | 155 | 0.519 | Medium | 2,473 |
https://leetcode.com/problems/min-stack/discuss/236242/Python3-52-ms-100-Deque | class MinStack:
def __init__(self):
self.dq = collections.deque([None])
def push(self, x: 'int') -> 'None':
if self.dq[0] == None or self.dq[0] >= x:
self.dq.appendleft(x)
self.dq.append(x)
def pop(self) -> 'None':
if self.dq[0] != None and self.dq[-1] <= self.... | min-stack | Python3, 52 ms, 100%, Deque | jimmyyentran | 1 | 183 | min stack | 155 | 0.519 | Medium | 2,474 |
https://leetcode.com/problems/min-stack/discuss/2819208/Python-Stack-Easy | class MinStack:
from collections import deque
def __init__(self):
self.stack = deque()
def push(self, val: int) -> None:
self.stack.appendleft(val)
def pop(self) -> None:
self.stack.popleft()
def top(self) -> int:
return self.stack[0]
def getMin(self) -> int:
return min(self.stack)
# Your Mi... | min-stack | Python Stack Easy | lucasschnee | 0 | 3 | min stack | 155 | 0.519 | Medium | 2,475 |
https://leetcode.com/problems/min-stack/discuss/2801248/Python-or-Stack-or-TC-O(1)-SC-O(n) | class MinStack:
def __init__(self):
self.stack = []
self.min_stack = []
def push(self, val: int) -> None:
self.stack.append(val)
val = self.min_stack[-1] if len(self.min_stack) > 0 and self.min_stack[-1] < val else val
self.min_stack.append(val)
def pop(self) -> No... | min-stack | Python | Stack | TC O(1), SC O(n) | baskvava | 0 | 1 | min stack | 155 | 0.519 | Medium | 2,476 |
https://leetcode.com/problems/min-stack/discuss/2800934/Python3-beats-99.9-using-one-stack-of-tuples-and-one-int | class MinStack:
def __init__(self):
self.stack = []
self.minimum = None
def push(self, val: int) -> None:
if self.stack:
self.stack.append((val, self.minimum))
self.minimum = min(self.minimum, val)
else:
self.stack.append((val, self.minimum)... | min-stack | Python3 beats 99.9% using one stack of tuples and one int | lucieperrotta | 0 | 2 | min stack | 155 | 0.519 | Medium | 2,477 |
https://leetcode.com/problems/min-stack/discuss/2786255/Best-Approach-using-one-stack.-Aditya-Verma-.O(1)-time-and-O(1)-extra-spaceorPython | class MinStack:
def __init__(self):
self.minval=float('inf')
self.stack=[]
def push(self, val: int) -> None:
if len(self.stack)==0:
self.minval=val
self.stack.append(val)
else:
if val >=self.minval:
self.stack.append(val)
... | min-stack | Best Approach using one stack. Aditya Verma .O(1) time and O(1) extra space|Python | abro_01 | 0 | 10 | min stack | 155 | 0.519 | Medium | 2,478 |
https://leetcode.com/problems/min-stack/discuss/2781893/Easy-Python-Solution-O(1)-time-every-function | class MinStack:
def __init__(self):
self.s=[]
self.minstack=[inf]
def push(self, val: int) -> None:
self.s.append(val)
if(self.minstack[-1]>val):
self.minstack.append(val)
else:
self.minstack.append(self.minstack[-1])
def pop(self) -> None:
... | min-stack | Easy Python Solution O(1) time every function | liontech_123 | 0 | 2 | min stack | 155 | 0.519 | Medium | 2,479 |
https://leetcode.com/problems/min-stack/discuss/2763295/Python-or-Simple-list-solution | class MinStack:
def __init__(self):
self.st = []
self.min = 1e18
def push(self, val: int) -> None:
self.st.append((val, self.min))
if val < self.min:
self.min = val
def pop(self) -> None:
if self.min == self.st[-1][0]:
self.min = self.st[-1]... | min-stack | Python | Simple list solution | LordVader1 | 0 | 20 | min stack | 155 | 0.519 | Medium | 2,480 |
https://leetcode.com/problems/min-stack/discuss/2757598/Python3-83-faster-with-explanation | class MinStack:
def __init__(self):
self.array = []
self.minimum = 0
def push(self, val: int) -> None:
if len(self.array) == 0:
self.minimum = val
else:
self.minimum = min(self.minimum, val)
self.array.append(val)
... | min-stack | Python3 83% faster with explanation | cvelazquez322 | 0 | 5 | min stack | 155 | 0.519 | Medium | 2,481 |
https://leetcode.com/problems/min-stack/discuss/2753742/Python-two-stacks-solution | class MinStack:
def __init__(self):
self.stack = []
self.tracker = [float('inf')]
def push(self, val: int) -> None:
self.stack.append(val)
if self.tracker and val <= self.tracker[-1]:
self.tracker.append(val)
def pop(self) -> None:
if self.stack[-1] <= se... | min-stack | Python two stacks solution | leetcodesquad | 0 | 3 | min stack | 155 | 0.519 | Medium | 2,482 |
https://leetcode.com/problems/min-stack/discuss/2736835/Python-Solution-and-Pretty-Efficient | class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, val: int) -> None:
self.stack.append(val)
minimum = min(val,self.minStack[-1] if self.minStack else val)
self.minStack.append(minimum)
def pop(self) -> None:
self.stack.po... | min-stack | Python Solution and Pretty Efficient | abe40 | 0 | 9 | min stack | 155 | 0.519 | Medium | 2,483 |
https://leetcode.com/problems/min-stack/discuss/2729550/Python3-two-stack-implementation | class MinStack:
def __init__(self):
self. stack = []
self.min_stack = []
def push(self, val: int) -> None:
self.stack.append(val)
if self.min_stack == [] or self.min_stack[-1] > val:
self.min_stack.append(val)
else:
self.min_stack.append(self.min... | min-stack | Python3, two stack implementation | paul1202 | 0 | 3 | min stack | 155 | 0.519 | Medium | 2,484 |
https://leetcode.com/problems/min-stack/discuss/2665189/Min-Stack-with-python-Using-Single-stack-with-less-time(beats-98.10)-and-space(beats-95.94) | class MinStack:
def __init__(self):
self.stack = []
self.min_value = float('inf')
def push(self, val: int) -> None:
if val <= self.min_value:
self.stack.append(self.min_value)
self.min_value = val
self.stack.append(val)
def pop(self) -> No... | min-stack | Min-Stack with python - Using Single stack with less time(beats 98.10%) and space(beats 95.94%) | user2385PN | 0 | 7 | min stack | 155 | 0.519 | Medium | 2,485 |
https://leetcode.com/problems/min-stack/discuss/2652294/Faster-than-95.26 | class MinStack:
def __init__(self):
self.stack = []
self.minStack = []
def push(self, val: int) -> None:
self.stack.append(val)
val = min(val,self.minStack[-1] if self.minStack else val)
self.minStack.append(val)
def pop(self) -> None:
self.stack.po... | min-stack | Faster than 95.26% | jayeshvarma | 0 | 62 | min stack | 155 | 0.519 | Medium | 2,486 |
https://leetcode.com/problems/min-stack/discuss/2640979/python-solution | class MinStack:
def __init__(self):
self.stack = []
self.minn_s = []
def push(self, val: int) -> None:
self.stack.append(val)
if len(self.stack) == 1:
self.minn_s.append(val)
elif self.minn_s[-1] > val:
self.minn_s.append(val)
el... | min-stack | python solution | sarthakchawande14 | 0 | 4 | min stack | 155 | 0.519 | Medium | 2,487 |
https://leetcode.com/problems/min-stack/discuss/2617666/Python-Solution-or-60-ms-or-Faster-than-95.96-or-Using-List | class MinStack:
def __init__(self):
self.a = []
self.min_ = float("inf")
def push(self, val: int) -> None:
self.a.append(val)
if val<self.min_:
self.min_ = val
def pop(self) -> None:
x = self.a.pop()
if x==self.min_:
if len(self.... | min-stack | Python Solution | 60 ms | Faster than 95.96% | Using List | rorschach86 | 0 | 64 | min stack | 155 | 0.519 | Medium | 2,488 |
https://leetcode.com/problems/min-stack/discuss/2594848/python-easy-solution | class MinStack:
def __init__(self):
self.stack = []
self.minstack = []
def push(self, val: int) -> None:
self.stack.append(val)
newval = min(val,self.minstack[-1] if self.minstack else val)
self.minstack.append(newval)
def pop(self) -> None:
self.stack.pop(... | min-stack | python easy solution | al5861 | 0 | 42 | min stack | 155 | 0.519 | Medium | 2,489 |
https://leetcode.com/problems/min-stack/discuss/2531686/Python3-or-Optimal-Constant-Time-Solution | class MinStack:
def __init__(self):
self.main = deque()
self.min = deque()
def push(self, val: int) -> None:
self.main.append(val)
minval = min(val, self.min[-1] if self.min else val)
self.min.append(minval)
def pop(self) -> None:
self.min.pop()
sel... | min-stack | Python3 | Optimal Constant Time Solution | chawlashivansh | 0 | 77 | min stack | 155 | 0.519 | Medium | 2,490 |
https://leetcode.com/problems/min-stack/discuss/2504258/Simple-python-code-not-so-fast-though | class MinStack:
def __init__(self):
self.stack=[]
self.length=0
def push(self, val:int)->None:
self.length+=1
self.stack.append(val)
def pop(self)->None:
self.length-=1
self.stack.pop()
def top(self)->int:
return self.stack[-1]
... | min-stack | Simple python code, not so fast though | CarolChang | 0 | 35 | min stack | 155 | 0.519 | Medium | 2,491 |
https://leetcode.com/problems/min-stack/discuss/2485293/50-faster-than-other-Python-submission-optimized-for-interviews | class MinStack:
def __init__(self):
self.bucket = []
def push(self, val: int) -> None:
if len(self.bucket) == 0:
self.bucket.append((val, val))
else:
currMin = self.getMin() if self.getMin() < val else val
self.bucket.append((val, currMi... | min-stack | 50% faster than other Python submission optimized for interviews | sajidrsk | 0 | 25 | min stack | 155 | 0.519 | Medium | 2,492 |
https://leetcode.com/problems/min-stack/discuss/2474150/BRUTALLY-OPTIMISED-Python-Solution-Mind-Blown-5-liner | class MinStack(object):
def __init__(self):
self.stck = []
self.min = [float('inf')]
def push(self, val):
self.stck += [val]
if self.min[-1]>=val:
self.min += [val]
def pop(self):
pop = self.stck.pop()
if pop == self.min[-1]: self.min.pop()
... | min-stack | BRUTALLY OPTIMISED Python Solution, Mind == Blown 5 liner | Nj-0 | 0 | 62 | min stack | 155 | 0.519 | Medium | 2,493 |
https://leetcode.com/problems/min-stack/discuss/2474150/BRUTALLY-OPTIMISED-Python-Solution-Mind-Blown-5-liner | class MinStack(object):
__init__ = lambda self: setattr(self,'stck',[])
top = lambda self: self.stck[-1][0]
getMin = lambda self: self.stck[-1][1] if self.stck else float('inf')
push = lambda self, v: self.stck.append((v, min(self.getMin(),v)))
pop = lambda self: self.stck.pop()[0] | min-stack | BRUTALLY OPTIMISED Python Solution, Mind == Blown 5 liner | Nj-0 | 0 | 62 | min stack | 155 | 0.519 | Medium | 2,494 |
https://leetcode.com/problems/min-stack/discuss/2446557/Python3.-Two-stacks-solution | class MinStack:
def __init__(self):
# Init variables
self._stack = []
self._min_stack = []
def push(self, val: int) -> None: # O(1) time complexity
# Find new minimum value
new_min_value = val
if len(self._stack) > 0:
new_min_value = min(new_min_value, self._mi... | min-stack | Python3. Two stacks solution | NonameDeadinside | 0 | 19 | min stack | 155 | 0.519 | Medium | 2,495 |
https://leetcode.com/problems/min-stack/discuss/2420789/Noob-Nested-Py-Code | class MinStack:
def __init__(self):
self.minimum = float("inf")
self.nums = []
def push(self, val: int) -> None:
self.minimum = min(val,self.minimum)
self.nums.append(val)
def pop(self) -> None:
if self.nums:
if self.nums[-1] == self.minimum:
... | min-stack | Noob Nested Py Code | ms1241721_lc | 0 | 18 | min stack | 155 | 0.519 | Medium | 2,496 |
https://leetcode.com/problems/min-stack/discuss/2398745/Python3-solution-easy-solution-87-faster | class MinStack:
def __init__(self):
self.data = []
#O(1) time complexity
def push(self, val: int) -> None:
if not self.data:
self.data.append([val, val])
else:
self.data.append([val, min(self.data[-1][1], val)])
#O(1) time complexity
def pop(... | min-stack | Python3 solution, easy solution, 87% faster | matteogianferrari | 0 | 63 | min stack | 155 | 0.519 | Medium | 2,497 |
https://leetcode.com/problems/min-stack/discuss/2250743/Python3-or-Super-Easy-or-Two-Stacks | class MinStack:
def __init__(self):
self.stack = []
self.min = []
def push(self, val: int) -> None:
self.stack.append(val)
val = min(val, self.min[-1] if self.min else val)
self.min.append(val)
def pop(self) -> None:
self.stack.pop()
self.min.pop()
... | min-stack | ✅Python3 | Super Easy | Two Stacks | thesauravs | 0 | 13 | min stack | 155 | 0.519 | Medium | 2,498 |
https://leetcode.com/problems/min-stack/discuss/2189141/Python3-or-Using-2-stacks | class MinStack:
def __init__(self):
self.s=[]
self.mins=[]
def push(self, val: int):
self.s.append(val)
if len(self.mins)==0:
self.mins.append(val)
elif val<=self.mins[-1]:
self.mins.append(val)
def pop(self):
x=sel... | min-stack | Python3 | Using 2 stacks | sogarwal | 0 | 47 | min stack | 155 | 0.519 | Medium | 2,499 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.