231. Power of Two Easy
1/**
2 * [231] Power of Two
3 *
4 * Given an integer n, return true if it is a power of two. Otherwise, return false.
5 * An integer n is a power of two, if there exists an integer x such that n == 2^x.
6 *
7 * Example 1:
8 *
9 * Input: n = 1
10 * Output: true
11 * Explanation: 2^0 = 1
12 *
13 * Example 2:
14 *
15 * Input: n = 16
16 * Output: true
17 * Explanation: 2^4 = 16
18 *
19 * Example 3:
20 *
21 * Input: n = 3
22 * Output: false
23 *
24 *
25 * Constraints:
26 *
27 * -2^31 <= n <= 2^31 - 1
28 *
29 *
30 * Follow up: Could you solve it without loops/recursion?
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/power-of-two/
35// discuss: https://leetcode.com/problems/power-of-two/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn is_power_of_two(n: i32) -> bool {
41 false
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_231() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.