当前位置:网站首页>剑指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;
}
}
边栏推荐
- Linux系统安装mysql(rpm方式安装)
- STM32——DMA
- Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
- Lock wait timeout exceeded解决方案
- Centos7 install mysql5.7 steps (graphical version)
- Sql解析转换之JSqlParse完整介绍
- Mysql应用安装后找不到my.ini文件
- C语言教程(一)-准备
- 剑指offer专项突击版 ---- 第1天
- MySQL优化:从十几秒优化到三百毫秒
猜你喜欢
CentOS7 —— yum安装mysql
MySQL-Explain详解
剑指offer专项突击版 --- 第 3 天
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
DVWA shooting range environment construction
Three oj questions on leetcode
ES source code API call link source code analysis
工作流编排引擎-Temporal
sql语句之多表查询
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
随机推荐
可点击也可直接复制指定内容js
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
DVWA靶场环境搭建
Unity resources management series: Unity framework how to resource management
Kubernetes 证书可用年限修改
工作流编排引擎-Temporal
账号或密码多次输入错误,进行账号封禁
[MQ I can speak for an hour]
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
MySQL_关于JSON数据的查询
Summary of MySQL common interview questions (recommended collection!!!)
Interviewer, don't ask me to shake hands three times and wave four times again
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
剑指offer专项突击版 ---- 第 6 天
【LeetCode-SQL每日一练】——2. 第二高的薪水
MySQL优化之慢日志查询
剑指offer专项突击版 --- 第 3 天
快速掌握并发编程 --- 基础篇
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
Centos7 install mysql5.7