题
- 1、最大距离
- 2、最长递增
1、最大距离
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();}
}
2、最长递增
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();}
}