Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/9d80b3995adf0b01f9d7 to your computer and use it in GitHub Desktop.
Save jianminchen/9d80b3995adf0b01f9d7 to your computer and use it in GitHub Desktop.
Two strings - byte, Hashset, beautiful code
using System;
using System.Collections.Generic;
class Solution
{
struct Data
{
public string a;
public string b;
}
static void Main(String[] args)
{
byte t = byte.Parse(Console.ReadLine());
Data[] datas = new Data[t];
for (int i = 0; i < t; i++)
{
datas[i] = new Data { a = Console.ReadLine(), b = Console.ReadLine() };
}
foreach (Data data in datas)
{
Console.WriteLine(CheckTwoStrings(data) ? "YES" : "NO");
}
}
private static bool CheckTwoStrings(Data data)
{
HashSet<char> hashSet = new HashSet<char>(data.a);
foreach (char c in data.b)
{
if (hashSet.Contains(c))
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment