09 2015 档案
摘要:原题链接在这里:https://leetcode.com/problems/permutation-sequence/ 题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labelin
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/combination-sum-iii/ 题目: Find all possible combinations of k numbers that add up to a number n, given that only
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/combination-sum-ii/ 题目: Given a collection of candidate numbers (C) and a target number (T), find all unique com
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/combination-sum/ 题目: Given an array of distinct integers candidates and a target integer target, return a list o
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/permutations-ii/ 题目: Given a collection of numbers that might contain duplicates, return all possible unique per
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/permutations/ 题目: Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3]
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/combinations/ 题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/subsets-ii/ 题目: Given a collection of integers that might contain duplicates, nums, return all possible subsets.
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/subsets/ 题目: Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solu
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/rotate-image/ 题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/spiral-matrix-ii/ 题目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral o
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/spiral-matrix/ 题目: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in sp
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/first-bad-version/ 题目: You are a product manager and currently leading a team to develop a new product. Unfortun
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/container-with-most-water/ 题目: Given n non-negative integers a1, a2, ..., an , where each represents a point at
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/move-zeroes/ 题目: Given an array nums, write a function to move all 0's to the end of it while maintaining the re
阅读全文
摘要:原题链接在这里: https://leetcode.com/problems/jump-game-ii/ 题目: Given an array of non-negative integers, you are initially positioned at the first index of t
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/jump-game/ 题目: Given an array of non-negative integers, you are initially positioned at the first index of the a
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/gas-station/ 题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/reverse-bits/ 题目: Reverse bits of a given 32 bits unsigned integer. Example 1: Example 2: Note: Note that in som
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/number-of-1-bits/ 题目: Write a function that takes an unsigned integer and return the number of '1' bits it has (
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/dungeon-game/ 题目: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a du
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/edit-distance/ 题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 t
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/scramble-string/这道题参考了这篇帖子:http://blog.csdn.net/linhuanmars/article/details/24506703这其实是一道三维动态规划的题目,我们提出维护量res[i...
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/generate-parentheses/ 题目: Given n pairs of parentheses, write a function to generate all combinations of well-fo
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string/ 题目: Given an input string, reverse the string word by word. For example,Given s = "th
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/simplify-path/ 题目: Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", =>
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/zigzag-conversion/ 题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/length-of-last-word/ 题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ',
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/count-and-say/ 题目: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211,
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/longest-common-prefix/ 题目: Write a function to find the longest common prefix string amongst an array of strings
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/compare-version-numbers/ 题目: Compare two version numbers version1 and version2.If version1 > version2 return 1,
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/interleaving-string/ 题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/distinct-subsequences/ 题目: Given a string S and a string T, count the number of distinct subsequences of S which
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/longest-valid-parentheses/ 题目: Given a string containing just the characters '(' and ')', find the length of the
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximal-rectangle/ 题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing o
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/largest-rectangle-in-histogram/description/ 题目: Given n non-negative integers representing the histogram's bar h
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/ 题目: Say you have an array for which the ith element is the price of a given
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/ 题目: Say you have an array for which the ith element is the price of a given
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 题目: Say you have an array for which the ith element is the price of a given
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ 题目: Say you have an array for which the ith element is the price of a given sto
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximal-square/ 题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1'
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximum-product-subarray/ 题目: Find the contiguous subarray within an array (containing at least one number) whic
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximum-subarray/ 题目: Find the contiguous subarray within an array (containing at least one number) which has th
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/decode-ways/ 题目: A message containing letters from A-Z is being encoded to numbers using the following mapping:
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/minimum-path-sum/ 题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom r
阅读全文
摘要:原题俩接在这里:https://leetcode.com/problems/ugly-number-ii/ 题目: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/ugly-number/ 题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive nu
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/powx-n/ 题目: Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Ou
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the least number of perfect square numbers (for example, 1
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/sqrtx/ 题目: Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non
阅读全文
摘要:Check if a given number is a perfect square with only addition orsubstraction operation.eg. 25 returns true; 19 returns false.Perfect square number 有一...
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/unique-paths-ii/ 题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram be
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/unique-paths/ 题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/palindrome-partitioning-ii/ 题目: Given a string s, partition s such that every substring of the partition is a pa
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/palindrome-partitioning/ 题目: Given a string s, partition s such that every substring of the partition is a palin
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/word-break-ii/ 题目: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, ad
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/word-break/ 题目: Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/triangle/ 题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/house-robber-ii/ 题目: Note: This is an extension of House Robber. After robbing those houses on that street, the
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/house-robber/ 题目: You are a professional robber planning to rob houses along a street. Each house has a certain
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can eith
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题目: Given a non-empty binary tree, find the maximum path sum. For this problem, a
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/unique-binary-search-trees-ii/ 题目: Given an integer n, generate all structurally unique BST's (binary search tre
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/unique-binary-search-trees/ 题目: Given n, how many structurally unique BST's (binary search trees) that store val
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/validate-binary-search-tree/ 题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assum
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/recover-binary-search-tree/description/ 题目: T Two elements of a binary search tree (BST) are swapped by mistake.
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题目: Given a binary tree Populate each next pointer to point to i
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ 题目: You are given a perfect binary tree where all leaves are on the
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-right-side-view/ 题目: Given a binary tree, imagine yourself standing on the right side of it, return
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/ 题目: Given a binary search tree, write a function kthSmallest to find
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/flatten-binary-tree-to-linked-list/description/ 题目: Given a binary tree, flatten it to a linked list in-place. F
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/count-complete-tree-nodes/ 题目: Given a complete binary tree, count the number of nodes. Definition of a complete
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/sum-root-to-leaf-numbers/ 题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/path-sum-ii/ 题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the giv
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-paths/ 题目: Given a binary tree, return all root-to-leaf paths. For example, given the following bina
阅读全文
摘要:To convert a int to string:int num = 123;String str = String.valueOf(num);To convert a string to int:String str = "123";int num = Integer.valueOf(str)...
阅读全文
摘要:Java 的 annotation 以@开头 比如@Override. 不改变complied program的action annotation不完全是comments 能够改变一段代码compile的方式 下面这段代码因为base class里没有display(int x), 所以是用@Ove
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ 题目: Given a binary tree, find the lowest common ancestor (LCA) of two g
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ 题目: Given a binary search tree (BST), find the lowest common anc
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/invert-binary-tree/ 题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 题解: 既可以自顶向下
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/symmetric-tree/ 题目: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题目: Given a binary tree, return the bottom-up level order traversal of its
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/same-tree/ 题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 题目: Given a binary tree, find its minimum depth. The minimum depth is the number o
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximum-depth-of-binary-tree/ 题目: Given a binary tree, find its maximum depth. The maximum depth is the number o
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/balanced-binary-tree/ 题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-ba
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/reorder-list/ 题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 题目: Given an array where elements are sorted in ascending order, con
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题目: Given a singly linked list where elements are sorted in ascending
阅读全文
摘要:Private means this could only be seen within this class. Protected means "package private", this could be seen by subclasses and package members. | Cl
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/sort-list/ 题目: Sort a linked list in O(n log n) time using constant space complexity. 题解: divide and conquer. 从中
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/insertion-sort-list/ 题目: Sort a linked list using insertion sort. 题解: 与Sort List类似. 当出现cur.val > cur.next.val时就需
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题目: Follow up for "Remove Duplicates":What if duplicates are allowed at
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 题目: Given a sorted array, remove the duplicates in place such that each ele
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 题目: Given a sorted linked list, delete all nodes that have duplicate numb
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 题目: Given a sorted linked list, delete all duplicates such that each element
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/partition-list/ 题目: Given a linked list and a value x, partition it such that all nodes less than x come before
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/linked-list-cycle-ii/ 题目: Given a linked list, return the node where the cycle begins. If there is no cycle, ret
阅读全文