관리 메뉴

솜씨좋은장씨

[leetCode] 367. Valid Perfect Square (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 367. Valid Perfect Square (Python)

솜씨좋은장씨 2021. 1. 25. 00:30
728x90
반응형

Given a positive integer num, write a function which returns True if num is a perfect square else False.

Follow up: Do not use any built-in library function such as sqrt.

 

Example 1:

Input: num = 16
Output: true

Example 2:

Input: num = 14
Output: false

Constraints:

  • 1 <= num <= 2^31 - 1

Solution

 class Solution:
    def isPerfectSquare(self, num: int) -> bool:
        sqrt_num = num ** 0.5
        
        answer = False
        
        if sqrt_num == int(sqrt_num):
            answer = True
            
        return answer

 

SOMJANG/CODINGTEST_PRACTICE

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

github.com

Comments