Skip to content

Commit fd9b644

Browse files
committed
Merge branch 'master' of github.com:doocs/leetcode
2 parents b898467 + 2639758 commit fd9b644

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

solution/020.Valid Parentheses/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
### 解法
4343
遍历 string,遇到左括号,压入栈中;遇到右括号,从栈中弹出元素,元素不存在或者元素与该右括号不匹配,返回 false。遍历结束,栈为空则返回 true,否则返回 false。
4444

45-
因为字符串只包含"(){}[]",也可以进行特殊处理,用映射来做
45+
因为字符串只包含"(){}[]",也可以进行特殊处理,用映射来做
4646

47-
#### java
48-
```
47+
#### Java 版实现
48+
```java
4949
class Solution {
5050
public boolean isValid(String s) {
5151
if (s == null || s == "") {
@@ -85,8 +85,8 @@ class Solution {
8585
}
8686
```
8787

88-
#### C++
89-
```
88+
#### C++ 版实现
89+
```cpp
9090

9191
class Solution {
9292
public:
@@ -135,7 +135,7 @@ public:
135135
}
136136
};
137137

138-
//特殊
138+
// 特殊
139139
class Solution {
140140
public:
141141
bool isValid(string s) {
@@ -165,4 +165,4 @@ public:
165165
}
166166
};
167167

168-
```
168+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int firstUniqChar(string s) {
4+
vector<int> cnts(26, 0), pos(26, s.size()) ;
5+
6+
7+
for (int i = s.size()-1; i >= 0; --i)
8+
{
9+
int index = s[i] - 'a' ;
10+
cnts[index]++ ;
11+
pos[index] = i ;
12+
}
13+
14+
int p = s.size() ;
15+
for (int i = 0; i < 26; ++i)
16+
{
17+
if (cnts[i] == 1 && pos[i] < p)
18+
p = pos[i] ;
19+
}
20+
21+
return p != s.size()? p: -1 ;
22+
}
23+
};

0 commit comments

Comments
 (0)