aboutsummaryrefslogtreecommitdiff
path: root/store/works/solutions/leetcode/cpp/69.c
diff options
context:
space:
mode:
Diffstat (limited to 'store/works/solutions/leetcode/cpp/69.c')
-rw-r--r--store/works/solutions/leetcode/cpp/69.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/store/works/solutions/leetcode/cpp/69.c b/store/works/solutions/leetcode/cpp/69.c
new file mode 100644
index 0000000..9914fff
--- /dev/null
+++ b/store/works/solutions/leetcode/cpp/69.c
@@ -0,0 +1,14 @@
+int mySqrt(int x) {
+ long long l = 0, r = x;
+
+ while (l != r) {
+ long long m = (l + r + 1) / 2;
+ if (m * m <= x) {
+ l = m;
+ } else {
+ r = m - 1;
+ }
+ }
+
+ return l;
+}