Re: [閒聊] 每日LeetCode已回收
看板Marginalman作者JerryChungYC (JerryChung)時間1年前 (2024/01/13 01:48)推噓0(0推 0噓 2→)留言2則, 2人參與討論串599/719 (看更多)
https://leetcode.com/problems/determine-if-string-halves-are-alike
1704. Determine if String Halves Are Alike
給一個偶數長度的字串s,把它分成兩半。如果兩半的母音數量相同則為Alike,傳回True
Example 1:
Input: s = "book"
Output: true
Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel.
Therefore, they are alike.
Python Code:
---------------------------------------------------
class Solution:
def halvesAreAlike(self, s: str) -> bool:
a = 0
vowels = set(["a", "e", "i", "o", "u",
"A", "E", "I", "O", "U"])
for i in range(len(s) // 2):
if s[i] in vowels:
a += 1
if s[-i-1] in vowels:
a -= 1
return a == 0
---------------------------------------------------
想說等人發結果都沒有
窩只剩這種Easy題可以來騙文章數了 :(
話說vowels有沒有set有差嗎 原本自己寫是沒加
不過也沒贏到哪去
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.45.8.224 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1705081705.A.DF3.html
→
01/13 01:58,
1年前
, 1F
01/13 01:58, 1F

→
01/13 02:43,
1年前
, 2F
01/13 02:43, 2F
討論串 (同標題文章)
完整討論串 (本文為第 599 之 719 篇):