给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。

案例:

s = "leetcode" 返回 0. s = "loveleetcode", 返回 2.

注意事项:您可以假定该字符串只包含小写字母。

class Solution {
public:
int firstUniqChar(string s) {
int len = s.size();
map<char, int> check;
for(int i = 0; i < len; i++)
{
check[s[i]]++;
}
for(int i = 0; i < len; i++)
{
if(check[s[i]] == 1)
return i;
}
return -1;
}
};

LeetCode387First Unique Character in a String字符串中第一个唯一字符的更多相关文章

  1. [LeetCode] 387. First Unique Character in a String 字符串的第一个唯一字符

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  2. LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)

    题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...

  3. 387 First Unique Character in a String 字符串中的第一个唯一字符

    给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1.案例:s = "leetcode"返回 0.s = "loveleetcode&qu ...

  4. [CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  5. [LeetCode] First Unique Character in a String 字符串第一个不同字符

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  6. 209. First Unique Character in a String

    Description Find the first unique character in a given string. You can assume that there is at least ...

  7. 【LeetCode】387. First Unique Character in a String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. String 字符串中含有 Unicode 编码时,转为UTF-8

    1.单纯的Unicode 转码 String a = "\u53ef\u4ee5\u6ce8\u518c"; a = new String(a.getBytes("UTF ...

  9. LeetCode_387. First Unique Character in a String

    387. First Unique Character in a String Easy Given a string, find the first non-repeating character ...

随机推荐

  1. LOIC Download

    { //https://github.com/NewEraCracker/LOIC }

  2. C++ 贪吃蛇一维

    #include <iostream> #include <conio.h> #include <windows.h> #include <time.h> ...

  3. ImageMagick convert多张照片JPG转成pdf格式,pdfunite合并PDF文件

      在认识ImageMagick之前,我***的图像浏览软件是KuickShow,截图软件是KSnapShot,这两款软件都是KDE附带的软件,用起来也是蛮方便的.在一次偶然的机会中,我遇到了Imag ...

  4. node.js在ubuntu上和windows上的安装

    Ubuntu 上安装 Node.js Node.js 源码安装 以下部分我们将介绍在Ubuntu Linux下安装 Node.js . 其他的Linux系统,如Centos等类似如下安装步骤. 在 G ...

  5. python笔记四

    #!/usr/bin/env python3 from datetime import datetime, timedelta # datetime是模块,datetime模块还包含一个datetim ...

  6. Java 内部类,成员类,局部类,匿名类等

    根据内部类的位置不同,可将内部类分为 :成员内部类与局部内部类. class outer{ class inner{//成员内部类 } public void method() { class loc ...

  7. Java程序员必备的10个大数据框架!

    作者:java妞妞 blog.csdn.net/javaniuniu/article/details/71250316 当今IT开发人员面对的最大挑战就是复杂性,硬件越来越复杂,OS越来越复杂,编程语 ...

  8. vue qs插件的使用

    参考:https://blog.csdn.net/weixin_43851769/article/details/86505164 qs 是一个增加了一些安全性的查询字符串解析和序列化字符串的库. 步 ...

  9. 机器学习-一对多(多分类)代码实现(matlab)

    %% Machine Learning Online Class - Exercise 3 | Part 1: One-vs-all % Instructions % ------------ % % ...

  10. python pip安装扩展报错

    1.安装tldr报错 (1)报错详情: [root@linuxnode1 ~]# pip install tldrCollecting tldr Downloading https://files.p ...