求一个字符串的最长回文子串。回文子串分为两种,一种是aba型的,一种是abba型的,因此两种情况都有考虑到。用一个循环,对字符串中的每一个字符作为中心进行判断,并记录下每个循环后的最长子串。时间复杂度为O(n*n)
之前写了一个程序可以运行,但是在leetcode中运行超时了。下面的是修改别人的程序,很精简。
{CSDN:CODE:578916}...
分类:
其他好文 时间:
2015-01-13 17:53:08
阅读次数:
166
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ...
分类:
其他好文 时间:
2015-01-13 15:45:26
阅读次数:
126
这一段一直忙考试,一直没有刷题,今天上来刷三道题感觉生疏起来了。。罪过啊。刷到今天了。。还是没有写算法的感觉,还是写代码太少了。java的用法又忘记了很多。java上手后就要开始写python了,反正现在就是没有写代码的感觉。题目:Longest Common Prefix通过率:26.5%难度:简...
分类:
其他好文 时间:
2015-01-13 13:51:15
阅读次数:
193
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest-palindromic-substring/Given a string S, find the ...
分类:
编程语言 时间:
2015-01-13 01:21:57
阅读次数:
285
求字符串中的最长无重复子串的长度,例如"abcabcbb",最长无重复子串为"abc",长度为3。因为要求无重复,因此想到要用HashMap来保存,因为HashMap的键值不能重复。将要存入的字符作为key,字符在字符串中的下标作为value,如果map中已经存有该字符,则删掉该字符以及字符串中该字符之前的所有字符,然后再存入。例如字符串为"abcbd",如已存入abc,现在要存b,则删掉ab,存...
分类:
其他好文 时间:
2015-01-12 11:38:25
阅读次数:
217
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/Given a st...
分类:
编程语言 时间:
2015-01-12 01:36:33
阅读次数:
255
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo...
分类:
其他好文 时间:
2015-01-11 22:58:44
阅读次数:
223
难点1,是栈,2是流程class Solution {public: int longestValidParentheses(string s) { stack mstack; char cbefore; int count = 0; if(s.empt...
分类:
其他好文 时间:
2015-01-11 12:14:33
阅读次数:
119
The problem 1:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to t...
分类:
其他好文 时间:
2015-01-11 06:07:49
阅读次数:
216
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The longes...
分类:
其他好文 时间:
2015-01-09 22:08:16
阅读次数:
178