当前位置:网站首页>[binary search - simple] 441 Arrange coins
[binary search - simple] 441 Arrange coins
2022-04-21 15:11:00 【Caicai 2022】
【 subject 】
【 Code 】
Execution time :40 ms, In all Python3 Defeated in submission 82.23% Users of
Memory consumption :14.8 MB, In all Python3 Defeated in submission 93.27% Users of
Pass the test case :1335 / 1335
class Solution:
def arrangeCoins(self, n: int) -> int:
def cal(n):
return (1+n)*n//2
line1=1
linen=n
while line1<=linen:
mid=line1+(linen-line1)//2
if cal(mid)==n:
return mid
elif cal(mid)<n:
line1=mid+1
elif cal(mid)>n:
linen=mid-1
return line1-1
class Solution:
def arrangeCoins(self, n: int) -> int:
def cal(n):
return (1+n)*n//2
line1=1
linen=n
while line1<=linen:
mid=line1+(linen-line1)//2
if cal(mid)==n:
return mid
elif cal(mid)<n:
line1=mid+1
elif cal(mid)>n:
linen=mid-1
return linen
版权声明
本文为[Caicai 2022]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211507333009.html
边栏推荐
- MongoDB分组查询
- MySQL8.0零基础入门之从青铜到钻石
- Cousin node-c language of binary tree
- MYSQL 第1章 数据库简介
- In the digital age, how can SaaS software become a light cavalry replaced by localization?
- ThreadLocal应用及原理解析
- 【二分查找-简单】69. x 的平方根
- Minimum steps of manufacturing letter ectopic words - C language solution
- Shang Silicon Valley smart campus - 6. Realization of administrator function
- SWOOLE高性能内存数据库的使用和配置教程
猜你喜欢

阿里P9详解高并发,带你了解淘宝怎么抗住双11等大型秒杀活动

【天梯赛】L2-040 哲哲打游戏 (25 point(s))(模拟)

嵌入式开发:重新利用开发板进行测试的3个技巧

MySQL 8.0.11 installation tutorial (Windows version)

In the digital age, how can SaaS software become a light cavalry replaced by localization?

解锁OpenHarmony技术日!年度盛会,即将揭幕!

Libmysql.com in vs2019 Lib garbled code

Mysql database (3)

突然掉电,为啥MySQL也不会丢失数据?(收藏)

基于JSP的公益网站设计与实现
随机推荐
关于Signal Catcher线程中对线程的理解
干货 | 移动端App自动化之App控件定位
Insect makefile
Storage system and memory
虫子 Makefile
Tutoriel de développement d'applications SAP ui5 70 - Comment utiliser un contrôle de bouton pour déclencher un saut de routage de page
Detailed explanation of basic knowledge of database 5: index and its two engines in mysql, master-slave replication and relational / non relational database
让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
The conversion between RDD and dataframe in pyspark is realized by RDD processing dataframe: data segmentation and other functions
ENSP三层交换机连接二层交换机及路由器的做法
Software testing (III) p51-p104 software test case methods and defects
&lt;译文&gt;设置Prometheus并将其与Grafana集成以进行监控
SAP UI5 应用开发教程之七十 - 如何使用按钮控件触发页面路由跳转
使用wx.showActionSheet选择框修改数据库中的信息,为什么会报data未定义的错呢
专题测试04·多元函数微分学【李艳芳全程班】
Manually adjust slf4j the log level
Druid database link problem
融云首席科学家任杰:互联网兵无常势,但总有人正年轻
【云驻共创】华为云数据库-基础知识
软件测试(三)p51-p104 软件测试用例方法、缺陷