unique character in string

librangel 2010-03-17 07:05:24
Implement an algorithm to determine if a string has all unique characters.
you can not use additional data structures?
请大侠指点
谢谢
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
如果允许破坏原来的数据,那么可以排序,在排序中判断是否有相等的,相等则跳出。

由于排序可以达到O(nlogn),所以这个方法不会低于O(nlogn)。
librangel 2010-03-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qiuzhenguang 的回复:]
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).
[/Quote]

不能用多于的data structure啊~~
qiuzhenguang 2010-03-17
  • 打赏
  • 举报
回复
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).

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧