这道题我真不知道它的难度为什么是中等,难道是我没理解透彻吗?
解答如下:
class Solution: def search(self, nums, target: int) -> int: if nums==[]: return -1 if len(nums)==1 and nums[0]==target: return 0 if target in nums: d=nums.index(target) #if nums[d-1]>target: return d else: return -1
执行用时 :48 ms, 在所有 Python3 提交中击败了93.74%的用户
内存消耗 :14 MB, 在所有 Python3 提交中击败了5.73%的用户
也不太明白为什么把第5第6行删了,运行时间就加长了,内存也多了:
执行用时 :56 ms, 在所有 Python3 提交中击败了80.91%的用户
内存消耗 :14.1 MB, 在所有 Python3 提交中击败了5.73%的用户
——2019.10.8