LeetCode & Q122-Best Time to Buy and Sell Stock II-Easy
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的更多相关文章
- [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 ...
- 【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 ...
- 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 ...
- 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 ...
- 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 ...
- LeetCode 122 Best Time to Buy and Sell Stock II(股票买入卖出的最佳时间 II)
翻译 话说你有一个数组,当中第i个元素表示第i天的股票价格. 设计一个算法以找到最大利润. 你能够尽可能多的进行交易(比如.多次买入卖出股票). 然而,你不能在同一时间来多次交易. (比如.你必须在下 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- FTP环境搭建及客户代码调用公共方法封装
一.背景 大型系统架构往往被分解为多个独立可运行的组件, 以满足性能.可靠性.可扩展性的需求.多个组件间的数据交互往往采用两种方式:小量数据通过Sock函数.RMI.WebService等接口方式传递 ...
- C++与Java通过WebService通信(上)
一. 前言 本篇讲述如果通过C++客户端访问Java服务端发布的SOAP模式的WebService接口.文档中的样例代码拷贝出去即可运行,所有的代码都是本地测试OK的:本文不但解决了接口调用的问题,同 ...
- ubuntu16.04 安装常见问题解决方案------输入法黑框
我的系统是 lubuntu 16.04 刚安装输入法候选字的地方全是黑框,然后百度查到了 compton 和 xcompmgr 这两个说是窗口微调 透明 ,这两个方法对我的系统不管用 .各位如果遇到黑 ...
- quartz.net 3.x 使用总结
quartz文档:https://www.quartz-scheduler.net/documentation/index.html 这里用新建的控制台项目进行演示. 目标效果为每隔一秒在控制台上输出 ...
- C语言与C++语言之间关系
很多时候我们对于C和C++的区别不是很清楚,以至于弄混的情况并不少见.那C语言和C++语言到底是怎么回事呢? 首先,我们来看下百度百科对语言和C++语言描述,相对而说也还算是比较权威的. C语言 C语 ...
- JS报表打印分页CSS
在调用window.print()时,可以实现打印效果,但内容太多时要进行分页打印. 在样式中有规定几个打印的样式 page-break-before和page-break-after CSS属性并不 ...
- 设计模式——组合模式(C++实现)
组合模式:将对象组合成树形结构以表示“部分-整体”的层次结构. 组合模式使得用户对单个对象和组合对象的使用具有一致性. 是一种结构型模式 使用场景: 1.用于对象的部分-整体层次结构,如树 ...
- Linux中断子系统:级联中断控制器驱动
Linux中断子系统 Linux中断子系统是个很大的话题,如下面的思维导图所示,包含硬件.驱动.中断上半部.中断下半部等等.本文着眼于中断控制器(PIC),特别是级联中断控制器驱动部分,对驱动的设计和 ...
- Cesium 鼠标拾取椭球、地形、模型坐标点(经度+纬度+高程)
首先,Cesium 中的坐标可分为两种情况:二维和三维,三维又有地形和模型之分: 1.二维坐标,获取椭球体表面的经纬度坐标: var handler = new Cesium.ScreenSpaceE ...
- Elasticsearch就这么简单
一.前言 最近有点想弄一个站内搜索的功能,之前学过了Lucene,后来又听过Solr这个名词.接着在了解全文搜索的时候就发现了Elasticsearch这个,他也是以Lucene为基础的. 我去搜了几 ...