I\'m just practicing some MIT java assignments. But, I\'m not sure how to find the second largest number. http://ocw.csail.mit.edu/f/13
public class Marath
Instead of resorting to sorting the array, you can simply do the following:
largestValue
and a secondLargestValue
largestValue
:
largestValue
to secondLargestValue
, then assign the current element to largestValue
(think of it as shifting everything down by 1)secondLargestValue
secondLargestValue
O(n) run time
O(1) space requirement