LeetCode 122 Best Time to Buy and Sell Stock II
2016-01-21 11:49
363 查看
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) { if(prices.length==0||prices.length==1) return 0; int result=0; for(int i=1;i<prices.length;i++){ if(prices[i]>prices[i-1]) result+=(prices[i]-prices[i-1]); } return result; } }
相关文章推荐
- 聚合框架
- 用ToggleButton和ImageView实现不同状态下显示的切换
- DM6437 720P调试问题记录
- keystore提取私钥和证书
- 3ds Max SDK 导入插件的一些技术障碍记录
- dba_segments和dba_tables的不同
- Spring4.0 + 实现简单的聊天
- Nginx HTTP请求流程
- bower简介
- 上下级查询
- Ubuntu14.04 SSH安装教程
- Maven引入hadoop依赖包出错解决办法
- FFMPEG
- Eclipse中65536的解决办法
- 深入android6.0 设备 idle状态
- 带图标和箭头、文字的垂直居中
- LeetCode 110 Balanced Binary Tree(平衡二叉树)(*)
- 使用Xcode HeaderDoc和Doxygen文档化你的Objective-C和Swift代码
- 克隆VMWare ESXi虚拟机
- 关系型数据库和非关系型数据库