摘要: Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring.参考:水中的鱼: [LeetCode]Longest Palindromic Substring解题报告定义函数P[i,j] = 字符串区间[i,j]是否为palindrome.首先找个例子,比如S="abccb", S= a b c c 阅读全文
posted @ 2014-02-08 03:32 Razer.Lu 阅读(288) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0参考 :http://www.cnb 阅读全文
posted @ 2014-02-08 03:09 Razer.Lu 阅读(231) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.解题思路 : 建立 fake noed 加在head 前面。cur = head; 比较cur 和 cur 阅读全文
posted @ 2014-02-08 02:57 Razer.Lu 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, 3, ... 阅读全文
posted @ 2014-02-08 02:17 Razer.Lu 阅读(173) 评论(0) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?参考:水中的鱼: [LeetCode]Rotate Image解题报告[解题思路]如下图,首先沿逆对角线翻转一次,然后按x轴中线翻转一次。 1 public class Solution { 2 public void rotate(int[][] matrix) { 3 if(matrix.length == ... 阅读全文
posted @ 2014-02-08 01:37 Razer.Lu 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].参考:水中的鱼: [LeetCode]Permutations II解题报告[解题思路]跟 Permutations的解法一样,就是要考虑“去重”。先对数组进行排序,这样在DFS的时候,可以先判断前面的一个数是否和自己相等,相 阅读全文
posted @ 2014-02-08 01:11 Razer.Lu 阅读(226) 评论(0) 推荐(0) 编辑