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 ...
随机推荐
- 【翻译】编译Cordova项目
针对iOS创建项目 需要安装iOS SDK才能创建Workshop项目 打开终端工具并使用cd命令进入workshop目录执行下面都命令 cordova build ios 项目建立在workshop ...
- Enhancing Reliability and Response Times via Replication in Computing Clusters---INFOCOM 2015
[标题] Enhancing Reliability and Response Times via Replication in Computing Clusters [作者] Zhan Qiu an ...
- linux和windows双系统时间错误解决方法
转自http://www.2cto.com/os/201204/126212.html windows时间会慢8小时,原因: 两个概念: UTC即Universal Time Coordinated, ...
- OAuth2.0 工作流程
重要术语 Authorization Server:授权服务器,能够成功验证资源拥有者和获取授权,并在此之后分发令牌的服务器: Resource Server:资源服务器,存储用户的数据资源,能够 ...
- nodejs在cmd提示不是内部或外部命令解决方法
今天用cmd安装个库,结果发现node不是内部命令,于是搜索了下解决方法,发现原来我上次重装nodejs换了个安装位置,path环境变量忘改了. 找到变量值中node的安装地址,比如C:develop ...
- fido-uaf-protocol-v1.0
EXAMPLE 1: Policy matching either a FPS-, or Face Recognition-based Authenticator { "accepted&q ...
- Ubuntu 14.0 升级内核到指定版本
1.卸载现有内核sudo apt purge linux-headers-* linux-headers-*-generic linux-image-*-generic linux-image-ext ...
- android app 集成 信鸽推送
推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客, ...
- noip2015Day2T1-跳石头
题目描述 Description 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有N ...
- mysql查超过15分钟未付款的订单,更新为失效状态
个人打开自己的订单时,才检查超过15分钟未付款的订单, 暂不使用机器人,更新状态, Difference counter 差分计数器订单超过15分钟.mysql的时间戳差分比较 $sql = TIM ...