3514. Number of Unique XOR Triplets II Medium

@problem@discussion
#Array#Math#Bit Manipulation#Enumeration



1/**
2 * [3514] Number of Unique XOR Triplets II
3 *
4 * <p data-end="261" data-start="147">You are given an integer array nums.
5 * A XOR triplet is defined as the XOR of three elements nums[i] XOR nums[j] XOR nums[k] where i <= j <= k.
6 * Return the number of unique XOR triplet values from all possible triplets (i, j, k).
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,3]</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * <p data-end="158" data-start="101">The possible XOR triplet values are:
14 * <ul data-end="280" data-start="159">
15 * 	<li data-end="188" data-start="159">(0, 0, 0) &rarr; 1 XOR 1 XOR 1 = 1
16 * 	<li data-end="218" data-start="189">(0, 0, 1) &rarr; 1 XOR 1 XOR 3 = 3
17 * 	<li data-end="248" data-start="219">(0, 1, 1) &rarr; 1 XOR 3 XOR 3 = 1
18 * 	<li data-end="280" data-start="249">(1, 1, 1) &rarr; 3 XOR 3 XOR 3 = 3
19 * 
20 * <p data-end="343" data-start="282">The unique XOR values are <code data-end="316" data-start="308">{1, 3}. Thus, the output is 2.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [6,7,8,9]</span>
25 * Output: <span class="example-io">4</span>
26 * Explanation:
27 * The possible XOR triplet values are <code data-end="275" data-start="267">{6, 7, 8, 9}. Thus, the output is 4.
28 * </div>
29 *  
30 * Constraints:
31 * 
32 * 	1 <= nums.length <= 1500
33 * 	1 <= nums[i] <= 1500
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/number-of-unique-xor-triplets-ii/
39// discuss: https://leetcode.com/problems/number-of-unique-xor-triplets-ii/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn unique_xor_triplets(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_3514() {
57    }
58}
59

Back
© 2026 bowen.ge All Rights Reserved.