当前位置:网站首页>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
边栏推荐
- Oracle triggers
- 大约SQL现场“这包括”与“包括在”字符串的写法
- "Chris Richardson microservices series" uses API gateway to build microservices
- 阿龙的感悟
- 华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
- AD637使用笔记
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- Server optimization of performance tuning methodology
- Analyse des risques liés aux liaisons de microservices
- 元宇宙中的三大“派系”
猜你喜欢
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
Concurrency control of performance tuning methodology
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
database mirroring
Installation of VMware Workstation
AD637 usage notes
Sentinel production environment practice (I)
Yolov5 training custom data set (pycharm ultra detailed version)
随机推荐
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Shell script, awk uses if, for process control
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Image editor for their AutoLayout environment
元宇宙中的三大“派系”
NET中小型企业项目开发框架系列(一个)
EBS Oracle 11g cloning steps (single node)
Drawing HSV color wheel with MATLAB
database mirroring
The American Championship is about to start. Are you ready?
POJ 3237 tree (tree chain splitting)
Official clarification statement of Jihu company
ICMP 介绍
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
AD637使用筆記
MMAP learning
Basic grammar of interview (Part 1)
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server