1486. XOR Operation in an Array Easy

@problem@discussion
#Math#Bit Manipulation



1/**
2 * [1486] XOR Operation in an Array
3 *
4 * You are given an integer n and an integer start.
5 * Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length.
6 * Return the bitwise XOR of all elements of nums.
7 *  
8 * Example 1:
9 * 
10 * Input: n = 5, start = 0
11 * Output: 8
12 * Explanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.
13 * Where "^" corresponds to bitwise XOR operator.
14 * 
15 * Example 2:
16 * 
17 * Input: n = 4, start = 3
18 * Output: 8
19 * Explanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= n <= 1000
25 * 	0 <= start <= 1000
26 * 	n == nums.length
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/xor-operation-in-an-array/
32// discuss: https://leetcode.com/problems/xor-operation-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn xor_operation(n: i32, start: i32) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_1486() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.