Skip to content

Commit 7d2b47c

Browse files
committed
longest increasing subsequence , Microsoft
1 parent a2040c0 commit 7d2b47c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Solution/Day-075.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int lengthOfLIS(vector<int>& nums) {
4+
const int array_size = static_cast<int>(nums.size());
5+
if(!array_size){
6+
return 0;
7+
}
8+
vector<int>dp(array_size , 1);
9+
for(int i=0; i<array_size; ++i){
10+
for(int j=0; j<i;++j){
11+
if(nums[i]>nums[j])
12+
dp[i] = max(dp[j]+1 , dp[i]);
13+
}
14+
}
15+
return *max_element(dp.begin() , dp.end());
16+
}
17+
};

0 commit comments

Comments
 (0)