693. Binary Number with Alternating Bits Easy

@problem@discussion
#Bit Manipulation



1/**
2 * [693] Binary Number with Alternating Bits
3 *
4 * Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
5 *  
6 * Example 1:
7 * 
8 * Input: n = 5
9 * Output: true
10 * Explanation: The binary representation of 5 is: 101
11 * 
12 * Example 2:
13 * 
14 * Input: n = 7
15 * Output: false
16 * Explanation: The binary representation of 7 is: 111.
17 * Example 3:
18 * 
19 * Input: n = 11
20 * Output: false
21 * Explanation: The binary representation of 11 is: 1011.
22 *  
23 * Constraints:
24 * 
25 * 	1 <= n <= 2^31 - 1
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/binary-number-with-alternating-bits/
31// discuss: https://leetcode.com/problems/binary-number-with-alternating-bits/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn has_alternating_bits(n: i32) -> bool {
37        false
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_693() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.