FirstUniqueCharacterInString
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的更多相关文章
随机推荐
- Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- OC的总结 ***希望对大家有帮助*** ---高小杰
1. NSLog 是Foundation提供的一个输出函数,它的功能非常强大,不仅可以输出字符串,还可以输出各种对象,到后面程序还会见到大量的使用NSLog()函数. 2. N ...
- opencv的学习笔记5
总结原博文中的一些边缘检测算子和滤波器.(Canny算子, Sobel算子, Laplace算子以及Scharr滤波器) 首先,一般的边缘检测包括三个步骤: 1)滤波:边缘检测的算法主要是基于图像 ...
- N久没写过东西了..写个最近在研究的程序
import numpy as np import matplotlib.pyplot as plt #a = np.matrix([[1,1.15],[1,1.9],[1,3.06],[1,4.66 ...
- Application Pool
- ASP.NET MVC 异步获取和刷新ExtJS6 TreeStore
从数据库获取构造树结构是ExtJS TreePanel的核心技术,常用方法是TreeStroe里配置proxy,这种方式的root成了一个不受控制的节点. TreeStroe的root实际是一个层叠j ...
- Bootstrap栅格系统详解,响应式布局
Bootstrap栅格系统详解 栅格系统介绍 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 栅格系统用于通 ...
- sqlalchemy ORM
本节内容 ORM介绍 sqlalchemy安装 sqlalchemy基本使用 多外键关联 多对多关系 1. ORM介绍 orm英文全称object ...
- AOP报错:Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut
Spring3.x升级4.x时遇到的,JDK版本1.7 aspectj版本问题,1.6.x升级到1.7.x,解决!
- PHP Problem with the SSL CA cert (path? access rights?)
1.php使用curl模块报错问题 开发遇到问题,直接使用系统的curl命令正常,使用php的curl模块报错 错误:PHP Problem with the SSL CA cert (path? a ...