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

边栏推荐
- 因子选股-打分模型
- [set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
- Web - Information Collection
- 跨境电商多商户系统怎么选
- How to retrieve the password for opening word files
- Xrandr modifier la résolution et le taux de rafraîchissement
- 2022-02-14 (394. String decoding)
- Interface in TS
- Dive Into Deep Learning——2.1数据操作&&练习
- 2.14 summary
猜你喜欢

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

2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis

Bugku CTF daily question baby_ flag. txt

Learning practice: comprehensive application of cycle and branch structure (I)

P35-P41 fourth_ context

FFMpeg filter

Redis persistence principle

SSM based campus part-time platform for College Students
![[free completion] development of course guidance platform (source code +lunwen)](/img/14/7c1c822bda050a805fa7fc25b802a4.jpg)
[free completion] development of course guidance platform (source code +lunwen)
![[nlp] - brief introduction to the latest work of spark neural network](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[nlp] - brief introduction to the latest work of spark neural network
随机推荐
How do you use lodash linking function- How do you chain functions using lodash?
[set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
FFMpeg filter
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
vulnhub HA: Natraj
Employee attendance management system based on SSM
Learning practice: comprehensive application of cycle and branch structure (I)
2022-02-12 (338. Bit count)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
金仓KFS数据双向同步场景部署
JS multidimensional array to one-dimensional array
2022-02-13 (347. Top k high frequency elements)
[set theory] inclusion exclusion principle (including examples of exclusion principle)
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Which code editor is easy to use? Code editing software recommendation
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
data2vec! New milestone of unified mode
Function introduction of member points mall system