Created
March 19, 2016 06:07
-
-
Save jianminchen/95b701e6d2146da13c1d to your computer and use it in GitHub Desktop.
Two string - using dictionary(int, char) - int - just a number starting from zero
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; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
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 n_tc = Convert.ToInt32(Console.ReadLine()); | |
for (int i = 0; i < n_tc; i++) | |
{ | |
var string1 = Console.ReadLine(); | |
var string2 = Console.ReadLine(); | |
Console.WriteLine(ValidateString(string1, string2) == false ? "NO" : "YES"); | |
} | |
} | |
static bool ValidateString(string str1, string str2) | |
{ | |
Dictionary<int,char> dex = new Dictionary<int,char>(); | |
int count = 0; | |
foreach (char i in str1) | |
{ | |
if (!dex.ContainsValue(i)) | |
dex.Add(count, i); | |
count++; | |
} | |
var returnValue = false; | |
foreach (char i in str2) | |
{ | |
returnValue = dex.ContainsValue(i); | |
if (returnValue) | |
return returnValue; | |
} | |
return returnValue ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment