Amazon OA 763. Partition Labels
class Solution { public: vector<int> partitionLabels(string S) { // 这是个好题 unordered_map<char, int> mp; vector<int> res; const int size = S.size(); if(size == 0){ return res; } for(int i = 0; i < size; i++){ mp[S[i]] = i; } int start = 0, end = 0; for(int i = 0; i < size; i++){ end = max(end, mp[S[i]]); if(i == end){ res.push_back(i - start + 1); start = end + 1; ...
Comments
Post a Comment