Given an array of integers, find the largest number in the array
- array.length >= 1
- Array is unsorted
- Array can contain duplicate numbers
Input: [2,1,9,4,10,3,7,5,6]
Output: 10
Explanation: 10 is the largest number in the given array of numbers
1. Maintain an int variable - max - to hold the largest number. Initialize to first element of array.
2. Traverse array from second element.
- compare element to max, if max is less than element - then set max to element
3. Return max
Time Complexity O(N)
Space Complexity O(1)