# 231 Power of Two

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

**The Idea:** A number is a power of 2 if it has a single activated bit. E.g.

```
00000000000000001
00000000000000010
00000000000000100
...
10000000000000000
```

**Complexity:** O(1) time and space

```python
class Solution:
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n <= 0:
            return False

        cur_power = 1
        while cur_power <= n:
            if cur_power == n:
                return True
            cur_power <<= 1
        return False
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/231-power-of-two.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
