03 2016 档案
摘要:查找等差数列中的缺失项. e.g.Input: arr[] = {2, 4, 8, 10, 12, 14} Output: 6 Input: arr[] = {1, 6, 11, 16, 21, 31}; Output: 26. 采用binary search. 若是arr[mid] - arr[l
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-vertical-order-traversal/ 题目: Given a binary tree, return the vertical order traversal of its nodes'
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/ 题目: Given an array of numbers, verify whether it is the correct
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/paint-house-ii/ 题目: There are a row of n houses, each house can be painted with one of the k colors. The cost of
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/paint-house/ 题目: There are a row of n houses, each house can be painted with one of the three colors: red, blue
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/house-robber-iii/ 题目: The thief has found himself a new place for his thievery again. There is only one entrance
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 题目: Given an array of integers that is already sorted in ascending order, find
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a TwoSum class. It should support the following oper
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/odd-even-linked-list/ 题目: Given a singly linked list, group all odd nodes together followed by the even nodes. P
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/burst-balloons/ 题目: Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represe
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/count-of-range-sum/ 题目: Given an integer array nums, return the number of range sums that lie in [lower, upper]
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/ 题目: The API: int read4(char *buf) reads 4 characters at a
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/read-n-characters-given-read4/ 题目: The API: int read4(char *buf) reads 4 characters at a time from a file. The r
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/shortest-distance-from-all-buildings/ 题目: You want to build a house on an empty land which reaches all buildings
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/ 题目: An image is represented by a binary matrix with 0 as a white pixe
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/count-of-smaller-numbers-after-self/ 题目: You are given an integer array nums and you have to return a new counts
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/description/ 题目: Given a list of airline tickets represented by pairs of departure and arr
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree characteristics, we can choose any node as the root.
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/missing-ranges/ 题目: Given a sorted integer array nums, where the range of elements are in the inclusive range [l
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ 题目: One way to serialize a binary tree is to use pre-order trave
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/patching-array/ 题目: Given a sorted positive integer array nums and an integer n, add/patch elements to the array
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/generalized-abbreviation/ 题目: Write a function to generate the generalized abbreviations of a word. Example: Giv
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ 题目: Say you have an array for which the ith element is the price
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/alien-dictionary/ 题目: There is a new alien language which uses the latin alphabet. However, the order among lett
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/3sum-smaller/ 题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all the palindromic permutations (without duplicates) of
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/palindrome-permutation/ 题目: Given a string, determine if a permutation of the string could form a palindrome. Fo
阅读全文
摘要:三种comments: 1 /* Test program */ 2 3 int main() 4 5 { 6 7 // variable declaration 8 9 int a, b, c; 10 11 /* This is a test 12 13 multiline 14 15 comme
阅读全文
摘要:以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. 与Fraction to Recurring Decimal类似.
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Given n nodes labeled from 0 to n - 1 and a list of u
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string , reverse the string word by word. Example: Input: ["t",
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/range-sum-query-2d-mutable/ 题目: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defi
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/paint-fence/ 题目: There is a fence with n posts, each post can be painted with one of the k colors. You have to p
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/strobogrammatic-number/ 题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (l
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/zigzag-iterator/ 题目: Given two 1d vectors, implement an iterator to return their elements alternately. For examp
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/remove-duplicate-letters/ 题目: Given a string which contains only lowercase letters, remove duplicate letters so
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/encode-and-decode-strings/ 题目: Design an algorithm to encode a list of strings to a string. The encoded string i
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/ 题目: Given an array nums and a target value k, find the maximum length of a s
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/unique-word-abbreviation/ 题目: An abbreviation of a word follows the form <first letter><number><last letter>. Be
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/graph-valid-tree/ 题目: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/super-ugly-number/ 题目: Write a program to find the nth super ugly number. Super ugly numbers are positive number
阅读全文
摘要:原题链接在这里:https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ 题目: Given a binary tree, find the length of the longest consecutive se
阅读全文