Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 07:02
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/10ece1c63d85e6ae3e12 to your computer and use it in GitHub Desktop.
Save jianminchen/10ece1c63d85e6ae3e12 to your computer and use it in GitHub Desktop.
Gem Stones - Less space solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GemStone2
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int n = Convert.ToInt16(s);
string[] sA = new string[n];
for (int i = 0; i < n; i++)
{
sA[i] = Console.ReadLine();
}
Console.WriteLine(getNumberOfGemElement(sA));
}
/*
* string length >=1, <=100
* only lower-cse Latin letters 'a'-'z'
*
* string array size 1 - 100
*/
public static int getNumberOfGemElement(string[] s)
{
int len = s.Length;
int[] sumA = new int[26];
for (int i = 0; i < len; i++)
{
string s1 = s[i];
// do not add same char twice
string countIn = "";
foreach (char c in s1)
{
if (!countIn.Contains(c.ToString()))
{
sumA[c - 'a']++;
countIn += c.ToString();
}
}
}
int number = 0;
for (int i = 0; i < 26; i++)
{
if (sumA[i] == len)
number++;
}
return number;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment