原文链接: https://leetcode-cn.com/problems/number-of-good-pairs 英文原文Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j. Example 1: Input: nums = [1,2,3,1,1,3] Output: 4 Explanati…
标签详情
数学 分类
原文链接: https://leetcode-cn.com/problems/number-of-substrings-with-only-1s 英文原文Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 109 + 7. Example 1: Input: s = "0110111…
原文链接: https://leetcode-cn.com/problems/best-position-for-a-service-centre 英文原文A delivery company wants to build a new service centre in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the n…
原文链接: https://leetcode-cn.com/problems/water-bottles 英文原文Given numBottles full water bottles, you can exchange numExchange empty water bottles for one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Ret…
原文链接: https://leetcode-cn.com/problems/minimum-operations-to-make-array-equal 英文原文You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e., 0 <= i < n). In one operation, you can select two indices x and y where 0 …
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-split-a-string 英文原文Given a binary string s (a string consisting only of '0's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s). Return the number of ways s can be s…
原文链接: https://leetcode-cn.com/problems/stone-game-v 英文原文There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue. In each round of the game, Alice divides the row into two no…
原文链接: 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/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/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers 英文原文Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: Type…
原文链接: https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments 英文原文Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments s…
原文链接: https://leetcode-cn.com/problems/fancy-sequence 英文原文Write an API that generates fancy sequences using the append, addAll, and multAll operations. Implement the Fancy class: Fancy() Initializes the object with an empty sequence. void append(val)…
原文链接: https://leetcode-cn.com/problems/maximum-number-of-visible-points 英文原文You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane. …
原文链接: https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls 英文原文You have an inventory of different colored balls, and there is a customer that wants orders balls of any color. The customer weirdly values the colored balls. Each color…
原文链接: https://leetcode-cn.com/problems/sum-of-all-subset-xor-totals 英文原文The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty. For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1. Giv…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible 英文原文There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from t…
原文链接: 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/minimum-cost-to-change-the-final-value-of-expression 英文原文You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),…
原文链接: https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors 英文原文You are given two identical eggs and you have access to a building with n floors labeled from 1 to n. You know that there exists a floor f where 0 <= f <= n such that any eg…
原文链接: https://leetcode-cn.com/problems/largest-odd-number-in-string 英文原文You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no od…
原文链接: https://leetcode-cn.com/problems/the-number-of-full-rounds-you-have-played 英文原文A new online video game has been released, and in this video game, there are 15-minute rounds scheduled every quarter-hour period. This means that at HH:00, HH:15, H…
原文链接: https://leetcode-cn.com/problems/count-square-sum-triples 英文原文A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2. Given an integer n, return the number of square triples such that 1 <= a, b, c <= n. Example 1: I…
原文链接: https://leetcode-cn.com/problems/sum-game 英文原文Alice and Bob take turns playing a game, with Alice starting first. You are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if…
原文链接: https://leetcode-cn.com/problems/count-good-numbers 英文原文A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7). For example, "2582" is good because the digits (2 and 8) …
原文链接: https://leetcode-cn.com/problems/three-divisors 英文原文Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false. An integer m is a divisor of n if there exists an integer k such that n = k * m. Example 1: I…
原文链接: https://leetcode-cn.com/problems/minimum-non-zero-product-of-the-array-elements 英文原文You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2p - 1] in their binary represen…
原文链接: https://leetcode-cn.com/problems/the-number-of-good-subsets 英文原文You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers. For example, if nums = [1, …
原文链接: https://leetcode-cn.com/problems/find-greatest-common-divisor-of-array 英文原文Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums. The greatest common divisor of two numbers is the larg…
原文链接: https://leetcode-cn.com/problems/number-of-pairs-of-interchangeable-rectangles 英文原文You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the it…
原文链接: https://leetcode-cn.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color 英文原文There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] …