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 ...
随机推荐
- echarts x轴或y轴文本字体颜色改变
1:x轴文本字体颜色改变 xAxis : [ { type : 'category', data : ['<30','30-','40-','50-','60-','>=70'], axi ...
- rsync 断点续传
# rsync -avzP file root@172.20.7.219:/root/tmp (我这里file指要传送的文件)
- we are happy 把空格换成 %20 剑指offer P44
public class StringReplace { public static void replaceSpace(String[] str, int length) { if(str == n ...
- datatables.js 里面遇到的问题
1. 假如需要A行的data 和 B行的data 合并 在B行 data:name 在A行的 render:function(){ return data+full.name 此时返回的就是A+B ...
- Github朝花夕拾
删除fork的项目 下载指定revision的repository 通过git log查看提交历史,最好是GUI查看 然后执行命令git reset –hard <sha1> 同步到最 ...
- 学到的较复杂的 mysql 语名
需求是这样的:需要找出没有发任务的店铺是哪些.好让客服去联系他们,询问情况. 每个商家可以有N个店铺,每个店铺可以放N个任务,一个任务会生成N个任务订单,会员接到任务去完成 SELECT *FROM ...
- ARM驱动调试方法、思路总结、笔记
驱动程序的调试一. 打印: prink, 自制proc文件UBOOT传入console=ttySAC0 console=tty11. 内核处理UBOOT传入的参数console_setup add_p ...
- ssh 依赖关系
安装ssh时: sudo apt-get install openssh-server 出现错误: 下列软件包有未满足的依赖关系: openssh-server : 依赖: openssh-clien ...
- 《Windows编程循序渐进》——建立MFC应用程序
如何建立MFC应用程序 打开VS2013:
- 第七十七节,CSS3前缀和rem长度单位
CSS3前缀和rem长度单位 学习要点: 1.CSS3前缀 2.长度单位rem 本章主要探讨HTML5中CSS在发展中实行标准化的一些问题,重点探讨CSS3中新属性前缀问题和新的单位rem. 一 CS ...