Description:

Say you have an array for which the ith element is the price of a given stock on day i.

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).

题目条件一改,就显得这题过于简单了...导致在Discuss里最高讨论就是"Is this question a joke?"

my Solution:

public class Solution {
public int maxProfit(int[] prices) {
int profit = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i] > prices[i-1]) {
profit += prices[i] - prices[i-1];
}
}
return profit;
}
}

LeetCode & Q122-Best Time to Buy and Sell Stock II-Easy的更多相关文章

  1. [LeetCode] 122. Best Time to Buy and Sell Stock II 买卖股票的最佳时间 II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. 【leetcode】Best Time to Buy and Sell Stock II

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  3. 31. leetcode 122. Best Time to Buy and Sell Stock II

    122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...

  4. leetcode 【 Best Time to Buy and Sell Stock II 】python 实现

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  5. LeetCode 122. Best Time to Buy and Sell Stock II (stock problem)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  6. LeetCode 122 Best Time to Buy and Sell Stock II(股票买入卖出的最佳时间 II)

    翻译 话说你有一个数组,当中第i个元素表示第i天的股票价格. 设计一个算法以找到最大利润. 你能够尽可能多的进行交易(比如.多次买入卖出股票). 然而,你不能在同一时间来多次交易. (比如.你必须在下 ...

  7. LeetCode 122. Best Time to Buy and Sell Stock II (买卖股票的最好时机之二)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. leetcode 122. Best Time to Buy and Sell Stock II ----- java

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. Java [Leetcode 122]Best Time to Buy and Sell Stock II

    题目描述: Say you have an array for which the ith element is the price of a given stock on day i. Design ...

  10. LeetCode 122 Best Time to Buy and Sell Stock II 解题报告

    题目要求 Say you have an array for which the ith element is the price of a given stock on day i. Design ...

随机推荐

  1. Java 计算年龄

    public static String getAgeTxt(String birthTime,String beginTime,int level){ if(StringUtils.isBlank( ...

  2. Oracle-数据类型为date 日期查询技巧

    date类型是oracle中存储日期类的一种常用类型,其处理也是在数据库使用中比较多需要注意的地方.如我们可以使用to_char函数将其转化为任意时间格式的字符串,也可使用to_date函数转化相应的 ...

  3. log4net应用实践(一)

          1.背景 log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具.它是.Net下一 ...

  4. C# Redis实战(六)

    六.查询数据 在C# Redis实战(五)中介绍了如何删除Redis中数据,本篇将继续介绍Redis中查询的写法. 1.使用Linq匹配关键字查询 using (var redisClient = R ...

  5. 在lamp上简单部署应用程序

    前言:上文中,说到了lamp的基本原理,apache与php的三种交互模式,php与mysql(mariadb)的交互,一次完整lamp的请求. LAMP简单的部署之后,便能够简单的搭建自己的网站. ...

  6. 使用BigDecimal报的错

    错误:java.lang.arithmeticexception: non-terminating decimal expansion; no exact representa  小数位膨胀 解决方法 ...

  7. 部署wcf出现的问题与解决方法

    我将本机作为服务器开发时,没出什么问题,将wcf服务端寄缩到另一台电脑上时,出现了一些问题,这里总结下: 1.wcf服务器和另一个网站应用出问题 服务器的iis上有一个网站应用,当我将wcf服务寄缩到 ...

  8. 如何给自己的外包APP开发报价?

    作者:CODING 兄弟,你看做这样一个软件需要多少钱?" 这估计是所有软件从业人员被问的最多也是最无奈的一个问题.这个问题等同于,"你看装修一个100平米的房子需要多少钱?&qu ...

  9. GO语言初探

    1.GO使用UTF-8编码,纯Unicode文本编写. 2.$ go verson (windows) 3.windows下,需要设置go语言的环境变量,新建一个名为 GOROOT的变量,指向go的具 ...

  10. IntelliJ Idea常用的快捷键

    以下是IntelliJ Idea2017版的,基本上不会有什么变化 IntelliJ Idea这个编译器现在非常流行,他强大的快捷键非常好用,相比于eclipse,IntelliJ Idea界面也比e ...