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. s=""
return -1;

Note:

You may assume the string contain only lowercase letters.

 public class Solution{
public int firstUniqChar(String s){
if (s == null || s.equals("")) return -1;
char[] c = s.toCharArray();
int[] cnt = new int[256]; for (int i = 0; i < c.length; i++) {
cnt[c[i]]++;
System.out.println(cnt[c[i]]);
} for (int i = 0; i < c.length; i++) {
if (cnt[c[i]] == 1) return i;
}
return -1;
}
}

FirstUniqueCharacterInString的更多相关文章

随机推荐

  1. No compiler is provided in this environment. Perhaps you are running on a JRE ra

    No compiler is provided in this environment. Perhaps you are running on a JRE ra,有需要的朋友可以参考下. 控制台输出的 ...

  2. javaSE基础第二篇

    1.JDK下载: www.oracle.com   2.JAVA_HOME bin目录:存放可执行文件.exe 把可能变的路径写入JAVA_HOME path=......;%JAVA_HOME%%; ...

  3. 图片轮播器bcastr4.swf“&”符号的问题

    bcastr4.swf是一个很不错的网页图片轮播器,我一直使用它作为网站首页图片轮播的控件. http://xiaogui.org/bcastr-open-source-flash-image-sil ...

  4. linux mysql root密码重置

    MySQL安装解决方法:重改密码 先停止 Mysql # stop mysql 重要:输入下面的代码# mysqld_safe --user=mysql --skip-grant-tables --s ...

  5. 安装hive+mysql

    1.源码安装mysql 以root用户首先安装libaio-0.3.104.tar.gz tar zxvf libaio-0.3.104.tar.gz cd libaio-0.3.104 make p ...

  6. SpringMVC 温故而知新

    http://www.cnblogs.com/bigdataZJ/p/5815467.html直接引用别人的吧,没时间呀

  7. PopupWindowAction breaking MEF import?

    If you use Prism InteractionRequest.PopupWindowAction feature, you might have found the MEF Import a ...

  8. javascript的类型、值和变量

    js的类型有多种分类,原始类型(数值,字符串,布尔值,null,undefined)和对象类型(object,String,Number,RgbExp等),或者是拥有方法的类型(object,Stri ...

  9. hdu 3839 Ancient Messages (dfs )

    题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...

  10. DELPHI XE5 与SQLITE

    最近一次使用DELPHI做项目是使用DELPHI2009,为了访问本地数据库方便,使用ACCESS数据库,不需要安装驱动,(WINDOWS自带),但是ACCESS数据库的性能确实很糟糕,通过ADO连接 ...