LeetCode 122
2016-04-24 23:08
113 查看
Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
public class Solution { public int maxProfit(int[] prices) { int profile = 0; if(prices.length <= 1){ return profile; }else{ for(int i=1; i<prices.length; i++){ profile += Math.max(prices[i] - prices[i - 1], 0); } return profile; } } }
相关文章推荐
- opencv_traincascade训练haar时Error: Insufficient memory等问题
- python爬虫实现----github地址
- nc suapUI 破解
- 设计模式学习-单例模式
- c#使用MethodInvoker解决跨线程访问控件
- php 自带过滤和转义函数
- 团队项目冲刺第七天
- VIM学习 (3)
- LeetCode 121
- UVA - 424 Integer Inquiry
- HIBERNATE与 MYBATIS的对比
- nc 单据拓展字段 元数据导出脚本
- 20145225《Java程序设计》 实验三 "敏捷开发与XP实践"
- 20145314郑凯杰 《Java程序设计》第8周学习总结
- 第八周学习进度
- 练习三1019
- 反射获得属性方法上面的注解
- html常用语法
- js中解决如何获取css中的参数
- LigerUI的简单使用示例