627
来源:互联网 发布:大学生网络创业问题 编辑:程序博客网 时间:2024/05/24 06:19
5.15
利用map找到两个相同的字母,那么最后的长度就可以加2;
如果map最后不为空,那么最后再加一即可。
public class Solution { /** * @param s a string which consists of lowercase or uppercase letters * @return the length of the longest palindromes that can be built */ public int longestPalindrome(String s) { // Write your code here int length = s.length(); int count = 0; HashMap<Character,Integer> map = new HashMap<Character,Integer>(); for(int i = 0; i < length; i++){ if(!map.containsKey(s.charAt(i))){ map.put(s.charAt(i),1); } else if(map.get(s.charAt(i)) == 1){ map.remove(s.charAt(i)); count ++; } } count = count *2; if(!map.isEmpty()){ count ++; } return count; }}
0 0
- 627
- NEFU 627
- 627总结
- nefu 627 剪纸游戏
- 627 A codeforces
- CF 627E
- 627A.XOR Equation
- 【LeetCode】627、Swap Salary
- 627A - XOR Equation 数学
- CodeForces 627B Factory Repairs
- CodeForces 627A XOR Equation
- Codeforces 627A XOR Equation
- lintcode(627)最长回文串
- nefu 627 剪纸游戏(搜索)
- SRM 627 D2L3: BubbleSortWithReversals, dp, 冒泡排序
- Codeforces 627A XOR Equation 【数学】
- Codeforces 627B Factory Repairs 【线段树】
- Codeforces 627B Factory Repairs 线段树
- eclipse新建maven工程
- java中native的用法
- javaweb之监听器详解
- 【Linux】Supervisor快速使用教程
- POJ 1163 The Triangle 笔记
- 627
- 防范比特币病毒的脚本
- java 导出excel
- 35个Java代码性能优化总结
- Android-PromptDialog 提示框,苹果风格对话框android等待加载框
- Android之BroadcastReceiver解析
- dubbo 入门
- caffe简单运行所需的文件——lenet(CSDN-markdown编辑器试用)
- C++ 多线程、网络编程实时笔记(草)