461. Hamming Distance Easy

@problem@discussion
#Bit Manipulation



1/**
2 * [461] Hamming Distance
3 *
4 * The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.
5 * Given two integers x and y, return the Hamming distance between them.
6 *  
7 * Example 1:
8 * 
9 * Input: x = 1, y = 4
10 * Output: 2
11 * Explanation:
12 * 1   (0 0 0 1)
13 * 4   (0 1 0 0)
14 *        &uarr;   &uarr;
15 * The above arrows point to positions where the corresponding bits are different.
16 * 
17 * Example 2:
18 * 
19 * Input: x = 3, y = 1
20 * Output: 1
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	0 <= x, y <= 2^31 - 1
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/hamming-distance/
31// discuss: https://leetcode.com/problems/hamming-distance/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn hamming_distance(x: i32, y: i32) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_461() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.