[LeetCode]Search Insert Position
生活随笔
收集整理的這篇文章主要介紹了
[LeetCode]Search Insert Position
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原題鏈接:http://oj.leetcode.com/problems/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.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0
題解:
水題。
1 class Solution { 2 public: 3 int searchInsert(int A[], int n, int target) { 4 for(int i=0; i<n; i++){ 5 if(target <= A[i]) 6 return i; 7 } 8 return n; 9 } 10 }; View Code轉載于:https://www.cnblogs.com/codershell/p/3600120.html
總結
以上是生活随笔為你收集整理的[LeetCode]Search Insert Position的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: APP测试点概述
- 下一篇: MyBatis 配制文件层次表