Python solution


  • 0
    H
    class Solution(object):
        def isPerfectSquare(self, num):
            """
            :type num: int
            :rtype: bool
            """
            if num<0:
                return False
            x,i=0,1
            while x<num:
                x+=i
                i+=2
            return x==num

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.