摘要:
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)
浙公网安备 33010602011771号