zl程序教程

您现在的位置是:首页 >  其它

当前栏目

​力扣解法汇总1832. 判断句子是否为全字母句

判断 是否 汇总 力扣 解法 字母 句子
2023-09-11 14:18:53 时间

 目录链接:

力扣编程题-解法汇总_分享+记录-CSDN博客

GitHub同步刷题项目:

https://github.com/September26/java-algorithms

原题链接:力扣


描述:

全字母句 指包含英语字母表中每个字母至少一次的句子。

给你一个仅由小写英文字母组成的字符串 sentence ,请你判断 sentence 是否为 全字母句 。

如果是,返回 true ;否则,返回 false 。

示例 1:

输入:sentence = "thequickbrownfoxjumpsoverthelazydog"
输出:true
解释:sentence 包含英语字母表中每个字母至少一次。

示例 2:

输入:sentence = "leetcode"
输出:false

提示:

  • 1 <= sentence.length <= 1000
  • sentence 由小写英语字母组成

解题思路:

* 解题思路:
* 用一个set来装载,size达到26就返回true。
 

代码:

public class Solution1832 {

    public boolean checkIfPangram(String sentence) {
        HashSet<Character> set = new HashSet<>();
        char[] chars = sentence.toCharArray();
        for (char c : chars) {
            set.add(c);
            if(set.size()>=26){
                return true;
            }
        }
        return false;
    }
}