HackerRank "Morgan and a String"

时间:2016-04-08 06:38:41   收藏:0   阅读:220

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

原文:http://www.cnblogs.com/tonix/p/5366382.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!