problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::partition_labels::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< int > partitionLabels (string s)
 

详细描述

在文件 leetcode.h2678 行定义.

成员函数说明

◆ partitionLabels()

vector< int > leetcode::partition_labels::Solution::partitionLabels ( string  s)
static

在文件 leetcode.cpp7254 行定义.

7254 {
7255 unordered_map<char, unsigned> last;
7256 vector<int> ans;
7257 for(int i = 0; i < s.length(); i++) {
7258 last[s[i]] = i;
7259 }
7260 for(int i = 0; i < s.length();) {
7261 unsigned last_pos = i;
7262 char ch = s[i];
7263 for(int j = i; j <= last_pos; j++) {
7264 last_pos = max(last_pos, last[s[j]]);
7265 }
7266 ans.emplace_back(last_pos - i + 1);
7267 i = last_pos + 1;
7268 }
7269 return ans;
7270 }

被这些函数引用 leetcode::partition_labels::TEST().


该类的文档由以下文件生成: