Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:51
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/b28fab138ad778bc4326 to your computer and use it in GitHub Desktop.
Save jianminchen/b28fab138ad778bc4326 to your computer and use it in GitHub Desktop.
Two strings - Hashset - overlaps - code is readable.
using System;
using System.Collections.Generic;
class Solution
{
static void Main(String[] args)
{
var t = Convert.ToInt32(Console.ReadLine());
var stringsA = new string[t];
var stringsB = new string[t];
for (var i = 0; i < t; i++)
{
stringsA[i] = Console.ReadLine();
stringsB[i] = Console.ReadLine();
};
for (var i = 0; i < t; i++)
{
var hasCommon = false;
var set = new HashSet<char>();
for (int j = 0; j < stringsA[i].Length; j++)
{
set.Add(stringsA[i][j]);
}
for (int j = 0; j < set.Count; j++)
{
hasCommon = set.Overlaps(stringsB[i].ToCharArray());
if (hasCommon) break;
}
Console.WriteLine(hasCommon ? "YES" : "NO");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment