Balanced strings are those who have equal quantity of 'L' and 'R' characters.

Given a balanced string s split it in the maximum amount of balanced strings.

Return the maximum amount of splitted balanced strings.

Example 1:

Input: s = "RLRRLLRLRL"
Output: 4
Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
Example 2:

Input: s = "RLLLLRRRLR"
Output: 3
Explanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.
Example 3:

Input: s = "LLLLRRRR"
Output: 1
Explanation: s can be split into "LLLLRRRR".

Constraints:

1 <= s.length <= 1000
s[i] = 'L' or 'R'

python3:

 class Solution:
def balancedStringSplit(self, s: str) -> int:
l = 0
r = 0
rst = 0
for s_str in s:
if s_str == 'L':
l += 1
elif s_str == 'R':
r += 1
if l == r:
rst += 1
l = 0
r = 0
return rst

[LeetCode]1221. Split a String in Balanced Strings的更多相关文章

  1. 【LeetCode】1221. Split a String in Balanced Strings 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 日期 题目地址:https://leetcode ...

  2. 【leetcode】1221. Split a String in Balanced Strings

    题目如下: Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced ...

  3. LeetCode 1234. Replace the Substring for Balanced String

    原题链接在这里:https://leetcode.com/problems/replace-the-substring-for-balanced-string/ 题目: You are given a ...

  4. 【LeetCode】1071. Greatest Common Divisor of Strings 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力遍历 日期 题目地址:https://leetc ...

  5. C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)

    split()首先是一个分隔符,它会把字符串按照split(' 字符')里的字符把字符串分割成数组,然后存给一个数组对象. 输出数组对象经常使用foreach或者for循环. 第一种方法 string ...

  6. [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维

    题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...

  7. StringUtils.split()和string.split()的区别

    场景 出于业务考虑,将多个字符串拼接起来时,使用的分隔符是;,;.如果要将这样一个拼接来的字符串分割成原本的多个字符串时,就需要使用到jdk自带的split()方法.不过因为公司的编程规范,改为使用了 ...

  8. Leetcode 344:Reverse String 反转字符串(python、java)

    Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...

  9. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

随机推荐

  1. 【449】backup get weekly tweets

    import pandas as pd from datetime import datetime fn = r"D:\OneDrive - UNSW\tweets_flu.csv" ...

  2. css重直居中代码

    老是忘,记在这里: vertical-align: middle;

  3. npm创建angular项目

    1.首先保证你本地的 node 环境 是ok的哦. 2.安装 angular-cli    命令  npm install -g @angular/cli.安装完成后,ng version 查看版本, ...

  4. (生鲜项目)03. xadmin的配置

    步骤1. 下载xadmin源码(git_hub上的源码已经不支持py3了,需要从其它老手那里获取),将本文件夹全部放置于合适的目录下(这里放到extra_apps内)2. 在settings的INST ...

  5. spring security进阶2 添加账户并对账户密码进行加密

    目录 spring security 添加账户并对账户密码进行加密 一.原理分析 1.1加密原理 1.2加密后的登录过程 二.代码实现 2.1添加用户的页面如下, register.html 2.2c ...

  6. 问题二:appium 搞定权限弹框的一个小办法

    public void permission() { for (int i=0; i <= 10; i++) { if (getPageSource().contains("允许&qu ...

  7. 「中山纪中集训省选组D2T1」书堆 欧拉常数

    题目描述 蚂蚁是勤劳的动物,他们喜欢挑战极限.现在他们迎来了一个难题!蚂蚁居住在图书馆里,图书馆里有大量的书籍.书是形状大小质量都一样的矩形.蚂蚁要把这些书摆在水平桌子的边缘.蚂蚁喜欢整洁的布置,所以 ...

  8. Windows常用网络命令(3)

    5.Netstat Netstat命令可以帮助网络管理员了解网络的整体使用情况.它可以显示当前正在活动的网络连接的详细信息,例如显示网络连接.路由表和网络接口信息,可以统计目前总共有哪些网络连接正在运 ...

  9. gorm 实现 mysql for update 排他锁

    关于 MySQL 的排他锁网上已经有很多资料进行了介绍,这里主要是记录一下 gorm 如果使用排他锁. 排他锁是需要对索引进行锁操作,同时需要在事务中才能生效.具体操作如下: 假设有如下数据库表结构: ...

  10. 【LEETCODE】46、999. Available Captures for Rook

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...