Skip to content

Commit bcb6262

Browse files
authored
Create three-divisors.py
1 parent 72e0be1 commit bcb6262

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/three-divisors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(sqrt(n))
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def isThree(self, n):
6+
"""
7+
:type n: int
8+
:rtype: bool
9+
"""
10+
cnt = 0
11+
i = 1
12+
while i*i <= n and cnt <= 3:
13+
if n%i == 0:
14+
cnt += 1 if i*i == n else 2
15+
i += 1
16+
return cnt == 3

0 commit comments

Comments
 (0)