题目
代码
执行用时:28 ms, 在所有 Python3 提交中击败了95.54% 的用户
内存消耗:14.8 MB, 在所有 Python3 提交中击败了89.76% 的用户
通过测试用例:79 / 79
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
return len(set(sentence))==26
【方法2】
执行用时:40 ms, 在所有 Python3 提交中击败了33.07% 的用户
内存消耗:14.8 MB, 在所有 Python3 提交中击败了97.90% 的用户
通过测试用例:79 / 79
class Solution:
def checkIfPangram(self, sentence: str) -> bool:
return len(collections.Counter(sentence))==26

本文探讨了两种Python实现检查句子是否为 pangram(使用所有26个英文字母)的方法。第一种方法利用集合的性质,第二种方法采用collections.Counter。虽然两者都通过了所有测试用例,但第一种方法在时间和内存效率上更优。

被折叠的 条评论
为什么被折叠?



