随笔分类 - LeetCode
摘要:Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum
阅读全文
摘要:You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be
阅读全文
摘要:Design a data structure that efficiently finds the majority element of a given subarray. The majority element of a subarray is an element that occurs
阅读全文
摘要:Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters. Ex
阅读全文
摘要:You have d dice and each die has f faces numbered 1, 2, ..., f. Return the number of possible ways (out of fd total ways) modulo 109 + 7 to roll the d
阅读全文
摘要:Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019-
阅读全文
摘要:You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that: subtexti is a non-empty string. The co
阅读全文
摘要:Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given len
阅读全文
摘要:Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and e
阅读全文
摘要:Given an array nums of integers, a move consists of choosing any element and decreasing it by 1. An array A is a zigzag array if either: Every even-in
阅读全文
摘要:Alice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of
阅读全文
摘要:Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn'
阅读全文
摘要:On an alphabet board, we start at position (0, 0), corresponding to character board[0][0]. Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy",
阅读全文
摘要:The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Exa
阅读全文
摘要:Given two arrays of integers with equal lengths, return the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| where the maximum is
阅读全文
摘要:Given an array arr of positive integers, consider all binary trees such that: Each node has either 0 or 2 children; The values of arr correspond to th
阅读全文
摘要:Consider a directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is either red or blue, and there could be self-edges or parall
阅读全文
摘要: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
阅读全文
摘要:In a project, you have a list of required skills req_skills, and a list of people. The ith person people[i] contains a list of skills that the person
阅读全文
摘要:We are given hours, a list of the number of hours worked per day for a given employee. A day is considered to be a tiring day if and only if the numbe
阅读全文