Showing posts with label Divide&Conquer. Show all posts
Showing posts with label Divide&Conquer. Show all posts

Monday, April 14, 2014

Minimum Depth of Binary Tree @LeetCode

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.

Tuesday, March 11, 2014

Same Tree @LeetCode

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.

Saturday, February 15, 2014

Path Sum @LeetCode

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 = 22,
              5
             / \
            4   8
           /   / \
          11  13  4
         /  \      \
        7    2      1
return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

Thursday, February 13, 2014

Construct Binary Tree from Inorder and Postorder Traversal @LeetCode


Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.

Construct Binary Tree from Preorder and Inorder Traversal @LeetCode


Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.

Convert Sorted List to Binary Search Tree @LeetCode


Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

Convert Sorted Array to Binary Search Tree @LeetCode

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

Wednesday, February 12, 2014

Lastest Common Ancester



Find the Latest Common Ancestor of two TreeNode.
For Example,
Given
         1
        / \
       2   5
      / \   \
     3   4   6

 The LCA of 3 and 4 is 2. 5 and 6 is 5.

Binary Tree Maximum Path Sum @LeetCode


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   3
Return 6.

Tuesday, February 11, 2014

Balanced Binary Tree @LeetCode


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 of every node never differ by more than 1.

Maximum Depth of Binary Tree @LeetCode


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.