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;
        }
    }
}
相关推荐
XXOOXRT12 分钟前
基于SpringBoot的加法计算器
java·spring boot·后端·html5
阿崽meitoufa15 分钟前
JVM虚拟机:垃圾收集器和判断对象是否存活的算法
java·jvm·算法
我是苏苏39 分钟前
C#高级:使用ConcurrentQueue做一个简易进程内通信的消息队列
java·windows·c#
heartbeat..2 小时前
数据库基础知识体系:概念、约束、范式与国产产品
java·数据库·学习笔记·国产数据库
PXM的算法星球2 小时前
【操作系统】哲学家就餐问题实现详解
java
2301_815357703 小时前
Java项目架构从单体架构到微服务架构的发展演变
java·微服务·架构
Ethan-D3 小时前
#每日一题19 回溯 + 全排列思想
java·开发语言·python·算法·leetcode
Echoo华地3 小时前
idea运行程序默认线程为daemon线程的问题
java·ide·intellij-idea
歪楼小能手3 小时前
Android16系统go版关闭重力旋转开关后缺失手动旋转屏幕悬浮按钮
android·java·平板
Coder_Boy_3 小时前
基于SpringAI的在线考试系统-DDD业务领域模块设计思路
java·数据库·人工智能·spring boot·ddd