成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

[LeetCode] Student Attendance Record I

RancherLabs / 1157人閱讀

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: False

Solution
class Solution {
    public boolean checkRecord(String s) {
        if (s == null || s.length() == 0) return true;
        Map map = 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://systransis.cn/yun/77140.html

相關(guān)文章

  • JavaEE環(huán)境配置與示例教程

    摘要:環(huán)境配置運(yùn)行環(huán)境安裝配置數(shù)據(jù)庫(kù)下載安裝下載地址牢記安裝過(guò)程中設(shè)置的用戶(hù)的密碼安裝選擇版本的安裝配置數(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é)了。。...

    AbnerMing 評(píng)論0 收藏0
  • [LeetCode] 763. Partition Labels

    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...

    iliyaku 評(píng)論0 收藏0
  • 【硬核】用C語(yǔ)言來(lái)寫(xiě)學(xué)生成績(jī)管理系統(tǒng),讓你的課設(shè)不再是難題

    摘要:嗨這里是狐貍大家的期末課設(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...

    seanHai 評(píng)論0 收藏0
  • [LeetCode] Intersection of Two Arrays I & II

    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...

    lucas 評(píng)論0 收藏0
  • LeetCode——Longest Substring Without Repeating Char

    摘要:原問(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...

    forsigner 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

RancherLabs

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<