给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -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. [JZOJ6278] 2019.8.5【NOIP提高组A】跳房子

    题目 题目大意 给你一个矩阵,从\((1,1)\)开始,每次往右上.右.右下三个格子中权值最大的那个跳. 第一行上面是第\(n\)行,第\(m\)列右边是第\(1\)列.反之同理. 有两个操作:跳\( ...

  2. JVM中堆栈

    1.JVM是基于堆栈的虚拟机.JVM为每个新创建的线程都分配一个堆栈.也就是说,对于一个Java程序来说,它的运行就是通过对堆栈的操作来完成的.堆栈以帧为单位保存线程的状态.JVM对堆栈只进行两种操作 ...

  3. 常用css初始化样式(淘宝)

    最简单粗暴的css初始化样式就是:*{padding:0:margin:0}(不推荐) 淘宝的样式初始化: body, h1, h2, h3, h4, h5, h6, hr, p, blockquot ...

  4. VS2010-MFC(对话框:向导对话框的创建及显示)

    转自:http://www.jizhuomi.com/software/166.html 上一节讲了属性页对话框和相关的两个类CPropertyPage类和CPropertySheet类,对使用属性页 ...

  5. Ubuntu下搭建Pixhawk开发环境

    安装提示 需要网络环境,不然下载会很慢. 工具安装 1. 权限设置 sudo usermod -a -G dialout $USER 代码输入可以拷贝,但是不可以用快捷键. 需要输入密码,输入密码无显 ...

  6. Python第一课-Python的下载与安装

    官网 https://www.python.org/ 我们安装的是windows 系统 Python3和Python2版本不兼容,我们下载最新的Python3.7.4 下载executatable版本 ...

  7. <selenium>selenium基础操作

    from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.c ...

  8. WPF基础之Grid面板

    一.显示 Grid的线条,设置ShowGridLiens="True".

  9. 03-css选择器

    <!doctype html><!--声明文档类型 网页文档--> <html><!--根目录标签 父级--> <head><!--网 ...

  10. 基于Java Properties类设置本地配置文件

    一.Java Properties类介绍 Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件, ...