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 568e36b

Browse files
committed
添加 0343.整数拆分.md Scala版本
1 parent fe3aa4f commit 568e36b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎problems/0343.整数拆分.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,22 @@ int integerBreak(int n){
335335
}
336336
```
337337
338+
### Scala
339+
340+
```scala
341+
object Solution {
342+
def integerBreak(n: Int): Int = {
343+
var dp = new Array[Int](n + 1)
344+
dp(2) = 1
345+
for (i <- 3 to n) {
346+
for (j <- 1 until i - 1) {
347+
dp(i) = math.max(dp(i), math.max(j * (i - j), j * dp(i - j)))
348+
}
349+
}
350+
dp(n)
351+
}
352+
}
353+
```
354+
338355
-----------------------
339356
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
(0)

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