summaryrefslogtreecommitdiff
path: root/leetcode
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-04-05 20:45:07 +0800
committercrupest <crupest@outlook.com>2021-04-05 20:45:07 +0800
commit7d658905c737287476d8da546fc53a2c23c89571 (patch)
tree2f6a5e4ff0ccfa84f0da4f1bb9fd5859e949c4f7 /leetcode
parent9c5636025aa91333baaa16e81a43ce3f488ef785 (diff)
downloadsolutions-7d658905c737287476d8da546fc53a2c23c89571.tar.gz
solutions-7d658905c737287476d8da546fc53a2c23c89571.tar.bz2
solutions-7d658905c737287476d8da546fc53a2c23c89571.zip
Add leetcode 69.
Diffstat (limited to 'leetcode')
-rw-r--r--leetcode/cpp/69.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/leetcode/cpp/69.c b/leetcode/cpp/69.c
new file mode 100644
index 0000000..9914fff
--- /dev/null
+++ b/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;
+}