821. Shortest Distance to a Character
Easy
Given a string s
and a character c
that occurs in s
, return an array of integers answer
where answer.length == s.length
and answer[i]
is the distance from index i
to the closest occurrence of character c
in s
.
The distance between two indices i
and j
is abs(i - j)
, where abs
is the absolute value function.
Example 1:
Example 2:
Constraints:
1 <= s.length <= 104
s[i]
andc
are lowercase English letters.It is guaranteed that
c
occurs at least once ins
.
解題
Runtime: 0 ms, faster than 100.00%
Memory Usage: 2.4 MB, less than 36.59%
Last updated