国产探花免费观看_亚洲丰满少妇自慰呻吟_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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 电白县| 黄骅市| 依安县| 襄垣县| 沧州市| 来安县| 海原县| 囊谦县| 越西县| 铁岭市| 建始县| 乃东县| 任丘市| 庆阳市| 曲麻莱县| 迭部县| 米林县| 桑植县| 文昌市| 济南市| 东阳市| 敖汉旗| 揭西县| 社会| 合肥市| 舞钢市| 贵港市| 庆阳市| 崇信县| 十堰市| 大姚县| 榆林市| 八宿县| 永康市| 绥德县| 和林格尔县| 云龙县| 察雅县| 渝北区| 威宁| 临西县|