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

  • 相关阅读:
    PowerShell尝试ssh登录
    PowerShell收发TCP消息包
    powershell对指定IP进行端口扫描
    PowerShell尝试登录ftp
    PowerShell批量扫描IP和端口
    《PowerShell 3.0 Advanced Admin handbook》已于今日上市
    PowerShell尝试登录SQL Server
    Docker 数据卷
    Dockerfile自定义镜像
    Docker 容器操作
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7522290.html
Copyright © 2011-2022 走看看