zoukankan      html  css  js  c++  java
  • 剑指offer 面试题35 第一个只出现一次的字符

      题目链接: 剑指offer

      题目描述: 输入一个字符串, 输出第一个只出现一次的字符

      解题思路: 哈希表啊.......map呗就, 但是剑指offer的意思是要自己实现, 那就自己实现咯

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iterator>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <deque>
    #include <map>
    #include <set>
    #include <queue>
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define mem0(a) memset(a,0,sizeof(a))
    #define mem1(a) memset(a,-1,sizeof(a))
    #define sca(x) scanf("%d",&x)
    //#define de printf("=======
    ")
    typedef long long ll;
    using namespace std;
    
    char FirstNotRepeatingChar(char * pstring) {
        if( pstring == NULL ) return '';
        const int tablesize = 256;
        unsigned int hashtable[tablesize];
        mem0(hashtable);
        char * pkey = pstring;
        while( *pkey != '' ) {
            hashtable[(int)(*pkey)]++;
            pkey++;
        }
        pkey = pstring;
        while( *pkey != '' ) {
            if( hashtable[(int)(*pkey)] == 1 ) {
                return *pkey;
            }
            pkey++;
        }
        return '';
    }
    
    int main() {
        char * str = "abaacc";
        printf( "%c
    ", FirstNotRepeatingChar(str));
        return 0;
    }
    View Code

      思考: 这个题有点儿水了 ..... 把剑指offer刷一遍啊

  • 相关阅读:
    JNI介绍
    github自己用(未完)
    Android中的内存泄漏问题前世今生(转)
    android开发之OpenGL(三)
    android之PopupWindow焦点问题
    Spring笔记2
    android 存储ANR问题的traces.txt
    Gallery与imageView的onClick事件冲突解决方法
    android小小的开发细节
    PHP网站中整体防注入方法
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7522290.html
Copyright © 2011-2022 走看看