当前位置:网站首页>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

边栏推荐
- Comment développer un plug - in d'applet
- 每日刷题记录 (十四)
- Oracle检查点队列–实例崩溃恢复原理剖析
- A trip to Suzhou during the Dragon Boat Festival holiday
- Common interview questions of JVM manufacturers
- Poj 3237 Tree (Tree Chain Split)
- oracle 控制文件的多路复用
- 让开发效率提升的跨端方案
- NET中小型企业项目开发框架系列(一个)
- 1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
猜你喜欢

CA certificate trampled pit

MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server

【愚公系列】2022年7月 Go教学课程 004-Go代码注释

The real situation of programmers

Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)

Oracle triggers

Huawei fast game failed to call the login interface, and returned error code -1

An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017

Pl/sql basic syntax

QML reported an error expected token ";", expected a qualified name ID
随机推荐
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
How can Huawei online match improve the success rate of player matching
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
DataGrid directly edits and saves "design defects"
Talking about MySQL index
Type of fault
总结出现2xx、3xx、4xx、5xx状态码的原因
Huawei cloud modelarts text classification - takeout comments
阿龙的感悟
Oracle views the data size of a table
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
HDU 4391 Paint The Wall 段树(水
如何向mongoDB中添加新的字段附代码(全)
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Learning of mall permission module
How to view Apache log4j 2 remote code execution vulnerability?
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
Index optimization of performance tuning methodology
MMAP学习