LeetCode算法入门- Search Insert Position -day19
生活随笔
收集整理的這篇文章主要介紹了
LeetCode算法入门- Search Insert Position -day19
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
LeetCode算法入門- Search Insert Position -day19
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:
Input: [1,3,5,6], 5
Output: 2
Example 2:
Input: [1,3,5,6], 2
Output: 1
Example 3:
Input: [1,3,5,6], 7
Output: 4
Example 4:
Input: [1,3,5,6], 0
Output: 0
題目分析
利用二分法來進行查找
Java實現
總結
以上是生活随笔為你收集整理的LeetCode算法入门- Search Insert Position -day19的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jackson高级操作————流式API
- 下一篇: 史上最容易理解的暴力递归和动态规划~~