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

[pull] master from youngyangyang04:master #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 14 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
7d92df3
Update 0309.最佳买卖股票时机含冷冻期.md about rust
fwqaaq Jun 30, 2023
fc2a54a
Merge pull request #2160 from fwqaaq/patch-41
youngyangyang04 Jul 20, 2023
c3ebc91
更新 双指针总结 排版格式修复
jinbudaily Jul 20, 2023
de770c6
更新 栈与队列理论基础 排版格式修复
jinbudaily Jul 20, 2023
4b5e198
更新 0232.用栈实现队列 排版格式修复
jinbudaily Jul 20, 2023
c18dbf0
更新 0225.用队列实现栈 排版格式修复
jinbudaily Jul 20, 2023
a1ef2d0
更新 020.有效的括号 排版格式修复
jinbudaily Jul 20, 2023
70888c2
更新 1047.删除字符串中的所有相邻重复项 排版格式修复
jinbudaily Jul 20, 2023
7f4d740
更新 0150.逆波兰表达式求值 排版格式修复
jinbudaily Jul 20, 2023
5a6bf6d
更新 0239.滑动窗口最大值 排版格式修复
jinbudaily Jul 20, 2023
0e4f91d
更新 0347.前k个高频元素 排版格式修复
jinbudaily Jul 20, 2023
f7b87e6
更新 栈与队列总结 排版格式修复
jinbudaily Jul 20, 2023
5d76e86
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 20, 2023
e6b208a
Merge pull request #2194 from jinbudaily/master
youngyangyang04 Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions problems/0020.有效的括号.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
* 输入: "{[]}"
* 输出: true

# 思路
## 算法公开课

《代码随想录》算法视频公开课:[栈的拿手好戏!| LeetCode:20. 有效的括号](https://www.bilibili.com/video/BV1AF411w78g),相信结合视频在看本篇题解,更有助于大家对链表的理解
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[栈的拿手好戏!| LeetCode:20. 有效的括号](https://www.bilibili.com/video/BV1AF411w78g),相信结合视频再看本篇题解,更有助于大家对本题的理解**

## 思路

## 题外话
### 题外话

**括号匹配是使用栈解决的经典问题。**

Expand All @@ -68,7 +69,7 @@ cd a/b/c/../../

这里我就不过多展开了,先来看题。

## 进入正题
### 进入正题

由于栈结构的特殊性,非常适合做对称匹配类的题目。

Expand Down Expand Up @@ -143,8 +144,8 @@ public:

## 其他语言版本

### Java:

Java:
```Java
class Solution {
public boolean isValid(String s) {
Expand All @@ -171,7 +172,8 @@ class Solution {
}
```

Python:
### Python:

```python
# 方法一,仅使用栈,更省空间
class Solution:
Expand Down Expand Up @@ -213,7 +215,8 @@ class Solution:
return True if not stack else False
```

Go:
### Go:

```Go
func isValid(s string) bool {
hash := map[byte]byte{')':'(', ']':'[', '}':'{'}
Expand All @@ -235,7 +238,8 @@ func isValid(s string) bool {
}
```

Ruby:
### Ruby:

```ruby
def is_valid(strs)
symbol_map = {')' => '(', '}' => '{', ']' => '['}
Expand All @@ -253,7 +257,8 @@ def is_valid(strs)
end
```

Javascript:
### Javascript:

```javascript
var isValid = function (s) {
const stack = [];
Expand Down Expand Up @@ -296,7 +301,7 @@ var isValid = function(s) {
};
```

TypeScript:
### TypeScript:

版本一:普通版

Expand Down Expand Up @@ -348,7 +353,7 @@ function isValid(s: string): boolean {
};
```

Swift
### Swift:

```swift
func isValid(_ s: String) -> Bool {
Expand All @@ -373,7 +378,8 @@ func isValid(_ s: String) -> Bool {
}
```

C:
### C:

```C
//辅助函数:判断栈顶元素与输入的括号是否为一对。若不是,则返回False
int notMatch(char par, char* stack, int stackTop) {
Expand Down Expand Up @@ -414,8 +420,8 @@ bool isValid(char * s){
}
```

### C#:

C#:
```csharp
public class Solution {
public bool IsValid(string s) {
Expand Down Expand Up @@ -447,7 +453,8 @@ public class Solution {
}
```

PHP:
### PHP:

```php
// https://www.php.net/manual/zh/class.splstack.php
class Solution
Expand Down Expand Up @@ -475,8 +482,8 @@ class Solution
}
```

### Scala:

Scala:
```scala
object Solution {
import scala.collection.mutable
Expand All @@ -499,7 +506,7 @@ object Solution {
}
```

rust:
### Rust:

```rust
impl Solution {
Expand Down
38 changes: 21 additions & 17 deletions problems/0150.逆波兰表达式求值.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>




> 这不仅仅是一道好题,也展现出计算机的思考方式

# 150. 逆波兰表达式求值
Expand Down Expand Up @@ -63,9 +61,13 @@

* 适合用栈操作运算:遇到数字则入栈;遇到运算符则取出栈顶两个数字进行计算,并将结果压入栈中。

# 思路
## 算法公开课

**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[栈的最后表演! | LeetCode:150. 逆波兰表达式求值](https://www.bilibili.com/video/BV1kd4y1o7on),相信结合视频再看本篇题解,更有助于大家对本题的理解**。

《代码随想录》算法视频公开课:[栈的最后表演! | LeetCode:150. 逆波兰表达式求值](https://www.bilibili.com/video/BV1kd4y1o7on),相信结合视频再看本篇题解,更有助于大家对本题的理解。
## 思路

### 正题

在上一篇文章中[1047.删除字符串中的所有相邻重复项](https://programmercarl.com/1047.删除字符串中的所有相邻重复项.html)提到了 递归就是用栈来实现的。

Expand Down Expand Up @@ -117,7 +119,7 @@ public:
* 空间复杂度: O(n)


## 题外话
### 题外话

我们习惯看到的表达式都是中缀表达式,因为符合我们的习惯,但是中缀表达式对于计算机来说就不是很友好了。

Expand All @@ -134,11 +136,9 @@ public:
> During the 1970s and 1980s, Hewlett-Packard used RPN in all of their desktop and hand-held calculators, and continued to use it in some models into the 2020s.




## 其他语言版本

java:
### Java:

```Java
class Solution {
Expand All @@ -164,7 +164,7 @@ class Solution {
}
```

python3
### Python3:

```python
from operator import add, sub, mul
Expand Down Expand Up @@ -201,7 +201,8 @@ class Solution:

```

Go:
### Go:

```Go
func evalRPN(tokens []string) int {
stack := []int{}
Expand All @@ -228,7 +229,7 @@ func evalRPN(tokens []string) int {
}
```

javaScript:
### JavaScript:

```js
var evalRPN = function (tokens) {
Expand Down Expand Up @@ -259,7 +260,7 @@ var evalRPN = function (tokens) {
};
```

TypeScript:
### TypeScript:

普通版:

Expand Down Expand Up @@ -324,7 +325,8 @@ function evalRPN(tokens: string[]): number {
};
```

Swift:
### Swift:

```Swift
func evalRPN(_ tokens: [String]) -> Int {
var stack = [Int]()
Expand Down Expand Up @@ -357,7 +359,8 @@ func evalRPN(_ tokens: [String]) -> Int {
}
```

C#:
### C#:

```csharp
public int EvalRPN(string[] tokens) {
int num;
Expand Down Expand Up @@ -391,8 +394,8 @@ public int EvalRPN(string[] tokens) {
}
```

### PHP:

PHP:
```php
class Solution {
function evalRPN($tokens) {
Expand All @@ -417,7 +420,8 @@ class Solution {
}
```

Scala:
### Scala:

```scala
object Solution {
import scala.collection.mutable
Expand Down Expand Up @@ -447,7 +451,7 @@ object Solution {
}
```

rust:
### Rust:

```rust
impl Solution {
Expand Down
Loading

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