HackerRank Two Strings

x·2021년 5월 2일
0

problem-solving

목록 보기
10/18
#!/bin/python3

import os
from enum import Enum


class BoolEnum(Enum):
    YES = "YES"
    NO = "NO"


def two_strings(s1: str, s2: str):
    s1_dict, s2_dict = {}, {}
    s1_len, s2_len = len(s1), len(s2)

    for c in s1:
        s1_dict[c] = True

    for c in s2:
        s2_dict[c] = True

    if s1_len > s2_len:
        for c in s2:
            if c in s1_dict:
                return BoolEnum.YES
    else:
        for c in s1:
            if c in s2_dict:
                return BoolEnum.YES

    return BoolEnum.NO


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    q = int(input().strip())

    for q_itr in range(q):
        s1 = input()

        s2 = input()

        result = two_strings(s1=s1, s2=s2)

        fptr.write(result + '\n')

    fptr.close()

0개의 댓글