leetcode菜鸡斗智斗勇系列(6)--- 检查一个string里面有几个对称的字段
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里面有几个对称的字段的更多相关文章
- leetcode菜鸡斗智斗勇系列(2)--- 把一个ipv4地址转换成一串数字
		1.原题: https://leetcode.com/problems/defanging-an-ip-address/ 这道题本身很简单, Given a valid (IPv4) IP addre ... 
- leetcode菜鸡斗智斗勇系列(3)--- Jewels and Stones珠宝和钻石
		1.原题: https://leetcode.com/problems/jewels-and-stones/ You're given strings J representing the types ... 
- leetcode菜鸡斗智斗勇系列(10)--- Decrypt String from Alphabet to Integer Mapping
		1.原题: https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/submissions/ Giv ... 
- leetcode菜鸡斗智斗勇系列(1)---把一个链表中的二进制数字转换为一个整型数(int)
		Convert Binary Number in a Linked List to Integer这道题在leetcode上面算作是“easy”,然而小生我还是不会做,于是根据大佬的回答来整理一下思路 ... 
- leetcode菜鸡斗智斗勇系列(4)--- 单一数字的乘积和总合的减法
		1.原题: https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ Given an i ... 
- 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 ... 
- 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 ... 
- leetcode菜鸡斗智斗勇系列(7)--- 用最小的时间访问所有的节点
		1.原题: https://leetcode.com/problems/minimum-time-visiting-all-points/ On a plane there are n points ... 
- leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字
		1.原题: https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Given an array nums of ... 
随机推荐
- 密码学笔记——Rot13
			Rot13:将每个在字母表上的字母,用后数13个后的字母代替,若超过时则重新绕回26字母开头即可. eg:A换成N.B换成O.依此类推到M换成Z,然后序列反转:N换成A.O换成B.最后Z换成M 1.密 ... 
- zookeeper and kafka
			kafka安装前期准备: 1,准备三个节点(根据自己需求决定) 2,三个节点上安装好zookeeper(也可以使用kafka自带的zookeeper) 3,关闭防火墙 chkconfig iptab ... 
- Boxes and Candies
			问题 G: Boxes and Candies 时间限制: 1 Sec 内存限制: 128 MB[提交] [状态] 题目描述 There are N boxes arranged in a row. ... 
- select2多选框初始化默认值和获得值
			select2多选自带手动输入搜索功能,可怜我还查寻半天api 获得值: //chang函数获取选择的option $(".js-example").change(function ... 
- 如何通过Docker搭建一个swoft开发环境
			本篇文章给大家分享的内容是关于如何通过Docker搭建一个swoft开发环境 ,内容很详细,有需要的朋友可以参考一下,希望可以帮助到你们. Swoft首个基于 Swoole 原生协程的新时代 PHP ... 
- 3种常见的CSS页面布局--双飞翼布局、粘连布局、左右两列布局
			一.左右两列布局 1.代码如下,可先粘贴复制,自行运行 <!DOCTYPE html><html> <head> <meta charset="UT ... 
- PAT 1010 Radix (二分)
			Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ... 
- centos openoffice 的启动
			https://blog.csdn.net/resolute123/article/details/77304973 
- 学习笔记(26)- plato-端到端模型-定闹钟
			今天用了定闹钟的场景语料,在plato框架尝试了端到端的模型. 本文先记录英文的训练过程,然后记录中文的训练过程. 训练端到端的模型 发现使用英文的模型,还是显示有中文,所以,新建目录,重新训练 1. ... 
- mcast_get_loop函数
			#include <errno.h> #include <net/if.h> #include <sys/socket.h> #include <netine ... 
