Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
133858 | baim. | 划分字母区间 | C++ | 编译错误 | 0 | 0 MS | 0 KB | 589 | 2024-03-02 10:02:09 |
#include<bits/stdc++.h> using namespace std; int main(){int[] last = new int[26]; int length = S.length(); for (int i = 0; i < length; i++) { last[S.charAt(i) - 'a'] = i; } List<Integer> partition = new ArrayList<Integer>(); int start = 0, end = 0; for (int i = 0; i < length; i++) { end = Math.max(end, last[S.charAt(i) - 'a']); if (i == end) { partition.add(end - start + 1); start = end + 1; } } cout<< partition; }