Last active
March 31, 2021 18:18
-
-
Save cylcrow/94c12f9110e780cc558354b36b91f919 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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