Student Attendance Record I

来源:互联网 发布:免费刷空间人气软件 编辑:程序博客网 时间:2024/06/06 14:20

https://leetcode.com/problems/student-attendance-record-i/#/description

题目思路:本题将输入一只含有P,A,L 三个字母的字符串,如果该字符串超过一个A则返回false,或者该字符串有超过两个L连续出现在一起,则返回false

public class Solution {    public boolean checkRecord(String s) {        int a = 0;        for(int i = 0, len = s.length(); i < len; i++) {            if(s.charAt(i) == 'A')                a ++;        }        if(a > 1 || s.contains("LLL"))            return false;        else            return true;    }}
原创粉丝点击