Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
138000 陈家宝 划分字母区间 C++ 通过 100 0 MS 244 KB 548 2024-03-13 13:21:18

Tests(2/2):


#include<bits/stdc++.h> using namespace std; vector<int> partitionLabels(string S){ vector<int> ans,ends(26, -1); for (int i = 0; i < S.length(); ++i)ends[S[i] - 'a'] = i; int i = 0; while (i < S.size()) { int r = ends[S[i] - 'a']; for (int j = i + 1; j <= r; ++j)r = max(r, ends[S[j] - 'a']); ans.push_back(r - i + 1); i = r + 1; } return ans; } int main(){ string s; cin >> s; vector<int> a = partitionLabels(s); for (vector<int>::iterator it = a.begin(); it != a.end(); ++it)cout << *it << " "; return 0; }


测评信息: