231. Power of Two java solutions

Given an integer, write a function to determine if it is a power of two.

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

 

Subscribe to see which companies asked this question

 
1 public class Solution {
2     public boolean isPowerOfTwo(int n) {
3         if(n < 1 ) return false;
4         return (n&(n-1)) == 0;
5     }
6 }

 

 

posted @ 2016-04-21 15:20  Miller1991  阅读(116)  评论(0编辑  收藏  举报