0821. Shortest Distance to a Character
https://leetcode.com/problems/shortest-distance-to-a-character
Description
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
.
ac
Last updated