zoukankan      html  css  js  c++  java
  • 从一个字符串中返回第一个没有重复出现的字符(例如"Hello World",返回"H")

     1 public static string GetTheFirstUniqueCharOfString(string str)
     2 {
     3     if (string.IsNullOrEmpty(str)) return str;
     4     IDictionary<intint> iDictionary = new Dictionary<intint>();
     5     for (int i = 0; i < 256; i++)
     6     {
     7         iDictionary.Add(i, 0);
     8     }
     9     char[] chars = str.ToCharArray();
    10     foreach (char c in chars)
    11     {
    12         iDictionary[(short)c] += 1;
    13     }
    14     foreach (char c in chars)
    15     {
    16         if (iDictionary[(short)c] == 1)
    17         {
    18             return c.ToString();
    19         }
    20     }
    21     return str;
    22 }
  • 相关阅读:
    将本地文件夹添加到Git仓库
    flex调用Webservice(一)
    经典的sql
    打印相关
    reporting services订阅
    关于TabIndex
    试题(一)
    试试用手机
    2010.07.13_19:30
    基础知识
  • 原文地址:https://www.cnblogs.com/panchunting/p/interview_technology_002.html
Copyright © 2011-2022 走看看