*Leetcode 763. Partition Labels
阿新 • • 發佈:2018-12-13
const int SIZE = 256; class Solution { public: bool judge( int cnt[], int hash[] ) { // bool ret = true; for (int i = 0; i < SIZE; i++) { if (hash[i] == cnt[i] || !hash[i])continue; return false; } return true; } vector<int> partitionLabels(string s) { int mem[SIZE] = {0}, hash[SIZE] = {0}; vector<int> ret; int cnt = 0; for (auto c : s) mem[c] ++; for (auto c : s) { cnt ++; hash[c] ++; if (judge(mem, hash)) { ret.push_back(cnt); cnt = 0; } } return ret; } };