题目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: # 将needle作为一个整体,只需遍历 len(haystack) - len(needle)次 for i in range(0, len(haystack) - len(needle) + 1): # 将needle的长度作为的切片长度 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