如题~

此算法仅供参考,小菜基本不懂高深的算法,只能用最朴实的思想去表达。

 //找出字符串中第一个不重复的字符
// firstUniqueChar("vdctdvc"); --> t
function firstUniqueChar(str){
var str = str || "",
i = 0,
k = "",
_char = "",
charMap = {},
result = {name: "",index: str.length}; for(i=0;i<str.length;i++){
_char = str.charAt(i);
if(charMap[_char] != undefined){
charMap[_char] = -1;
}else{
charMap[_char] = i;
}
} for(k in charMap){
if(charMap[k]<0){
continue;
}
if(result.index>charMap[k]){
result.index = charMap[k];
result.name = k;
}
} return result.name;
}

找出字符串中第一个不重复的字符(JavaScript实现)的更多相关文章

  1. 剑指Offer 找出字符串中第一个只出现一次的字符

    题目描述 找出字符串中第一个只出现一次的字符 如果无此字符 请输出'.' 输入描述: 输入一串字符,由小写字母组成 输出描述: 输出一个字符 输入例子: asdfasdfo 输出例子: o 思路:数组 ...

  2. C++版 - 剑指Offer 面试题35:第一个只出现一次的字符 解题报告(华为OJ034-找出字符串中第一个只出现一次的字符)

    面试题35:第一个只出现一次的字符 题目:在一个字符串中找到第一个只出现一次的字符.如输入abaccdeff,则输出b.(2006年google的一道笔试题.) 分析: 首先应向确认一下是ASCII字 ...

  3. 剑指offer35题:第一个只出现一次的字符+剑指offer55题:字符流中第一个不重复的字符+剑指offer51题:数组中重复的数字

    在看剑指offer的时候,感觉这三个题目很像,都是用哈希表可以解决,所以把这三个题整理出来,以供复习. 剑指offer35题:第一个只出现一次的字符 题目描述:在字符串中找出第一个只出现一次的字符.如 ...

  4. 剑指Offer-字符流中第一个不重复的字符

    package String; import java.util.LinkedHashMap; import java.util.Map; /** * 字符流中第一个不重复的字符 * 题目描述 * 请 ...

  5. 【剑指Offer】字符流中第一个不重复的字符 解题报告(Python)

    [剑指Offer]字符流中第一个不重复的字符 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interv ...

  6. JZ-054-字符流中第一个不重复的字符

    字符流中第一个不重复的字符 题目描述 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g&q ...

  7. 剑指offer——python【第54题】字符流中第一个不重复的字符

    题目描述 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读出 ...

  8. leetCode 题解之字符串中第一个不重复出现的字符

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

  9. Java 返回字符串中第一个不重复字符的下标 下标从0开始

    比如abcdefgabdef 其中字符c和g不重复,返回c的小标,下标从0开始,那么是2 package com.example.demo; import org.testng.annotations ...

随机推荐

  1. ADAS技术应用

    ADAS技术应用: LDW:Lane Departure Warning 车道偏离警告VD: Vihicle Detection 车辆检测FCW: Front Collision Warning 前向 ...

  2. I can connect to an FTP site but I can't list or transfer files.

    原文 FTP sessions use two network connections: The control channel is for user authentication and send ...

  3. C# 队列集合的使用

    using System; using System.Collections.Generic; using System.Text; using System.Collections; namespa ...

  4. SGU 311. Ice-cream Tycoon(线段树)

    311. Ice-cream Tycoon Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: standar ...

  5. dojo 加载Json数据

    1.今天研究了dojo datagrid加载WebService后台传上来的数据.研究来研究去发现他不是很难.用谷歌多调试一下就好了. 2.看很多例子,这个例子能够更好的帮我解决问题:https:// ...

  6. rhel7网络管理

    实验-禁用网卡命名规则: 在GRUB_CMDLINE_Linux=“rd.lvm.lv=rhel/root  vconsole.keymap=us vconsole.font=latarcyheb-s ...

  7. 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)

    var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...

  8. Top Data Scientists to Follow & Best Data Science Tutorials on GitHub

    http://www.analyticsvidhya.com/blog/2015/07/github-special-data-scientists-to-follow-best-tutorials/ ...

  9. makeinfo: command not found

    解决办法:sudo apt-get install texinfo

  10. jQuery学习实用记录

    //jQuery加载 $(document).ready(function(){ //开始编写函数 }); //点击后 上下滑动隐藏效果 $("#id").click(functi ...