描述 现有一条单向单车道隧道,每一辆车从隧道的一端驶入,另一端驶出,不允许超车 该隧道对车辆的高度有一定限制,在任意时刻,管理员希望知道此时隧道中最高车辆的高度是多少 现在请你维护这条隧道的车辆进出记录,并支持查询最高车辆的功能 输入 第一行仅含一个整数,即高度查询和车辆出入操作的总次数n 以下n行,依次这n次操作.各行的格式为以下几种之一: 1. E x //有一辆高度为x的车进入隧道(x为整数) 2. D //有一辆车离开隧道 3. M //查询此时隧道中车辆的最大高度 输出 若D和M操作共…
Description Cycle shifting refers to following operation on the sting. Moving first letter to the end and keeping rest part of the string. For example, apply cycle shifting on ABCD will generate BCDA. Given any two strings, to judge if arbitrary time…
Description Let's play the game Zuma! There are a sequence of beads on a track at the right beginning. All the beads are colored but no three adjacent ones are allowed to be with a same color. You can then insert beads one by one into the sequence. O…
第一题,列车调度(train) 在这个题目中,模拟压栈出栈,同时判断调度方案是否可行. #include <cstdio> #include <cstring> #define MAX 1600005 using namespace std; int stack[MAX];//stack[0]作为旗标 int top; int pushed;//已经压入的最大值 int out[MAX];//输出 *MAX][]; int result_len;//result的长度 int ma…
Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the tree, and for each node we check if current_node.val > prev_node.val. The code is as follows. # Definition for a binary tree node # class TreeNode: #…
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder traversal of a binary search tree should be a sorted array. Therefore, we can compare each node with its previous node in the inorder to find the two…
Problem Link: https://oj.leetcode.com/problems/same-tree/ The following recursive version is accepted but the iterative one is not accepted... # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left =…
Problem Link: https://oj.leetcode.com/problems/symmetric-tree/ To solve the problem, we can traverse the tree level by level. For each level, we construct an array of values of the length 2^depth, and check if this array is symmetric. The tree is sym…