力扣_設計問題
阿新 • • 發佈:2022-03-08
打亂陣列
/** * Your Solution object will be instantiated and called as such: * Solution obj = new Solution(nums); * int[] param_1 = obj.reset(); * int[] param_2 = obj.shuffle(); */ //設定一個數組shuffle為了儲存調換後的陣列,否則就返回不了以前的值 //設定一個隨機數為了保證哪種調換都是有可能的 class Solution { int[] shuffle; int[] nums; Random random;最小棧
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack();public void pop() { stack.pop(); minStack.pop(); } public int top() { return stack.peek(); } public int getMin() { return minStack.peek(); } }