LeetCode Search Insert Position

BabbleDay posted @ 2015年7月17日 16:53 in 刷题防身 with tags python java leetcode Search Insert Position , 1003 阅读

二分插入

def searchInsert(self, nums, target):
        l, r, i = 0, len(nums)-1, 0
        while l<r:
            i = (l+r)/2
            if nums[i]<target:
                if l==i:
                    i += 1
                l = i
            elif nums[i]>target:
                r = i
            else:
                return i
        if nums[i]<target:
            return i+1
        return i

 

关注插入点 Most Voted Solution

public int searchInsert(int[] A, int target) {
        int low = 0, high = A.length-1;
        while(low<=high){
            int mid = (low+high)/2;
            if(A[mid] == target) return mid;
            else if(A[mid] > target) high = mid-1;
            else low = mid+1;
        }
        return low;
    }
Avatar_small
For More Information 说:
2019年12月24日 21:30

The password should be a strong password for an email account. A strong password should have at least 10 characters long with a mixture of uppercase letters, lowercase letters, numbers, and punctuations. If the password has all the above-mentioned functions then your email account will be safe For More Information.

Avatar_small
deep cleaning servic 说:
2020年2月21日 22:33

As being the name usually means, deep cleaning up represents another a higher standard cleaning right up your office or home. Basic cleaning up includes general correct like wiping plus vacuuming your kitchen, bathroom, bedroom and living room area floors, and cleaning a cupboard entrances, tables, ergonomic chair, and the like, using waters or almost every other basic cleaning up products; having said that, deep cleaning concerns making time for the points and ridding yourself of hidden debris, dirt, plus small bothersome stains. It is actually a top so that you can bottom scrubbing of your abode, from ceilings so that you can floors, A example of deep cleaning up include cleaning up what’s regarding the tiles, behind the actual model, under a sink, from the oven, cleaning the surrounding corners…etc.

Avatar_small
cleaners in dubai 说:
2020年2月22日 18:16

Another thing it's best to check regarding before appointing a rug cleaning company is certainly they types of carpet maintenance equipment together with methods they will use when they are known for any a single type for service. You need to ask if he or she fully understand your specific types of rugs together with carpets when they will use the right technique for cleaning for what you may have. Another thing you'd like is in your Oriental rugs and carpets or Persian carpets to generally be ruined web-site needs to be company used unacceptable carpet maintenance process or simply chemicals.

Avatar_small
BSEB Question Paper 说:
2022年9月05日 23:14

Bihar Board Model Paper 2023 Class 4 Pdf Download with Answers for English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term1 & Term2 Exams at official website. BSEB Question Paper Class 4 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter