【leetcode❤python】387. First Unique Character in a String
#-*- coding: UTF-8 -*-
class Solution(object):
def firstUniqChar(self, s):
s=s.lower()
sList=list(s)
numCdic={}
for c in s:
numCdic[c]=numCdic[c]+1 if c in numCdic else 1
for i in range(len(sList)):
if numCdic[sList[i]]==1:
return i
return -1
sol=Solution()
print sol.firstUniqChar('loveleetcode')
【leetcode❤python】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】387. First Unique Character in a String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】387. First Unique Character in a String
Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/first-unique-cha ...
- 【leetcode❤python】 438. Find All Anagrams in a String
class Solution(object): def findAnagrams(self, s, p): """ :type s: s ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 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
Problem: Given a string, find the first non-repeating character in it and return it's index. If it d ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
随机推荐
- PIC18F中断定时器
//基于MCC18编译器,使用HI-PICC不可用 //-------------------------------------------- #include <p18F452.h> ...
- 【python cookbook】【数据结构与算法】11.对切片命名
问题:如何清理掉到处都是硬编码的切片索引 解决方案:对切片命名 假设有一些代码用来从字符串的固定位置中取出具体的数据(比如从一个平面文件或类似的格式:平面文件flat file是一种包含没有相对关系结 ...
- scala的继承
package com.test.scala.test /** * 模拟java的继承,扩展类 */ abstract class ExtendClass(val des:String) { def ...
- linux cache and buffer【转】
转自:http://blog.csdn.net/turkeyzhou/article/details/6426738 版权声明:本文为博主原创文章,未经博主允许不得转载. Linux下对文件的访问和设 ...
- Java中类方法与实例方法的区别
实例方法可以对当前对象的实例变量进行操作,也可以对类变量进行操作,但类方法不能访问实例变量.实例方法必须由实例对象来调用,而类方法除了可由实例对象调用外,还可以由类名直接调用. 另外,在类方法中不能使 ...
- mybatis n+1问题
mybatis的一对多或者多对多的时候,2中方式解决,一种是嵌套select,但是会有n+1问题,不推荐:另外一种是使用一条sql,在该sql里面使用子查询的方式来完成.比如 select * fro ...
- Java Properties工具类详解
1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...
- PHP程序员如何突破成长瓶颈
PHP因为简单而使用,但不能因为它的简单而限制我们成长!文章给PHP工程师突破成长瓶颈提了一些建议,希望PHPer能够突破自己,有更好的发展. AD: 作为Web开发中应用最广泛的语言之一,PHP有着 ...
- PHP和ajax详解
优点:减轻服务器的负担,按需取数据,最大程度的减少冗余请求局部刷新页面,减少用户心理和实际的等待时间,带来更好的用户体验基于xml标准化,并被广泛支持,不需安装插件等进一步促进页面和数据的分离缺点:A ...
- hdu5681 zxa and wifi
这道题目是不太好想的,尽管很容易看出来应该是dp,但是状态转移总觉得无从下手. 其实我们可以将状态分层,比如设$dp(i, j)$为用$i$个路由器覆盖前$j$个点所需的最小代价 我们先不考虑状态,而 ...