Re: [闲聊] 每日leetcode

楼主: SecondRun (雨夜琴声)   2024-06-05 15:16:28
1002. Find Common Characters
找共通字串
Example 1:
Input: words = ["bella","label","roller"]
Output: ["e","l","l"]
想法: 没有,就硬干
C# code:
public class Solution
{
public IList<string> CommonChars(string[] words)
{
var count = new int[26];
for (int i = 0; i < count.Length; i++)
{
count[i] = words[0].Count(x => x == 'a' + i);
for (int j = 1; j < words.Length; j++)
{
if (count[i] == 0) break;
count[i] = Math.Min(count[i], words[j].Count(x => x == 'a' + i));
}
}
var result = new List<string>();
for (int i=0; i<count.Length; i++)
{
while (count[i] != 0)
{
result.Add(((char)('a' + i)).ToString());
count[i]
作者: JIWP (JIWP)   2024-06-05 15:17:00
大师
作者: CanIndulgeMe   2024-06-05 15:17:00
没力气了,别再卷了……
作者: seanpai (Seanpai)   2024-06-05 15:19:00
大师
作者: DJYOSHITAKA (Evans)   2024-06-05 15:24:00
别卷了...
作者: sustainer123 (caster)   2024-06-05 15:24:00
大师
作者: deatheo (逆十字)   2024-06-05 16:17:00
大师
作者: orangeNoob   2024-06-05 16:27:00
别卷了

Links booklink

Contact Us: admin [ a t ] ucptt.com