
算法
Java
Leetcode
Golang
Java
Leetcode
Golang
Question
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.
See it on Leetcode
Example 1
|
|
Example 2
|
|
Hint
Brute force approach may result in Time Limit Exceeded. Try greedy approach.
Solution in Java and Golang
- java
- go
1 |
public class { |




近期评论