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

#include <leetcode.h>

静态 Public 成员函数

static unsigned int str2bin (const string &)
 
static int wordCount (vector< string > &startWords, vector< string > &targetWords)
 

详细描述

在文件 leetcode.h300 行定义.

成员函数说明

◆ str2bin()

unsigned int leetcode::count_words_obtained_after_adding_a_letter::Solution::str2bin ( const string &  str)
static

在文件 leetcode.cpp713 行定义.

713 {
714 unsigned int ret = 0;
715 for(const char ch: str) {
716 ret |= 1 << ch - 'a';
717 }
718 return ret;
719 }

被这些函数引用 wordCount().

◆ wordCount()

int leetcode::count_words_obtained_after_adding_a_letter::Solution::wordCount ( vector< string > &  startWords,
vector< string > &  targetWords 
)
static

在文件 leetcode.cpp692 行定义.

693 {
694 int count = 0;
695 auto start = unordered_set<unsigned int>();
696 for(const string &word: startWords) {
697 auto bin = str2bin(word);
698 start.insert(bin);
699 }
700 for(const string &word: targetWords) {
701 const auto bin = str2bin(word);
702 for(int i = 0; i < 26; i++) {
703 if((bin & 1 << i) != 0 && start.contains(bin - (1 << i))) {
704 //bin有第i个字母且bin去掉第i个字母在start中仍然存在
705 count++;
706 break;
707 }
708 }
709 }
710 return count;
711 }

引用了 str2bin().

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


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