当前位置:网站首页>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
边栏推荐
- Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
- MMAP学习
- MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
- The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
- Web3为互联网带来了哪些改变?
- Talking about MySQL index
- database mirroring
- A long's perception
- 科技云报道:算力网络,还需跨越几道坎?
- Shell script, awk uses if, for process control
猜你喜欢
Granularity of blocking of concurrency control
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
MMAP learning
Daily question brushing record (XIV)
Performance monitoring of database tuning solutions
Dbeaver executes multiple insert into error processing at the same time
Overview of concurrency control
Learning of mall permission module
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
随机推荐
Business learning of mall commodity module
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
854. String BFS with similarity K
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
Pointer parameter passing vs reference parameter passing vs value parameter passing
Multiplexing of Oracle control files
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
oracle 控制文件的多路复用
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
Win11运行cmd提示“请求的操作需要提升”的解决方法
Decorator learning 01
Comment développer un plug - in d'applet
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
大约SQL现场“这包括”与“包括在”字符串的写法
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Drawing HSV color wheel with MATLAB
Installation of VMware Workstation
database mirroring
Performance monitoring of database tuning solutions