Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 42955f5

Browse files
committed
refmt
1 parent 52c6aea commit 42955f5

7 files changed

+38
-10
lines changed

kamyu104/src/bitwise_and_of_numbers_range.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Space: O(1)
33

44
pub struct Solution1 {}
5-
pub struct Solution2 {}
6-
75
impl Solution1 {
86
pub fn range_bitwise_and(m: u32, mut n: u32) -> u32 {
97
while m < n {
@@ -14,6 +12,7 @@ impl Solution1 {
1412
}
1513
}
1614

15+
pub struct Solution2 {}
1716
impl Solution2 {
1817
pub fn range_bitwise_and(m: u32, n: u32) -> u32 {
1918
let (mut i, mut diff): (u32, u32) = (0, n - m);

kamyu104/src/number_of_1_bits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Space: O(1)
33

44
pub struct Solution {}
5-
65
impl Solution {
76
pub fn hamming_weight(mut n: u32) -> u8 {
87
let mut cnt: u8 = 0;

kamyu104/src/power_of_two.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1+
// Time: O(1)
2+
// Space: O(1)
3+
4+
pub struct Solution1 {}
5+
impl Solution1 {
6+
pub fn is_power_of_two(n: i32) -> bool {
7+
n > 0 && (n & (n - 1)) == 0
8+
}
9+
}
10+
11+
pub struct Solution2 {}
12+
impl Solution2 {
13+
pub fn is_power_of_two(n: i32) -> bool {
14+
n > 0 && (n & !-n) == 0
15+
}
16+
}
17+
18+
19+
#[cfg(test)]
20+
mod tests {
21+
// Note this useful idiom: importing names from outer (for mod tests) scope.
22+
use super::*;
23+
24+
#[test]
25+
fn test_is_power_of_two() {
26+
assert_eq!(Solution1::is_power_of_two(1), true);
27+
assert_eq!(Solution1::is_power_of_two(16), true);
28+
assert_eq!(Solution1::is_power_of_two(218), false);
29+
30+
assert_eq!(Solution2::is_power_of_two(1), true);
31+
assert_eq!(Solution2::is_power_of_two(16), true);
32+
assert_eq!(Solution2::is_power_of_two(218), false);
33+
}
34+
}
135

kamyu104/src/reverse_bits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Space: O(1)
33

44
pub struct Solution {}
5-
65
impl Solution {
76
pub fn reverse_bits(mut n: u32) -> u32 {
87
let mut result: u32 = 0;

kamyu104/src/single_number.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Space: O(1)
33

44
pub struct Solution {}
5-
65
impl Solution {
76
pub fn single_number(nums: Vec<i32>) -> i32 {
87
nums.iter().fold(0, |acc, &num| acc ^ num)

kamyu104/src/single_number_ii.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
use std::collections::HashSet;
55

66
pub struct Solution1 {}
7-
pub struct Solution2 {}
8-
pub struct Solution3 {}
9-
pub struct Solution4 {}
10-
117
impl Solution1 {
128
pub fn single_number(nums: Vec<i32>) -> i32 {
139
let (mut one, mut two): (i32, i32) = (0, 0);
@@ -21,6 +17,7 @@ impl Solution1 {
2117
}
2218
}
2319

20+
pub struct Solution2 {}
2421
impl Solution2 {
2522
pub fn single_number(nums: Vec<i32>) -> i32 {
2623
let (mut one, mut two, mut carry): (i32, i32, i32) = (0, 0, 0);
@@ -36,11 +33,13 @@ impl Solution2 {
3633
}
3734

3835
// https://github.com/kamyu104/LeetCode-Solutions/blob/master/Python/single-number-ii.py#L31
36+
// pub struct Solution3 {}
3937
// impl Solution3 {
4038
// pub fn single_number(nums: Vec<i32>) -> i32 {
4139
// }
4240
// }
4341

42+
pub struct Solution4 {}
4443
impl Solution4 {
4544
pub fn single_number(nums: Vec<i32>) -> i32 {
4645
let sum: i32 = nums.iter().sum();

kamyu104/src/template.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub struct Solution {}
2-
32
impl Solution {
43
pub fn add(a: i32, b: i32) -> i32 {
54
// only print when a test fails

0 commit comments

Comments
 (0)