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
Sstring length is in[1, 10000].Cis a single character, and guaranteed to be in stringS.- All letters in
SandCare lowercase.
❀ 翻譯
問題
給定一個字串 S, 一個字符 C,
回傳字符 C 在字串裡代表的最短距離的數字字串.
注意
- 字串
S的長度在[1, 10000]之間. C是單一字符, 而且保證會出現在字串S裡面.- 所有字串
S和字符C都會是小寫字母.
❀ Solution
JavaScript
1 | /** |