-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path367.valid-perfect-square.cpp
More file actions
50 lines (49 loc) · 895 Bytes
/
Copy path367.valid-perfect-square.cpp
File metadata and controls
50 lines (49 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* @lc app=leetcode id=367 lang=cpp
*
* [367] Valid Perfect Square
*
* https://leetcode.com/problems/valid-perfect-square/description/
*
* algorithms
* Easy (43.19%)
* Likes: 2587
* Dislikes: 246
* Total Accepted: 394.4K
* Total Submissions: 913.3K
* Testcase Example: '16'
*
* Given a positive integer num, write a function which returns True if num is
* a perfect square else False.
*
* Follow up: Do not use any built-in library function such as sqrt.
*
*
* Example 1:
* Input: num = 16
* Output: true
* Example 2:
* Input: num = 14
* Output: false
*
*
* Constraints:
*
*
* 1 <= num <= 2^31 - 1
*
*
*/
// @lc code=start
class Solution
{
public:
bool isPerfectSquare(int num)
{
for (int i = 1; i < 46341 && i * i <= num; i++)
if (i * i == num)
return true;
return false;
}
};
// @lc code=end