随笔分类 -  leetcode

摘要:Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note:Elements in a subset must be in non-descending ord... 阅读全文
posted @ 2015-05-01 17:06 丶Blank 阅读(173) 评论(0) 推荐(0)
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1... 阅读全文
posted @ 2015-05-01 14:06 丶Blank 阅读(166) 评论(0) 推荐(0)
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文
posted @ 2015-04-23 21:40 丶Blank 阅读(166) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2015-04-23 16:37 丶Blank 阅读(175) 评论(0) 推荐(0)
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文
posted @ 2015-04-23 12:54 丶Blank 阅读(137) 评论(0) 推荐(0)
摘要:Find 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,−1,2,1,... 阅读全文
posted @ 2015-04-23 11:27 丶Blank 阅读(137) 评论(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 n... 阅读全文
posted @ 2015-04-22 22:40 丶Blank 阅读(293) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2015-04-22 16:27 丶Blank 阅读(145) 评论(0) 推荐(0)
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.You m... 阅读全文
posted @ 2015-04-22 12:08 丶Blank 阅读(186) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题目大意:给定一个链表,判断是否有环?解题思路:解法一:快慢指针,如果有环,那么快慢... 阅读全文
posted @ 2015-04-22 10:33 丶Blank 阅读(173) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2015-04-22 10:11 丶Blank 阅读(886) 评论(0) 推荐(0)
摘要:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文
posted @ 2015-04-21 21:47 丶Blank 阅读(159) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.题目大意:给定一个二叉树的前序和中序序列,构建出这个二叉树。解题思路:跟中序和后序一样,在先序中取出根节点,然后在中序中找到根节点,划分左右子树,递归构... 阅读全文
posted @ 2015-04-21 15:42 丶Blank 阅读(153) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.题目大意:给定一个二叉树的中序和后续序列,构建出这个二叉树。解题思路:首先后序序列的最后一个是根节点,然后在中序序列中找到这个节点,中序序列中这个节点... 阅读全文
posted @ 2015-04-21 15:26 丶Blank 阅读(165) 评论(0) 推荐(0)
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题目大意:给定一个升序序列的数组,将其转换为二叉搜索树。解题思路:数组中间元素是根元素,根元素将数组划分为... 阅读全文
posted @ 2015-04-20 21:28 丶Blank 阅读(140) 评论(0) 推荐(0)
摘要:Given a list of non negative integers, arrange them such that they form the largest number.For example, given[3, 30, 34, 5, 9], the largest formed num... 阅读全文
posted @ 2015-04-20 19:36 丶Blank 阅读(185) 评论(0) 推荐(0)
摘要:Given a range [m, n] where 0 offset = new HashSet(); for (int i = 0; i >=1; n>>=1; offset++; } return m<<o... 阅读全文
posted @ 2015-04-20 17:42 丶Blank 阅读(1362) 评论(0) 推荐(0)
摘要:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit in... 阅读全文
posted @ 2015-04-20 16:43 丶Blank 阅读(119) 评论(0) 推荐(0)
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2015-04-20 16:36 丶Blank 阅读(174) 评论(0) 推荐(0)
摘要:Given 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 andsum =... 阅读全文
posted @ 2015-04-13 21:11 丶Blank 阅读(136) 评论(0) 推荐(0)