number int64 1 2.6k | difficulty int64 0 2 | question stringlengths 294 4.95k |
|---|---|---|
225 | 0 | class MyStack:
def __init__(self):
def push(self, x: int) -> None:
def pop(self) -> int:
def top(self) -> int:
def empty(self) -> bool:
"""
Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push... |
226 | 0 | class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
"""
Given the root of a binary tree, invert the tree, and return its root.
Example 1:
Input: root = [4,2,7,1,3,6,9]
Output: [4,7,2,9,6,3,1]
Example 2:
Input: root = [2,1,3]
... |
227 | 1 | class Solution:
def calculate(self, s: str) -> int:
"""
Given a string s which represents an expression, evaluate this expression and return its value.
The integer division should truncate toward zero.
You may assume that the given expression is always valid. All intermediate result... |
228 | 0 | class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
"""
You are given a sorted unique integer array nums.
A range [a,b] is the set of all integers from a to b (inclusive).
Return the smallest sorted list of ranges that cover all the numbers in the array exactly. Th... |
229 | 1 | class Solution:
def majorityElement(self, nums: List[int]) -> List[int]:
"""
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]
... |
230 | 1 | class Solution:
def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
"""
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
Example 1:
Input: root = [3,1,4,null,2], k = 1
O... |
231 | 0 | class Solution:
def isPowerOfTwo(self, n: int) -> bool:
"""
Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output: true
E... |
232 | 0 | class MyQueue:
def __init__(self):
def push(self, x: int) -> None:
def pop(self) -> int:
def peek(self) -> int:
def empty(self) -> bool:
"""
Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (pu... |
233 | 2 | class Solution:
def countDigitOne(self, n: int) -> int:
"""
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
Example 1:
Input: n = 13
Output: 6
Example 2:
Input: n = 0
Output: 0
... |
234 | 0 | class Solution:
def isPalindrome(self, head: Optional[ListNode]) -> bool:
"""
Given the head of a singly linked list, return true if it is a palindrome or false otherwise.
Example 1:
Input: head = [1,2,2,1]
Output: true
Example 2:
Input: head = [1,2]
O... |
235 | 1 | class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
"""
Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common an... |
236 | 1 | class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
"""
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined... |
237 | 1 | class Solution:
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
There is a singly-linked list head and we want to delete a node node in it.
You are given the node to be deleted node. You will not be given... |
238 | 1 | class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
"""
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].
The product of any prefix or suffix of nums is guaranteed to fit in a 32-... |
239 | 2 | class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
"""
You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding wi... |
240 | 1 | class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
"""
Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:
Integers in each row are sorted in ascending from left to r... |
241 | 1 | class Solution:
def diffWaysToCompute(self, expression: str) -> List[int]:
"""
Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.
The test cases... |
242 | 0 | class Solution:
def isAnagram(self, s: str, t: str) -> bool:
"""
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exact... |
257 | 0 | class Solution:
def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:
"""
Given the root of a binary tree, return all root-to-leaf paths in any order.
A leaf is a node with no children.
Example 1:
Input: root = [1,2,3,null,5]
Output: ["1->2->5","1->3"]
... |
258 | 0 | class Solution:
def addDigits(self, num: int) -> int:
"""
Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.
Example 1:
Input: num = 38
Output: 2
Explanation: The process is
38 --> 3 + 8 --> 11
11 --... |
260 | 1 | class Solution:
def singleNumber(self, nums: List[int]) -> List[int]:
"""
Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
You must... |
263 | 0 | class Solution:
def isUgly(self, n: int) -> bool:
"""
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number.
Example 1:
Input: n = 6
Output: true
Explanation: 6 = 2 × 3
... |
264 | 1 | class Solution:
def nthUglyNumber(self, n: int) -> int:
"""
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, 4, 5, 6,... |
268 | 0 | class Solution:
def missingNumber(self, nums: List[int]) -> int:
"""
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
Explanation: n = ... |
273 | 2 | class Solution:
def numberToWords(self, num: int) -> str:
"""
Convert a non-negative integer num to its English words representation.
Example 1:
Input: num = 123
Output: "One Hundred Twenty Three"
Example 2:
Input: num = 12345
Output: "Twelve Thousand ... |
274 | 1 | class Solution:
def hIndex(self, citations: List[int]) -> int:
"""
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher's h-index.
According to the definition of h-index on Wikipedia: A sci... |
275 | 1 | class Solution:
def hIndex(self, citations: List[int]) -> int:
"""
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in an ascending order, return compute the researcher's h-index.
According to... |
278 | 0 | class Solution:
def firstBadVersion(self, n: int) -> int:
"""
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions af... |
279 | 1 | class Solution:
def numSquares(self, n: int) -> int:
"""
Given an integer n, return the least number of perfect square numbers that sum to n.
A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, ... |
282 | 2 | class Solution:
def addOperators(self, num: str, target: int) -> List[str]:
"""
Given a string num that contains only digits and an integer target, return all possibilities to insert the binary operators '+', '-', and/or '*' between the digits of num so that the resultant expression evaluates to the... |
283 | 0 | class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place witho... |
284 | 1 | """
Design an iterator that supports the peek operation on an existing iterator in addition to the hasNext and the next operations.
Implement the PeekingIterator class:
PeekingIterator(Iterator<int> nums) Initializes the object with the given integer iterator iterator.
in... |
287 | 1 | class Solution:
def findDuplicate(self, nums: List[int]) -> int:
"""
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.
There is only one repeated number in nums, return this repeated number.
You must solve the problem witho... |
289 | 1 | class Solution:
def gameOfLife(self, board: List[List[int]]) -> None:
"""
Do not return anything, modify board in-place instead.
According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in ... |
290 | 0 | class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
"""
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 1:
Input:... |
292 | 0 | class Solution:
def canWinNim(self, n: int) -> bool:
"""
You are playing the following Nim Game with your friend:
Initially, there is a heap of stones on the table.
You and your friend will alternate taking turns, and you go first.
On each turn, the person whose t... |
295 | 2 | class MedianFinder:
def __init__(self):
def addNum(self, num: int) -> None:
def findMedian(self) -> float:
"""
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.
... |
297 | 2 | class Codec:
def serialize(self, root):
"""Encodes a tree to a single string.
:type root: TreeNode
:rtype: str
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a ne... |
299 | 1 | class Solution:
def getHint(self, secret: str, guess: str) -> str:
"""
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 with the following info:
... |
300 | 1 | class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
"""
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Example 1:
Input: nums = [10,9,2,5,3,7,101,18]
Output: 4
Explanation: The longest increasing subsequence i... |
301 | 2 | class Solution:
def removeInvalidParentheses(self, s: str) -> List[str]:
"""
Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.
Return a list of unique strings that are valid with the minimum number of remo... |
303 | 0 | class NumArray:
def __init__(self, nums: List[int]):
def sumRange(self, left: int, right: int) -> int:
"""
Given an integer array nums, handle multiple queries of the following type:
Calculate the sum of the elements of nums between indices left and right inclusive where left <= righ... |
304 | 1 | class NumMatrix:
def __init__(self, matrix: List[List[int]]):
def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:
"""
Given a 2D matrix matrix, handle multiple queries of the following type:
Calculate the sum of the elements of matrix inside the rectangle defined ... |
306 | 1 | class Solution:
def isAdditiveNumber(self, num: str) -> bool:
"""
An additive number is a string whose digits can form an additive sequence.
A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the s... |
307 | 1 | class NumArray:
def __init__(self, nums: List[int]):
def update(self, index: int, val: int) -> None:
def sumRange(self, left: int, right: int) -> int:
"""
Given an integer array nums, handle multiple queries of the following types:
Update the value of an element in nums.
... |
309 | 1 | class Solution:
def maxProfit(self, prices: List[int]) -> int:
"""
You are given an array prices where prices[i] is the price of a given stock on the ith day.
Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the s... |
310 | 1 | class Solution:
def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:
"""
A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.
Given a tree of n nodes labelled from... |
312 | 2 | class Solution:
def maxCoins(self, nums: List[int]) -> int:
"""
You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.
If you burst the ith balloon, you will get nums[i - 1] * nums[... |
313 | 1 | class Solution:
def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:
"""
A super ugly number is a positive integer whose prime factors are in the array primes.
Given an integer n and an array of integers primes, return the nth super ugly number.
The nth super ugly number i... |
315 | 2 | class Solution:
def countSmaller(self, nums: List[int]) -> List[int]:
"""
Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].
Example 1:
Input: nums = [5,2,6,1]
Output: [2,1,1,0]
Explan... |
316 | 1 | class Solution:
def removeDuplicateLetters(self, s: str) -> str:
"""
Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.
Example 1:
Input: s = "... |
318 | 1 | class Solution:
def maxProduct(self, words: List[str]) -> int:
"""
Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.
Example 1:
Input: words = ["abcw","baz",... |
319 | 1 | class Solution:
def bulbSwitch(self, n: int) -> int:
"""
There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.
On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you ... |
321 | 2 | class Solution:
def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:
"""
You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
Create the maximum number ... |
322 | 1 | class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
"""
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.
Return the fewest number of coins that you need to make up that amoun... |
324 | 1 | class Solution:
def wiggleSort(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
You may assume the input array always has a valid answer.
Examp... |
326 | 0 | class Solution:
def isPowerOfThree(self, n: int) -> bool:
"""
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Example 1:
Input: n = 27
Output: true
... |
327 | 2 | class Solution:
def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:
"""
Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.
Range sum S(i, j) is defined as the sum of the elements in nums bet... |
328 | 1 | class Solution:
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
"""
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.
The first node is considered odd, and the s... |
329 | 2 | class Solution:
def longestIncreasingPath(self, matrix: List[List[int]]) -> int:
"""
Given an m x n integers matrix, return the length of the longest increasing path in matrix.
From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or mo... |
330 | 2 | class Solution:
def minPatches(self, nums: List[int], n: int) -> int:
"""
Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.
Return the minimum number o... |
331 | 1 | class Solution:
def isValidSerialization(self, preorder: str) -> bool:
"""
One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.
For example, the abov... |
332 | 2 | class Solution:
def findItinerary(self, tickets: List[List[str]]) -> List[str]:
"""
You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.
All of the tickets bel... |
334 | 1 | class Solution:
def increasingTriplet(self, nums: List[int]) -> bool:
"""
Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.
Example 1:
Input: nums = [1,2... |
335 | 2 | class Solution:
def isSelfCrossing(self, distance: List[int]) -> bool:
"""
You are given an array of integers distance.
You start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[... |
336 | 2 | class Solution:
def palindromePairs(self, words: List[str]) -> List[List[int]]:
"""
You are given a 0-indexed array of unique strings words.
A palindrome pair is a pair of integers (i, j) such that:
0 <= i, j < words.length,
i != j, and
words[i] + words[j]... |
337 | 1 | class Solution:
def rob(self, root: Optional[TreeNode]) -> int:
"""
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.
Besides the root, each house has one and only one parent house. After a tour, the smart thief realized tha... |
338 | 0 | class Solution:
def countBits(self, n: int) -> List[int]:
"""
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
Example 1:
Input: n = 2
Output: [0,1,1]
Explanation... |
341 | 1 | """
You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.
Implement the NestedIterator class:
NestedIterator(List<NestedInteger> nestedList) Initializes ... |
342 | 0 | class Solution:
def isPowerOfFour(self, n: int) -> bool:
"""
Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four, if there exists an integer x such that n == 4x.
Example 1:
Input: n = 16
Output: true
... |
343 | 1 | class Solution:
def integerBreak(self, n: int) -> int:
"""
Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.
Return the maximum product you can get.
Example 1:
Input: n = 2
Output: 1
Exp... |
344 | 0 | class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra... |
345 | 0 | class Solution:
def reverseVowels(self, s: str) -> str:
"""
Given a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.
Example 1:
Input: s = "hello"
... |
347 | 1 | class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
"""
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]
Exa... |
349 | 0 | class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
"""
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:
Input: nums1 ... |
350 | 0 | class Solution:
def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
"""
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 return the result in any order.
... |
352 | 2 | class SummaryRanges:
def __init__(self):
def addNum(self, value: int) -> None:
def getIntervals(self) -> List[List[int]]:
"""
Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals.
Implement the SummaryRa... |
354 | 2 | class Solution:
def maxEnvelopes(self, envelopes: List[List[int]]) -> int:
"""
You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.
One envelope can fit into another if and only if both the width and height of one en... |
355 | 1 | class Twitter:
def __init__(self):
def postTweet(self, userId: int, tweetId: int) -> None:
def getNewsFeed(self, userId: int) -> List[int]:
def follow(self, followerId: int, followeeId: int) -> None:
def unfollow(self, followerId: int, followeeId: int) -> None:
"""
Design a simplifie... |
357 | 1 | class Solution:
def countNumbersWithUniqueDigits(self, n: int) -> int:
"""
Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.
Example 1:
Input: n = 2
Output: 91
Explanation: The answer should be the total numbers in the rang... |
363 | 2 | class Solution:
def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int:
"""
Given an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k.
It is guaranteed that there will be a rectangle with a sum no larger th... |
365 | 1 | class Solution:
def canMeasureWater(self, jug1Capacity: int, jug2Capacity: int, targetCapacity: int) -> bool:
"""
You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly ta... |
367 | 0 | class Solution:
def isPerfectSquare(self, num: int) -> bool:
"""
Given a positive integer num, return true if num is a perfect square or false otherwise.
A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.
Yo... |
368 | 1 | class Solution:
def largestDivisibleSubset(self, nums: List[int]) -> List[int]:
"""
Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:
answer[i] % answer[j] == 0, or
... |
371 | 1 | class Solution:
def getSum(self, a: int, b: int) -> int:
"""
Given two integers a and b, return the sum of the two integers without using the operators + and -.
Example 1:
Input: a = 1, b = 2
Output: 3
Example 2:
Input: a = 2, b = 3
Output: 5
"... |
372 | 1 | class Solution:
def superPow(self, a: int, b: List[int]) -> int:
"""
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example 1:
Input: a = 2, b = [3]
Output: 8
Example 2:
... |
373 | 1 | class Solution:
def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:
"""
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
Define a pair (u, v) which consists of one element from the first array and one element fr... |
374 | 0 | class Solution:
def guessNumber(self, n: int) -> int:
"""
We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your ... |
375 | 1 | class Solution:
def getMoneyAmount(self, n: int) -> int:
"""
We are playing the Guessing Game. The game will work as follows:
I pick a number between 1 and n.
You guess a number.
If you guess the right number, you win the game.
If you guess the wrong n... |
376 | 1 | class Solution:
def wiggleMaxLength(self, nums: List[int]) -> int:
"""
A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one eleme... |
377 | 1 | class Solution:
def combinationSum4(self, nums: List[int], target: int) -> int:
"""
Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.
The test cases are generated so that the answer can fit in a 32-bit inte... |
378 | 1 | class Solution:
def kthSmallest(self, matrix: List[List[int]], k: int) -> int:
"""
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.
Note that it is the kth smallest element in the sorted order, not the kth d... |
380 | 1 | class RandomizedSet:
def __init__(self):
def insert(self, val: int) -> bool:
def remove(self, val: int) -> bool:
def getRandom(self) -> int:
"""
Implement the RandomizedSet class:
RandomizedSet() Initializes the RandomizedSet object.
bool insert(int val) Inserts a... |
381 | 2 | class RandomizedCollection:
def __init__(self):
def insert(self, val: int) -> bool:
def remove(self, val: int) -> bool:
def getRandom(self) -> int:
"""
RandomizedCollection is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should suppor... |
382 | 1 | class Solution:
def __init__(self, head: Optional[ListNode]):
def getRandom(self) -> int:
"""
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.
Implement the Solution class:
Solution(ListNo... |
383 | 0 | class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
"""
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.
Each letter in magazine can only be used once in ransomNote.
... |
384 | 1 | class Solution:
def __init__(self, nums: List[int]):
def reset(self) -> List[int]:
def shuffle(self) -> List[int]:
"""
Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.
... |
385 | 1 | """
Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.
Each element is either an integer or a list whose elements may also be integers or other lists.
Example 1:
Input: s = "324"
... |
386 | 1 | class Solution:
def lexicalOrder(self, n: int) -> List[int]:
"""
Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.
You must write an algorithm that runs in O(n) time and uses O(1) extra space.
Example 1:
Input: n = 13
Out... |
387 | 0 | class Solution:
def firstUniqChar(self, s: str) -> int:
"""
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:
Input: s = "loveleetcode"
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.