题目说至少是拆分两个,还可以继续拆分,所以可以对n - j继续拆分,也可以不继续拆分。 n - j继续拆解,就划分为子问题了。
暴力递归拆解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
classSolution{ funintegerBreak(n: Int): Int { if (n == 0 || n == 1) return0 if (n == 2) return1 var maxProduct = -1 for (j in1 until n) { val i = n - j maxProduct = maxOf( maxProduct, j * i, j * integerBreak(i) ) } return maxProduct } }