From dacd1a91d4c4cfeeeebd77b3840118f1ba61e02d Mon Sep 17 00:00:00 2001 From: ZKkkk Date: Tue, 4 Jul 2023 19:46:00 +0800 Subject: [PATCH] =?UTF-8?q?Update=201221.=E5=88=86=E5=89=B2=E5=B9=B3?= =?UTF-8?q?=E8=A1=A1=E5=AD=97=E7=AC=A6=E4=B8=B2.md=20about=20TypeScript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1221.分割平衡字符串.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md index b587514a..2a7b0922 100644 --- a/problems/1221.分割平衡字符串.md +++ b/problems/1221.分割平衡字符串.md @@ -156,6 +156,21 @@ var balancedStringSplit = function(s) { }; ``` +### TypeScript + +```ts +function balancedStringSplit(s: string): number { + let count: number = 0 + let res: number = 0 + for(let i of s){ + if(i === 'R') count++ + else count-- + if(count === 0) res++ + } + + return res +}; +```