上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 43 下一页
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Input: ["tea","and","ate","eat","den"]Output:["tea","ate","eat"]["",""]-------------> 阅读全文
posted @ 2013-08-07 15:00 feiling 阅读(1391) 评论(1) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?如下图,首先沿逆对角线翻转一次,然后按x轴中线翻转一次。 1 public void rotate(int[][] matrix) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 ... 阅读全文
posted @ 2013-08-07 13:27 feiling 阅读(231) 评论(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].解题思路:Permutations 那题输入是不包含重复元素的,故生成的排列都是不同的,II中输入元素可能相同因而可能会产生相同的排列,这里需要去重,没有找到很好的剪枝条件,这里使用HashSet来去重,当发现已经添加过该组合 阅读全文
posted @ 2013-08-07 10:49 feiling 阅读(382) 评论(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].求每个位置所有可能出现的情况:固定第一个字符,然后求后面所有字符的排列。这个时候仍把后面的所有字符分成两部分:后面字符的第一个字符,以及这个字符之后的所有字符 1 public class Solution { 2 public ArrayList> per. 阅读全文
posted @ 2013-08-07 09:58 feiling 阅读(292) 评论(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.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse.[解 阅读全文
posted @ 2013-08-06 20:43 feiling 阅读(261) 评论(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.大整数乘法,一位一位往上乘,注意进位的处理即可。此外,注意0的处理 1 public class Solution { 2 public String multiply(String num1, String num2) { 3 // Start typing yo... 阅读全文
posted @ 2013-08-05 23:02 feiling 阅读(383) 评论(0) 推荐(0) 编辑
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.从后往前遍历,减少移动次数。此题与替换字符串类似 1 public void merge(int A[], int m, int B[], int n) 阅读全文
posted @ 2013-08-05 20:54 feiling 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文
posted @ 2013-08-05 20:12 feiling 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 阅读全文
posted @ 2013-08-04 23:24 feiling 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文
posted @ 2013-08-04 21:10 feiling 阅读(229) 评论(0) 推荐(0) 编辑
上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 43 下一页