Check if the string has unique char.

来源:互联网 发布:如何查询海关数据 编辑:程序博客网 时间:2024/05/20 04:12

 

The code is using additional space to store if the char is already contained in the string or not. 

现在这段code和之前的remove duplicate char in a string其实是一样的。

另外现在的这段code仅限于ascii,不适用于UTF。因为UTF可能是16位的。

Will post another snipet of code which doesn't use any other space.

 

以上这个方法是O(n*n)时间复杂度

后来书上查到一个方法是O(nlog n)的方法,因为用了快速排序,当然修改了一把

其中用到的partition方法是快速排序中标准的方法

 

原创粉丝点击