Game of Thrones - I

  • + 0 comments

    JAVA

    public static String gameOfThrones(String s) {
        // Write your code here
            int[] CHAR = new int[26];
            int oddCount = 0;
            for(int i=0;i<s.length();i++) {
                CHAR[s.charAt(i)-97]++; // ascii of a is 97
            }
            for(int i=0;i<26;i++){
                oddCount += CHAR[i]%2;
            }
            if(s.length()%2==0 && oddCount == 0) return "YES";
            if(s.length()%2!=0 && oddCount == 1) return "YES";
            return "NO";
        }