软件工程实验一

public class Solution {
/**
* @param A: a array of integers
* @return : return an integer
*/
public int removeDuplicates(int[] nums) {
// write your code here
int i,j;
int m=nums.length;
for(i=0;i<m-1;i++)
{
if(nums[i]==nums[i+1])
{
for(j=i;j<m-1;j++)
{
nums[j]=nums[j+1];
}
m--;
i--;
}
}

return m;
}
}

class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
int i;
int ly=0;
if(prices.size()<2)
{
return ly;
}
int zx=prices[0];

for(i=1;i<prices.size();i++)
{
if(prices[i]-zx<ly)
{
ly=ly;
}
else
{
ly=prices[i]-zx;
}
if(zx>prices[i])
{
zx=prices[i];
}
else
{
zx=zx;
}
}
return ly;
}

};

class Solution {
public:
/**
* @param n: An integer
* @return: An integer
*/
int climbStairs(int n) {
// write your code here

int i;

if(n<=1)
{
return 1;
}
int a[n+1];
a[0]=1;
a[1]=1;
for(i=2;i<n+1;i++)
{
a[i]=a[i-1]+a[i-2];

}

return a[n];
}
};

posted @ 2017-03-06 20:17  手心的温暖  阅读(100)  评论(0编辑  收藏  举报