821. Shortest Distance to a Character 與字元的最短距離
❀ Origin
Problem
Given a string S
and a character C
,
return an array of integers representing the shortest distance from the character C
in the string.
Example 1
1 | Input: S = "loveleetcode", C = 'e' |
Note
S
string length is in[1, 10000]
.C
is a single character, and guaranteed to be in stringS
.- All letters in
S
andC
are lowercase.
❀ 翻譯
問題
給定一個字串 S
, 一個字符 C
,
回傳字符 C
在字串裡代表的最短距離的數字字串.
注意
- 字串
S
的長度在[1, 10000]
之間. C
是單一字符, 而且保證會出現在字串S
裡面.- 所有字串
S
和字符C
都會是小寫字母.
❀ Solution
JavaScript
1 | /** |