leetcode 121 Best Time to Buy and Sell Stock C++
2016-05-23 21:27
447 查看
动态规划
class Solution { public: int maxProfit(vector<int>& prices) { if(prices.size() <= 0) return 0; int minPrice = prices[0]; int maxProfit = 0; for(int i =0 ;i<prices.size();i++){ maxProfit = max(maxProfit,prices[i]-minPrice); minPrice = min(minPrice,prices[i]); } return maxProfit; } };
相关文章推荐
- c语言课程设计
- C++ hashmap
- 322. Coin Change(C++实现)
- C语言快排函数qsort()
- C++中map的使用
- 俄罗斯方块和贪吃蛇游戏软件:C语言应用初始感受
- 初次接受c语言程序游戏的感受
- 俄罗斯方块软件:C语言应用初步感受
- 关于俄罗斯方块游戏软件C语言初步感受
- 俄罗斯游戏软件:C语言应用初步感受
- C++作业6
- C++笔记--类型和声明
- 初次接受C语言游戏程序感受
- C++实验6-数组操作
- C++ 标准库的 locale 类用法
- Dos界面 五步棋
- 关于c语言程序的感受
- c++中头文件iomanip
- [C++]关于数据永久化的思考(不使用数据库)
- 山东省第六届ACM大学生程序设计竞赛-Single Round Math(大数除法)