【leetcode】367. Valid Perfect Square【M】【35】

OpenCV C++ 图像处理实战 ——《基于轮廓比对的缺陷检测》 本文使用OpenCV C++ 实现基于轮廓比对的缺陷检测。 阅读详情

Given a positive integer num, write a function which returns True if num is a perfect square else False.

Note: Do not use any built-in library function such as sqrt.

Example 1:

Input: 16
Returns: True

Example 2:

Input: 14
Returns: False

Credits:
Special thanks to @elmirap for adding this problem and creating all test cases.


Subscribe to see which companies asked this question


最开始的想法是,从1~num/2挨个枚举,看看有没有是它的平方的,后来一想,直接挨个算,算到平方超过这个数,就结束。。



class Solution(object):
	def isPerfectSquare(self, num):
		i = 1
		#res = 1
		while 1:#i <= num:
			#print res
			res = i**2
			if res > num:
			    return False
			if res == num:
				return True
			i += 1
			#res += i+i-1
		return False


097、Zephyr RTOS驱动开发实战:传感器驱动(陀螺仪) I2C速率别设太高:LSM6DSO支持最高400kHz,但实际布线有寄生电容时,400kHz容易出错。工业产品我统一用100kHz,稳定压倒一切。FIFO水印值要计算:假设ODR=6.66kHz,每150us产生一组数据,如果水印设32组,则每4.8ms触发一次中断。这个间隔要大于I2C读取耗时(实测约200us),否则中断堆积。电源纹波敏感:陀螺仪对电源噪声敏感,特别是3.3V供电时。我遇到过因为DC-DC纹波太大,陀螺仪输出噪声从0.1dps飙升到2dps。 阅读详情

相关推荐

STM32 HAL库串口DMA接收不定长数据的两种实战方法:IDLE中断与超时管理详解

本文详细解析了STM32 HAL库中串口DMA接收不定长数据的两种实战方法:IDLE中断与超时管理。通过对比分析两种方案的硬件要求、响应速度和适用场景,为嵌入式开发者提供了高效可靠的串口通信解决方案,特别适用于智能家居、传感器网络等需要处理不定长数据包的应用场景。

weixin_30954265的博客 471

[leetcode-367]Valid Perfect Square(java)

这道题利用了如下一个数学公式 1+3+5+..+(2N-1) == N^2; 因此我们从1开始累加即可,加法的速度要比乘法的速度快得多,而且还不用考虑一不小心就溢出的问题。代码如下:public class Solution { public boolean isPerfectSquare(int num) { for(int i = 1;num > 0;i+=2)

中华胡杨的专栏 1223

从ADS到HFSS:耦合线带通滤波器的设计与模型转换实战

本文详细介绍了耦合线带通滤波器的完整设计流程,重点阐述了从ADS电路级快速优化到HFSS三维电磁场精确验证的模型转换实战方法。通过对比ADS理想模型仿真与HFSS全波仿真结果,指导读者进行参数校准与迭代优化,并分享了关键的板材选择、加工误差及端口设置等避坑指南,确保设计性能与实物测试高度一致。

weixin_29290863的博客 344

[leetcode]367. Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt.class Solution { public: bool is

github_35095990的博客 438

汇川机器人与PLC通信-ModbusTCP超详细案例

通过汇川机器人与PLC的ModbusTCP通信项目案例,我们可以了解通讯配置的过程,地址映射的方式,对接信号的转换,运行时序的逻辑等注意事项,帮助我们快速应用到项目中。

weixin_44166380的博客 1万+

支付漏洞防护绕过的一种方式

放完包后就到了提交订单的地方,可以发现,金额确实小了很多,合理的搭配的话还可以更低,再次前进可以发现,金额确实是这么多,后面就不支付了,到此就结束了。也就是说数量可以为负数,但是金额不能为0或者0以下,有什么方法可以绕过这个限制吗,其实并不难,既然可以为负数,只是对金额不能为0或者负数做了限制。我们可以尝试拼接法,利用负数加上正数让他的值变得很低,但是又大于0就可以了,这里利用购物车的结算方法,随机加一些在购物车里。这里为了方便查看数据包,我这边商品的数量选择3,点击立即购买并抓包。

2301_80115097的博客 1529

367. Valid Perfect Square

题目: Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input:

StudingCoder的博客 351

2026年广东省职业院校技能大赛中职组“大数据应用与服务”样题一完整参考答案

2026年广东省职业院校技能大赛中职组“大数据应用与服务”样题一完整参考答案

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 744

C#LeetCode刷题之#367-有效的完全平方数(Valid Perfect Square)

问题 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。 说明:不要使用任何内置的库函数,如 sqrt。 输入:16 输出:True 输入:14 输出:False Given a positive integer num, write a function which returns True if num is ...

比特飞 1万+

46、聚类算法在智能交通数据分析中的应用

本文探讨了聚类算法在智能交通数据分析中的应用,介绍了K-均值算法、K-中心点算法和基于模型的聚类算法的基本原理及特点,并结合实际交通数据讨论了其应用场景与挑战。通过聚类分析,能够从海量交通数据中发现隐藏模式,为交通管理和规划提供科学依据。文章还展示了具体的案例分析和实现流程,为未来智能交通系统的发展提供了参考。

zz67890的博客 133

如何懂固高卡以及滚筒轴+平移轴配合运动?

🏆本文收录于专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家!持续更新中,up!up!up!!

**My Coding Family** 847

【leetcode】(python) 367. Valid Perfect Square有效的完全数

有效的完全数DescriptionExample题意思路1 二分法code思路2 牛顿迭代法code Description Valid Perfect Square Easy Given a positive integer num, write a function which returns True if num is a perfect square else False. Note...

。 445

华为OD机考双机位C卷 - 评委评分 (Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 评委评分 (OD上机考试双机位C卷)。提供在线OJ刷题。Java、C++、Python、GO语言、C语言、JavaScript题解,并提供完整思路讲解。

算法大师! 1750

367. Valid Perfect Square(python+cpp)(c++代码超时

题目: Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Output:...

小湉湉的博客 367

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【leetcode】463. Island Perimeter【E】

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely

sscssz的博客 1405

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【leetcode】453. Minimum Moves to Equal Array Elements【E】

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,3] Ou

sscssz的博客 978

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

50. Pow(x, n) 【M】【62】

Implement pow(x, n). Subscribe to see which companies asked this question 最开始肯定是用x ** n,当然这个太无赖。 开始自己实现,首先想的是,每次平方,但是遇到2^k - 1这种,就等于没有量级上的优化,肯定是超时了。 提示是二分法,那就增加一个字典,来存这

sscssz的博客 907

【leetcode】462. Minimum Moves to Equal Array Elements II【M】

Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by

sscssz的博客 853

【Leetcode】397. Integer Replacement QuestionEditorial Solution【E】

Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1. What is the minimum number o

sscssz的博客 654

【LeetCode】492. Construct the Rectangle【E】【73】

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L

sscssz的博客 642

【leetcode】414. Third Maximum Number【E】【85】

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2,

sscssz的博客 596

233. Number of Digit One【H】【33】【再来一遍】

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. For example: Given n = 13, Return 6, because digit 1 occurred in the followin

sscssz的博客 569

43. Multiply Strings 【66】【M】

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative.Converting the input string to integ

sscssz的博客 565

【leetcode】423. Reconstruct Original Digits from English【M】【95】

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order. Note: Input contains only lowercase English letters.Input is g

sscssz的博客 548

304. Range Sum Query 2D - Immutable 【M】【27】

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2). The above rectangle (with the red bord

sscssz的博客 489

【leetcode】441. Arranging Coins【E】

You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed.

sscssz的博客 484
上一篇: 【leetcode】371. Sum of Two Integers【E】
下一篇: 【leetcode】69. Sqrt(x)【M】【74】
Vicky_Vicky_990121
博客等级 码龄14年 23粉丝 187原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值