0%

Description

Difficulty: Simple

用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 )

示例 :

输入:[“CQueue”,”appendTail”,”deleteHead”,”deleteHead”],[[],[3],[],[]]
输出:[null,null,3,-1]

输入:[“CQueue”,”deleteHead”,”appendTail”,”appendTail”,”deleteHead”,”deleteHead”],[[],[],[5],[2],[],[]]
输出:[null,-1,null,null,5,2]

Read more »

Description

Difficulty: Medium

Given preorder and inorder traversal of a tree, construct the binary tree.

Note:
You may assume that duplicates do not exist in the tree.

For example, given

1
2
preorder = [3,9,20,15,7] // 前序遍历(VLR): 首先访问根结点,然后遍历左子树,最后遍历右子树。
inorder = [9,3,15,20,7] // 中序遍历(LDR): 首先遍历左子树,然后访问根结点,最后遍历右子树。

Return the following binary tree:

1
2
3
4
5
  3
/ \
9 20
/ \
15 7
Read more »

Description

Difficulty: Simple

输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。

示例 :

1
2
输入:head = [1,3,2]
输出:[2,3,1]
1
2
3
4
5
6
7
8
/**
\* Definition for singly-linked list.
\* public class ListNode {
\* int val;
\* ListNode next;
\* ListNode(int x) { val = x; }
\* }
*/
Read more »