Easy Java Binary Search Solution


  • 0
    public class Solution {
        public boolean isPerfectSquare(int num) {
            int l=1,r=num;
            while(l<r){
                int mid=l+(r-l)/2;
                if(mid<num/mid)
                    l=mid+1;
                else
                    r=mid;
            }
            return l==(double)num/l;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.