上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".StringBuilder + reverse methodpublic class Solution { public String addBinary(String a, String b) { if(a == null || a.equals("")) return b; if(b == null || b 阅读全文
posted @ 2014-01-31 04:02 Razer.Lu 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:建Hashtable,用排序过的string作为key,它的anagram作为ArrayList题目的意思是给一个String数组,找出其中由相同字母组成的单词。例如:S = ["abc", "bca", "bac", "bbb", "bbca", "abc 阅读全文
posted @ 2014-01-31 03:43 Razer.Lu 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 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正确的解出来方法是用二维的dp。假如我们要将字符串str1变成str2,sstr1(i)是s 阅读全文
posted @ 2014-01-31 02:56 Razer.Lu 阅读(272) 评论(0) 推荐(0) 编辑
摘要: http://blog.csdn.net/twtsa/article/details/8120269http://blog.csdn.net/sunjilong/article/details/8254108public class Solution { public int maximalRectangle(char[][] matrix) { if(matrix.length=0;j--){ // 如果遍历元素为'1',right[j]取R和right[j]中的最小值 if(matrix[i][j]=='1')... 阅读全文
posted @ 2014-01-31 01:21 Razer.Lu 阅读(349) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { v... 阅读全文
posted @ 2014-01-29 09:11 Razer.Lu 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed./* 阅读全文
posted @ 2014-01-29 09:08 Razer.Lu 阅读(274) 评论(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].Analysis:The idea of this classic problem is to use backtracking.We want to get permutations, which is mainly about swap values in th 阅读全文
posted @ 2014-01-29 08:57 Razer.Lu 阅读(297) 评论(0) 推荐(0) 编辑
摘要: Permutation SequenceThe 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 thekthperm 阅读全文
posted @ 2014-01-29 07:48 Razer.Lu 阅读(401) 评论(1) 推荐(0) 编辑
摘要: Implementint sqrt(int x).Compute and return the square root ofx.public class Solution { public int sqrt(int x) { int start = 0; int end = x; if(x == 0 || x == 1) return x; while(start x/m){ end = m -1; }else{ s... 阅读全文
posted @ 2014-01-28 16:30 Razer.Lu 阅读(104) 评论(0) 推荐(0) 编辑
摘要: Search in Rotated Sorted Array ||Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array 阅读全文
posted @ 2014-01-28 16:28 Razer.Lu 阅读(183) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页