zoukankan      html  css  js  c++  java
  • 【leetcode】】有效的完全平方数

    .

    /*
    1 = 1;
    4 = 1 + 3;
    9 = 1 + 3 + 5;
    16 = 1 + 3 + 5 + 7;
    */
    
    计算过程只需要加减法,效率极高。
    
    
    bool isPerfectSquare(int num){
        if (num == 0 ) return false;
    
        int i = 1;
        while ( num > 0){
            num -= i;
            i += 2;
        }
        return num == 0 ? true : false;
    
    }
    bool isPerfectSquare(int num){
        unsigned int i;
        for (i=0; i<10000; i++)
        {
            if (i*i == num)
                return true;
            else if(i*i > num)
                return false;
        }
    }
  • 相关阅读:
    hanoi(老汉诺塔问题新思维)
    ABP文档
    ABP文档
    ABP文档
    ABP文档
    ABP文档
    ABP文档
    ABP文档
    ABP文档
    ABP框架
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13564312.html
Copyright © 2011-2022 走看看