摘要:题目: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...
阅读全文
摘要:题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the ...
阅读全文
摘要:题目:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints ...
阅读全文
摘要:题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters...
阅读全文
摘要:题目:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complet...
阅读全文
摘要:题目:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction ...
阅读全文
摘要:题目: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 max...
阅读全文
摘要:题目: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 max...
阅读全文
摘要:题目:Implementint sqrt(int x).Compute and return the square root ofx.代码:class Solution {public: int mySqrt(int x) { if (x mid )...
阅读全文
摘要:题目:Implement pow(x,n).代码:class Solution {public: double myPow(double x, int n) { double ret = Solution::positivePow(fabs(x), ...
阅读全文
摘要:题目: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 "adj...
阅读全文
摘要:题目:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be...
阅读全文
摘要:题目:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"(((...
阅读全文
摘要:题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each numb...
阅读全文
摘要:题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated ...
阅读全文
摘要:题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["25...
阅读全文
摘要:题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.代码:class Solution {publi...
阅读全文
摘要:题目:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all dist...
阅读全文
摘要:题目: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 spac...
阅读全文
摘要:题目: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 poi...
阅读全文
摘要:题目:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, ...
阅读全文
摘要:题目:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded reg...
阅读全文
摘要:题目:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be chan...
阅读全文
摘要:题目:Given two words (beginWordandendWord), and a dictionary, find the length of shortest transformation sequence frombeginWordtoendWord, such that:Only...
阅读全文
摘要:题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telep...
阅读全文
摘要:题目: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,...
阅读全文
摘要:题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique p...
阅读全文
摘要:题目: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],...
阅读全文
摘要:题目:Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note:Elements in a subset must be in non-descending ...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted fro...
阅读全文
摘要:题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in...
阅读全文
摘要:题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ...
阅读全文
摘要:题目: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,...
阅读全文
摘要:题目:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should...
阅读全文
摘要:题目:Sort a linked list inO(nlogn) time using constant space complexity.代码:/** * Definition for singly-linked list. * struct ListNode { * int val; *...
阅读全文
摘要:题目:Sort a linked list using insertion sort.代码:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ...
阅读全文
摘要:题目:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.代码:/** * Definition for singly-linked list. * struc...
阅读全文
摘要:题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.代码:/**...
阅读全文
摘要:题目:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is gr...
阅读全文
摘要:题目:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which ...
阅读全文
摘要:题目:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
阅读全文
摘要:题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsu...
阅读全文
摘要:题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest...
阅读全文
摘要:题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.代码:/** * Definition for singly-linked ...
阅读全文
摘要:题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.代码:/** * Definition for a binary tree node. * stru...
阅读全文
摘要:题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains onl...
阅读全文
摘要:题目:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 ...
阅读全文
摘要:题目: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. ...
阅读全文
摘要:题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.代码:/** * De...
阅读全文
摘要:题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.代码:/** * Def...
阅读全文
摘要:题目:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution s...
阅读全文
摘要:题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattene...
阅读全文
摘要:题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / ...
阅读全文
摘要:题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical...
阅读全文
摘要:题目:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space ...
阅读全文
摘要:题目:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目: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,...
阅读全文
摘要:题目:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1]...
阅读全文
摘要:题目:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].N...
阅读全文
摘要:题目:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]....
阅读全文
摘要:刷题进入到二叉树这个章节,开篇随笔记录下二叉树相关的内容:二叉树的各种遍历和操作:http://blog.csdn.net/fansongy/article/details/6798278二叉搜索树(BST)的插入、查找、删除:http://segmentfault.com/a/1190000002...
阅读全文
摘要:题目:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expr...
阅读全文
摘要:题目: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 his...
阅读全文
摘要:题目:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the long...
阅读全文
摘要:题目:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the corre...
阅读全文
摘要:题目:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word ...
阅读全文
摘要:题目:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner ...
阅读全文
摘要:题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.代码:class Solution {public: vect...
阅读全文
摘要:题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as...
阅读全文
摘要:题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.代码:class Solution {public: int romanTo...
阅读全文
摘要:题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.代码:class Solution {public: string intT...
阅读全文
摘要:题目:Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem s...
阅读全文
摘要:题目:Write a function to find the longest common prefix string amongst an array of strings.代码:class Solution {public: string longestCommonPrefix(vect...
阅读全文
摘要:题目:Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including th...
阅读全文
摘要:题目:Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element....
阅读全文
摘要:题目:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest...
阅读全文
摘要:题目:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".代码:class Solution {public: string addBina...
阅读全文
摘要:题目:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below a...
阅读全文
摘要:题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The...
阅读全文
摘要:题目:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: P...
阅读全文
摘要:题目:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the v...
阅读全文
摘要:题目:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For e...
阅读全文