class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
if (nums.size() == 0)
return 0;
int * dp = new int[nums.size()];
for (int i = 0; i < nums.size(); i++)
{
dp[i] = 1;
}
for (int i = 1; i < nums.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
{
dp[i] = max(1+dp[j],dp[i]);
}
}
}
int max = -1;
for (int i = 0; i < nums.size(); i++)
{
if (max < dp[i])
{
max = dp[i];
}
}
return max;
}
};
public:
int lengthOfLIS(vector<int>& nums) {
if (nums.size() == 0)
return 0;
int * dp = new int[nums.size()];
for (int i = 0; i < nums.size(); i++)
{
dp[i] = 1;
}
for (int i = 1; i < nums.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
{
dp[i] = max(1+dp[j],dp[i]);
}
}
}
int max = -1;
for (int i = 0; i < nums.size(); i++)
{
if (max < dp[i])
{
max = dp[i];
}
}
return max;
}
};
评论
发表评论