-----------爬楼梯-------------
class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
//
{
if(n<=0)
{
return 0;
}
else if(n==1)
{
return 1;
}
else if(n==2)
{
return 2;
}
else
{
return climbStairs(n-1)+climbStairs(n-2);
}
}
return climbStairs(n);
}
}
----------删除有序数组重复元素------------
class Solution {
public:
/**
* @param A: a list of integers
* @return : return an integer
*/
int removeDuplicates(vector<int> &nums) {
// write your code here
int end= 1;
int l= nums.size();
if(l==0)
{
return 0;
}
else
if(l == 1)
{
return 1;
}
else{
for(int i=1;i<l;i++)
{
if(nums[i]!=nums[end-1])
{
nums[end++] = nums[i];
}
}
return end;
}
}
};
--------------买卖股票最佳时期--------------
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
int re=0;
if(prices.size()<2)
return re;
int lowest = prices[0];
for(int i=1;i<prices.size();i++)
{
int cur = prices[i];
re = max(re,cur-lowest);
lowest = min(lowest,cur);
}
return re;
}
};