aboutsummaryrefslogtreecommitdiff
path: root/store/works/solutions/leetcode/cpp/69.c
blob: 9914fff2520116a1fb38ce2caf275b8ea00dbc02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}