Valid Perfect Square

所有的平方数都是由1,3,5,7,9,11...这样的奇数相加构成的

class Solution(object):
    def isPerfectSquare(self, num):
        """
        :type num: int
        :rtype: bool
        """
        count = 1
        while num > 0:
            num -= count
            count += 2
        return num == 0

results matching ""

    No results matching ""