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相关推荐

  1. 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 ...

  2. [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 ...

  3. python leetcode 387. First Unique Character in a String

    利用find函数能极大地减少运行时间 class Solution:def firstUniqChar(self, s):""":type s: str:rtype: i ...

  4. C#LeetCode刷题之#387-字符串中的第一个唯一字符(First Unique Character in a String)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回 ...

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

    目录 题目描述: 示例: 解法: 题目描述: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 示例: s = "leetcode"返回 0. ...

  6. First Unique Character in a String(leetcode387)

    2019独角兽企业重金招聘Python工程师标准>>> Given a string, find the first non-repeating character in it an ...

  7. 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 ...

  8. 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 ...

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

    leetcode:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 387. 字符串中的第一个唯一字符 给定一个 ...

最新文章

  1. 用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool
  2. 限定通配符和非限定通配符_为什么我不信任通配符以及为什么我们仍然需要通配符...
  3. web单页应用(一)
  4. SAP License:SD与COPA集成
  5. 拓端tecdat|R语言旅行推销员问题TSP
  6. 计算机一级题库ps视频,计算机一级Photoshop题库及答案
  7. IDEA jsp页面代码没有高亮
  8. Python操作Excel制作可视化数据图,实现自动化办公
  9. c语言相机翻译器下载,拍照翻译器
  10. 通过建设银行外联平台进行转账/提现操作(Java)
  11. SNF快速开发平台项目实践介绍
  12. android 7 蓝牙版本,Android N及高版本蓝牙适配
  13. 计算机代码rsi是什么意思,RSI指标计算(修正版)
  14. git安装问题解决方案
  15. 统计学习方法--牛顿法和拟牛顿法
  16. 我的第一个开源项目:Java爬虫爬取旧版正方教务系统课程表、成绩表
  17. 记忆大师(记忆练习/学习记忆/增强记忆)
  18. 蓝桥杯突击10-NE555方波发生器
  19. 【SpringBoot搭建个人博客】- 相册管理(九)
  20. python3自动爬笑话

热门文章

  1. 杨中科的.NET 6新书的出版进度汇报
  2. WPF开源项目:WPF-ControlBase
  3. 鹅厂二面,Nginx回忆录
  4. .NET 5 部署在docker上运行
  5. 没有Kubernets,学习Docker还有用吗?
  6. 【BCVP】实现基于 Redis 的消息队列
  7. Asp.Net Core多榜逆袭,这是.NET最好的时代!
  8. 【项目升级】单库、多库、读写分离 · 任你选
  9. 【朝夕技术专刊】Core3.1WebApi_Filter多种注册方式支持依赖注入
  10. 微软推出全新的Windows 10系统图标