File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
algorithms/cpp/longestIncreasingSubsequence Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 11// Source : https://leetcode.com/problems/longest-increasing-subsequence/
2- // Author : Calinescu Valentin
2+ // Author : Calinescu Valentin, Hao Chen
33// Date : 2015-11-06
44
55/* **************************************************************************************
2222 *
2323 ***************************************************************************************/
2424
25+
26+
27+ // O(n^2) - dynamic programming
28+ class Solution {
29+ public:
30+ int lengthOfLIS (vector<int >& nums) {
31+
32+ int len = nums.size ();
33+ int maxLen = 0 ;
34+ vector<int > dp (len, 1 );
35+
36+ for (int i=0 ; i<len; i++) {
37+ for (int j=0 ; j<i; j++) {
38+ if ( nums[j] < nums[i] ) {
39+ dp[i] = max (dp[i], dp[j] + 1 );
40+ }
41+ }
42+ maxLen = max (maxLen, dp[i]);
43+ }
44+ return maxLen;
45+ }
46+ };
47+
48+
2549class Solution {
2650public:
2751
You can’t perform that action at this time.
0 commit comments