[抄题]:

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.

This is case sensitive, for example "Aa" is not considered a palindrome here.

Note:
Assume the length of given string will not exceed 1,010.

Example:

Input:
"abccccdd" Output:
7 Explanation:
One longest palindrome that can be built is "dccaccd", whose length is 7.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

不知道多余了一些单独的字母时,应该怎么处理

[一句话思路]:

先处理成对的,单独的在结果处操作

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. 多想一些情况:最后剩余1个字母、多个字母,都是count * 2 + 1

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

先处理成对的,单独的在结果处操作

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

set-remove

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

class Solution {
public int longestPalindrome(String s) {
//cc
if (s.length() == 0) {
return 0;
} //ini:set
Set set = new HashSet();
int count = 0; //for loop: contains, count+1
for (char c : s.toCharArray()) {
if (! set.contains(c)) {
set.add(c);
}else {
set.remove(c);
count++;
}
} //res count * 2 + 1
if (set.size() != 0) {
return count * 2 + 1;
}else {
return count * 2;
} }
}

最新文章

  1. mybatis map常用数据类型
  2. android nfc中Ndef格式的读写
  3. VirtualBox虚拟机运行Ubuntu如何不卡
  4. jQuery对话框插件 ThickBox
  5. js 生成m位随机数入门实例
  6. 贝努利概率 matlab
  7. angular 页面加载时可以调用 函数处理
  8. (转)IIS设置优化(需根据服务器性能,调整具体参数值)
  9. 12 Useful “df” Commands to Check Disk Space in Linux
  10. hdu 1085
  11. JavaScript 一个等号 两个等号 三个等号的区别
  12. Linux下搭建Oracle11g RAC(2)----配置DNS服务器,确认SCAN IP可以被解析
  13. NSnotificationCenter 正确使用姿势, removeObject 探索
  14. ThinkPHP 关联模型(二十)
  15. PHP的几个常用加密函数【转载】
  16. 极化码的matlab仿真(2)——编码
  17. 土旦:关于display:flex碰上white-space nowrap 影响布局的问题
  18. Asp.Net Core Options模式的知识总结
  19. SOAR SQL进行优化和改写的自动化工具
  20. 史上最全的Spring Boot配置文件详解

热门文章

  1. 西交利物浦大学Java PAPER CODE: CSE105/12-13/S1/Resit Coursework
  2. test20181219(期末考试)
  3. 【转】IUSR和IIS_IUSRS
  4. C#结构体数组间的转化
  5. 3145 code[VS]汉诺塔游戏--递归
  6. 列表推导式,两个for循环的例子
  7. excel oracle字段命名(大写下划线分词)转 驼峰命名
  8. IT售前经验谈
  9. Java 数组的定义和遍历
  10. 常用JavaScript操作页面元素的方法