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

#include <leetcode.h>

静态 Public 成员函数

static vector< string > uncommonFromSentences (const string &s1, const string &s2)
 

详细描述

在文件 leetcode.h790 行定义.

成员函数说明

◆ uncommonFromSentences()

vector< string > leetcode::uncommon_words_from_two_sentences::Solution::uncommonFromSentences ( const string &  s1,
const string &  s2 
)
static

在文件 leetcode.cpp1896 行定义.

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));
1907 } else {
1908 um[word_str]++;
1909 }
1910 }
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));
1915 } else {
1916 um[word_str]++;
1917 }
1918 }
1919 for(const auto &p: um) {
1920 if(p.second == 1) {
1921 ans.push_back(p.first);
1922 }
1923 }
1924 delete[] s1_str;
1925 delete[] s2_str;
1926 return ans;
1927 }

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