技术栈

Java | Leetcode Java题解之第343题整数拆分

m0_571957582024-08-18 22:10

题目:

题解:

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;
        }
    }
}
上一篇:已解决:java.net.BindException: 地址已在使用
下一篇:Java TCP练习1
相关推荐
夕除
6 分钟前
Mysql--15
java·数据库·mysql
smileNicky
11 分钟前
Linux 系列从多节点的catalina 日志中统计设备调用频次
java·linux·服务器
AlenTech
23 分钟前
647. 回文子串 - 力扣(LeetCode)
算法·leetcode·职场和发展
py有趣
27 分钟前
力扣热门100题之合并两个有序链表
算法·leetcode·链表
赵丙双
34 分钟前
spring boot 排除自动配置类的方式和原理
java·spring boot·自动配置
8Qi8
42 分钟前
LeetCode热题100--45.跳跃游戏 II
java·算法·leetcode·贪心算法·编程
bilI LESS
1 小时前
Spring Boot接收参数的19种方式
java·spring boot·后端
Chan16
1 小时前
MCP 开发实战:Git 信息查询 MCP 服务开发
java·开发语言·spring boot·git·spring·java-ee·intellij-idea
九皇叔叔
1 小时前
004-SpringSecurity-Demo 拆分环境
java·springboot3·springsecurity
北顾笙980
1 小时前
day12-数据结构力扣
数据结构·算法·leetcode
热门推荐
01GitHub 镜像站点02Qwen3.5-Omni与Qwen3.6模型全面解析(含测评/案例/使用教程)032026年3月AI领域大事件:DeepSeek引领开源风暴04黄金未来走势预测05Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services06AI 编程效率翻倍:Superpowers Skills 上手清单 + 完整指南07Mac 本地部署 OMLX + 通义千问 Qwen3.5-27B 保姆级教程08UV安装并设置国内源09让 Trae IDE 智能体 “读懂”文档 Excel+PDF+DOCX :mcp-documents-reader 工具使用指南10“wsl --install -d Ubuntu-22.04”下载慢,中国地区离线安装 Ubuntu 22.04 WSL方法(亲测2025年5月6日)