09 2015 档案

摘要:QuestionGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree ... 阅读全文
posted @ 2015-09-30 23:24 树獭君 阅读(127) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the give... 阅读全文
posted @ 2015-09-30 22:52 树獭君 阅读(166) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths a... 阅读全文
posted @ 2015-09-30 05:00 树獭君 阅读(192) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each nex... 阅读全文
posted @ 2015-09-29 10:38 树獭君 阅读(190) 评论(0) 推荐(0)
摘要:QuestionGiven 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 contain... 阅读全文
posted @ 2015-09-29 09:27 树獭君 阅读(157) 评论(0) 推荐(0)
摘要:(referrence: ProgramCreek)The key to solve inorder traversal of binary tree includes the following:The order of "inorder" is: left child -> parent -> ... 阅读全文
posted @ 2015-09-29 08:43 树獭君 阅读(220) 评论(0) 推荐(0)
摘要:QuestionThere are a total ofncourses you have to take, labeled from0ton - 1.Some courses may have prerequisites, for example to take course 0 you have... 阅读全文
posted @ 2015-09-29 07:19 树獭君 阅读(249) 评论(0) 推荐(0)
摘要:Topological sorting/ ordering is a linear ordering of itsverticessuch that for every directed edgeuvfrom vertexuto vertexv,ucomes beforevin the orderi... 阅读全文
posted @ 2015-09-28 23:05 树獭君 阅读(566) 评论(0) 推荐(0)
摘要:Question Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the f 阅读全文
posted @ 2015-09-24 10:17 树獭君 阅读(134) 评论(0) 推荐(0)
摘要:QuestionClone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labe... 阅读全文
posted @ 2015-09-24 10:07 树獭君 阅读(198) 评论(0) 推荐(0)
摘要:Reference: superWhen we override superclass's methods, but still want to invoke them, we can use keyword super in child classes.We can also usesuperto... 阅读全文
posted @ 2015-09-24 08:38 树獭君 阅读(179) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next leve... 阅读全文
posted @ 2015-09-24 07:04 树獭君 阅读(175) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the ne... 阅读全文
posted @ 2015-09-24 05:39 树獭君 阅读(155) 评论(0) 推荐(0)
摘要:QuestionGiven a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root)... 阅读全文
posted @ 2015-09-24 04:58 树獭君 阅读(176) 评论(0) 推荐(0)
摘要:Question Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binar 阅读全文
posted @ 2015-09-24 04:47 树獭君 阅读(194) 评论(0) 推荐(0)
摘要:There are two ways to conduct BFS on tree.Solution 1 -- Given levelUse recursion to find given level, and print./*Function to print level order traver... 阅读全文
posted @ 2015-09-24 04:18 树獭君 阅读(303) 评论(0) 推荐(0)
摘要:QuestionFind thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Fo... 阅读全文
posted @ 2015-09-22 07:24 树獭君 阅读(718) 评论(0) 推荐(0)
摘要:QuestionMergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution 1 -- Merge SortWe can follow the meth... 阅读全文
posted @ 2015-09-22 04:53 树獭君 阅读(147) 评论(0) 推荐(0)
摘要:QuestionThere are two sorted arraysnums1andnums2of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexit... 阅读全文
posted @ 2015-09-22 03:03 树獭君 阅读(203) 评论(0) 推荐(0)
摘要:QuestionGiven a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the follow... 阅读全文
posted @ 2015-09-21 08:40 树獭君 阅读(165) 评论(0) 推荐(0)
摘要:QuestionSay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may co... 阅读全文
posted @ 2015-09-21 07:23 树獭君 阅读(150) 评论(0) 推荐(0)
摘要:QuestionSay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may co... 阅读全文
posted @ 2015-09-21 05:39 树獭君 阅读(172) 评论(0) 推荐(0)
摘要:QuestionSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transac... 阅读全文
posted @ 2015-09-21 03:47 树獭君 阅读(203) 评论(0) 推荐(0)
摘要:QuestionGiven 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... 阅读全文
posted @ 2015-09-21 03:30 树獭君 阅读(231) 评论(0) 推荐(0)
摘要:QuestionGivenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return a... 阅读全文
posted @ 2015-09-21 02:36 树獭君 阅读(171) 评论(0) 推荐(0)
摘要:QuestionGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BS... 阅读全文
posted @ 2015-09-20 07:46 树獭君 阅读(127) 评论(0) 推荐(0)
摘要:QuestionFollow 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... 阅读全文
posted @ 2015-09-20 03:04 树獭君 阅读(135) 评论(0) 推荐(0)
摘要:QuestionA robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at an... 阅读全文
posted @ 2015-09-20 02:41 树獭君 阅读(142) 评论(0) 推荐(0)
摘要:QuestionFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4... 阅读全文
posted @ 2015-09-20 02:26 树獭君 阅读(179) 评论(0) 推荐(0)
摘要:QuestionYou are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can y... 阅读全文
posted @ 2015-09-19 23:46 树獭君 阅读(213) 评论(0) 推荐(0)
摘要:QuestionAfter robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention... 阅读全文
posted @ 2015-09-19 23:33 树獭君 阅读(155) 评论(0) 推荐(0)
摘要:QuestionYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint sto... 阅读全文
posted @ 2015-09-19 23:05 树獭君 阅读(199) 评论(0) 推荐(0)
摘要:QuestionGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a can... 阅读全文
posted @ 2015-09-17 08:05 树獭君 阅读(170) 评论(0) 推荐(0)
摘要:QuestionGivennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpo... 阅读全文
posted @ 2015-09-17 03:46 树獭君 阅读(140) 评论(0) 推荐(0)
摘要:QuestionGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given... 阅读全文
posted @ 2015-09-16 22:59 树獭君 阅读(135) 评论(0) 推荐(0)
摘要:QuestionWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: ... 阅读全文
posted @ 2015-09-16 10:45 树獭君 阅读(191) 评论(0) 推荐(0)
摘要:QuestionMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.S... 阅读全文
posted @ 2015-09-16 09:03 树獭君 阅读(123) 评论(0) 推荐(0)
摘要:QuestionGiven a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. ... 阅读全文
posted @ 2015-09-16 06:09 树獭君 阅读(177) 评论(0) 推荐(0)
摘要:QuestionReverse a singly linked list.Solution 1 -- IterativeRemember to set head.next = null or it will report "memory limit exceeds" error. 1 /** 2 ... 阅读全文
posted @ 2015-09-16 03:17 树獭君 阅读(196) 评论(0) 推荐(0)
摘要:QuestionGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating le... 阅读全文
posted @ 2015-09-16 01:55 树獭君 阅读(112) 评论(0) 推荐(0)
摘要:QuestionAll DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes us... 阅读全文
posted @ 2015-09-15 06:05 树獭君 阅读(216) 评论(0) 推荐(0)
摘要:QuestionGiven an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, re... 阅读全文
posted @ 2015-09-15 04:45 树獭君 阅读(133) 评论(0) 推荐(0)
摘要:QuestionGiven an array of integers, every element appearstwiceexcept for one. Find that single one.Solution 1 -- SetWe can use a hash set to record ea... 阅读全文
posted @ 2015-09-15 04:45 树獭君 阅读(164) 评论(0) 推荐(0)
摘要:QuestionGiven two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car... 阅读全文
posted @ 2015-09-15 02:04 树獭君 阅读(184) 评论(0) 推荐(0)
摘要:QuestionCount the number of prime numbers less than a non-negative number,n.Solution 1Naive way, to check each number one by one. If a number i is pri... 阅读全文
posted @ 2015-09-14 06:44 树獭君 阅读(204) 评论(0) 推荐(0)
摘要:QuestionGiven two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrenc... 阅读全文
posted @ 2015-09-14 04:43 树獭君 阅读(181) 评论(0) 推荐(0)
摘要:QuestionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were insert... 阅读全文
posted @ 2015-09-14 02:10 树獭君 阅读(152) 评论(0) 推荐(0)
摘要:QuestionGiven an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order... 阅读全文
posted @ 2015-09-12 00:56 树獭君 阅读(159) 评论(0) 推荐(0)
摘要:QuestionGiven an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the... 阅读全文
posted @ 2015-09-11 23:26 树獭君 阅读(152) 评论(0) 推荐(0)
摘要:QuestionGiven an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].SolutionSimilar with Pascal's Triangle. Note... 阅读全文
posted @ 2015-09-11 23:06 树獭君 阅读(220) 评论(0) 推荐(0)
摘要:QuestionGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,... 阅读全文
posted @ 2015-09-11 08:47 树獭君 阅读(374) 评论(0) 推荐(0)
摘要:QuestionGiven a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].S... 阅读全文
posted @ 2015-09-11 07:56 树獭君 阅读(165) 评论(0) 推荐(0)
摘要:QuestionGiven an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doe... 阅读全文
posted @ 2015-09-11 05:51 树獭君 阅读(133) 评论(0) 推荐(0)
摘要:QuestionGiven a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra spa... 阅读全文
posted @ 2015-09-11 05:42 树獭君 阅读(148) 评论(0) 推荐(0)
摘要:QuestionRotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Solution... 阅读全文
posted @ 2015-09-11 05:19 树獭君 阅读(181) 评论(0) 推荐(0)
摘要:QuestionGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant dig... 阅读全文
posted @ 2015-09-11 04:24 树獭君 阅读(173) 评论(0) 推荐(0)
摘要:QuestionGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in... 阅读全文
posted @ 2015-09-11 04:03 树獭君 阅读(150) 评论(0) 推荐(0)
摘要:QuestionGiven two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that ... 阅读全文
posted @ 2015-09-11 03:53 树獭君 阅读(189) 评论(0) 推荐(0)
摘要:Solution 1Naive wayFirst, sort the array using Arrays.sort in Java. Than, scan once to find the majority element. Time complexity O(nlog(n)) 1 public ... 阅读全文
posted @ 2015-09-11 03:07 树獭君 阅读(171) 评论(0) 推荐(0)
摘要:Question: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 t... 阅读全文
posted @ 2015-09-01 10:52 树獭君 阅读(231) 评论(0) 推荐(0)