2 ms·
The simpler solution is to set currentMax = myArray[0] initially, which works regardless of the sign of the array elements (though it assumes that the array is
by schoen 9y ago
The simpler solution is to set currentMax = myArray[0] initially, which works regardless of the sign of the array elements (though it assumes that the array is non-empty).
- aarohmankad 9y agoThis is the correct answer. We can even account for the assumption with an empty check before the rest of the code. (If the array is empty, it doesn't have a max value.)