原文链接: https://leetcode-cn.com/problems/contains-duplicate 英文原文Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Ex…
标签详情
哈希表 分类
原文链接: https://leetcode-cn.com/problems/contains-duplicate-ii 英文原文Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k. Example 1: Input: nums…
原文链接: 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/valid-anagram 英文原文Given two strings s and t, return true if t is an anagram of s, and false otherwise. Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "car" Output: f…
原文链接: https://leetcode-cn.com/problems/ugly-number-ii 英文原文An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the nth ugly number. Example 1: Input: n = 10 Output: 12 Explanation: [1, 2, 3, …
原文链接: https://leetcode-cn.com/problems/missing-number 英文原文Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums = [3,0,1] Output: 2 Explanatio…
原文链接: https://leetcode-cn.com/problems/word-pattern 英文原文Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. Example …
原文链接: 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/palindrome-pairs 英文原文Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome. Example 1…
原文链接: 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/intersection-of-two-arrays 英文原文Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Example 1: In…
原文链接: https://leetcode-cn.com/problems/intersection-of-two-arrays-ii 英文原文Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may retu…
原文链接: https://leetcode-cn.com/problems/design-twitter 英文原文Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed. Implement the Twitter cl…
原文链接: https://leetcode-cn.com/problems/insert-delete-getrandom-o1 英文原文Implement the RandomizedSet class: RandomizedSet() Initializes the RandomizedSet object. bool insert(int val) Inserts an item val into the set if not present. Returns true if the i…
原文链接: https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed 英文原文RandomizedCollection is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing …
原文链接: 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/find-the-difference 英文原文You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t. Example 1: …
原文链接: https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters 英文原文Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greate…
原文链接: https://leetcode-cn.com/problems/random-pick-index 英文原文Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array. Implement the …
原文链接: https://leetcode-cn.com/problems/longest-palindrome 英文原文Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example…
原文链接: https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array 英文原文Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n. Example 1: Input: nums = [3,10,5,25,2,8] Output: 28 Explanation: T…
原文链接: https://leetcode-cn.com/problems/reconstruct-original-digits-from-english 英文原文Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order. Example 1: Input: s = "owoztneoer" Output: "01…
原文链接: https://leetcode-cn.com/problems/all-oone-data-structure 英文原文Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts. Implement the AllOne class: AllOne() Initializes the object…
原文链接: https://leetcode-cn.com/problems/minimum-genetic-mutation 英文原文A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'. Suppose we need to investigate a mutation from a gene string start to a gene…
原文链接: https://leetcode-cn.com/problems/find-all-anagrams-in-a-string 英文原文Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. An Anagram is a word or phrase formed by rearra…
原文链接: https://leetcode-cn.com/problems/find-all-duplicates-in-an-array 英文原文Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that…
原文链接: https://leetcode-cn.com/problems/number-of-boomerangs 英文原文You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distan…
原文链接: https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array 英文原文Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1:…
原文链接: 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…