551. Student Attendance Record I

2017-09-30  本文已影响0人  namelessEcho
class Solution {
    public boolean checkRecord(String s) {
        int countL =0;
        int countA = 0;
        int i =0;
        while(i<s.length())
        {
            char ch = s.charAt(i);
            if(ch=='A')
            {
                countA++;
                if(countA>=2) return false;
                i++;
            }
            else if(ch=='L')
            {
               while(i<s.length()&&s.charAt(i)=='L')
               {
                   countL++;
                   i++;
               }
                if(countL>=3) return false;
                else countL=0;
            }
            else
                i++;
                
        }
        return true;
    }
}
上一篇下一篇

猜你喜欢

热点阅读