Created
March 13, 2016 05:00
-
-
Save jianminchen/6bf133d5c42e18260410 to your computer and use it in GitHub Desktop.
HackerRank: Game Throne - code to study - March 12, 2016
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.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