Loading

上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页
摘要: 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项(即 F(N))。斐波那契数列的定义如下: F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), 其中 N > 1.斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得 阅读全文
posted @ 2021-11-23 10:58 aalanwyr 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 示例 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] Output: [3,9,20,null,nul 阅读全文
posted @ 2021-11-23 10:49 aalanwyr 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 简单思路:利用一个vector容器存储存储链表中的元素,然后利用函数对vector容器进行翻转。 函数原型: template <class Bidirecti 阅读全文
posted @ 2021-11-23 10:18 aalanwyr 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 示例 1: 输入:s = "We are happy." 输出:"We%20are%20happy." class Solution { public: string replaceSpace(string s) { string tmp 阅读全文
posted @ 2021-11-23 10:04 aalanwyr 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 阅读全文
posted @ 2021-11-23 09:55 aalanwyr 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 找出数组中重复的数字。 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 示例 1: 输入:[2, 3, 1, 0, 2, 5, 3] 输出:2 或 3 clas 阅读全文
posted @ 2021-11-23 09:46 aalanwyr 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例 1: 输入: ["CQueue","appendTail","dele 阅读全文
posted @ 2021-11-23 09:27 aalanwyr 阅读(28) 评论(0) 推荐(0) 编辑
摘要: Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th 阅读全文
posted @ 2021-11-22 20:49 aalanwyr 阅读(45) 评论(0) 推荐(0) 编辑
摘要: Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the 阅读全文
posted @ 2021-11-21 17:40 aalanwyr 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 由前序和中序数组构建二叉树 Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder trave 阅读全文
posted @ 2021-11-21 17:38 aalanwyr 阅读(31) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页