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.

Example 1:

Example 2:

 

题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

 

一堆股票价格 – 每天买一次卖一次 – 问最大收益 Eazy难度 – 不过2016携程笔试考到了原题,所以就翻出来Ac了一下…

提交代码:

 

携程AC代码:

 

嗯 – 就是酱…

【LeetCode】121. Best Time to Buy and Sell Stock
Tagged on:
0 0 vote
Article Rating
订阅
提醒
0 评论
Inline Feedbacks
View all comments