Skip to content

Commit d18732e

Browse files
authored
Merge pull request #3756 from NotADucc/0069
create csharp/0069-sqrt.cs
2 parents 986f35a + 9898f4b commit d18732e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

csharp/0069-sqrtx.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Solution
2+
{
3+
public int MySqrt(int x)
4+
{
5+
int left = 0, right = x;
6+
while (left <= right)
7+
{
8+
int mid = (left + right) >> 1;
9+
long pow = (long)mid * mid;
10+
if (pow <= x)
11+
{
12+
left = mid + 1;
13+
}
14+
else
15+
{
16+
right = mid - 1;
17+
}
18+
}
19+
return left - 1;
20+
}
21+
}

0 commit comments

Comments
 (0)