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.

思路,统计每个每个字母出现的次数到一个数组中,数组大小为26个小写字母。

int firstUniqChar(char* s) {int i;char *str;int count[26];memset(count, 0, 26 * sizeof(int));for(str = s; *str != '\0'; str++) {i = *str - 'a';count[i]++;}for(str = s; *str != '\0'; str++) {i = *str - 'a';if(count[i] == 1)return str - s;}return -1;
}

387. First Unique Character in a String QuestionEditorial Solution相关推荐

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

    leetcode:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 387. 字符串中的第一个唯一字符 给定一个 ...

  2. LeetCode: 387. First Unique Character in a String

    051105 题目 Given a string, find the first non-repeating character in it and return it's index. If it ...

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

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

  5. python leetcode 387. First Unique Character in a String

    利用find函数能极大地减少运行时间 class Solution:def firstUniqChar(self, s):""":type s: str:rtype: i ...

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

    目录 题目描述: 示例: 解法: 题目描述: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 示例: s = "leetcode"返回 0. ...

  7. First Unique Character in a String(leetcode387)

    2019独角兽企业重金招聘Python工程师标准>>> Given a string, find the first non-repeating character in it an ...

  8. LeetCode之First Unique Character in a String

    1.题目 Given a string, find the first non-repeating character in it and return it's index. If it doesn ...

  9. C#LeetCode刷题之#387-字符串中的第一个唯一字符(First Unique Character in a String)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回 ...

最新文章

  1. 我所知道的flex布局 —— 上篇
  2. 百度地图开发总结----3.判断一个点是否在一片区域内
  3. NOI2006 最大获利
  4. 经典的java程序_Java经典程序
  5. php html邮件,php发送HTML邮件
  6. c语言数组宏定义标识符,C语言学习笔记--预编译/宏定义/数组/参数传递/函数指针...
  7. opencv1-加载、修改、保存图像
  8. cygwin的安装使用
  9. python利器-python利器去广告版
  10. 计算机考试系统———全套视频
  11. Vue实例与组件实例
  12. 关于机器人创业:学术界vs工业界及中国机器人企业的机会
  13. 数字孪生是什么?以山海鲸智慧园区三维可视化系统为例说明
  14. Spring boot 集成 Redis Scarch
  15. python做一段有意思的代码_Python爬虫入门有意思的小长代码
  16. No Target connected Target DLL has been cancelled(电压问题记录)
  17. delphi中通快递(支持快递查询、快递下单)
  18. SwiftUI中微信认证成功但App回调方法未被调用的解决
  19. 远程桌面计算机用户名,远程桌面设置及使用
  20. 通信电子电路(3)---高频功率放大器

热门文章

  1. 解决布局拖动混乱的问题
  2. SaaS风暴:中国软件企业如何应对挑战?
  3. 制作点击文字变颜色_腾讯的动态时间轴PPT火了!制作简单又有逼格,都学起来啊...
  4. winform打开cad图纸_为什么CAD图纸打开后会显示很多问号“???”,该怎么解决...
  5. jsp文件上传_文件上传
  6. 一串事物中每个事物的前后位置与顺序编号的转换问题
  7. JS实现刷新iframe的方法
  8. android 固定比例图片裁剪插件,如何在Android中裁剪不同比例的图像?
  9. mysql把游标数据存入表中_利用Python爬股票数据并存入数据库Mysql
  10. PAT_B_1033_Java(20分)