上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页
摘要: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5].相当于一圈一圈的剥掉矩阵,剥掉一圈,row-2, col-2 1 public class Solution { 2 public ArrayList spiralO... 阅读全文
posted @ 2014-02-11 14:05 Razer.Lu 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑
摘要: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.跟N-Queens 一个解发 最后return result.size()public class Solution{ public ArrayList solveNQueens(int n) { ArrayList result = new ArrayList(); int[] queenList = new... 阅读全文
posted @ 2014-02-07 07:54 Razer.Lu 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文
posted @ 2014-02-07 03:58 Razer.Lu 阅读(223) 评论(0) 推荐(0) 编辑
摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.二维DP。设数组A[row][col],Min[i][j] = min(Min[i-1][j], Min[i][j-1]) +A[i][j];注意初始条件即可。public class 阅读全文
posted @ 2014-02-07 03:33 Razer.Lu 阅读(154) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页