题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
let arr = [];
void async function () {
// Write your code here
while(line = await readline()){
let tokens = line.split(' ');
let len = arr.length;
if(tokens[0] == 'push') {
arr.push(parseInt(tokens[1]));
}else if(tokens[0] == 'pop') {
if(arr[len - 1]) {
console.log(arr[len - 1]);
arr.pop()
}else {
console.log("error");
}
}else if(tokens[0] == "top") {
if(arr[len - 1]) {
console.log(arr[len - 1]);
}else {
console.log("error");
}
}
}
}()
// 第一次做牛客的题目,感觉不是很顺手,不知道用户输入什么需要用什么获取,后面多做题吧!!!
算法题合集 文章被收录于专栏
自己做算法的解题代码
