Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit f7bf96f

Browse files
committed
slt121 c
1 parent f9aeb3d commit f7bf96f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scala-leetcode/src/main/scala/io/github/dreamylost/Leetcode_121.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package io.github.dreamylost
66
* 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。
77
* 注意你不能在买入股票前卖出股票。
88
* @author 梦境迷离
9-
* @time 2018年8月14日
9+
* @since 2018年8月14日
1010
* @version v1.0
1111
*/
1212
object Leetcode_121 extends App {
@@ -17,12 +17,12 @@ object Leetcode_121 extends App {
1717

1818
if (prices.length == 0) return 0
1919
var max = 0
20-
var temp = prices(0)
20+
var minPrice = prices(0)
2121
for (i <- 1 until prices.length) {
22-
if (temp > prices(i)) {
23-
temp = prices(i)
22+
if (minPrice > prices(i)) {
23+
minPrice = prices(i)
2424
} else {
25-
max = math.max(max, prices(i) - temp)
25+
max = math.max(max, prices(i) - minPrice)
2626
}
2727
}
2828
max

0 commit comments

Comments
 (0)