Skip to content

Commit

Permalink
Merge branch 'master' of github.com:youngyangyang04/leetcode-master
Browse files Browse the repository at this point in the history
  • Loading branch information
youngyangyang04 committed Jan 17, 2023
2 parents d52112c + 6d74c17 commit 653c0a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
8 changes: 3 additions & 5 deletions problems/0102.二叉树的层序遍历.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions problems/0150.逆波兰表达式求值.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion problems/0222.完全二叉树的节点个数.md
Original file line number Diff line number Diff line change
Expand Up @@ -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是有目的的,为了下面求指数方便
Expand Down Expand Up @@ -843,3 +843,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

0 comments on commit 653c0a1

Please sign in to comment.