首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

unique character in string,该怎么处理

2012-02-06 
uniquecharacter in stringImplement an algorithm to determine if a string has all unique characters.

unique character in string
Implement an algorithm to determine if a string has all unique characters.
you can not use additional data structures?
请大侠指点 
谢谢

[解决办法]
Use hash table to detect if there is repeated characters,When hash collision occurs,there must be characteres that is not unique.
The time complicity and space complexity are both O(n).
[解决办法]
如果允许破坏原来的数据,那么可以排序,在排序中判断是否有相等的,相等则跳出。

由于排序可以达到O(nlogn),所以这个方法不会低于O(nlogn)。

热点排行