标签:最长上升子序列 i++ color 个数 length int 组合 bsp 遇到
int lengthOfLIS(int* nums, int numsSize) { if(numsSize == 0) return 0; int dp[numsSize]; int p = -1; dp[++p] = nums[0]; for(int i=0; i<numsSize; i++) { if(nums[i] > dp[p]) { dp[++p] = nums[i]; } else //进行二分查找法 { int low = 0; //指向头部 int high = p; //指向尾部 int ptr = 0; while(low <= high) { int mid = (high+low)/2; //指向中间 if(nums[i] > dp[mid]) { ptr = mid; low = mid+1; } else if(nums[i] <= dp[mid]) { high = mid-1; } } if(dp[ptr] >= nums[i]) { dp[ptr] = nums[i]; } else { dp[ptr+1] = nums[i]; } } } return p+1; }
贪心+二分查找:最长上升子序列(3.14 leetcode每日打卡)
标签:最长上升子序列 i++ color 个数 length int 组合 bsp 遇到
原文地址:https://www.cnblogs.com/ZhengLijie/p/12493638.html