原文链接: https://leetcode-cn.com/problems/majority-element 英文原文Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element a…
标签详情
计数 分类
原文链接: https://leetcode-cn.com/problems/majority-element-ii 英文原文Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Example 1: Input: nums = [3,2,3] Output: [3] Example 2: Input: nums = [1] Output: [1…
原文链接: https://leetcode-cn.com/problems/bulls-and-cows 英文原文You are playing the Bulls and Cows game with your friend. You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint wit…
原文链接: https://leetcode-cn.com/problems/top-k-frequent-elements 英文原文Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] …
原文链接: https://leetcode-cn.com/problems/ransom-note 英文原文Given two stings ransomNote and magazine, return true if ransomNote can be constructed from magazine and false otherwise. Each letter in magazine can only be used once in ransomNote. Example 1: I…
原文链接: https://leetcode-cn.com/problems/first-unique-character-in-a-string 英文原文Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: Input: s = "leetcode" Output: 0 Example 2: …
原文链接: https://leetcode-cn.com/problems/sort-characters-by-frequency 英文原文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 in the string. Return the s…
原文链接: https://leetcode-cn.com/problems/task-scheduler 英文原文Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time…
原文链接: https://leetcode-cn.com/problems/top-k-frequent-words 英文原文Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequ…
原文链接: https://leetcode-cn.com/problems/reorganize-string 英文原文Given a string s, rearrange the characters of s so that any two adjacent characters are not the same. Return any possible rearrangement of s or return "" if not possible. Example 1: Input: …
原文链接: https://leetcode-cn.com/problems/reordered-power-of-2 英文原文You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this so that t…
原文链接: https://leetcode-cn.com/problems/rle-iterator 英文原文We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of…
原文链接: https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards 英文原文In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more gr…
原文链接: https://leetcode-cn.com/problems/3sum-with-multiplicity 英文原文Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target. As the answer can be very large, retu…
原文链接: https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique 英文原文You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1. Return the minimum number of moves to m…
原文链接: https://leetcode-cn.com/problems/subarrays-with-k-different-integers 英文原文Given an integer array nums and an integer k, return the number of good subarrays of nums. A good array is an array where the number of different integers in that array is…
原文链接: https://leetcode-cn.com/problems/pairs-of-songs-with-total-durations-divisible-by-60 英文原文You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in s…
原文链接: 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/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/number-of-equivalent-domino-pairs 英文原文Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino …
原文链接: https://leetcode-cn.com/problems/maximum-number-of-balloons 英文原文Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the…
原文链接: https://leetcode-cn.com/problems/split-a-string-in-balanced-strings 英文原文Balanced strings are those that have an equal quantity of 'L' and 'R' characters. Given a balanced string s, split it in the maximum amount of balanced strings. Return the …
原文链接: https://leetcode-cn.com/problems/count-servers-that-communicate 英文原文You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two serv…
原文链接: https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits 英文原文Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more …
原文链接: https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number 英文原文Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number …
原文链接: https://leetcode-cn.com/problems/construct-k-palindrome-strings 英文原文Given a string s and an integer k. You should construct k non-empty palindrome strings using all the characters in s. Return True if you can use all the characters in s to cons…
原文链接: https://leetcode-cn.com/problems/find-lucky-integer-in-an-array 英文原文Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value. Return a lucky integer in the array. If there are multiple …
原文链接: https://leetcode-cn.com/problems/minimum-number-of-frogs-croaking 英文原文You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multi…
原文链接: https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals 英文原文Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements. Example 1: Input: arr = [5,5,4], …
原文链接: https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k 英文原文Given an array of integers arr of even length n and an integer k. We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k…
1 / 2