LeetCode 231. Power of Two

来源:互联网 发布:nginx 转发到其他ip 编辑:程序博客网 时间:2024/06/04 01:04

Description

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

Code

class Solution {public:    bool isPowerOfTwo(int n) {        if (n<=0) return false;        return ((n & (n-1)) == 0);    }};

Appendix

  • Link: https://leetcode.com/problems/power-of-two/
  • Run Time: 3ms
0 0
原创粉丝点击