Find First And Last Position Of Element In Sorted Array - LeetCode 34 - JavaScript

preview_player
Показать описание


Step by step walk through of the solution to the popular Meta coding interview question, Find First And Last Position Of Element In Sorted Array.

LeetCode 34

JavaScript

0:00 Intro
0:47 Explanation
3:26 Code

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

Thanks a lot for sharing.
I like the fact that you don't wast the time and go immediately to the point

abdoooooooooo
Автор

Why is it that for the left bound while loop, in the second if block, its nums[mid] < target, and for the same if block in the right bound while loop, its nums[mid] <= target? one is strictly less than, while the other is less than / equal to

OnEwHoRiDesLinEs
Автор

function searchRange(nums: number[], target: number): number[] {
if (nums.length === 0) return [-1, -1]
const arr = []

for (let i = 0; i < nums.length; i++) {
if (nums[i] === target && arr.length === 0) {
arr.push(i)
}
if (nums[i] === target) {
arr[1] = i
}
}
if (arr.length === 1) {
arr.push(arr[0])
}
return arr.length === 0 ? [-1, -1] : arr

};

AkhilAravind