Shared Once
Sometimes you need to find words that appear in two lists but never repeat in either one. Write a function count_words that receives two word lists, words1 and words2. Count how many words appear exactly once in the first list and exactly once in the second list. Return that count.
Примеры
Ввод
["leetcode", "is", "amazing", "as", "is"], ["amazing", "leetcode", "is"]Вывод
2Ввод
["b", "bb", "bbb"], ["a", "aa", "aaa"]Вывод
0Ввод
["a", "ab"], ["a", "a", "a", "ab"]Вывод
1Нужно реализовать
def count_words(words1: list[str], words2: list[str]) -> int:
Теги
stringshashmapdict
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
["leetcode","is","amazing","as","is"], ["amazing","leetcode","is"]Expected
22
Input
["b","bb","bbb"], ["a","aa","aaa"]Expected
03
Input
["a","ab"], ["a","a","a","ab"]Expected
14
Input
["x"], ["x"]Expected
15
Input
["x","x"], ["x"]Expected
06
Input
["p","q","r"], ["q","r","s"]Expected
2Focus radio
Paused · SomaFM · Fluid