674. Longest Continuous Increasing Subsequence@python
Given an unsorted array of integers, find the length of longest continuous
increasing subsequence (subarray).
Example 1:
- Input: [1,3,5,4,7]
- Output: 3
- Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
- Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
题目地址: Longest Continuous Increasing Subsequence
难度: Easy
题意: 找出呈递增的趋势的子数组,返回最大长度
思路:
遍历数组,并计数,比较简单
- class Solution(object):
def findLengthOfLCIS(self, nums):- """
- :type nums: List[int]
- :rtype: int
- """
- n = len(nums)
- if n <= 1:
- return len(nums)
- res = 0
- length = 1
- for i in range(n-1):
- if nums[i] < nums[i+1]:
- length += 1
- else:
- res = max(length, res)
- length = 1
- res = max(length, res)
- return res
时间复杂度: O(n)
空间复杂度: O(1)
674. Longest Continuous Increasing Subsequence@python的更多相关文章
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- 【Leetcode_easy】674. Longest Continuous Increasing Subsequence
problem 674. Longest Continuous Increasing Subsequence solution class Solution { public: int findLen ...
- [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...
- 【LeetCode】674. Longest Continuous Increasing Subsequence 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 空间压缩DP 日期 题目地址:https: ...
- [LeetCode] 674. Longest Continuous Increasing Subsequence 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- [Leetcode]674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- 674. Longest Continuous Increasing Subsequence最长连续递增子数组
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...
- LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
随机推荐
- sublime text 插件的删除方法
1.ctr+shift+P,输入Package Control: Remove Package 2.回车, 3.出现一个弹出框,输入你要删除的package 4.回车,OK!!!
- AOP 应用
AOP 的核心:解耦 1. 权限认证2. 事务3. 日志4. Lazy loading 懒加载5. Context Process 上下文处理6. Error Handler 错误追踪(异常捕获)7. ...
- flask_context
定义全局的钩子函数 有的时候在处理请求之前和之后,执行某些特定的代码是很有用的,这就用到了请求钩子 例如在请求之前创建数据库连接或者redis连接:或者是系统里面用户请求处理之前先验证用户的身份,是否 ...
- ZROI #364. 【2018普转提day18专题】嘤嘤嘤
ZROI #364. [2018普转提day18专题]嘤嘤嘤 直接贴代码 具体见注释 #include<stdio.h> #include<cstring> #include& ...
- NOI2012 D2T1扩展欧几里得
#include <bits/stdc++.h> using namespace std; #define ll long long ll extgcd(ll a,ll b,ll & ...
- Bear and Tower of Cubes Codeforces - 680D
https://codeforces.com/contest/680/problem/D 一道2D,又是搞两个小时才搞出来...不过好在搞出来了 官方题解:可以证明对于m,设a是满足a^3<=m ...
- Springboot日志配置探索(主要看logback)(二)
这篇博客主要是讲在Springboot中扩展的日志框架的配置,也是主要讲logback 8 继续看文档,这里讲到: springboot里面还有几个日志系统框架可以选择使用,你可以通过在classpa ...
- 二叉查找树之AVL树
定义平衡树节点: class TreeNode { /** * 树节点的值 */ private int val; /** * 树的高度 */ private int height; /** * 左子 ...
- 安装drupal对服务器环境的要求
Drupal 8 Apache 2.x PHP 5.5.9 及以上版本 MySQL 5.5.3 及以上版本 Drupal 7 Apache 2.x PHP 5.2.5 及以上版本(推荐 PHP 5.4 ...
- IO多路复用机制(转)
1.简介 希望通过这篇文章,可以回答以下几个问题? 为什么需要IO多路复用? 什么是IO多路复用机制? IO多路复用的机制该怎么使用? epoll比select/poll相比,优势在哪里? 在了解I/ ...