1.原题:

https://leetcode.com/problems/split-a-string-in-balanced-strings/

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.

翻译:

对称的字段意思就是: LLRR 或者 LR 这种,现在给定一个字符串,然后查找里面有几个对称的字段。

2.解题思路:

这道题其实非常直白,你只需要用for loop去对照数量就行。因为字符串里面是由好几对对称的字段组成,所以你只需要记录每一次L和R数量一样的时刻就行了,因为这时候肯定是一个新的对称。

这题我因为偷懒就用了python2,实际上语法任何一个语言都行:

class Solution(object):
def balancedStringSplit(self, s):
count_tmp1 = count_tmp2 = count_tmp3 = 0 
for S in s:        #检索整个字符串
if (S == "R"):
count_tmp1 += 1 #R的数量
else:
count_tmp2 += 1 #L的数量
if (count_tmp1 == count_tmp2):  #当两者数量一致的时候,说明有一个新的对称
count_tmp3 += 1
return count_tmp3

leetcode菜鸡斗智斗勇系列(6)--- 检查一个string里面有几个对称的字段的更多相关文章

  1. leetcode菜鸡斗智斗勇系列(2)--- 把一个ipv4地址转换成一串数字

    1.原题: https://leetcode.com/problems/defanging-an-ip-address/ 这道题本身很简单, Given a valid (IPv4) IP addre ...

  2. leetcode菜鸡斗智斗勇系列(3)--- Jewels and Stones珠宝和钻石

    1.原题: https://leetcode.com/problems/jewels-and-stones/ You're given strings J representing the types ...

  3. leetcode菜鸡斗智斗勇系列(10)--- Decrypt String from Alphabet to Integer Mapping

    1.原题: https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/submissions/ Giv ...

  4. leetcode菜鸡斗智斗勇系列(1)---把一个链表中的二进制数字转换为一个整型数(int)

    Convert Binary Number in a Linked List to Integer这道题在leetcode上面算作是“easy”,然而小生我还是不会做,于是根据大佬的回答来整理一下思路 ...

  5. leetcode菜鸡斗智斗勇系列(4)--- 单一数字的乘积和总合的减法

    1.原题: https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ Given an i ...

  6. leetcode菜鸡斗智斗勇系列(9)--- Range Sum of BST

    1.原题: https://leetcode.com/problems/range-sum-of-bst/ Given the root node of a binary search tree, r ...

  7. leetcode菜鸡斗智斗勇系列(8)--- Find N Unique Integers Sum up to Zero

    1.原题: https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/ Given an integer n, retur ...

  8. leetcode菜鸡斗智斗勇系列(7)--- 用最小的时间访问所有的节点

    1.原题: https://leetcode.com/problems/minimum-time-visiting-all-points/ On a plane there are n points ...

  9. leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字

    1.原题: https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Given an array nums of ...

随机推荐

  1. LeetCodr 43 字符串相乘

    思路 用一个数组记录乘积的结果,最后处理进位. 代码 class Solution { public: string multiply(string num1, string num2) { if(n ...

  2. Codeforces Round #598 (Div. 3) C. Platforms Jumping

    There is a river of width nn. The left bank of the river is cell 00 and the right bank is cell n+1n+ ...

  3. C# 将DataGridView中显示的数据导出到Excel(.xls和.xlsx格式)—NPOI

    前言 https://blog.csdn.net/IT_xiao_guang_guang/article/details/104217491  本地数据库表中有46785条数据,测试正常  初次运行程 ...

  4. 每天进步一点点------SOPC TIMER (一)

    寄存器图 可以通过操作以下的寄存器来实现对timer(定时器)内核的操作(仅描述32位计数器) 状态寄存器: TO(timeout) :计数器计数到0时,该位置1,之后TO位的值会保持,直到手动清零, ...

  5. async 异步协程进阶

    协程通过 async/await 语法进行声明,是编写异步应用的推荐方式 例如新定义一个协程(coroutine object): async def foo(): return 42 首先先来介绍下 ...

  6. 李超线段树(segment[HEOI2013]-洛谷T4097)

    (neng了好久好久才糊弄懂得知识点...) 一.李超线段树 在线动态维护一个二维平面直角坐标系, 支持插入一条线段, 询问与直线x = x0相交的所有线段中,交点y的最大/小值 (若有多条线段符合条 ...

  7. 创建Maven project 提示pom.xml 首行错误

    背景 使用eclipse创建Maven SpringBoot 2.2.0 项目时报错,更换springboot 版本也不行,排除框架依赖原因.然后别人的eclipse创建的同样2.2.2 maven项 ...

  8. MyBatis学习总结(一)--mybatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  9. JAVA基础学习(7)之函数

    7函数 7.1函数定义与调用 7.1.1函数定义 7.1.2函数调用 package com.study.main; public class ObjectStudy { public static ...

  10. 【转】docker配置参数详解---/etc/docker/daemon.json完整参数

    docker-daemon.json各配置详解 { “api-cors-header”:"", ——————在引擎API中设置CORS标头 “authorization-plugi ...