137. Single Number II Medium

@problem@discussion
#Array#Bit Manipulation



1/**
2 * [137] Single Number II
3 *
4 * Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.
5 * You must implement a solution with a linear runtime complexity and use only constant extra space.
6 *  
7 * Example 1:
8 * Input: nums = [2,2,3,2]
9 * Output: 3
10 * Example 2:
11 * Input: nums = [0,1,0,1,0,1,99]
12 * Output: 99
13 *  
14 * Constraints:
15 * 
16 * 	1 <= nums.length <= 3 * 10^4
17 * 	-2^31 <= nums[i] <= 2^31 - 1
18 * 	Each element in nums appears exactly three times except for one element which appears once.
19 * 
20 */
21pub struct Solution {}
22
23// problem: https://leetcode.com/problems/single-number-ii/
24// discuss: https://leetcode.com/problems/single-number-ii/discuss/?currentPage=1&orderBy=most_votes&query=
25
26// submission codes start here
27
28impl Solution {
29    pub fn single_number(nums: Vec<i32>) -> i32 {
30        0
31    }
32}
33
34// submission codes end
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_137() {
42    }
43}
44


Back
© 2025 bowen.ge All Rights Reserved.