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的更多相关文章

  1. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  2. 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 ...

  3. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  4. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

  5. [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 ...

  6. [LeetCode] Group Shifted Strings 群组偏移字符串

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  7. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. [LeetCode] Multiply Strings 字符串相乘

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. 使用strings查看二进制文件中的字符串

    使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...

随机推荐

  1. vuex的购物车效果 index.js

    import Vue from 'vue'; import Vuex, { Store } from 'vuex'; import { stat } from 'fs'; Vue.use(Vuex); ...

  2. POJ_1185_炮兵阵地 dp+状态压缩

    题目:炮兵阵地 链接:http://poj.org/problem?id=1185 解题思路: 首先用 int 来表示每一行的情况,比如说第一行是k1,那么[ k1&(k1>>2) ...

  3. oracle查看表结构命令desc

  4. (二)Wireshark的实用表格

    主要内容: 1.了解端点概念,学习如何在Wireshark中查询端点信息 2.学习利用端点窗口与会话窗口来分析数据包的特点 3.学会Wireshark的协议分层统计窗口的用法 一.端点概念 和数学里的 ...

  5. 如何确定 Hadoop map和reduce的个数--map和reduce数量之间的关系是什么?

    1.map和reduce的数量过多会导致什么情况?2.Reduce可以通过什么设置来增加任务个数?3.一个task的map数量由谁来决定?4.一个task的reduce数量由谁来决定? 一般情况下,在 ...

  6. centso7 安装redmine

    一.安装rvm ###安装rvm gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D3 ...

  7. 获取DataSet中某行某列的数据

    LabelText = DataSet11.Tables("COMM.USERS").Rows[0]["User_Name"].tostring() Label ...

  8. 一、VScode构建.NET应用程序

    一.准备工具 1.安装.NET SDK(软件开发工具包) https://microsoft.com/net/core 2.安装VScode并安装 3.安装VS Code C# extension(即 ...

  9. js对日期的判断

    在初始页面获取倒当前时间并向前推N天后作为起始时间       function date(){          var myDate = new Date();          //获取当前时间 ...

  10. XCTF 4th-WHCTF-2017 creakme

    exe文件 运行一下 随便输一下 ps.这个曹操身边的故事挺有意思的 但是没啥卵用....... 查一下壳无壳 ida载入 发现找不到main函数 直接看start感觉逻辑乱乱的(萌新求不喷..... ...