Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 68e8b59

Browse files
🐱(dp): 121. 买卖股票的最佳时机 补充 golang 题解
1 parent 35d313f commit 68e8b59

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎docs/data-structure/array/README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ class Solution:
10281028

10291029
2019年01月05日 复盘打卡
10301030

1031+
<!-- tabs:start -->
1032+
1033+
#### **Python**
1034+
10311035
```python
10321036
class Solution(object):
10331037
def maxProfit(self, prices):
@@ -1051,7 +1055,30 @@ class Solution(object):
10511055
return max_val
10521056
```
10531057

1058+
#### **Go**
1059+
1060+
```go
1061+
func maxProfit(prices []int) int {
1062+
dayCount := len(prices)
1063+
if dayCount == 0 {
1064+
return 0
1065+
}
1066+
res := 0
1067+
min := prices[0]
1068+
for i := 1; i < dayCount; i++ {
1069+
get := prices[i] - min
1070+
if get > res {
1071+
res = get
1072+
}
1073+
if prices[i] < min {
1074+
min = prices[i]
1075+
}
1076+
}
1077+
return res
1078+
}
1079+
```
10541080

1081+
<!-- tabs:end -->
10551082

10561083

10571084
## 167. 两数之和 II - 输入有序数组

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /