Leetcode1684. 统计一致字符串的数目[C++题解]:字符串O(n^2)简单题
生活随笔
收集整理的這篇文章主要介紹了
Leetcode1684. 统计一致字符串的数目[C++题解]:字符串O(n^2)简单题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 題目分析
- 題目鏈接
題目分析
對于vector中的每一個字符串,遍歷之,如果出現不同的字母就放棄,繼續遍歷下一個,如果該字符串中的每個字母都是allowed中的,計數器加1.
ac代碼
class Solution { public:int countConsistentStrings(string allowed, vector<string>& words) {int n = words.size();int res=0;for(int i=0;i<n;i++){string t=words[i];// cout<<t<<endl;for(int j=0;j<t.size();j++){if( allowed.find(t[j])==-1) break;if(j==t.size()-1) res++;}}return res;} };題目鏈接
Leetcode1684. 統計一致字符串的數目
總結
以上是生活随笔為你收集整理的Leetcode1684. 统计一致字符串的数目[C++题解]:字符串O(n^2)简单题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode1703. 得到连续 K
- 下一篇: Leetcode1685. 有序数组中差