题目描述:
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ...
最后更新于 .
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ...
最后更新于 .
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}, reorder it to {1,4,2,3}.
给定一个单链表L:L0→L1→…→Ln-1→Ln
重新将其排序为: L0→Ln→L1→Ln-1→L2→Ln-2→…
必须在不改变节点值的前提下就地完成链表的顺序重排。
1. 利用快慢指针找到链表中点mid,将链表分为左右两半
2. 将链表的右半部分就地逆置 ...
最后更新于 .
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 = empty stack
while (not parentStack.isEmpty() or ...
最后更新于 .
You are a traveling salesman. You have already heard a lot about how hard the problems of a traveling salesman can be. Luckily, the one you currently have seems easier.
There are M cities where you can sell products. ...
最后更新于 .
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 | ...