Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcddddca

Browse files
LEET-[551] add 551
1 parent296f635 commitcddddca

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

‎leetcode-algorithms/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#[LeetCode](https://leetcode.com/problemset/algorithms/)![Language](https://img.shields.io/badge/language-Java-blue.svg)[![Build Status](https://travis-ci.org/fishercoder1534/Leetcode.svg?branch=master)](https://travis-ci.org/fishercoder1534/Leetcode)[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE.md)
1+
#[LeetCode](https://leetcode.com/problemset/algorithms/)![Language](https://img.shields.io/badge/language-Java-blue.svg)[![Build Status](https://travis-ci.org/fishercoder1534/Leetcode.svg?branch=master)](https://travis-ci.org/fishercoder1534/Leetcode)[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE.md)
22

33
##Algorithms
44
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
55
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
66
|557|[Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ReverseWordsinaStringIII.java) | O(n) |O(n) | Easy | String
77
|556|[Next Greater Element III](https://leetcode.com/problems/next-greater-element-iii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/NextGreaterElementIII.java) | O(n)|O(1)| Medium | String
88
|554|[Brick Wall](https://leetcode.com/problems/brick-wall/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/BrickWall.java) | O(n) (n is total number of bricks in the wall) |O(m) (m is width of the wall) | Medium | HashMap
9+
|551|[Student Attendance Record I](https://leetcode.com/problems/Student Attendance Record I/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/StudentAttendanceRecordI.java) | O(n)| O(1) | Easy| String
910
|549|[Binary Tree Longest Consecutive Sequence II](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/BinaryTreeLongestConsecutiveSequenceII.java) | O(n) |O(n) | Medium | Tree
1011
|548|[Split Array with Equal Sum](https://leetcode.com/problems/split-array-with-equal-sum/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/SplitArraywithEqualSum.java) | O(n^2) |O(1) | Medium | Array
1112
|547|[Friend Circles](https://leetcode.com/problems/friend-circles/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/FriendCircles.java) | O(n^2) |O(n) | Medium | Union Find
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
packagecom.stevesun.solutions;
2+
3+
/**
4+
* You are given a string representing an attendance record for a student. The record only contains the following three characters:
5+
6+
'A' : Absent.
7+
'L' : Late.
8+
'P' : Present.
9+
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
10+
11+
You need to return whether the student could be rewarded according to his attendance record.
12+
13+
Example 1:
14+
Input: "PPALLP"
15+
Output: True
16+
17+
Example 2:
18+
Input: "PPALLL"
19+
Output: False
20+
21+
*/
22+
publicclassStudentAttendanceRecordI {
23+
24+
publicbooleancheckRecord(Strings) {
25+
intaCount =0;
26+
for (inti =0;i <s.length();i++) {
27+
if (s.charAt(i) =='A') {
28+
aCount++;
29+
if (aCount >1)returnfalse;
30+
}elseif (s.charAt(i) =='L') {
31+
intcontinuousLCount =0;
32+
while (i <s.length() &&s.charAt(i) =='L') {
33+
i++;
34+
continuousLCount++;
35+
if (continuousLCount >2)returnfalse;
36+
}
37+
i--;
38+
}
39+
}
40+
returntrue;
41+
}
42+
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.stevesun;
2+
3+
importcom.stevesun.solutions.StudentAttendanceRecordI;
4+
importorg.junit.Before;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importstaticjunit.framework.Assert.assertEquals;
9+
10+
publicclassStudentAttendanceRecordITest {
11+
privatestaticStudentAttendanceRecordItest;
12+
privatestaticbooleanexpected;
13+
privatestaticbooleanactual;
14+
privatestaticStrings;
15+
16+
@BeforeClass
17+
publicstaticvoidsetup(){
18+
test =newStudentAttendanceRecordI();
19+
}
20+
21+
@Before
22+
publicvoidsetupForEachTest(){}
23+
24+
@Test
25+
publicvoidtest1(){
26+
s ="ALLAPPL";
27+
expected =false;
28+
actual =test.checkRecord(s);
29+
assertEquals(expected,actual);
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp