[抄題]:
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
?[暴力解法]:
時間分析:
空間分析:
?[優化后]:
時間分析:
空間分析:
[奇葩輸出條件]:
[奇葩corner case]:
[思維問題]:
以為要用for 來循環找L,但是其實還是index更方便
[一句話思路]:
String類的.indexof contains(雙引號字符串)方法很方便也很基礎,要熟悉 多用
[輸入量]:空:?正常情況:特大:特小:程序里處理到的特殊情況:異常情況(不合法不合理的輸入):
[畫圖]:
[一刷]:
- 又錯了:布爾型默認情況是return true, 一般情況都是正常即正確的
[二刷]:
[三刷]:
[四刷]:
[五刷]:
? [五分鐘肉眼debug的結果]:
[總結]:
String類的.indexof contains(雙引號字符串)方法很方便也很基礎
[復雜度]:Time complexity: O(n) Space complexity: O(1)
[英文數據結構或算法,為什么不用別的數據結構或算法]:
[關鍵模板化代碼]:
[其他解法]:
[Follow Up]:
[LC給出的題目變變變]:
552.?Student Attendance Record II 具體方案還用DP就不懂了
?[代碼風格] :


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;} }
?