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

  • 相关阅读:
    web页面静态化与伪静态化
    mysql 优化之空间换时间
    QPS、PV、UV、RT 之间的关系
    接口
    MySQL 索引
    名词解释
    go 语言标识符
    Git版本控制与工作流
    Maven安装与配置
    IDEA工具使用说明
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7522290.html
Copyright © 2011-2022 走看看