mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加 0343.整数拆分.md Scala版本
This commit is contained in:
@ -335,5 +335,22 @@ int integerBreak(int n){
|
||||
}
|
||||
```
|
||||
|
||||
### Scala
|
||||
|
||||
```scala
|
||||
object Solution {
|
||||
def integerBreak(n: Int): Int = {
|
||||
var dp = new Array[Int](n + 1)
|
||||
dp(2) = 1
|
||||
for (i <- 3 to n) {
|
||||
for (j <- 1 until i - 1) {
|
||||
dp(i) = math.max(dp(i), math.max(j * (i - j), j * dp(i - j)))
|
||||
}
|
||||
}
|
||||
dp(n)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user