I was asked in an interview. In the normal method, we initialized the res to the zero. But what if there is no single number exists in the array? How to know the final result is 0 or no single number?
There's no way to know the difference, if you're returning an int in all cases. If you return an Integer, you could return null in the case where no single number exists. Or you could throw an Exception if the function expects a single number to be there.
@wwtwxlwjh Easy, if the array has odd length then it's a single zero and if has even length then there's no single number.