剑指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刷一遍啊

原文地址:https://www.cnblogs.com/FriskyPuppy/p/7522290.html