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;
        }
    }
}
相关推荐
Forever Nore16 分钟前
LeetCode 16 最接近的三数之和 - 双指针逼近
算法·leetcode·职场和发展
杨丰玮41817 分钟前
暑假Java知识点回顾:类与对象知识总结
java·开发语言
盐焗鹌鹑蛋18 分钟前
【Linux】ELF与库加载
java·linux·服务器
WarPigs23 分钟前
Unity未激活的物体无法响应事件?
java·unity·游戏引擎
smj2302_7968265223 分钟前
解决leetcode第4033题有效K个不同元素子数组I
数据结构·python·算法·leetcode
十五喵源码网27 分钟前
基于SpringBoot2+vue2的公寓报修管理系统
java·毕业设计·springboot·论文笔记
珍珠先生28 分钟前
第16章 集合框架:List 与 Set
java
薛定猫AI1 小时前
【深度解析】DeepSeek Harness:可插拔智能体运行时如何连接大模型与真实计算机
java·运维·网络
rannn_1111 小时前
【力扣hot100】回溯专题|全排列、子集、字母组合、组合总和、括号生成、单词搜索、分割回文串、N皇后
java·算法·leetcode·回溯
旖旎夜光1 小时前
LCR 173:在点名(二分查找) —— 题解
数据结构·c++·算法·leetcode·二分查找