leetcode 551. 学生出勤记录 I(Java版)
生活随笔
收集整理的這篇文章主要介紹了
leetcode 551. 学生出勤记录 I(Java版)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目
https://leetcode-cn.com/problems/student-attendance-record-i/
題解
public class Solution {public boolean checkRecord(String s) {char[] chars = s.toCharArray();int countA = 0;int continuousL = 0;boolean preIsL = false;for (int i = 0; i < chars.length; i++) {if (chars[i] == 'A') {preIsL = false;countA++;if (countA > 1) return false;} else if (chars[i] == 'L') {if (preIsL) {continuousL++;if (continuousL > 2) return false;} else {continuousL = 1;}preIsL = true;} else {preIsL = false;}}return true;} }總結
以上是生活随笔為你收集整理的leetcode 551. 学生出勤记录 I(Java版)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode 543. 二叉树的直径
- 下一篇: leetcode 557. 反转字符串中