Show problems as
Classic problem #1748EasyArrayHash TableCounting

Sum of Unique Elements

Real-world version: Face Values Held Only Once
Tracked in this browser only
Read Sum of Unique Elements on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A stamp album lists the face value of every stamp mounted in it, in mounting order, as the list faces. A face value is called a singleton when exactly one stamp in the album carries it.

Return the total of the singleton face values. A face value carried by two or more stamps contributes nothing at all, not even one copy. Return 0 when the album holds no singleton.

Examples

Example 1

Input
faces = [8, 3, 8, 5]
Output
8

Face value 8 is carried by two stamps, so it drops out. The singletons are 3 and 5, which total 8.

Example 2

Input
faces = [7, 7, 7, 2]
Output
2

Three stamps carry face value 7, so it is not a singleton. Only 2 is, and the total is 2.

Example 3

Input
faces = [6, 6, 6]
Output
0

Every stamp in the album carries the same face value, so the album holds no singleton and the total is 0.

Constraints

  • 1 <= faces.length <= 100
  • 1 <= faces[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def sum_singleton_values(faces: list[int]) -> int:
Java
public int sumSingletonValues(int[] faces)