Re: [閒聊] 每日LeetCode已回收
1832. Check if the Sentence Is Pangram
給予一個字串如果該字串包含所有26個字母返回true,否則false。
Example 1:
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence contains at least one of every letter of the English
alphabet.
思路:
1.把所有字元加入Set
2.每次加入完先檢查Set的大小是否是26是的話直接返回。
Java Code:
class Solution {
public boolean checkIfPangram(String sentence) {
Set<Character> set = new HashSet<>();
for(char c : sentence.toCharArray()) {
set.add(c);
if(set.size() == 26) return true;
}
return false;
}
}
https://i.imgur.com/Mi7Z2s9.png

我這輩子只解的出Eazy了
--
https://i.imgur.com/bFRiqA3.jpg

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.159.111.108 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1665970972.A.AF5.html
推
10/17 12:08,
3年前
, 1F
10/17 12:08, 1F
推
10/17 18:39,
3年前
, 2F
10/17 18:39, 2F
討論串 (同標題文章)
完整討論串 (本文為第 49 之 719 篇):