๐ 343. ๆดๆฐๆๅ
2022ๅนด6ๆ9ๆฅๅฐไบ 1 ๅ้
๐ 343. ๆดๆฐๆๅ
้พๅบฆ: ๐
้ฎ้ขๆ่ฟฐ
่งฃๆณ
class Solution {
public int integerBreak(int n) {
// ๆ่ทฏ๏ผ
// ๅฐฝๅฏ่ฝๆๆ 3 ็ๅๆฐ
if(n == 2) {
return 1;
}
if(n == 3) {
return 2;
}
if(n == 4) {
return 4;
}
// n > 4
int count = n / 3;
int left = n % 3;
if(left == 0) {
return (int)Math.pow(3, count);
} else if(left == 1) {
return (int)Math.pow(3, count - 1) * 4;
} else if(left == 2) {
return (int)Math.pow(3, count) * 2;
}
return 0;
}
}