leet-code/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.java

63 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//全字母句 指包含英语字母表中每个字母至少一次的句子。
//
// 给你一个仅由小写英文字母组成的字符串 sentence ,请你判断 sentence 是否为 全字母句 。
//
// 如果是,返回 true ;否则,返回 false 。
//
//
//
// 示例 1
//
//
//输入sentence = "thequickbrownfoxjumpsoverthelazydog"
//输出true
//解释sentence 包含英语字母表中每个字母至少一次。
//
//
// 示例 2
//
//
//输入sentence = "leetcode"
//输出false
//
//
//
//
// 提示:
//
//
// 1 <= sentence.length <= 1000
// sentence 由小写英语字母组成
//
// Related Topics 字符串
// 👍 9 👎 0
package leetcode.editor.cn;
import java.util.ArrayList;
import java.util.List;
//1832:判断句子是否为全字母句
public class CheckIfTheSentenceIsPangram{
public static void main(String[] args) {
//测试代码
Solution solution = new CheckIfTheSentenceIsPangram().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public boolean checkIfPangram(String sentence) {
List<Character> list = new ArrayList<>();
int num = 0;
for (char ch : sentence.toCharArray()) {
if (ch >= 'a' && ch <= 'z' && !list.contains(ch)) {
list.add(ch);
num++;
}
}
return num==26;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}