2017年1月4日 星期三

[LeetCode] 112. 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.
<Solution>

[LeetCode] 111. 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.
<Solution>

[LeetCode] 110. 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.
<Solution>

2017年1月3日 星期二

[LeetCode] 109. 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.
<Solution>

[C++] tuple Usage

在 c++11,tuple 變成一個內建的 data structure

這邊記錄一下一些 sample code

<Example 1> Basic usage

2017年1月2日 星期一

2017年1月1日 星期日

[LeetCode] 106. 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.
<Solution>