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

边栏推荐
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- 2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
- 拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
- Bugku CTF daily question baby_ flag. txt
- How to use kotlin to improve productivity: kotlin tips
- Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
- Kubernetes源码分析(一)
- AWS VPC
- GFS distributed file system (it's nice to meet it alone)
- 2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
猜你喜欢
![[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN

Preliminary cognition of C language pointer

Design and implementation of JSP logistics center storage information management system

How to choose cross-border e-commerce multi merchant system

拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。

Function introduction of member points mall system

2022 new examination questions for the main principals of hazardous chemical business units and examination skills for the main principals of hazardous chemical business units

JVM原理简介

Feature_selection

Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
随机推荐
2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
Priv-app permission异常
Redis persistence principle
解决bp中文乱码
Employee attendance management system based on SSM
The latest activation free version of Omni toolbox
vulnhub HA: Natraj
Mongodb slow query optimization analysis strategy
Bugku CTF daily question baby_ flag. txt
怎么用Kotlin去提高生产力:Kotlin Tips
Summary of training competition (Lao Li's collection of questions)
[free completion] development of course guidance platform (source code +lunwen)
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
Reptile exercise 03
X-ray normal based contour rendering
2022-02-13 (347. Top k high frequency elements)
Xrandr modifier la résolution et le taux de rafraîchissement
Youdao cloud notes
Preliminary cognition of C language pointer