Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:47
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/aa87f82f0247c4b59ab6 to your computer and use it in GitHub Desktop.
Save jianminchen/aa87f82f0247c4b59ab6 to your computer and use it in GitHub Desktop.
Two Strings - 2 hashset, and then, find the common element
namespace Solution
{
using System;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
int val = int.Parse(Console.ReadLine());
for(int i=0;i<val;i++)
{
char[] s1 = Console.ReadLine().Trim().ToCharArray();
char[] s2 = Console.ReadLine().Trim().ToCharArray();
HashSet<char> H1=new HashSet<char>();
HashSet<char> H2=new HashSet<char>();
//bool check = false;
for(int x=0;x<s1.Length;x++)H1.Add(s1[x]);
for(int y=0;y<s2.Length;y++)H2.Add(s2[y]);
bool chk=false;
foreach(char c in H1){
if(H2.Contains(c))chk=true;
}
Console.WriteLine(chk?"YES":"NO");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment