[LeetCode]1221. Split a String in Balanced Strings
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的更多相关文章
- 【LeetCode】1221. Split a String in Balanced Strings 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 日期 题目地址:https://leetcode ...
- 【leetcode】1221. Split a String in Balanced Strings
题目如下: Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced ...
- LeetCode 1234. Replace the Substring for Balanced String
原题链接在这里:https://leetcode.com/problems/replace-the-substring-for-balanced-string/ 题目: You are given a ...
- 【LeetCode】1071. Greatest Common Divisor of Strings 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力遍历 日期 题目地址:https://leetc ...
- C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)
split()首先是一个分隔符,它会把字符串按照split(' 字符')里的字符把字符串分割成数组,然后存给一个数组对象. 输出数组对象经常使用foreach或者for循环. 第一种方法 string ...
- [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维
题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...
- StringUtils.split()和string.split()的区别
场景 出于业务考虑,将多个字符串拼接起来时,使用的分隔符是;,;.如果要将这样一个拼接来的字符串分割成原本的多个字符串时,就需要使用到jdk自带的split()方法.不过因为公司的编程规范,改为使用了 ...
- Leetcode 344:Reverse String 反转字符串(python、java)
Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...
- 【LeetCode】481. Magical String 解题报告(Python)
[LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...
随机推荐
- Zookeeper 安装与简单使用
一.安装Zookeeper 其实Zookeeper的安装特别简单,也不能算安装了,只需要将Zookeeper下载后解压,就完成了安装操作. 下载地址:http://zookeeper.apache.o ...
- shell 判断一个字符串是否由字母数字组成
摘自:http://blog.51cto.com/lynnteng0/804520 describe="it's a describe by yourself" if echo & ...
- IEnumerable是什么
首先怎么认识一个对象 IE+number+able IE数字 可能 从名字上看不出什么玩意,以至于很久都没人真正认识这个接口 先看官方的解释 IEnumerable Interface Expose ...
- centos7.3部署memcached服务
我们需要下载libevent和memcached这两个压缩包进行安装,可使用以下百度网盘链接进行下载 链接:https://pan.baidu.com/s/1vehZ5odzXFKwNjWT9_W0T ...
- spring boot @RequestBody数据传递及解析
@RequestBody需要接的参数是一个string化的json @RequestBody,要读取的数据在请求体里,所以要发post请求,还要将Content-Type设置为application/ ...
- jquery trigger使用方法
jquery trigger使用方法比方说写了下面点击事件 采用trigger 要触发他<pre> $('.biaoqian_ula').on('click',function () { ...
- 如何配置STP
一.搭建本次实验的拓扑结构 两台s5700交换机模拟核心交换,两台s3700交换机模拟接入交换机,核心上配置eth-trunk 二.开启所有交换机的stp功能 开启stp [S1]stp enab ...
- QT--学习疑惑探索
用C++定义了一个类,并注册到qml文件中,但是这个类只能用Quickview进行显示,用其他方法好像不行. 启发: 1 window控件类是没有parent的widget. 2 m_view = ...
- WordPress概览
"绝望是一种罪过"-------------------------<老人与海> WordPress 是世界上使用最广泛的博客系统,是一款开源的PHP软件,在GNU通用 ...
- 微信小程序获取位置
获取位置 getLocation wx.getLocation({ type: 'wgs84', success (res) { const latitude = res.latitude const ...