转发: 巨硬校园面试

coding: find the length of the longest substring that contains the character in the given string. 比如 String s = “abc”, String a = “asaaabcccqmhacb”, return 7. 因为最长的substirng 是 “aaabccc“。 当时只想到了暴力解,因为面试只有30分钟,我就写了暴力解,怕写新的解法想不出来。然后面试官说其实这题可以用two pointer做。然后就挂了。果然不写最优解会挂。

有个问题 如果是最长的子串 最长为什么不是原string了?