Skip to content

[WEEK11] 추슬기#50

Merged
doitchuu merged 2 commits into
pnt-fe-study:mainfrom
doitchuu:doitchuu
May 6, 2026
Merged

[WEEK11] 추슬기#50
doitchuu merged 2 commits into
pnt-fe-study:mainfrom
doitchuu:doitchuu

Conversation

@doitchuu
Copy link
Copy Markdown
Member

이렇게 풀었어요

1. 다음 큰 숫자

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

1) 복잡도 계산

  • 시간 복잡도: O(k * m)
  • 공간 복잡도: O(m)

2) 접근 아이디어

  1. 현재 숫자의 이진수 표현에서 1의 개수를 먼저 구했다.
  2. 다음 숫자부터 하나씩 증가시키면서 같은 1 개수를 가지는지 확인했다.
  3. 1의 개수가 같아지는 첫 숫자를 답으로 반환했다.

3) 회고

이진법 변환이나 이진법 방식을 이해하면 더 쉽게도 풀 수 있을 것 같다.

다른 사람 풀이:

function solution(n,a=n+1) {
    return n.toString(2).match(/1/g).length == a.toString(2).match(/1/g).length ? a : solution(n,a+1);
}

다른 사람 풀이 핵심: match(/1/g)로 1의 개수를 세고, 재귀로 다음 숫자를 바로 탐색하는 방식이었다.
내 생각: match라는 메서드를 활용해서 1과 일치하는 문자열을 배열로 채워서 length로 계산하는 방법도 있었다. 재귀로 푸는 예시도 참고할 만한 듯하다.



2. 숫자의 표현

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

1) 복잡도 계산

  • 시간 복잡도: O(n^2)
  • 공간 복잡도: O(1)

2) 접근 아이디어

  1. 시작 숫자를 1부터 n / 2까지 하나씩 올려가며 탐색했다.
  2. 각 시작점마다 연속된 수를 더해가면서 합을 누적했다.
  3. 합이 n이 되면 경우의 수를 하나 늘리고, n을 넘으면 그 시작점 탐색을 중단했다.

3) 회고

while문 하나로 푼 방식도 있었는데,

다른 사람 풀이:

function solution(n) {
    var answer = 0;
    let  i = 0;
    while(n > 0){
        i++;
       if(n % i  === 0)  answer++;
        n -= i;
    }
    return answer;
}

다른 사람 풀이 핵심: 연속합을 직접 모두 만들지 않고, while문 하나로 n을 줄여가며 나누어떨어지는 횟수만 세는 방식이었다.
내 생각: while문 하나로 푼 방식도 있었는데, 같은 문제를 보는 관점을 수열 합이 아니라 규칙으로 바꿔서 보면 더 간단해질 수 있다는 점이 인상적이었다.



@doitchuu doitchuu self-assigned this Apr 21, 2026
Copy link
Copy Markdown
Collaborator

@LeeBaeJin LeeBaeJin left a comment

Choose a reason for hiding this comment

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

수고많으셨습니다!

}

function countOne(num) {
return num.toString(2).replace(/0/g, "").length;
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.

준호님은 1을 찾으셨고, 슬기님은 0을 지우셨네요!
접근은 비슷하지만 과정에서의 차이를 보는 작은 재미가 있었습니다.

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.

저와 풀이가 비슷하시군요ㅎ

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.

ㅠㅠ 일이 많아서 리뷰 까먹고 있었네요 죄송🥹 고생하셨습니다!

@doitchuu doitchuu merged commit 6167a49 into pnt-fe-study:main May 6, 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