LeetCode第九天

35.Search Insert Position 

获取到输入值应该出现在的位置,比较简单,今天状态不太好,在换季,时冷时热有点热感冒。

class Solution:
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        num = 0
        if len(nums) == 0:
            return 0
        elif len(nums) == 1:
            return 0 if target<=nums[0] else 1
        else:
            for i in range(0, len(nums)):
                if target<=nums[i]:
                    return i
                else:
                    num +=1
            if num == len(nums):
                return num

 

posted @ 2018-03-07 22:16  Vancuicide  阅读(93)  评论(0)    收藏  举报