Created
July 25, 2016 05:50
-
-
Save jianminchen/9c61868800a9835347ffc1047960ea08 to your computer and use it in GitHub Desktop.
string construction - HackerRank - world codesprint #5 score 25/25 easy question
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 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