https://www.lanqiao.cn/problems/155/learning/
解法:暴力遍历
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
int n = scan.nextInt();
int[] array = new int [n];
for(int i = 0 ; i < n ; i++) {
array[i] = scan.nextInt();
}
int range = 0;
for(int j = 0 ; j < n ; j++) {
for(int k = j+1 ; k < n;k++) {
int sum = Math.abs( j - k) + Math.abs(array[j] - array[k]);
if(sum > range) {
range = sum;
}
}
}
System.out.println(range);
scan.close();
}
}
https://www.lanqiao.cn/problems/158/learning/
解法:暴力遍历
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
int n = scan.nextInt();
int[] array = new int[n];
for( int i = 0 ; i < n ; i++) {
array[i] = scan.nextInt();
}
int count = 1;
int max = 0;
for(int j = 0; j < n - 1 ; j++) {
if(array[j] < array[j+1]) {
count++;
}else {
count = 1;
}
if(max < count ) {
max = count;
}
}
System.out.println(max);
scan.close();
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有