[刷题]Best Time to Buy and Sell Stock II

来源:互联网 发布:北京程序员 编辑:程序博客网 时间:2024/06/05 00:57

[LintCode]Best Time to Buy and Sell Stock II

class Solution {    /**     * @param prices: Given an integer array     * @return: Maximum profit     */    public int maxProfit(int[] prices) {        // 2015-09-15        if (prices == null || prices.length == 0) {            return 0;        }                int rst = 0;        for (int i = 1; i < prices.length; i++) {            int sub = prices[i] - prices[i - 1];            if (sub > 0) {                rst += sub;            }        }        return rst;    }};


0 0
原创粉丝点击