leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0290.cpp (631B)


0 class Solution { 1 public: 2 bool wordPattern(string pattern, string s) { 3 vector<string> done(26, ""); 4 unordered_set<string> st; 5 6 int c = 0; 7 istringstream in(s); 8 for (string crnt; in >> crnt; ++c) { 9 if (c >= pattern.size()) return false; 10 int index = pattern[c] - 'a'; 11 if (done[index].empty()) { 12 if (st.count(crnt)) return false; 13 st.insert(done[index] = crnt); 14 } else if (done[index] != crnt) 15 return false; 16 } 17 if (pattern.size() > c) return false; 18 19 return true; 20 } 21 };