Two methords used Python


  • 0
    W

    One is this:

    class Solution(object):
        def isPerfectSquare(self, num):
            """
            :type num: int
            :rtype: bool
            """
            newNum = int(num**(0.5))
            return newNum**2==num
    

    And this:(compare the length)

    class Solution(object):
        def isPerfectSquare(self, num):
            """
            :type num: int
            :rtype: bool
            """
    
            if (len(str(math.sqrt(num)))-len(str(int(math.sqrt(num))))>2):
                    return False
            return True
    

    Third:(maybe binary search is effictive)

    Binary search:.....
    

Log in to reply
 

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