Example 9 The permutation of integers $1,2, \cdots, n$ satisfies: each number is either greater than all the numbers before it, or less than all the numbers before it. How many such permutations are there?
(21st Canadian High School Mathematics Competition)