*387. First Unique Character in a String (linkedhashmap + string) debug manunally instead of using leetcode
The ability to debug and overall thinking need to improve
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.
Solution: using linkedHashMap<> : have the insertion order!
class Solution {
public int firstUniqChar(String s) {
Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();
for(int i = 0; i<s.length(); i++){
Character c = s.charAt(i);
if(map.containsKey(c)){
map.put(c, 2);
}else {
map.put(c,1);
}
}
char temp = '#';
for(Map.Entry<Character, Integer> entry : map.entrySet()){
System.out.println(entry.getKey() + " " + entry.getValue());
if(entry.getValue() == 1){
temp = entry.getKey();
break;
}
}
for(int i = 0; i<s.length(); i++){
if(s.charAt(i) == temp) return i;
}
return -1;
}
}
*387. First Unique Character in a String (linkedhashmap + string) debug manunally instead of using leetcode的更多相关文章
- 【LeetCode】387. First Unique Character in a String
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/first-unique-cha ...
- LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...
- 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
Problem: Given a string, find the first non-repeating character in it and return it's index. If it d ...
- leetcode修炼之路——387. First Unique Character in a String
最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: Given a string, find the first non-repeating characte ...
- 18. 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 ...
- [LeetCode&Python] Problem 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第一个不重复字母
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- Java [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 does ...
随机推荐
- http文件上传/下载
package unit; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputSt ...
- day26 网络通讯的整个流程
一.网络通信原理 1. 互联网的本质就是一系列的网络协议 2. 互联网协议按照功能不同分为osi七层或tcp/ip五层或tcp/ip四层 各层的功能简述: [1]物理层:主要定义物理设备标准,如网 ...
- python中 列表 字典 元组的了解
#######列表######1.列表的特性 server = [['http'],['ssh'],['ftp']] server1 = [['mysql'],['firewalld']] 连接 ...
- Ubuntu14.10:Install Apache,PHP,Mysql以及扩展库
step 1: Apache sudo apt-get install apache2 After have apache2 installed, go to localhost by browser ...
- 工作必备,五分钟如何搞定Excel甘特图
工作必备,五分钟如何搞定Excel甘特图 https://www.sohu.com/a/212628821_641930 EXCEL中如何给图表添加标题 1.选中图表 >> [布局] 菜 ...
- Linux安装Sqlmap等工具
简单记录一下安装过程,都是小白教程,省的哪天又忘了要去百度. 1.下载sqlmap 源码进行安装 wget https://github.com/sqlmapproject/sqlmap/tarbal ...
- pandas DataFrame数据转为list
dfpath=df[df['mm'].str.contains('20180122\d')].values dfplist=np.array(dfpath).tolist()
- 信息检索和自然语言处理 IR&NLP howto
课程: 6.891 (Fall 2003): Machine Learning Approaches for Natural Language Processing http://www.ai.mit ...
- Lights Out Game
Lights Out Game 在线的游戏:http://www.neok12.com/games/lights-out/lights-out.htm 瞎试一阵子未成之后,终于找到了标准答案:http ...
- Linux的cron服务
可以用以下命令启动和停止服务: /sbin/service crond start /sbin/service crond stop /sbin/service crond restart /sbin ...