博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【14】387. First Unique Character in a String
阅读量:4548 次
发布时间:2019-06-08

本文共 921 字,大约阅读时间需要 3 分钟。

387. First Unique Character in a String

Total Accepted: 41662

  • Total Submissions: 91486
  • Difficulty: Easy
  • Contributors: Admin

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 class Solution { 2 public: 3     int firstUniqChar(string s) { 4         unordered_map
hash; 5 for(char c : s){ 6 hash[c]++; 7 } 8 /* 9 for(int i : hash){10 if(i == 1)11 }*///没法从hash表里判断,因为只知道value不能逆向得知hash里面的key12 //所以要从原string里找13 for(int i = 0; i < s.size(); i++){14 if(hash[s[i]] == 1){15 return i;16 }17 }18 return -1;19 }20 };

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/93scarlett/p/6363944.html

你可能感兴趣的文章
innerHtml安全问题
查看>>
UVA 11992,。。。伪-二维线段树
查看>>
[原创]通过函数指针实现事件消息处理
查看>>
IE下JS保存图片
查看>>
293.Flip Game
查看>>
uvaLive5713 次小生成树
查看>>
mysql原生语句基础知识
查看>>
Ubuntu11搭建QT开发环境
查看>>
深度学习样本不均衡问题解决
查看>>
Servlet中Web.xml的配置详解
查看>>
RabbitMQ headers Exchange
查看>>
硬件产品测试
查看>>
nmon for linux
查看>>
H5 EventSource 实现web页面推送功能demo
查看>>
Android JNI 学习(十):String Operations Api & Other Apis
查看>>
AutoMapper
查看>>
ecshop绕过验证码暴力破解
查看>>
数组和字符串的API使用
查看>>
201671010118 2016-2017-2《Java程序设计》 第十一周学习心得
查看>>
Get Sauce(状压DP)
查看>>