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't exist, return -1.
Examples:
s = "leetcode"
return 0.s = "loveleetcode",
return 2.
2、代码实现
public class Solution {public int firstUniqChar(String s) {if (s == null || s.length() == 0) {return -1;}HashMap<Character, Integer> map = new HashMap<Character, Integer>();for (int i = 0; i < s.length(); i++) {Integer in = map.get(s.charAt(i));if (in == null) map.put(s.charAt(i), 1);elsemap.put(s.charAt(i), 2);}for (int i = 0; i < s.length(); i++) {if(map.get(s.charAt(i)) == 2) {continue;} else {if (map.get(s.charAt(i)) == 1) {return i;}}} return -1;}
}
LeetCode之First Unique Character in a String相关推荐
- 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 ...
- [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 ...
- C#LeetCode刷题之#387-字符串中的第一个唯一字符(First Unique Character in a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回 ...
- leetcode 387. 字符串中的第一个唯一字符(First Unique Character in a String)
目录 题目描述: 示例: 解法: 题目描述: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 示例: s = "leetcode"返回 0. ...
- First Unique Character in a String(leetcode387)
2019独角兽企业重金招聘Python工程师标准>>> Given a string, find the first non-repeating character in it an ...
- 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 ...
- 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 ...
- 387. 字符串中的第一个唯一字符(javascript)387. First Unique Character in a String
leetcode:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 387. 字符串中的第一个唯一字符 给定一个 ...
最新文章
- 用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool
- 限定通配符和非限定通配符_为什么我不信任通配符以及为什么我们仍然需要通配符...
- web单页应用(一)
- SAP License:SD与COPA集成
- 拓端tecdat|R语言旅行推销员问题TSP
- 计算机一级题库ps视频,计算机一级Photoshop题库及答案
- IDEA jsp页面代码没有高亮
- Python操作Excel制作可视化数据图,实现自动化办公
- c语言相机翻译器下载,拍照翻译器
- 通过建设银行外联平台进行转账/提现操作(Java)
- SNF快速开发平台项目实践介绍
- android 7 蓝牙版本,Android N及高版本蓝牙适配
- 计算机代码rsi是什么意思,RSI指标计算(修正版)
- git安装问题解决方案
- 统计学习方法--牛顿法和拟牛顿法
- 我的第一个开源项目:Java爬虫爬取旧版正方教务系统课程表、成绩表
- 记忆大师(记忆练习/学习记忆/增强记忆)
- 蓝桥杯突击10-NE555方波发生器
- 【SpringBoot搭建个人博客】- 相册管理(九)
- python3自动爬笑话