Created
March 19, 2016 01:47
-
-
Save jianminchen/aa87f82f0247c4b59ab6 to your computer and use it in GitHub Desktop.
Two Strings - 2 hashset, and then, find the common element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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