原文链接: https://leetcode-cn.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor 英文原文Given an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let's define a and b as follows: a = arr[…
标签详情
前缀和 分类
原文链接: https://leetcode-cn.com/problems/running-sum-of-1d-array 英文原文Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,…
原文链接: https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum 英文原文Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109 + 7. Example 1: Input: arr = [1,3,5]…
原文链接: https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target 英文原文Given an array nums and an integer target. Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in e…
原文链接: https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays 英文原文Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays. A subarray is a contiguous subsequence of the array. Return the sum of all odd…
原文链接: https://leetcode-cn.com/problems/maximum-sum-obtained-of-any-permutation 英文原文We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + …
原文链接: https://leetcode-cn.com/problems/minimum-operations-to-reduce-x-to-zero 英文原文You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its…
原文链接: https://leetcode-cn.com/problems/maximum-subarray-min-product 英文原文The min-product of an array is equal to the minimum value in the array multiplied by the array's sum. For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 *…
原文链接: https://leetcode-cn.com/problems/stone-game-viii 英文原文Alice and Bob take turns playing a game, with Alice starting first. There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the …
原文链接: https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered 英文原文You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and e…
原文链接: https://leetcode-cn.com/problems/find-the-student-that-will-replace-the-chalk 英文原文There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number…
原文链接: https://leetcode-cn.com/problems/minimum-space-wasted-from-packaging 英文原文You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply)…
原文链接: https://leetcode-cn.com/problems/number-of-wonderful-substrings 英文原文A wonderful string is a string where at most one letter appears an odd number of times. For example, "ccjjc" and "abab" are wonderful, but "ab" is not. Given a string word that…
原文链接: https://leetcode-cn.com/problems/describe-the-painting 英文原文There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique colo…
原文链接: https://leetcode-cn.com/problems/unique-length-3-palindromic-subsequences 英文原文Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same su…
原文链接: https://leetcode-cn.com/problems/find-the-middle-index-in-array 英文原文Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones). A middleIndex is an index where nums[0] + nums[1] + ... …
原文链接: https://leetcode-cn.com/problems/maximize-the-confusion-of-an-exam 英文原文A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecut…
原文链接: https://leetcode-cn.com/problems/maximum-number-of-ways-to-partition-an-array 英文原文You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions: 1 <= p…
原文链接: https://leetcode-cn.com/problems/grid-game 英文原文You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots i…
原文链接: https://leetcode-cn.com/problems/plates-between-candles 英文原文There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a pl…
原文链接: https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof 中文题目给定一个数组 A[0,1,…,n-1],请构建一个数组 B[0,1,…,n-1],其中 B[i] 的值是数组 A 中除了下标 i 以外的元素的积, 即 B[i]=A[0]×A[1]×…×A[i-1]×A[i+1]×…×A[n-1]。不能使用除法。 示例: 输入: [1,2,3,4,5] 输出: [120,60,40,30,24] 提示: 所有元素乘积之…
原文链接: https://leetcode-cn.com/problems/find-longest-subarray-lcci 英文原文Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers. Return the subarray. If there are more than one answer, retur…
原文链接: https://leetcode-cn.com/problems/max-submatrix-lcci 英文原文Given an NxM matrix of positive and negative integers, write code to find the submatrix with the largest possible sum. Return an array [r1, c1, r2, c2], where r1, c1 are the row number and…
原文链接: https://leetcode-cn.com/problems/2VG8Kg 中文题目给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 1: 输入:target = 7, nums = [2,3,1,2,4,3] 输出:2 解释:子数组 [4,3] 是该条件下…
原文链接: https://leetcode-cn.com/problems/tvdfij 中文题目给你一个整数数组 nums ,请计算数组的 中心下标 。 数组 中心下标 是数组的一个下标,其左侧所有元素相加的和等于右侧所有元素相加的和。 如果中心下标位于数组最左端,那么左侧数之和视为 0 ,因为在下标的左侧不存在元素。这一点对于中心下标位于数组最右端同样适用。 如果数组有多个中心下标,应该返回 最靠近左边 的那一个。如果数组不存在中心下标,返回 -1 。 示例 1: 输入:nums = [1…
原文链接: https://leetcode-cn.com/problems/A1NYOS 中文题目给定一个二进制数组 nums , 找到含有相同数量的 0 和 1 的最长连续子数组,并返回该子数组的长度。 示例 1: 输入: nums = [0,1] 输出: 2 说明: [0, 1] 是具有相同数量 0 和 1 的最长连续子数组。 示例 2: 输入: nums = [0,1,0] 输出: 2 说明: [0, 1] (或 [1, 0]) 是具有相同数量 0 和 1 的最长连续子数组。 提示: 1…
原文链接: https://leetcode-cn.com/problems/O4NDxx 中文题目给定一个二维矩阵 matrix,以下类型的多个请求: 计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2) 。 实现 NumMatrix 类: NumMatrix(int[][] matrix) 给定整数矩阵 matrix 进行初始化 int sumRegion(int row1, int col1, int row2, int col2…
原文链接: https://leetcode-cn.com/problems/cuyjEf 中文题目给定一个正整数数组 w ,其中 w[i] 代表下标 i 的权重(下标从 0 开始),请写一个函数 pickIndex ,它可以随机地获取下标 i,选取下标 i 的概率与 w[i] 成正比。 例如,对于 w = [1, 3],挑选下标 0 的概率为 1 / (1 + 3) = 0.25 (即,25%),而选取下标 1 的概率为 3 / (1 + 3) = 0.75(即,75%)。 也就是说,选取下标…
上一页
2 / 2