leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1525.cpp (677B)
0 class Solution { 1 public: 2 int numSplits(const string &s) { 3 bool seen[27] = {0}; 4 int uniq[100000] = {0}; 5 6 for (int i = 0, acc = 0; i < s.size(); i++) { 7 if (!seen[s[i] & 0x1F]) { 8 seen[s[i] & 0x1F] = true; 9 acc++; 10 } 11 uniq[i] = acc; 12 } 13 14 memset(seen, 0x00, sizeof(seen)); 15 seen[s.back() & 0x1F] = true; 16 17 int res = 0; 18 for (int i = s.size() - 2, acc = 1; i >= 0; i--) { 19 if (uniq[i] == acc) res++; 20 if (seen[s[i] & 0x1F]) continue; 21 seen[s[i] & 0x1F] = true; 22 acc++; 23 } 24 25 return res; 26 } 27 };