Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (麵包屌)時間3年前 (2022/12/01 16:35), 編輯推噓1(101)
留言2則, 2人參與, 3年前最新討論串123/719 (看更多)
1704. Determine if String Halves Are Alike 給你一個字串,問你他的前後兩半是否相似。 相似的定義為擁有同樣數量的母音(包含aeiouAEIOU)。 Example 1: Input: s = "book" Output: true Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Example 2: Input: s = "textbook" Output: false Explanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. 思路: 1.切一半,Counter(),把母音數量的差距加起來看是不是0,沒了 class Solution: def halvesAreAlike(self, s: str) -> bool: n = len(s) a = Counter(s[:n//2]) b = Counter(s[n//2:]) return sum([a[c] - b[c] for c in 'aeiouAEIOU']) == 0 又是開心水題的一天 -- 蛤? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.216.212 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1669883721.A.7A1.html

12/01 16:37, 3年前 , 1F
大師
12/01 16:37, 1F

12/01 16:46, 3年前 , 2F
大師
12/01 16:46, 2F
文章代碼(AID): #1ZY6T9UX (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ZY6T9UX (Marginalman)