当前位置:网站首页>Sword finger offer14 the easiest way to cut rope
Sword finger offer14 the easiest way to cut rope
2022-07-03 12:50:00 【Mcc_ mingchao】

Analyzing the topic, we found , stay n<4 When , The maximum product is n-1( You have to cut ), be equal to 4 Cut into 2 Equal division , The product is 2, But more than 4 When , We can find out , Cut into several pieces with length of three , remainder <=4 Multiple line segments of , The bigger the product ( Because as long as it is greater than 4, Just cut it into pieces with one 3 The length must be larger than the product of other tangents , such as 5 Cut into pieces 2 3,6 Cut into pieces 3 3) such as 10 We are divided into 3 3 4, The product is 36,17 Cut into pieces 3 3 3 3 3 2 The product of 3^5*2. According to this principle We can easily make a while Cycle to achieve
class Solution {
public int cuttingRope(int n) {
if(n < 4){
return n - 1;
}
int res = 1;
while(n > 4){
res *= 3;
n -= 3;
//
}
return res * n;
}
}meanwhile 15 Cutting rope II of the question is to add a remainder operation on this basis
class Solution { public int cuttingRope(int n) { if(n<4){ return n-1; }long total=1; while(n>4){ total*=3; total=total%1000000007; n-=3; } return (int )(total*n%1000000007); } }
边栏推荐
- TOGAF认证自学宝典V2.0
- 【数据挖掘复习题】
- Sqoop1.4.4原生增量导入特性探秘
- Swift5.7 扩展 some 到泛型参数
- 初入职场,如何快速脱颖而出?
- Sword finger offer07 Rebuild binary tree
- 【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
- Export the entire Oracle Database
- Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
- Idea packages the web project into a war package and deploys it to the server to run
猜你喜欢

Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)

电压环对 PFC 系统性能影响分析
![Sword finger offer04 Search in two-dimensional array [medium]](/img/c4/002c951f8d914aaea4f4133685ebd1.png)
Sword finger offer04 Search in two-dimensional array [medium]

【数据库原理复习题】

Node.js: express + MySQL的使用

【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
![[problem exploration and solution of one or more filters or listeners failing to start]](/img/82/e7730d289c4c1c4800b520c58d975a.jpg)
[problem exploration and solution of one or more filters or listeners failing to start]

Solve the problem of VI opening files with ^m at the end

【ManageEngine】IP地址扫描的作用

社交社区论坛APP超高颜值UI界面
随机推荐
【習題七】【數據庫原理】
剑指Offer10- I. 斐波那契数列
Using swift language features, write a pseudo-random number generator casually
并网-低电压穿越与孤岛并存分析
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
[problem exploration and solution of one or more filters or listeners failing to start]
Public and private account sending prompt information (user microservice -- message microservice)
flinksql是可以直接客户端建表读mysql或是kafka数据,但是怎么让它自动流转计算起来呢?
Record your vulnhub breakthrough record
Lambda expression
强大的头像制作神器微信小程序
Is it safe to open an account for online stock speculation? Who can answer
Oh my Zsh + TMUX installation
Recovery of website address and method of Amazon account login two-step verification failure caused by mobile phone number becoming empty
JVM memory model
Everything comes to him who waits
Pytext training times error: typeerror:__ init__ () got an unexpected keyword argument 'serialized_ options'
【数据库原理复习题】
Method overloading and rewriting
T430 toss and install OS majave 10.14