1832:判断句子是否为全字母句
This commit is contained in:
parent
3bec4cc5d6
commit
a26ae5485a
@ -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<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)
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<p><strong>全字母句</strong> 指包含英语字母表中每个字母至少一次的句子。</p>
|
||||||
|
|
||||||
|
<p>给你一个仅由小写英文字母组成的字符串 <code>sentence</code> ,请你判断 <code>sentence</code> 是否为 <strong>全字母句</strong> 。</p>
|
||||||
|
|
||||||
|
<p>如果是,返回<em> </em><code>true</code> ;否则,返回<em> </em><code>false</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>sentence = "thequickbrownfoxjumpsoverthelazydog"
|
||||||
|
<strong>输出:</strong>true
|
||||||
|
<strong>解释:</strong><code>sentence</code> 包含英语字母表中每个字母至少一次。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>sentence = "leetcode"
|
||||||
|
<strong>输出:</strong>false
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= sentence.length <= 1000</code></li>
|
||||||
|
<li><code>sentence</code> 由小写英语字母组成</li>
|
||||||
|
</ul>
|
||||||
|
<div><div>Related Topics</div><div><li>字符串</li></div></div>\n<div><li>👍 9</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user