GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/code/lc122.java at master · mJackie/leetcode Expand file tree/ Copy pathlc122.javaMore file actions 20 lines (20 loc) · 590 Bytes / Copy pathlc122.javaFile metadata and controls20 lines (20 loc) · 590 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 package code; /* * 122. Best Time to Buy and Sell Stock II * 题意:买卖股票最大利润,可以买多次 * 难度:Easy * 分类:Array, Greedy * 思路:计算 prices[i] 与 prices[i-1] 的差值,把正数全加起来就行了 * Tips:lc121, lc309, lc188, lc123, lc714 */ public class lc122 { public int maxProfit(int[] prices) { if(prices.length<1) return 0; int res = 0; for (int i = 1; i < prices.length ; i++) { if(prices[i]-prices[i-1]>0) res += prices[i]-prices[i-1]; } return res; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |