国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

300. Longest Increasing Subsequence

2019-11-06 08:20:24
字體:
來源:轉載
供稿:網友

Given an unsorted array of integers, find the length of longest increasing subsequence.

For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for you to return the length.

Your algorithm should run in O(n2) complexity.

Follow up: Could you imPRove it to O(n log n) time complexity? O(n2)算法

class Solution {public: int lengthOfLIS(vector<int>& nums) { int size = nums.size(), max = 1; if(size == 0) return 0; for(int i = 0; i < size - 1; ++i){ int pre = nums[i], len = 1, prePre = 0x7fffffff; for(int j = i + 1; j < size; ++j){ if(nums[j] > pre){ ++len; prePre = pre; pre = nums[j]; } else if(prePre < nums[j] && nums[j] < pre && nums[j] > nums[i]){ prePre = pre; pre = nums[j]; } } if(len > max) max = len; } return max; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 土默特右旗| 太仆寺旗| 涿州市| 岳普湖县| 寻乌县| 镇赉县| 吉隆县| 玉门市| 福贡县| 安福县| 华安县| 新野县| 巴中市| 金阳县| 巧家县| 临湘市| 进贤县| 姜堰市| 台中县| 大竹县| 华安县| 井陉县| 瑞丽市| 崇明县| 咸阳市| 安吉县| 广昌县| 武胜县| 寻乌县| 蚌埠市| 南汇区| 黑河市| 新田县| 巫山县| 晴隆县| 蕲春县| 博客| 平原县| 石柱| 扶绥县| 津南区|