763. Partition Labels
A string S
of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Example 1:
Note:
S
will have length in range[1, 500]
.S
will consist of lowercase letters ('a'
to'z'
) only.
解题要点:
先遍历一次,把每个字母最后出现的index记录下来。然后从第一位开始找它最后出现的位置,加到返回值里,并将起始值更新为这个位置的后一位,继续寻找。
Last updated
Was this helpful?