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;
        }
    }
}
相关推荐
栈溢出了24 分钟前
Java Lambda 表达式笔记
java·开发语言·intellij-idea
会周易的程序员25 分钟前
使用 pybind11 封装 C++ 日志库 microLog 为 Python 模块
java·c++·python·物联网·架构·日志·aiot
zhixingheyi_tian34 分钟前
一份GC日志的解读
java·开发语言
ywl47081208744 分钟前
ArrayList和LinkedList内部的实现原理和区别
java·java基础
沉静的小伙1 小时前
Spring事务
java·数据库·spring
apihz1 小时前
随机驾考题目(C 照科一 / 科四 2000+ 题)免费API调用教程
android·java·c语言·开发语言·网络协议·tcp/ip
AIGS0011 小时前
企业AI落地:Agent OS 治理框架实践
java·大数据·人工智能·机器学习·人工智能ai大模型应用
-西门吹雪2 小时前
现代C++ 并发编程-学习指南
java·jvm·c++
lh17932 小时前
数据产业服务分类(53)——分类设计——数据能力集成
java·人工智能·分类
想你依然心痛2 小时前
自定义RTOS内核:从零实现上下文切换与任务调度——汇编、PendSV
java·开发语言·汇编·pendsv