vault backup: 2022-07-03 09:58:52

This commit is contained in:
juan 2022-07-03 09:58:52 +08:00
parent 23989ed98b
commit e9be4598c4
2 changed files with 73 additions and 2 deletions

View file

@ -9,7 +9,7 @@
> ##### Additional tags: > ##### Additional tags:
> #leetcode > #leetcode
> ##### Revisions: > ##### Revisions:
> Initial encounter: 2022-06-16 > 1st revision: 2022-07-03 optimize code
##### Related topics: ##### Related topics:
```expander ```expander
@ -60,6 +60,41 @@ Basic stack usage.
Can be implemented using std_stack or stc_vector. Can be implemented using std_stack or stc_vector.
obviously i should use std_stack. obviously i should use std_stack.
### Solution ### Solution
1st revision: optimized code
```cpp
class Solution {
public:
bool isValid(string s) {
stack<char> st;
char pairs[3][2] = {'(', ')', '{', '}', '[', ']'};
const int pairSize = 3;
for (char c : s) {
for (int i = 0; i < pairSize; i++) {
if (pairs[i][0] == c) {
// {([
st.push(c);
} else if (pairs[i][1] == c) {
// ]})
if (st.empty()) {
// empty
return false;
} else if (st.top() != pairs[i][0]) {
// mismatch
return false;
} else {
st.pop();
}
}
}
}
return st.empty();
}
};
```
```cpp ```cpp
class Solution { class Solution {
@ -99,4 +134,5 @@ public:
} }
}; };
``` ```

View file

@ -0,0 +1,35 @@
# Leetcode Implement-Queue-Using-Stacks
#### 2022-07-03 09:52
> ##### Data structures:
> #DS #stack #queue
> ##### Difficulty:
> #coding_problem #difficulty-easy
> ##### Additional tags:
> #leetcode #CS_list_need_understanding
> ##### Revisions:
> N/A
##### Related topics:
```expander
tag:#stack tag:#queue
```
##### Links:
- [Link to problem]()
___
### Problem
#### Examples
#### Constraints
### Thoughts
> [!summary]
> This is a #template_remove_me
### Solution