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.

Note: You may assume the string contain only lowercase letters.

 class Solution {
public int firstUniqChar(String s) {
int freq[] = new int[];
for (int i = ; i < s.length(); i++) {
freq[s.charAt(i) - 'a']++;
} for (int i = ; i < s.length(); i++) {
if (freq[s.charAt(i) - 'a'] == ) {
return i;
}
}
return -;
}
}

First Unique Character in a String的更多相关文章

  1. 209. First Unique Character in a String

    Description Find the first unique character in a given string. You can assume that there is at least ...

  2. LeetCode_387. First Unique Character in a String

    387. First Unique Character in a String Easy Given a string, find the first non-repeating character ...

  3. Leetcode算法比赛----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 ...

  4. LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)

    题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...

  5. [LeetCode] 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 ...

  6. 387. 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 ...

  7. LeetCode 387. First Unique Character in a String

    Problem: Given a string, find the first non-repeating character in it and return it's index. If it d ...

  8. LeetCode First Unique Character in a String

    原题链接在这里:https://leetcode.com/problems/first-unique-character-in-a-string/ 题目: Given a string, find t ...

  9. leetcode修炼之路——387. First Unique Character in a String

    最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: Given a string, find the first non-repeating characte ...

  10. 18. leetcode 387. 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 ...

随机推荐

  1. 菜鸟学python之程序初体验

    作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2684 1.字符串操作: 解析身份证号:生日.性别.出生地等. def id ...

  2. win 解压安装mysql步骤

    5  安装成功之后,启动mysql时报错: 系统错误2,找不到指定的文件.原因:有的系统安装过MySQL没有卸载干净,或者系统自带精简版的MySQL导致注册表关于MySQL的配置与实际安装路径不一致. ...

  3. cordova的常用命令

    常用命令 npm install -g cordova // 加载cordovecordova create MyApp //创建一个新的文件夹cd MyApp //找到当前目录cordova pla ...

  4. Python进阶8---面向对象基础1

    面向对象 语言的分类 Python的类 定义 class ClassName: pass class MyCalss: """A example class"& ...

  5. 利用ajax技术 实现用户注册。

    一.ajax? 异步加载技术,在不刷新网页的前提下,实现部分网页内容的更新! AJAX 最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容. 思考? 注册界面刚好可以应用 ...

  6. Want To Say Something

    2019.3.3 明天要演讲了,在这里为自己打一下气! 加油!     2019.3.31 停课三周的第一次写日志 怎么说这三周结交了很多八班的朋友 在竞赛上一直在学数论快学吐了,但没办法呀还是要为出 ...

  7. Linux下批量管理工具pssh安装和使用

    Linux下批量管理工具pssh安装和使用 pssh工具包 安装:yum -y install pssh pssh:在多个主机上并行地运行命令 pscp:把文件并行地复制到多个主机上 prsync:通 ...

  8. Outlook 2013 日历/任务本地备份与还原

    1.日历: 备份日历:切换到日历项,按如下步骤备份.文件 --> 保存日历 --> 其它选项: 日期范围:指定日期(开始日期:2018/1/1,结束日期:2018/12/31) 详细信息: ...

  9. opencv + cuda编译

    #获取最新代码git clone "https://github.com/opencv/opencv.git" #build目录mkdir buildcd build #使用ccm ...

  10. linux 常用命令集锦

    喝断片儿了,我是谁?我在什么地方?我做过些什么事?查看当前用户 who am i查看当前路径 pwd查看历史记录 history 我忘了程序放哪了,就记得个名.更新系统数据库 updatedb查找文件 ...