Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 1.25 KB

File metadata and controls

52 lines (35 loc) · 1.25 KB

367. Valid Perfect Square - 有效的完全平方数

给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。

说明:不要使用任何内置的库函数,如  sqrt

示例 1:

输入:16
输出:True

示例 2:

输入:14
输出:False

题目标签:Math / Binary Search

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
python3 44 ms N/A
class Solution:
    def isPerfectSquare(self, num):
        """
        :type num: int
        :rtype: bool
        """
        if num % 10 in (2, 3, 7, 8):
            return False
        i = 1
        while num > 0:
            num -= i
            if num == 0:
                return True
            i += 2
        return False