随笔分类 -  Great Questions

摘要:Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Given n, how many structurally unique BSTs (binary search tr 阅读全文
posted @ 2016-07-08 23:11 北叶青藤 阅读(183) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文
posted @ 2016-07-08 10:29 北叶青藤 阅读(169) 评论(0) 推荐(0)
摘要:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. Example Given the below binary tree: 1 / \ 2 3 ret 阅读全文
posted @ 2016-07-08 10:19 北叶青藤 阅读(230) 评论(0) 推荐(0)
摘要:Given two strings, find the longest common subsequence (LCS). Your code should return the length of LCS. Example For "ABCD" and "EDCA", the LCS is "A" 阅读全文
posted @ 2016-07-06 12:51 北叶青藤 阅读(265) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example Given lists: [ 2->4->null, null, -1->null ] 阅读全文
posted @ 2016-07-06 07:22 北叶青藤 阅读(173) 评论(0) 推荐(0)
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文
posted @ 2016-07-06 07:06 北叶青藤 阅读(173) 评论(0) 推荐(0)
摘要:Ugly Number Write a program to check whether a given number is an ugly number`. Ugly numbers are positive numbers whose prime factors only include 2,  阅读全文
posted @ 2016-07-06 04:12 北叶青藤 阅读(333) 评论(0) 推荐(0)
摘要:For an array A, if i < j, and A [i] > A [j], called (A [i], A [j]) is a reverse pair.return total of reverse pairs in A. For an array A, if i < j, and 阅读全文
posted @ 2016-07-06 02:01 北叶青藤 阅读(220) 评论(0) 推荐(0)
摘要:Swap Nodes | Given a linked list, swap every two adjacent nodes and return its head. Example Given 1->2->3->4, you should return the list as 2->1->4-> 阅读全文
posted @ 2016-07-05 12:24 北叶青藤 阅读(191) 评论(0) 推荐(0)
摘要:Best Time to Buy and Sell Stock I Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted t 阅读全文
posted @ 2016-07-05 09:14 北叶青藤 阅读(238) 评论(0) 推荐(0)
摘要:There are two sorted arrays A and B of size m and nrespectively. Find the median of the two sorted arrays. There are two sorted arrays A and B of size 阅读全文
posted @ 2016-07-05 07:55 北叶青藤 阅读(206) 评论(0) 推荐(0)
摘要:Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back f 阅读全文
posted @ 2016-07-05 06:06 北叶青藤 阅读(178) 评论(0) 推荐(0)
摘要:Jump Game | Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represent 阅读全文
posted @ 2016-07-05 03:18 北叶青藤 阅读(179) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Clarification Your algorithm should run in O(n) com 阅读全文
posted @ 2016-07-05 01:48 北叶青藤 阅读(185) 评论(0) 推荐(0)
摘要:k Sum Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers where sum is target. Calculate how many solutions the 阅读全文
posted @ 2016-07-05 00:55 北叶青藤 阅读(249) 评论(0) 推荐(0)
摘要:Single Number Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1,2,2,1,3,4,3], return 4 分析: 利用bit operator ^ 的特点即 阅读全文
posted @ 2016-07-04 11:27 北叶青藤 阅读(165) 评论(0) 推荐(0)
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2016-07-04 10:30 北叶青藤 阅读(216) 评论(0) 推荐(0)
摘要:Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2, 阅读全文
posted @ 2016-07-04 05:29 北叶青藤 阅读(242) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it has a cycle in it. Given a linked list, determine if it h 阅读全文
posted @ 2016-07-03 11:45 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要: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. Merge Sort version 1 /** 阅读全文
posted @ 2016-07-03 10:24 北叶青藤 阅读(185) 评论(0) 推荐(0)