1832:判断句子是否为全字母句(每日一题2022.12.13)
This commit is contained in:
parent
2b7b78180e
commit
95c1188cbc
@ -47,16 +47,31 @@ public class CheckIfTheSentenceIsPangram {
|
||||
//力扣代码
|
||||
//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;
|
||||
//}
|
||||
public boolean checkIfPangram(String sentence) {
|
||||
List<Character> list = new ArrayList<>();
|
||||
int num = 0;
|
||||
if (sentence.length() < 26) {
|
||||
return false;
|
||||
}
|
||||
int[] arrs = new int[26];
|
||||
for (char ch : sentence.toCharArray()) {
|
||||
if (ch >= 'a' && ch <= 'z' && !list.contains(ch)) {
|
||||
list.add(ch);
|
||||
num++;
|
||||
arrs[ch - 'a']++;
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (arrs[i] == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return num == 26;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
|
Loading…
Reference in New Issue
Block a user