LeetCode
文章平均质量分 74
风吹得好舒服
发现更大的世界~
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode---Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()原创 2014-11-13 16:22:58 · 747 阅读 · 0 评论 -
Subsets
一道非常有意思的题目。 原题如下: Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [原创 2014-12-15 17:24:44 · 681 阅读 · 0 评论 -
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. 题意很简单:根据中序遍历和后序遍历的序列生成树 思路很简单:根据后序遍历的序列确定根节点,在中序遍历中找到根节点,将原来的序列分为左右两个部分,递归解决左右两个部分就可以解决这个问题。 Java代码如下: publ原创 2015-01-07 01:37:03 · 909 阅读 · 0 评论 -
Unique Binary Search Trees II
这道题承接Unique Binary Search Trees,只需要返回搜索二叉树的个数,用DP求解。但是这道题需要得到所有树的集合,可以用DFS求解。 原题是这个样子的: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's原创 2014-12-16 22:54:39 · 818 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
public TreeNode sortedListToBST(ListNode head) { if (head == null) return null; int len = 0; ListNode nextNode = head; while (nextNode != null) { nextNode = nextNode.next; len++; } return buildTree(head, 0, len - 1); } public Tree原创 2014-12-16 19:40:48 · 786 阅读 · 0 评论 -
Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Replace a原创 2015-01-10 17:09:11 · 636 阅读 · 0 评论 -
Sum Root to Leaf Numbers
终于完成了LeetCode 上AC率在30%以上的题目,这道题是最后一道,纪念一下。 原题是这个样子的: 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原创 2014-12-13 23:41:16 · 692 阅读 · 0 评论
分享