Dec 26, 2008

How to decide whether there is a duplicate in a string

How to decide whether there is a duplicate in a string
1. use hashtable time O(n), space O(26)
2. use bitset time O(n), space O(26)
3. sort and find, time O(nlogn), space O(1)
4. use the msb of each char as bitvector O(n), O(1) (the length of string is bigger than 26)

No comments:

Post a Comment