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 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 profile = 0;
         if(prices.length <= 1){
             return profile;
         }else{
                 for(int i=1; i<prices.length; i++){
                     profile += Math.max(prices[i] - prices[i - 1], 0);
             }
             return profile;
         }
     }
 }
LeetCode 122的更多相关文章
- 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 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 买卖股票的最佳时间 II
		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 买卖股票的最佳时机 II
		122. 买卖股票的最佳时机 II 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意: ... 
- leetcode 122 123   309 188 714  股票买卖 动态规划
		这类问题有一个通法 https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii/solution/yi-ge-tong-y ... 
- 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] - 买入与卖出股票的最佳时机II(Best Time to Buy and Sell Stock 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 ... 
随机推荐
- Linux date命令 - 显示和设置系统日期与时间
			操作系统上的时间也许只是当做一个时钟.特别在控制台下, 我们通常并不认为时间有什么重要的.但是对于管理员,这种认识是错误的.你知道错误的日期和时间会导致你不能编译程序么? 因为日期和时间很重要,这或许 ... 
- <a href="javascript:void(0);" id='test' onclick="javascript:alert('即将上线,敬请期待!');"><em class="rmwd"></em>征稿平台</a>
			<a href="javascript:void(0);" id='test' onclick="javascript:alert('即将上线,敬请期待!');&q ... 
- Listview上下滚动崩溃
			利用CursorAdapter在ListView中显示Cursor中不同同类型的item,加载均正常,滚动时报如下错误: 11-28 15:18:16.703: E/InputEventReceive ... 
- Unity3D之ScriptableObject学习笔记
			不同与C#提供的Serializable序列化功能,ScriptableObject是Unity3D提供的一个数据存储类,我们接下来学习一下这个类的功能. 官方文档 http://docs.unity ... 
- 初学Android 一 基本开发环境
			Android平台架构 1.应用程序层: 核心应用程序和普通应用程序,他们都是平级的,都可以平等的调用下层. 2.应用程序框架:供上一层调用的API. 3.函数库: 不能被直接调用的C/C++库的集合 ... 
- FOR XML PATH的用法
			USE [ChangHongWMS612]GO/****** Object: StoredProcedure [dbo].[st_WMS_SelStockInBillList] Script Date ... 
- status pending状态
			开发采用ssh,注解的方式,事物也application.xml配置了,但是在业务层没有使用@Transactional造成浏览器一直处于status pending状态,为什么没有使用@Transa ... 
- VMware虚拟机扩容
			作者:金良(golden1314521@gmail.com) csdn博客:http://blog.csdn.net/u012176591 用了一段Linux虚拟机.发现安装虚拟机时分配的空间不够用, ... 
- delphi 立即显示提示
			procedure TForm1.FormCreate(Sender: TObject); begin Application.HintPause:=0;//立即显示 Application.hi ... 
- Html页中使用OCX控件
			原文:http://blog.csdn.net/mouse8166/article/details/5515657 最近准备开发一个b/s架构的应用程序需要用到activeX控件,web服务器尚未进入 ... 
