Valid Perfect Square Solution by Java


  • 1
    1
    class Solution{
        public boolean isPerfectSquare(int num){                       //数学技巧:所有的完全平方数都可以被表示成奇数和1+3+5+7+9 ...。
               int i=1;
               while(num>0)                                        
               {
                  num-=i;
                   i+=2;
               }
               
            return num==0;
        }
    }
    

Log in to reply
 

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