技术栈

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

m0_571957582024-08-18 22:10

题目:

题解:

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;
        }
    }
}
上一篇:已解决:java.net.BindException: 地址已在使用
下一篇:Java TCP练习1
相关推荐
雨中飘荡的记忆
17 小时前
保证金系统入门到实战
java·后端
Nyarlathotep0113
17 小时前
Java内存模型
java
暮色妖娆丶
21 小时前
不过是吃了几年互联网红利罢了,我高估了自己
java·后端·面试
NE_STOP
1 天前
MyBatis-参数处理与查询结果映射
java
狂奔小菜鸡
1 天前
Day40 | Java中的ReadWriteLock读写锁
java·后端·java ee
SimonKing
1 天前
JetBrains 用户狂喜!这个 AI 插件让 IDE 原地进化成「智能编码助手」
java·后端·程序员
狂奔小菜鸡
1 天前
Day39 | Java中更灵活的锁ReentrantLock
java·后端·java ee
NE_STOP
2 天前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类
java
后端AI实验室
2 天前
用AI写代码,我差点把漏洞发上线:血泪总结的10个教训
java·ai
热门推荐
01GitHub 镜像站点02OpenClaw 使用和管理 MCP 完全指南03OpenClaw + 飞书(Feishu)环境搭建指南04本地部署 OpenClaw + DeepSeek-R1 完全指南05Window 10部署openclaw报错node.exe : npm error code 12806OpenClaw优化飞书API 额度已耗尽问题07Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services08OpenClaw 连接飞书完整指南:插件安装、配置与踩坑记录09小黑课堂计算机二级WPSoffice题库软件下载安装教程(2026年3月最新版)10让 Trae IDE 智能体 “读懂”文档 Excel+PDF+DOCX :mcp-documents-reader 工具使用指南