leetCode练习(5)
2016-09-15 11:24
323 查看
题目:Longest Palindromic Substring
难度:medium
问题描述:
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of
S is 1000, and there exists one unique longest palindromic substring.
解题思路:
从第[I]个字符开始,依次向两边比较是否相等即可。注意奇数回文数和偶数回文数的比较有差池。代码如下:
难度:medium
问题描述:
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of
S is 1000, and there exists one unique longest palindromic substring.
解题思路:
从第[I]个字符开始,依次向两边比较是否相等即可。注意奇数回文数和偶数回文数的比较有差池。代码如下:
public class Solution { public String longestPalindrome(String s) { if(s==null){ return ""; } if(s.length()==1){ return s; } int len=s.length(); char[] reverse={}; int stringlen=0; char[] cs=new char[len]; for(int i=0;i
相关文章推荐
- leetCode练习(48)
- LeetCode Online Judge 题目C# 练习 - Rotate Image
- LeetCode Online Judge 题目C# 练习 - Sort Color
- LeetCode Online Judge 题目C# 练习 - Unique Paths
- 数据结构与算法 LeetCode编程练习--Delete Node in a Linked List
- leetcode练习 add two numbers
- Leetcode__链表练习
- leetCode练习(60)
- leetcode练习 Delete and Earn
- 通过一道leetcode练习switch case
- 『LeetCode』练习第四弹_算法6题
- leetcode练习
- Leetcode编程练习:火柴匹配
- Leetcode练习-Best Time to Buy and Sell Stock II
- leetCode练习(2)
- leetCode练习(92)
- Leetcode练习- Symmetric Tree
- 【leetcode】sql练习
- 数据结构与算法-LeetCode练习二分查找应用
- leetCode练习(101)