Leetcode Problem 484. Find Permutation

484. Find Permutation

Leetcode Solutions

Approach # Using Stack

  1. Initialize an empty stack and an empty list for the result.
  2. Iterate through the numbers from 1 to n+1 (inclusive).
  3. For each number, if the current character in s (or the end of s is reached) is 'I', push the number onto the stack.
  4. If the current character in s is 'I' or the end of s is reached, pop all elements from the stack and append them to the result.
  5. After the loop, if there are any remaining elements in the stack, pop them and append them to the result.
  6. Return the result list as the final permutation.
UML Thumbnail

Approach # Reversing the subarray

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...