[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 exist, return -1.

Examples:

s = "leetcode"
return 0.

s = "loveleetcode",
return 2.

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

用数组,简单粗暴,把字符个数都记录下来,最后遍历一下原来的字符串,判断再这个数组里面的个数就行。

public int firstUniqChar1(String s) {
        if (s == null || s.length() == 0)
            return -1;
        int[] 
LeetCode 旋转数字(多种算法实现) 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 同的数。要求每位数字都要被旋转。 如果一个数的每位数字被旋转以后仍然还是一个数字, 则这个数是有效的。0, 1, 和 8 被旋转后仍然是它们自己;2 和 5 可以互相旋转成对方;6 和 9 同理,除了这些以外其他的数字旋转以后都再是有效的数字。 现在我们有一个正整数 N, 计算从 1 到... 阅读详情

相关推荐

SpringBoot 入门小程序

SpringBoot 入门小程序CSDN下载 SpringBoot 入门小程序GitHub下载 老规矩,先看项目结构。 有必要参考前面的博客。maven构建web工程 我们构建好maven工程之后,用pom导入jar包。 pom.xml <project xmlns="http://maven.apac...

weixin_33866037的博客 214

LeetCode387First Unique Character in a String

LeetCode387 First Unique Character in A String

上善若水 1862

LeetCode //C - 387. First Unique Character in a String

【代码】LeetCode //C - 387. First Unique Character in a String

Made in Code 967

Leetcode PHP题解--D100 387. First Unique Character in a String

D100 387. First Unique Character in a String 题目链接 387. First Unique Character in a String 题目分析 返回给定字符串中第一个只出现了一次的单词下标。 若没有,则返回-1。 思路 把遇到的单词存进两个数组。 ...

240

LeetCode 387. First Unique Character in a String 题解

本题是字符串处理的基础问题。字符计数遍历顺序边界条件处理通过本题可以深入理解哈希表和数组在字符处理中的应用。

cannonjinx的博客 1005

leetcode 387. First Unique Character in a String

目录 一、问题描述 二、代码实现 1、两遍遍历 2、一遍遍历 https://leetcode.com/problems/first-unique-character-in-a-string/ 返回给定字符第一个只出现一次的字符的下标,存在则返回-1 一、问题描述 测试用例: s = "leetcode" return 0. s = "loveleetcode...

小景的博客 212

[LeetCode]387. First Unique Character in a String

[LeetCode]387. First Unique Character in a String题目描述思路遍历,对于每个字符,找到第一个相同的字符就终止 找到第一满足条件的字符,终止循环代码class Solution { public: int firstUniqChar(string s) { int len = s.size(); int resu

Lcharon的博客 3290

LeetCode387First 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 exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2.

指尖飞舞 2486

Leetcode387. First Unique Character in a String

class Solution1(object): def firstUniqChar(self, s): """ use dictionary and scan two pass """ from collections import defaultdict dictonary = defaultdict(i...

很吵请安静 183

LeetCode String 387 First Unique Character in a String

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 exist, return -1. Examples: s = “leetcode” return 0. s = “lov...

Yi Jiao's Blog 141

LeetCode387 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 exist, return -1. 给定一个字符串,找到其中第一个重复字符并返回它的索引。如果存在,返回-1。 Examples: s = "leetcode" return 0....

bystc的博客 273

leetcode[387]First Unique Character in a String

问题:给定一个字符串,找到它的第一个重复字符,并返回它的索引。 输入:一个字符串(仅包含英文小写字母) 输出:第一个重复字符索引(存在则返回-1) 思路: 遍历一遍字符串,利用hash表存储,每个字符为key时,value加1。 然后,正序遍历一遍字符串,如果value为1,则返回其索引。 (或者,遍历一遍hash表,如下第一个代码,判断是否为重复的数字,比较得到最小的索...

Black Mamba的博客 186

LeetCode387. First Unique Character in a String

字符串中首个重复字符

grllery的博客 375

[leetcode] 387. First Unique Character in a String 解题报告

题目链接:https://leetcode.com/problems/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 exist, return -1. Examp

小榕流光的专栏 2697

LeetCode 387. First Unique Character in a String

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 exist, return -1. Examples: s = "leetcode" retu

雪水 571

LeetCode & 剑指offer刷题】字符串题1:50 第一个只出现一次的字符387. First Unique Character in a String...

LeetCode &amp; 剑指offer刷题】字符串题1:50 第一个只出现一次的字符387. First Unique Character in a String) 【LeetCode &amp; 剑指offer 刷题笔记】目录(持续更新中...387. First Unique Character in a String G...

技术改变世界 1176
上一篇: [LeetCode]--383. Ransom Note
下一篇: [LeetCode]--389. Find the Difference
杜鲁门
博客等级 码龄11年 219粉丝 316原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值