[Leetcode] 551. Student Attendance Record I

Algorithm|2021. 11. 18. 13:33
반응형
 

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

중간에 a 가 나와도 l_count를 다시 0으로 초기화시켜줘야 된다는 걸 놓침

class Solution {
public:
    bool checkRecord(string s) 
    {
        int a_count = 0;
        int l_count = 0;
        
        for(int i=0;i<s.size(); i++)
        {
            if(s[i] == 'L')
                l_count++;
            
            else 
            {
                if(s[i] == 'A')
                    a_count++;
                l_count = 0;
            }
            
            if(l_count == 3 || a_count >= 2)
                return false;
        }
        return true;
        
    }
};
반응형

'Algorithm' 카테고리의 다른 글

[Leetcode] 860. Lemonade Change  (0) 2021.11.19
[Leetcode] 6. Zigzag Conversion  (0) 2021.11.18
[백준] 6321. IBM 빼기 1  (0) 2021.11.17
[Leetcode] 844. Backspace String Compare  (0) 2021.11.17
[Programmers] 소수만들기  (0) 2021.11.17

댓글()