-
Notifications
You must be signed in to change notification settings - Fork 858
/
GameOfThronesI.java
41 lines (37 loc) · 850 Bytes
/
GameOfThronesI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
* Problem Statement-
* [Game of Thrones - I](https://www.hackerrank.com/challenges/game-of-thrones/problem)
*
*/
package com.javaaid.hackerrank.solutions.algorithms.strings;
import java.util.Scanner;
/**
* @author Kanahaiya Gupta
*
*/
public class GameOfThronesI {
static String gameOfThrones(String s) {
int a[] = new int[26];
for (int i = 0; i < s.length(); i++) {
int index = s.charAt(i) - 'a';
a[index]++;
}
int oddCount = 0;
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
if ((a[i] & 1) == 1) {
oddCount++;
}
}
}
return oddCount > 1 ? "NO" : "YES";
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
String result = gameOfThrones(s);
System.out.println(result);
in.close();
}
}