Skip to content

[WEEK10] 이배진#45

Merged
LeeBaeJin merged 1 commit into
mainfrom
bjlee
Apr 20, 2026
Merged

[WEEK10] 이배진#45
LeeBaeJin merged 1 commit into
mainfrom
bjlee

Conversation

@LeeBaeJin
Copy link
Copy Markdown
Collaborator

@LeeBaeJin LeeBaeJin commented Apr 13, 2026

이렇게 풀었어요

1. 최솟값 만들기

  • 문제를 풀었어요.
  • 풀이 시간 : 12분

1) 복잡도 계산

시간 복잡도 : O(n log n)
공간 복잡도 : O(1)


2) 접근 아이디어

일단 배열을 먼저 정렬하는 것부터 생각하였습니다. 곰곰히 살펴보니 A의 오름차순 값과 B의 내림차순 값을 순서대로 곱해서 합하면 최솟값이 나타난다는 것을 파악하고. 풀이를 해봤습니다. 문제는 자바에서 역순 정렬하는 함수가 성능이 매우 좋지 못하다는 것을 알기에 좋은 방법이 없을까 고민해보다가. B 또한 오름차순 정렬하고 총 길이에서 -인덱스(i) -1을 하면 B배열의 가장 큰 값이 표현할 수 있다는 것을 생각해내어 이러한 풀이를 서술하였습니다.


3) 회고

간만에 수학적 사고를 펼쳐서 좋았다고 생각했는데, 저처럼 생각하신 분들이 많은 것을 보고 조금 시무룩했습니다.



2. 이진 변환 반복하기

  • 문제를 풀었어요.
  • 풀이 시간 : 6분

1) 복잡도 계산

시간 복잡도 : O(n)
공간 복잡도 : O(log n)


2) 접근 아이디어

이 문제의 조건이 1이 최소 하나는 있다는 것이고, 최종적으로 정수 1은 이진수 1과 같기 때문에 s가 1이 될때까지 반복(while문 사용)하면 되겠다고 떠올랐습니다. 그 후, 이진수 1만 추출하여 카운트 해준 뒤, 그 카운트를 다시 이진수로 변환하여 최종적으로 정수 1이 될 때까지 0을 제거 및 반복시켰습니다!


3) 회고

저번 주 보다는 쉽게 쉽게 생각해서 잘 풀어나갈 수 있는 문제였다고 생각합니다.



@LeeBaeJin LeeBaeJin changed the title 최솟값 만들기, 이진 변환 반복하기 풀이 [WEEK10] 이배진 Apr 13, 2026
answer += A[i] * B[B.length-i-1];
}

return answer;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

함수가 역순 정렬이 안좋다는 걸 생각하셔서 최대한 성능 좋게 구현하신 점이 좋네요 👍

rzCnt++;
}
}
s = Integer.toBinaryString(one); // Java에서 사용하는 이진 변환 함수(String 타입으로 리턴)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

주석까지.....🥲👍

Copy link
Copy Markdown
Collaborator

@raejun92 raejun92 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Java는 내림차순을 하려면 오름차순 정렬 후에 뒤집어야 하는군요ㅠ
비효율을 효율적으로 풀어내시려는 모습에 한 수 배워갑니다!

rzCnt++;
}
}
s = Integer.toBinaryString(one); // Java에서 사용하는 이진 변환 함수(String 타입으로 리턴)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이진수로 바꿔주는 메서드군요!
혹시 4진수나 16진수 같은 건 어떻게 하나요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

4진수는 따로 함수가 없고

8진수는 Integer.toOctalString(Int타입 변수)
16진수는 Integer.toHexString(Int타입 변수)

로 내장함수로 쉽게 변환이 가능합니다!

Copy link
Copy Markdown
Collaborator

@sik9252 sik9252 left a comment

Choose a reason for hiding this comment

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

역시 자바... 기본 문법부터 길군요 그런데도 잘 푸셔서 대단하십니다~! 고생하셨습니다

@LeeBaeJin LeeBaeJin merged commit 316a2ae into main Apr 20, 2026
1 check passed
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.

4 participants