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; } }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/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...
閱讀 1961·2021-09-30 09:46
閱讀 1371·2019-08-30 15:43
閱讀 1130·2019-08-29 13:28
閱讀 1931·2019-08-29 11:24
閱讀 1691·2019-08-26 13:22
閱讀 3945·2019-08-26 12:01
閱讀 1827·2019-08-26 11:33
閱讀 3250·2019-08-23 15:34