Skip to content

Commit 7ef0f50

Browse files
committed
8-4-2020
1 parent 8faeaed commit 7ef0f50

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/_0342_power_of_four.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct Solution;
2+
3+
impl Solution {
4+
pub fn is_power_of_four(num: i32) -> bool {
5+
return num > 0 && (num & (num - 1)) == 0 && (num & 0b1010101010101010101010101010101 != 0);
6+
}
7+
}
8+
9+
#[test]
10+
fn test() {
11+
assert_eq!(Solution::is_power_of_four(16), true);
12+
assert_eq!(Solution::is_power_of_four(5), false);
13+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ mod _0001_two_sum;
1414
//
1515
mod _0002_add_two_numbers;
1616
//
17+
mod _0003_longest_substring_without_repeating_characters;
18+
//
1719
mod _0005_longest_palindromic_substring;
1820
//
1921
mod _0007_reverse_integer;
@@ -100,6 +102,8 @@ mod _0268_missing_number;
100102
//
101103
mod _0283_move_zeroes;
102104
//
105+
mod _0342_power_of_four;
106+
//
103107
mod _0344_reverse_string;
104108
//
105109
mod _0347_top_k_frequent_elements;

0 commit comments

Comments
 (0)