3456. Find Special Substring of Length K
You are given a string
s
and an integerk
.Determine if there exists a substring of length exactly
k
ins
that satisfies the following conditions:
- The substring consists of only one distinct character (e.g.,
"aaa"
or"bbb"
).- If there is a character immediately before the substring, it must be different from the character in the substring.
- If there is a character immediately after the substring, it must also be different from the character in the substring.
Return
true
if such a substring exists. Otherwise, returnfalse
.
1 | class Solution { |