def shortestToChar(S, C): c=[] s=[] for i,v in enumerate(S): if v==C: c.append(i) for i,v in enumerate(S): m=[] for j in c: m.append(abs(i-j)) s.append(min(m)) return s
原文地址:https://www.cnblogs.com/zhangtianxia/p/9043620.html
时间: 2024-10-08 11:13:38