https://leetcode.com/problems/set-mismatch/description/?envType=daily-question&envId=2024-01-22
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
|
class Solution:
def findErrorNums(self, nums: List[int]) -> List[int]:
check = [0] * (len(nums) + 1)
answer = [0, 0]
for i in nums:
check[i] += 1
for i in range(1, len(check)):
if check[i] == 2:
answer[0] = i
elif check[i] == 0:
answer[1] = i
return answer
|
cs |
처음에는.. 각 인덱스가 해당 숫자의 위치에 없는 경우로 착각해서 정렬해서 풀었는데
그게 아니라 문제가
중복되서 나온 숫자, 그리고 안나온 숫자 이렇게 return 하라는 문제여서 순차탐색에서 쉽게 풂
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 3014. Minimum Number of Pushes to Type Word I (1) | 2024.01.23 |
---|---|
leetcode 3010. Divide an Array Into Subarrays With Minimum Cost I (0) | 2024.01.23 |
leetcode 1207. Unique Number of Occurrences (0) | 2024.01.17 |
leetcode 2913. Subarrays Distinct Element Sum of Squares I (0) | 2024.01.15 |
leetcode 3005. Count Elements With Maximum Frequency (0) | 2024.01.15 |
댓글