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 ...
随机推荐
- RestTemplete
RestTemplete是由spring提供的,可以用来模拟浏览器进行服务调用的封装好的Api,和Apache 的HttpClient功能相同,在分布式系统中可以用来服务之间的调用. 开发步骤: 1. ...
- MySQL 使用左连接替换not in
众所周知,左连接和右连接的含义是以哪一张表为准. 左连接就是以左表为准,查出的结果中包含左表所有的记录,如果右表中没有与其对应的记录,那么那一行记录中B表部分的内容就全是NULL. 现在有两个表,一个 ...
- MySQL慢查询日志配置方式 slow_query_log
MySQL慢查询(一) - 开启慢查询 - 鲁玉成 - 博客园 https://www.cnblogs.com/luyucheng/p/6265594.html mysql开启慢查询方法 - lava ...
- Linux基础命令和NAT技术
yum yellowdog updater,modified是一种用python写的基于rpm的管理工具 用于解决rpm包的依赖性 要安装编译工具 yum install gcc 库函数:静态库 ...
- switch-case和if-else可互换时
当switch-case和if-else可互换时,应当优先采用switch-case.因为switch-case的效率更高(详情下回分解).
- CodeForces 126B Password
题目链接:http://codeforces.com/problemset/problem/126/B 题目大意: 多组数据每组给定1个字符串S,问是否存在S的一个尽量长的子串,同时是S的前缀和后缀, ...
- Spark join连接
内链接
- React Native & Google & Proxy
React Native & Google & Proxy https://snack.expo.io/ https://expo.io/snacks/@xgqfrms https:/ ...
- qtp 自动化测试--点滴 菜单没有了,有些控件运行时找不到
test项目页签下-没有了 菜单栏:file edit view insert 看不到了 1 解决:在startpage标签下-tool-option-点击 restore layout-确定 2 菜 ...
- SQL Server中的完全连接(full join)
一.建库和建表 create database scort use scort create table emp ( empno int primary key, ename ), sal int, ...