题解 | #整型数组合并#

整型数组合并

https://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b

m = int(input())

mlist = list(map(int, input().split()))
mlist = sorted(set(mlist))  # 排序并去重
#print(mlist)
n = int(input())
nlist = list(map(int, input().split()))
nlist = sorted(set(nlist))  # 排序并去重
#print(nlist)
res = ''
i, j = 0, 0

while i < len(mlist) and j < len(nlist):
    if mlist[i] < nlist[j]:
        res += str(mlist[i])
        i += 1
    elif mlist[i] > nlist[j]:
        res += str(nlist[j])
        j += 1
    else:
        res += str(mlist[i])  # 两者相等,添加任意一个
        i += 1
        j += 1

# 直接添加剩余元素(如果有的话,由于列表已排序,这里只会添加一个列表的剩余部分)
res += "".join(map(str, mlist[i:])) + "".join(map(str, nlist[j:]))

print(res)

全部评论

相关推荐

07-04 16:00
门头沟学院 Java
点赞 评论 收藏
分享
仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务