Skip to content

Instantly share code, notes, and snippets.

@cylcrow
Last active March 31, 2021 18:18
Show Gist options
  • Select an option

  • Save cylcrow/94c12f9110e780cc558354b36b91f919 to your computer and use it in GitHub Desktop.

Select an option

Save cylcrow/94c12f9110e780cc558354b36b91f919 to your computer and use it in GitHub Desktop.
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var searchRange = function(nums, target) {
let result = [-1,-1];
nums.forEach((e,i) => {
if(e <= target){
if(e === target){
if(result[0] === -1){
result[0] = i;
result[1] = i;
} else {
result[1] = i;
}
}
} else {
return result;
}
});
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment