feat: add LeetCode problem 69 (#1259)

* feat: add LeetCode problem 69

Here is the code for the problem 69 of leetcode as there are many ways to do it we programmers need to find the most optimal way to solve a problem statement so i used binary-search approach inorder to solve it.
All  suggestions are accepted!!!

* Update 69.c

I have updated the solution according to the suggestions.

* Update 69.c

* Update 69.c
This commit is contained in:
hemanth8819 2023-06-28 01:19:43 +05:30 committed by GitHub
parent f4ee5743af
commit db69d0a539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

23
leetcode/src/69.c Normal file
View File

@ -0,0 +1,23 @@
//using the binary search method is one of the efficient ones for this problem statement.
int mySqrt(int x){
int start=0;
int end=x;
long long int ans=0;
while(start <= end){
long long int mid=(start+end)/2;
long long int val=mid*mid;
if( val == x){
return mid;
}
//if mid is less than the square root of the number(x) store the value of mid in ans.
if( val < x){
ans = mid;
start = mid+1;
}
//if mid is greater than the square root of the number(x) then ssign the value mid-1 to end.
if( val > x){
end = mid-1;
}
}
return ans;
}