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();
}
}

最新文章

  1. chrome调试
  2. javascript中的true和false
  3. PHP创建缩略图造成图片质量低下的完美解决方法
  4. boost编译批处理脚本
  5. 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon
  6. 单机/伪分布式Hadoop2.4.1安装文档
  7. html常用标签有哪些
  8. 【jar包】图片的异步加载--【 Imageloader】
  9. jquery对象和js对象
  10. STL常用整理
  11. atool-build 打包项目报JavaScript heap out of memory 错误
  12. LeetCode 15 输入无序、有重复,输出排重版 3-Sum
  13. 【javascript】原生js更改css样式的两种方式
  14. 错误 error C2678: 二进制“&lt;”: 没有找到接受“const card”类型的左操作数的运算符(或没有可接受的转换)
  15. JavaWeb总结(十)
  16. 【转】楼天城楼教主的acm心路历程(作为励志用)
  17. Innodb和Mysiam引擎的区别
  18. SSM整合Redis
  19. 【MATLAB】读取和写入文本文件
  20. Hibernate入门(4)- Hibernate数据操作

热门文章

  1. request.getParameterValues()用法
  2. 第一百七十节,jQuery,事件对象,event 对象,默认行为,冒泡
  3. 浅谈IM软件怎样建立安全socket连接、登录
  4. linux系统启动过程具体解释-开机加电后发生了什么 --linux内核剖析(零)
  5. struts2之constant 讲解 (转)
  6. win10输入法设置
  7. MySQL的下载及安装
  8. JAVA学习第六十三课 — 关于client服务端 &amp;amp;&amp;amp; URL类 &amp;amp; URLConnection
  9. 获取当前AppDelegate 正在显示的UIViewController
  10. Python 邮箱