Skip to content

Commit d045120

Browse files
committed
Runtime: 4011 ms (Top 18.39%) | Memory: 19.7 MB (Top 40.23%)
1 parent 9576873 commit d045120

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
# Runtime: 4011 ms (Top 18.39%) | Memory: 19.7 MB (Top 40.23%)
12
class Solution:
23
def recoverArray(self, n: int, sums: List[int]) -> List[int]:
3-
res = [] # Result set
4+
res = [] # Result set
45
sums.sort()
5-
6+
67
while len(sums) > 1:
78
num = sums[-1] - sums[-2] # max - secondMax
89
countMap = Counter(sums) # Get count of each elements
910
excluding = [] # Subset sums that do NOT contain num
1011
including = [] # Subset sums that contain num
11-
12+
1213
for x in sums:
1314
if countMap.get(x) > 0:
1415
excluding.append(x)
1516
including.append(x+num)
1617
countMap[x] -= 1
1718
countMap[x+num] -= 1
18-
19-
# Check validity of excluding set
19+
20+
# Check validity of excluding set
2021
if 0 in excluding:
2122
sums = excluding
2223
res.append(num)
2324
else:
2425
sums = including
2526
res.append(-1*num)
26-
27-
return res
27+
28+
return res

0 commit comments

Comments
 (0)