Skip to content

Conversation

@snughnu
Copy link
Contributor

@snughnu snughnu commented Jul 5, 2025

1. 롤케이크 자르기 - 구현

🔗 문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/132265

✔️ 소요된 시간

30분

✨ 수도 코드

func solution(_ topping: [Int]) -> Int {
    // topping에서 왼쪽 오른쪽을 Set으로 만들어서 비교
    for i in (1..<topping.count) {
        // 왼쪽 집합 만들기
        // 오른쪽 집합 만들기

        // if 왼쪽집합개수 == 오른쪽집합개수 { count += 1 }
    }
}

1차 잘못된 구현

  • 매 반복마다 새로운 배열을 만들어서 O(n^2)의 시간복잡도를 가짐 -> 시간초과
func solution(_ topping: [Int]) -> Int {
    // 먼저 모든 토핑을 rightDict에 저장
        // 오른쪽은 Dictionary로 개수도 파악하기
    // 왼쪽에서 하나씩 늘려가면서 비교하기
        // 왼쪽은 Set으로 종류만 파악해도 충분
}

2차 개선

  • 먼저 모든 토핑을 rightDict에 저장하고
  • 왼쪽부터 하나씩 Set에 넣고, 오른쪽은 한개씩 빼고
    • 왼쪽Set의 개수 == 오른쪽Dictionary의 개수 -> 카운팅

📚 새롭게 알게된 내용

  • 1차 잘못된 구현때 배열을 만드는 새로운 방법을 알았어요

2. 기능개발 - 스택

🔗 문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/42586

✔️ 소요된 시간

30분

✨ 수도 코드

func solution(_ progresses: [Int], _ speeds: [Int]) -> [Int] {
    // 남은 배포일 계산

    // 스택에 넣으면서 결과 만들기
        // 같은 배포일을 가질때 처리
            // top과 비교해서 스택에 넣기
        // 다른 배포일을 가질때 처리
            // 기존 스택의 개수를 기록하고, 스택 비우기
}

📚 새롭게 알게된 내용

  • 스택을 사용하지 않아도 비슷한 로직으로 풀 수 있네요

@snughnu snughnu changed the title Week7sunghun kim Week7_SunghunKim Jul 5, 2025
@snughnu snughnu self-assigned this Jul 5, 2025
@snughnu snughnu added ✏️ 문제 더 풀거에요 Something isn't working 🥳 리뷰 해주세요 Improvements or additions to documentation 👾 문제 다 풀었어요 Extra attention is needed and removed ✏️ 문제 더 풀거에요 Something isn't working labels Jul 5, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

저도 첫번째 방법을 가장 먼저 생각했네요,,, 핵심은 저장 데이터?를 적게 만드는 것 같습니당 이 코드로 중복 검사를 set외에 dictonary를 이용하는 방법 있다는 걸 알게 되었습니다☺️

Copy link
Contributor

Choose a reason for hiding this comment

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

저는 큐를 생각했는데, 생각해보니 결국 어차피 한 방향으로 꺼내기만 하는거라 스택이든 큐든 상관이 없네용

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 스택 큐 둘다 안쓰고도 되더라구요

Copy link
Member

Choose a reason for hiding this comment

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

뒤에다가 !를붙이는군요 스위프트에서는 신기하네요!
수고하셨습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

딕셔너리는 키로 값을 찾을때 보통 null이 나올 수 있는 자료구조니깐 값을 꺼낼때 조심해야해요
근데 !는 안전하게 값을 꺼내는 방법이 아닌 강제로 꺼내는 방식인데,
앞에 코드에서 딕셔너리에 값을 직접 등록했기 때문에 해당 키 값이 반드시 존재한다고 확신하고 !를 썼습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👾 문제 다 풀었어요 Extra attention is needed 🥳 리뷰 해주세요 Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants