当前位置:网站首页>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;
}
边栏推荐
- Mysql配置主从数据库
- How to implement observer mode
- Idea auto completion
- 商业智能BI的未来,如何看待AI+BI这种模式?
- The principle of session and cookie
- Pytoch Summary - transform between sensor and numpy
- SPI drive of lsm6dsl
- Wechat applet sub components transfer values to the page (communication between parent and child components) with source code
- UE4 compile a single file (VS and editor start respectively)
- Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
猜你喜欢

Gd32f4xx Ethernet chip (ENC28J60) driver migration

遍历vector容器中的对象的方式

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION

1.4 regression of machine learning methods

Yotact real-time instance segmentation

Segmentation of Head and Neck Tumours Using Modified U-net

Kicad learning notes - shortcut keys

UE4 blueprint modify get a copy in array to reference

Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear

Factory mode
随机推荐
Simplicity studio does not recognize the new JLINK V9 solution
数据治理:数据治理在数据中台下的解决方案
UE4 VS的Visual Assist插件设置
Pytorch summary learning series - broadcast mechanism
Five heart charity matchmaker team
UE4 compile a single file (VS and editor start respectively)
Basic operations of MAC MySQL database
Research progress of target detection in the era of deep convolutional neural network
你知道BFD是什么吗?一文详解BFD协议原理及使用场景
HB5470民用飞机机舱内部非金属材料燃烧测试
Data governance: Metadata Management (Part 2)
GD32F4xx 以太網芯片(enc28j60)驅動移植
How to do unit test well
UE4 动画重定向
KiCad学习笔记--快捷键
Gd32f4xx Ethernet chip (ENC28J60) driver migration
How to set Google Chrome as the default browser
Wechat applet user refuses to authorize geographic location information and calls up the authorization window again
MATLAB小技巧(21)矩阵分析--偏最小二乘回归
用户级线程和内核级线程