leetcode--Best Time to Buy and Sell Stock II
来源:互联网 发布:2017年火灾数据 编辑:程序博客网 时间:2024/06/09 17:03
Say you have an array for which the ith element is the price of a given stock on dayi.
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 res = 0; if(prices.length==0) return res; for(int i=1;i<prices.length;i++){ if(prices[i]>prices[i-1]){ res += prices[i]-prices[i-1]; } } return res; }}
0 0
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- [Leetcode]Best Time to Buy and Sell Stock II
- [leetcode]Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- LeetCode-Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock II
- leetcode--CountCompleteTreeNodes
- lvs(+keepalived)、haproxy(+heartbeat)、nginx 负载均衡的比较分析
- LeetCode 111 Minimum Depth of Binary Tree
- 事务
- 黑马程序员学习日记--网络编程
- leetcode--Best Time to Buy and Sell Stock II
- 《C专家编程》笔记一:第二章 这不是Bug,而是语言特性
- 成绩查询系统--框架篇--jar包分析
- 重新理解计算机(一)
- webservice客户端 发生undefined element declaration 's:schema'
- 如何成为编程大牛
- 浅析Scanf源码
- Android应用程序实现欢迎引导页面的方法实现
- Unity3d_数组类型