Search Insertion Position
- javascript
- arrays
Problem URL:Search Insertion Position
My Solution
JavaScript
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
const searchInsert = (nums, target) => {
let pos = nums.indexOf(target);
if (pos < 0) {
nums.push(target);
nums.sort((a, b) => a - b);
pos = nums.indexOf(target);
}
return pos;
};
Let's Connect
Twitter •GitHub •LinkedIn