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

边栏推荐
- MongoDB 慢查询语句优化分析策略
- 2022-02-13 (347. Top k high frequency elements)
- x Problem B
- 2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
- FISCO bcos zero knowledge proof Fiat Shamir instance source code
- Wine travel Jianghu War: Ctrip is strong, meituan is strong, and Tiktok is fighting
- After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
- [set theory] binary relation (example of binary relation on a | binary relation on a)
- When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
- 2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
猜你喜欢

Fcpx template: sweet memory electronic photo album photo display animation beautiful memory

Bugku CTF daily question baby_ flag. txt

Golang -- realize file transfer

Contents of welder (primary) examination and welder (primary) examination in 2022

2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills

2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical

Arthas watch grabs a field / attribute of the input parameter

消息队列(MQ)介绍

Pdf editing tool movavi pdfchef 2022 direct download

data2vec! New milestone of unified mode
随机推荐
How do you use lodash linking function- How do you chain functions using lodash?
Integration of Android high-frequency interview questions (including reference answers)
How to use kotlin to improve productivity: kotlin tips
vulnhub HA: Natraj
FISCO bcos zero knowledge proof Fiat Shamir instance source code
Kingbasees plug-in KDB of Jincang database_ date_ function
Redis persistence principle
arthas watch 抓取入参的某个字段/属性
FFMpeg example
Two drawing interfaces - 1 Matlab style interface
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Joint search set: the number of points in connected blocks (the number of points in a set)
P35-P41 fourth_ context
vulnhub HA: Natraj
Reptile exercise 02
会员积分商城系统的功能介绍
[set theory] binary relation (example of binary relation on a | binary relation on a)
Preliminary cognition of C language pointer
What functions need to be set after the mall system is built