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的更多相关文章

  1. 【leetcode❤python】387. First Unique Character in a String

    #-*- coding: UTF-8 -*- class Solution(object):    def firstUniqChar(self, s):        s=s.lower()     ...

  2. 【LeetCode】387. First Unique Character in a String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 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 ...

  4. LeetCode 387. First Unique Character in a String (字符串中的第一个唯一字符)

    题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作va ...

  5. [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 ...

  6. leetcode修炼之路——387. First Unique Character in a String

    最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: Given a string, find the first non-repeating characte ...

  7. 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 ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. virtualenv 运行python 解决依赖冲突问题 尤其是django那种蛋疼的版本问题

    Create a python virtual environment and install python dependencies. cd evalai virtualenv venv sourc ...

  2. Struts 2 初步入门(二)

    Struts 2 动态方法调用 1.在HelloWorldAction中添加两个新的方法如下: import com.opensymphony.xwork2.ActionSupport; public ...

  3. angular4,angular6中解决内层盒子到底外层盒子滚动

    //用来处理 里盒子滚完外盒子滚的问题 scrollUnique(who){ document.getElementsByClassName(who)[0].addEventListener('mou ...

  4. ajax常见的面试问题

    1:什么是ajax?ajax作用是什么? 异步的javascript和xml AJAX 是一种用于创建快速动态网页的技术. ajax用来与后台交互 2:原生js ajax请求有几个步骤?分别是什么 / ...

  5. pytesseract 验证码识别

    以下代码,如有不懂加群讨论# *-* coding:utf-8 *-* #import jsonimport requestsimport pytesseractimport timeimport d ...

  6. 请问微信小程序let和var以及const有什么区别

    在JavaScript中有三种声明变量的方式:var.let.const. var:声明全局变量,换句话理解就是,声明在for循环中的变量,跳出for循环同样可以使用. [JavaScript] 纯文 ...

  7. R语言中的采样与生成组合

    不放回采样:sample(1:10, 5, replace = FALSE) 生成组合:

  8. day10-高阶函数

    高阶函数 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs)) 结果: 19 解释: 调用a ...

  9. HTML编辑笔记3

    表单 1.语法 <form method="get|post" action="数据向哪提交的地址"> //表单内容 </form> 2 ...

  10. Linux命令----su(切换用户)以及passwd(修改用户密码)

    一.su命令登录root 用户在使用telnet命令可以远程登录,但不可以登录root,这样就需要使用su命令来登录root用户. telnet登录(不能登录root)--- 1.启动终端 输入 te ...