deno.land / x / masx200_leetcode_test@10.6.5 / valid-parentheses / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default function isValid(s: string): boolean { if (s.length === 0) return true; if (s.length % 2) return false; const stk = []; for (const ch of s) { if (pairs.has(ch)) { if (stk.length === 0) return false; if (stk.slice(-1)[0] !== pairs.get(ch)) return false; stk.pop(); } else { stk.push(ch); } } return stk.length === 0;}const pairs = new Map([ [")", "("], ["]", "["], ["}", "{"],]);
masx200_leetcode_test

Version Info

Tagged at
a year ago