관리 메뉴

솜씨좋은장씨

[leetCode] 633. Sum of Square Numbers (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 633. Sum of Square Numbers (Python)

솜씨좋은장씨 2020. 6. 19. 21:43
728x90
반응형

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.

 

Example 1:

Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5

Example 2:

Input: 3
Output: False

Solution

class Solution:  
    def judgeSquareSum(self, c): 
        for i in range(0,int(c**0.5)+1):  
            extra=c-pow(i, 2)  
            if (pow(int(extra**0.5),2)) == extra:  
                return True  
        return False 

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments