King Robert has 7 kingdoms under his rule. He gets to know from a raven that the Dothraki are going to wage a war against him soon. But, he knows the Dothraki need to cross the narrow river to enter his dynasty. There is only one bridge that connects both sides of the river which is sealed by a huge door.

The king wants to lock the door, so that, the Dothraki can't enter. But, to lock the door he needs a key that is an anagram of a certain palindrome string.

The king has a list of words. Help him figure out if any anagram of the words can be a palindrome or not?

Input Format
A single line which contains the input string

Constraints
1<=length of string <= 10^5
Each character of the string is a lowercase english letter.

Output Format
A single line which contains YES/NO in capital letter of english alphabet.


题解:一个字符串能够通过变换变成一个回文串的充要条件是它里面最多有一种字母,在字符串里面出现的次数是奇数,其他种的字符在字符串里面出现的次数都是偶数。

 import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*; public class Solution { static String GameOfThronesI(String a){
int[] count = new int[26];
for(int i =0;i < a.length();i++)
count[a.charAt(i)-'a']++;
int isOdd = 0;
for(int i = 0;i < 26;i++)
if(count[i]%2 != 0)
isOdd++;
return isOdd <= 1?"YES":"NO";
}
public static void main(String[] args) {
Scanner myScan = new Scanner(System.in);
String inputString = myScan.nextLine(); // Assign ans a value of s or no, depending on whether or not inputString satisfies the required condition
System.out.println(GameOfThronesI(inputString));
myScan.close();
}
}

【HackerRank】 Game Of Thrones - I的更多相关文章

  1. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  2. 【HackerRank】Running Time of Quicksort

    题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...

  3. 【hackerrank】Week of Code 30

    Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...

  4. 【hackerrank】Week of Code 26

    在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...

  5. 【HackerRank】Median

    题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大 ...

  6. 【HackerRank】Coin on the Table

    题目链接:Coin on the Table 一开始想用DFS做的,做了好久都超时. 看了题解才明白要用动态规划. 设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的 ...

  7. 【HackerRank】Pairs

    题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...

  8. 【HackerRank】Cut the tree

    题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ...

  9. 【HackerRank】Missing Numbers

    Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very pr ...

随机推荐

  1. 使用nginx cache缓存网站数据实践

    Nginx本身就有缓存功能,能够缓存静态对象,比如图片.CSS.JS等内容直接缓存到本地,下次访问相同对象时,直接从缓存即可,无需访问后端静态服务器以及存储存储服务器,可以替代squid功能. 1   ...

  2. android自定义View_4——自定义属性的格式选择

    reference - if it references another resource id (e.g, "@color/my_color", "@layout/my ...

  3. poj 2516(拆点+最小权匹配)

    题目链接:http://poj.org/problem?id=2516 思路:考虑某种货物,由于某个订货商可能接受来自不同地区的货物,而某一地区的货物也可能送给不同的订货商,显然不能直接进行匹配,必须 ...

  4. ios --也是在B页面的生命周期设置如下代码。方法一是直接关闭和激活侧滑手势,方法二则是B遵循协议UIGestureRecognizerDelegate,设置侧滑交互代理,重写手势方法。

    @property (weak, nonatomic) id<UIGestureRecognizerDelegate> restoreInteractivePopGestureDelega ...

  5. java中訪问修饰符

    较之c++ 中 public,proctected, private 三种訪问控制, java多了默认訪问控制. java中四种訪问控制权限 简单描写叙述为一下四句: 1)private 仅本类可见 ...

  6. 大话DFT频谱分析(并不是我的话)

    有限长信号DFT结果的频谱泄露 提出问题 依照我们在"信号与系统"这门课建立的印象,不管如何频率的连续正弦信号,其频谱应当是两根笔直的谱线(含负频率) 但是,当我们把一段正弦信号採 ...

  7. 在程序内部使用winGraphviz进行图形自动布局

    winGraphviz支持內部圖形形狀進行佈局圖輸出.當然,在我們程序內部並不需要這樣的一個圖,因為我們的圖可能需要其它的繪製元素,而且我們還會在圖形上進行拖動.放大.縮小等功能,一張簡單的佈局圖是不 ...

  8. Android无线测试之—Genymotion配置过程中常见问题

    一.前提条件: 已经部署好了Android UiAutomator测试环境. 二.在部署Genymotion时遇到了两类问题: 1.通过eclipse打开一个模拟设备,然后将编译好的jar包push到 ...

  9. Win7 maven安装及配置

    1. 前期准备 ① jdk 1.8 ② maven 3.5.4 下载地址:http://maven.apache.org/download.cgi 2. 配置maven环境变量 ① maven解压到指 ...

  10. 《从零开始学Swift》学习笔记(Day 53)——do-try-catch错误处理模式

    原创文章,欢迎转载.转载请注明:关东升的博客 Swift 1.x的错误处理模式存在很多弊端,例如:为了在编程时候省事,给error参数传递一个nil,或者方法调用完成后不去判断error是否为nil, ...