leetcode387
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.
找出第一次出现的不重复的字符
public class Solution {
public int firstUniqChar(String s) {
//97-122
int[] map = new int[123];
int i=0;
int length = s.length();
for(i=0;i<length;i++)
{
map[s.charAt(i)]++;
}
for(i=0;i<length;i++)
{
if(map[s.charAt(i)] == 1)
return i;
}
return -1;
}
}
除了两次for循环,暂时没有想到N时间复杂度的解法。
leetcode387的更多相关文章
- [Swift]LeetCode387. 字符串中的第一个唯一字符 | 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 ...
随机推荐
- 使用vs2010打开VS2013的工程文件
在开发团队,会出现vs工具使用版本的不一样的情况.我的电脑使用的是VS2010,可是其他人员使用的是vs2013. 要打开其他人员上传的工程文件,可以通过三种方式: 1.下载一个vs2013版本. 2 ...
- Voting
Voting time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- rsync 断点续传
# rsync -avzP file root@172.20.7.219:/root/tmp (我这里file指要传送的文件)
- laravel php artisan migrate 数据迁移时出现的[HY000][1045]错误
(zz找了块一个小时才发现)主要的错误在于.env文件和database.php的配置不匹配. 1.找到.env文件 2.更改数据库表账密 3.改database.php的数据库账密 4.完成
- angularjs uigrid 中celltemplate的写浮动框
columnDefs: [ {field: 'collegename', enableFiltering: false ,width:"12%",displayName:" ...
- 工艺成型及仿真、铸造工艺及仿真ProCAST软件入门认识介绍
视频源:技术邻 关键词:ProCAST.工艺成型及仿真.铸造工艺及仿真 简介:ProCAST 软件是由美国 USE 公司开发的铸造过程的模拟软件采用基于有限元(FEM)的数值计算和综合求解的方法,对铸 ...
- 为啥使用Iscroll.js之后,a不能触发点击事件?
原因:是iscroll.js阻止了a的行为. 解决方法:打开iscroll-probe.js,然后找到preventDefaultException方法. 然后修改为: // preventDefau ...
- redis连接池操作
/** * @类描述 redis 工具 * @功能名 POJO * @author zxf * @date 2014年11月25日 */public final class RedisUtil { p ...
- js提交form表单
<form action="/Enterprise/member" id="sendinviteid" method="post"&g ...
- Spring自动扫描
需要在Springde 配置文件中加入 <context:component-scan base-package="com.annoation"> base-packa ...