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 ...
随机推荐
- CDH仅完成 0/3 个步骤。首个失败:主机 node6 (id=2) 上的客户端配置 (id=1) 已使用 1 退出,而预期值为 0。
CDH仅完成 0/3 个步骤.首个失败:主机 node6 (id=2) 上的客户端配置 (id=1) 已使用 1 退出,而预期值为 0 javaHome出现了问题 JAVA_HOME并不是根据环境 ...
- Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive
Vue控制台警告: Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider markin ...
- 其他 - 阻塞 & 同步 的基本认识
1. 概述 有些概念, 老是弄不清楚 同步异步 阻塞非阻塞 2. 准备 场景 角色 client 发起请求 接受请求 server 接受请求 执行操作 返回响应 行为 大致是一个 C/S 模式的模型 ...
- 每天进步一点点------Alpha半透明图形叠加算法Matlab+Verilog实现
Alpha图形叠加算法Matlab+Verilog实现 1.1. Alpha算法的研究 Alpha通道是一个8位的灰度通道,该通道用256级灰度来记录图像中的透明度信息,定义透明.不透明和半透明区域, ...
- 04hive查询
详细文档查看:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select 一. 基本查询(SELECT …FROM) ...
- mvc 部分页
在一些复杂的项目中,我们经常会遇到一个页面存在很多模块,存在页面交互或者加载数据过多等问题,这种时候,我们很可能会考虑到通过使用部分页来解决这个问题(ps:当然还有很多的解决方案,在这里只是简单介绍这 ...
- opencv python:图像二值化
import cv2 as cv import numpy as np import matplotlib.pyplot as plt # 二值图像就是将灰度图转化成黑白图,没有灰,在一个值之前为黑, ...
- spring 基于xml的申明式AspectH中的后置通知的返回值获取
spring 基于xml的申明式AspectH中的后置通知的返回值获取 1. 配置文件 <aop:config> <aop:aspect ref="myAspect&quo ...
- pandas库笔记
本笔记为自学笔记 1.pandas.DataFrame() 一种保存矩阵的数据格式 grades_df = pd.DataFrame( data={'exam1': [43, 81, 78, 75, ...
- 剑指offer系列——62.二叉搜索树的第k个结点
Q:给定一棵二叉搜索树,请找出其中的第k小的结点.例如, (5,3,7,2,4,6,8) 中,按结点数值大小顺序第三小结点的值为4. T: 中序遍历,递归: int count = 0; public ...