Lintcode214-Max of Array-Naive
生活随笔
收集整理的這篇文章主要介紹了
Lintcode214-Max of Array-Naive
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Given an array with couple of float numbers. Return the max value of them.
Example
Example 1:
Input: [1.0, 2.1, -3.3] Output: 2.1 Explanation: return the Max one.Example 2:
Input: [1.0, 1.0, -3.3] Output: 1.0 Explanation: return the Max one.注意:
maxNum要定義在for循環(huán)外面,否則return的時候找不到變量。定義在for循環(huán)內(nèi)的變量,for循環(huán)外面無法訪問。
表示Float的范圍下限:? float maxNum = -Float.MAX_VALUE;?而Float.MIN_VALUE == 2-149 表示float精度的最小值, 是個正數(shù)。https://docs.oracle.com/javase/6/docs/api/java/lang/Float.html#MIN_VALUE
代碼:
public float maxOfArray(float[] A) {float maxNum = -Float.MAX_VALUE;for (int i = 0; i < A.length; i++){maxNum = Math.max(maxNum, A[i]);}return maxNum;}?
?轉(zhuǎn)載于:https://www.cnblogs.com/Jessiezyr/p/10635596.html
總結(jié)
以上是生活随笔為你收集整理的Lintcode214-Max of Array-Naive的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssm框架搭建和整合流程
- 下一篇: 【Windows10】我的电脑从新装到优