当前位置:网站首页>leetcode 300. Longest increasing subsequence
leetcode 300. Longest increasing subsequence
2022-06-12 06:21:00 【Well, let me see】
300. The longest increasing subsequence 
Thought analysis :
Maintain an array v, In this array v[i] Indicates that the longest subsequence length is i+1 The minimum value of the last bit of the subsequence of , And constantly updated , If the current number num > v[i], be v[i + 1] = num
Boundary situation 1: If the current number is larger than the largest of the array , Then the length should be updated , To add
Boundary situation 2: If the current number is smaller than the smallest of the array , Then the length remains the same , Update minimum
AC Code :
int lengthOfLIS(vector<int>& nums) {
vector<int> q;
for(auto x:nums) {
// Boundary situation 1: If the current number is larger than the largest of the array , Then the length should be updated , To add
if(q.empty() || x > q.back())
q.push_back(x);
// Boundary situation 2: If the current number is smaller than the smallest of the array , Then the length remains the same , Update minimum
else if(x <= q[0]) q[0] = x;
else {
// Binary search update the maintained array
int l = 0, r = q.size() - 1;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(q[mid] < x) l = mid;
else r = mid - 1;
}
q[r + 1] = x;
}
}
return q.size();
}
边栏推荐
- Leetcode-1043. Separate arrays for maximum sum
- Nocturnal simulator ADB view log
- CONDA create use virtual environment
- Open the camera in unity3d and display the contents of the camera in the scene as texture2d
- Opencv_100问_第五章 (21-25)
- Leetcode-553. Optimal division
- English grammar_ Adverb_ With or without ly, the meaning is different
- dlib 人脸检测
- SQL注入原理即sqli-labs搭建,sql注入简单实战
- . Net core and Net framework comparison
猜你喜欢

Introduction to the method of diligently searching for the alliance procedure

Houdini terrain creation

Computer composition and design work06 —— 基于MIPS

BRDF of directx11 advanced tutorial PBR (2)

Houdini & UE4 programmed generation of mountains and multi vegetation scattering points

Multithreading (2) -- pipeline (4) -- Park and unpark

sqlite交叉編譯動態庫

Logistic regression model

How do I get the date and time from the Internet- How to get DateTime from the internet?

(UE4 4.27) customize primitivecomponent
随机推荐
Bulk Rename Utility
JS预解析
Houdini terrain creation
Redis data type (VII) -- hyperloglog
Unity custom translucent surface material shader
468. verifying the IP address
The first principle of thinking method
First note
English语法_副词_有无ly,意义不同
基于报错的 SQL 注入
Information content security experiment of Harbin Institute of Technology
SQL注入——联合查询union
摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
Idea common configuration
AI operation ch8
Leetcode-646. Longest number pair chain
Computer composition and design work06 —— 基于MIPS
English grammar_ Adverb_ With or without ly, the meaning is different
C # converts the hexadecimal code form of text to text (ASCII)
Leetcode-1552. Magnetic force between two balls