Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/money89757/Linux-Book
Browse files Browse the repository at this point in the history
  • Loading branch information
money89757 committed May 16, 2018
2 parents 881d0ab + 2e039ae commit 8976400
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 算法/LeetCode/mySqrt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>

int mySqrt(int x)
{
long long i = 0;
long long j = x/2+1;
while(i <= j)
{
long long mid = (i+j) / 2;
long long sq = mid * mid;
if(sq == x)
return mid;
else if(sq < x)
i = mid + i;
else
j = mid - 1;
}

return j;
}


int main(int argc, const char *argv[])
{
int num;
scanf("%d",&num);
int number = mySqrt(num);

printf("mySqrt = %d",number);
return 0;
}

0 comments on commit 8976400

Please sign in to comment.