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'.
HackerRank "Morgan and a String"的更多相关文章
- HackerRank beautiful string
问题 https://vjudge.net/problem/HackerRank-beautiful-string 给一个字符串S,可以任意取走S中的两个字符从而得到另外一个字符串P,求有多少种不同的 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- *[hackerrank]Lexicographic paths
https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps 这题还是折腾很久的.题目意思相当于,比如有两个1两个0,那么 ...
- *[hackerrank]Sam and sub-strings
https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...
- [hackerrank]The Love-Letter Mystery
https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery 简单题. #include <cstdlib& ...
- *[hackerrank]ACM ICPC Team
https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team 这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过 ...
- Hackerrank 2020 February 2014 解题报告
Hackerrank 2020 February 2014 解题报告 比赛链接 Sherlock and Watson (20分) 题意:给定一个数组,向右平移K次,然后有Q个询问,问第x位置上是几 ...
- hackerrank:Almost sorted interval
题目链接:https://www.hackerrank.com/challenges/almost-sorted-interval 题目大意: 定义一个“几乎单调”区间(区间最小值在最左面,最大值在最 ...
- 【转】morgan stanley 电面面经新鲜出炉
楼楼早上上午大概11点接到的电话,一个声音炒鸡好听的GG,说他是来自morgan stanley的,想和我约一下店面时间.我一听,真是戳不及防,掐指一算,online的IKE测试已经过去20几天了吧, ...
随机推荐
- C语言字符串声明
重新学习C语言字符串声明char *a="nihao";char a[]="nihao";什么区别?前者定义的是指针,并且指向字符串常量“nihao”,后者是字 ...
- CentOS7.0关于libguestfs的bug
libguestfs,libguestfs-tools是用来在不启动虚拟机的情况下,快速简单访问虚拟机磁盘的工具. 今天在CentOS7.0系统上通过guestmount命令去mount虚拟机磁盘的时 ...
- Oracle 12C RAC的optimizer_adaptive_features造成数据插入超时
问题分析 使用10046事件追踪方式,直接生成上传时的数据库事件日志进行分析,发现主要区别在于以下两条sql语句在每次长时间上传时都有出现,并且执行用户不是上传用户,而是数据库SYS用户. ***** ...
- Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
svn更新代码后,打开xcode工程文件,会出现 xxx..xcodeproj cannot be opened because the project file cannot be parsed ...
- Validform:一行代码搞定整站的表单验证!
表单验证不再发愁,http://validform.rjboy.cn/
- codeforces hungry sequence 水题
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...
- PHP实例开发(1)PHP站内搜索
PHP站内搜索:多关键字.加亮显示 1.SQL语句中的模糊查找 $sql = "SELECT * FROM `message` WHERE `content`like '%$k[0]%' a ...
- Makefile---make内嵌函数及make命令显示 (九)
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 这一节我们讲一下make的函数,在之前的章节已经讲到了几个函数:wildcard.patsubs ...
- leetcode 41 First Missing Positive ---java
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- php MySQL数据库操作类源代码
php MySQL数据库操作类源代码: <?php class MySQL{ private $host; //服务器地址 private $name; //登录账号 private $pwd; ...