From a26ae5485a34c0781b1ed3da342717e748413708 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Mon, 7 Jun 2021 13:06:03 +0800 Subject: [PATCH] =?UTF-8?q?1832:=E5=88=A4=E6=96=AD=E5=8F=A5=E5=AD=90?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E5=85=A8=E5=AD=97=E6=AF=8D=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/CheckIfTheSentenceIsPangram.java | 63 +++++++++++++++++++ .../editor/cn/CheckIfTheSentenceIsPangram.md | 32 ++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.java create mode 100644 src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.md diff --git a/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.java b/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.java new file mode 100644 index 0000000..19edaf2 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.java @@ -0,0 +1,63 @@ +//全字母句 指包含英语字母表中每个字母至少一次的句子。 +// +// 给你一个仅由小写英文字母组成的字符串 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 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) + +} \ No newline at end of file diff --git a/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.md b/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.md new file mode 100644 index 0000000..c907d36 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/CheckIfTheSentenceIsPangram.md @@ -0,0 +1,32 @@ +

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

+ +

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

+ +

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

+ +

 

+ +

示例 1:

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

示例 2:

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

 

+ +

提示:

+ + +
Related Topics
  • 字符串
  • \n
  • 👍 9
  • 👎 0
  • \ No newline at end of file