LeetCode 950. Reveal Cards In Increasing Order

Problem Statement


use std::collections::VecDeque;

impl Solution {
pub fn deck_revealed_increasing(deck: Vec<i32>) -> Vec<i32> {
let mut d = deck;
d.sort();
let (mut q, n, mut ans) = (VecDeque::new(), d.len(), vec![0; d.len()]);
for i in 0..n {
q.push_back(i);
}
for i in 0..n {
let mut cur = q.front().unwrap().clone();
ans[cur] = d[i];
q.pop_front();
if q.is_empty() {
break;
}

cur = q.front().unwrap().clone();
q.push_back(cur);
q.pop_front();
}
return ans;
}
}