zoukankan      html  css  js  c++  java
  • LeetCode "Populating Next Right Pointers in Each Node"

    Apparently BFS is the most obvious one.. but it is not that simple - only constant extra space is provided.

    Then the only strategy to take is recursion. I bogged down for quite while.. only after checked http://leetcode.com/2010/03/first-on-site-technical-interview.html, I got enlightment: pick a pen and a piece of paper, and simulate the procedure by drawing - this strategy is working so well on diagram-like problems! Just like "starting from enumeration and check pattern" strategy, a good solution starts from basics.

    class Solution {
    public:
        void connect(TreeLinkNode *p) {
            if (!p) return;
            if (p->left)    p->left->next = p->right;    // with the same parent
            if (p->right)    p->right->next = (p->next) ? p->next->left : NULL;
            connect(p->left);
            connect(p->right);
        }
    };
  • 相关阅读:
    一个通用的事件监听函数全集
    单应性矩阵
    opencv姿态估计
    opencv相机标定
    Harris角点
    盒滤波Box Filter
    win10+vs2015+pcl1.8.1安装配置
    图像元素遍历
    阈值分割
    二叉树的层次遍历
  • 原文地址:https://www.cnblogs.com/tonix/p/3857655.html
Copyright © 2011-2022 走看看