2955. Number of Same-End Substrings
You are given a 0-indexed string
s
, and a 2D array of integersqueries
, wherequeries[i] = [li, ri]
indicates a substring ofs
starting from the indexli
and ending at the indexri
(both inclusive), i.e.s[li..ri]
.Return an array
ans
whereans[i]
is the number of same-end substrings ofqueries[i]
.A 0-indexed string
t
of lengthn
is called same-end if it has the same character at both of its ends, i.e.,t[0] == t[n - 1]
.A substring is a contiguous non-empty sequence of characters within a string.
c++
1 |
|
c++
1 |
|