想不明白为什么这样做只能通过30%的案例,中序遍历然后判断list是否对称
对称的二叉树
http://www.nowcoder.com/questionTerminal/ff05d44dfdb04e1d83bdbdab320efbcb
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) { this.val = val; }
}
*/
import java.util.ArrayList;
public class Solution {
static ArrayList<treenode>list=new ArrayList<>();</treenode>
boolean isSymmetrical(TreeNode pRoot) { order(pRoot); for(int i=0;i<list.size()/2;i++){ if(list.get(i).val!=list.get(list.size()-1-i).val){ return false; } } return true; } public void order(TreeNode pRoot){ if(pRoot!=null){ order(pRoot.left); list.add(pRoot); order(pRoot.right); } }
}