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; } }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/77140.html
摘要:環(huán)境配置運(yùn)行環(huán)境安裝配置數(shù)據(jù)庫(kù)下載安裝下載地址牢記安裝過(guò)程中設(shè)置的用戶的密碼安裝選擇版本的安裝配置數(shù)據(jù)庫(kù)驅(qū)動(dòng)教程前提開(kāi)發(fā)環(huán)境參考環(huán)境配置文檔基礎(chǔ)知識(shí)基本語(yǔ)法協(xié)議基礎(chǔ)知識(shí)只需了解請(qǐng)求即可基礎(chǔ)的等。 **寒假的時(shí)候老師讓寫(xiě)個(gè)簡(jiǎn)單的JavaEE教程給學(xué)弟or學(xué)妹看,于是寫(xiě)了下面的內(nèi)容。發(fā)表到這個(gè)地方以防丟失。。。因?yàn)閷?xiě)的時(shí)候用的是word,直接復(fù)制過(guò)來(lái)格式有點(diǎn)亂。。。所以不要在意細(xì)節(jié)了。。...
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...
摘要:嗨這里是狐貍大家的期末課設(shè)要來(lái)了吧,有想法做什么了嘛,有沒(méi)有為此熬夜,有沒(méi)有為此努力呢,今天,我們來(lái)寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng),一方面是讓大家復(fù)習(xí)一下自己學(xué)過(guò)的知識(shí),一方面是為了給大家的期末課設(shè)提供一點(diǎn)思路。 目錄 序 嗨!這里是狐貍~~ 一、需求分析說(shuō)明 二、概要設(shè)計(jì)說(shuō)明 三、詳細(xì)設(shè)計(jì)說(shuō)明 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...
摘要:原問(wèn)題我的沙雕解法無(wú)重復(fù)字母存在重復(fù)字母挨打最暴力的無(wú)腦解法,耗時(shí)。。。 原問(wèn)題 Given a string, find the length of the?longest substring?without repeating characters. Example 1: Input: abcabcbb Output: 3 Explanation: The answer is a...
閱讀 1960·2021-09-30 09:46
閱讀 1370·2019-08-30 15:43
閱讀 1130·2019-08-29 13:28
閱讀 1929·2019-08-29 11:24
閱讀 1687·2019-08-26 13:22
閱讀 3932·2019-08-26 12:01
閱讀 1824·2019-08-26 11:33
閱讀 3247·2019-08-23 15:34