L_J_SHOU

2014年2月12日

LeetCode----Sqrt(x)

摘要: Implement int sqrt(int x).Compute and return the square root of x.思路: 其实就是求解 非线性方程 x^2 = A. (A为开方的数)一般形式是 求解 f (x) = 0解法1: 牛顿切线法这是牛顿在 1736年提出的方法,其实思想非... 阅读全文

posted @ 2014-02-12 21:59 L_J_SHOU 阅读(135) 评论(0) 推荐(0)
LeetCode----First Missing Positive

摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文

posted @ 2014-02-12 21:33 L_J_SHOU 阅读(111) 评论(0) 推荐(0)
数据结构《13》----二叉树 Morris 前序遍历

摘要: 三种二叉树的后序遍历的方法: 1. 递归 O(n) 时间复杂度, O(n) 空间复杂度 2. 迭代(用栈) O(n) 时间复杂度, O(n) 空间复杂度 3. Morris 后序遍历 O(n) 时间复杂度, O(1)空间复杂度关于 Morris 中序遍历见http://blog.... 阅读全文

posted @ 2014-02-12 14:02 L_J_SHOU 阅读(206) 评论(0) 推荐(0)
数据结构《12》----二叉树遍历的非递归版本(不用栈)

摘要: 二叉树遍历的非递归版本除了可以使用 stack 外, 见 http://blog.csdn.net/shoulinjun/article/details/19089155还可以采用 parent 指针和标记来实现。二叉树节点的数据结构如下:/*** struct TreeNode * {* ch... 阅读全文

posted @ 2014-02-12 11:53 L_J_SHOU 阅读(175) 评论(0) 推荐(0)
数据结构《11》----二叉树遍历的非递归版本(栈)

摘要: 二叉树的前序,中序,后序遍历的非递归版本有许多种。较为简单的是采用栈,来模拟递归。此外,还可以采用标记,或者父亲指针来实现。这些算法都需要 O(n)的空间,还有一类算法仅仅需要常数的空间即可。如 Morris 遍历 http://blog.csdn.net/shoulinjun/article/de... 阅读全文

posted @ 2014-02-12 11:08 L_J_SHOU 阅读(142) 评论(0) 推荐(0)