摘要: Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n 阅读全文
posted @ 2020-03-31 22:54 米开朗菠萝 阅读(92) 评论(0) 推荐(0)
摘要: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文
posted @ 2020-03-31 22:17 米开朗菠萝 阅读(138) 评论(0) 推荐(0)
摘要: 一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 示例 1: 输入:n = 2输出:2示例 2: 输入:n = 7输出:21提示: 0 <= n 阅读全文
posted @ 2020-03-31 18:48 米开朗菠萝 阅读(259) 评论(0) 推荐(0)
摘要: 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项。斐波那契数列的定义如下: F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), 其中 N > 1.斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。 答案需要取 阅读全文
posted @ 2020-03-31 18:39 米开朗菠萝 阅读(209) 评论(0) 推荐(0)
摘要: 用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例 1: 输入:["CQueue","appendTail","delet 阅读全文
posted @ 2020-03-31 18:28 米开朗菠萝 阅读(118) 评论(0) 推荐(0)
摘要: 在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19] 阅读全文
posted @ 2020-03-31 17:33 米开朗菠萝 阅读(124) 评论(0) 推荐(0)
摘要: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文
posted @ 2020-03-31 16:27 米开朗菠萝 阅读(89) 评论(0) 推荐(0)
摘要: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two di 阅读全文
posted @ 2020-03-31 15:28 米开朗菠萝 阅读(92) 评论(0) 推荐(0)
摘要: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] 阅读全文
posted @ 2020-03-31 15:20 米开朗菠萝 阅读(99) 评论(0) 推荐(0)