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. Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用(转)

    原文地址:https://www.cnblogs.com/fashflying/p/6908028.html 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对 ...

  2. Photoshop打造唯美的蓝色古装外景人物图片

    <点小图查看大图> 最终效果 1.打开原图素材大图,按Ctrl + J 把背景图层复制一层,用模糊工具把红圈区域背景模糊处理. <图1> 2.创建可选颜色调整图层,对黄色,绿色 ...

  3. java返回数据工具类

    import com.qbskj.project.util.SpringUtils; /** * 消息 * */ public class Message { /** * 类型 */ public e ...

  4. 浅析Java数据类型

    前言: 该系列会辅以MindMap进行说明. 下面会贴两张我不同时期画的Java数据类型的思维导图,本篇主要侧重于Java的8种基本类型 MindMap-1 这张MindMap主要是根据 菜鸟教程+参 ...

  5. ionic3隐藏子页面的tabs和配置返回按钮

    在app.modlues.ts文件中修改 imports: [ BrowserModule, IonicModule.forRoot(MyApp, { tabsHideOnSubPages: 'tru ...

  6. codeforces305A

    Strange Addition CodeForces - 305A Unfortunately, Vasya can only sum pairs of integers (a, b), such ...

  7. [ffmpeg] 解码API

    版本迭代 ffmpeg解码API经过了好几个版本的迭代,上一个版本的API是 解码视频:avcodec_decode_video2 解码音频:avcodec_decode_audio4 我们现在能看到 ...

  8. linux 系统工具图

  9. leanote使用本地账户时,去掉待同步的小红点

    切换开发者工具,如下图,点击左上角的箭头图标,选取元素,直接选择小红点. 然后会看到小红点来自于resources/app/public/themes/default.css文件中2092行: .it ...

  10. mysql优化 | 存储引擎,建表,索引,sql的优化建议

    个人对于选择存储引擎,建表,建索引,sql优化的一些总结,给读者提供一些参考意见 推荐访问我的个人网站,排版更好看: https://chenmingyu.top/mysql-optimize/ 存储 ...