Array of unique elements?

后端 未结 5 2077
时光取名叫无心
时光取名叫无心 2020-12-06 05:52

Given an array like the one below, I was wondering if there is an easy way to turn this array into an array with unique values only?

This is given:

         


        
5条回答
  •  臣服心动
    2020-12-06 06:18

    Two options

    1. Keep a map of count and element and finally only use those elements with count 1. (Need extra storage but is faster)

    2. Sort the array and as you move through the array only use non-repeated ones.

    Doesn't need extra space but will be O(n lg(n))

提交回复
热议问题