From 02df09d6e18db2380028e82923ccaba3bfbbec0d Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 5 Apr 2021 20:45:07 +0800 Subject: import(solutions): Add leetcode 69. --- works/solutions/.editorconfig | 3 +++ works/solutions/leetcode/cpp/69.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 works/solutions/leetcode/cpp/69.c (limited to 'works') diff --git a/works/solutions/.editorconfig b/works/solutions/.editorconfig index 0cc28a1..28365d2 100644 --- a/works/solutions/.editorconfig +++ b/works/solutions/.editorconfig @@ -1,2 +1,5 @@ +[*.c] +tab_width = 2 + [*.cpp] tab_width = 2 diff --git a/works/solutions/leetcode/cpp/69.c b/works/solutions/leetcode/cpp/69.c new file mode 100644 index 0000000..9914fff --- /dev/null +++ b/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; +} -- cgit v1.2.3