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

边栏推荐
- [nlp] - brief introduction to the latest work of spark neural network
- [set theory] binary relation (example of binary relation on a | binary relation on a)
- xrandr修改分辨率與刷新率
- Which code editor is easy to use? Code editing software recommendation
- [set theory] binary relationship (definition field | value field | inverse operation | inverse synthesis operation | restriction | image | single root | single value | nature of synthesis operation)
- Two drawing interfaces - 1 Matlab style interface
- Two points -leetcode-540 A single element in an ordered array
- Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
- 使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
- MySQL field userid comma separated save by userid query
猜你喜欢

A outsourcing boy's mid-2022 summary

redis 持久化原理
![[文献阅读] 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

MC Layer Target

data2vec! New milestone of unified mode

使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错

7. Integrated learning

2022 P cylinder filling test content and P cylinder filling simulation test questions

2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination

Jincang KFS data bidirectional synchronization scenario deployment
随机推荐
xrandr修改分辨率與刷新率
[set theory] inclusion exclusion principle (including examples of exclusion principle)
redis 持久化原理
重绘和回流
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
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
stm32逆向入门
Web - Information Collection
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
会员积分商城系统的功能介绍
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Employee attendance management system based on SSM
After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
2022-02-14 (394. String decoding)
Basic use of continuous integration server Jenkins
Integration of Android high-frequency interview questions (including reference answers)
Redraw and reflow
消息队列(MQ)介绍