华为不该再提起"床垫文化"的

356 阅读4分钟

床垫文化

最近,在余承东和董宇辉的直播对话中,一个很久没被提起的词,被重新翻出。

床垫文化。

具体是指,在华为,几乎每个研发人员都有一张床垫,放在铁柜的底层,办公桌的下面。

午休时,席地而卧,项目加班严重时,甚至不离开公司,就靠这张床垫,累了睡,醒了则爬起来继续干活。

这次床垫文化在余承东口中被提起,则被进一步提炼为:大家都睡在公司,一天三顿饭都在公司吃。

如果翻看历史,床垫文化其实早在华为成立之初就被提出。

1988 年,华为还在起步阶段,产品越来越多,客户越来越多,需求越来越多,加班几乎成为了每个人的常态,在质量和稳定性都面临许多问题的时候,华为不得不砸进更多的人和时间。

华为也确实靠"床垫文化"度过了艰难的初创时光。

但这样的文化放在如今是否还适用,其实争议很大。

余承东在直播间分享华为人在公司初期高度敬业和奉献自我,没啥问题。

但在分享公司多年前的"床垫文化"之余,还强调自己近 30 年也都在公司吃喝,就容易被断章取义解读成「华为近 30 年都在宣扬"床垫文化"」,容易成为那些热衷于学习华为"狼性文化"的公司管理者 PUA 员工的话术。

个人认为,不考虑时代的适应性,将"床垫文化"这种只适合作为"精神传承"的内容拿出来宣扬,难以起到正向作用。

尤其在当年,床垫文化本身就曾引起过巨大的舆论争议,全社会一度认为这样的文化应当被制止。

2006 年,深圳华为年仅 25 岁的员工胡新宇因工作任务紧迫持续加班近一个月,过度劳累,导致全身多个器官衰竭而离开人世。

大家不该忘记这样的事实,不该忘记这些文化背后的代价。

...

回归主题。

来一道和「虾皮社招」相关的题目。

题目描述

平台:LeetCode

题号:919

完全二叉树是每一层(除最后一层外)都是完全填充(即节点数达到最大)的,并且所有的节点都尽可能地集中在左侧。

设计一种算法,将一个新节点插入到一个完整的二叉树中,并在插入后保持其完整。

实现 CBTInserter 类:

  • CBTInserter(TreeNode root) 使用头节点为 root 的给定树初始化该数据结构;
  • CBTInserter.insert(int v)  向树中插入一个值为 Node.val == val 的新节点 TreeNode。使树保持完全二叉树的状态,并返回插入节点 TreeNode 的父节点的值
  • CBTInserter.get_root() 将返回树的头节点。

示例 1:

输入
["CBTInserter", "insert", "insert", "get_root"]
[[[1, 2]], [3], [4], []]

输出
[null, 1, 2, [1, 2, 3, 4]]

解释
CBTInserter cBTInserter = new CBTInserter([1, 2]);
cBTInserter.insert(3);  // 返回 1
cBTInserter.insert(4);  // 返回 2
cBTInserter.get_root(); // 返回 [1, 2, 3, 4]

提示:

  • 树中节点数量范围为 [1,1000][1, 1000]
  • 0<=Node.val<=50000 <= Node.val <= 5000
  • root 是完全二叉树
  • 0<=val<=5000 0 <= val <= 5000 
  • 每个测试用例最多调用 insert 和 get_root 操作 10410^4 次

BFS

起始使用数组对构造函数传入的 root 进行 BFS 层序遍历(由于仍要保留层序遍历顺序,因此使用下标指针 cur 来模拟出队位置)。

对于 insert 操作而言,我们要在数组(层序遍历顺序)中找到首个「存在左右空子节点」的父节点 fa,由于找到 fa 节点的过程数组下标单调递增,因此可以使用全局变量 idx 不断往后搜索,每次将新节点 node 添加到当前树后,需要将 node 添加到数组尾部。

get_root 操作则始终返回数组首位元素即可。

Java 代码:

class CBTInserter {
    List<TreeNode> list = new ArrayList<>();
    int idx = 0;
    public CBTInserter(TreeNode root) {
        list.add(root);
        int cur = 0;
        while (cur < list.size()) {
            TreeNode node = list.get(cur);
            if (node.left != null) list.add(node.left);
            if (node.right != null) list.add(node.right);
            cur++;
        }
    }
    public int insert(int val) {
        TreeNode node = new TreeNode(val);
        while (list.get(idx).left != null && list.get(idx).right != null) idx++;
        TreeNode fa = list.get(idx);
        if (fa.left == null) fa.left = node;
        else if (fa.right == null) fa.right = node;
        list.add(node);
        return fa.val;
    }
    public TreeNode get_root() {
        return list.get(0);
    }
}

C++ 代码:

class CBTInserter {
public:
    vector<TreeNode*> list;
    int idx = 0;
    CBTInserter(TreeNode* root) {
        list.push_back(root);
        int cur = 0;
        while (cur < list.size()) {
            auto node = list[cur];
            if (node->left) list.push_back(node->left);
            if (node->right) list.push_back(node->right);
            cur++;
        }
    }
    int insert(int val) {
        auto node = new TreeNode(val);
        while (list[idx]->left && list[idx]->right) idx++;
        auto fa = list[idx];
        if (!fa->left) fa->left = node;
        else if (!fa->right) fa->right = node;
        list.push_back(node);
        return fa->val;
    }
    TreeNode* get_root() {
        return list.front();
    }
};

Python 代码:

class CBTInserter:
    def __init__(self, root):
        self.lz = [root]
        self.idx = 0
        cur = 0
        while cur < len(self.lz):
            node = self.lz[cur]
            if node.left: self.lz.append(node.left)
            if node.right: self.lz.append(node.right)
            cur += 1

    def insert(self, val):
        node = TreeNode(val)
        while self.lz[self.idx].left and self.lz[self.idx].right:
            self.idx += 1
        fa = self.lz[self.idx]
        if not fa.left:
            fa.left = node
        else:
            fa.right = node
        self.lz.append(node)
        return fa.val

    def get_root(self):
        return self.lz[0]

TypeScript 代码:

class CBTInserter {
    list: TreeNode[] = new Array<TreeNode>()
    idx: number = 0
    constructor(root: TreeNode | null) {
        this.list.push(root)
        let cur = 0
        while (cur < this.list.length) {
            const node = this.list[cur]
            if (node.left != null) this.list.push(node.left)
            if (node.right != null) this.list.push(node.right)
            cur++
        }
    }
    insert(val: number): number {
        const node = new TreeNode(val)
        while (this.list[this.idx].left != null && this.list[this.idx].right != null) this.idx++
        const fa = this.list[this.idx]
        if (fa.left == null) fa.left = node
        else if (fa.right == null) fa.right = node
        this.list.push(node)
        return fa.val
    }
    get_root(): TreeNode | null {
        return this.list[0]
    }
}
  • 时间复杂度:O(n)O(n)
  • 空间复杂度:O(n)O(n)