classMinStack{//用链表模拟栈,作为栈存储的容器classListNode{int val;//当前结点的值int min;//当前最小值。用一个变量模拟最小值栈ListNode next;//下一个结点publicListNode(){}publicListNode(int val,int min,ListNode next){this.val = val;this.min = min;//min就是最小值栈this.next = next;}}ListNode head;//头结点publicMinStack(){head =newListNode();//头结点初始化}//入栈操作publicvoidpush(int val){ListNode next = head.next, cur;//获取栈顶元素next,cur是当前要插入结点if(next !=null&& next.min < val){//如果栈不为空//但是当前栈中最小值,比val更小,那么将当前结点入栈,但是最小值依然保存next.mincur =newListNode(val, next.min, next);}else{//如果栈为空,直接入栈当前结点//或者栈不为空,但是当前结点的值更小的话,那么新的最小值为当前的val值cur =newListNode(val, val, next);}head.next = cur;//头插法,实现先入后出}//出栈publicvoidpop(){ListNode del = head.next;//取出栈顶元素head.next = del.next;//头结点指向新的栈顶元素}//获取栈顶元素的值publicinttop(){return head.next.val;}//获取最小值,就在栈顶元素的min变量中保存publicintgetMin(){return head.next.min;}}/*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(val);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.getMin();*//*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(val);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.getMin();*/
问题描述
PS E:\AWorkDataease\DataEase\core\core-frontend> npm run dev dataease0.0.0 dev NODE_OPTIONS–max_old_space_size4096 vite --mode dev --host 0.0.0.0 ‘NODE_OPTIONS’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
解决方案
遇到…
AtCoder Beginner Contest 341 D - Only one of two (Java)
比赛链接:AtCoder Beginner Contest 341
D题传送门AtCoder:D - Only one of two
D题传送门洛谷:[ABC341D] Only one of two
题目:[ABC341D】 Only one of two
题目…