summaryrefslogtreecommitdiff
path: root/0069
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-09-06 23:17:22 +0800
committerMistivia <i@mistivia.com>2025-09-06 23:17:41 +0800
commitad95cba8220e2a7c86362caeb76e1a4333e9c2b8 (patch)
tree30b31d94e2ceb46d4e946bfa1eb88b956508f760 /0069
parent5dd8dcdc2ccfa89d25a3cb342a2f89c644236971 (diff)
refactor
Diffstat (limited to '0069')
-rw-r--r--0069/main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/0069/main.c b/0069/main.c
new file mode 100644
index 0000000..86aab4a
--- /dev/null
+++ b/0069/main.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int mySqrt(int x) {
+ int64_t t = x;
+ int64_t ln = 0, rn = x;
+ while (ln <= rn) {
+ int64_t mid = ln + (rn - ln) / 2;
+ if (mid * mid < x) {
+ if ((mid + 1) * (mid + 1) > x) {
+ return mid;
+ }
+ ln = mid + 1;
+ } else if (mid * mid > x) {
+ rn = mid - 1;
+ } else {
+ return mid;
+ }
+ }
+ return -1;
+}
+
+int main() {
+ printf("%d\n", mySqrt(9));
+ return 0;
+}