题目1
题解1
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
for index, num in enumerate(nums):
if target <= num:
return index
return len(nums)
题目2
题解2
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
for i in range(0, len(haystack) - len(needle) + 1):
if haystack[i:i+len(needle)] == needle:
return i
return -1
题目3:
题解3
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
s = 0
for i in range(len(nums)):
if nums[i] != val:
nums[s] = nums[i]
s += 1
return s