//GitHub https://github.com/vellimole0621
vellimole0621 - Overview
キム・ヒョンギュ . vellimole0621 has 6 repositories available. Follow their code on GitHub.
github.com
367. Valid Perfect Square
문제 - https://leetcode.com/problems/valid-perfect-square/
Valid Perfect Square - LeetCode
Can you solve this real interview question? Valid Perfect Square - Given a positive integer num, return true if num is a perfect square or false otherwise. A perfect square is an integer that is the square of an integer. In other words, it is the product o
leetcode.com
문제 설명
Given a positive integer num, return true if num is a perfect square or false otherwise.
A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.
You must not use any built-in library function, such as sqrt.
=> 제곱근이 정수인지, 확인하라.
내 풀이
math.sqrt() 함수를 이용해서 제곱근을 구하고, 소수 첫째자리가 0인지 확인
# https://leetcode.com/problems/valid-perfect-square/
# 367. Valid Perfect Square
import math
class Solution:
def isPerfectSquare(self, num: int) -> bool:
if (math.sqrt(num) * 10) % 10 == 0.0:
return True
else:
return False
'프로그래밍 > Python' 카테고리의 다른 글
[파이썬 Python/알고리즘] LeetCode - Richest Customer Wealth (0) | 2023.07.30 |
---|---|
[파이썬 Python/알고리즘] LeetCode - Integer to Roman (0) | 2023.07.29 |
[파이썬 Python/알고리즘] LeetCode - Unique Paths (0) | 2023.07.16 |
[파이썬 Python/알고리즘] LeetCode - Single Number II (0) | 2023.07.04 |
[파이썬 Python/알고리즘] LeetCode - Buddy Strings (0) | 2023.07.03 |