首页 > 其他 > 详细

HackerRank "Morgan and a String"

时间:2016-04-08 06:38:41      阅读:218      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!