3158. Find the XOR of Numbers Which Appear Twice Easy
1/**
2 * [3158] Find the XOR of Numbers Which Appear Twice
3 *
4 * You are given an array nums, where each number in the array appears either once or twice.
5 * Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,2,1,3]</span>
10 * Output: <span class="example-io">1</span>
11 * Explanation:
12 * The only number that appears twice in nums is 1.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [1,2,3]</span>
17 * Output: <span class="example-io">0</span>
18 * Explanation:
19 * No number appears twice in nums.
20 * </div>
21 * <strong class="example">Example 3:
22 * <div class="example-block">
23 * Input: <span class="example-io">nums = [1,2,2,1]</span>
24 * Output: <span class="example-io">3</span>
25 * Explanation:
26 * Numbers 1 and 2 appeared twice. 1 XOR 2 == 3.
27 * </div>
28 *
29 * Constraints:
30 *
31 * 1 <= nums.length <= 50
32 * 1 <= nums[i] <= 50
33 * Each number in nums appears either once or twice.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice/
39// discuss: https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn duplicate_numbers_xor(nums: Vec<i32>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3158() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.