算法之arrays and strings

1.  question:  Is Unique: Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

     answer:    首先需要假设字符串是ASCII字符串;

      可以使用额外的数据结构的做法: 定义一个128存储空间的布尔数组,循环字符串,直接在布尔数组寻址每个字符的地址,如果是true则代表有重复,否则修改次地址的值为true。

      可以使用额外的数据结构的做法: 定义一个字符串长度的字符数据,将字符数据进行快速排序,然后再循环整个字符串,判断前后字符串是否有相同。

      不可使用额外数据结构的做法:使用位数组来进行标记,加入字符串全部是小写字母,可以使用一个int变量来记录每个标记位。更多的位存储可以使用数组,因为数组是连续存储空间。

----待续

猜你喜欢

转载自www.cnblogs.com/lingqingyu/p/12622031.html
今日推荐