当前位置:网站首页>A substring with a length of three and different characters in the leetcode simple question
A substring with a length of three and different characters in the leetcode simple question
2022-07-05 22:03:00 【·Starry Sea】
subject
If a string does not contain any duplicate characters , We call this string good character string .
Give you a string s , Please return s The middle length is 3 Of Good substring The number of .
Be careful , If the same good substring appears more than once , Every time should be included in the answer .
Substring Is a continuous sequence of characters in a string .
Example 1:
Input :s = “xyzzaz”
Output :1
explain : All in all 4 A length of 3 Substring of :“xyz”,“yzz”,“zza” and “zaz” .
The only length is 3 The good substring is “xyz” .
Example 2:
Input :s = “aababcabc”
Output :4
explain : All in all 7 A length of 3 Substring of :“aab”,“aba”,“bab”,“abc”,“bca”,“cab” and “abc” .
Good substrings include “abc”,“bca”,“cab” and “abc” .
Tips :
1 <= s.length <= 100
s Only lowercase letters .
source : Power button (LeetCode)
Their thinking
To determine whether there are duplicate elements, you can use a hash table , Then traverse the string and check one by one 3 Are all the elements different .
class Solution:
def countGoodSubstrings(self, s: str) -> int:
if len(s)<3:
return 0
i=2
count=0
while i<len(s):
if len(set(s[i-2:i+1]))==3:
count+=1
i+=1
return count

边栏推荐
- 每日刷题记录 (十四)
- Codeforces 12D ball tree array simulation 3 sorting elements
- 如何开发引入小程序插件
- Official clarification statement of Jihu company
- Yolov5 training custom data set (pycharm ultra detailed version)
- Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
- Poj3414广泛搜索
- Livelocks and deadlocks of concurrency control
- matlab绘制hsv色轮图
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
猜你喜欢

Stored procedures and stored functions

Oracle triggers

Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes

Meituan dynamic thread pool practice ideas, open source

资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌

Performance monitoring of database tuning solutions

Matlab | app designer · I used Matlab to make a real-time editor of latex formula

MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器

从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析

Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
随机推荐
Reptile practice
Blocking of concurrency control
matlab绘制hsv色轮图
QML reported an error expected token ";", expected a qualified name ID
Huawei fast game failed to call the login interface, and returned error code -1
Two stage locking protocol for concurrency control
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
Server optimization of performance tuning methodology
Daily question brushing record (XIV)
Poj 3237 Tree (Tree Chain Split)
Talking about MySQL index
The simple problem of leetcode is to split a string into several groups of length K
HDU 4391 Paint The Wall 段树(水
Image editor for their AutoLayout environment
如何组织一场实战攻防演练
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
AD637 usage notes
MMAP learning
How to organize an actual attack and defense drill
Overview of concurrency control