Problem
You are given a string representing an attendance record for a student. The record only contains the following three characters:
"A" : Absent.
"L" : Late.
"P" : Present.
A student could be rewarded if his attendance record doesn"t contain more than one "A" (absent) or more than two continuous "L" (late).
You need to return whether the student could be rewarded according to his attendance record.
Example 1:
Input: "PPALLP" Output: True
Example 2:
Input: "PPALLL" Output: FalseSolution
class Solution { public boolean checkRecord(String s) { if (s == null || s.length() == 0) return true; Mapmap = new HashMap<>(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (!map.containsKey(ch)) map.put(ch, 1); else map.put(ch, map.get(ch)+1); if (ch == "A" && map.get(ch) > 1) return false; if (i+3 <= s.length() && s.substring(i, i+3).equals("LLL")) { return false; } } return true; } }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/77140.html
摘要:环境配置运行环境安装配置数据库下载安装下载地址牢记安装过程中设置的用户的密码安装选择版本的安装配置数据库驱动教程前提开发环境参考环境配置文档基础知识基本语法协议基础知识只需了解请求即可基础的等。 **寒假的时候老师让写个简单的JavaEE教程给学弟or学妹看,于是写了下面的内容。发表到这个地方以防丢失。。。因为写的时候用的是word,直接复制过来格式有点乱。。。所以不要在意细节了。。...
Problem A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers represe...
摘要:嗨这里是狐狸大家的期末课设要来了吧,有想法做什么了嘛,有没有为此熬夜,有没有为此努力呢,今天,我们来写一个学生成绩管理系统,一方面是让大家复习一下自己学过的知识,一方面是为了给大家的期末课设提供一点思路。 目录 序 嗨!这里是狐狸~~ 一、需求分析说明 二、概要设计说明 三、详细设计说明 1...
Intersection of Two Arrays I Problem Given two arrays, write a function to compute their intersection. Example Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note Each element in the result m...
摘要:原问题我的沙雕解法无重复字母存在重复字母挨打最暴力的无脑解法,耗时。。。 原问题 Given a string, find the length of the longest substring without repeating characters. Example 1: Input: abcabcbb Output: 3 Explanation: The answer is a...
阅读 1912·2021-09-30 09:46
阅读 1334·2019-08-30 15:43
阅读 1100·2019-08-29 13:28
阅读 1904·2019-08-29 11:24
阅读 1654·2019-08-26 13:22
阅读 3747·2019-08-26 12:01
阅读 1798·2019-08-26 11:33
阅读 3217·2019-08-23 15:34