Skip to content

Commit f713da4

Browse files
authored
Create 069. Sqrt(x).java
1 parent 2c1b7b3 commit f713da4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

069. Sqrt(x).java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Solution {
2+
public int mySqrt(int x) {
3+
if (x <= 0) { return x; }
4+
else {
5+
// Binary/Newton's
6+
long r = x;
7+
while (r*r > x)
8+
r = (r + x/r) / 2;
9+
return (int) r;
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)