leetcode-387-First Unique Character in a String
2017-01-16 22:44
393 查看
问题
题目:[leetcode-387]思路
思路很简单,首先枚举一遍。记录hash值。然后,还是根据s进行枚举,找到hash值为1的返回即可。关键是一定要按照s的顺序进行枚举。
代码
class Solution { public: int firstUniqChar(string s) { int hash[128]; std::memset( hash, 0, sizeof(hash) ); int sz = s.size(); for( int i = 0; i < sz; ++i ){ ++hash[s[i]]; } for( int i = 0; i < sz; ++i ){ if( 1==hash[s[i]] ) return i; } return -1; } };
相关文章推荐
- EL表达式和request.getParameter()接收请求参数
- 为图片存储而作——记一次UEditor源码的修改
- easyui 带参数的datagride
- Android禁止在非Activity主线程中更新UI的解决办法
- Best Sequence poj1699(dfs)
- Codeforces Round #326 (Div. 1) E. Duff as a Queen
- vue中使用scss, 小记~安装sass-loader
- 第3章 软件也要拼脸蛋-UI开发的点点滴滴
- HDOJ 4010 Query on The Trees(LCT动态树)
- HDU - 3530 Subsequence 单调队列
- 【九度】题目1442:A sequence of numbers
- iOS开发-UI (一)常用控件
- UILabel的高度和宽度自适应
- Qt常用UI控件读取、写入方法
- sublime vue 语法高亮插件安装
- 【USACO】【贪心】Sorting a Three-Valued Sequence
- Failed to run the WC DB work queue associated with 错误的解决
- Short类型的List contains(Byte.valueOf("1"))的问题
- Bad request的解决方案:
- duilib基本流程