#include <leetcode.h>
|
static string | alienOrder (vector< string > &words) |
|
◆ alienOrder()
string leetcode::alien_dictionary::Solution::alienOrder |
( |
vector< string > & |
words | ) |
|
|
static |
在文件 leetcode.cpp 第 9154 行定义.
9155 unordered_map<char, unordered_set<char>> g;
9156 unordered_map<char, int> in;
9158 unordered_set<char> charset;
9159 for(
const auto &word: words) {
9160 for(
const auto &ch: word) {
9164 for(
const auto &ch: charset) {
9165 g[ch] = unordered_set<char>();
9169 for(
const auto &word: words) {
9170 max_len = max(max_len,
static_cast<int>(word.length()));
9172 for(
int i = 0; i < max_len; i++) {
9173 unordered_map<string, vector<string>> um;
9174 for(
const auto &word: words) {
9175 if(word.length() >= i) {
9176 um[i > 0 ? word.substr(0, i) :
""].emplace_back(word);
9179 for(
const auto &[pred, section]: um) {
9180 for(
int j = 0, k = 1; k < section.size(); j++, k++) {
9181 if(i < section[j].length() && i < section[k].length()) {
9182 if(section[j][i] != section[k][i]) {
9183 g[section[j][i]].insert(section[k][i]);
9185 }
else if(i < section[j].length()) {
9191 for(
const auto &[k, section]: g) {
9192 for(
const auto &n: section) {
9197 unordered_set<char> vis;
9200 for(
const auto &[ch, n]: in) {
9201 if(n == 0 && !vis.contains(ch)) {
9205 for(
const auto &nc: g[ch]) {
9211 for(
const auto &[ch, n]: in) {
被这些函数引用 leetcode::alien_dictionary::TEST().
该类的文档由以下文件生成: