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 ...
随机推荐
- 【学习总结】Git学习-参考廖雪峰老师教程二-安装Git
学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...
- Dockers 学习
Docker镜像操作,有五个常用的命令: a.拉取镜像,后跟镜像仓库名称,如果要指定某个版本,可以带上tag. > docker pull <repo>[:tag] b.列出所有镜像 ...
- C#中闭包的陷阱
我们在使用lambda的时候会遇到闭包,在闭包中有一个陷阱是在for循环中产生的,先上代码: class Program { static void Main(string[] args) { Act ...
- springmvc配置文件的主要内容
springmvc配置文件的主要内容:
- 2017 Python最新面试题及答案16道题
1.Python是如何进行内存管理的? 答:从三个方面来说,一对象的引用计数机制,二垃圾回收机制,三内存池机制 一.对象的引用计数机制 Python内部使用引用计数,来保持追踪内存中的对象,所有对象都 ...
- 解决mybatis generator警告Cannot obtain primary key information from the database, generated objects may be incomplete
使用 mybatis generator 生成pojo.dao.mapper时 经常出现 Cannot obtain primary key information from the database ...
- 微信小程序wxml無法實現頁面跳轉的問題
wxml的 navigator的url設置后無法跳轉? 檢查要跳轉的頁面是否是在APP.json的tabBar里註冊過,如果是tabBar頁面是不能用wx.navigateTo和wx.Redirect ...
- Python学习之路——Day06 元组
一.元组 t1 = (1, 2) t2 = tuple((1, 2)) t3 = (1, ) # 索引 | 切片 | 长度 # .count(obj) | .index(obj, bIndex, eI ...
- js 插件使用总结
1:树形菜单插件: z-tree 和dtree 2: 弹窗插件layer 3: 前端ui框架ace , h-ui , layui 4:产品设计图绘制软件Axure和Mockplus(推荐)
- Visual Studio常用插件整理
Visual Studio Tools for Git GIT代码管理工具 Resharper 代码生成工具 CSOutline2017 语法级别的代码折叠 ...