子数组最大乘积

子数组最大乘积

http://www.nowcoder.com/questionTerminal/9c158345c867466293fc413cff570356

public  double maxProduct(double[] arr) {
    double count = 1 ;
    //假设最大值为arr[0]
    double resultMax = arr[0];
    for(int i = 0 ; i < arr.length ;i++){
        count = arr[i];
         // 每次先与arr[i]进行比较
        resultMax = Math.max(resultMax,count);
        for(int j = i+1 ; j < arr.length ; j++){
            if (arr[j] != 0){
                count *= arr[j];
                resultMax = Math.max(resultMax,count);
            }else {
             //连续 即如果存在一个数为0则最大的连续数字串肯定为0,所以不需要继续比较后续的值
                break;
            }
        }
    }
    return resultMax;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:55
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 11:16
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务