每日一练——鬼画符门之宗门大比题解

题目描述

给定整数序列A。 求在整数序列A中连续权值最大的子序列的权值。

输入描述:

第一行输入整数n.(1<=n<=1000) 第二行输入n整数a。(-1000<=a<=1000) 

输出描述:

输出子序列最大权值。 

 代码实现:

import java.util.ArrayList;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str_0 = scan.nextLine().trim();
		int n = Integer.parseInt(str_0);

        

        
        String str_1 = scan.nextLine();
        String[] line_list_1 = str_1.trim().split(" ");        
        ArrayList<Integer> arr = new ArrayList<>();
        for(int i = 0; i < line_list_1.length; i++){
            arr.add(Integer.parseInt(line_list_1[i]));
        }
    

        scan.close();

        int result = solution(n, arr);

        System.out.println(result);

    }

    public static int solution(int n, ArrayList<Integer> arr){
       int result = 0;
        
        for(int i=0;i<n;i++){
            if(arr.get(i)<=0){
                continue;
            }
            int tmp=0;
            for(int j=i;j<n;j++){
                tmp+=arr.get(j);
                result=Math.max(tmp,result);
            }
            
        }
        return result;
       
    }
}

 长时间观察CSDN每日一练,发现在很多情况,简单题比困难题更难。也不知道是官方故意这么做的,从而来激发博客们敢于做难题的信心,还是别的。。。,不管官方怎么去思考,我还是希望官方能够重新认真调整题目的难易标签,(更方便)使博客们根据自身情况能够找到适合自己的题目。

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Luck&Strive

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值