LeetCode——Best Time to Buy and Sell Stock
来源:互联网 发布:nginx module 编写 编辑:程序博客网 时间:2024/06/07 08:48
Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Java代码:public class Solution { public int maxProfit(int[] prices) { if(prices.length == 0)return 0; int min = 0; int profit =0; min = prices[0]; for(int i=1;i<prices.length;i++) { profit = (prices[i] - min)>profit?prices[i] - min:profit; //profit = (min > prices[i])?profit+(min - prices[i]):profit; min = (min > prices[i])?prices[i]:min; } return profit; }}
0 0
- Leetcode —— Best Time to Buy and Sell Stock
- LeetCode——Best Time to Buy and Sell Stock
- LeetCode——Best Time to Buy and Sell Stock
- leetcode——Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock——LeetCode
- leetcode——Best Time to Buy and Sell Stock
- LeetCode——Best Time to Buy and Sell Stock
- LeetCode—Best Time to Buy and Sell Stock
- 【LeetCode】Best Time to Buy and Sell Stock & Best Time to Buy and Sell Stock
- DP——Best Time to Buy and Sell Stock
- Algorithms—121.Best Time to Buy and Sell Stock
- LeetCode121—Best Time to Buy and Sell Stock
- LeetCode122—Best Time to Buy and Sell Stock II
- LeetCode123—Best Time to Buy and Sell Stock III
- LeetCode188—Best Time to Buy and Sell Stock IV
- Leetcde——121 Best Time to Buy and Sell Stock && 123 Best Time to Buy and Sell Stock
- [LeetCode] [LeetCode]Best Time to Buy and Sell Stock
- leetcode——309——Best Time to Buy and Sell Stock with Cooldown
- 嵌入式开发基础--Linux与windows的共享问题解决方法一
- 杭州奢侈品寄售回收哪儿好
- linux下星际译王stardict 及词典的安装
- windows7 64位安装eclipse 插件spket 搭建ExtJS提示
- Objective-C之成魔之路【15-Foundation框架】
- LeetCode——Best Time to Buy and Sell Stock
- gson常用用法小结
- postfix + dovecot + mutt 搭建邮件服务器( 失败原因初步分析 )
- From N to N+1: Multiclass Transfer Incremental Learning 代码分析(1)
- 1.2 自话遗传算法
- 简单好用又大方的table
- Fackbook Presto 安装使用
- vim
- Android——自定义View类(一 )