Skip to content

Commit fca0598

Browse files
committed
create csharp/0069-sqrt.cs
1 parent 9014b37 commit fca0598

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

csharp/0069-sqrt.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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy