136. Single Number Easy
1/**
2 * [136] Single Number
3 *
4 * Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
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,1]
9 * Output: 1
10 * Example 2:
11 * Input: nums = [4,1,2,1,2]
12 * Output: 4
13 * Example 3:
14 * Input: nums = [1]
15 * Output: 1
16 *
17 * Constraints:
18 *
19 * 1 <= nums.length <= 3 * 10^4
20 * -3 * 10^4 <= nums[i] <= 3 * 10^4
21 * Each element in the array appears twice except for one element which appears only once.
22 *
23 */
24pub struct Solution {}
25
26// problem: https://leetcode.com/problems/single-number/
27// discuss: https://leetcode.com/problems/single-number/discuss/?currentPage=1&orderBy=most_votes&query=
28
29// submission codes start here
30
31impl Solution {
32 pub fn single_number(nums: Vec<i32>) -> i32 {
33 0
34 }
35}
36
37// submission codes end
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn test_136() {
45 }
46}
47
Back
© 2025 bowen.ge All Rights Reserved.