上一页 1 ··· 3 4 5 6 7 8 9 10 下一页
摘要: Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character---public class Solution { public int minDi... 阅读全文
posted @ 2013-09-11 22:16 LEDYC 阅读(133) 评论(0) 推荐(0)
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cases.---stack---public class Solution { public String simplifyPath(String path) { if (path == null || path 阅读全文
posted @ 2013-09-11 22:05 LEDYC 阅读(153) 评论(0) 推荐(0)
摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?---map[n+1]!!!(0-n), length = n+1public class Solution { public int climbStairs(int n) { int[] map = new int[n+1]; ... 阅读全文
posted @ 2013-09-11 10:40 LEDYC 阅读(127) 评论(0) 推荐(0)
摘要: Implementint sqrt(int x).Compute and return the square root ofx.---BST---public static int helper(int x, int l, int r) { if (l x || l > r) return Math.min(l, r); // x=2, rst=1, x=8, rst=2; int mid = l + (r - l) / 2; if (x / mid == mid) return mid; else if (x /... 阅读全文
posted @ 2013-09-11 10:30 LEDYC 阅读(150) 评论(0) 推荐(0)
摘要: Given a number represented as an array of digits, plus one to the number.---return Arrays.copyOfRange(rst, 1, n+1);---public class Solution { public int[] plusOne(int[] digits) { int n = digits.length; int[] rst = new int[n+1]; int carry = 1; for(int i=... 阅读全文
posted @ 2013-09-11 09:33 LEDYC 阅读(119) 评论(0) 推荐(0)
摘要: The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, return thekthpermutation sequence.Not 阅读全文
posted @ 2013-09-10 02:00 LEDYC 阅读(99) 评论(0) 推荐(0)
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.---/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = 阅读全文
posted @ 2013-09-10 01:41 LEDYC 阅读(131) 评论(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 @ 2013-09-10 01:36 LEDYC 阅读(127) 评论(0) 推荐(0)
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文
posted @ 2013-09-10 00:50 LEDYC 阅读(147) 评论(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 !!!---1. basic 二维数组注意i=0, j=0,其他min[i][j] = Math.min(min[i][j-1], min[i-1][j]) + grid[ 阅读全文
posted @ 2013-09-10 00:25 LEDYC 阅读(176) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 下一页