LeetCode 35 搜索插入位置

Posted Starzkg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 35 搜索插入位置相关的知识,希望对你有一定的参考价值。

https://leetcode-cn.com/problems/search-insert-position/

解决方案

class Solution 
    public int searchInsert(int[] nums, int target) 
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) 
            int mid = (left + right) / 2;
            if (nums[mid] >= target) 
                right = mid - 1;
             else 
                left = mid + 1;
            
        
        return left;
    

以上是关于LeetCode 35 搜索插入位置的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 35. 搜索插入位置

leetcode-35.搜索插入位置

leetcode 35. 搜索插入位置

LeetCode 35 搜索插入位置

LeetCode 35 搜索插入位置

leetcode35.搜索插入位置(遍历并进行大小判断)