File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 1
- // Time: O(n^2 * 2^(n/2))
1
+ // Time: O(n * 2^(n/2))
2
2
// Space: O(2^(n/2))
3
3
4
4
class Solution {
@@ -31,12 +31,12 @@ class Solution {
31
31
vector<int > sorted_sums1 (cbegin (sums1), cend (sums1)); // Space: O(2^(n/2))
32
32
sort (begin (sorted_sums1), end (sorted_sums1)); // Time: O((n/2) * 2^(n/2)) = O(n * 2^(n/2))
33
33
unordered_set<int > sums2{0 };
34
- for (int i = size (nums) / 2 ; i < size (nums); ++i) { // O(n/2) times
35
- for (const auto & x : vector<int >(cbegin (sums2), cend (sums2))) { // O(2^(n/2)) times
34
+ for (int i = size (nums) / 2 ; i < size (nums); ++i) {
35
+ for (const auto & x : vector<int >(cbegin (sums2), cend (sums2))) {
36
36
if (!sums2.emplace (x + nums[i]).second ) {
37
37
continue ;
38
38
}
39
- auto cit = lower_bound (cbegin (sorted_sums1), cend (sorted_sums1), goal - x - nums[i]); // Time: O(n/2)
39
+ auto cit = lower_bound (cbegin (sorted_sums1), cend (sorted_sums1), goal - x - nums[i]); // Time: O(2^(n/2)) * O( n/2)
40
40
if (cit != cend (sorted_sums1)) {
41
41
result = min (result, abs (goal - x - nums[i] - *cit));
42
42
}
You can’t perform that action at this time.
0 commit comments