码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode题解

时间:2015-07-06 21:26:00      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

1、231 Power of  Two

题目很简单,直接上代码,主要是掌握bitset的使用。

 1 class Solution {
 2 public:
 3     bool isPowerOfTwo(int n) {
 4         bitset<32> myset(n);
 5         if (n<=0)
 6         {
 7             return false;
 8         }
 9 
10         if (1==myset.count() || 0==myset.count())
11         {
12             return true;
13         }
14 
15         return false;
16 
17 
18     }
19 };

 

Leetcode题解

标签:

原文地址:http://www.cnblogs.com/LCCRNblog/p/4625266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!