Java | Leetcode Java题解之第343题整数拆分

题目:

题解:

java 复制代码
class Solution {
    public int integerBreak(int n) {
        if (n <= 3) {
            return n - 1;
        }
        int quotient = n / 3;
        int remainder = n % 3;
        if (remainder == 0) {
            return (int) Math.pow(3, quotient);
        } else if (remainder == 1) {
            return (int) Math.pow(3, quotient - 1) * 4;
        } else {
            return (int) Math.pow(3, quotient) * 2;
        }
    }
}
相关推荐
mifengxing8 小时前
LeetCode 41.缺失的第一个正数|Hard题O(n)+O(1)最优解法深度解析
java·算法·leetcode·排序算法
markinmarkin10 小时前
Spring 中Bean 的作用域有哪些?
java·后端·spring
山荷枝11 小时前
Java学习第十天
java·学习
matlabgoodboy12 小时前
计算机毕设代做|Java Python Matlab APP 全套开发设计
java·python·课程设计
hanlin0313 小时前
动态规划专练:力扣第121、122题
笔记·算法·leetcode
To_OC13 小时前
LC 74 搜索二维矩阵:换皮的二分查找,我居然一开始没看出来
javascript·算法·leetcode
玖玥拾13 小时前
LeetCode 189 轮转数组
算法·leetcode
程序员雷欧13 小时前
环形缓冲区深度解析:从基础原理到Disruptor源码的全面剖析
java
xiaoqiMikko13 小时前
Dependabot 面板全绿,不代表你的 Tomcat 没洞
java·spring boot
前端开发张小七13 小时前
Java 学习笔记 · 第三课:多线程与并发编程(线程、同步、死锁、Lock、乐观锁与悲观锁)
java·后端·程序员