Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 25, 2016 05:50
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/9c61868800a9835347ffc1047960ea08 to your computer and use it in GitHub Desktop.
Save jianminchen/9c61868800a9835347ffc1047960ea08 to your computer and use it in GitHub Desktop.
string construction - HackerRank - world codesprint #5 score 25/25 easy question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stringConstruction
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
for (int a0 = 0; a0 < n; a0++)
{
string s = Console.ReadLine();
Console.WriteLine(getNo(s));
}
}
public static int getNo(string s)
{
if (s == null || s.Length == 0)
return 0;
string arr = "abcdefghijklmnopqrstuvwxyz";
int TOTAL = 26;
bool[] found = new bool[TOTAL];
int count = 0;
char[] aA = arr.ToArray();
for(int i = 0; i < s.Length; i++)
{
int index = s[i] - 'a';
if(!found[index])
{
found[index] = true;
count++;
}
if (count == TOTAL)
break;
}
return count;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment