上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页
摘要: 给定输入字符串,要求判断任意子字符串是否对称。基本思路就是DP写出DP表达式为 dp[i][j] = dp[i + 1][j - 1] && (s[i] == s[j]) dp[i][j]代表s(i,j)的子串是否对称注意在for循环赋值时,这里增长的对象其实是子串的长度。长度为奇数时:(->... 阅读全文
posted @ 2015-11-03 11:02 树獭君 阅读(270) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Solution这一题思路并不难。要满足follow-u... 阅读全文
posted @ 2015-11-03 07:49 树獭君 阅读(214) 评论(0) 推荐(0) 编辑
摘要: Question Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return a 阅读全文
posted @ 2015-11-02 03:28 树獭君 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Access: Random / Sequential1. Array element can be randomly accessed using index2. Random access for element of linked list costs O(n) time3. Generall... 阅读全文
posted @ 2015-10-30 02:17 树獭君 阅读(209) 评论(0) 推荐(0) 编辑
摘要: QuestionReverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5-... 阅读全文
posted @ 2015-10-28 22:08 树獭君 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Question1 1 1 1 1 01 0 1 0 0 11 0 1 0 0 11 1 0 1 1 11 is earth, 0 is water.i) count the number of 'islands' that the matrix has.ii) count the number o... 阅读全文
posted @ 2015-10-28 09:52 树獭君 阅读(177) 评论(0) 推荐(0) 编辑
摘要: QuestionImplementint sqrt(int x).Compute and return the square root ofx.Solution 1 -- O(log n)常规做法是用的binary search。注意这里mid一定要是long类型,否则mid * mid会溢出。 1... 阅读全文
posted @ 2015-10-28 08:37 树獭君 阅读(271) 评论(0) 推荐(0) 编辑
摘要: QuestionMedian is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of... 阅读全文
posted @ 2015-10-28 03:27 树獭君 阅读(253) 评论(0) 推荐(0) 编辑
摘要: QuestionGiven an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) spac... 阅读全文
posted @ 2015-10-27 22:02 树獭君 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Two methods:1. Traverse2. Divide & Conquer 1 // Traverse: usually do not have return value 2 public class Solution { 3 public void traverse(TreeNo... 阅读全文
posted @ 2015-10-26 00:41 树獭君 阅读(123) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 22 下一页