diff --git a/solution/0000-0099/0046.Permutations/README_EN.md b/solution/0000-0099/0046.Permutations/README_EN.md index a49c7aa2567c..056f26bad408 100644 --- a/solution/0000-0099/0046.Permutations/README_EN.md +++ b/solution/0000-0099/0046.Permutations/README_EN.md @@ -17,7 +17,7 @@ tags: -

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

+

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

 

Example 1:

diff --git a/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md b/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md index 1df2c504fbd9..c50ea8c99c33 100644 --- a/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md +++ b/solution/0200-0299/0241.Different Ways to Add Parentheses/README.md @@ -57,6 +57,7 @@ tags:
  • 1 <= expression.length <= 20
  • expression 由数字和算符 '+''-''*' 组成。
  • 输入表达式中的所有整数值在范围 [0, 99] 
  • +
  • 输入表达式中的所有整数都没有前导 '-' 或 '+' 表示符号。
  • diff --git a/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md b/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md index 894e83e1a5bd..3d803c63fdf5 100644 --- a/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md +++ b/solution/0200-0299/0241.Different Ways to Add Parentheses/README_EN.md @@ -55,6 +55,7 @@ tags:
  • 1 <= expression.length <= 20
  • expression consists of digits and the operator '+', '-', and '*'.
  • All the integer values in the input expression are in the range [0, 99].
  • +
  • The integer values in the input expression do not have a leading '-' or '+' denoting the sign.
  • diff --git a/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md b/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md index 5862de27b597..0e762ef6fd4c 100644 --- a/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md +++ b/solution/0200-0299/0287.Find the Duplicate Number/README_EN.md @@ -23,7 +23,7 @@ tags:

    There is only one repeated number in nums, return this repeated number.

    -

    You must solve the problem without modifying the array nums and uses only constant extra space.

    +

    You must solve the problem without modifying the array nums and using only constant extra space.

     

    Example 1:

    diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md index bb61fc31744b..186ce882a509 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md @@ -29,7 +29,7 @@ tags:
     输入:n = 2
     输出:91
    -解释:答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。
    +解释:答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。 
     

    示例 2:

    diff --git a/solution/0400-0499/0438.Find All Anagrams in a String/README.md b/solution/0400-0499/0438.Find All Anagrams in a String/README.md index 2110c185a9f5..751abfe3739c 100644 --- a/solution/0400-0499/0438.Find All Anagrams in a String/README.md +++ b/solution/0400-0499/0438.Find All Anagrams in a String/README.md @@ -18,9 +18,7 @@ tags: -

    给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。

    - -

    异位词 指由相同字母重排列形成的字符串(包括相同的字符串)。

    +

    给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。

     

    diff --git a/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md b/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md index a84b5a544ec4..d7d1616bf1ef 100644 --- a/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md +++ b/solution/0400-0499/0438.Find All Anagrams in a String/README_EN.md @@ -18,9 +18,7 @@ tags: -

    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:

    diff --git a/solution/0500-0599/0567.Permutation in String/README.md b/solution/0500-0599/0567.Permutation in String/README.md index 5220856ba65d..ef8815d2d436 100644 --- a/solution/0500-0599/0567.Permutation in String/README.md +++ b/solution/0500-0599/0567.Permutation in String/README.md @@ -19,7 +19,7 @@ tags: -

    给你两个字符串 s1 和 s2 ,写一个函数来判断 s2 是否包含 s1 的排列。如果是,返回 true ;否则,返回 false

    +

    给你两个字符串 s1 和 s2 ,写一个函数来判断 s2 是否包含 s1 排列。如果是,返回 true ;否则,返回 false

    换句话说,s1 的排列之一是 s2子串

    diff --git a/solution/0500-0599/0567.Permutation in String/README_EN.md b/solution/0500-0599/0567.Permutation in String/README_EN.md index c1b2e5349668..dc9c2f639604 100644 --- a/solution/0500-0599/0567.Permutation in String/README_EN.md +++ b/solution/0500-0599/0567.Permutation in String/README_EN.md @@ -19,7 +19,7 @@ tags: -

    Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

    +

    Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

    In other words, return true if one of s1's permutations is the substring of s2.

    diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md index 7188711b1fb7..015e941acf43 100644 --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md @@ -25,7 +25,7 @@ tags:
     输入: n = 5
     输出: 5
    -解释:
    +解释: 
     下面列出范围在 [0, 5] 的非负整数与其对应的二进制表示:
     0 : 0
     1 : 1
    diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md
    index 470a1d720dd9..e989af0b602f 100644
    --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md	
    +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md	
    @@ -32,7 +32,7 @@ Here are the non-negative integers <= 5 with their corresponding binary repre
     3 : 11
     4 : 100
     5 : 101
    -Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule.
    +Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 
     

    Example 2:

    diff --git a/solution/0600-0699/0666.Path Sum IV/README_EN.md b/solution/0600-0699/0666.Path Sum IV/README_EN.md index a2a7c91da890..82cdad3b19f3 100644 --- a/solution/0600-0699/0666.Path Sum IV/README_EN.md +++ b/solution/0600-0699/0666.Path Sum IV/README_EN.md @@ -20,36 +20,48 @@ tags: -

    If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. For each integer in this array:

    +

    If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. You are given an ascending array nums consisting of three-digit integers representing a binary tree with a depth smaller than 5, where for each integer:

    -

    Given an array of ascending three-digit integers nums representing a binary tree with a depth smaller than 5, return the sum of all paths from the root towards the leaves.

    +

    Return the sum of all paths from the root towards the leaves.

    It is guaranteed that the given array represents a valid connected binary tree.

     

    Example 1:

    - -
    -Input: nums = [113,215,221]
    -Output: 12
    -Explanation: The tree that the list represents is shown.
    -The path sum is (3 + 5) + (3 + 1) = 12.
    -
    + +

    + +
    +

    Input: nums = [113,215,221]

    + +

    Output: 12

    + +

    Explanation:

    + +

    The tree that the list represents is shown.
    +The path sum is (3 + 5) + (3 + 1) = 12.

    +

    Example 2:

    - -
    -Input: nums = [113,221]
    -Output: 4
    -Explanation: The tree that the list represents is shown. 
    -The path sum is (3 + 1) = 4.
    -
    + +

    + +
    +

    Input: nums = [113,221]

    + +

    Output: 4

    + +

    Explanation:

    + +

    The tree that the list represents is shown. 
    +The path sum is (3 + 1) = 4.

    +

     

    Constraints:

    diff --git a/solution/0700-0799/0733.Flood Fill/README_EN.md b/solution/0700-0799/0733.Flood Fill/README_EN.md index baa48975fdd5..695663dd6381 100644 --- a/solution/0700-0799/0733.Flood Fill/README_EN.md +++ b/solution/0700-0799/0733.Flood Fill/README_EN.md @@ -19,13 +19,18 @@ tags: -

    An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.

    +

    You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fill on the image starting from the pixel image[sr][sc].

    -

    You are also given three integers sr, sc, and color. You should perform a flood fill on the image starting from the pixel image[sr][sc].

    +

    To perform a flood fill:

    -

    To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with color.

    +
      +
    1. Begin with the starting pixel and change its color to color.
    2. +
    3. Perform the same process for each pixel that is directly adjacent (pixels that share a side with the original pixel, either horizontally or vertically) and shares the same color as the starting pixel.
    4. +
    5. Keep repeating this process by checking neighboring pixels of the updated pixels and modifying their color if it matches the original color of the starting pixel.
    6. +
    7. The process stops when there are no more adjacent pixels of the original color to update.
    8. +
    -

    Return the modified image after performing the flood fill.

    +

    Return the modified image after performing the flood fill.

     

    Example 1:

    @@ -41,7 +46,7 @@ tags:

    From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.

    -

    Note the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.

    +

    Note the bottom corner is not colored 2, because it is not horizontally or vertically connected to the starting pixel.

    Example 2:

    diff --git a/solution/0900-0999/0912.Sort an Array/README.md b/solution/0900-0999/0912.Sort an Array/README.md index b2f6ed0ebcc2..7f047c913c19 100644 --- a/solution/0900-0999/0912.Sort an Array/README.md +++ b/solution/0900-0999/0912.Sort an Array/README.md @@ -25,6 +25,8 @@ tags:

    给你一个整数数组 nums,请你将该数组升序排列。

    +

    你必须在 不使用任何内置函数 的情况下解决问题,时间复杂度为 O(nlog(n)),并且空间复杂度尽可能小。

    +

     

      diff --git a/solution/1800-1899/1813.Sentence Similarity III/README_EN.md b/solution/1800-1899/1813.Sentence Similarity III/README_EN.md index b586818efcdd..c12ddb9e1897 100644 --- a/solution/1800-1899/1813.Sentence Similarity III/README_EN.md +++ b/solution/1800-1899/1813.Sentence Similarity III/README_EN.md @@ -20,36 +20,55 @@ tags: -

      A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercase and lowercase English letters.

      +

      You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters.

      -

      Two sentences sentence1 and sentence2 are similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. For example, sentence1 = "Hello my name is Jane" and sentence2 = "Hello Jane" can be made equal by inserting "my name is" between "Hello" and "Jane" in sentence2.

      +

      Two sentences s1 and s2 are considered similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. Note that the inserted sentence must be separated from existing words by spaces.

      -

      Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.

      +

      For example,

      + + + +

      Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.

       

      Example 1:

      -
      -Input: sentence1 = "My name is Haley", sentence2 = "My Haley"
      -Output: true
      -Explanation: sentence2 can be turned to sentence1 by inserting "name is" between "My" and "Haley".
      -
      +
      +

      Input: sentence1 = "My name is Haley", sentence2 = "My Haley"

      + +

      Output: true

      + +

      Explanation:

      + +

      sentence2 can be turned to sentence1 by inserting "name is" between "My" and "Haley".

      +

      Example 2:

      -
      -Input: sentence1 = "of", sentence2 = "A lot of words"
      -Output: false
      -Explanation: No single sentence can be inserted inside one of the sentences to make it equal to the other.
      -
      +
      +

      Input: sentence1 = "of", sentence2 = "A lot of words"

      + +

      Output: false

      + +

      Explanation:

      + +

      No single sentence can be inserted inside one of the sentences to make it equal to the other.

      +

      Example 3:

      -
      -Input: sentence1 = "Eating right now", sentence2 = "Eating"
      -Output: true
      -Explanation: sentence2 can be turned to sentence1 by inserting "right now" at the end of the sentence.
      -
      +
      +

      Input: sentence1 = "Eating right now", sentence2 = "Eating"

      + +

      Output: true

      + +

      Explanation:

      + +

      sentence2 can be turned to sentence1 by inserting "right now" at the end of the sentence.

      +

       

      Constraints:

      diff --git a/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md b/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md index 905435ae041d..e1c9aef5308f 100644 --- a/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md +++ b/solution/1900-1999/1945.Sum of Digits of String After Convert/README_EN.md @@ -19,50 +19,63 @@ tags: -

      You are given a string s consisting of lowercase English letters, and an integer k.

      +

      You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:

      -

      First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.

      +
        +
      1. Convert s into an integer by replacing each letter with its position in the alphabet (i.e. replace 'a' with 1, 'b' with 2, ..., 'z' with 26).
      2. +
      3. Transform the integer by replacing it with the sum of its digits.
      4. +
      5. Repeat the transform operation (step 2) k times in total.
      6. +

      For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:

      - +
    -

    Return the resulting integer after performing the operations described above.

    +

    Return the resulting integer after performing the operations described above.

     

    Example 1:

    -
    -Input: s = "iiii", k = 1
    -Output: 36
    -Explanation: The operations are as follows:
    -- Convert: "iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
    -- Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36
    -Thus the resulting integer is 36.
    -
    +
    +

    Input: s = "iiii", k = 1

    + +

    Output: 36

    + +

    Explanation:

    + +

    The operations are as follows:
    +- Convert: "iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
    +- Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36
    +Thus the resulting integer is 36.

    +

    Example 2:

    -
    -Input: s = "leetcode", k = 2
    -Output: 6
    -Explanation: The operations are as follows:
    -- Convert: "leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
    -- Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
    -- Transform #2: 33 ➝ 3 + 3 ➝ 6
    -Thus the resulting integer is 6.
    -
    +
    +

    Input: s = "leetcode", k = 2

    + +

    Output: 6

    + +

    Explanation:

    + +

    The operations are as follows:
    +- Convert: "leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
    +- Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
    +- Transform #2: 33 ➝ 3 + 3 ➝ 6
    +Thus the resulting integer is 6.

    +

    Example 3:

    -
    -Input: s = "zbax", k = 2
    -Output: 8
    -
    +
    +

    Input: s = "zbax", k = 2

    + +

    Output: 8

    +

     

    Constraints:

    diff --git a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md index 4b97b0cbba73..4e935c18db84 100644 --- a/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md +++ b/solution/2200-2299/2208.Minimum Operations to Halve Array Sum/README_EN.md @@ -35,7 +35,7 @@ The following is one of the ways to reduce the sum by at least half: Pick the number 19 and reduce it to 9.5. Pick the number 9.5 and reduce it to 4.75. Pick the number 8 and reduce it to 4. -The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75. +The final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75. The sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5. Overall, 3 operations were used so we return 3. It can be shown that we cannot reduce the sum by at least half in less than 3 operations. @@ -51,7 +51,7 @@ The following is one of the ways to reduce the sum by at least half: Pick the number 20 and reduce it to 10. Pick the number 10 and reduce it to 5. Pick the number 3 and reduce it to 1.5. -The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5. +The final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5. The sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5. Overall, 3 operations were used so we return 3. It can be shown that we cannot reduce the sum by at least half in less than 3 operations. diff --git a/solution/2600-2699/2687.Bikes Last Time Used/README.md b/solution/2600-2699/2687.Bikes Last Time Used/README.md index feeb362b818a..1df4bb0a8481 100644 --- a/solution/2600-2699/2687.Bikes Last Time Used/README.md +++ b/solution/2600-2699/2687.Bikes Last Time Used/README.md @@ -28,7 +28,9 @@ tags: | end_time | datetime | +-------------+----------+ ride_id 是该表的主键。 -每行包含一个骑行信息,包括 ride_id、自行车编号、骑行的起始和结束时间。 +每行包含一个骑行信息,包括 ride_id、自行车编号、骑行的起始和结束时间。 +输入保证 start_time 和 end_time 是有效的日期值。 +

    编写一个解决方案,找出每辆自行车 最近一次被使用 的时间。

    diff --git a/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md b/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md index 5faf3f375adf..1bdfa280fd99 100644 --- a/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md +++ b/solution/2600-2699/2687.Bikes Last Time Used/README_EN.md @@ -29,6 +29,8 @@ tags: +-------------+----------+ ride_id column contains unique values. Each row contains a ride information that includes ride_id, bike number, start and end time of the ride. +It is guaranteed that start_time and end_time are valid datetime values. +

    Write a solution to find the last time when each bike was used.

    diff --git a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md index e84aebd68c6e..9c939f87bf10 100644 --- a/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md +++ b/solution/3000-3099/3038.Maximum Number of Operations With the Same Score I/README.md @@ -47,7 +47,7 @@ tags:
     输入:nums = [3,2,6,1,4]
    -输出:1
    +输出:2
     解释:我们执行以下操作:
     - 删除前两个元素,分数为 3 + 2 = 5 ,nums = [6,1,4] 。
     由于下一次操作的分数与前一次不相等,我们无法继续进行任何操作。
    diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README.md b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README.md
    index 8d3c1bc8d4c8..be9583b7acda 100644
    --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README.md	
    +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README.md	
    @@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3294.Co
     
     
     
    -# [3294. Convert Doubly Linked List to Array II 🔒](https://leetcode.cn/problems/convert-doubly-linked-list-to-array-ii)
    +# [3294. 将双链表转换为数组 II 🔒](https://leetcode.cn/problems/convert-doubly-linked-list-to-array-ii)
     
     [English Version](/solution/3200-3299/3294.Convert%20Doubly%20Linked%20List%20to%20Array%20II/README_EN.md)
     
    @@ -14,34 +14,36 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3294.Co
     
     
     
    -

    You are given an arbitrary node from a doubly linked list, which contains nodes that have a next pointer and a previous pointer.

    +

    给定一个 双链表 的 任意 node,其中的节点具有指向下一个节点的指针和上一个节点的指针。

    -

    Return an integer array which contains the elements of the linked list in order.

    +

    返回一个 按顺序 包含链表中元素的整数数组。

     

    -

    Example 1:

    + +

    示例 1:

    -

    Input: head = [1,2,3,4,5], node = 5

    +

    输入:head = [1,2,3,4,5], node = 5

    -

    Output: [1,2,3,4,5]

    +

    输出:[1,2,3,4,5]

    -

    Example 2:

    +

    示例 2:

    -

    Input: head = [4,5,6,7,8], node = 8

    +

    输入:head = [4,5,6,7,8], node = 8

    -

    Output: [4,5,6,7,8]

    +

    输出:[4,5,6,7,8]

     

    -

    Constraints:

    + +

    提示:

    @@ -75,13 +77,12 @@ class Node: class Solution: def toArray(self, node: "Optional[Node]") -> List[int]: - cur = node - while cur and cur.prev: - cur = cur.prev + while node.prev: + node = node.prev ans = [] - while cur: - ans.append(cur.val) - cur = cur.next + while node: + ans.append(node.val) + node = node.next return ans ``` @@ -99,14 +100,12 @@ class Node { class Solution { public int[] toArray(Node node) { - var cur = node; - while (cur != null && cur.prev != null) { - cur = cur.prev; + while (node != null && node.prev != null) { + node = node.prev; } var ans = new ArrayList(); - while (cur != null) { - ans.add(cur.val); - cur = cur.next; + for (; node != null; node = node.next) { + ans.add(node.val); } return ans.stream().mapToInt(i -> i).toArray(); } @@ -130,14 +129,12 @@ class Solution { class Solution { public: vector toArray(Node* node) { - Node* cur = node; - while (cur && cur->prev) { - cur = cur->prev; + while (node && node->prev) { + node = node->prev; } vector ans; - while (cur) { - ans.push_back(cur->val); - cur = cur->next; + for (; node; node = node->next) { + ans.push_back(node->val); } return ans; } @@ -157,13 +154,11 @@ public: */ func toArray(node *Node) (ans []int) { - cur := node - for cur != nil && cur.Prev != nil { - cur = cur.Prev + for node != nil && node.Prev != nil { + node = node.Prev } - for cur != nil { - ans = append(ans, cur.Val) - cur = cur.Next + for ; node != nil; node = node.Next { + ans = append(ans, node.Val) } return } @@ -188,14 +183,12 @@ func toArray(node *Node) (ans []int) { */ function toArray(node: _Node | null): number[] { - let cur = node; - while (cur && cur.prev) { - cur = cur.prev; + while (node && node.prev) { + node = node.prev; } const ans: number[] = []; - while (cur) { - ans.push(cur.val); - cur = cur.next; + for (; node; node = node.next) { + ans.push(node.val); } return ans; } diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README_EN.md b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README_EN.md index 00d7b88a6e2e..bbb603284b23 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README_EN.md +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/README_EN.md @@ -75,13 +75,12 @@ class Node: class Solution: def toArray(self, node: "Optional[Node]") -> List[int]: - cur = node - while cur and cur.prev: - cur = cur.prev + while node.prev: + node = node.prev ans = [] - while cur: - ans.append(cur.val) - cur = cur.next + while node: + ans.append(node.val) + node = node.next return ans ``` @@ -99,14 +98,12 @@ class Node { class Solution { public int[] toArray(Node node) { - var cur = node; - while (cur != null && cur.prev != null) { - cur = cur.prev; + while (node != null && node.prev != null) { + node = node.prev; } var ans = new ArrayList(); - while (cur != null) { - ans.add(cur.val); - cur = cur.next; + for (; node != null; node = node.next) { + ans.add(node.val); } return ans.stream().mapToInt(i -> i).toArray(); } @@ -130,14 +127,12 @@ class Solution { class Solution { public: vector toArray(Node* node) { - Node* cur = node; - while (cur && cur->prev) { - cur = cur->prev; + while (node && node->prev) { + node = node->prev; } vector ans; - while (cur) { - ans.push_back(cur->val); - cur = cur->next; + for (; node; node = node->next) { + ans.push_back(node->val); } return ans; } @@ -157,13 +152,11 @@ public: */ func toArray(node *Node) (ans []int) { - cur := node - for cur != nil && cur.Prev != nil { - cur = cur.Prev + for node != nil && node.Prev != nil { + node = node.Prev } - for cur != nil { - ans = append(ans, cur.Val) - cur = cur.Next + for ; node != nil; node = node.Next { + ans = append(ans, node.Val) } return } @@ -188,14 +181,12 @@ func toArray(node *Node) (ans []int) { */ function toArray(node: _Node | null): number[] { - let cur = node; - while (cur && cur.prev) { - cur = cur.prev; + while (node && node.prev) { + node = node.prev; } const ans: number[] = []; - while (cur) { - ans.push(cur.val); - cur = cur.next; + for (; node; node = node.next) { + ans.push(node.val); } return ans; } diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.cpp b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.cpp index 0715dac7c638..8dd6779b22e0 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.cpp +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.cpp @@ -12,14 +12,12 @@ class Solution { public: vector toArray(Node* node) { - Node* cur = node; - while (cur && cur->prev) { - cur = cur->prev; + while (node && node->prev) { + node = node->prev; } vector ans; - while (cur) { - ans.push_back(cur->val); - cur = cur->next; + for (; node; node = node->next) { + ans.push_back(node->val); } return ans; } diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.go b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.go index 0b78caa070fe..31a6b68b7060 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.go +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.go @@ -8,13 +8,11 @@ */ func toArray(node *Node) (ans []int) { - cur := node - for cur != nil && cur.Prev != nil { - cur = cur.Prev + for node != nil && node.Prev != nil { + node = node.Prev } - for cur != nil { - ans = append(ans, cur.Val) - cur = cur.Next + for ; node != nil; node = node.Next { + ans = append(ans, node.Val) } return } diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.java b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.java index b1a89a618bfe..012b8b14b979 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.java +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.java @@ -9,14 +9,12 @@ class Node { class Solution { public int[] toArray(Node node) { - var cur = node; - while (cur != null && cur.prev != null) { - cur = cur.prev; + while (node != null && node.prev != null) { + node = node.prev; } var ans = new ArrayList(); - while (cur != null) { - ans.add(cur.val); - cur = cur.next; + for (; node != null; node = node.next) { + ans.add(node.val); } return ans.stream().mapToInt(i -> i).toArray(); } diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.py b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.py index da1b8def752d..98064e84063f 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.py +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.py @@ -10,11 +10,10 @@ def __init__(self, val, prev=None, next=None): class Solution: def toArray(self, node: "Optional[Node]") -> List[int]: - cur = node - while cur and cur.prev: - cur = cur.prev + while node.prev: + node = node.prev ans = [] - while cur: - ans.append(cur.val) - cur = cur.next + while node: + ans.append(node.val) + node = node.next return ans diff --git a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.ts b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.ts index d9b17f1588fc..02ec842f850f 100644 --- a/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.ts +++ b/solution/3200-3299/3294.Convert Doubly Linked List to Array II/Solution.ts @@ -14,14 +14,12 @@ */ function toArray(node: _Node | null): number[] { - let cur = node; - while (cur && cur.prev) { - cur = cur.prev; + while (node && node.prev) { + node = node.prev; } const ans: number[] = []; - while (cur) { - ans.push(cur.val); - cur = cur.next; + for (; node; node = node.next) { + ans.push(node.val); } return ans; } diff --git a/solution/README.md b/solution/README.md index e9f8a7ddfe40..762cdbd246b4 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3304,7 +3304,7 @@ | 3291 | [形成目标字符串需要的最少字符串数 I](/solution/3200-3299/3291.Minimum%20Number%20of%20Valid%20Strings%20to%20Form%20Target%20I/README.md) | `字典树`,`线段树`,`数组`,`字符串`,`二分查找`,`动态规划`,`字符串匹配`,`哈希函数`,`滚动哈希` | 中等 | 第 415 场周赛 | | 3292 | [形成目标字符串需要的最少字符串数 II](/solution/3200-3299/3292.Minimum%20Number%20of%20Valid%20Strings%20to%20Form%20Target%20II/README.md) | `线段树`,`数组`,`字符串`,`二分查找`,`动态规划`,`字符串匹配`,`哈希函数`,`滚动哈希` | 困难 | 第 415 场周赛 | | 3293 | [计算产品最终价格](/solution/3200-3299/3293.Calculate%20Product%20Final%20Price/README.md) | `数据库` | 中等 | 🔒 | -| 3294 | [Convert Doubly Linked List to Array II](/solution/3200-3299/3294.Convert%20Doubly%20Linked%20List%20to%20Array%20II/README.md) | | 中等 | 🔒 | +| 3294 | [将双链表转换为数组 II](/solution/3200-3299/3294.Convert%20Doubly%20Linked%20List%20to%20Array%20II/README.md) | | 中等 | 🔒 | ## 版权