Posted 浠g爜璺笂
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
//缁欏畾涓€涓簩鍙夋爲锛岃繑鍥炲畠鐨?鍚庡簭 閬嶅巻銆?nbsp;
//
// 绀轰緥:
//
// 杈撳叆: [1,null,2,3]
// 1
// \
// 2
// /
// 3
//
//杈撳嚭: [3,2,1]
//
// 杩涢樁: 閫掑綊绠楁硶寰堢畝鍗曪紝浣犲彲浠ラ€氳繃杩唬绠楁硶瀹屾垚鍚楋紵
// Related Topics 鏍?鏍?nbsp;
// 馃憤 483 馃憥 0
//leetcode submit region begin(Prohibit modification and deletion)
import java.util.LinkedList;
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
//鍚庣画閬嶅巻浣跨敤閫掑綊
//1.鑾峰彇褰撳墠鑺傜偣鐨勫乏瀛愭爲
//2.鑾峰彇褰撳墠鑺傜偣鐨勫彸瀛愭爲
//3.灏嗗綋鍓嶈妭鐐瑰姞鍏?/p>
LinkedList<Integer> result = new LinkedList<>();
if(root == null) {
return result;
}
helper(root,result);
return result;
}
private void helper(TreeNode node,LinkedList<Integer> list){
if(node == null ){
return;
}
helper(node.left,list);
helper(node.right,list);
list.addLast(node.val);
}
}
//leetcode submit region end(Prohibit modification and deletion)
以上是关于的主要内容,如果未能解决你的问题,请参考以下文章