Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
<Solution>You may assume that duplicates do not exist in the tree.
3 / \ 9 20 / \ 15 7
[ [3], [20,9], [15,7] ]<Solution>
3 / \ 9 20 / \ 15 7
[ [15,7], [9,20], [3] ]<Solution>
3 / \ 9 20 / \ 15 7
[ [3], [9,20], [15,7] ]<Solution>
1 / \ 2 2 / \ / \ 3 4 4 3
1 / \ 2 2 \ \ 3 3
2 / \ 1 3Binary tree
1 / \ 2 3Binary tree
'A' -> 1 'B' -> 2 ... 'Z' -> 26
[ [2], [1], [1,2,2], [2,2], [1,2], [] ]<Solution>
00 - 0 01 - 1 11 - 3 10 - 2
[ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ]word =
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]<Solution>
[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]<Solution>
[ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ]
[ [0,0,0], [0,1,0], [0,0,0] ]
[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]<Solution>
[ [".Q..", // Solution 1 "...Q", "Q...", "..Q."], ["..Q.", // Solution 2 "Q...", "...Q", ".Q.."] ]<Solution>
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3<Solution>
1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3<Solution>
[ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ]
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const char *s, const char *p)
Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "*") → true
isMatch("aa", "a*") → true
isMatch("ab", "?*") → true
isMatch("aab", "c*a*b") → false
<Solution>