[Leetcode] 34. Find First and Last Position of Element in Sorted Array (JavaScript)
Source
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/solution/
Find First and Last Position of Element in Sorted Array - LeetCode
Can you solve this real interview question? Find First and Last Position of Element in Sorted Array - Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in t
leetcode.com
Code
const searchRange = (nums, target) => {
const start = nums.indexOf(target)
const end = nums.lastIndexOf(target)
return [start, end]
};
How to solve?
indexOf, lastIndexOf 함수를 사용한다.
'Problem solve' 카테고리의 다른 글
[Leetcode] 27. Remove Element (JavaScript) (0) | 2023.06.09 |
---|---|
[Leetcode] 26. Remove Duplicates from Sorted Array (0) | 2023.05.16 |
[Leetcode] 48. Rotate Image (Python) (0) | 2023.05.15 |
[Leetcode] 11. Container With Most Water (JavaScript) (0) | 2023.05.07 |
[Leetcode] 28. Find the Index of the First Occurrence in a String (JavaScript) (0) | 2023.05.06 |