HackerRank "Morgan and a String"

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'.

上一篇:数据库SQL的多表查询


下一篇:C#操作redis代码汇总