For the guys who still confused about why the following codes both work:if (i > 0 && nums[i] == nums[i - 1] && used[i - 1] != 1) continue; if (i > 0 && nums[i] == nums[i - 1] && used[i - 1] == 1) continue;
Here I used int used to indicate whether the number in int nums is used (1 for used).First method will count the consecutive identical numbers when they appear at first time, 'continue' will only be executed once when previous identical number is used (from left to right, then count it). Second method is completely opposite, 'continue' will be executed once when previous identical number is not used (from right to left, then count it).
So we can see that the procedures of skipping consecutive identical numbers are different, while the key point of both methods is same: count the consecutive identical sequence only once, following a certain rule.
Now we can explain why the first way is more efficient: when we scan the nums from left to right, the consecutive identical sequence will be counted at the first time.