连接两个字符串中的不同字符 lintcode python

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 18:54   1891   0

给出两个字符串, 你需要修改第一个字符串,将所有与第二个字符串中相同的字符删除, 并且第二个字符串中不同的字符与第一个字符串的不同字符连接

样例

给出 s1 = aacdb, s2 = gafd
返回 cbgf
给出 s1 = abcs, s2 = cxzca;
返回 bsxz

思路启发自博客连接两个字符串中的不同字符

class Solution:
    """
    @param: : the 1st string
    @param: : the 2nd string
    @return: uncommon characters of given strings
    """
    
    def concatenetedString(self, s1, s2):
        # write your code here
        s3=''
        for i in range(len(s1)):
            if s1[i] not in s2:
              s3=s3+s1[i]   
        for i in range(len(s2)):
            if s2[i] not in s1:
              s3=s3+s2[i]
        return s3


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP