1748. Sum of Unique Elements Easy
1/**
2 * [1748] Sum of Unique Elements
3 *
4 * You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.
5 * Return the sum of all the unique elements of nums.
6 *
7 * Example 1:
8 *
9 * Input: nums = [1,2,3,2]
10 * Output: 4
11 * Explanation: The unique elements are [1,3], and the sum is 4.
12 *
13 * Example 2:
14 *
15 * Input: nums = [1,1,1,1,1]
16 * Output: 0
17 * Explanation: There are no unique elements, and the sum is 0.
18 *
19 * Example 3:
20 *
21 * Input: nums = [1,2,3,4,5]
22 * Output: 15
23 * Explanation: The unique elements are [1,2,3,4,5], and the sum is 15.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= nums.length <= 100
29 * 1 <= nums[i] <= 100
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/sum-of-unique-elements/
35// discuss: https://leetcode.com/problems/sum-of-unique-elements/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn sum_of_unique(nums: Vec<i32>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1748() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.