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