1. 程式人生 > 實用技巧 >datasets of sklearn

datasets of sklearn

技術標籤:學習總結二叉樹java資料結構

二叉樹層序遍歷(Java)

class Solution {
    List<List<Integer>> node=new ArrayList();
    public List<List<Integer>> levelOrder(TreeNode root) {
        cx(root,0);
        return node;

    }
    public void cx(TreeNode root,int k){
        if(root!=null){
            if
(node.size()<=k) { node.add(new ArrayList()); } node.get(k).add(root.val); cx(root.left,k+1); cx(root.right,k+1); } } }