Skip to content
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 투포인터 #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

11 투포인터 #8

wants to merge 3 commits into from

Conversation

kimeunsom
Copy link
Collaborator

@kimeunsom kimeunsom commented Nov 15, 2023

###인적사항
학번 : 2271018
이름 : 김은솜

###과제제출
기존제출 : 2531, 20922
추가제출 : 14503

Copy link

@mingulmangul mingulmangul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[투포인터 알고리즘 코드 리뷰 완료]
20922, 2531(P2)
안녕하세요 은솜님!
두 문제 모두 투포인터를 활용해서 잘 풀어주신 것 같습니다!
저와는 또 다른 방식으로 풀어주셔서 저도 새롭게 배워가는 것 같습니다 👍
주석도 꼼꼼하게 달아주셔서 코드가 잘 읽히고 좋았습니다 ^^
과제하느라 고생많으셨습니다🥰💚

sequence.push_back(t);
}

cout<<findLength(sequence, cnt, k);;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

연산 로직을 메인 메소드의 입출력과 분리해서 구현해주셨네요! 덕분에 코드가 더 깔끔한 것 같아 좋습니다 ^^ 👍


using namespace std;

int findLength(const vector<int> &sequence, int * cnt, int k) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

벡터를 const로 넘겨 주셨네요! 이렇게 하면 벡터가 어떤 식으로 사용될 지 한눈에 알 수 있어서 좋은 것 같습니다. 이런 사소한 부분이 코드 퀄리티를 높여주는 것 같습니다 ☺️

Comment on lines +21 to +38
if(tag==0) {
right = sequence[rp]; //현재 ep가 가리키는 수
cnt[right]++; //카운팅 +1
}


if(cnt[right]<=k) { //아직 중복 개수가 2보다 작은 동안,
tag = 0;
rp++;

} else { //중복이 k 초과한 순간,
tag = 1;

left = sequence[lp]; //현재 sp가 가리키는 수
cnt[left]--; //카운트 -1
lp++;
continue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag로 right 카운팅 여부를 결정하도록 구현해주셨네요! 이렇게 변수를 플래그로 활용하는 방식도 좋습니다! 👍 추가적으로 tag를 사용하지 않고 구현하는 방식도 한 번 생각해보시면 더 좋을 것 같습니다 :)

Comment on lines +30 to +33
if(rp-lp == k-1 ) { // k개의 초밥이 충족됐으면, 현재의 cnt 값을 max에 저장
max_cnt = cur_cnt;
break;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. while문의 조건이 rp-lp < k이니까 그 직전인 rp-lp == k-1에서 break를 거는 부분이 꼭 필요하지는 않아 보입니다! 물론 만약 여기를 지우게 되면 while문이 끝났을 때 rp의 값이 몇인지에 유의하셔야 될 것 같아요 :)

lp%=n;
rp%=n;

// 회전 초밥이니깐, 원형큐의 개념 떠올리며 mod 연산해주기

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자료구조와 연결 지어서 고려해 주신 점 좋습니다!! 👍👍👍

Comment on lines +52 to +53
lp%=n;
rp%=n;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 이 부분에서 mod 연산을 수행하는데 lp와 rp를 dish의 인덱스로 사용할 때에도 mod 연산을 수행하고 있네요! 중복 코드는 최대한 줄이는 게 좋으니 둘 중 하나는 생략해도 될 것 같습니다 :)

Comment on lines +65 to +69
//쿠폰 초밥 구간 내 미포함이면, 쿠폰 한 종류 더 추가 !
if(visited[c]==0) {
cur_cnt++;
coupon=1;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 쿠폰으로는 항상 하나의 초밥을 먹을 수 있죠. 그러면 visited[c]가 0이 될 필요가 있을까요? 쿠폰을 확인하는 if문을 생략할 수 있도록 미리 초기화를 진행할 수 있는데 이런 방식도 한 번 고민해 보시면 좋을 것 같습니다! 이렇게 하면 아래에 적용된 쿠폰을 다시 초기화하는 작업도 생략할 수 있어 보입니다 :)

Copy link

@kimhj010502 kimhj010502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[투 포인터 구현 문제 코드 리뷰 완료]

14503(P3)

은솜님 안녕하세요!
과제하시느라 수고 많으셨습니다!! 어려운 문제인데도 잘 풀어주셨네요! 🥰
코드에 대한 주석도 너무 좋았습니다 👍
궁금한 점이 있으면 리뷰어를 호출해주세요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants