Created
March 13, 2016 07:02
-
-
Save jianminchen/10ece1c63d85e6ae3e12 to your computer and use it in GitHub Desktop.
Gem Stones - Less space solution
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; | |
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