Return if string t contains all chars in s
2014-10-30 07:12
232 查看
bool isSubsetOf(const string& s, const string& t) { if(s.length() > t.length()) return false; vector<int> table(256,0); int cur = 0; for(int i=0;i<s.length();++i) { if(table[s[i]] > 0) // if the char has been checked in t, decrease the counter by 1 { --table[s[i]]; continue; } else if(cur == t.length()) return false; while(cur < t.length()) { if(t[cur] != s[i]) { ++table[t[cur]]; ++cur; } else { ++cur; break; } } } return true; }
相关文章推荐
- Using BitSet to to judge if string a contains all letters in string b
- [JS Array]Find an item in an array that contains a string and then return that string
- What is the fastest, case insensitive, way to see if a string contains another string in C#?
- return columns.All(new Func<string, bool>(list.Contains));
- How can I check if one string contains another substring in JavaScript?
- 438. Find All Anagrams in a String
- 438. Find All Anagrams in a String
- mybatis String的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- 438. Find All Anagrams in a String
- LeetCode 438: Find All Anagrams in a String
- Two Solutions to fix issue: ORDER BY items must appear in the select list if the statement contains a UNION, ...
- HashTable-438-Find All Anagrams in a String
- 438. Find All Anagrams in a String(不太懂)
- LINQ to SQL语句小结之 Exists/In/Any/All/Contains(转载)
- leetcode 438. Find All Anagrams in a String 一个简单的移动窗口问题
- [LeetCode] Find All Anagrams in a String 找出字符串中所有的变位词
- LINQ体验(7)——LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains (转载)
- LINQ系列:LINQ to SQL Exists/In/Any/All/Contains
- Find All Anagrams in a String
- leetcode 438[easy]---Find All Anagrams in a String