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 exist, return -1.
Examples:
s = "leetcode"
return 0. s = "loveleetcode",
return 2.
Note: You may assume the string contain only lowercase letters.
class Solution {
public int firstUniqChar(String s) {
int freq[] = new int[];
for (int i = ; i < s.length(); i++) {
freq[s.charAt(i) - 'a']++;
}
for (int i = ; i < s.length(); i++) {
if (freq[s.charAt(i) - 'a'] == ) {
return i;
}
}
return -;
}
}
First Unique Character in a String的更多相关文章
- 209. First Unique Character in a String
Description Find the first unique character in a given string. You can assume that there is at least ...
- LeetCode_387. First Unique Character in a String
387. First Unique Character in a String Easy Given a string, find the first non-repeating character ...
- Leetcode算法比赛----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 ...
- LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...
- [LeetCode] 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. 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 First Unique Character in a String
原题链接在这里:https://leetcode.com/problems/first-unique-character-in-a-string/ 题目: Given a string, find t ...
- 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 ...
随机推荐
- 企业出口退税申报系统的Sqlite数据库破解及读写
QQ:564955427 原始出处:https://www.cnblogs.com/Charltsing/p/TSSB.html 最近一些朋友反映龙图的企业出口退税申报系统的Sqlite数据库改变了加 ...
- 正则表达式和re模块
目录 re的元字符 字符集[ ] 转义符 分组 ( ) |符号 re下的常用方法 分组 re的元字符 import re ret = re.findall("e..a", &quo ...
- MVC 全局过滤器
1. 新创建一个类 CheckLogin2. 在类中加入以下代码 public class CheckLogin : ActionFilterAttribute { public override v ...
- deeplearing4j学习以及踩过的坑
1. 添加dl4j后, run项目时, 一直run不起来, run按钮绿色但是点击没反应. 查看日志后发现: 是classpath太长导致的. 在本项目的.idea文件夹,找到文件夹中的works ...
- 【zabbix教程系列】六、自动注册(Linux)
一.agent安装脚本 #!/bin/bash #ltt #安装zabbix源 rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zab ...
- Ajax 的优势和不足
Ajax 的优势 1. 不需要插件支持 Ajax 不需要任何浏览器插件,就可以被绝大多数主流浏览器所支持,用户只需要允许 JavaScript 在浏览器上执行即可. 2. 优秀的用户体验 这是 Aja ...
- 初识flink
接触flink已经有3个月了,第一次接触flink是从极客时间上的大沙的演讲中了解的. 最近半年对大数据已经有了一定的入门,一方面因为工作中会用到hive,另外工作已经快5年了,一直从事java后台开 ...
- 利用layui前端框架实现对不同文件夹的多文件上传
利用layui前端框架实现对不同文件夹的多文件上传 问题场景: 普通的input标签实现多文件上传时,只能对同一个文件夹下的多个文件进行上传,如果要同时上传两个或多个文件夹下的文件,是无法实现的.这篇 ...
- codeforces16B
Burglar and Matches CodeForces - 16B A burglar got into a matches warehouse and wants to steal as ma ...
- 【BZOJ4002】[JLOI2015]有意义的字符串(数论,矩阵快速幂)
[BZOJ4002][JLOI2015]有意义的字符串(数论,矩阵快速幂) 题面 BZOJ 洛谷 题解 发现我这种题总是做不动... 令\(A=\frac{b+\sqrt d}{2},B=\frac{ ...