diff --git "a/2209040080/chapter 3/lc\345\237\272\346\234\254\350\256\241\347\256\227\346\234\2722.cpp." "b/2209040080/chapter 3/lc\345\237\272\346\234\254\350\256\241\347\256\227\346\234\2722.cpp." new file mode 100644 index 0000000000000000000000000000000000000000..0e61e3f178f2389cd43c78f3cc03f466fb72b2c6 --- /dev/null +++ "b/2209040080/chapter 3/lc\345\237\272\346\234\254\350\256\241\347\256\227\346\234\2722.cpp." @@ -0,0 +1,21 @@ +class Solution { +public: + int calculate(string s) { + int n = s.size(),dgt=0; + char preSign='+';//第一个数是正的 + vector v; + for(int i=0; i a; + queue b; + MyStack() { + + } + + void push(int x) { + b.push(x); + swap(a,b); + while(b.size()){ + a.push(b.front());b.pop(); + } + } + + int pop() { + int res = a.front(); + a.pop(); + return res; + } + + int top() { + return a.front(); + } + + bool empty() { + return a.empty(); + } +}; \ No newline at end of file diff --git "a/2209040080/chapter 3/lc\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp." "b/2209040080/chapter 3/lc\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp." new file mode 100644 index 0000000000000000000000000000000000000000..f49b0fba2b8c819879f2be955d2db8ffcbe810d1 --- /dev/null +++ "b/2209040080/chapter 3/lc\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp." @@ -0,0 +1,32 @@ +class Solution { +public: + int evalRPN(vector& tokens) { + stack st; + for (string s : tokens) { + if (s == "+") { + int a = st.top(); st.pop(); + int b = st.top(); st.pop(); + st.push(a+b); + } + else if (s == "-") { + int a = st.top(); st.pop(); + int b = st.top(); st.pop(); + st.push(b-a); + } + else if (s == "*") { + int a = st.top(); st.pop(); + int b = st.top(); st.pop(); + st.push(a*b); + } + else if (s == "/") { + int a = st.top(); st.pop(); + int b = st.top(); st.pop(); + st.push(b/a); + } + else { + st.push(stoi(s)); + } + } + return st.top(); + } +}; \ No newline at end of file diff --git "a/2209040080/chapter 6/lc\346\234\200\345\244\247\350\277\236\347\273\255 1 \347\232\204\344\270\252\346\225\260.cpp." "b/2209040080/chapter 6/lc\346\234\200\345\244\247\350\277\236\347\273\255 1 \347\232\204\344\270\252\346\225\260.cpp." new file mode 100644 index 0000000000000000000000000000000000000000..f4faa55149c4f8de7d25a07bd42674dee09be5f1 --- /dev/null +++ "b/2209040080/chapter 6/lc\346\234\200\345\244\247\350\277\236\347\273\255 1 \347\232\204\344\270\252\346\225\260.cpp." @@ -0,0 +1,19 @@ +class Solution { +public: + int findMaxConsecutiveOnes(vector& nums) { +int max = 0; + int count = 0; + for (int num : nums) { + if (num == 1) { + count++; + } else { + if (max < count) { + max = count; + } + count = 0; + } + } + return count > max ? count : max; + + } +}; \ No newline at end of file