Skip to content

Commit 1af9993

Browse files
committed
Added Python solution for "Set Mismatch"
1 parent c413acd commit 1af9993

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Python/Set Mismatch.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
Time: O(n)
7+
Memory: O(1)
8+
"""
9+
10+
def findErrorNums(self, nums: List[int]) -> List[int]:
11+
duplicate = -1
12+
missing = 1
13+
14+
for n in nums:
15+
if nums[abs(n) - 1] < 0:
16+
duplicate = abs(n)
17+
else:
18+
nums[abs(n) - 1] *= -1
19+
20+
for i in range(1, len(nums)):
21+
if nums[i] > 0:
22+
missing = i + 1
23+
24+
return [duplicate, missing]
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)