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

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

LeetCode 387. First Unique Character in a String

2019-11-11 03:46: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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广饶县| 偏关县| 漳平市| 大田县| 道真| 沭阳县| 永年县| 香格里拉县| 卓资县| 沅陵县| 安西县| 静海县| 酒泉市| 嵩明县| 马边| 永川市| 邵阳市| 宁乡县| 余江县| 西丰县| 高陵县| 东丽区| 扶余县| 康马县| 梁河县| 顺昌县| 尤溪县| 大余县| 卢氏县| 和田市| 临海市| 南乐县| 惠东县| 东至县| 丰都县| 乌拉特中旗| 洪雅县| 峨山| 白山市| 依安县| 万年县|