• [去哪儿网]首个重复字符


    时间限制:3秒 空间限制:32768K 热度指数:33999
    本题知识点: 查找

    题目描述

    对于一个字符串,请设计一个高效算法,找到第一次重复出现的字符。

    给定一个字符串(不一定全为字母)A及它的长度n。请返回第一个重复出现的字符。保证字符串中有重复字符,字符串的长度小于等于500。

    测试样例:
    "qywyer23tdd",11
    返回:y
     1 #include<iostream>
     2 #include<vector>
     3 class FirstRepeat {
     4 public:
     5     char findFirstRepeat(string A, int n) {
     6         // write code here
     7         vector<int> Avec;
     8         char ch;
     9         
    10         for(int i=0;i<128;i++)
    11             Avec.push_back(0);//一共有128个字符
    12         
    13         for(int j=0;j<n;j++)
    14             {
    15               int index=A[j];
    16               Avec[index]++;
    17               if(Avec[index]==2)
    18                   {
    19                      ch=A[j];
    20                      break;
    21                      
    22               }
    23         }
    24         return ch;
    25     }
    26     
    27 };
  • 相关阅读:
    echarts 饼图
    vue echarts
    :style :class
    弹框弹出时禁止页面滚动
    2019-2-10 日记
    2019-1-27 日记
    2019-1-26 日记
    2019-1-3 日记
    2019-1-10 日记
    2019-1-2 日记
  • 原文地址:https://www.cnblogs.com/bxyan/p/6910402.html
Copyright © 2020-2023  润新知