551:学生出勤记录 I

This commit is contained in:
huangge1199 2021-08-17 16:31:02 +08:00
parent acc0364a81
commit b2b6ff6290
4 changed files with 126 additions and 2 deletions

View File

@ -0,0 +1,80 @@
//给你一个字符串 s 表示一个学生的出勤记录其中的每个字符用来标记当天的出勤情况缺勤迟到到场记录中只含下面三种字符
//
//
// 'A'Absent缺勤
// 'L'Late迟到
// 'P'Present到场
//
//
// 如果学生能够 同时 满足下面两个条件则可以获得出勤奖励
//
//
// 总出勤 学生缺勤'A'严格 少于两天
// 学生 不会 存在 连续 3 天或 3 天以上的迟到'L'记录
//
//
// 如果学生可以获得出勤奖励返回 true 否则返回 false
//
//
//
// 示例 1
//
//
//输入s = "PPALLP"
//输出true
//解释学生缺勤次数少于 2 且不存在 3 天或以上的连续迟到记录
//
//
// 示例 2
//
//
//输入s = "PPALLL"
//输出false
//解释学生最后三天连续迟到所以不满足出勤奖励的条件
//
//
//
//
// 提示
//
//
// 1 <= s.length <= 1000
// s[i] 'A''L' 'P'
//
// Related Topics 字符串
// 👍 99 👎 0
package leetcode.editor.cn;
//551:学生出勤记录 I
class StudentAttendanceRecordI {
public static void main(String[] args) {
//测试代码
Solution solution = new StudentAttendanceRecordI().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public boolean checkRecord(String s) {
int ca = 0;
int cl = 0;
for (char ch : s.toCharArray()) {
if (ch == 'A') {
ca++;
}
if (ch == 'L') {
cl++;
} else {
cl = 0;
}
if (ca == 2 || cl == 3) {
return false;
}
}
return true;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,44 @@
<p>给你一个字符串 <code>s</code> 表示一个学生的出勤记录,其中的每个字符用来标记当天的出勤情况(缺勤、迟到、到场)。记录中只含下面三种字符:</p>
<ul>
<li><code>'A'</code>Absent缺勤</li>
<li><code>'L'</code>Late迟到</li>
<li><code>'P'</code>Present到场</li>
</ul>
<p>如果学生能够 <strong>同时</strong> 满足下面两个条件,则可以获得出勤奖励:</p>
<ul>
<li><strong>总出勤</strong> 计,学生缺勤(<code>'A'</code><strong>严格</strong> 少于两天。</li>
<li>学生 <strong>不会</strong> 存在 <strong>连续</strong> 3 天或 3 天以上的迟到(<code>'L'</code>)记录。</li>
</ul>
<p>如果学生可以获得出勤奖励,返回 <code>true</code> ;否则,返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "PPALLP"
<strong>输出:</strong>true
<strong>解释:</strong>学生缺勤次数少于 2 次,且不存在 3 天或以上的连续迟到记录。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "PPALLL"
<strong>输出:</strong>false
<strong>解释:</strong>学生最后三天连续迟到,所以不满足出勤奖励的条件。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>s[i]</code><code>'A'</code><code>'L'</code><code>'P'</code></li>
</ul>
<div><div>Related Topics</div><div><li>字符串</li></div></div>\n<div><li>👍 99</li><li>👎 0</li></div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long