找出字符串中第一个不重复出现的字符(仅小写字母)

/// <summary>

/// Uses letterCount array to record each letter's cout, count of letter 'a' stored in letterCount[0],

/// count of letter 'b' stored in letterCount[1], count of letter 'c' stored in letterCount[2], etc.

/// The complexity of this algorism is O(n).

/// </summary>

/// <param name="s"></param>

private static void FindFirstNotDuplicatedLetter(string s)

{

int[] letterCount = new int[26];

for (int i = 0; i < s.Length; i++)

{

letterCount[s[i] - 'a']++;

}

 

bool found = false;

for (int i = 0; i < s.Length; i++)

{

if (letterCount[s[i] - 'a'] == 1)

{

found = true;

Console.WriteLine(s[i]);

break;

}

}

 

if (!found)

Console.WriteLine("No not duplicated letter.");

}

原文地址:https://www.cnblogs.com/bear831204/p/2471633.html