153. Find Minimum in Rotated Sorted Array | Javascript

preview_player
Показать описание
Detail explaination of problem 153. Find Minimum in Rotated Sorted Array in javascript. This is a leetCode question.
Рекомендации по теме
Комментарии
Автор

So this works: if (nums[M] > nums[R]) { L = M+1 } else { R = M }
But this doesn't: if (nums[M] > nums[L]) { L = M+1 } else { R = M }
Nor this: if (nums[M] < nums[L]) { R = M } else { L = M+1 }
It seems like the only way that works is the one in this video, comparing with the right side. Comparing with the left side doesn't seem to work. Anyone got an intuitive explanation why? Or how you think of using the right index instead of the left index?

hchiam
Автор

What was the space complexity for this one

jamesmeegan
Автор

Thank you very much for the helpful video. But I would have understood faster if you had spent more time explaining the logic behind this code => if (nums[mid] > nums[right]) left = mid + 1

leongrin