首页 > 编程知识 正文

leetcode top100,no devices found

时间:2023-05-06 03:51:53 阅读:136964 作者:4449

主题: https://leet code.com/problems/find-k-length-substrings-with-no-repeated-characters /

给定字符串SS,在KK的长字符串中,询问每个字符只出现一次的子串有几个。

对于每个长k k k子串,可以通过数组动态计数每个字母出现了多少次。 代码如下所示。

public class solution { publicintnumklensubstrnorepeats (strings,int K ) if ) s.length ) k ) { return 0; } int[] count=new int[26]; for(intI=0; i K; I ) {count(s.Charat(I )-'a ); (intRES=check(count ) )? 1 : 0; for(intI=k; i S.length (; I ) ) count(s.charat(I-k )-'a ' )--; count[s.Charat(I )- 'a']; if(check(count ) ) { res; } } return res; } privatebooleancheck (int [ ] count ) ) for ) intI=0; i 26; I () if ) count[I]=2) ) { return false; } }返回真; }时间复杂度o(LS ) o ) L_S ) o ) l ) s,空间o )1) o )1) o )1) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。