#include <leetcode.h>
◆ uncommonFromSentences()
vector< string > leetcode::uncommon_words_from_two_sentences::Solution::uncommonFromSentences |
( |
const string & |
s1, |
|
|
const string & |
s2 |
|
) |
| |
|
static |
在文件 leetcode.cpp 第 1896 行定义.
1897 auto ans = vector<string>();
1898 auto um = unordered_map<string, unsigned int>();
1899 auto *
const s1_str =
new char[s1.length() + 1];
1900 auto *
const s2_str =
new char[s2.length() + 1];
1901 strcpy(s1_str, s1.c_str());
1902 strcpy(s2_str, s2.c_str());
1903 for(
char *word = strtok(s1_str,
" "); word !=
nullptr; word = strtok(
nullptr,
" ")) {
1904 auto word_str = string(word);
1905 if(!um.contains(word_str)) {
1906 um.insert(pair(word_str, 1));
1911 for(
char *word = strtok(s2_str,
" "); word !=
nullptr; word = strtok(
nullptr,
" ")) {
1912 auto word_str = string(word);
1913 if(!um.contains(word_str)) {
1914 um.insert(pair(word_str, 1));
1919 for(
const auto &p: um) {
1921 ans.push_back(p.first);
该类的文档由以下文件生成: