code.cpp 392 B

123456789101112
  1. /* Given an array of numbers, write a function that returns an array that...
  2. Has all duplicate elements removed.
  3. Is sorted from least value to greatest value.
  4. */
  5. std::vector<int> uniqueSort(std::vector<int> arr) {
  6. std::sort(arr.begin(),arr.begin()+arr.size());
  7. std::vector<int>::iterator i = std::unique (arr.begin(), arr.end());
  8. arr.resize(std::distance (arr.begin(),i));
  9. return arr;
  10. }