728x90
48ms
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
ans = nums+[target]
ans.sort()
return ans.index(target)
target 의 index를 for loop으로 찾기 보다는
ans에 추가하고 sort한 뒤 index로 찾기
40ms: append로 넣었을때
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
nums.append(target)
nums.sort()
return nums.index(target)
728x90
'Leetcode' 카테고리의 다른 글
[LeetCode] Length of Last Word 파이썬 (rstrip, split) (0) | 2021.03.30 |
---|---|
[LeetCode] Maximum Subarray 파이썬 (dp, local max, global max) (0) | 2021.03.30 |
[LeetCode] Implement strStr() 파이썬 (exhaustive search, find, index string) (0) | 2021.03.29 |
[LeetCode] Remove Element 파이썬 (list remove) (0) | 2021.03.29 |
[LeetCode] Merge Two Sorted Lists 파이썬 (linked list) (0) | 2021.03.29 |
댓글