Day 55: find the first and last position of an element in a sorted array
Address: leetcode-cn.com/problems/fi…
IndexOf and lastIndexOf
var searchRange = function(nums, target) {
return nums.indexOf(target) !== -1 ? [nums.indexOf(target), nums.lastIndexOf(target)] : [-1, -1];
};
Copy the code
Execution time: 72 ms, beating 98.02% of all JavaScript commits
Memory consumption: 38.9 MB, beating 61.46% of all JavaScript commits