How can i optimize it further?


#1

Comment body goes here.
int Solution::sqrt(int A) {
if(A == 0 || A == 1) return A;
if(A == 2 || A == 3) return 1;
int ans=0;
for(long long i=1;i<=A/2;i++)
{
if(i*i<=A)
{
ans=i;
}
else
break;
}
return ans;
}


#2

Your solution’s run time is O(A) but they are expecting O(logA). You can do a binary search from 1 to A to find the answer to this problem.


#3

you need to start from 1 to A and apply Binary search.just replaced condition with square ones.
so time complexity would be O(logA)