-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11 투포인터 #10
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "11_\uD22C\uD3EC\uC778\uD130"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[투포인터 알고리즘 코드 리뷰 완료]
20922(P3), 2531(P3)
안녕하세요 예린님!
두 문제 모두 투포인터 알고리즘을 적절하게 사용해서 정말 잘 풀어주신 것 같습니다👍
클린 코드를 위해 추가로 고려하면 좋을 포인트들만 몇 가지 적어두었으니 한 번 읽어봐주세요 ^^
과제하느라 고생많으셨습니다🥰💚
for (int i = 0; i < n; i++) { | ||
cin >> arr[i]; | ||
} | ||
cout<<result(n,k,arr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
연산 로직을 메인 메소드와 분리해서 구현해주셨네요! 덕분에 코드가 더 깔끔한 것 같아 좋습니다 ^^ 👍
|
||
int result(int n, int k, vector<int>& arr){ | ||
int left =0, right =0; | ||
int Max=1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3. 지역 변수는 소문자로 시작하는게 좋습니다! 상수, 변수, 메소드, 클래스 등을 쉽게 구분하기 위함이니 코드를 작성할 때 네이밍 컨벤션도 고려해 주시면 더 좋을 것 같습니다 :)
while (left<=right && right < n){ | ||
|
||
if(check[arr[right]]<k){ | ||
check[arr[right]]++; | ||
right++; | ||
Max=max(Max,right-left); | ||
} else{ | ||
check[arr[left]]--; | ||
left++; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두 포인터가 각각 어떻게 움직여야 하는지 잘 구현해주신 것 같습니다 !👍
kind[c]++;//쿠폰 | ||
cnt++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
쿠폰으로 먹은 초밥을 초기화 과정에서 미리 카운팅해주신 점 좋습니다! 이렇게 하면 이후 코드에서 쿠폰 사용을 따로 고려할 필요가 없겠네요
if(kind[sushi[left++]]==0) cnt--; | ||
right = (right+1)%n; | ||
kind[sushi[right]]++; | ||
if(kind[sushi[right]]==1) cnt++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3. if문 내에 코드가 한 줄이더라도 중괄호로 감싸주는 게 좋습니다! 이렇게 하면 추후에 코드를 수정할 일이 있을 때 편하고 가독성도 더 좋아요 :)
while (left<n){ | ||
|
||
kind[sushi[left]]--; | ||
if(kind[sushi[left++]]==0) cnt--; | ||
right = (right+1)%n; | ||
kind[sushi[right]]++; | ||
if(kind[sushi[right]]==1) cnt++; | ||
result=max(result,cnt); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
투포인터를 잘 활용해서 깔끔하게 로직을 세워주신 것 같습니다 🥰👍
예린님 안녕하세요! |
인적사항
학번: 2171023
이름: 송예린
과제제출
기존제출: 2473, 2531, 20922
추가제출: