LeetCode
来源:互联网 发布:东方娱乐有什么软件 编辑:程序博客网 时间:2024/06/07 12:00
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.
找出第一个不重复的字母,若没有,返回-1
唔,遍历一遍存每个字母出现过了几次;然后再遍历一遍,当次数为1时返回index
class Solution {public: int firstUniqChar(string s) { unordered_map<char, int> vis; for (int i = 0; i < s.length(); ++i) { vis[s[i]]++; } for (int i = 0; i < s.length(); ++i) { if (vis[s[i]] == 1) return i; } return -1; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- 了解人工智能之基础概念-基本概念问答
- SQL总结(四)编辑类
- memcached的内存管理机制
- 文章标题
- 1442.排列第几大。(排列组合问题)
- LeetCode
- ng4 路由多参数传参以及接收
- 全面剖析Pwnable.kr unlink
- sql语句优化:用join取代not in
- 利用SQL注入漏洞登录后台
- [CODEVS 1959]拔河比赛
- P1007_独木桥
- java中重载与重写的区别
- 机器学习影响现代云计算的五种方式