Created
March 19, 2016 01:55
-
-
Save jianminchen/9d80b3995adf0b01f9d7 to your computer and use it in GitHub Desktop.
Two strings - byte, Hashset, beautiful code
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
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