I wanted to count numbers inside of "target" and I could not write what I wanted.
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
i = count.target.index
return i
AI checked this code and answered like this.
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
try:
i = nums.index(target)
except ValueError:
nums.append(target)
nums.sort()
i = nums.index(target)
return i
I have to practice try except.
Top comments (0)