美文网首页
551. Student Attendance Record I

551. Student Attendance Record I

作者: namelessEcho | 来源:发表于2017-09-30 17:50 被阅读0次
    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;
        }
    }
    

    相关文章

      网友评论

          本文标题:551. Student Attendance Record I

          本文链接:https://www.haomeiwen.com/subject/yelnextx.html