2018年2月6日

二叉树的非递归遍历-O(1)空间

摘要: 问题描述: 对一颗二叉树进行中序遍历,要求空间复杂度为O(1),即常数空间。 解题方法: 由于要求空间复杂度为O(1),显然不能采用递归和栈的方式来遍历。由于树中的叶子节点的左右指针域都为空, 因此可以利用叶子节点的指针域记录后驱节点,类似于线索二叉树,这种方法叫Morris Traversal方法 阅读全文

posted @ 2018-02-06 11:28 IT_Amateur 阅读(237) 评论(0) 推荐(0) 编辑

LeetCode 89. Gray Code

摘要: 题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total 阅读全文

posted @ 2018-02-06 09:05 IT_Amateur 阅读(197) 评论(0) 推荐(0) 编辑

导航