35. Search Insert Position
題目原文
Given a sorted array 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.
You may assume no duplicates in the array.
Example 1:
Example 2:
Example 3:
Example 4:
解題思路
比較target是否小於等於nums[i],是的話就是那個位置。
要注意的是宣告i的scope。
程式解答
Last updated
Was this helpful?