Best algorithm for delete duplicates in array of strings

前端 未结 7 1893
一个人的身影
一个人的身影 2021-02-09 02:44

Today at school the teacher asked us to implement a duplicate-deletion algorithm. It\'s not that difficult, and everyone came up with the following solution (pseudocode):

<
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 03:12

    add is O(n), so your CC calculation is wrong. Your algorithm is O(n^2).

    Moreover, how would remove be implemented? It also looks like it would be O(n) - so the initial algorithm would be O(n^3).

提交回复
热议问题