- 博客(200)
- 资源 (1)
- 收藏
- 关注
原创 CODE 38: Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2013-09-21 10:40:34 538
原创 CODE 36: Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret
2013-09-20 23:36:14 593
原创 CODE 35: Validate Binary Search Tree
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 nodes with keys less than the node's key.Th
2013-09-20 21:39:24 636
原创 CODE 26: Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},
2013-09-20 19:38:56 683
原创 CODE 34: Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a
2013-09-20 19:33:34 827
原创 CODE 33: Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. public
2013-09-20 18:35:57 732
原创 CODE 32: Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f
2013-09-20 18:30:19 681
原创 CODE 31: Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /
2013-09-20 18:08:53 674
原创 CODE 30: 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
2013-09-20 18:06:20 741
原创 CODE 29: Maximum Depth of Binary Tree
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 farthest leaf node. public int maxDepth(TreeNode ro
2013-09-20 15:48:40 944
原创 CODE 28: Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. public TreeNode buildTree(int[] preorder, int[] inor
2013-09-20 15:43:46 935
原创 CODE 27: 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. public TreeNode buildTree(int[] inorder, int[] post
2013-09-20 13:31:37 956
原创 CODE 24: 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. public TreeNode sortedListToBST(ListNode head) { // Start typing your Java solution
2013-09-20 09:58:18 696
原创 CODE 25: Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. public TreeNode sortedArrayToBST(int[] num) { // Start typing your Java solution below // DO N
2013-09-20 09:18:09 648
原创 CODE 23: Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never differ
2013-09-19 21:07:00 662
原创 CODE 22: Minimum Depth of Binary Tree
Given 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 nearest leaf node. public int minDepth(TreeNode root) {
2013-09-19 20:16:48 693
原创 CODE 20: Path Sum II
public ArrayList> pathSum(TreeNode root, int sum) { // Start typing your Java solution below // DO NOT write main() function ArrayList> paths = new ArrayList>(); if (null == root) { re
2013-09-19 19:11:32 613
原创 CODE 21: Path Sum
Given 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 given sum.For example:Given the below binary tree and sum
2013-09-18 23:16:25 574
原创 CODE 19: 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 \
2013-09-17 22:31:52 545
原创 CODE 18: Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)
2013-09-17 21:16:00 505
原创 CODE 16: Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extr
2013-09-16 21:23:51 703
原创 CODE 17: 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 t
2013-09-16 21:22:44 604
原创 CODE 15: Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]My Code: public
2013-09-16 20:59:27 634
原创 CODE 9: Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.
2013-09-16 20:53:06 782
原创 CODE 2: Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"],
2013-09-16 20:25:58 689
原创 CODE 14: Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space? public Ar
2013-09-15 21:19:49 560
原创 CODE 13: 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],
2013-09-15 18:57:30 518
原创 CODE 10: Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may no
2013-09-15 16:57:05 814
原创 CODE 11: Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2013-09-15 16:56:50 843
原创 CODE 12: Best Time to Buy and Sell Stock
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 to complete at most one transaction (ie, buy one and sell one share of the stock),
2013-09-15 16:55:55 763
原创 CODE 8: Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pa
2013-09-12 22:13:27 661
原创 CODE 7: Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence fromstart to end, such that:Only one letter can be changed at a time Each intermediate word
2013-09-12 00:05:40 659
原创 CODE 5: Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3,
2013-09-10 22:28:57 530
原创 CODE 4: 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
2013-09-09 22:47:01 667
原创 CODE 3: Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X O
2013-09-09 21:30:24 684 1
原创 CODE 1: Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 s
2013-09-08 15:08:02 540 1
转载 人生就是不停的战斗————九把刀北大演讲
时间:2011年11月5日地点:北京大学2号楼205主题:人生就是不停的战斗手打组:中财刘铮,魏文婷请尊重手打组作品,转载勿删除手打组。 非常非常开心能够来北京大学演讲,我能表现出的最大的诚意就是,今天的演讲将是原汁原味非常忠于台湾版本的“人生就是不停的战斗”,还加了一段目前在台湾演讲一共讲了不到三次的“神的微笑”。希望我们今天晚上会有非常热血的两个小时。但是“人生就是
2011-11-18 13:42:20 2383
原创 python 串口测试工具中 py2exe的使用
python 串口测试工具中 py2exe的使用from distutils.core import setupimport py2exeimport sys, ossys.argv.append('py2exe')origIsSystemDLL = py2exe.build_exe.isSystemDLLdef isSystemDLL(pathname): if os
2011-11-17 23:09:22 1368
转载 python串口通信模块——pySerial
pySerialOverviewThis module encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux, BSD (possibly any POSIX compliant system), Jython and IronPython
2011-11-17 22:20:24 3541
原创 在python文件中集成图片
方法一:http://leo108.com/pid-938.asp使用base64方式编解码。 核心代码如下:1.将图片文件编码为base64字符串:import base64 #导入base64库 f = open(r'/home/1.ico','rb') #用二进制方式打开图片文件str = base64.b64encode(
2011-11-14 13:43:34 600
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人