note that when num[i] == num[i + 1], skip the position i + 1