LintCode_149_买卖股票的最佳时机
来源:互联网 发布:sql server数据库开发 编辑:程序博客网 时间:2024/05/17 03:02
假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格。如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润。
样例
给出一个数组样例 [3,2,3,1,2], 返回 1
两个循环 前后找差值最大的
public class Solution { /** * @param prices: Given an integer array * @return: Maximum profit */ public int maxProfit(int[] prices) { // write your code here int profit = 0; for(int i = prices.length - 1 ; i > 0 ; i--){ for(int j = 0; j < i ; j++){ int temp = prices[i] - prices[j]; if(temp > profit){ profit = temp; } } } return profit; }}
0 0
- LintCode_149_买卖股票的最佳时机
- LintCode_149_买卖股票的最佳时机
- 买卖股票的最佳时机
- 买卖股票的最佳时机
- 买卖股票的最佳时机
- LintCode-买卖股票的最佳时机
- 题目:买卖股票的最佳时机
- LintCode--买卖股票的最佳时机
- Lintcode:买卖股票的最佳时机
- 买卖股票的最佳时机 II
- 买卖股票的最佳时机 III
- 买卖股票的最佳时机|_1
- 买卖股票的最佳时机||_1
- 买卖股票的最佳时机,lintcode
- 【LintCode】买卖股票的最佳时机
- lintcode--买卖股票的最佳时机
- Lintcode 买卖股票的最佳时机
- 买卖股票的最佳时机-LintCode
- python核心编程中的对象值比较VS对象身份比较
- jquery---判断是否支持Placeholder属性
- Xcode brew安装和使用
- 几种常见排序算法的JavaScript实现
- 自动更新 ishadowsocks 提供的免费账号的账号及密码
- LintCode_149_买卖股票的最佳时机
- 有向图强连通分量Tarjan模板
- 小笨狼漫谈多线程:GCD(1)
- mysql主从复制及自动备份脚本
- C++ Mfc 吹泡泡程序编程实例 下载
- 在百度地图API开发中已知两个点之间的经纬度坐标计算其距离
- 1231 - Coin Change (I) 多重背包
- matlab暗通道图像去雾算法实现
- 快速排序