zoukankan      html  css  js  c++  java
  • 在字符串中找出第一个只出现一次的字符串,如输入"abaccdeff",输出'b'

    在字符串中找出第一个只出现一次的字符串,如输入"abaccdeff",输出'b'

     1 char firstNotRepeatingChar(char *str)
     2 {
     3     /* hash表存储 每个可能出现的字符作为索引值 数组内容即为出现的次数 */
     4     char ret = '';
     5     // 1.建立hashtable
     6     const int size = 256;
     7     // 全部初始化为0
     8     int hashtable[size] = {0};
     9     char *hashKey = str;
    10     // 2.记录出现次数
    11     while(*hashKey != '')
    12     {
    13         hashtable[*hashKey]++;
    14         hashKey++;
    15     }
    16     // 3.查找返回
    17     hashKey = str;
    18     while(*hashKey != '')
    19     {
    20         if (hashtable[*hashKey] == 1)
    21         {
    22             ret = *hashKey;
    23             return ret;
    24         }
    25         hashKey++;
    26     }
    27     return ret;
    28 
    29 }
  • 相关阅读:
    python 冒泡排序
    python 文件操作
    20180401 lambda表达式
    python 全局变量 局部变量
    python 参数
    window.open
    正则表达式
    应用环境操作
    python 十大经典排序算法
    W3C------JS
  • 原文地址:https://www.cnblogs.com/jianghg/p/4495014.html
Copyright © 2011-2022 走看看