Created
March 19, 2016 01:51
-
-
Save jianminchen/b28fab138ad778bc4326 to your computer and use it in GitHub Desktop.
Two strings - Hashset - overlaps - code is readable.
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 | |
{ | |
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