当前位置:网站首页>[数组]NC95 数组中的最长连续子序列-较难
[数组]NC95 数组中的最长连续子序列-较难
2022-07-23 23:19:00 【51CTO】
描述
给定无序数组arr,返回其中最长的连续序列的长度(要求值连续,位置可以不连续,例如 3,4,5,6为连续的自然数)
数据范围: ,数组中的值满足
要求:空间复杂度 ,时间复杂度
示例1
输入:
返回值:
示例2
输入:
返回值:
题解
排序+统计
思路:
先将数组排序,然后统计连续的数字。注意,如果连续的2个数字相等,此时不应该重置连续长度。
和该解法类似的还有使用set存放所有元素然后进行统计,或者使用hash表统计~~
代码如下:
并查集
边栏推荐
- 2、 Digital logic functional unit
- What are the three-party payment companies?
- Contemporary inspirational "women"
- DHCP: prevent rogue DHCP server in the network
- STM32F4查看系统各部分频率
- strncat() strncmp()
- Can Intel NUC replace the host_ It's finally perfect! The latest Intel NUC Mini host comes online
- Smart IOT source code with configuration IOT source code industrial IOT source code: support sensor analysis services, real-time data collection and remote control
- This article will show you what typescript is
- Tap series article 7 | easy to manage pipeline configuration
猜你喜欢

The ultimate experiment of OSPF -- learn the example of OSPF century template

Tap series article 4 | backstage based tap developer portal

2、 Digital logic functional unit

疑似未系安全带 林志颖伤势相对稳定

YOLOv4: Optimal Speed and Accuracy of Object Detection

strncat() strncmp()

Mongodb - Introduction to the use of $exists and the combination of $ne, $nin, $nor, $not in query statements

TAP 系列文章9 | 应用开发加速器

Leetcode: palindrome number

fl studio 20.9更新中文版宿主DAW数字音频工作站
随机推荐
[C language] address book (static version)
Build your own target detection environment, model configuration, data configuration mmdetection
Tensorflow one layer neural network training handwritten digit recognition
dried food! Implicit sparse regularization effect in neural networks
D1-H 开发板——哪吒 开发入门
Programming in the novel [serial 18] the moon bends in the yuan universe
Preparation for raspberry pie 3B serial port login
TAP 系列文章7 | 易于管理的流水线配置
TAP 系列文章8 | TAP 学习中心——通过动手教程来学习
Tap series article 4 | backstage based tap developer portal
Analytic hierarchy process (matlab)
121. The best time to buy and sell stocks
Diabetes genetic risk testing challenge baseline
Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?
[leetcode ladder] linked list · 203 remove linked list elements
汇编语言伪指令详解(附实例)
Smart IOT source code with configuration IOT source code industrial IOT source code: support sensor analysis services, real-time data collection and remote control
DHCP: prevent rogue DHCP server in the network
接口测试
[laser principle and Application-8]: EMC design of laser circuit