04 2015 档案
摘要:题目: Given a singly linked list L: 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.
阅读全文
摘要:题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up:Can you solve it without using extra spa
阅读全文
摘要:题目: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 链接: http://leetcode.com/problems/lin
阅读全文
摘要:题目:Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such poss...
阅读全文
摘要:题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
阅读全文
摘要:题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep co...
阅读全文
摘要:题目: Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runti
阅读全文
摘要:题目: Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime com
阅读全文
摘要:题目: There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the followin
阅读全文
摘要:题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it
阅读全文
摘要:题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are lab
阅读全文
摘要:题目:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ...
阅读全文
摘要:题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For ex
阅读全文
摘要:题目: 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 surrou
阅读全文
摘要:题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3
阅读全文
摘要:题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The lo
阅读全文
摘要:题目: Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWo
阅读全文
摘要:题目:Given two words (beginWordandendWord), and a dictionary's word list, find all shortest transformation sequence(s) frombeginWordtoendWord, such that...
阅读全文
摘要:题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal:
阅读全文
摘要:题目:Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in ...
阅读全文
摘要:题目: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may co
阅读全文
摘要:题目: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may co
阅读全文
摘要:题目: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transac
阅读全文
摘要:题目: 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 th
阅读全文
摘要:题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. 链接: http://leetcode.com/problems/pascals
阅读全文
摘要:题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1
阅读全文
摘要:题目: 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
阅读全文
摘要:题目: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to it
阅读全文
摘要:题目:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the o...
阅读全文
摘要:题目: Given a binary tree, flatten it to a linked list in-place. For example,Given The flattened tree should look like: click to show hints. Hints: If y
阅读全文
摘要:题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. return 链接: http://leetcode.com/problems/pat
阅读全文
摘要:题目: 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 su
阅读全文
摘要:题目: 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 neare
阅读全文
摘要:题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the
阅读全文
摘要:题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 链接: http://leetcode.com/problems/con
阅读全文
摘要:题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 链接: http://leetcode.com/problems/convert-sorted-
阅读全文
摘要:题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
阅读全文
摘要:题目: Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. 链接: http
阅读全文
摘要:题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. 链接: http:
阅读全文
摘要:题目: 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 farthe
阅读全文
摘要:题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level
阅读全文
摘要:题目: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tre
阅读全文
摘要:题目: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: But the
阅读全文
摘要:题目: 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 identic
阅读全文
摘要:题目: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, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: 链接:http://leetcode.com/problems/vali
阅读全文
摘要:题目:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens...
阅读全文
摘要:题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique
阅读全文
摘要:题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return
阅读全文
摘要:题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,3,2]. 链接: http://leetco
阅读全文
摘要:题目: Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return
阅读全文
摘要:题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3
阅读全文
摘要:题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded me
阅读全文
摘要:题目: Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descend
阅读全文
摘要:题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total
阅读全文
摘要:题目: 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
阅读全文
摘要:题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible represen
阅读全文
摘要:题目: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve
阅读全文
摘要:题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 链接: http://leetcode.com/prob
阅读全文
摘要:题目: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the
阅读全文
摘要:题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3
阅读全文
摘要:题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given
阅读全文
摘要:题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a fun
阅读全文
摘要:题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array nums = [1,1,1,2,2,3], Your function
阅读全文
摘要:题目: 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 "a
阅读全文
摘要:题目: Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set mus
阅读全文
摘要:题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is: [ [2,4],
阅读全文
摘要:题目: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOB
阅读全文
摘要:题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order r
阅读全文
摘要:题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sort
阅读全文
摘要:题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 链接: http://leetcode.com/problems/set-matrix-zeroes/
阅读全文
摘要:题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You h
阅读全文
摘要:题目: Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c" click to sho
阅读全文
摘要:题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can yo
阅读全文
摘要:题目: Implement int sqrt(int x). Compute and return the square root of x. 链接: http://leetcode.com/problems/sqrtx/ 题解: 求平方根。 二分法, Time Complexity - O(log
阅读全文
摘要:题目: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You
阅读全文
摘要:题目: Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 链接: http://leetcode.com/problems/add-b
阅读全文
摘要:题目: Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit
阅读全文
摘要:题目: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true Note: It is intended for
阅读全文
摘要:题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its pa
阅读全文
摘要:题目: 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 s
阅读全文
摘要:题目: A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below). The robot can only move either down or right at an
阅读全文
摘要:题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2
阅读全文
摘要:题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequ
阅读全文
摘要:题目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3, You should return the fol
阅读全文
摘要:题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last
阅读全文
摘要:题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were in
阅读全文
摘要:题目: 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]. Given
阅读全文
摘要:题目: 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 m
阅读全文
摘要:题目: Given a matrix of m x n elements (m rows, ncolumns), return all elements of the matrix in spiral order. For example,Given the following matrix: Yo
阅读全文
摘要:题目: 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,−
阅读全文
摘要:题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. Show Tags Show Simila
阅读全文
摘要:题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return
阅读全文
摘要:题目: Implement pow(x, n). 链接: http://leetcode.com/problems/powx-n/ 题解: 使用二分法求实数幂,假如不建立临时变量halfPow,直接return计算结果的话会超时,还没仔细研究为什么。 Time Complexity - O(logn
阅读全文
摘要:题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. Hide Tags Hash Table String Giv
阅读全文
摘要:题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? 链接: http
阅读全文
摘要:题目: Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following uniqu
阅读全文
摘要:题目: 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
阅读全文
摘要:题目: 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 m
阅读全文
摘要:题目: Implement wildcard pattern matching with support for '?' and '*'. 链接: http://leetcode.com/problems/wildcard-matching/ 题解: 这道题是一刷里放弃的6道题中第一道。看过<挑战程
阅读全文
摘要:题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non
阅读全文
摘要:题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after rain
阅读全文
摘要:题目: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2. Your algorit
阅读全文
摘要:题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each
阅读全文
摘要:题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same re
阅读全文
摘要:题目: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11.11 is read
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled
阅读全文
摘要:题目: 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 i
阅读全文
摘要:题目: 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 th
阅读全文
摘要:题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a targe
阅读全文
摘要:题目: Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", th
阅读全文
摘要:题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not po
阅读全文
摘要:题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a c
阅读全文
摘要:题目: Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 链接: http://leetcode.com/problems/d
阅读全文
摘要:题目: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 an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn'
阅读全文
摘要:题目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra spac
阅读全文
摘要:题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k th
阅读全文
摘要:题目: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Yo
阅读全文
摘要:题目:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.链接:http://leetcode.com/problems/merge-k-sorted-list...
阅读全文
摘要:题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set i
阅读全文
摘要:题目: 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 a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in
阅读全文
摘要:题目: Given a linked list, remove the nth node from the end of list and return its head. For example, Note:Given n will always be valid.Try to do this i
阅读全文
摘要:题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array
阅读全文
摘要:题目: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the tel
阅读全文
摘要:题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integ
阅读全文
摘要:题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum
阅读全文
摘要:题目: Write a function to find the longest common prefix string amongst an array of strings. 链接:http://leetcode.com/problems/longest-common-prefix/ 题解:
阅读全文
摘要:题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 链接: http://leetcode.com/problems/roman
阅读全文
摘要:题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 链接: http://leetcode.com/problems/integ
阅读全文
摘要:题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two e
阅读全文
摘要:题目: Implement regular expression matching with support for '.' and '*'. 链接:http://leetcode.com/problems/regular-expression-matching/ 题解: 这道题也卡了很久,一开始就
阅读全文
摘要:题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Could negative integers be palindromes? (ie, -1
阅读全文
摘要:题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see be
阅读全文
摘要:题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers. Have you thought about this? He
阅读全文
摘要:题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed f
阅读全文
摘要:题目:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letter
阅读全文
摘要:题目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a sin
阅读全文
摘要:题目: 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 t
阅读全文