Skip to content

Commit 0fe437a

Browse files
authored
Refactor README for Next Greater Element IV
Updated formatting for clarity and consistency in the README.
1 parent ebdcc08 commit 0fe437a

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

solution/2400-2499/2454.Next Greater Element IV/README_EN.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -830,31 +830,30 @@ class TreeMultiSet<T = number> {
830830

831831
<!-- solution:end -->
832832

833-
<!-- problem:end -->
834-
835833
### Solution 2: Double Stacks
834+
836835
We maintain two decreasing monotonic stacks:
837836

838-
```stackOne```: stores elements that have not yet encountered any greater element to their right.
837+
`stackOne`: stores elements that have not yet encountered any greater element to their right.
839838

840-
```stackTwo```: stores elements that have encountered exactly one greater element to their right.
839+
`stackTwo`: stores elements that have encountered exactly one greater element to their right.
841840

842841
Algorithm:
843842

844-
As we iterate through the array ```nums```, for current element $nums[k]$, have these steps:
843+
As we iterate through the array `nums`, for current element $nums[k]$, have these steps:
845844

846-
1. While ```stackTwo``` is not empty and its top element is less than $nums[k]$,
845+
1. While `stackTwo` is not empty and its top element is less than $nums[k]$,
847846
these top elements have found their second next greater element.
848847
Pop them and record $nums[k]$ as the answer for their respective indices.
849848

850-
2. While ```stackOne``` is not empty and its top element is less than $nums[k]$,
849+
2. While `stackOne` is not empty and its top element is less than $nums[k]$,
851850
these top elements have found their first next greater element.
852-
Pop them to move them to a temporary list/vector called ```transporter```.
851+
Pop them to move them to a temporary list/vector called `transporter`.
853852

854-
3. Pop all elements from the back of ```transporter``` and push them onto ```stackTwo```.
855-
These elements will naturally maintain the decreasing order in ```stackTwo```.
853+
3. Pop all elements from the back of `transporter` and push them onto `stackTwo`.
854+
These elements will naturally maintain the decreasing order in `stackTwo`.
856855

857-
4. Push current element $nums[k]$ into ```stackOne``` for future comparisons.
856+
4. Push current element $nums[k]$ into `stackOne` for future comparisons.
858857

859858
Our time complexity is $O(n)$, where $n$ is the length of the array nums.
860859

0 commit comments

Comments
 (0)