Skip to content

Commit

Permalink
Add fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Sep 21, 2024
1 parent 7e218a9 commit 7ac23d9
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ impl Solution {
let i = right_sums.partition_point(|&x| x < target);

if let Some(&right_sum) = right_sums.get(i) {
min_sum = u32::min(min_sum, ((left_sum + right_sum) * 2 - sum) as _);
let candidate = (left_sum + right_sum) * 2 - sum;

if candidate == 0 {
return 0;
}

min_sum = u32::min(min_sum, candidate as _);
}
}
}
Expand Down

0 comments on commit 7ac23d9

Please sign in to comment.