Skip to content

Commit 72e0be1

Browse files
authored
Create three-divisors.cpp
1 parent 01bbf09 commit 72e0be1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

C++/three-divisors.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(sqrt(n))
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool isThree(int n) {
7+
int cnt = 0;
8+
for (int i = 1; i <= n / i && cnt <= 3; ++i) {
9+
if (n % i == 0) {
10+
cnt += (i == n / i) ? 1 : 2;
11+
}
12+
}
13+
return cnt == 3;
14+
}
15+
};

0 commit comments

Comments
 (0)