Skip to content

Commit 0475166

Browse files
committed
035
1 parent 2669095 commit 0475166

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

035/main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} target
4+
* @return {number}
5+
*/
6+
var searchInsert = function (nums, target) {
7+
let ans = nums.length
8+
nums.some((item, i) => {
9+
if (item >= target) {
10+
ans = i
11+
return true
12+
}
13+
})
14+
return ans
15+
}
16+
17+
if (process.env.LZS) { // local test
18+
const assert = require('assert')
19+
assert(searchInsert([1, 3, 5, 6], 5) === 2)
20+
assert(searchInsert([1, 3, 5, 6], 2) === 1)
21+
assert(searchInsert([1, 3, 5, 6], 7) === 4)
22+
assert(searchInsert([1, 3, 5, 6], 0) === 0)
23+
}

0 commit comments

Comments
 (0)