Leetcode Problem 484. Find Permutation
484. Find Permutation
AI Mock Interview
Leetcode Solutions
Approach # Using Stack
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize an empty stack and an empty list for the result.
Iterate through the numbers from 1 to n+1 (inclusive).
For each number, if the current character in
s
(or the end of
s
is reached) is 'I', push the number onto the stack.
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.
After the loop, if there are any remaining elements in the stack, pop them and append them to the result.
Return the result list as the final permutation.
Approach # Reversing the subarray
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...