当前位置:网站首页>The statistics of leetcode simple question is the public string that has appeared once
The statistics of leetcode simple question is the public string that has appeared once
2022-07-05 22:03:00 【·Starry Sea】
subject
Here are two string arrays words1 and words2 , Please return in two string arrays Just once Number of strings .
Example 1:
Input :words1 = [“leetcode”,“is”,“amazing”,“as”,“is”], words2 = [“amazing”,“leetcode”,“is”]
Output :2
explain :
- “leetcode” Occurs exactly once in both arrays , Count answers .
- “amazing” Occurs exactly once in both arrays , Count answers .
- “is” In both arrays , But in words1 In the 2 Time , Don't count the answers .
- “as” stay words1 There's a time when , But in words2 There's no such thing as , Don't count the answers .
therefore , Yes 2 A string appears exactly once in both arrays .
Example 2:
Input :words1 = [“b”,“bb”,“bbb”], words2 = [“a”,“aa”,“aaa”]
Output :0
explain : No string occurs exactly once in both arrays .
Example 3:
Input :words1 = [“a”,“ab”], words2 = [“a”,“a”,“a”,“ab”]
Output :1
explain : The only string that appears once in both arrays is “ab” .
Tips :
1 <= words1.length, words2.length <= 1000
1 <= words1[i].length, words2[j].length <= 30
words1[i] and words2[j] All contain only lower case letters .
source : Power button (LeetCode)
Their thinking
Count two... Respectively words The frequency of the string in , Then traverse the common parts of the two frequency tables , Search frequency is 1 String .
class Solution:
def countWords(self, words1: List[str], words2: List[str]) -> int:
words1=Counter(words1)
words2=Counter(words2)
count=0
for i in words1.keys()&words2.keys():
if words1[i]==1 and words2[i]==1:
count+=1
return count
边栏推荐
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- Sentinel production environment practice (I)
- AD637使用筆記
- Detailed explanation of memset() function usage
- database mirroring
- Image editor for their AutoLayout environment
- "Chris Richardson microservices series" uses API gateway to build microservices
- 了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
- MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
- 如何開發引入小程序插件
猜你喜欢
PIP install beatifulsoup4 installation failed
The real situation of programmers
CA certificate trampled pit
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
EBS Oracle 11g 克隆步骤(单节点)
Huawei fast game failed to call the login interface, and returned error code -1
Ad637 notes d'utilisation
The American Championship is about to start. Are you ready?
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
随机推荐
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Index optimization of performance tuning methodology
Robot operation mechanism
装饰器学习01
Talking about MySQL index
华为快游戏调用登录接口失败,返回错误码 -1
EBS Oracle 11g cloning steps (single node)
How to organize an actual attack and defense drill
Overview of concurrency control
华为联机对战如何提升玩家匹配成功几率
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
AD637 usage notes
[Yugong series] go teaching course in July 2022 004 go code Notes
Huawei cloud modelarts text classification - takeout comments
Deeply convinced plan X - network protocol basic DNS
大约SQL现场“这包括”与“包括在”字符串的写法
Meituan dynamic thread pool practice ideas, open source
Common interview questions of JVM manufacturers
Performance monitoring of database tuning solutions