当前位置:网站首页>剑指offer基础版 --- 第24天
剑指offer基础版 --- 第24天
2022-07-31 05:09:00 【米兰的小红黑】
class Solution {
public int cuttingRope(int n) {
int[] dp = new int[n + 1];
dp[2] = 1;
for(int i = 3; i <= n; i++){
for(int j = 2; j < i; j++){
dp[i] = Math.max(dp[i],Math.max(j * (i - j),j * dp[i - j]));
}
}
return dp[n];
}
}
class Solution {
public int[][] findContinuousSequence(int target) {
int i = 1, j = 2, s = 3;
List<int[]> res = new ArrayList<>();
while(i < j) {
if(s == target) {
int[] ans = new int[j - i + 1];
for(int k = i; k <= j; k++)
ans[k - i] = k;
res.add(ans);
}
if(s >= target) {
s -= i;
i++;
} else {
j++;
s += j;
}
}
return res.toArray(new int[res.size()][]);
}
}
class Solution {
public int lastRemaining(int n, int m) {
int ans = 0;
// 最后一轮剩下2个人,所以从2开始反推
for (int i = 2; i <= n; i++) {
ans = (ans + m) % i;
}
return ans;
}
}
边栏推荐
- 账号或密码多次输入错误,进行账号封禁
- 110道 MySQL面试题及答案 (持续更新)
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
- SQL statement to range query time field
- What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
- Anaconda配置环境指令
- C语言如何分辨大小端
- 有了MVC,为什么还要DDD?
- STM32 - DMA
猜你喜欢
centos7安装mysql5.7步骤(图解版)
MYSQL下载及安装完整教程
Linux系统安装mysql(rpm方式安装)
centos7安装mysql5.7
Interviewer, don't ask me to shake hands three times and wave four times again
SQL行列转换
matlab abel变换图片处理
MySQL8.0.26安装配置教程(windows 64位)
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
随机推荐
.NET-9. A mess of theoretical notes (concepts, ideas)
剑指offer专项突击版 ---- 第 6 天
Unity mobile game performance optimization series: performance tuning for the CPU side
What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
剑指offer专项突击版 ---第 5 天
工作流编排引擎-Temporal
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
可点击也可直接复制指定内容js
目标检测学习笔记
Reference code series_1. Hello World in various languages
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
sql statement - how to query data in another table based on the data in one table
基于flask的三方登陆的流程
快速掌握并发编程 --- 基础篇
numpy和pytorch中的元素拼接操作:stack,concatenat,cat
On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
Flask 的初识
Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
Kubernetes 证书可用年限修改