TopcoderARCHIVE
Archive/Problems/SumUnique
SRM · Problem 14771

SumUnique

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a list of int values. We wish to find the sum of these values, however we want to ignore duplicates. Return the sum of the unique values in the list.

Definition

Class:
SumUnique
Method:
getSum
Parameters:
int[]
Returns:
int
Method signature:
int getSum(int[] values)
(be sure your method is public)

Constraints

  • values will contain between 1 and 50 elements, inclusive.
  • Each element of values will be between 1 and 100, inclusive.

Examples

  1. { 1, 2, 3, 4, 5 }
    Returns: 15
    The values are all unique, so we return 1 + 2 + 3 + 4 + 5 = 15.
  2. { 1, 2, 3, 4, 3 }
    Returns: 10
    The value 3 is duplicated, so we only count it once. 1 + 2 + 3 + 4 = 10.
  3. { 1, 1, 1, 1, 1, 1, 1, 1, 1 }
    Returns: 1
  4. { 18, 22, 9, 1, 7, 18, 13, 49, 13, 9, 49, 49, 7 }
    Returns: 119
← All problems