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()