Skip to content

Commit ea10dc8

Browse files
committed
Time: 2 ms (100%), Space: 17.9 MB (100%) - LeetHub
1 parent acd546c commit ea10dc8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# time complexity: O(n)
2+
# space complexity: O(n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def findMissingElements(self, nums: List[int]) -> List[int]:
8+
minNum = min(nums)
9+
maxNum = max(nums)
10+
numSet = set(nums)
11+
result = []
12+
for num in range(minNum, maxNum + 1):
13+
if num not in numSet:
14+
result.append(num)
15+
return result
16+
17+
18+
nums = [1, 4, 2, 5]
19+
print(Solution().findMissingElements(nums))
20+
nums = [7, 8, 6, 9]
21+
print(Solution().findMissingElements(nums))
22+
nums = [5, 1]
23+
print(Solution().findMissingElements(nums))

0 commit comments

Comments
 (0)