Movatterモバイル変換


[0]ホーム

URL:


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

Commit8094a7e

Browse files
committed
update: 20
1 parentc8cf955 commit8094a7e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
2323
| 16|[3Sum Closest](https://leetcode.com/problems/3sum-closest/)|[JavaScript](./src/3sum-closest/res.js)| Medium|
2424
| 17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)|[JavaScript](./src/letter-combinations-of-a-phone-number/res.js)| Medium|
2525
| 19|[Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)|[JavaScript](./src/remove-nth-node-from-end-of-list/res.js)| Medium|
26+
| 20|[valid-parentheses](https://leetcode.com/problems/valid-parentheses/)|[TypeScript](./src/valid-parentheses/res.ts)| Easy|
2627
| 22|[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)|[JavaScript](./src/generate-parentheses/res.js)| Medium|
2728
| 24|[swap-nodes-in-pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)|[TypeScript](./src/swap-nodes-in-pairs/res.ts)| Medium|
2829
| 26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)|[JavaScript](./src/remove-duplicates-from-sorted-array/res.js)| Easy|

‎src/valid-parentheses/res.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
functionisValid(s:string):boolean{
2+
constsLength=s.length;
3+
if(sLength<2){
4+
return!sLength;
5+
}
6+
7+
letstack:string[]=[s[0]];
8+
9+
for(leti=1;i<sLength;i++){
10+
constcurrent=s[i];
11+
if(['{','(','['].includes(current)){
12+
stack.push(current);
13+
}elseif(['}',')',']'].includes(current)){
14+
constmatchedList=['{}','()','[]'];
15+
if(matchedList.includes(stack[stack.length-1]+current)){
16+
stack.pop();
17+
}elseif(stack.length){
18+
break;
19+
}else{
20+
stack.push(current);
21+
}
22+
}
23+
}
24+
25+
returnstack.length===0;
26+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp