原文链接: https://leetcode-cn.com/problems/climbing-stairs 英文原文You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Outpu…
标签详情
记忆化搜索 分类
原文链接: https://leetcode-cn.com/problems/word-break 英文原文Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary …
原文链接: https://leetcode-cn.com/problems/word-break-ii 英文原文Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note …
原文链接: https://leetcode-cn.com/problems/different-ways-to-add-parentheses 英文原文Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return…
原文链接: https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix 英文原文Given an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: left, right, up, or dow…
原文链接: https://leetcode-cn.com/problems/integer-replacement 英文原文Given a positive integer n, you can apply one of the following operations: If n is even, replace n with n / 2. If n is odd, replace n with either n + 1 or n - 1. Return the minimum number…
原文链接: https://leetcode-cn.com/problems/can-i-win 英文原文In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins. What if we change the game …
原文链接: https://leetcode-cn.com/problems/zuma-game 英文原文You are playing a variation of the game Zuma. In this variation of Zuma, there is a single row of colored balls on a board, where each ball can be colored red 'R', yellow 'Y', blue 'B', green 'G', …
原文链接: https://leetcode-cn.com/problems/remove-boxes 英文原文You are given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time you can choos…
原文链接: https://leetcode-cn.com/problems/shopping-offers 英文原文In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale p…
原文链接: https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets 英文原文Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal. Example 1: Input: nums = […
原文链接: https://leetcode-cn.com/problems/all-possible-full-binary-trees 英文原文Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0. Each element of the answer is th…
原文链接: https://leetcode-cn.com/problems/cat-and-mouse 英文原文A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph…
原文链接: https://leetcode-cn.com/problems/n-th-tribonacci-number 英文原文The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Example 1: Input: n = 4 Output: 4 Exp…
原文链接: https://leetcode-cn.com/problems/sort-integers-by-the-power-value 英文原文The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps: if x is even then x = x / 2 if x is odd then x = 3 * x + 1…
原文链接: https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza 英文原文Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to c…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges 英文原文There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows: Eat one orange. If the number of remaining oranges n is divisible…
原文链接: https://leetcode-cn.com/problems/count-all-possible-routes 英文原文You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing …
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst 英文原文Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nu…
原文链接: https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero 英文原文Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representati…
原文链接: https://leetcode-cn.com/problems/maximize-grid-happiness 英文原文You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCoun…
原文链接: https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph 英文原文There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1. You are given a string colors where colors[i] is a lowercase English …
原文链接: https://leetcode-cn.com/problems/the-earliest-and-latest-rounds-where-players-compete 英文原文There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial stan…
原文链接: https://leetcode-cn.com/problems/three-steps-problem-lcci 英文原文A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the s…
原文链接: https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof 中文题目写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项(即 F(N))。斐波那契数列的定义如下: F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), 其中 N > 1. 斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。 答案需要取模 1e9+7(1000000007),如…
原文链接: https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof 中文题目一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 示例 1: 输入:n = 2 输出:2 示例 2: 输入:n = 7 输出:21 示例 3: 输入:n = 0 输出:1 提示: 0 <= n …
原文链接: https://leetcode-cn.com/problems/boolean-evaluation-lcci 英文原文Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the nu…
原文链接: https://leetcode-cn.com/problems/meChtZ 英文原文 中文题目小扣打算去秋日市集,由于游客较多,小扣的移动速度受到了人流影响: - 小扣从 `x` 号站点移动至 `x + 1` 号站点需要花费的时间为 `inc`; - 小扣从 `x` 号站点移动至 `x - 1` 号站点需要花费的时间为 `dec`。 现有 m 辆公交车,编号为 0 到 m-1。小扣也可以通过搭乘编号为 i 的公交车,从 x 号站点移动至 jump[i]*x 号站点,耗时仅为 co…
原文链接: https://leetcode-cn.com/problems/fpTFWP 中文题目给定一个 m x n 整数矩阵 matrix ,找出其中 最长递增路径 的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。 不能 在 对角线 方向上移动或移动到 边界外(即不允许环绕)。 示例 1: 输入:matrix = [[9,9,4],[6,6,8],[2,1,1]] 输出:4 解释:最长递增路径为 [1, 2, 6, 9]。 示例 2: 输入:matrix = [[3,4,5]…
原文链接: https://leetcode-cn.com/problems/kplEvH 英文原文 中文题目「力扣挑战赛」中 `N*M` 大小的自行车炫技赛场的场地由一片连绵起伏的上下坡组成,场地的高度值记录于二维数组 `terrain` 中,场地的减速值记录于二维数组 `obstacle` 中。 - 若选手骑着自行车从高度为 `h1` 且减速值为 `o1` 的位置到高度为 `h2` 且减速值为 `o2` 的相邻位置(上下左右四个方向),速度变化值为 `h1-h2-o2`(负值减速,正值增速)…