Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 06:07
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/95b701e6d2146da13c1d to your computer and use it in GitHub Desktop.
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
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