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.
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...
- [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 ...
- 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 ...
- 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 ...
- LeetCode First Unique Character in a String
原题链接在这里:https://leetcode.com/problems/first-unique-character-in-a-string/ 题目: Given a string, find t ...
- leetcode修炼之路——387. First Unique Character in a String
最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: Given a string, find the first non-repeating characte ...
- 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 ...
随机推荐
- C语言之将弧度值转换为角度值
#include<stdio.h> #include<stdlib.h> #define pi 3.141592 void conver_radian(float radian ...
- ecshop 商品属性显示方法
功能:在商品列表上,点击放大镜,显示商品所有属性以及其价格,效果如下: 方法/步骤: 1.编辑\admin\templates\goods_list.htm 模板,在 <!-- 商品搜索 --& ...
- 搭建一个MP-demo(mybatis_plus)
MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 搭建一个简单的MP-demo 1.配置pom.xml ...
- python_正则表达式随笔
webpage_regex = re.search(r'span_ed7[\s\S]*', dd) [\s\S]* 匹配多行,转义字符 webpage_regex = re.compile('< ...
- Centos7 安装gitLab
我这里使用的是centos 7 64bit,我试过centos 6也是可以的! 1. 安装依赖软件 yum -y install policycoreutils openssh-server open ...
- parcel+vue入门
一.parcel简单使用 npm install -D parcel-bundler npm init -y (-y表示yes,跳过项目初始化提问阶段,直接生成package.json 文件.) Pa ...
- Xshell连接ubuntu server端的vim(256色彩配置)
VIM主题(Xshell端) [注]我的配置:Xshell连接VMware Workstation Pro下的Ubuntu 18 server版(要注意这里的server版,好似该版本没有下述的256 ...
- IAR使用跳转功能时不正常的情况
@2019-04-12 [小记] [使用环境]IAR-Arm8.30.1 [验证] 均为实测 1. 出现如下图这种情况应该是工程所在路径太深导致 2. 如果不弹出上图警告,但还是不跳转应该是工程编译信 ...
- CF1155E Guess the Root
题意:交互,有一个10次多项式,你可以询问50次当x为某个取值时多项式的值.你需要回答这个多项式的零点. 解:询问11个数然后高斯消元解方程得出系数.然后枚举定义域看有无0点. #include &l ...
- Ubuntu18安装Pycharm时遇到的几个问题
今天给电脑安装了Ubuntu18.04,安装了一些基础软件. 这里是Ubuntu安装Pycharm的一些问题: 1.安装Pycharm. 首先需要到Pycharm官网进行下载安装包,由于我的是Ubun ...