(int N )
| 2 | { |
| 3 | // return either a perfect square root or floor value |
| 4 | public static int mySqrt(int N ) { |
| 5 | int start=1; |
| 6 | int end=N; |
| 7 | while(start<=end) |
| 8 | { |
| 9 | int mid = start+(end-start)/2; |
| 10 | if(mid<=N/mid) |
| 11 | { |
| 12 | if(N%mid==0 && mid==N/mid) |
| 13 | { |
| 14 | return mid; |
| 15 | } |
| 16 | start=mid+1; |
| 17 | } |
| 18 | else end=mid-1; |
| 19 | } |
| 20 | return start; |
| 21 | } |
| 22 | static int countSquares(int N) { |
| 23 | // code here |
| 24 | int sqrRoot = mySqrt(N); |