这道题主要是有三个变量。因为要确定一个substring,就有start point和end point,这组成了两个变量。然后其次,我们至少对每个substring从头到尾loop一遍,来确定这个substring是不是palindrome,这又需要一个n。所以,如果用暴力解法的话,这道题的tim ...
分类:
其他好文 时间:
2018-11-12 11:25:52
阅读次数:
126
两种方法: 先sort,再找。time complexity: O(nlogn)如果用array记录次数,space complexity是O(n)。如果只用int来记录current length以及longest length, space complexity 是O(1) 用hashset。T ...
分类:
其他好文 时间:
2018-11-10 15:29:52
阅读次数:
116
Sliding window Hashset Loop through every element inside the string. If the current char is not inside the hashset, push the char into the hashset and ...
分类:
其他好文 时间:
2018-11-10 15:04:19
阅读次数:
189
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest le ...
分类:
其他好文 时间:
2018-11-10 10:51:42
阅读次数:
147
这个题主要考察对树的操作,主要思想是DFS或者BFS,其次是找树的直径方法(既要运用两次BFS/DFS),最后作为小白,还练习了vector的操作。 DFS框架伪码: vector的操作: 大意是给一个树,每个边的权重已知,求树的直径。 After a long time of algorithm ...
分类:
其他好文 时间:
2018-11-09 23:24:49
阅读次数:
219
题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of $n$ DNA samples, where each sample is a string containing characters from {A, C, G, T}, ...
分类:
其他好文 时间:
2018-11-09 22:56:18
阅读次数:
288
题目链接:http://poj.org/problem?id=3764 Time Limit: 2000MS Memory Limit: 65536K Description In an edge-weighted tree, the xor-length of a path p is define ...
分类:
其他好文 时间:
2018-11-09 00:48:00
阅读次数:
204
https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix/solution/ Given a 01 matrix M, find the longest line of consecutive one in the... ...
分类:
其他好文 时间:
2018-11-08 18:32:34
阅读次数:
216
题目: 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为1000。 示例 1: 输入: "babad" 输出: "bab" 注意: "aba"也是一个有效答案。 示例 2: 输入: "cbbd" 输出: "bb" 题目: 给定一个字符串 s,找到 s 中最长的回文子串。你 ...
分类:
其他好文 时间:
2018-11-07 20:08:20
阅读次数:
159
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Examp... ...
分类:
其他好文 时间:
2018-11-06 11:23:22
阅读次数:
183