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;