My one line AC solution in Java


  • 0
    W

    public class Solution {
    public boolean isPerfectSquare(int num) {
    return Math.sqrt(num) == Math.ceil(Math.sqrt(num));
    }
    }

    The idea is neat. Just check if the root is int by Math.ceil();


Log in to reply
 

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