You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The test cases didn't consider the edge case as below.
The code I submitted can be accepted, but the algorithm cannot handle every edge case.
For example:
nums = [3, 5, 6, 0, 1, 2]
target = 5
The algorithm couldn't handle it, however, NeetCode accepted the code.
class Solution:
def search(self, nums: List[int], target: int) -> int:
l, r = 0, len(nums) - 1
result = -1
while l <= r:
if nums[l] == target:
result = l
elif nums[r] == target:
result = r
m = l + ((r - l) // 2)
if nums[m] > target:
if nums[r] > nums[m]:
r = m - 1
else:
l = m + 1
elif nums[m] < target:
if nums[l] < nums[m]:
l = m + 1
else:
r = m - 1
else:
result = m
break
return result
The text was updated successfully, but these errors were encountered:
Bug Report for https://neetcode.io/problems/find-target-in-rotated-sorted-array
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The test cases didn't consider the edge case as below.
The code I submitted can be accepted, but the algorithm cannot handle every edge case.
For example:
nums = [3, 5, 6, 0, 1, 2]
target = 5
The algorithm couldn't handle it, however, NeetCode accepted the code.
class Solution:
def search(self, nums: List[int], target: int) -> int:
l, r = 0, len(nums) - 1
result = -1
The text was updated successfully, but these errors were encountered: