- 博客(142)
- 资源 (3)
- 收藏
- 关注
原创 34. Search for a Range
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 the order of O(log n).If the target is not found in
2016-07-28 16:23:57 130
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Subscribe to see which companies asked this question注意
2016-07-28 15:08:13 152
原创 103. Binary Tree Zigzag Level Order Traversal
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 and alternate between).For example:Given binary tr
2016-07-27 17:49:45 127
原创 Unique Paths II
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 space is marked as 1 and 0 respectively in the grid.
2016-07-27 17:34:31 111
原创 372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer andb is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example2:a = 2
2016-07-27 17:12:33 109
原创 86. Partition List
Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2016-07-27 16:09:15 127
原创 147. Insertion Sort List
Sort a linked list using insertion sort.Subscribe to see which companies asked this question/** * Definition for singly-linked list. * struct ListNode { * in
2016-07-27 15:17:47 120
原创 274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A
2016-07-27 14:32:31 255
原创 120. Triangle
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 the following triangle[ [2], [3,4], [6,
2016-07-24 21:33:26 128
原创 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this questio/** * Definition for singly-linked li
2016-07-24 21:26:46 162
原创 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?Subsc
2016-07-21 22:47:20 138
原创 90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a solutio
2016-07-21 22:41:58 175
原创 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.Credits:Special thanks to @amrsaqr for adding this problem and creating all test cases.Subscribe to se
2016-07-21 22:20:12 128
原创 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \
2016-07-20 22:42:51 147
原创 39. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe
2016-07-19 21:09:50 138
原创 81. Search in Rotated Sorted Array II
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 function to determine if a given target is in the arr
2016-07-19 20:32:21 155
原创 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as#.
2016-07-19 19:53:51 140
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1], [2]
2016-07-19 17:15:32 141
原创 275. H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Subscribe to see which companies asked thiclass Solution {public: int hInd
2016-07-19 17:06:10 161
原创 80. Remove Duplicates from Sorted Array II
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 should return length = 5, with the first five e
2016-07-19 16:54:20 136
原创 129. Sum Root to Leaf Numbers
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 which represents the number123.Find the total sum
2016-07-19 16:42:28 116
原创 284. Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be re
2016-07-19 16:30:06 151
原创 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because12 = 4 + 4 + 4; given n = 13,
2016-07-17 17:28:15 147
原创 73. Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) s
2016-07-17 16:24:00 363
原创 74. Search a 2D Matrix
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 from left to right.The first integer of each
2016-07-17 15:51:21 155
原创 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.N
2016-07-17 15:20:43 146
原创 289. Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m b
2016-07-17 14:23:40 131
原创 334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] arr[j]
2016-07-17 11:50:51 148
原创 75. Sort 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, white and blue.Here, we will use the integers 0,
2016-07-17 11:27:01 322
原创 48. Rotate Image
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?Subscribe to see which companies asked this question注
2016-07-17 11:01:28 126
原创 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], theref
2016-07-17 10:15:43 171
原创 240. Search a 2D Matrix II
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 in ascending from left to right.Integers in
2016-07-17 10:07:52 116
原创 313. Super Ugly Number
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 listprimes of size k. For example, [1, 2, 4, 7, 8, 13, 14,
2016-07-16 11:56:52 161
原创 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at
2016-07-16 11:27:21 117
原创 77. Combinations
Given two integers n and k, return all possible combinations ofk numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2016-07-16 11:19:54 139
原创 173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and
2016-07-16 11:11:41 145
原创 59. Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2016-07-16 10:57:30 154
原创 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2016-07-16 10:28:25 189
原创 367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return
2016-07-16 09:57:56 187
原创 Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If the
2016-07-16 09:56:31 150
python xlrd3 安装包 用于python3以后的版本
2016-07-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人