2085. Count Common Words With One Occurrence - LeetCode Solution


Hash Table

Python Code:

class Solution:
    def countWords(self, word1: List[str], word2: List[str]) -> int:
        dict = {}
        dict2 = {}
        for i in word1:
            if i in dict:
                dict[i] +=1
            else:
                dict[i] = 1
        for i in word2:
            if i in dict2:
                dict2[i] +=1
            else:
                dict2[i] = 1
        count = 0
        for i in dict:
            if dict[i] == 1:
                if i in dict2:
                    if dict2[i] == 1:
                        count+=1
        return count
                
        


Comments

Submit
0 Comments
More Questions

1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves