摘要: 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) 编辑
摘要: Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [0,1, 阅读全文
posted @ 2014-02-07 02:49 Razer.Lu 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minimum n 阅读全文
posted @ 2014-02-07 01:57 Razer.Lu 阅读(231) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse. 1 阅读全文
posted @ 2014-02-07 01:20 Razer.Lu 阅读(263) 评论(0) 推荐(0) 编辑