上一页 1 ··· 4 5 6 7 8 9 10 下一页
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.---/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * ... 阅读全文
posted @ 2013-09-10 00:11 LEDYC 阅读(74) 评论(0) 推荐(0)
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".---public class Solution { public String addBinary(String a, String b) { // convert to int if(a == null || b == null) return null; int x = 0; for(int i=... 阅读全文
posted @ 2013-09-10 00:01 LEDYC 阅读(95) 评论(0) 推荐(0)
摘要: Implement pow(x,n).---Recursivedivide-and-conquer approachO(lgn)---public class Solution { double pow(double x, int n) { if (n == 0) return 1.0; // Compute x^{n/2} and store the result into a temporary // variable to avoid unnecessary computing double half = pow(x,... 阅读全文
posted @ 2013-09-07 05:01 LEDYC 阅读(125) 评论(0) 推荐(0)
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.---public class Solution { public ArrayList anagrams(String[] strs) { ArrayList rst = new ArrayList(); HashMap> map = new HashMap>(); for (String s : strs)... 阅读全文
posted @ 2013-09-07 04:54 LEDYC 阅读(133) 评论(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?---public class Solution { public void rotate(int[][] matrix) { if(matrix == null) return; if(matrix.length != matrix[0].length) return; ... 阅读全文
posted @ 2013-09-07 04:41 LEDYC 阅读(147) 评论(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].---sort arraycheck duplicationrecursive---public class Solution { public ArrayList> permuteUnique(int[] num).. 阅读全文
posted @ 2013-09-07 03:36 LEDYC 阅读(145) 评论(0) 推荐(0)
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of 阅读全文
posted @ 2013-09-06 02:11 LEDYC 阅读(174) 评论(0) 推荐(0)
摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.---09/21, Review顺序,最高位是0要去掉public class Solution { public String multiply(String num1, String num2) { if (num1.equals("0") || num... 阅读全文
posted @ 2013-09-06 01:36 LEDYC 阅读(161) 评论(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 @ 2013-09-06 01:16 LEDYC 阅读(148) 评论(0) 推荐(0)
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].---参考cc150 9.5O(N!) N factorial---1. Interationpublic class Solution { public ArrayList> permute(int[] num) { Array... 阅读全文
posted @ 2013-09-06 00:46 LEDYC 阅读(156) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 下一页