原文链接: https://leetcode-cn.com/problems/longest-arithmetic-subsequence 英文原文Given an array nums of integers, return the length of the longest arithmetic subsequence in nums. Recall that a subsequence of an array nums is a list nums[i1], nums[i2], ..., …
分类详情
中等 分类
原文链接: https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor 英文原文Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A nod…
原文链接: https://leetcode-cn.com/problems/two-city-scheduling 英文原文A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the it…
原文链接: https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays 英文原文Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and…
原文链接: https://leetcode-cn.com/problems/moving-stones-until-consecutive 英文原文There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones. In one move, you pick up a stone at an endp…
原文链接: https://leetcode-cn.com/problems/coloring-a-border 英文原文You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location. Two squares belong to th…
原文链接: https://leetcode-cn.com/problems/uncrossed-lines 英文原文You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a stra…
原文链接: https://leetcode-cn.com/problems/minimum-score-triangulation-of-polygon 英文原文You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex (i.e., cl…
原文链接: https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii 英文原文There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones. Call a stone an endpoint stone if it has the…
原文链接: https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree 英文原文Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all ke…
原文链接: https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree 英文原文Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of n…
原文链接: https://leetcode-cn.com/problems/as-far-from-land-as-possible 英文原文Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized…
原文链接: https://leetcode-cn.com/problems/robot-bounded-in-circle 英文原文On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions: "G": go straight 1 unit; "L": turn 90 degrees to the left; "…
原文链接: https://leetcode-cn.com/problems/flower-planting-with-no-adjacent 英文原文You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want …
原文链接: https://leetcode-cn.com/problems/partition-array-for-maximum-sum 英文原文Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maxim…
原文链接: https://leetcode-cn.com/problems/longest-string-chain 英文原文You are given an array of words where each word consists of lowercase English letters. wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA w…
原文链接: https://leetcode-cn.com/problems/last-stone-weight-ii 英文原文You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them tog…
原文链接: https://leetcode-cn.com/problems/grumpy-bookstore-owner 英文原文There is a bookstore owner that has a store open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers of length n where custo…
原文链接: https://leetcode-cn.com/problems/previous-permutation-with-one-swap 英文原文Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly…
原文链接: https://leetcode-cn.com/problems/distant-barcodes 英文原文In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i]. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guar…
原文链接: https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows 英文原文You are given an m x n binary matrix matrix. You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the…
原文链接: https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths 英文原文Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree. A no…
原文链接: https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters 英文原文Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once. Example 1: Input: s = "bcabc"…
原文链接: https://leetcode-cn.com/problems/largest-values-from-labels 英文原文There is a set of n items. You are given two integer arrays values and labels where the value and the label of the ith element are values[i] and labels[i] respectively. You are als…
原文链接: https://leetcode-cn.com/problems/statistics-from-a-large-sample 英文原文You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count where count[k] is the number of times that k a…
原文链接: https://leetcode-cn.com/problems/car-pooling 英文原文There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west). You are given the integer capacity and an array trips where trip[i] = [numPass…
原文链接: https://leetcode-cn.com/problems/building-h2o 英文原文There are two kinds of threads: oxygen and hydrogen. Your goal is to group these threads to form water molecules. There is a barrier where each thread has to wait until a complete molecule can b…
原文链接: https://leetcode-cn.com/problems/print-foobar-alternately 英文原文Suppose you are given the following code: class FooBar { public void foo() { for (int i = 0; i < n; i++) { print("foo"); } } public void bar() { for (int i = 0; i < n; i++) { print("…
原文链接: https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree 英文原文In an infinite binary tree where every node has two children, the nodes are labelled in row order. In the odd numbered rows (ie., the first, third, fifth,...), the labelli…
原文链接: https://leetcode-cn.com/problems/filling-bookcase-shelves 英文原文You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth. We want to place the…