code.cpp 372 B

1234567891011
  1. /* Create a function that takes an array of numbers and return the number
  2. * that's unique.
  3. */
  4. // a a a a b -> abaaa returns '2'
  5. // c d d d d d -> cddddd returns '2'
  6. double unique(std::vector<double> arr) {
  7. std::sort (arr.begin(),arr.end());
  8. std::unique (arr.begin(),arr.end());
  9. // expression ? trueValue : falseValue
  10. return arr[1]!=arr[2] ? arr[1] : arr[0];
  11. }