[LeetCode&Python] Problem 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.
from collections import Counter
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
m=100000
a=Counter(s)
for i in a:
if a[i]==1:
ind=s.index(i)
if m>ind:
m=ind if m<100000:
return m
return -1
[LeetCode&Python] Problem 387. First Unique Character in a String的更多相关文章
- 【leetcode❤python】387. First Unique Character in a String
#-*- coding: UTF-8 -*- class Solution(object): def firstUniqChar(self, s): s=s.lower() ...
- 【LeetCode】387. First Unique Character in a String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 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 387. First Unique Character in a String (字符串中的第一个唯一字符)
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...
- [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 ...
- 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 ...
- [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 ...
- Java [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 does ...
随机推荐
- js如何简单实现汉字转成拼音的功能
最近项目需要一个功能,实现汉字转拼音功能,具体比如说输入一个“你好”,同时带出对应拼音“NiHao”,在此做一下记录 1.首先引入两个文件 <script src="jquery.mi ...
- mysql 如何在访问某张数据表按照某个字段分类输出
也许大家有时候会遇到需要将把数据库中的某张表的数据按照该表的某个字段分类输出,比如一张数据表area如下 我们需要将里面的area按照serialize字段进行分类输出,比如这种形式: areas ...
- Linux第六周作业
一 实验过程 1 先进入LinuxKernel环境下,更新menu代码到最新版,用到的命令为rm menu -rf //强制删除当前menu,git clone http://git.shiyanlo ...
- url 传参数时出现中文乱码该怎么解决
一般出现乱码都是在js裏面跳转到哪个类 然後得到这个参数的时候中文乱码,有一个非常实用的办法,在js你可以这样写:var url=........;url=encodeURI(url); url=en ...
- [javamail]AUTH LOGIN failed;Invalid username or password报错
项目中需要用到javamailAPI,邮箱服务器用的sohu闪电邮,SMTP协议用来发送,赋值代码: Properties props = new Properties(); props.setPro ...
- CentOS7下安装MySQL5.7安装与配置
介绍在CentOS7上yum安装数据库服务器MySQL Community Server 5.7的方法. 准备 CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL ...
- PC/FORTH 判定
body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...
- (C/C++学习笔记) 五. 常变量(只读变量)和宏
五. 常变量(只读变量)和宏 ● 常变量 常变量 #include <iostream.h> //预处理文件 int main() { const d ...
- Linux3.10.0块IO子系统流程(4)-- 为请求构造SCSI命令
首先来看scsi_prep_fn int scsi_prep_fn(struct request_queue *q, struct request *req) { struct scsi_device ...
- 3-D crustal model transfer to cdl format
The downloaded crustal model file, for example, its name is TW-PS-H14.nc The command is ncdump -b c ...