Re: [閒聊] 每日leetcode

看板Marginalman作者 (可可粉)時間11月前 (2025/01/03 01:40), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1237/1554 (看更多)
2559. Count Vowel Strings in Ranges Prefix Sum,用一個陣列儲存每個index符合條件的words數量 再將queries查詢條件裡對應的index相減 private readonly char[] vowels = new char[]{'a','e','i','o','u'}; public int[] VowelStrings(string[] words, int[][] queries) { var checkList = new int[words.Length+1]; var i = 1; foreach (var word in words) { if (vowels.Contains(word[0]) && vowels.Contains(word[word.Length-1])) { checkList[i] = checkList[i-1] + 1; } else { checkList[i] = checkList[i-1]; } i++; } var j = 0; var result = new int[queries.Length]; foreach (var query in queries) { result[j] = checkList[query[1]+1] - checkList[query[0]]; j++; } return result; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.249.70.234 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1735839612.A.834.html
文章代碼(AID): #1dTizyWq (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dTizyWq (Marginalman)