class Solution {
public:
bool checkRecord(string s) {
return s.find("LLL") != string::npos || count(s.begin(), s.end(), 'A') > 1 ? false : true;
}
};
string에 내장되어있는 find 함수를 이용해 LLL을 찾았거나 결석(A) 가 2번이상이면 false를 리턴하도록 구현하였다.
stiring의 find 함수는 algorithm의 find 함수와 다르게 find(찾을문자, 시작점)을 주어준다.
문제: https://leetcode.com/problems/student-attendance-record-i/
Student Attendance Record I - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'Problem Solving > 리트코드(leetcode)' 카테고리의 다른 글
[Leetcode/C++] 496. Next Greater Element 1 (0) | 2022.01.24 |
---|---|
[Leetcode/C++] 1021. Remove Outermost Parentheses (0) | 2022.01.24 |
[LeetCode/C++] 14. Longest Common Prefix (0) | 2022.01.23 |
[LeetCode/C++] 844. Backspace String Compare (0) | 2022.01.20 |
Determine if String Halves Are Alike (0) | 2022.01.16 |