Java recursive binary search

  • 0
    public class Solution {
        public boolean isPerfectSquare(int num) {
            return isPS(num, 0, Integer.MAX_VALUE);
        private boolean isPS(long n, long l, long h){
            long m = (l+h)/2;
            if (l == h) return false;
            if (m*m == n) return true;
            return (m*m < n)?isPS(n,m+1,h):isPS(n,l, m);

Log in to reply

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