问题描述 改变一个数字,判断一个序列的最大连续上升子序列长度
问题分析
遇到的问题!
在对对象进行假设性试验 操作时候!
不要!改变!原来的!数据结构!
实现思路
首先是判断一个序列的最大连续上升序列长度方法
public static int maxlength(int[] word) {
int len = 1;
int maxn = 1;
int[] temp1=new int[word.length];
for (int h=0;
h
【改变任意一个数,判断一个序列的最大连续上升子序列长度】然后利用该方法,对数组进行遍历,每次遍历修改一个数字,比后面一位数小,最后一位数修改为比它前一个数大,
然后对得出修改后的数组的连续上升字序列的最大长度。
import java.util.Scanner;
public class Main {public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] word = new int[num];
int max = 1;
for (int i = 0;
i < num;
i++)
word[i] = sc.nextInt();
for (int i = 0;
i < num ;
i++) {
if (i < num - 1) {
int[] temp=new int[word.length];
for (int h=0;
h
推荐阅读
- 数据结构与算法|【算法】力扣第 266场周赛
- leetcode|今天开始记录自己的力扣之路
- Python|Python 每日一练 二分查找 搜索旋转排序数组 详解
- 【LeetCode】28.实现strstr() (KMP超详细讲解,sunday解法等五种方法,java实现)
- LeetCode-35-搜索插入位置-C语言
- leetcode python28.实现strStr()35. 搜索插入位置
- Leetcode Permutation I & II
- python|leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法
- LeetCode 28 Implement strStr() (C,C++,Java,Python)
- Python|Python Leetcode(665.非递减数列)