62: Shortest distance to the character

Given a lower case string and target character, find out the shortest distance for each character in the given string to target character

Note: the target character always exists in the given string

 

Example 1

Input:   word = "abcade", target = a

Output:  [0, 1, 1, 0, 1, 2]

Example 2

Input:   word = "aaa", target = a

Output:  [0, 0, 0]
Difficulty:Easy
Topic:String
Problem #:62