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;
        }
    }
}
相关推荐
im_AMBER7 分钟前
杂记 15
java·开发语言·算法
豆沙沙包?15 分钟前
2025年--Lc182--sql(排序和分组)--Java版
java·数据库·sql
爱coding的橙子21 分钟前
每日算法刷题Day70:10.13:leetcode 二叉树10道题,用时2h
算法·leetcode·深度优先
CryptoRzz1 小时前
欧美(美股、加拿大股票、墨西哥股票)股票数据接口文档
java·服务器·开发语言·数据库·区块链
杂货铺的小掌柜1 小时前
apache poi excel 字体数量限制
java·excel·poi
大厂码农老A1 小时前
你打的日志,正在拖垮你的系统:从P4小白到P7专家都是怎么打日志的?
java·前端·后端
艾菜籽2 小时前
Spring MVC入门补充2
java·spring·mvc
爆更小哇2 小时前
统一功能处理
java·spring boot
程序员鱼皮2 小时前
我造了个程序员练兵场,专治技术焦虑症!
java·计算机·程序员·编程·自学
n8n2 小时前
SpringAI 完全指南:为Java应用注入生成式AI能力
java·后端