From 8634595c4dfa3c10c844180a6cfc23941165b7a1 Mon Sep 17 00:00:00 2001 From: chw9 <43727884+chw9@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:57:09 -0400 Subject: [PATCH] added algorithm for 0367 --- LeetCode/0367_ValidPerfectSquare.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 LeetCode/0367_ValidPerfectSquare.py diff --git a/LeetCode/0367_ValidPerfectSquare.py b/LeetCode/0367_ValidPerfectSquare.py new file mode 100644 index 0000000..d6c025b --- /dev/null +++ b/LeetCode/0367_ValidPerfectSquare.py @@ -0,0 +1,15 @@ +class Solution(object): + def isPerfectSquare(self, num): + """ + :type num: int + :rtype: bool + """ + + i = 1 + sum_odds = 0 + while sum_odds < num: + sum_odds += i + if sum_odds == num: + return True + i += 2 + return False \ No newline at end of file