avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

2085. Public string that has occurred once

  2023-12-01        
字数统计: 95字   |   阅读时长: 1min

topic:

screenshot2024-01-12 afternoon5.12.50.png

Thought:

First useCountercount,use & The symbol is connected to two dictionarieskeys, The remaining part is both。
Traversing this remaining part,Determine whether it is equal to 1 Be

Code:

1
2
3
4
5
6
7
8
9
10
class Solution:
def countWords(self, words1: List[str], words2: List[str]) -> int:
words_1 = Counter(words1)
words_2 = Counter(words2)
ans = 0
for i in words_1.keys() & words_2.keys():
if words_1[i] == 1 and words_2[i] == 1:
ans += 1
return ans

One -line writing
1
return sum(1 for i in Counter(words1) & Counter(words2) if Counter(words1)[i] == 1 and Counter(words2)[i] == 1)
  • Array
  • String
  • Hash table
  • count

扫一扫,分享到微信

微信分享二维码
Sword finger Offer II 021. Delete the countdown of the linked list n Node
Next.js Fundamentals
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号