Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 578c077

Browse files
Merge pull request greyireland#30 from Promacanthus/improve
IMPROVE: optimize the reverse function
2 parents 2741c8c + 158486d commit 578c077

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

‎data_structure/binary_tree.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,7 @@ func zigzagLevelOrder(root *TreeNode) [][]int {
640640
}
641641
func reverse(nums []int) {
642642
for i := 0; i < len(nums)/2; i++ {
643-
t := nums[i]
644-
nums[i] = nums[len(nums)-1-i]
645-
nums[len(nums)-1-i] = t
643+
nums[i], nums[len(nums)-1-i] = nums[len(nums)-1-i], nums[i]
646644
}
647645
}
648646
```

‎data_structure/stack_queue.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ func (this *MinStack) GetMin() int {
8383

8484
[evaluate-reverse-polish-notation](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/)
8585

86-
> **波兰表达式计算** > **输入:** ["2", "1", "+", "3", "*"] > **输出:** 9
87-
> **解释:** ((2 + 1) \* 3) = 9
86+
> **波兰表达式计算** > **输入:** `["2", "1", "+", "3", "*"]` > **输出:** 9
87+
>
88+
> **解释:** `((2 + 1) * 3) = 9`
8889
8990
思路:通过栈保存原来的元素,遇到表达式弹出运算,再推入结果,重复这个过程
9091

@@ -100,7 +101,7 @@ func evalRPN(tokens []string) int {
100101
if len(stack)<2{
101102
return -1
102103
}
103-
// 注意:a为除数,b为被除数
104+
// 注意:a为被除数,b为除数
104105
b:=stack[len(stack)-1]
105106
a:=stack[len(stack)-2]
106107
stack=stack[:len(stack)-2]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /