We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e0ec6c4 commit b206168Copy full SHA for b206168
Day 9 Valid Perfect Square.cpp
@@ -0,0 +1,42 @@
1
+PROBLEM:
2
+
3
4
+Given a positive integer num, write a function which returns True if num is a perfect square else False.
5
6
+Note: Do not use any built-in library function such as sqrt.
7
8
+Example 1:
9
10
+Input: 16
11
+Output: true
12
+Example 2:
13
14
+Input: 14
15
+Output: false
16
17
18
19
+SOLUTION:
20
21
22
+class Solution {
23
+public:
24
+ bool isPerfectSquare(int num) {
25
26
+ long long i,a,b;
27
28
+ for(i=1;i*i<=num;i++)
29
+ {
30
+ if(num%i==0)
31
32
+ a=num/i;
33
+ b=i;
34
35
+ if(a==b)
36
+ return true;
37
+ }
38
39
40
+ return false;
41
42
+};
0 commit comments