File tree 1 file changed +11
-27
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +11
-27
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 367. Valid Perfect Square
5
- *
6
- * Given a positive integer num, write a function which returns True if num is a perfect square else False.
7
-
8
- Note: Do not use any built-in library function such as sqrt.
9
-
10
- Example 1:
11
-
12
- Input: 16
13
- Returns: True
14
- Example 2:
15
-
16
- Input: 14
17
- Returns: False
18
- */
19
3
public class _367 {
20
4
21
- public static class Solution1 {
22
- public boolean isPerfectSquare (int num ) {
23
- long i = 1 ;
24
- long temp = 1 ;
25
- while (temp < num ) {
26
- i += 2 ;
27
- temp += i ;
28
- }
29
- return temp == num ;
30
- }
31
- }
5
+ public static class Solution1 {
6
+ public boolean isPerfectSquare (int num ) {
7
+ long i = 1 ;
8
+ long temp = 1 ;
9
+ while (temp < num ) {
10
+ i += 2 ;
11
+ temp += i ;
12
+ }
13
+ return temp == num ;
14
+ }
15
+ }
32
16
}
You can’t perform that action at this time.
0 commit comments