国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 387. First Unique Character in a String

2019-11-11 04:20:29
字體:
來源:轉載
供稿:網友

描述 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.

Examples:

s = "leetcode"return 0.s = "loveleetcode",return 2.

Note: You may assume the string contain only lowercase letters.

分析 考慮到題目中只有小寫字母,可以采用桶計數的思路。

代碼

class Solution {public: int firstUniqChar(string s) { int alpha[26] = {0}; const int n = s.size(); for (int i = 0; i < n; ++i) alpha[s[i] - 'a']++; for (int i = 0; i < n; ++i) if (alpha[s[i] - 'a'] == 1) return i; return -1; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇庆市| 锡林浩特市| 遂平县| 凤台县| 兴和县| 道真| 丰顺县| 锡林浩特市| 孝昌县| 隆尧县| 县级市| 团风县| 含山县| 玉树县| 综艺| 沁水县| 罗定市| 凌云县| 泸定县| 湄潭县| 莱西市| 盘山县| 祁连县| 中牟县| 扶绥县| 额敏县| 溆浦县| 崇文区| 原阳县| 松阳县| 广东省| 南溪县| 嘉义县| 贵南县| 临高县| 昌乐县| 洪洞县| 延长县| 梅河口市| 洱源县| 汽车|