File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed
Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -215,4 +215,45 @@ public int lengthOfLIS(int[] nums) {
215215<img src =" ../pictures/qrcode.jpg " width =200 >
216216</p >
217217
218- ======其他语言代码======
218+ ======其他语言代码======
219+
220+ [ Kian] ( https://github.com/KianKw/ ) 提供 C++ 代码
221+
222+ ``` c++
223+ class Solution {
224+ public:
225+ int lengthOfLIS(vector<int >& nums) {
226+ /* len 为牌的数量 * /
227+ int len = nums.size();
228+ vector<int > top(len, 0);
229+ /* 牌堆数初始化为0 * /
230+ int piles = 0;
231+ for (int i = 0; i < len; i++) {
232+ /* nums[ i] 为要处理的扑克牌 * /
233+ int poker = nums[ i] ;
234+
235+ /***** 搜索左侧边界的二分查找 *****/
236+ int left = 0, right = piles;
237+ while (left < right) {
238+ int mid = left + (right - left) / 2;
239+ if (top[mid] > poker) {
240+ right = mid;
241+ } else if (top[mid] < poker) {
242+ left = mid + 1;
243+ } else if (top[mid] == poker) {
244+ right = mid;
245+ }
246+ }
247+ /* ********************************/
248+
249+ /* 没找到合适的牌堆,新建一堆 */
250+ if (left == piles)
251+ piles++;
252+ /* 把这张牌放到牌堆顶 */
253+ top[left] = poker;
254+ }
255+ /* 牌堆数就是 LIS 长度 */
256+ return piles;
257+ }
258+ };
259+ ```
You can’t perform that action at this time.
0 commit comments