Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:52
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/775cf5e16d065e66feae to your computer and use it in GitHub Desktop.
Save jianminchen/775cf5e16d065e66feae to your computer and use it in GitHub Desktop.
Two strings - Array, BinarySearch method, Array.sort
using System;
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 count = Convert.ToInt32(Console.ReadLine());
for(int i=0; i < count; i++)
{
bool found = false;
char [] myFirstChar = Console.ReadLine().ToCharArray();
char [] mySecondChar = Console.ReadLine().ToCharArray();
Array.Sort(myFirstChar);
Array.Sort(mySecondChar);
for(int j=0; j < myFirstChar.Length; j++){
if(Array.BinarySearch(mySecondChar,myFirstChar[j])>=0)
{ found = true; break;}
}
if (found)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment