Print a binary tree in an m*n 2D string array following these rules:
m
should be equal to the height of the given binary tree.n
should always be an odd number.""
.Example 1:
Input: 1 / 2 Output: [["", "1", ""], ["2", "", ""]]
Example 2:
Input: 1 / \ 2 3 \ 4 Output: [["", "", "", "1", "", "", ""], ["", "2", "", "", "", "3", ""], ["", "", "4", "", "", "", ""]]
Example 3:
Input: 1 / \ 2 5 / 3 / 4 Output: [["", "", "", "", "", "", "", "1", "", "", "", "", "", "", ""] ["", "", "", "2", "", "", "", "", "", "", "", "5", "", "", ""] ["", "3", "", "", "", "", "", "", "", "", "", "", "", "", ""] ["4", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]]
Note: The height of binary tree is in the range of [1, 10].
struct Solution;
impl Solution {
fn judge_circle(moves: String) -> bool {
let mut x = 0;
let mut y = 0;
for c in moves.chars() {
match c {
'U' => y += 1,
'D' => y -= 1,
'L' => x -= 1,
'R' => x += 1,
_ => (),
}
}
x == 0 && y == 0
}
}
#[test]
fn test() {
assert_eq!(Solution::judge_circle("UD".to_string()), true);
assert_eq!(Solution::judge_circle("LL".to_string()), false);
}