題目
A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.
Example
Input: sentence = "thequickbrownfoxjumpsoverthelazydog"
Output: true
Explanation: sentence contains at least one of every letter of the English alphabet.
- 題意: sentence中至少要出現一次a-z
解法
import (
"strings"
)
func checkIfPangram(sentence string) bool {
if len(sentence) < 26 {
return false
}
for i := 'a'; i <= 'z'; i++ {
if strings.Index(sentence, string(i)) == -1 {
return false
}
}
return true
}
- 加個測試,看看結果是不是如預期
func TestCheckIfPangram(t *testing.T) {
assert.Equal(t, true, checkIfPangram("thequickbrownfoxjumpsoverthelazydog"))
assert.Equal(t, false, checkIfPangram("leetcode"))
}