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 bd4f69d

Browse files
committed
添加 0053.最大子序和(动态规划).md Scala版本
1 parent a6ce79a commit bd4f69d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎problems/0053.最大子序和(动态规划).md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,22 @@ const maxSubArray = nums => {
186186
};
187187
```
188188

189-
189+
Scala:
190+
191+
```scala
192+
object Solution {
193+
def maxSubArray(nums: Array[Int]): Int = {
194+
var dp = new Array[Int](nums.length)
195+
var result = nums(0)
196+
dp(0) = nums(0)
197+
for (i <- 1 until nums.length) {
198+
dp(i) = math.max(nums(i), dp(i - 1) + nums(i))
199+
result = math.max(result, dp(i)) // 更新最大值
200+
}
201+
result
202+
}
203+
}
204+
```
190205

191206
-----------------------
192207
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
(0)

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