dp篇
一眼单调栈
之前写的python题解
佬解 单调栈+二分查找
我靠,大师我悟了
class Solution {
public int lengthOfLIS(int[] nums) {
if (nums.length<=1){
return 1;
}
List<Integer>stack=new ArrayList<>();
stack.add(nums[0]);
for(int i=1;i<nums.length;i++){
if(nums[i]>stack.get(stack.size()-1)){
stack.add(nums[i]);
}else if(nums[i]<stack.get(stack.size()-1)){
int left=0;
int right=stack.size()-1;
while(left<right){
int mid=(left+right)/2;
if(nums[i]<=stack.get(mid)){
right=mid;
}else{
left=mid+1;
}
}
stack.set(left,nums[i]);
}
}
return stack.size();
}
}
ps: