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;
        }
    }
}
相关推荐
圆山猫5 小时前
[Virtualization](四):Linux KVM/RISC-V 的 vCPU 运行路径
java·linux·risc-v
城管不管6 小时前
ReAct、Plan-and-Execute、Reflection 三大智能 Agent 范式核心区别
java·人工智能·算法·spring·ai·动态规划
IT小白杨6 小时前
从环境制备到自动化工作流:多账号运营的工程化架构拆解
java·经验分享·自动化·安全架构·指纹浏览器
豆瓣鸡7 小时前
算法日记 - Day3
java·开发语言·算法
白白白小纯7 小时前
算法篇—反转链表
c语言·数据结构·算法·leetcode
萧瑟余晖7 小时前
Java深入解析篇九之NIO详解
java·网络·nio
The Chosen One9857 小时前
高进度算法模板速记(待完善)
java·前端·算法
极光代码工作室9 小时前
基于SpringBoot的课程预约系统
java·springboot·web开发·后端开发
圣保罗的大教堂10 小时前
leetcode 3517. 最小回文排列 I 中等
leetcode
Leighteen10 小时前
`try-finally` 里的 `return`:为什么 `finally` 会悄悄改掉返回值、吞掉异常
java·开发语言