Ad
  • Custom User Avatar

    Because arr[i] still needs to be counted - which would not happen when the If statement fails. This is especially important in this challenge where the value you want to return may only appear once.

    Since the array is sorted first, incrementing num in the else statement is the equivalent of saying "This is the last time this number appears in the array, let's see if it showed up an odd number of times."