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 ...
随机推荐
- lucene 总结收集(url)
1.倒排索引结构 2.lucene自定义评分域 3.Lucene系列-FieldCache 4.Lucene系列-facet | IT瘾 5.lucene4.7 之排序 6.lucene排序---相关 ...
- MAC下安装automake autoconf工具
I noticed today that while Mac OS 10.6 (specifically, 10.6.2) comes with automake and autoconf, the ...
- ZeroMQ中PUB-SUB模式测试
因为公司有需求,对程序模块之间通信效率有较高的需求.之前公司用的通信组件是ActiveMQ,根据网上公布的测试结果显示其效率比较低, 后来考虑准备在新的项目中开始使用ZeroMQ.看了几天发现用起来比 ...
- WebApi Help Pages
如何新建Help Pages在此不多复述,网上很多: https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/ ...
- Finish and error to: Error Domain=NSURLErrorDomain Code=-1001 "请求超时。
错误显示:Finish and error to: Error Domain=NSURLErrorDomain Code=-1001 "请求超时." UserInfo={NSUnd ...
- java变量初始化
java全局变量会自动初始化,但局部变量不会自动初始化.当我们新建一个对象的时候,java会申请一个区域存放类的数据,而成员变量就是类的数据,也是放在这个内存区域中,jvm申请内存时初始化.而方法中变 ...
- Linux服务器rsync自动备份
一.在 server 端配置 1. 编辑配置文件 #vi /etc/rsyncd.conf 添加下面的配置参数: uid = nobody # 该选项指定当该模块传输文件时守护进程应该具有的uid.默 ...
- JQ中的clone()方法与DOM中的cloneNode()方法
JQ中的clone()方法与DOM中的cloneNode()方法 cloneNode()定义和用法 cloneNode()方法创建节点的拷贝,并返回该副本. 语法: node.cloneNode(de ...
- 2016年团体程序设计天梯赛-决赛 L1-8. Left-pad(20)
根据新浪微博上的消息,有一位开发者不满NPM(Node Package Manager)的做法,收回了自己的开源代码,其中包括一个叫left-pad的模块,就是这个模块把javascript里面的Re ...
- apt-get 安装路径
apt-get安装目录和安装路径:apt-get 下载后,软件所在路径是:/var/cache/apt/archivesubuntu 默认的PATH为PATH=/home/brightman/bin: ...