题目:在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b。
分析:这道题是2006年google的一道笔试题。
C# codes as below:
using System;
using System.Collections.Generic;
namespace ConsoleApp
{
class RunClass
{
static void Main()
{
char i = new Helper().Print("2233") ?? ' ';
Console.WriteLine(i);
Console.ReadLine();
}
}
class Helper
{
public char? Print(string str)
{
if (str.Length == 0 || str == null)
return null;
bool[] marks = new bool[str.Length];
for (int i = 0; i < str.Length; i++)
{
if (marks[i] != true)
{
marks[i] = true;
int count = 0;
for (int j = i; j < str.Length; j++)
{
if (str[j] == str[i])
{
count++;
marks[j] = true;
}
}
if (count == 1)
{
return str[i];
}
}
}
return null;
}
}
}