Skip to content

Instantly share code, notes, and snippets.

@jikeytang
Last active August 29, 2015 14:01
Show Gist options
  • Save jikeytang/f46ce22363dedecb8a13 to your computer and use it in GitHub Desktop.
Save jikeytang/f46ce22363dedecb8a13 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140522-题目2
在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b。
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
3. 经测试,test方法轻松获胜。
http://jsperf.com/only-occur-once
@wsgouwan
Copy link

        function getChar( str ){
        for( var i=0; i < str.length; i ++ ){
            var judge = true;

            for( j = 0; j <str.length; j ++ ){
                if( i == j  ) continue ;
                if( str[i] == str[j] ){
                    judge = false;
                    break;
                }
            };

            if( judge ) return str[i]
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment