702. Concatenated String with Uncommon Characters of Two Strings

最后的结果是:s1+s2,但去掉了所有一开始的共用字符

直接遍历s2的字符,从s1/s2里面删掉,再拼结果。

遍历s1其实也一样。

class Solution:
    """
    @param s1: the 1st string
    @param s2: the 2nd string
    @return: uncommon characters of given strings
    """
    def concatenetedString(self, s1, s2):
        for char in s2:
            if char in s1:
                s1 = s1.replace(char, '')
                s2 = s2.replace(char, '')
        return s1+s2

Last updated

Was this helpful?