Merge branch 'master' of github.com:youngyangyang04/leetcode-master

This commit is contained in:
programmercarl
2023-01-17 11:32:26 +08:00
3 changed files with 24 additions and 6 deletions

View File

@ -2532,20 +2532,18 @@ class Solution:
return 0
queue_ = [root]
result = []
depth = 0
while queue_:
length = len(queue_)
sub = []
for i in range(length):
cur = queue_.pop(0)
sub.append(cur.val)
#子节点入队列
if cur.left: queue_.append(cur.left)
if cur.right: queue_.append(cur.right)
result.append(sub)
depth += 1
return len(result)
return depth
```
Go

View File

@ -163,6 +163,25 @@ class Solution {
python3
```python
from operator import add, sub, mul
class Solution:
op_map = {'+': add, '-': sub, '*': mul, '/': lambda x, y: int(x / y)}
def evalRPN(self, tokens: List[str]) -> int:
stack = []
for token in tokens:
if token not in {'+', '-', '*', '/'}:
stack.append(int(token))
else:
op2 = stack.pop()
op1 = stack.pop()
stack.append(self.op_map[token](op1, op2)) # 第一个出来的在运算符后面
return stack.pop()
```
另一种可行但因为使用eval相对较慢的方法:
```python
class Solution:
def evalRPN(self, tokens: List[str]) -> int:

View File

@ -188,7 +188,7 @@ public:
```CPP
if (root == nullptr) return 0;
// 开始根据深度和深度是否相同来判断该子树是不是满二叉树
// 开始根据深度和深度是否相同来判断该子树是不是满二叉树
TreeNode* left = root->left;
TreeNode* right = root->right;
int leftDepth = 0, rightDepth = 0; // 这里初始为0是有目的的为了下面求指数方便
@ -843,3 +843,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>