HR_Two Strings
https://www.hackerrank.com/challenges/two-strings/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps
考虑时间效率 先去重再排序 有共同子串的必有共同的字母
list(set(list)) --先将列表转化为set,再转化为list就可以实现去重操作
#!/bin/python3 import math
import os
import random
import re
import sys # Complete the twoStrings function below.
def twoStrings(s1, s2):
s1 = list(set(s1))
s2 = list(set(s2))
for i in range(len(s1)):
for j in range(len(s2)):
if s1[i] == s2[j]:
return 'YES'
return 'NO' if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w') q = int(input()) for q_itr in range(q):
s1 = input() s2 = input() result = twoStrings(s1, s2) fptr.write(result + '\n') fptr.close()
HR_Two Strings的更多相关文章
- Hacker Rank: Two Strings - thinking in C# 15+ ways
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...
- StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?
StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...
- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Encode and Decode Strings 加码解码字符串
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...
- [LeetCode] Group Shifted Strings 群组偏移字符串
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- [LeetCode] Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- [LeetCode] Multiply Strings 字符串相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 使用strings查看二进制文件中的字符串
使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...
随机推荐
- css横线中间放图片或者文字
效果图: 先贴代码 HTML: <div class="forshow middle"> <div class="flex"></ ...
- 1 CHM 中文都是乱码
CHM格式是Windows系统里常见的帮助文档格式,但有时一些CHM格式的文档会局部显示乱码,特别是一些外文文档在中文版Windows里.这是因为,CHM格式文档在Windows下默认是使用IE浏览器 ...
- Java8 Hash改进/内存改进
又开新坑o(*≧▽≦)ツ讲讲几个Java版本的特性,先开始Java8, HashMap的改进 HashMap采用哈希算法,先使用hashCode()判断哈希值是否相同,如果相同,再使用equals() ...
- Spring boot+ logback环境下,日志存放路径未定义的问题
日志路径未定义 环境:Spring boot + logback 配置文件: <configuration> <springProfile name="dev"& ...
- echo "" > 和 echo "" >> 的区别
在写shell脚本中,如果判断一个文件已经存在,但希望重写这个文件,一般用如下方式 echo "" > file.txt 这个表示清空文件的内容,如果使用 echo “” & ...
- Antd & ice
Antd & ice Angular https://github.com/NG-ZORRO/ng-zorro-antd https://ng.ant.design/docs/introduc ...
- 猜数字游戏 在控制台运行--java详解!了;来玩
import java.util.Scanner;//导入包 import java.util.Scanner; 注意格式 符号的使用 public class Demo{ //猜数字游戏 练习 pu ...
- HTML 中的 href\src\url
1. 2. -------from Stack Overflow <a><link>使用 href; <img><script>使用 src;
- spawn
转载:http://motioo.blog.163.com/blog/static/117718291200954102830215/ 并行计算使用的节点数在开始运行程序时进行指定. 学习了FFT之后 ...
- Jetson TX1 install py-faster-rcnn
Install py-faster-rcnn following the official version https://github.com/rbgirshick/py-faster-rcnn ...