704 Binary Search LeetCode (Google Interview Question) JavaScript

preview_player
Показать описание
704 Binary Search LeetCode (Google Interview Question) JavaScript

"Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
You must write an algorithm with O(log n) runtime complexity."

Final code:

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

Great explanation man !! keep up the good work :)

saankaalppp
Автор

Awesome! Very clear and easy explanation. I didn't get lost once lol.

tghhh
Автор

I get why you compare num[mid] to target, as they are both values in the array.
Maybe its only me but why do you compare mid to target, as mid is an index compared to target which is a variable.
Is it because we know its ordered, so we can guess the index to be related to the target?

staybalancedn
Автор

On line 13 it should be nums[mid], otherwise enjoyed your explanation. Thank you

the-s-tack
Автор

I actualy like how you give clear eplaination

KwetuAfricaTV
join shbcf.ru