微信商城网站哪家做的好,成都房屋装修设计公司,旅行社建网站,建设银行网上营业厅1、题目
全字母句 指包含英语字母表中每个字母至少一次的句子。
给你一个仅由小写英文字母组成的字符串 sentence #xff0c;请你判断 sentence 是否为 全字母句 。
如果是#xff0c;返回 true #xff1b;否则#xff0c;返回 false 。
示例 1#xff1a;
输入请你判断 sentence 是否为 全字母句 。
如果是返回 true 否则返回 false 。
示例 1
输入sentence “thequickbrownfoxjumpsoverthelazydog” 输出true 解释sentence 包含英语字母表中每个字母至少一次。 示例 2
输入sentence “leetcode” 输出false
提示
1 sentence.length 1000 sentence 由小写英语字母组成
2、解
直接在sentence中查找是否包含所有的小写字母。 bool chekIfPangram(string sentence){for(char s a ; s z 1; s){if(string::npos sentence.find(s)) return false;}return true;}另解 遍历 sentence中的每个字符 c如果 c 是字母表中的第 i (0≤i26)字母就将 exist[i] 置为 true。最后检查 exist 中是否存在 false如果存在返回}false否则返回 true。 bool chekIfPangramA(string sentence){vectorint words(26);for(auto s : sentence){words[s - a] 1;}for(auto w : words){if(0 w) return false;}return true;}另解 还可以记录sentence中每个出现过的字母最后判断是否为26个。 bool checkIfPangramC(string sentence){unordered_mapchar, int sen;for(auto s : sentence){sen[s];}return 26 sen.size();}