367. Valid Perfect Square

n*n=1+2+3+...+(2n-1)

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     bool isPerfectSquare(int num) 
12     {
13         for(int i=1;num>0;i+=2)
14             num-=i;
15         return num==0;
16     }
17 };

猜你喜欢

转载自www.cnblogs.com/zhuangbijingdeboke/p/9093172.html
今日推荐