Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequen

**Output:** [1]

**Example 3:**

**Input:** nums = [1,2,1,2,1,2,3,1,3,2], k = 2

**Output:** [1,2]

**Constraints:**

* <code>1 <= nums.length <= 10<sup>5</sup></code>
* <code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code>
* `k` is in the range `[1, the number of unique elements in the array]`.
* It is **guaranteed** that the answer is **unique**.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Medium

You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`.
You are given two integer arrays `nums1` and `nums2` sorted in **non-decreasing order** and an integer `k`.

Define a pair `(u, v)` which consists of one element from the first array and one element from the second array.

Expand All @@ -14,27 +14,20 @@ Return _the_ `k` _pairs_ <code>(u<sub>1</sub>, v<sub>1</sub>), (u<sub>2</sub>, v

**Output:** [[1,2],[1,4],[1,6]]

**Explanation:** The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]
**Explanation:** The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]

**Example 2:**

**Input:** nums1 = [1,1,2], nums2 = [1,2,3], k = 2

**Output:** [[1,1],[1,1]]

**Explanation:** The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]

**Example 3:**

**Input:** nums1 = [1,2], nums2 = [3], k = 3

**Output:** [[1,3],[2,3]]

**Explanation:** All possible pairs are returned from the sequence: [1,3],[2,3]
**Explanation:** The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]

**Constraints:**

* <code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code>
* <code>-10<sup>9</sup> <= nums1[i], nums2[i] <= 10<sup>9</sup></code>
* `nums1` and `nums2` both are sorted in **ascending order**.
* `1 <= k <= 1000`
* `nums1` and `nums2` both are sorted in **non-decreasing order**.
* <code>1 <= k <= 10<sup>4</sup></code>
* `k <= nums1.length * nums2.length`
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ You must implement the functions of the class such that each function works in *

* <code>-2<sup>31</sup> <= val <= 2<sup>31</sup> - 1</code>
* At most `2 * `<code>10<sup>5</sup></code> calls will be made to `insert`, `remove`, and `getRandom`.
* There will be **at least one** element in the data structure when `getRandom` is called.
* There will be **at least one** element in the data structure when `getRandom` is called.
8 changes: 4 additions & 4 deletions src/main/java/g0301_0400/s0383_ransom_note/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

Easy

Given two stings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed from `magazine` and `false` otherwise.
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`.

**Example 1:**

**Input:** ransomNote = "a", magazine = "b"

**Output:** false
**Output:** false

**Example 2:**

**Input:** ransomNote = "aa", magazine = "ab"

**Output:** false
**Output:** false

**Example 3:**

**Input:** ransomNote = "aa", magazine = "aab"

**Output:** true
**Output:** true

**Constraints:**

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/g0301_0400/s0392_is_subsequence/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ Easy

Given two strings `s` and `t`, return `true` _if_ `s` _is a **subsequence** of_ `t`_, or_ `false` _otherwise_.

A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of `"abcde"` while `"aec"` is not).
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of <code>"<ins>a</ins>b<ins>c</ins>d<ins>e</ins>"</code> while `"aec"` is not).

**Example 1:**

**Input:** s = "abc", t = "ahbgdc"

**Output:** true
**Output:** true

**Example 2:**

**Input:** s = "axc", t = "ahbgdc"

**Output:** false
**Output:** false

**Constraints:**

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/g0301_0400/s0394_decode_string/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Given an encoded string, return its decoded string.

The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer.

You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.
You may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there will not be input like `3a` or `2[4]`.

Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there won't be input like `3a` or `2[4]`.
The test cases are generated so that the length of the output will never exceed <code>10<sup>5</sup></code>.

**Example 1:**

Expand All @@ -28,12 +28,6 @@ Furthermore, you may assume that the original data does not contain any digits a

**Output:** "abcabccdcdcdef"

**Example 4:**

**Input:** s = "abc3[cd]xyz"

**Output:** "abccdcdcdxyz"

**Constraints:**

* `1 <= s.length <= 30`
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/g0301_0400/s0399_evaluate_division/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Return _the answers to all queries_. If a single answer cannot be determined, re

**Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.

**Note:** The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them.

**Example 1:**

**Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
Expand All @@ -28,13 +30,13 @@ return: [6.0, 0.5, -1.0, 1.0, -1.0 ]

**Input:** equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]

**Output:** [3.75000,0.40000,5.00000,0.20000]
**Output:** [3.75000,0.40000,5.00000,0.20000]

**Example 3:**

**Input:** equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]

**Output:** [0.50000,2.00000,-1.00000,-1.00000]
**Output:** [0.50000,2.00000,-1.00000,-1.00000]

**Constraints:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Medium

Given a **non-empty** array `nums` containing **only positive integers**, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_.

**Example 1:**

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

Medium

Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent the `grid` with a Quad-Tree.
Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent `grid` with a Quad-Tree.

Return _the root of the Quad-Tree_ representing the `grid`.

Notice that you can assign the value of a node to **True** or **False** when `isLeaf` is **False**, and both are **accepted** in the answer.
Return _the root of the Quad-Tree representing_ `grid`.

A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:

Expand Down Expand Up @@ -34,7 +32,7 @@ If you want to know more about the Quad-Tree, you can refer to the [wiki](https:

**Quad-Tree format:**

The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below.
You don't need to read this section for solving the problem. This is only if you want to understand the output format here. The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below.

It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list `[isLeaf, val]`.

Expand Down Expand Up @@ -75,4 +73,4 @@ If the value of `isLeaf` or `val` is True we represent it as **1** in the list `
**Constraints:**

* `n == grid.length == grid[i].length`
* <code>n == 2<sup>x</sup></code> where `0 <= x <= 6`
* <code>n == 2<sup>x</sup></code> where `0 <= x <= 6`
20 changes: 6 additions & 14 deletions src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,30 @@ Medium

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 string `end` where one mutation is defined as one single character changed in the gene string.
Suppose we need to investigate a mutation from a gene string `startGene` to a gene string `endGene` where one mutation is defined as one single character changed in the gene string.

* For example, `"AACCGGTT" --> "AACCGGTA"` is one mutation.

There is also a gene bank `bank` that records all the valid gene mutations. A gene must be in `bank` to make it a valid gene string.

Given the two gene strings `start` and `end` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `start` _to_ `end`. If there is no such a mutation, return `-1`.
Given the two gene strings `startGene` and `endGene` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `startGene` _to_ `endGene`. If there is no such a mutation, return `-1`.

Note that the starting point is assumed to be valid, so it might not be included in the bank.

**Example 1:**

**Input:** start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"]
**Input:** startGene = "AACCGGTT", endGene = "AACCGGTA", bank = ["AACCGGTA"]

**Output:** 1

**Example 2:**

**Input:** start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]
**Input:** startGene = "AACCGGTT", endGene = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]

**Output:** 2

**Example 3:**

**Input:** start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"]

**Output:** 3

**Constraints:**

* `start.length == 8`
* `end.length == 8`
* `0 <= bank.length <= 10`
* `bank[i].length == 8`
* `start`, `end`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`.
* `startGene.length == endGene.length == bank[i].length == 8`
* `startGene`, `endGene`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

Medium

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 rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
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**.

**Example 1:**

Expand Down Expand Up @@ -32,4 +30,4 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ
**Constraints:**

* <code>1 <= s.length, p.length <= 3 * 10<sup>4</sup></code>
* `s` and `p` consist of lowercase English letters.
* `s` and `p` consist of lowercase English letters.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Medium

Given an array of integers `nums` and an integer `k`, return _the total number of continuous subarrays whose sum equals to `k`_.
Given an array of integers `nums` and an integer `k`, return _the total number of subarrays whose sum equals to_ `k`.

A subarray is a contiguous **non-empty** sequence of elements within an array.

**Example 1:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Given the `root` of a binary tree, return _the average value of the nodes on eac

**Input:** root = [3,9,20,null,null,15,7]

**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].
**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg)

**Input:** root = [3,9,20,15,7]

**Output:** [3.00000,14.50000,11.00000]
**Output:** [3.00000,14.50000,11.00000]

**Constraints:**

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/g0701_0800/s0763_partition_labels/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Medium

You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part.
You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string `"ababcc"` can be partitioned into `["abab", "cc"]`, but partitions such as `["aba", "bcc"]` or `["ab", "ab", "cc"]` are invalid.

Note that the partition is done so that after concatenating all the parts in order, the resultant string should be `s`.

Return _a list of integers representing the size of these parts_.

Expand All @@ -12,11 +14,7 @@ Return _a list of integers representing the size of these parts_.

**Output:** [9,7,8]

**Explanation:**

The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.
**Explanation:** The partition is "ababcbaca", "defegde", "hijhklij". This is a partition so that each letter appears in at most one part. A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.

**Example 2:**

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ You start on square `1` of the board. In each move, starting from square `curr`,
* If `next` has a snake or ladder, you **must** move to the destination of that snake or ladder. Otherwise, you move to `next`.
* The game ends when you reach the square <code>n<sup>2</sup></code>.

A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and <code>n<sup>2</sup></code> do not have a snake or ladder.
A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and <code>n<sup>2</sup></code> are not the starting points of any snake or ladder.

Note that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder.
Note that you only take a snake or ladder at most once per dice roll. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder.

* For example, suppose the board is `[[-1,4],[-1,3]]`, and on the first move, your destination square is `2`. You follow the ladder to square `3`, but do **not** follow the subsequent ladder to `4`.

Return _the least number of moves required to reach the square_ <code>n<sup>2</sup></code>_. If it is not possible to reach the square, return_ `-1`.
Return _the least number of dice rolls required to reach the square_ <code>n<sup>2</sup></code>_. If it is not possible to reach the square, return_ `-1`.

**Example 1:**

Expand Down Expand Up @@ -45,11 +45,11 @@ This is the lowest possible number of moves to reach the last square, so return

**Input:** board = [[-1,-1],[-1,3]]

**Output:** 1
**Output:** 1

**Constraints:**

* `n == board.length == board[i].length`
* `2 <= n <= 20`
* `grid[i][j]` is either `-1` or in the range <code>[1, n<sup>2</sup>]</code>.
* The squares labeled `1` and <code>n<sup>2</sup></code> do not have any ladders or snakes.
* `board[i][j]` is either `-1` or in the range <code>[1, n<sup>2</sup>]</code>.
* The squares labeled `1` and <code>n<sup>2</sup></code> are not the starting points of any snake or ladder.