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;
        }
    }
}
相关推荐
Python+993 分钟前
Java 枚举类(Enum)详解:从基础到高级应用
java·开发语言·python
G.O.G.O.G18 分钟前
LeetCode SQL 从入门到精通(MySQL)06(上)
数据库·sql·mysql·leetcode
二炮手亮子27 分钟前
浅记java线程池
java·开发语言
一路向北North28 分钟前
Spring Security OAuth2.0(23):分布式系统授权-转发明文给微服务
java·spring·微服务
闪电悠米2 小时前
力扣hot100-56.合并区间-排序详解
数据结构·算法·leetcode·贪心算法·排序算法
爱吃牛肉的大老虎2 小时前
rust基础之环境搭建
java·开发语言·rust
tellmewhoisi3 小时前
多版本共用redis的token有效期校验(过期重新登录)
java·redis·缓存
疯狂打码的少年3 小时前
【软件工程】结构化设计:模块独立性与耦合内聚
java·开发语言·笔记·软件工程
乐观的Terry3 小时前
3、数据库设计与领域实体
java·数据库·spring boot·spring cloud·ai编程
卡提西亚4 小时前
leetcode-1438. 绝对差不超过限制的最长连续子数组
算法·leetcode·职场和发展