763. Partition Labels Medium

@problem@discussion
#Hash Table#Two Pointers#String#Greedy



1/**
2 * [763] Partition Labels
3 *
4 * You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.
5 * Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.
6 * Return a list of integers representing the size of these parts.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "ababcbacadefegdehijhklij"
11 * Output: [9,7,8]
12 * Explanation:
13 * The partition is "ababcbaca", "defegde", "hijhklij".
14 * This is a partition so that each letter appears in at most one part.
15 * A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.
16 * 
17 * Example 2:
18 * 
19 * Input: s = "eccbbbbdec"
20 * Output: [10]
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= s.length <= 500
26 * 	s consists of lowercase English letters.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/partition-labels/
32// discuss: https://leetcode.com/problems/partition-labels/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn partition_labels(s: String) -> Vec<i32> {
38        vec![]
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_763() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.