Skip to content

Commit f8a892d

Browse files
committed
Runtime: 694 ms (Top 46.21%) | Memory: 141.7 MB (Top 30.30%)
1 parent 079273f commit f8a892d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
// Runtime: 694 ms (Top 46.21%) | Memory: 141.7 MB (Top 30.30%)
12
class Solution {
23
public:
34
vector<int> recoverArray(int n, vector<int>& sums) {
4-
sort(sums.begin(), sums.end());
5-
6-
vector<int> ans;
5+
sort(sums.begin(), sums.end());
6+
7+
vector<int> ans;
78
while (n--) {
8-
int diff = sums[1] - sums[0];
9-
unordered_map<int, int> freq;
10-
vector<int> ss0, ss1;
11-
bool on = false;
12-
for (auto& x : sums)
9+
int diff = sums[1] - sums[0];
10+
unordered_map<int, int> freq;
11+
vector<int> ss0, ss1;
12+
bool on = false;
13+
for (auto& x : sums)
1314
if (!freq[x]) {
14-
ss0.push_back(x);
15-
freq[x+diff]++;
16-
if (x == 0) on = true;
15+
ss0.push_back(x);
16+
freq[x+diff]++;
17+
if (x == 0) on = true;
1718
} else {
18-
ss1.push_back(x);
19-
freq[x]--;
19+
ss1.push_back(x);
20+
freq[x]--;
2021
}
2122
if (on) {
22-
ans.push_back(diff);
23-
sums = ss0;
23+
ans.push_back(diff);
24+
sums = ss0;
2425
} else {
25-
ans.push_back(-diff);
26-
sums = ss1;
26+
ans.push_back(-diff);
27+
sums = ss1;
2728
}
2829
}
29-
return ans;
30+
return ans;
3031
}
31-
};
32+
};

0 commit comments

Comments
 (0)