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 +}; +```