<p>You are given a string <code>s</code>. We want to partition the string into as many parts as possible so that each letter appears in at most one part.</p>

<p>Note that the partition is done so that after concatenating all the parts in order, the resultant string should be <code>s</code>.</p>

<p>Return <em>a list of integers representing the size of these parts</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;ababcbacadefegdehijhklij&quot;
<strong>Output:</strong> [9,7,8]
<strong>Explanation:</strong>
The partition is &quot;ababcbaca&quot;, &quot;defegde&quot;, &quot;hijhklij&quot;.
This is a partition so that each letter appears in at most one part.
A partition like &quot;ababcbacadefegde&quot;, &quot;hijhklij&quot; is incorrect, because it splits s into less parts.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;eccbbbbdec&quot;
<strong>Output:</strong> [10]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 500</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution {
public:
    vector<int> partitionLabels(string s) {
        int hash[27] = {};
        int size = s.size();
        vector<int> result;
        if (size < 2)
            return result;
        //先算每個字母出現的最後位置
        for (int i = 0; i < size; i++) {
            int j = s[i] - 'a';
            hash[j] = i;
        }

        int left = 0, right = 0;
        for (int j = 0; j < size; j++) {
            //挑出現次數大的，當 i == 出現次數時，代表這段區間的字母不會跑到其他區間    
            right = max(right, hash[s[j] - 'a']);
            if (j == right) {
                //cout<<"right = "<<right<<",j = "<<j<<endl;
                result.push_back(right - left + 1);
                left = j+1;
            }
        }
        return result;
    }
};
8100