946. Validate Stack Sequences Medium

@problem@discussion
#Array#Stack#Simulation



1/**
2 * [946] Validate Stack Sequences
3 *
4 * Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.
5 *  
6 * Example 1:
7 * 
8 * Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
9 * Output: true
10 * Explanation: We might do the following sequence:
11 * push(1), push(2), push(3), push(4),
12 * pop() -> 4,
13 * push(5),
14 * pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
15 * 
16 * Example 2:
17 * 
18 * Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
19 * Output: false
20 * Explanation: 1 cannot be popped before 2.
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= pushed.length <= 1000
26 * 	0 <= pushed[i] <= 1000
27 * 	All the elements of pushed are unique.
28 * 	popped.length == pushed.length
29 * 	popped is a permutation of pushed.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/validate-stack-sequences/
35// discuss: https://leetcode.com/problems/validate-stack-sequences/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn validate_stack_sequences(pushed: Vec<i32>, popped: Vec<i32>) -> bool {
41        false
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_946() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.