随笔分类 -  Leetcode

摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2014-11-13 03:45 Phoebe815 阅读(162) 评论(0) 推荐(0)
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文
posted @ 2014-11-13 02:39 Phoebe815 阅读(213) 评论(0) 推荐(0)
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated num... 阅读全文
posted @ 2014-11-13 02:14 Phoebe815 阅读(165) 评论(0) 推荐(0)
摘要:Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].Solution: 1 /*... 阅读全文
posted @ 2014-11-13 01:36 Phoebe815 阅读(152) 评论(0) 推荐(0)
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2014-11-12 16:05 Phoebe815 阅读(161) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number... 阅读全文
posted @ 2014-11-12 13:47 Phoebe815 阅读(134) 评论(0) 推荐(0)
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Solution: 1 /** 2 * Definition for a point. 3 * cla... 阅读全文
posted @ 2014-11-12 09:43 Phoebe815 阅读(144) 评论(0) 推荐(0)
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ... 阅读全文
posted @ 2014-11-10 15:42 Phoebe815 阅读(174) 评论(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.Solution: 1 public class Solution... 阅读全文
posted @ 2014-11-10 05:54 Phoebe815 阅读(121) 评论(0) 推荐(0)
摘要:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(... 阅读全文
posted @ 2014-11-02 10:42 Phoebe815 阅读(154) 评论(0) 推荐(0)
摘要:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]... 阅读全文
posted @ 2014-11-02 04:59 Phoebe815 阅读(113) 评论(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 (size that is greater or equal... 阅读全文
posted @ 2014-11-02 04:19 Phoebe815 阅读(92) 评论(0) 推荐(0)
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文
posted @ 2014-11-02 03:51 Phoebe815 阅读(157) 评论(0) 推荐(0)
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2014-11-02 02:59 Phoebe815 阅读(130) 评论(0) 推荐(0)
摘要:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation... 阅读全文
posted @ 2014-11-01 16:13 Phoebe815 阅读(132) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2014-11-01 08:21 Phoebe815 阅读(129) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... 阅读全文
posted @ 2014-11-01 01:02 Phoebe815 阅读(144) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2014-11-01 00:59 Phoebe815 阅读(211) 评论(0) 推荐(0)
摘要:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文
posted @ 2014-11-01 00:56 Phoebe815 阅读(202) 评论(0) 推荐(0)
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-10-31 15:04 Phoebe815 阅读(125) 评论(0) 推荐(0)