实验1

删除数组重复元素
 1 class Solution {
 2 public:
 3     /**
 4      * @param prices: Given an integer array
 5      * @return: Maximum profit
 6      */
 7     int maxProfit(vector<int> &prices) {
 8         // write your code here
 9         int start = 0;  
10         if(prices.size()<2)  
11             return start;  
12             
13             
14         int lowest; 
15         lowest = prices[0];  
16         for(int i=1;i<prices.size();i++) 
17         
18         {  
19             int fall;
20             fall= prices[i];  
21             start = max(start,fall-lowest);  
22             lowest  = min(lowest,fall);  
23         }  
24         
25         return start;
26     }
27 };
 
  

 

买卖股票的最佳时机
 1 class Solution {
 2 public:
 3     /**
 4      * @param n: An integer
 5      * @return: An integer
 6      */
 7     int climbStairs(int n) {
 8         // write your code here
 9         int result = 1;
10         int first = 1;
11         int next = 1;
12         while (--n > 0)
13         {
14             result = first + next;
15             first = next;
16             next = result;
17         }
18 
19        return result;
20     }
21 };
 
  

爬楼梯


1
/*#include "stdafx.h" 2 #include<iostream> 3 using namespace std;*/ 4 5 class Solution { 6 public: 7 /** 8 * @param A: a list of integers 9 * @return : return an integer 10 */ 11 int removeDuplicates(vector<int> &nums) { 12 // write your code here 13 if(nums.size() == 0) return 0; 14 int i; 15 int j = 1; 16 for(i = 1; i < nums.size(); ++i) 17 { 18 if(nums[i] != nums[j-1]) 19 { 20 nums[j] = nums[i]; 21 j++; 22 } 23 } 24 return j; 25 } 26 };

 

转载于:https://www.cnblogs.com/9153299q/p/6519080.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值