Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
//Go funcsearchInsert(nums []int, target int)int { for i := 0;i <len(nums);i++ { if nums[i] >= target { return i } } returnlen(nums) }
执行结果:
1 2 3 4 5 6 7
leetcode: Runtime: 4 ms, faster than 88.29% of Go online submissions for Search Insert Position. Memory Usage: 3.1 MB, less than 100.00% of Go online submissions for Search Insert Position.
leetcode-cn: 执行用时:4 ms, 在所有 Go 提交中击败了90.15%的用户 内存消耗:2.9 MB, 在所有 Go 提交中击败了100.00%的用户
leetcode-cn: 执行用时:4 ms, 在所有 Go 提交中击败了90.15%的用户 内存消耗:3 MB, 在所有 Go 提交中击败了56.60%的用户
leetcode: Runtime: 8 ms, faster than 8.78% of Go online submissions for Search Insert Position. Memory Usage: 3.3 MB, less than 6.08% of Go online submissions for Search Insert Position.
leetcode: Runtime: 4 ms, faster than 88.29% of Go online submissions for Search Insert Position. Memory Usage: 3.1 MB, less than 100.00% of Go online submissions for Search Insert Position.
leetcode-cn: 执行用时:4 ms, 在所有 Go 提交中击败了90.15%的用户 内存消耗:3 MB, 在所有 Go 提交中击败了56.60%的用户