3702. Longest Subsequence With Non-Zero Bitwise XOR Medium
1/**
2 * [3702] Longest Subsequence With Non-Zero Bitwise XOR
3 *
4 * You are given an integer array nums.
5 * Return the length of the longest <span data-keyword="subsequence-array-nonempty">subsequence</span> in nums whose bitwise XOR is non-zero. If no such subsequence exists, return 0.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,2,3]</span>
10 * Output: <span class="example-io">2</span>
11 * Explanation:
12 * One longest subsequence is [2, 3]. The bitwise XOR is computed as 2 XOR 3 = 1, which is non-zero.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [2,3,4]</span>
17 * Output: <span class="example-io">3</span>
18 * Explanation:
19 * The longest subsequence is [2, 3, 4]. The bitwise XOR is computed as 2 XOR 3 XOR 4 = 5, which is non-zero.
20 * </div>
21 *
22 * Constraints:
23 *
24 * 1 <= nums.length <= 10^5
25 * 0 <= nums[i] <= 10^9
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/longest-subsequence-with-non-zero-bitwise-xor/
31// discuss: https://leetcode.com/problems/longest-subsequence-with-non-zero-bitwise-xor/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn longest_subsequence(nums: Vec<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_3702() {
49 }
50}
51Back
© 2026 bowen.ge All Rights Reserved.