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

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

LeetCode 387. First Unique Character in a String

2019-11-11 05:17:45
字體:
來源:轉載
供稿:網友

描述 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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天祝| 鹤庆县| 呈贡县| 教育| 威信县| 清水河县| 哈密市| 花莲县| 南郑县| 宿松县| 凤凰县| 依安县| 肥乡县| 舟曲县| 驻马店市| 江门市| 井冈山市| 通州市| 晋州市| 许昌县| 永新县| 曲麻莱县| 黄龙县| 鹰潭市| 九龙坡区| 天柱县| 靖宇县| 南昌市| 克什克腾旗| 金乡县| 平南县| 涟源市| 土默特左旗| 桦南县| 石家庄市| 新乡市| 宿松县| 汕尾市| 眉山市| 新巴尔虎左旗| 洪雅县|