Algorithm: efficient way to remove duplicate integers from an array

前端 未结 30 2645
离开以前
离开以前 2020-11-22 16:03

I got this problem from an interview with Microsoft.

Given an array of random integers, write an algorithm in C that removes duplicated numbers an

30条回答
  •  一向
    一向 (楼主)
    2020-11-22 16:25

    If you are looking for the superior O-notation, then sorting the array with an O(n log n) sort then doing a O(n) traversal may be the best route. Without sorting, you are looking at O(n^2).

    Edit: if you are just doing integers, then you can also do radix sort to get O(n).

提交回复
热议问题