-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathts.ts
34 lines (24 loc) · 775 Bytes
/
ts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import readlineSync from 'readline-sync'
const readline = () => readlineSync.prompt({ encoding: 'utf-8', prompt: '' })
// ------ Everything above this line will get cut when running copy script
const str = readline()
const stack = []
const charsOpen = '[{('.split('')
const charsClose = ']})'.split('')
let isGood = true
for (let i = 0; i < str.length; i++) {
// console.error(str[i])
if (charsOpen.includes(str[i])) {
stack.push(str[i])
} else if (charsClose.includes(str[i])) {
const lastOpen = stack.pop() as string
console.error(lastOpen, str[i])
if (charsClose.indexOf(str[i]) !== charsOpen.indexOf(lastOpen)) {
isGood = false
break
}
}
console.error()
}
console.error(stack)
console.log(isGood && stack.length === 0)