Skip to content

Commit

Permalink
Merge pull request #2743 from tony8888lrz/master
Browse files Browse the repository at this point in the history
Update 0343.整数拆分.md Java版本增加贪心算法,清晰注释
  • Loading branch information
youngyangyang04 authored Sep 27, 2024
2 parents c0aae6a + b3c0d03 commit e7c8d01
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions problems/0343.整数拆分.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,29 @@ class Solution {
}
}
```
贪心
```Java
class Solution {
public int integerBreak(int n) {
// with 贪心
// 通过数学原理拆出更多的3乘积越大,则
/**
@Param: an int, the integer we need to break.
@Return: an int, the maximum integer after breaking
@Method: Using math principle to solve this problem
@Time complexity: O(1)
**/
if(n == 2) return 1;
if(n == 3) return 2;
int result = 1;
while(n > 4) {
n-=3;
result *=3;
}
return result*n;
}
}
```

### Python
动态规划(版本一)
Expand Down

0 comments on commit e7c8d01

Please sign in to comment.