O(1) C# Solution


  • -5
    G
    public bool IsPerfectSquare(int num) {
        double sqrt = Math.Sqrt(num);
        return Math.Floor(sqrt)==Math.Ceiling(sqrt);
    }

  • -1
    A

    Same like ur code :)

    public class Solution {

    public boolean isPerfectSquare(int num) {
        double sq=Math.sqrt(num);   
        if(sq%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.