当前位置:网站首页>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
边栏推荐
- Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
- "Chris Richardson microservices series" uses API gateway to build microservices
- Recovery technology with checkpoints
- Oracle triggers
- Hysbz 2243 staining (tree chain splitting)
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- QML reported an error expected token ";", expected a qualified name ID
- 华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
- ICMP 介绍
- Livelocks and deadlocks of concurrency control
猜你喜欢
CA certificate trampled pit
Yolov5 training custom data set (pycharm ultra detailed version)
Concurrency control of performance tuning methodology
深信服X计划-网络协议基础 DNS
Drawing HSV color wheel with MATLAB
How can Huawei online match improve the success rate of player matching
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Defect detection - Halcon surface scratch detection
Oracle hint understanding
Performance monitoring of database tuning solutions
随机推荐
How to use tensorflow2 for cat and dog classification and recognition
Analyse des risques liés aux liaisons de microservices
EBS Oracle 11g cloning steps (single node)
NET中小型企业项目开发框架系列(一个)
K210学习笔记(四) K210同时运行多个模型
database mirroring
Scenario interview: ten questions and ten answers about distributed locks
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
华为快游戏调用登录接口失败,返回错误码 -1
Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
AD637 usage notes
K210 learning notes (IV) k210 runs multiple models at the same time
MMAP
Oracle HugePages没有被使用导致服务器很卡的解决方法
总结出现2xx、3xx、4xx、5xx状态码的原因
poj 3237 Tree(树链拆分)
Robot operation mechanism
PyGame practical project: write Snake games with 300 lines of code
Performance monitoring of database tuning solutions