LeetCode 33 | Search in Rotated Sorted Array | Algorithm Explained (Java)

preview_player
Показать описание
The description reads:
"Given an integer array nums sorted in ascending order, and an integer target.

Suppose that nums is rotated at some pivot unknown to you beforehand (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

You should search for target in nums and if you found return its index, otherwise return -1.



Example 1:

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Example 2:

Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1
Example 3:

Input: nums = [1], target = 0
Output: -1"

Рекомендации по теме
Комментарии
Автор

Just a heads up for when you are talking this through with an interviewer, when you initialized the while-loop, you mentioned we were basicaly iterating through all of the indecies. If that was the case it would be O(n) runtime, n being the length of the array.

sawmonabo
Автор

Great video! Btw, Java or python both round down. So 3/2 -> 1.

eugenekim