# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 返回其中包含A、B、C这三个字符的最短子串的长度,如果不存在该子串,请返回0。 # @param s string字符串 代表题中所述字符串 # @return int整型 # class Solution: def findMinLength(self , s ): # write code here if 'A' not in s or 'B'not in s or'C'not in s: return 0 else: ans,a,b,c=len(s),-len(s),-len(s),-len(s) for i in range(len(s)): if s[i] == 'A': a = i if s[i] == 'B': b = i if s[i] == 'C': c = i ans = min(ans, max({a, b, c}) - min({a, b, c}) + 1) return ans