精華區beta Marginalman 關於我們 聯絡資訊
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]--; } } return result; } } -- (づ′・ω・)づ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.51.52 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1717571791.A.D43.html
JIWP: 大師 06/05 15:17
CanIndulgeMe: 沒力氣了,別再卷了…… 06/05 15:17
seanpai: 大師 06/05 15:19
DJYOSHITAKA: 別捲了... 06/05 15:24
sustainer123: 大師 06/05 15:24
deatheo: 大師 06/05 16:17
orangeNoob: 別捲了 06/05 16:27