2014年3月17日

Binary Tree Level Order Traversal

摘要: Given a binary tree, return thelevel ordertraversal 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 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]用lev记录当前树到了第几层。/** * Definition for binary... 阅读全文

posted @ 2014-03-17 22:28 pengyu2003 阅读(143) 评论(0) 推荐(0)

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 keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文

posted @ 2014-03-17 22:20 pengyu2003 阅读(120) 评论(0) 推荐(0)

Unique Binary Search Trees

摘要: 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 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文

posted @ 2014-03-17 21:49 pengyu2003 阅读(139) 评论(0) 推荐(0)

Reverse Linked List II

摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.用了栈。注意指针移动时不同指针的分工。/** * Definition for singly-linked 阅读全文

posted @ 2014-03-17 15:39 pengyu2003 阅读(125) 评论(0) 推荐(0)

Decode Ways

摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文

posted @ 2014-03-17 15:15 pengyu2003 阅读(104) 评论(0) 推荐(0)

Partition List

摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文

posted @ 2014-03-17 14:40 pengyu2003 阅读(134) 评论(0) 推荐(0)

导航