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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

LeetCode 387. First Unique Character in a String

2019-11-11 03:13:25
字體:
供稿:網(wǎng)友

描述 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.

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

代碼

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; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 霸州市| 乌海市| 南陵县| 嘉义县| 孝感市| 临清市| 花莲市| 庆元县| 九龙县| 白城市| 蒙阴县| 荔波县| 夏河县| 洪洞县| 婺源县| 金湖县| 新龙县| 儋州市| 通州市| 韩城市| 威海市| 平江县| 红桥区| 舞阳县| 乾安县| 额济纳旗| 昌宁县| 托克托县| 邯郸县| 北票市| 青浦区| 双城市| 柳林县| 金昌市| 桑日县| 桃江县| 蓬安县| 库伦旗| 江山市| 鄱阳县| 江山市|