leetcode-easy-string-387 First Unique Character in a String
mycode 24.42%
class Solution:
def firstUniqChar(self, s: str) -> int:
dic = {}
for i in range(len(s)):
dic[s[i]] = dic.get(s[i],0) + 1
for i,val in dic.items():
if val == 1:
return s.index(i)
return -1
参考
class Solution:
def firstUniqChar(self, s: str) -> int:
# # two-pass
# ctr = collections.Counter(s)
# for i,v in enumerate(s):
# if ctr[v] == 1:
# return i
# return -1 letters='abcdefghijklmnopqrstuvwxyz'
index=[s.index(l) for l in letters if s.count(l) == 1]
return min(index) if len(index) > 0 else -1
leetcode-easy-string-387 First Unique Character in a String的更多相关文章
- [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 ex ...
- 【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
最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: Given a string, find the first non-repeating characte ...
- 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
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/first-unique-cha ...
- 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 ...
- 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 ...
随机推荐
- 第三篇 HTML 表单及表格
表单及表格 表单,常用在登录.注册等地方,这也是一个最基本的. 我们就用登录,来学习什么是表单! 表单 form 标签,在某些好用的编辑工具,比如:WebStorm 你在上面写出form再按 ...
- Visual Studio解决方案的目录结构设置和管理
摘至:http://blog.csdn.net/lp310018931/article/details/47991759 首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件 ...
- Linux查看修改文件句柄数
SuSE 11SP3 默认句柄数是1024 1.查看linux的文件句柄数 ulimit -a 2.修改文件句柄数 ①ulimit -n 65535②修改linux系统参数.vi /etc/secur ...
- pt-archiver配置自动归档
Mysql的数据归档通常使用percona的pt-archiver.通过shell脚本加crontab可以应对大多数场景下的数据自动归档. 安装 Percona Toolkit的安装不再赘述,请自行搜 ...
- linux 之实现定时任务
一.方式一 (1)命令行 的方法: 一.方式一 需求:每分钟执行一次/etc 目录的添加 到/tmp/a.txt 中 (1) touch a.txt创建文件 (2) crotab -e 进行任务的定制 ...
- Java注解的继承
注解继承的说明 1.首先要想Annotation能被继承,需要在注解定义的时候加上@Inherited,并且如果要被反射应用的话,就需要还有个事@Retention(RetentionPolicy.R ...
- Linux中FTP服务器配置
1.FTP服务器的一些基本概念 (1)FTP连接方式 控制连接:标准端口为21,用于发送FTP命令信息. 数据连接:标准端口为20,用于上传.下载数据. ...
- tornada-数据库
数据库 torndb安装 连接初始化 执行语句 execute execute_rowcount 查询语句 get query 与Django框架相比,Tornado没有自带ORM,对于数据库需要自己 ...
- 批量处理window下^M符号
#!/bin/ksh #set -x # #去掉文件中的^M 符号 # usage() { echo "Usage : sh ToAscll.sh [Option] [value]" ...
- C#基础进阶
观看C#高级教程进行学习.巩固基础,进阶学习. 1.委托 把方法当做参数来传递就是委托.委托的关键字是delegate. class Program { private delegate string ...