第一次实验

 
class Solution {
public:
/**
* @param A: a list of integers
* @return : return an integer
*/
int removeDuplicates(vector<int> &nums) {
// write your code here
if(nums.empty())
{
return 0;
}
int n = nums.size(),j=0;
for(int i=1;i<n;++i)
{
if(nums[i] != nums[j])
{
nums[++j] = nums[i];
}
}
nums.newsize(j+1);
return j+1;
}
};
 
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
if(prices.empty())
return 0 ;
int max=0; /* 定义最大利润 */
int min prices[0];
for(int i=1;i<prices.size();i++ )
{
if(prices[i] < min)
min = prices[i];
int differ = prices[i] - min ;
if(differ > max)
max = differ;
}
return max;
}
};
 
class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
// write your code here
int one = 0;
int two = 1;
while(n>0)
{
two=one+two;
one=two-one;
n--;
}
return two;
}
};
posted @ 2017-03-08 21:48  598692456  阅读(179)  评论(0编辑  收藏  举报