Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 05:00
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/6bf133d5c42e18260410 to your computer and use it in GitHub Desktop.
Save jianminchen/6bf133d5c42e18260410 to your computer and use it in GitHub Desktop.
HackerRank: Game Throne - code to study - March 12, 2016
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Solution {
static bool isOdd(int n) {
return 0 != (n % 2);
}
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
string word = Console.ReadLine();
Dictionary<char,int> letterCounts = new Dictionary<char,int>();
foreach (char letter in word.Distinct()) {
letterCounts[letter] = word.Count(c => letter == c);
}
int oddCount = letterCounts.Values.Count(isOdd);
if (oddCount <= 1) {
Console.Write("YES");
} else {
Console.Write("NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment