/// <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.");

}

相关文章:

  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-09
  • 2021-10-15
  • 2022-01-18
  • 2022-01-14
  • 2022-01-13
  • 2022-01-23
相关资源
相似解决方案