[LeetCode]Binary Tree Preorder Traversal

题目描述:

Given a binary tree, return the preorder traversal of its nodes' values.

For example:

Given binary tree {1,#,2,3},

   1
    \
     2
    /
   3

return [1,2,3].

题目大意:

给定一棵二叉树,返回节点值的先序遍历结果(尽量使用非递归算法)。

解题思路:

使用数据结构栈(Stack)

先序遍历非递归算法的伪代码如下(摘自Wikipedia):

iterativePreorder(node)
  parentStack ...

继续阅读

[LeetCode]Department Top Three Salaries

题目描述:

The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id.

+----+-------+--------+--------------+
| Id | Name  | Salary | DepartmentId |
+----+-------+--------+--------------+
| 1  | Joe   | 70000  | 1            |
| 2  | Henry | 80000  | 2            |
| 3  | Sam   | 60000  | 2            |
| 4  | Max ...

继续阅读

年度归档