By Long Luo

# Greedy

If we want to partition, we must maintain Two Pointers at the beginning and the end of a section. The Next Partition will start at the end of last Partition.

While scanning the string, if all the characters in the Partition only appear in the Partition, we can Partition it.

As the picture below shows, the farthest position of all the chars is no more than 8, so we can partition it.

and so on.

## Analysis

• Time Complexity: $O(n)$, we will traversal the string twice.
• Space Complexity: $O(|\Sigma|)$，the $\Sigma = 26$.

All suggestions are welcome.
If you have any query or suggestion please comment below.
Please upvote👍 if you like💗 it. Thank you:-)

Explore More Leetcode Solutions. 😉😃💗