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