11 2021 档案
摘要:Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example 1: Input: matri
阅读全文
摘要:Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the el
阅读全文
摘要:Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any orde
阅读全文
摘要:Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if i
阅读全文
摘要:You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each li
阅读全文
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is
阅读全文
摘要:地上有一个m行n列的方格,从坐标 [0,0] 到坐标 [m-1,n-1] 。一个机器人从坐标 [0, 0] 的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于k的格子。例如,当k为18时,机器人能够进入方格 [35, 37] ,因为3+5+
阅读全文
摘要:You are given an integer array of unique positive integers nums. Consider the following graph: There are nums.length nodes, labeled nums[0] to nums[nu
阅读全文
摘要:给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。 例
阅读全文
摘要:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一个旋转,该数组的最小值为1。 示例 1: 输入:[3,4,5,1,2]输出:1示例 2: 输入:[2,2,2
阅读全文
摘要:一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 示例 1: 输入:n = 2 输出:2 示例 2: 输入:n = 7 输出:21 class S
阅读全文
摘要:写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项(即 F(N))。斐波那契数列的定义如下: F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), 其中 N > 1.斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得
阅读全文
摘要:输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 示例 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] Output: [3,9,20,null,nul
阅读全文
摘要:输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 简单思路:利用一个vector容器存储存储链表中的元素,然后利用函数对vector容器进行翻转。 函数原型: template <class Bidirecti
阅读全文
摘要:请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 示例 1: 输入:s = "We are happy." 输出:"We%20are%20happy." class Solution { public: string replaceSpace(string s) { string tmp
阅读全文
摘要:在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12,
阅读全文
摘要:找出数组中重复的数字。 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 示例 1: 输入:[2, 3, 1, 0, 2, 5, 3] 输出:2 或 3 clas
阅读全文
摘要:用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例 1: 输入: ["CQueue","appendTail","dele
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:由前序和中序数组构建二叉树 Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder trave
阅读全文
摘要:You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
阅读全文
摘要:Given an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i
阅读全文
摘要:You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum ju
阅读全文
摘要:You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected hor
阅读全文
摘要:Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive. 范围内的数字按照位数与
阅读全文
摘要:Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwee
阅读全文
摘要:Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding t
阅读全文
摘要:Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by
阅读全文
摘要:Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears
阅读全文
摘要:Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k]
阅读全文
摘要:Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subse
阅读全文
摘要:Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in
阅读全文
摘要:Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is
阅读全文
摘要:You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1]. You should build a set s[k] = {num
阅读全文
摘要:Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [
阅读全文
摘要:You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented b
阅读全文
摘要:Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c. 只要是two_sum 变形 都可以考虑用hash_set来做。 class Solution { p
阅读全文
摘要:Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure. fin
阅读全文
摘要:Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each inp
阅读全文
摘要:Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific targe
阅读全文
摘要:Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the g
阅读全文
摘要:Share Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain t
阅读全文
摘要:Given an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i
阅读全文
摘要:One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node,
阅读全文
摘要:Given a string s, reverse the string according to the following rules: All the characters that are not English letters remain in the same position. Al
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You mus
阅读全文
摘要:There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edge
阅读全文
摘要:Given an m x n board of characters and a list of strings words, return all words on the board. Each word must be constructed from letters of sequentia
阅读全文
摘要:Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequent
阅读全文
摘要:Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. 一般如果只
阅读全文
摘要:Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the
阅读全文
摘要:Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its ro
阅读全文
摘要:Given the root of a complete binary tree, return the number of the nodes in the tree. According to Wikipedia, every level, except possibly the last, i
阅读全文
摘要:You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the
阅读全文
摘要:You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day
阅读全文
摘要:You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an e
阅读全文
摘要:A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are va
阅读全文
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, return
阅读全文

浙公网安备 33010602011771号