-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqrtx69.java
More file actions
39 lines (36 loc) · 794 Bytes
/
Sqrtx69.java
File metadata and controls
39 lines (36 loc) · 794 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
package com.leetcode.problems;
class Solution69 {
public int mySqrt(int x) {
if(x==0)
{
return 0;
}
if(x==1||x==2)
{
return 1;
}
for (int i = 1; i <= x/2; i++) {
if(i>=46335&&i<47000)
{
System.out.println(i*i);
}
if(i*i<=x && (i+1)*(i+1)>x)
{
return i;
}
if(i*i<=x&&(i+1)*(i+1)<0)
{
return i;
}
}
return 1;
}
}
public class Sqrtx69 {
public static void main(String[] args) {
Solution69 s = new Solution69();
for (int i = 0; i < 100; i++) {
System.out.println(i+" " + s.mySqrt(i));
}
}
}