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;
        }
    }
}
相关推荐
kk哥88992 小时前
分享一些学习JavaSE的经验和技巧
java·开发语言
栈与堆2 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
lagrahhn3 小时前
Java的RoundingMode舍入模式
java·开发语言·金融
鸽鸽程序猿3 小时前
【JavaEE】【SpringCloud】注册中心_nacos
java·spring cloud·java-ee
云上凯歌3 小时前
01 GB28181协议基础理解
java·开发语言
鹿角片ljp3 小时前
力扣7.整数反转-从基础到边界条件
算法·leetcode·职场和发展
java修仙传3 小时前
力扣hot100:前K个高频元素
算法·leetcode·职场和发展
Coder_Boy_3 小时前
基于SpringAI的在线考试系统-考试系统DDD(领域驱动设计)实现步骤详解
java·数据库·人工智能·spring boot
毕设源码-钟学长3 小时前
【开题答辩全过程】以 基于Java的运动器材销售网站为例,包含答辩的问题和答案
java·开发语言
workflower3 小时前
软件需求规约的质量属性
java·开发语言·数据库·测试用例·需求分析·结对编程