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. Vue 部署IIS 单页面刷新报404问题

    参考地址: https://blog.csdn.net/yinjing8435/article/details/71274416

  2. Vue 路由心得总结

    一. 嵌套路由 a.主页面,  main.vue ,   子页面分别为  shouye.vue   /    liuyan.vue   / about.vue   , 首先, 在main.vue加入导 ...

  3. 用redis实现分布式锁,秒杀案例(转)

    分布式锁的简单实现代码: 需要的jar包: jedis-2.9.0.jar. commons-pool2-2.4.2.jar import java.util.List; import java.ut ...

  4. [转帖]优化IMPDP/EXPDP导入导出速度

    优化IMPDP/EXPDP导入导出速度 https://www.2cto.com/database/201308/238176.html 一年半没太学习数据库了.. 其实这个parallel 的参数一 ...

  5. mysql时间比较

    ' and ZXBZ ='Y' AND SQRQ >= '2017-04-28 00:00:00' AND SQRQ <= '2017-04-28 23:59:59'; ;

  6. 题解 P2763 【试题库问题】

    这题可以用网络流,但我用的是匈牙利算法 进入正题 设第个类型需要个.将每个类型拆成个点,用一个边集数组记录它拆成的点. 第个试题有个类型,分别将与拆成的点连边,这样便构成了一个二分图. 使用匈牙利算法 ...

  7. golang项目练习

    一.记账系统 1.该软件能够记录收入.支出,并能够打印收支明细表 2. 代码 package main import ( . "fmt" ) func menu() string{ ...

  8. html 通用导航 a链接跳转时给当前导航添加选中颜色

    学习前端的同学或许会遇到这个问题 做一个基本的小站有几个导航的,如下图 无论有几个页面,这里的导航的样式都是一样,唯一不同的就是进入哪个页面时当前有个选中的样式 一般这样通用的导航在开发的时候都会封装 ...

  9. TsinsenA1489 抽奖 【期望】

    题目分析: 问题可以转化成将m个球放进n个盒子里,每个盒子的贡献为盒子中球数的平方. 第一问考虑增量. 对于一个原本有$x$个球的盒子,新加一个球的贡献是$2x+1$.期望条件下仍然满足. 第$i$个 ...

  10. THUWC2019 游记

    DAY1 开场先看 t1,发现答案的分子就是 \(\sum_i\) 颜色 \(i\) 在 A 中的出现次数乘上颜色 \(i\) 在 B 中的出现次数,分母就是 B 的长度,就去写了一个按颜色的出现次数 ...