当前位置:网站首页>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();
}
边栏推荐
- PDF. JS help file
- 夜神模拟器adb查看log
- How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]
- JS pre parsing
- SQL注入——联合查询union
- Summary of some problems in sensor bring up
- Computer composition and design work06 —— 基于MIPS
- Leetcode sword finger offer II 119 Longest continuous sequence
- Unity3d multi platform method for reading text files in streamingasset directory
- 关于 Sensor flicker/banding现象的解释
猜你喜欢

Guns framework multi data source configuration without modifying the configuration file

Why doesn't the database use binary tree, red black tree, B tree and hash table? Instead, a b+ tree is used

IBL of directx11 advanced tutorial PBR (3)

Summary of some problems in sensor bring up

Findasync and include LINQ statements - findasync and include LINQ statements

Bert use

Opencv_ 100 questions_ Chapter V (21-25)

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

Poisson disk sampling for procedural placement

Trunet: short videos generation from long videos via story preserving truncation (thesis translation)
随机推荐
Redis problem (I) -- cache penetration, breakdown, avalanche
OverFeat: Integrated Recognition, Localization and Detection using Convolutional Networks
. Net core - pass Net core will Net to cross platform
Cross compile libev
Opencv_100问_第五章 (21-25)
N-degree Bessel curve
Houdini & UE4 programmed generation of mountains and multi vegetation scattering points
cv2.fillPoly coco annotator segment坐标转化为mask图像
Android studio mobile development creates a new database and obtains picture and text data from the database to display on the listview list
Highlight detection with pairwise deep ranking for first person video summary (thesis translation)
Multithreading (2) -- pipeline (2) -- synchronized underlying monitor, lightweight, biased lock, lock inflation
CONDA create use virtual environment
Unity surface shader with template buffer
Understand Houdini's (heightfield) remap operation
LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格
UE4 4.27 modify the mobile forward pipeline to support cluster multi light source culling
Directx11 advanced tutorial cluster based deffered shading
Jetson TX2 machine brushing jetpack4.2 (self test successful version)
Leetcode-2048. Next larger numerical balance
(UE4 4.27) customize primitivecomponent