当前位置:网站首页>367. effective complete square dichotomy
367. effective complete square dichotomy
2022-06-29 09:44:00 【Mr Gao】
367. Effective complete square number
Given a Positive integer num , Write a function , If num It's a complete square , Then return to true , Otherwise return to false .
Advanced : Don't Use any built-in library functions , Such as sqrt .
Example 1:
Input :num = 16
Output :true
Example 2:
Input :num = 14
Output :false
We should first think of the dichotomy , It's important , Can greatly reduce the time complexity , We can learn more about this method :
bool isPerfectSquare(int num){
int low=0;
int high=num;
long long p=(low+high)/2;
//printf("%d ",p);
while(p*p!=num&&low<=high){
if(p*p>num){
high=p-1;
p=(low+high)/2;
}
else{
low=p+1;
p=(low+high)/2;
}
}
printf("%d ",p);
if(p*p==num){
return true;
}
return false;
}
边栏推荐
- Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation
- Reading notes on how to connect the network - Web server request and response (V)
- Pytorch Summary - sensor on GPU
- es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
- 基于PyQt5和Qt Designer的简易加法计算器的制作
- CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
- Pytorch summary learning series - operation
- Pytorch Summary - Automatic gradient
- Chang'an chain go language smart contract writing and compilation
- 数据可视化:数据可视化四象限,教你正确应用图标
猜你喜欢

Introduction to Chang'an chain data storage and construction of MySQL storage environment

Summary of 3DMAX jamming, white screen and rendering crash

Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks

Simplicity Studio无法识别新买的JLink v9解决方法

Mongodb persistence

Closed training (25) basic web security

LC236. 二叉树的最近公共祖先

1424. 对角线遍历 II

如何将谷歌浏览器设置为默认浏览器

Factory mode
随机推荐
[noi Simulation Competition] add points for noi (heavy chain dissection, line segment tree)
Pytorch summary learning series - data manipulation
Simplicity studio does not recognize the new JLINK V9 solution
Implementation of multi key state machine based on STM32 standard library
LeetCode刷题——泰波那契数列
转载 :判断对象是否具有属性的5种方法
UE4 蓝图修改Array 中Get a copy 为 reference
基于PyQt5和Qt Designer的简易加法计算器的制作
UE4 installs the datasmith plug-in in version 4.20-23
通识篇:原型设计的认知,设计及最佳实践
Find the most repeated element in the string
3DMax 卡死、白屏、渲染死机问题总结
Five heart charity matchmaker team
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
数据治理:数据治理在数据中台下的解决方案
In the era of data processing, data quality construction is the way for enterprises to survive
Wechat applet sub components transfer values to the page (communication between parent and child components) with source code
你必须知道的23个最有用的Elasticseaerch检索技巧
Invalidconnectionattributeexception exception exception handling
The principle of session and cookie