Wednesday, February 3, 2016

Max of Array

Max of Array

Given an array with couple of float numbers. Return the max value of them..


Example
Given [1.0, 2.1, -3.3], return 2.1.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class Solution {
    /**
     * @param A a float array
     * @return a float number
     */
    public float maxOfArray(float[] A) {
        // Write your code here
        float max = A[0];
        for(int i = 1; i < A.length; i++){
            if(A[i] > max) {
                max = A[i];
            }
        }
        return max;
    }
}