当前位置:网站首页>2022.05.24(LC_674_最长连续递增序列)
2022.05.24(LC_674_最长连续递增序列)
2022-06-10 18:16:00 【Leeli9316】

方法一:枚举
class Solution {
public int findLengthOfLCIS(int[] nums) {
int n = nums.length;
int ans = 0;
for (int i = 0; i < n; i++) {
int pre = nums[i];
int count = 1;
for (int j = i + 1; j < n; j++) {
if (nums[j] <= pre) break;
count++;
pre = nums[j];
}
ans = Math.max(ans, count);
}
return ans;
}
}方法二:动态规划
class Solution {
public int findLengthOfLCIS(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
Arrays.fill(dp, 1);
int ans = 1;
for (int i = 1; i < n; i++) {
if (nums[i] > nums[i - 1]) {
dp[i] = dp[i - 1] + 1;
}
ans = Math.max(ans, dp[i]);
}
return ans;
}
}方法三:贪心
class Solution {
public int findLengthOfLCIS(int[] nums) {
int ans = 1;
int count = 1;
for (int i = 1; i < nums.length; i++) {
if (nums[i] > nums[i - 1]) {
count++;
} else {
count = 1;
}
ans = Math.max(ans, count);
}
return ans;
}
}边栏推荐
- Detailed explanation of Lora module wireless transceiver communication technology
- Rewrite clear Bayesian formula with base ratio
- mysql8.0(新特性小结)
- Adobe Premiere foundation - tool use (selection tool, razor tool, and other common tools) (III)
- Adobe Premiere Foundation (track related) (V)
- How to play the Dragon Boat Festival "immersive cloud Tour"? That is to say, it helps "live broadcast +" new scene landing
- Db2 SQL PL的数组类型
- How to transform digital transformation? Which way?
- What is Bi? Talk about the definition and function of Bi
- Ibox system development core functions and some core source codes
猜你喜欢

Adobe Premiere Basic - tool use (select tools, rasoir tools, and other Common Tools) (III)

HelloWorld example of TestNG and how to run it from the command line

How can bi help enterprises reduce labor, time and management costs?

How to correctly understand the real-time nature of Bi?

How to set up salesmartly for Google Analytics tracking

AEC:回声产生原因及回声消除原理解析

The value of Bi in the enterprise: business analysis and development decision

基于JSP的医院预约挂号平台设计与开发.zip(论文+项目源码)

基于谱加权的波束方向图分析

How to play the Dragon Boat Festival "immersive cloud Tour"? That is to say, it helps "live broadcast +" new scene landing
随机推荐
C知识练习
Win32-子窗口-父窗口-窗口所有者
Nodejs basic architecture analysis parsing engine directory plug-in installation core module
《Single Image Haze Removal Using Dark Channel Prior》去雾代码实现分析
Adobe Premiere Foundation (track related) (V)
VMware horizon 82111 deployment series (XVI) blast bandwidth test
How to transform digital transformation? Which way?
[kuangbin]专题二十二 区间DP
The question of enterprise managers, where have we spent our money after so many years of informatization?
Design and implementation of online ordering system based on SSM Rar (project source code)
RK1126 新添加一个模块
Openssl1.1.1 compilation error can't locate win32/console pm in @INC
[kuangbin]专题十二 基础DP1
第6章 关系数据理论练习
Win32 child window parent window window owner
SQL function
Chapter II data type (I)
Request header field XXXX is not allowed by access control allow headers in preflight response
[kuangbin] topic 12 basic DP1
How can bi help enterprises reduce labor, time and management costs?