LeetCode: 387. First Unique Character in a String
051105
题目
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.
我的解题思路
这道题的解题思路跟LeetCode:383. Ransom Note类似,首先可以先建立一个map,遍历字符串,计算每个字符的出现的次数,之后返回第一个只出现一次的字符的位置即可。
class Solution {
public:int firstUniqChar(string s) {if(s.length()==0) return -1;unordered_map<char, int> map(26);for (int i = 0; i < s.length(); ++i)++map[s[i]];for (int i = 0; i < s.length(); ++i){if(map[s[i]]==1) return i;}return -1;}
};
围观了一波大佬的解法,发现能跟上了,加油!
LeetCode: 387. First Unique Character in a String相关推荐
- [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 ...
- python leetcode 387. First Unique Character in a String
利用find函数能极大地减少运行时间 class Solution:def firstUniqChar(self, s):""":type s: str:rtype: i ...
- 387. 字符串中的第一个唯一字符(javascript)387. First Unique Character in a String
leetcode:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 387. 字符串中的第一个唯一字符 给定一个 ...
- 387. First Unique Character in a String QuestionEditorial Solution
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- LeetCode之First Unique Character in a String
1.题目 Given a string, find the first non-repeating character in it and return it's index. If it doesn ...
- 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 ...
- leetcode 387. 字符串中的第一个唯一字符(First Unique Character in a String)
目录 题目描述: 示例: 解法: 题目描述: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 示例: s = "leetcode"返回 0. ...
- C#LeetCode刷题之#387-字符串中的第一个唯一字符(First Unique Character in a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回 ...
- First Unique Character in a String(leetcode387)
2019独角兽企业重金招聘Python工程师标准>>> Given a string, find the first non-repeating character in it an ...
最新文章
- 熬夜翻译完的PureFTPd配置文件
- 明晚8点直播 | 顺丰科技如何利用深度学习赋能智慧物流?
- python学习笔记之编写readConfig读写配置文件
- android开发系列之数据存储
- Git record
- ASP.NET Web - 服务器控件
- 046_byte的值在计算机中的表示
- 六、数据的基本统计描述
- php公告滚动源码,10行js代码实现上下滚动公告效果方法
- 队列/优先队列的应用问题
- webuploader项目中多图片上传实例
- 【修正补发】Scratch2exe-ch将sb2文件转换为exe文件
- 关于《训练指南》中的“翻棋子游戏”
- dell latitude3400 笔记本QQ语音别人听不到声音
- POJ 3537.Crosses and Crosses(定义sg函数)
- 360和腾讯之争的建议
- win10计算机还原点如何创建,win10系统如何建立自动还原点?
- 架构设计的深入思考与总结——概述
- 产品经理自学资料/UI交互设计/产品相关电子书/求职招聘/案例资料免费领取
- 物联网企业争抢「两轮车换电」赛道
热门文章
- 中国人工智能学会通讯——智能语音技术与产业应用展望 1.2 智能语音产业应用的现状和挑战...
- Fiddler小技巧-测试上传文件接口多参数并传情况
- 正则表达式了解和使用
- HTML DOM getElementById() 方法
- LabVIEW基础培训
- ashx页面中context.Session[xxx]获取不到值的解决办法
- gitlab run成功 但无法访问_gitlab 部署 管理
- html调用asp边疆,[求助]怎么实现ASP在HTML中调用
- 笔录软件在linux系统,Linux下查看已安装软件
- java 魔法王国,游历魔法王国