1 line Python


  • 0

    Just check it one by one from 0 to sqrt(c), very straight forward.

    class Solution(object):
        def judgeSquareSum(self, c):
            """
            :type c: int
            :rtype: bool
            """
            return any(c - a*a == int((c - a*a) ** 0.5) ** 2 for a in range(int(c ** 0.5) + 1))
    

Log in to reply
 

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