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. 2.4 【配置环境】TestNG安装

    两种方法可以安装TestNG Eclipse插件:  (来源:http://blog.csdn.net/hongchangfirst/article/details/7679849/) 第一种,离线安 ...

  2. Springboot MongoTemplate

    springboot mongodb配置解析 MongoTemplate进行增删改查 mongoTemplate 手把手教springboot访问/操作mongodb(查询.插入.删除) Spring ...

  3. 【音乐欣赏】《Fake》 - The Tech Thieves

    曲名:Fake 作者:The Tech Thieves [01;12.092]I got wasted,learning how to let it out [01;24.009]Please don ...

  4. Angular 使用 frame 加载网络资源显示路径不安全问题

    Angular 使用 frame 加载网络资源显示路径不安全问题 做项目的时候,angular 使用 frame 加载网络pdf文件的时候出现 unsafe value 问题,路径不安全.解决办法. ...

  5. python中 使用join()方法

    使用join()方法 对各种数据类型中元的素进行合并拼接 "连接符".join(列表或元组或字符串或字典) 返回的是一个使用连接符进行拼接的字符串 如果对象是列表,元组,就是以一个 ...

  6. rosserial学习记录

    1.参考博客:rosserial移植到STM32(CUBEMX+HAL库) 网址:https://blog.csdn.net/qq_37416258/article/details/84844051 ...

  7. java8date

    Java 8:新的时间和日期API 在Java 8之前,所有关于时间和日期的API都存在各种使用方面的缺陷,因此建议使用新的时间和日期API,分别从旧的时间和日期的API的缺点以及解决方法.Java ...

  8. java web编写四则运算

    首先先画出一个表 <%@ page language="java" contentType="text/html; charset=UTF-8" page ...

  9. Java进阶学习(3)之对象容器(上)

    对象容器 顺序容器 记事本的例子 UI设计和业务逻辑要分离 接口设计 add(String note); getSize(); getNote(int index); removeNote(index ...

  10. wampserver3.0.6 外网 不能访问

    # 开始 今天在服务器上安装了wampserver3.0.6 然后在我的电脑浏览器上面打开服务器ip提示 Forbidden 下面一行小字提示没有权限访问"/"目录 # 解决 打开 ...