Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddb221a

Browse files
find Squareroot of number
1 parent c8e5e2e commit ddb221a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.leetcode.solution;
2+
3+
public class StringMatch {
4+
5+
public static void main(String[] args) {
6+
7+
Squareroot sr=new Squareroot();
8+
double result= sr.mySqrt(16);
9+
System.out.println(result);
10+
11+
12+
13+
}
14+
}
15+
class Squareroot {
16+
public int mySqrt(int x) {
17+
18+
if(x < 2) return x;
19+
int low = 1, high = x / 2, mid;
20+
while(low <= high){
21+
mid = (low + high) / 2;
22+
if(mid == x / mid) return mid;
23+
else if(mid < x / mid) low = mid + 1;
24+
else high = mid - 1;
25+
}
26+
return high;
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /