Java Solution Math.sqrt


  • 0
    A

    public class Solution {

    public boolean judgeSquareSum(int c) {
        if (c == 0) return true;
        int i = (int)Math.sqrt(c);
        for (int j = 1; j <= i; j ++) {
            if (Math.sqrt(c - j * j ) % 1 == 0) {
                return true;
            }
        }
        return false;
    }
    

    }


Log in to reply
 

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