尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
LeetCode //C - 1221. Split a String in Balanced Strings
1221. Split a String in Balanced StringsBalanced strings are those that have an equal quantity of ‘L’ and ‘R’ characters.Given a balanced string s, split it into some number of substrings such that:Each substring is balanced.Returnthe maximum number of balanced strings you can obtain.Example 1:Input:s “RLRRLLRLRL”Output:4Explanation:s can be split into “RL”, “RRLL”, “RL”, “RL”, each substring contains same number of ‘L’ and ‘R’.Example 2:Input:s “RLRRRLLRLL”Output:2Explanation:s can be split into “RL”, “RRRLLRLL”, each substring contains same number of ‘L’ and ‘R’.Note that s cannot be split into “RL”, “RR”, “RL”, “LR”, “LL”, because the 2nd and 5th substrings are not balanced.Example 3:Input:s “LLLLRRRR”Output:1Explanation:s can be split into “LLLLRRRR”.Constraints:2 s.length 1000s[i] is either ‘L’ or ‘R’.s is a balanced string.From: LeetCodeLink: 1221. Split a String in Balanced StringsSolution:Ideas:use a counter. Add 1 for R, -1 for L. Every time counter becomes 0, we found one balanced substring.Code:intbalancedStringSplit(char*s){intbalance0;intcount0;for(inti0;s[i]!\0;i){if(s[i]R){balance;}else{balance--;}if(balance0){count;}}returncount;}
RELATED

相关推荐

2019牛客二模编程题复盘:核心题型与笔试避坑指南

2019牛客二模编程题复盘:核心题型与笔试避坑指南

大家好,我是经历过2019年那一波校招的老兵。那年春天,牛客网把模考系统做得越来越像真实笔试,尤其“二模”这套编程题集合,可以说是我刷过的模拟卷里最贴近大厂实战风格的之一。当时我和几个朋友同时做这套题,出来一合…

📅 2026/10/14 7:59:58
国内小白第一款Agent工具怎么选?6款主流工具横向实测与选型指南

国内小白第一款Agent工具怎么选?6款主流工具横向实测与选型指南

一年多前我在公司内部搭知识库问答机器人时,第一批接触的就是 Agent 工具。当时网上资料很杂,今天看人说 A 工具是国产之光,明天又看到帖子说 B 工具才是真正能落地的,结果我把几个主流平台都注册了一遍,还在本地折腾了…

📅 2026/10/14 8:58:57
途虎养车秋招测试笔试试卷B:核心考点与解题思路复盘

途虎养车秋招测试笔试试卷B:核心考点与解题思路复盘

途虎养车2023秋招测试笔试试卷B——这个名字对今年准备投测试岗的同学来说应该不陌生。我身边几个师弟师妹秋招时都碰过这套题,网上也有不少人问“B卷难不难”“考什么”。作为在测试行业泡了七八年的老人,我在帮他们复盘的过程中把这份试卷从头到尾捋了…

📅 2026/10/14 12:32:23
MORE NEWS

更多资讯

📰

5个信号识别垃圾账号:anti-slop用户检查如何过滤AI slop贡献者

【免费下载链接】anti-slop A GitHub action that detects and automatically closes low-quality and AI slop PRs. 项目地址: https://gitcode.com/gh_mirrors/an/anti-slop 点击查看 免费下载 开源维护者正被大量低质量 PR 淹没,其中不少是 AI 自动生…

📰

cursor-free-vip 使用教程:三步重置 Cursor 机器 ID,恢复 AI 助手试用额度

cursor-free-vip 使用教程:三步重置 Cursor 机器 ID,恢复 AI 助手试用额度 【免费下载链接】cursor-free-vip [Support 0.45](Multi Language 多语言)自动注册 Cursor Ai ,自动重置机器ID , 免费升级使用Pr…

📰

ComfyUI 中文工作流合集:18 个现成模板,十分钟跑通第一张图

ComfyUI 中文工作流合集:18 个现成模板,十分钟跑通第一张图 【免费下载链接】ComfyUI-Workflows-ZHO 我的 ComfyUI 工作流合集 | My ComfyUI workflows collection 项目地址: https://gitcode.com/GitHub_Trending/co/ComfyUI-Workflows-ZHO Comf…

📰

G-Helper 华硕笔记本调校三步配好

G-Helper 华硕笔记本调校三步配好 【免费下载链接】g-helper Lightweight Armoury Crate alternative for Asus laptops with nearly the same functionality. Works with ROG Zephyrus, Flow, TUF, Strix, Scar, ProArt, Vivobook, Zenbook, Expertbook, ROG Ally, and more. …

📰

YimMenu 实战指南:GTA5 开源菜单从 CMake 编译到 Lua 脚本扩展

YimMenu 实战指南:GTA5 开源菜单从 CMake 编译到 Lua 脚本扩展 【免费下载链接】YimMenu YimMenu, a GTA V menu protecting against a wide ranges of the public crashes and improving the overall experience. 项目地址: https://gitcode.com/GitHub_Trending…

📰

中科晟达注塑机 MES 系统:从车间到数字化的智能制造实践

1. 引言 注塑成型是制造业中应用最广泛的工艺之一,从汽车零部件、家电外壳到医疗器械、精密电子,几乎无处不在。然而,传统注塑车间长期面临设备状态不透明、生产计划靠经验、质量追溯困难、模具与工艺参数管理粗放等痛点。随着智能制造与工业…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬