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

  • 相关阅读:
    Python脚本抓取京东手机的配置信息
    Python中的Pandas模块
    Python中的Pandas模块
    XML和JSON数据格式
    XML和JSON数据格式
    Linux运维比较常用的一些脚本
    Linux运维比较常用的一些脚本
    Keepalived高可用集群
    Keepalived高可用集群
    Linux中正则表达式和字符串的查询、替换(tr/diff/wc/find)
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7522290.html
Copyright © 2020-2023  润新知