python-algorithm
leetcode 645. Set Mismatch
무적김두칠
2024. 1. 22. 21:51
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 하라는 문제여서 순차탐색에서 쉽게 풂
반응형