以leetcode 20为例
0.首先编写代码
function isValid(s: string): boolean {let stack: string[] = []for (let index = 0; index < s.length; index++) {let x: string = s[index]debuggerswitch (x) {case '(':stack.push(')')breakcase '[':stack.push(']')breakcase '{':stack.push('}')breakdefault:if (stack.pop() !== x) {debuggerreturn false}break}}return stack.length === 0
}const str1: string = '({{}}{}[])'
const str2: string = '({{[}{]}}[])'
const str3: string = '({{}}{}[]])'
console.log(isValid(str1)) //true
console.log(isValid(str2)) //false
console.log(isValid(str3)) //false
2.编译ts文件,运行js文件
PS C:\Desktop\软件开发\编程\ts-leetcode-hot100\Stack05\VaildBracket20> tsc .\VB20.ts
PS C:\Desktop\软件开发\编程\ts-leetcode-hot100\Stack05\VaildBracket20> node .\VB20.js
true
false
false
3.在代码中添加断点(上边的源码中加过了),并运行调试器
PS C:\Desktop\软件开发\编程\ts-leetcode-hot100\Stack05\VaildBracket20> node --inspect-brk .\VB20.js
Debugger listening on ws://127.0.0.1:9229/a32c1233-13d9-4de6-83aa-540fb4227c8d
For help, see: https://nodejs.org/en/docs/inspector
4.(谷歌)浏览器中输入
127.0.0.1:9229/a32c1233-13d9-4de6-83aa-540fb4227c8d
5.在开启一个窗口输入
chrome://inspect
稍等一会,点击
6.开始调试