您的位置:首页 > 其它

HackerRank "Morgan and a String"

2016-04-08 03:13 417 查看
I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution:

for _ in range(int(input())):
a = input() + '['
b = input() + '['

output = ""
for _ in range(len(a) + len(b) - 2):
if a < b:
output += a[0]
a = a[1:]
else:
output += b[0]
b = b[1:]

print(output)


Please note: '[' is the first char after 'Z'.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: