use std::collections::VecDeque;
struct MinStack {
stack: VecDeque<i32>,
min_stack: VecDeque<i32>,
}
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl MinStack {
/** initialize your data structure here. */
fn new() -> Self {
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
}
fn push(&mut self, x: i32) {
self.stack.push_back(x);
if self.min_stack.is_empty() || *self.min_stack.back().unwrap() >= x {
self.min_stack.push_back(x);
}
}
fn pop(&mut self) {
let val = self.stack.pop_back().unwrap();
if *self.min_stack.back().unwrap() == val {
self.min_stack.pop_back();
}
}
fn top(&self) -> i32 {
*self.stack.back().unwrap()
}
fn get_min(&self) -> i32 {
*self.min_stack.back().unwrap()
}
}
/**
* Your MinStack object will be instantiated and called as such:
* let obj = MinStack::new();
* obj.push(x);
* obj.pop();
* let ret_3: i32 = obj.top();
* let ret_4: i32 = obj.get_min();
*/
Output code
use std::collections::VecDeque;
struct MinStack {
stack: VecDeque<i32>,
min_stack: VecDeque<i32>,
}
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl MinStack {
/** initialize your data structure here. */
fn new() -> Self {
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
}
fn push(&mut self, x: i32) {
self.stack.push_back(x);
if self.min_stack.is_empty() || *self.min_stack.back().unwrap() >= x {
self.min_stack.push_back(x);
}
}
fn pop(&mut self) {
let val = self.stack.pop_back().unwrap();
if *self.min_stack.back().unwrap() == val {
self.min_stack.pop_back();
}
}
fn top(&self) -> i32 {
*self.stack.back().unwrap()
}
fn get_min(&self) -> i32 {
*self.min_stack.back().unwrap()
}
}/**
* Your MinStack object will be instantiated and called as such:
* let obj = MinStack::new();
* obj.push(x);
* obj.pop();
* let ret_3: i32 = obj.top();
* let ret_4: i32 = obj.get_min();
*/
Additional context
Hello, thank you for developing such a useful Prettier plugin. I encountered two issues while using it:
Commented code blocks are also being formatted.
This plugin seems to be unable to format code blocks in Markdown files with triple backticks for Rust (rust). How should I handle this?
Input code
Output code
Additional context
Hello, thank you for developing such a useful Prettier plugin. I encountered two issues while using it:
rust
). How should I handle this?