The ability to debug and overall thinking need to improve 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…
Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/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 =…
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作value. 遍历string,如果这个 char 没有在 map 里,说明第一次出现,存入 char,index:                    如果这个 char 已经在 map 里,说明不是第一次出现,而且我们不在乎这种情况,更新 char, -1. 遍历hashmap,把最小的 inde…
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. 分析:找出字符串中第一次出现且不重复的字符,返回其字符的下标,如果不存在就返回-1. 用hashMap进行求…
Problem: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Example: s = "leetcode" return 0. s = "loveleetcode", return 2. 本题的第一想法是开一个字母表计数器,遍历string s中的元素,并利用计数器对每一个字母计…
最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: 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: Y…
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 lowerca…
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…
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…
题目描述: 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. 解题思路: 开个26个数的数组,然后先对字符串过一遍,统计每个字母出现的次数,然后从头再国一遍,…
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…
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…
题目描述 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 lowe…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/first-unique-character-in-a-string/description/ 题目描述 Given a string, find the first non-repeating character in it and return it's index. I…
-------------------------------------------------- 最开始的想法是统计每个字符的出现次数和位置,如下: AC代码: public class Solution { public int firstUniqChar(String s) { Count c[]=new Count[26]; for(int i=0;i<s.length();i++){ int index=s.charAt(i)-'a'; if(c[index]==null) c[in…
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1.案例:s = "leetcode"返回 0.s = "loveleetcode",返回 2.注意事项:您可以假定该字符串只包含小写字母.详见:https://leetcode.com/problems/first-unique-character-in-a-string/description/ C++: class Solution { public: int firstUniq…
#-*- 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)):   …
387. First Unique Character in a String Easy 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…
Description Find the first unique character in a given string. You can assume that there is at least one unique character in the string. Example For "abaccdeff", return 'b'. 解题:返回仅出现一次,并且排在最前面的那个元素,而不是返回第一个不同的元素,一开始理解错了.如果仅仅对于ASCII中的256个字符,可以用数组…
今天上午在CSDN的论坛里看到有朋友提的问题如下: /** @param maxSize Maximum sum of the sizes of the Bitmaps in this cache */ public LruMemoryCache(int maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } this.maxSize = maxSize; th…
写在前面 之前自信撸码时踩了一次小坑,代码如下: private static void AppServer_NewMessageReceived(WebSocketSession session, string value) { if (string.IsNullOrEmpty(value)) { return; } value = HttpUtility.UrlDecode(value); SuperSocketTemp<string> model = JsonConvert.Deseri…
bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 有些时候在某些服务管理脚本中看到$"$string"或$"string",经过一些测试,又发现引号外面的$有和没有是一样的.一直也没去找究竟,刚才有人问了我,于是就去翻了下man bash,找到了解释. (1).如果没有特殊定制bash环境或有特殊需求,$"string"和"string"是…
目录 String 源码分析 常用的API isEmpty() length() charAt() substring() equals() equals()与"==" intern() 一些基础 Java基本数据类型和引用类型 Java自动装箱/拆箱 StringBuilder 定义的常量 构造方法 append()方法 StringBuffer StringBuilder 和 StringBuffer 适用的场景是什么? 扩展小知识 参考链接 String String是一个很普通…
string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string 与原义 string string 的转义序列 格式化字符串 操作子字符串 字符串的 null 与 ""(空) 可提高性能的 StringBuilder 序 字符串是 String 类型的对象,它的值是文本. 在内部,文本被存储为 Char 对象的顺序只读集合. C# 字符串末尾没有以 n…
java.lang.String.getBytes(String charsetName) 方法编码将此String使用指定的字符集的字节序列,并将结果存储到一个新的字节数组. 声明 以下是java.lang.String.getBytes()方法的声明 public byte[] getBytes(String charsetName) throws UnsupportedEncodingException 参数 charset -- 这是一个支持的字符集的名称. 返回值 此方法返回得到的字节…
Lua有7种数据类型,分别是nil.boolean.number.string.table.function.userdata.这里我总结一下Lua的string类型和string库,复习一下,以便加深记忆. 个人认为string是Lua编程使用数据结构的时候,重要性仅次于table的类型.十分重要! 一.string基础. Lua并没有字符类型,Lua的string类型表示字符序列.所以,长度为1的string就表示了单个字符.Lua的字符类型有这些特征: 1.string字符序列中的字符采用…
转载:http://www.cnblogs.com/xshy3412/archive/2007/08/29/874362.html 1,int转成string用toString 或者Convert.toString()如下 例如:int varInt = 1; string varString = Convert.ToString(varInt); string varString2 = varInt.ToString(); 2,string转成int如果确定字符串中是可以转成数字的字符,可以用…
开篇之作,简单的对string与string[]进行初步操作,入门篇也,不多说,直接上代码. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { String[] str1 = new string[]{"A1&qu…
1. 首先String不属于8种基本数据类型,String是一个对象.   因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. new String()和new String(“”)都是申明一个新的空字符串,是空串不是null: 3. String str=”kvill”:  String str=new String (“kvill”);的区别: 在这里,我们不谈堆,也不谈栈,只先简单引入常量池这个简单的概念.  常量池(…
// List<int>转string[] public string[] ListInt2StringArray(List<int> input) { return Array.ConvertAll(input.ToArray(), new Converter<int, string>(a => Convert.ToString(a))); } List<int> arr = new List<int>(); arr.Add(); arr…