1160. 拼写单词
生活随笔
收集整理的這篇文章主要介紹了
1160. 拼写单词
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2020-03-17
1.題目描述
拼寫單詞2.解析
直接進行搜索即可3.代碼
#include <iostream> #include <cstring> #include <vector> #include <algorithm> using namespace std;class Solution { public:int countCharacters(vector<string>& words, string chars) {int l = words.size(),ll,i,j,k,cnt=0;bool f[110];for (i=0;i<l;i++){memset(f,false,sizeof(f));string tmp=words[i];ll=tmp.length();for (j=0;j<ll;j++){for (k=0;k<chars.length();k++){if (tmp[j]==chars[k]){if (!f[k]) {f[k]=true;break;}}}if (k>=chars.length()) break;}if (j>=ll) cnt+=ll;}return cnt;} };int main(){Solution s;vector<string> words={"cat","bt","hat","tree"};string chars="atach";cout<<s.countCharacters(words,chars)<<endl;return 0; }總結
以上是生活随笔為你收集整理的1160. 拼写单词的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将Jquery序列化后的表单值转换成Js
- 下一篇: 第二周学习进度条