日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

551. Student Attendance Record I 从字符串判断学生考勤

發(fā)布時間:2023/11/30 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 551. Student Attendance Record I 从字符串判断学生考勤 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

[抄題]:

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

    ?[暴力解法]:

    時間分析:

    空間分析:

    ?[優(yōu)化后]:

    時間分析:

    空間分析:

    [奇葩輸出條件]:

    [奇葩corner case]:

    [思維問題]:

    以為要用for 來循環(huán)找L,但是其實還是index更方便

    [一句話思路]:

    String類的.indexof contains(雙引號字符串)法很方便也很基礎(chǔ),要熟悉 多用

    [輸入量]:空:?正常情況:特大:特小:程序里處理到的特殊情況:異常情況(不合法不合理的輸入):

    [畫圖]:

    [一刷]:

  • 又錯了:布爾型默認(rèn)情況是return true, 一般情況都是正常即正確
  • [二刷]:

    [三刷]:

    [四刷]:

    [五刷]:

    ? [五分鐘肉眼debug的結(jié)果]:

    [總結(jié)]:

    String類的.indexof contains(雙引號字符串)方法很方便也很基礎(chǔ)

    [復(fù)雜度]:Time complexity: O(n) Space complexity: O(1)

    [英文數(shù)據(jù)結(jié)構(gòu)或算法,為什么不用別的數(shù)據(jù)結(jié)構(gòu)或算法]:

    [關(guān)鍵模板化代碼]:

    [其他解法]:

    [Follow Up]:

    [LC給出的題目變變變]:

    552.?Student Attendance Record II 具體方案還用DP就不懂了

    ?[代碼風(fēng)格] :

    class Solution {public boolean checkRecord(String s) {//ccif (s.length() == 0) {return true;}//judgeif ((s.indexOf("A") != s.lastIndexOf("A")) || (s.contains("LLL"))) return false;//return return true;} } View Code

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/immiao0319/p/8649343.html

    總結(jié)

    以上是生活随笔為你收集整理的551. Student Attendance Record I 从字符串判断学生考勤的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。