04 2016 档案
摘要:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. Example Given n = 3, your program should return all 5 u
阅读全文
摘要:Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Example Given n = 3, there are a total of 5 unique BST's. 1
阅读全文
摘要: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 two n
阅读全文
摘要: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 raining.
阅读全文
摘要:Given an directed graph, a topological order of the graph nodes is defined as follow: For each directed edge A -> B in graph, A must before B in the o
阅读全文
摘要:Given two array of integers(the first array is array A, the second array is array B), now we are going to find a element in array A which is A[i], and
阅读全文
摘要:Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate value
阅读全文
摘要: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 surround
阅读全文
摘要:There is a fence with n posts, each post can be painted with one of the kcolors.You have to paint all the posts such that no more than two adjacent fe
阅读全文
摘要:Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes
阅读全文
摘要:Ugly number is a number that only have factors 2, 3 and 5. Design an algorithm to find the nth ugly number. The first 10 ugly numbers are 1, 2, 3, 4,
阅读全文
摘要:Write a program to check whether a given number is an ugly number`. Ugly numbers are positive numbers whose prime factors only include 2,3, 5. For exa
阅读全文
摘要:Given a list of numbers that may has duplicate numbers, return all possible subsets Notice Each element in a subset must be in non-descending order. T
阅读全文
摘要:Given a set of distinct integers, return all possible subsets. Notice Elements in a subset must be in non-descending order. The solution set must not
阅读全文
摘要:Given an integer matrix, find a submatrix where the sum of numbers is zero. Your code should return the coordinate of the left-up and right-down numbe
阅读全文
摘要:Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number. Example Given [-3, 1, 1, -3,
阅读全文
摘要:Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order. Example Given n = 3, You should return the following
阅读全文
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example Given the following matrix: [ [ 1, 2,
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example Given 1-3->2->null, sort it to 1->2->3->null. /** * Definition for List
阅读全文
摘要:Given a string which contains only letters. Sort it by lower case first and upper case second. Notice It's NOT necessary to keep the original order of
阅读全文
摘要:Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors
阅读全文
摘要: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 red,
阅读全文
摘要:Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Example Given [1,2,2,3,4,4,5,3] return 1 and 5 Given [1,2,2,3,4,4,5,3] return
阅读全文
摘要:Given 3*n + 1 numbers, every numbers occurs triple times except one, find it. Example Given [1,1,2,3,3,3,2,2,4,1] return 4 Given [1,1,2,3,3,3,2,2,4,1]
阅读全文
摘要:Given an absolute path for a file (Unix-style), simplify it. Example "/home/", => "/home" "/a/./b/../../c/", => "/c" "/home/", => "/home" "/a/./b/../.
阅读全文
摘要:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Example Given a matrix [ [1,2], [0,3] ], return[[0,2],[0
阅读全文
摘要:For an array, we can build a SegmentTree for it, each node stores an extra attributecount to denote the number of elements in the the array which valu
阅读全文
摘要:For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores an extra attribute m
阅读全文
摘要:For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in this node's interval. Implement a modify function wit
阅读全文
摘要:The structure of Segment Tree is a binary tree which each node has two attributesstart and end denote an segment / interval. start and end are both in
阅读全文
摘要:The structure of Segment Tree is a binary tree which each node has two attributesstart and end denote an segment / interval. start and end are both in
阅读全文
摘要: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 functio
阅读全文
摘要: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 target va
阅读全文
摘要:Given a sorted array of n integers, find the starting and ending position of a given target value. If the target is not found in the array, return [-1
阅读全文
摘要:Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it. This matrix has the following properties: Inte
阅读全文
摘要:Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x s
阅读全文
摘要:Given a directed graph, design an algorithm to find out whether there is a route between two nodes. Example Given graph: A >B >C \ | \ | \ | \ v ->D >
阅读全文
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. Example Given 1->2->3->4->5 and k = 2, return 4->5->1->2->3. /** * De
阅读全文
摘要:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise). Example Given a matrix [ [1,2], [3,4] ] rotate it b
阅读全文
摘要:Given a roman numeral, convert it to an integer. The answer is guaranteed to be within the range from 1 to 3999. Example IV -> 4 XII -> 12 XXI -> 21 X
阅读全文
摘要:Reverse a linked list from position m to n. Notice Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list. Given m, n satisfy the foll
阅读全文
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example Given "25525511135", return [ "255.
阅读全文
摘要:Given a singly linked list L: L0 → L1 → … → Ln-1 → Ln reorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … Example Given 1->2->3->4->null, reorder it to
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example Given 1->2->3-
阅读全文
摘要:The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should do
阅读全文
摘要:Print numbers from 1 to the largest number with N digits by recursion. Notice It's pretty easy to do recursion like: recursion(i) { if i > largest num
阅读全文
摘要:Given a list of integers, which denote a permutation. Find the previous permutation in ascending order. Notice The list may contains duplicate integer
阅读全文
摘要:Implement pow(x, n). Notice You don't need to care about the precision of your answer, it's acceptable if the expected answer and your answer 's diffe
阅读全文
摘要:Given a list of numbers with duplicate number in it. Find all unique permutations. Example For numbers [1,2,2] the unique permutations are: [ [1,2,2],
阅读全文
摘要:Given a list of numbers, return all possible permutations. Example For nums = [1,2,3], the permutations are: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,
阅读全文
摘要:Given n and k, return the k-th permutation sequence. Notice n will be between 1 and 9 inclusive. n will be between 1 and 9 inclusive. n will be betwee
阅读全文
摘要:Given a permutation which may contain repeated numbers, find its index in all the permutations of these numbers, which are ordered in lexicographical
阅读全文
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Example Given n = 12, retu
阅读全文
摘要:Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that: All elements < k are moved to the left
阅读全文
摘要:Given a string s, cut s into some substrings such that every substring is a palindrome. Return the minimum cuts needed for a palindrome partitioning o
阅读全文
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example Gi
阅读全文
摘要:Implement a function to check if a linked list is a palindrome. Example Given 1->2->1, return true Given 1->2->1, return true Given 1->2->1, return tr
阅读全文
摘要:There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certai
阅读全文
摘要:Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Comparison of a nut to ano
阅读全文
摘要:Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most? Notice If landing and flying happen
阅读全文
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib
阅读全文
摘要:恢复内容开始 Given a list of integers, which denote a permutation. Find the next permutation in ascending order. Notice The list may contains duplicate inte
阅读全文
摘要:Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. Example For n=4, there ar
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×nchessboard such that no two queens attack each other. Given an integer n, return all d
阅读全文
摘要:Given a string source and a string target, find the minimum window in source which will contain all the characters in target. Notice If there is no su
阅读全文

浙公网安备 33010602011771号