摘要:
请用栈实现一个队列,支持如下四种操作: push(x) – 将元素x插到队尾; pop() – 将队首的元素弹出,并返回该元素; peek() – 返回队首元素; empty() – 返回队列是否为空; class MyQueue { public: /** Initialize your data 阅读全文
posted @ 2022-12-10 16:52
!&&||
阅读(28)
评论(0)
推荐(0)
摘要:
给定一棵二叉树的其中一个节点,请找出中序遍历序列的下一个节点。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNod 阅读全文
posted @ 2022-12-10 16:42
!&&||
阅读(26)
评论(0)
推荐(0)
摘要:
输入一棵二叉树前序遍历和中序遍历的结果,请重建该二叉树。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i 阅读全文
posted @ 2022-12-10 16:21
!&&||
阅读(20)
评论(0)
推荐(0)
摘要:
输入一个链表的头结点,按照 从尾到头 的顺序返回节点的值。 返回的结果用数组存储。 class Solution { public: vector<int> printListReversingly(ListNode* head) { vector<int> ans; for (auto p = h 阅读全文
posted @ 2022-12-10 15:34
!&&||
阅读(19)
评论(0)
推荐(0)
摘要:
请实现一个函数,把字符串中的每个空格替换成"%20"。 class Solution { public: string replaceSpaces(string &s) { string ans = ""; for (char c : s) { if (c == ' ') { ans += "%20 阅读全文
posted @ 2022-12-10 15:31
!&&||
阅读(49)
评论(0)
推荐(0)
摘要:
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 class Solution { public: bool searchArray(vector<vector<int>> arr 阅读全文
posted @ 2022-12-10 14:02
!&&||
阅读(20)
评论(0)
推荐(0)
摘要:
在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 注意:不能修改输入的数组。 class Solution { public: int duplicateInAr 阅读全文
posted @ 2022-12-10 13:59
!&&||
阅读(27)
评论(0)
推荐(0)

浙公网安备 33010602011771号