본문 바로가기

Algorithm/Leet Code

LeetCode #551 StudentAttendanceRecord1. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

LeetCode #551 StudentAttendanceRecord1. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접



 막 풀고 예외케이스 그때그때 틀어막아서 풀었더니 풀고나서 만족감이 떨어짐.. 퍼포먼스는 100%..


I solved just trying again and again, and fixed exception case after submit. So.. I cannot satisfied with it even if I solved.. performance is 100% tho..




LeetCode #551

Q.

You are given a string representing an attendance record for a student. The record only contains the following three characters:
'A' : Absent.
'L' : Late.
'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).

You need to return whether the student could be rewarded according to his attendance record.


 학생의 출석기록부 문자열을 받는다. 기록에는 3가지 문자가 있다.
A - 결석
L - 지각
P - 출석

학생은 A 가 1개 초과로 없거나, 2개까지 연속된 L 이 1개 초과로 없으면 상을 받는다.

출석점수로 상을 받을 수 있는지 없는지 확인해봐라



e.g. 

Example 1:

Input: "PPALLP"

Output: True

Example 2:

Input: "PPALLL"

Output: False


Process

// Process

//1. Input student attendance record string

//2. Iterate from begin to the end && countAbsent < 2 && countContinousLate < 3

// 2.1. Check if it's A

//  2.1.1. If so -> count absent

//  2.1.2. If else it's L

//   2.1.2.1. If so -> Check if it's continousLate

//    2.1.2.1.1. If so -> count continousLate

//  2.1.3. else

//   2.1.3.1. -> initialize continousLate

//3. Check any count is over the standard

//4. Return result


// 처리과정

//1. 학생 출석 기록 문자열을 입력받는다.

//2. 시작부터 끝까지 반복하고 && 결석횟수 < 2 && 연속지각횟수 < 3 이면 반복한다.

// 2.1. A 이면

//  2.1.1. 결석횟수 센다.

// 2.2. L 이면

//  2.2.1. 연속인지 확인해서

//   2.2.1.1. 연속이면 -> 연속횟수 센다.

//   2.2.1.2. 아니면 -> 연속으로 바꾼다.

// 2.3. 그 외이면

//  2.3.1. 연속지각 초기화한다.

//3. 각 횟수들이 기준치를 넘는지 확인해서 결과를 만든다.

//4. 결과 리턴한다.





Code.. lemme see example code!!!

코드.. 예제코드를 보자!!!




#include <string>


using namespace std;


class Solution {

public:

bool checkRecord(string s) {

int countAbsent = 0;

bool continousLate = false;

int countContinousLate = 1;


for (int i = 0; countAbsent < 2 && countContinousLate < 3

&& i < s.size(); ++i)

{

if (s[i] == 65)

{

++countAbsent;

continousLate = false;

countContinousLate = 1;

}

else if (s[i] == 76)

{

if (continousLate)

++countContinousLate;

else

continousLate = true;

}

else

{

continousLate = false;

countContinousLate = 1;

}

}


if (countAbsent > 1 || countContinousLate > 2)

return false;

return true;

}

};




Something else you might like...?





2019/02/22 - [Algorithm/Leet Code] - LeetCode #429 N-aryTreeLevelOrderTraversal. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/02/18 - [Algorithm/Leet Code] - LeetCode #412 FizzBuzz. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/02/17 - [Algorithm/Leet Code] - LeetCode #415 AddStrings. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/02/10 - [Algorithm/Leet Code] - LeetCode #171 ExcelSheetColumnNumber. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/02/09 - [Algorithm/Leet Code] - LeetCode #709 ToLowerCase. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/02/08 - [Algorithm/Leet Code] - LeetCode #400 NthDigit. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접





2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #58 messageFromBinaryCode. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/07 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #57 fileNaming. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/04 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #56 digitsProduct. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제,문제해결능력,example, c++ java c# scalar

2019/01/04 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #55 differentSquares. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제,문제해결능력,example, c++ java c# scalar



2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)

2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)



2019/01/14 - [Programming/Java] - 자바 메모리 누수 체크/확인/고치는 방법, Memory leak check/fix in Java application, cleanCode/좋은코드/oop/객체지향



2019/01/25 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법(3)

2018/12/16 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법(2)

2018/12/27 - [Life/Health care] - Milk-Thistle 밀크시슬 usage/side effects/dosage/fatigue/supplement,효능/부작용/성인,소아 용법/건강/피로회복/영양제

2018/12/26 - [Life/Health care] - Selenium 셀레늄 usage/side effects/dosage 효능/부작용/성인,소아 용법