Skip to content

Commit 64f05e3

Browse files
committed
Time: 7 ms (82.99%), Space: 18.9 MB (91.53%) - LeetHub
1 parent a304ffa commit 64f05e3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# time complexity: O(n)
2+
# space complexity: O(n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def findErrorNums(self, nums: List[int]) -> List[int]:
8+
length = len(nums)
9+
countArray = [0] * (length + 1)
10+
same, miss = 0, 0
11+
for num in nums:
12+
countArray[num] += 1
13+
14+
for i in range(1, len(countArray)):
15+
if countArray[i] == 2:
16+
same = i
17+
if countArray[i] == 0:
18+
miss = i
19+
20+
return [same, miss]
21+
22+
23+
nums = [1, 1]
24+
print(Solution().findErrorNums(nums))

0 commit comments

Comments
 (0)