551:学生出勤记录 I
This commit is contained in:
parent
acc0364a81
commit
b2b6ff6290
@ -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)
|
||||
|
||||
}
|
44
src/main/java/leetcode/editor/cn/StudentAttendanceRecordI.md
Normal file
44
src/main/java/leetcode/editor/cn/StudentAttendanceRecordI.md
Normal 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> </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> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 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
Loading…
Reference in New Issue
Block a user