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 ...
随机推荐
- 多线程系列之十一:Two-Phase Termination模式
一,Two-Phase Termination模式 翻译过来就是:分两阶段终止 二,示例程序 public class CountupTread extends Thread { private lo ...
- No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type LeadRestControllerTest (e.g. x.new A() where x is an instance of ).
java - No enclosing instance is accessible. Must qualify the allocation with an enclosing instance o ...
- [转帖]buffer与cache的区别
作者:沈万马链接:https://www.zhihu.com/question/26190832/answer/146259979来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- Oracle 检查约束check
--检查约束 create table test1( id ) primary key, email ) check (email like '%@%') ) drop table test1 ,'1 ...
- 用户认证--------------auth模块
一.auth模块 from django.contrib import auth 1 .authenticate() :验证用户输入的用户名和密码是否相同 提供了用户认证,即验证用户名以及密码是否 ...
- python爬虫之scrapy安装(一)
简介: Scrapy,Python开发的一个快速.高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据.Scrapy用途广泛,可以用于数据挖掘.监测和自动化测试. Scrap ...
- Java变量类型识别的3种方式
内容导览 反射方式,成员变量的类型判断 isInstance用法 利用泛型识别类型 测试类: package com.cxyapi.oo; import java.util.Date; import ...
- 三、oneinstack
一.介绍 oneinstack https://www.cnblogs.com/lxwphp/p/9231554.html
- PHP namespace、require、use区别
假设 有文件a.php 代码 <?php class a{//类a public function afun()//函数afun { echo "aaaa"; } } ?&g ...
- 转载 -- CSS3 中关于 select 下拉列表的样式
截图效果: