Skip to content

Commit 8492b02

Browse files
perf: a little tricky $15.3-sum (azl397985856#316)
* Update 15.3-sum a trick to improve performence * fix: code style Co-authored-by: lucifer <azl397985856@gmail.com>
1 parent 45e683e commit 8492b02

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

problems/15.3-sum.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ var threeSum = function(nums) {
8989
const list = [];
9090
nums.sort((a, b) => a - b);
9191
for (let i = 0; i < nums.length; i++) {
92+
//nums is sorted,so it's impossible to have a sum = 0
93+
if (nums[i] > 0) break;
9294
// skip duplicated result without set
9395
if (i > 0 && nums[i] === nums[i - 1]) continue;
9496
let left = i;

0 commit comments

Comments
 (0)