【Cracking the coding interview】Q1.1(字符唯一)
来源:互联网 发布:配置网络 ubuntu 编辑:程序博客网 时间:2024/05/01 12:28
读了Hawstein大神的大作,读书笔记记录之,膜拜大神用,给自己增些知识。
更多大神的著作参见这里 http://hawstein.com/posts/1.1.html
Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?
实现一个算法来判断一个字符串中的字符是否唯一
思路:用最小的数组或者是用位运算来实现。acii的字符用256位来记录就够了。
bool a[256]; if(a[i]) return false;else return true;
如果只有小写字母用一个int就可以了,这里涉及到位运算
bool isUnique(string s){ int check = 0; int len = s.length(); for(int i=0; i<len; ++i) { int v = (int)(s[i]-'a'); if(check & (1<<v)) return false; check |= (1<<v); } return true;}
更多大神的著作参见这里 http://hawstein.com/posts/1.1.html
0 0
- 【Cracking the coding interview】Q1.1(字符唯一)
- Cracking The Coding Interview--Q1.1
- Cracking the coding interview Q1.1
- Cracking the coding interview--Q1.1
- Cracking the coding interview Q1.1
- Cracking the coding interview Q1.1
- Cracking the Coding Interview Chap1 Q1.1
- Cracking the coding interview--Q1.1
- Cracking the coding interview--Q1.1
- Cracking the coding interview--Q1.1
- Cracking the coding interview--Q1.1
- Cracking the coding interview--Q1
- 【Cracking the coding interview】Q1.3(移除重复字符)
- Cracking the coding interview--Q1.1(python的位操作)
- 【Cracking the coding interview】Q1.2(反转字符串)
- 【Cracking the coding interview】Q1.4(变位词)
- 【Cracking the coding interview】Q1.5(替换字符串)
- 【Cracking the coding interview】Q1.6(旋转矩阵)
- 2013年小结及2014年展望
- kmp java implement--转
- java实现迷宫算法--转
- Memcached分布式算法详解--转
- 设计模式之原型模式
- 【Cracking the coding interview】Q1.1(字符唯一)
- Unity屏幕渲染技术
- Oracle中出现Ora-00054该怎么处理,V$locked_object和V$session的用法
- TS流的基本概念
- secureCRT下的串口不能输入
- 解决GPG error: The following signatures couldn't be verified because the public key is not available
- Ubuntu下使用Mysql
- 黑马程序员_多态性
- 开发者所需要知道的iOS7 SDK新特性