classCQueue{public:
stack<int> stack1;
stack<int> stack2;CQueue(){}voidappendTail(int value){
stack1.push(value);}intdeleteHead(){int ret =-1;if(stack2.empty()){while(!stack1.empty()){int temp = stack1.top();
stack2.push(temp);
stack1.pop();}}if(stack2.empty()){return ret;}
ret = stack2.top();
stack2.pop();return ret;}};/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/
classSolution{public:intfib(int n){int MOD =1000000007;if(n <=1){return n;}// return fib(n - 1) + fib(n - 2);int a =0, b =1, c;for(int i =2; i <= n; i ++){
c =(a + b)%1000000007;
a = b;
b = c;}return c;}};
classSolution{public:boolexist(vector<vector<char>>& board, string word){
rows = board.size();
cols = board[0].size();for(int i =0; i < rows; i++){for(int j =0; j < cols; j++){if(dfs(board, word, i, j,0))returntrue;}}returnfalse;}private:int rows, cols;booldfs(vector<vector<char>>& board, string word,int i,int j,int k){if(i >= rows || i <0|| j >= cols || j <0|| board[i][j]!= word[k])returnfalse;if(k == word.size()-1)returntrue;
board[i][j]='\0';bool res =dfs(board, word, i +1, j, k +1)||dfs(board, word, i -1, j, k +1)||dfs(board, word, i, j +1, k +1)||dfs(board, word, i , j -1, k +1);
board[i][j]= word[k];return res;}};
classSolution{public:intcuttingRope(int n){if(n <=3)return n -1;int MOD =1000000007;long ret =1;if(n %3==1){//3 * 1 < 4
ret =4;
n = n -4;}if(n %3==2){
ret =2;
n = n -2;}while(n){
n = n -3;
ret = ret *3% MOD;}return ret;}};
classSolution{public:doublemyPow(double x,int n){//用二进制想问题 11(3)、2^10double ret =1.0;for(int i = n; i !=0; i /=2){if(i %2!=0){
ret *= x;}
x *= x;}return n >=0? ret :1/ ret;}};
classSolution{public:boolisNumber(string s){//正则表达式 确定有限状态自动机(DFA)// 空格 +/- 数字 . E/e int tansfer[9][5]={{0,1,2,4,-1},{-1,-1,2,4,-1},{8,-1,2,3,5},{8,-1,3,-1,5},{-1,-1,3,-1,-1},{-1,6,7,-1,-1},{-1,-1,7,-1,-1},{8,-1,7,-1,-1},{8,-1,-1,-1,-1}};int state =0;for(char ch : s){if(ch ==' ') state = tansfer[state][0];elseif(ch =='+'|| ch =='-') state = tansfer[state][1];elseif(isdigit(ch)) state = tansfer[state][2];elseif(ch =='.') state = tansfer[state][3];elseif(ch =='E'|| ch =='e') state = tansfer[state][4];else state =-1;if(state ==-1)returnfalse;}return state ==2|| state ==3|| state ==7|| state ==8;}};
classMinStack{public:
stack<int> sk;
stack<int> sk_m;/** initialize your data structure here. */MinStack(){
sk_m.push(INT_MAX);}voidpush(int x){
sk.push(x);
sk_m.push(std::min(x, sk_m.top()));}voidpop(){
sk.pop();
sk_m.pop();}inttop(){return sk.top();}intmin(){return sk_m.top();}};/**
* Your MinStack object will be instantiated and called as such:
* MinStack* obj = new MinStack();
* obj->push(x);
* obj->pop();
* int param_3 = obj->top();
* int param_4 = obj->min();
*/
classSolution{public:boolvalidateStackSequences(vector<int>& pushed, vector<int>& popped){int len = pushed.size(), index =0;// vector<int> mp;// for (int i = 0; i < len; i++) {// mp[pushed[i]] = i;// }// for (auto& ch : popped) {// }
stack<int> sk;for(int i =0; i < len; i++){
sk.push(pushed[i]);while(index < len &&!sk.empty()&& popped[index]== sk.top()){
index++;
sk.pop();}}return index == len ?true:false;}};