Best Time to Buy and Sell Stock
2015-06-09 12:11
302 查看
public class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) { return 0; } int low = Integer.MAX_VALUE; int profits = 0; for (int i = 0; i < prices.length; i++) { low = prices[i] < low ? prices[i] : low; profits = (prices[i] - low) > profits ? (prices[i] - low) : profits; } return profits; } }
相关文章推荐
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android px、dp、sp之间相互转换
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- TYVJ1193 括号序列解题报告
- 对DP的一点感想
- TYVJ上一些DP的解题报告
- soj1005. Roll Playing Games
- 01背包问题
- LeetCode之Maximum Product Subarray
- DP Flow
- zoj3605 Find the Marble(三维dp)
- Word Break I,II, Triangle,Palindrome Partitioning 动态规划 DP
- Unique Paths I,II, Minimum Path Sum
- Gas Station