摘要:
Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文
posted @ 2016-01-06 16:10
西小贝
阅读(144)
评论(0)
推荐(0)
摘要:
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2016-01-06 16:09
西小贝
阅读(188)
评论(0)
推荐(0)
摘要:
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2016-01-06 16:09
西小贝
阅读(149)
评论(0)
推荐(0)
摘要:
Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note:Elements in a subset must be in non-descending ord... 阅读全文
posted @ 2016-01-06 16:07
西小贝
阅读(187)
评论(0)
推荐(0)
摘要:
A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2016-01-06 16:07
西小贝
阅读(201)
评论(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 @ 2016-01-06 16:06
西小贝
阅读(155)
评论(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 origi... 阅读全文
posted @ 2016-01-06 16:05
西小贝
阅读(125)
评论(0)
推荐(0)
摘要:
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2016-01-06 16:04
西小贝
阅读(112)
评论(0)
推荐(0)
摘要:
Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to... 阅读全文
posted @ 2016-01-06 16:03
西小贝
阅读(99)
评论(0)
推荐(0)
摘要:
Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted arraynums=[1,1,1,2,2,3],Your function should re... 阅读全文
posted @ 2016-01-06 16:02
西小贝
阅读(99)
评论(0)
推荐(0)
摘要:
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjace... 阅读全文
posted @ 2016-01-06 16:00
西小贝
阅读(132)
评论(0)
推荐(0)
摘要:
Given a set of distinct integers,nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not... 阅读全文
posted @ 2016-01-06 15:59
西小贝
阅读(125)
评论(0)
推荐(0)
摘要:
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 @ 2016-01-06 15:57
西小贝
阅读(139)
评论(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 @ 2016-01-06 15:56
西小贝
阅读(112)
评论(0)
推荐(0)
摘要:
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2016-01-06 15:55
西小贝
阅读(196)
评论(0)
推荐(0)
摘要:
Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution... 阅读全文
posted @ 2016-01-06 15:54
西小贝
阅读(141)
评论(0)
推荐(0)
摘要:
Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"Corner Cases:Did you con... 阅读全文
posted @ 2016-01-06 15:52
西小贝
阅读(148)
评论(0)
推荐(0)
摘要:
Implementint sqrt(int x).Compute and return the square root ofx. 1 class Solution {//二分 2 public: 3 int mySqrt(int x) { 4 if(x<=1) 5 ... 阅读全文
posted @ 2016-01-06 15:50
西小贝
阅读(150)
评论(0)
推荐(0)
摘要:
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2016-01-06 15:48
西小贝
阅读(120)
评论(0)
推荐(0)
摘要:
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2016-01-06 15:46
西小贝
阅读(162)
评论(0)
推荐(0)
摘要:
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文
posted @ 2016-01-06 15:46
西小贝
阅读(147)
评论(0)
推荐(0)
摘要:
Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL. 1 /*... 阅读全文
posted @ 2016-01-06 15:44
西小贝
阅读(160)
评论(0)
推荐(0)
摘要:
The 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... 阅读全文
posted @ 2016-01-06 15:43
西小贝
阅读(154)
评论(0)
推荐(0)
摘要:
Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri... 阅读全文
posted @ 2016-01-06 15:42
西小贝
阅读(131)
评论(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 maximu... 阅读全文
posted @ 2016-01-06 15:41
西小贝
阅读(119)
评论(0)
推荐(0)
摘要:
Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ],... 阅读全文
posted @ 2016-01-06 15:40
西小贝
阅读(134)
评论(0)
推荐(0)
摘要:
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,... 阅读全文
posted @ 2016-01-06 15:38
西小贝
阅读(121)
评论(0)
推荐(0)
摘要:
Implement pow(x,n). 1 class Solution { 2 public: 3 double myPow(double x, int n) { 4 if(n>=1;20 x*=x;21 }22 23... 阅读全文
posted @ 2016-01-06 15:37
西小贝
阅读(168)
评论(0)
推荐(0)
摘要:
Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["na... 阅读全文
posted @ 2016-01-06 15:31
西小贝
阅读(139)
评论(0)
推荐(0)
摘要:
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 t... 阅读全文
posted @ 2016-01-06 15:29
西小贝
阅读(123)
评论(0)
推荐(0)
摘要:
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文
posted @ 2016-01-06 15:10
西小贝
阅读(137)
评论(0)
推荐(0)
摘要:
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 ... 阅读全文
posted @ 2016-01-06 15:05
西小贝
阅读(147)
评论(0)
推荐(0)

浙公网安备 33010602011771号