当前位置:网站首页>Number of uniform strings of leetcode simple problem
Number of uniform strings of leetcode simple problem
2022-07-03 04:31:00 【·Starry Sea】
subject
Give you a string of different characters allowed And an array of strings words . If every character of a string is in allowed in , Call this string Consistent string .
Please return words Array Consistent string Number of .
Example 1:
Input :allowed = “ab”, words = [“ad”,“bd”,“aaab”,“baa”,“badab”]
Output :2
explain : character string “aaab” and “baa” It's all consistent strings , Because they only contain characters ‘a’ and ‘b’ .
Example 2:
Input :allowed = “abc”, words = [“a”,“b”,“c”,“ab”,“ac”,“bc”,“abc”]
Output :7
explain : All strings are consistent .
Example 3:
Input :allowed = “cad”, words = [“cc”,“acd”,“b”,“ba”,“bac”,“bad”,“ac”,“d”]
Output :4
explain : character string “cc”,“acd”,“ac” and “d” Is a consistent string .
Tips :
1 <= words.length <= 10^4
1 <= allowed.length <= 26
1 <= words[i].length <= 10
allowed The characters in Different from each other .
words[i] and allowed Only lowercase letters .
source : Power button (LeetCode)
Their thinking
If words All the characters in the words in allowed If so, the string is consistent , So just ask words The elements and allowed The difference set of , If the difference set is not empty , said words Some of the elements allowed No, , If it is empty , said words There are elements allowed It's all inside .
class Solution:
def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
count=0
for i in words:
if len(set(i)-set(allowed))==0:
count+=1
return count
边栏推荐
- Basic types of data in TS
- Bugku CTF daily question baby_ flag. txt
- 智能合约安全审计公司选型分析和审计报告资源下载---国内篇
- P35-P41 fourth_ context
- arthas watch 抓取入参的某个字段/属性
- [set theory] binary relation (example of binary relation on a | binary relation on a)
- Kingbasees plug-in KDB of Jincang database_ database_ link
- Kingbasees plug-in KDB of Jincang database_ date_ function
- BMZCTF simple_ pop
- [set theory] Cartesian product (concept of Cartesian product | examples of Cartesian product | properties of Cartesian product | non commutativity | non associativity | distribution law | ordered pair
猜你喜欢
arthas watch 抓取入参的某个字段/属性
Asp access teaching management system design finished product
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Function introduction of member points mall system
金仓KFS数据双向同步场景部署
2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
2022 P cylinder filling test content and P cylinder filling simulation test questions
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found
Feature_selection
随机推荐
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
Priv-app permission异常
Hj35 serpentine matrix
有道云笔记
Mount NFS in kubesphere
[Thesis Writing] how to write the overall design of JSP tourism network
Redraw and reflow
X-ray normal based contour rendering
arthas watch 抓取入参的某个字段/属性
Library management system based on SSM
Xrandr modify resolution and refresh rate
Pyqt control part (II)
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
Kingbasees plug-in KDB of Jincang database_ date_ function
Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
Jincang KFS data bidirectional synchronization scenario deployment
Database management tool, querious direct download
FISCO bcos zero knowledge proof Fiat Shamir instance source code
AWS VPC
What's wrong with SD card data damage? How to recover SD card data damage