码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank "Morgan and a String"

时间:2016-04-08 06:38:54      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

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

HackerRank "Morgan and a String"

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!