摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
阅读全文
摘要: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 algorithm
阅读全文
摘要: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
阅读全文
摘要: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]. 这题和Inser
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文
摘要: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 repeat
阅读全文
摘要:Given n x m non-negative integers representing an elevation map 2d where the area of each cell is 1 x 1, compute how much water it is able to trap aft
阅读全文
摘要:Find K-th largest element in N arrays. Example In n=2 arrays [[9,3,2,4,7],[1,2,3,4,8]], the 3rd largest element is 7. In n=2 arrays [[9,3,2,4,8],[1,2,
阅读全文
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: You
阅读全文
摘要: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 sorted f
阅读全文
摘要:Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [3,2,1]. 后续遍历二叉树,主要是使用栈来非递归实
阅读全文
摘要: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 functi
阅读全文
摘要:Implement pow(x, n) 这题用二分做,思路很明确,但是具体怎么做很有trick. 首先是n可能为INT_MIN ,如果将n直接取绝对值,则会溢出,另外,此时直接求分母,最后再求倒数,也可能在求分母的过程中溢出. 所以比较好的办法每次需要乘元素的时候乘以1/x(n<0)时. 大坑:py
阅读全文
摘要:Sort a linked list using insertion sort. 这道题目要求插入排序,插入排序的做法的正常做法是,对于当前要处理的数字,朝前查找在已排序数组中的位置. 对于单向链表而言,无法朝前走,所以一个替换的选择是从头朝后走.直到后面的节点值大于当前处理的节点. 值得注意的有两
阅读全文
摘要:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such p
阅读全文
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determine t
阅读全文
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: 这
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho
阅读全文
摘要:You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of
阅读全文
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the
阅读全文
摘要:Partition an integers array into odd number first and even number second. 剑指offer的一道题,把所有奇数移动到偶数前面,其实是partition的双端解法,利用双指针。先检测两边合格的元素,都不合格,则交换,继续。 需要注
阅读全文