GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/Tree/655.Print-Binary-Tree at master · wisdompeak/LeetCode

Expand file tree

/

655.Print-Binary-Tree

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

655.Print-Binary-Tree

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
655.Print-Binary-Tree.cpp
655.Print-Binary-Tree.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

655.Print-Binary-Tree

先求出这棵树的高度height,那么整个结果矩阵的宽度就是 pow(2,height)-1.

如何填充这个矩阵数组呢?要利用每个父节点在下一层的相对位置,是其所有子节点的最中央的特点,用DFS来做。设置每一层的start和end,找到mid的位置放置父节点的值。则左子树在下一层的摆放区间就在start~mid-1,右子树在下一层的摆放区间就在mid+1~end.如此就可以设置递归函数。

Leetcode Link

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.