79691209

Date: 2025-07-05 17:34:54
Score: 2
Natty:
Report link

Since array have duplicate numbers, so we can only use each element once, we need to make sure we dont have repeated combination multiple times

candidate = [1, 1, 2], target = 3

Without skipping duplicate result could be

[1,2] (from first 1)

[1,2] (from second 1) ← duplicate!

We only want one [1,2].

so by sorting array duplicate numbers are next to each other, so it makes easier to skip them by using below condition

if (i > index && candidates[i] == candidates[i - 1]) continue;

Reasons:
  • Contains signature (1):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: M B