public void flatten(TreeNode root) {
        // Start typing your Java solution below
        // DO NOT write main() function

        if (root == null) {
            return;
        }
        root = toFlat(root, null);
    }