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

5-erase-jeong #18

Merged
merged 2 commits into from
Jul 10, 2024
Merged

5-erase-jeong #18

merged 2 commits into from
Jul 10, 2024

Conversation

erase-jeong
Copy link
Collaborator

@erase-jeong erase-jeong commented Apr 14, 2024

commit

πŸ”— 문제 링크

κΈ°λŠ₯개발

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

λŒ€λž΅ 1μ‹œκ°„μ •λ„..? 1μ‹œκ°„λ³΄λ‹€λŠ” 덜 κ±Έλ¦°λ“―

✨ μˆ˜λ„ μ½”λ“œ

  1. 각 μž‘μ—…μ΄ μ™„λ£Œλ˜κΈ°κΉŒμ§€ ν•„μš”ν•œ 일수λ₯Ό κ³„μ‚°ν•˜μ—¬ devTime λ¦¬μŠ€νŠΈμ— μ €μž₯ν•œλ‹€.
  2. devTime 리슀트λ₯Ό μˆœνšŒν•˜λ©΄μ„œ 배포가 κ°€λŠ₯ν•œ μž‘μ—…λ“€μ„ κ·Έλ£Ήν™”ν•˜μ—¬ answer λ¦¬μŠ€νŠΈμ— μ €μž₯ν•œλ‹€.
    • 첫 번째 μž‘μ—…μ˜ 일수λ₯Ό κΈ°μ€€μœΌλ‘œ(tmp) 이후 μž‘μ—…λ“€μ˜ 일수λ₯Ό λΉ„κ΅ν•œλ‹€.
    • λ§Œμ•½ devTime[i]κ°€ tmp보닀 크닀면 μƒˆλ‘œμš΄ 배포 그룹을 μƒμ„±ν•˜κ³ , 그렇지 μ•Šλ‹€λ©΄ ν˜„μž¬ 배포 그룹에 ν¬ν•¨μ‹œν‚¨λ‹€.
  3. μ΅œμ’…μ μœΌλ‘œ answer 리슀트λ₯Ό λ°˜ν™˜ν•œλ‹€.

μ½”λ“œ 해석

def solution(progresses, speeds):
    devTime = []
    answer = []
    count = 0

    # 각 μž‘μ—…μ΄ μ™„λ£Œλ˜κΈ°κΉŒμ§€ ν•„μš”ν•œ 일수λ₯Ό 계산
    for i in range(len(progresses)):
        time = (100 - progresses[i]) / speeds[i]
        if time % 1 != 0:
            time = time // 1 + 1  # 올림 처리
        devTime.append(int(time))

    # 배포 κ°€λŠ₯ν•œ μž‘μ—…λ“€μ„ κ·Έλ£Ήν™”
    tmp = devTime[0]
    for i in range(1, len(devTime)):
        if tmp < devTime[i]:
            count += 1
            answer.append(count)
            count = 0
            tmp = devTime[i]
        else:
            count += 1

       #반볡문이 λ§ˆμ§€λ§‰ μš”μ†Œλ₯Ό μ²˜λ¦¬ν•  λ•Œ
        if i == len(devTime) - 1:  
            answer.append(count + 1)

    return answer

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@Me-in-U
Copy link
Collaborator

Me-in-U commented May 30, 2024

public static int[] solution(int[] progresses, int[] speeds) {
    List<Integer> result = new ArrayList<>();
    int[] days = new int[progresses.length];
    for (int i = 0; i < days.length; i++) {
        days[i] = (int) Math.ceil((100 - progresses[i]) / (double) speeds[i]);
    }
    int maxDay = days[0];
    int count = 1;
    for (int i = 1; i < days.length; i++) {
        if (maxDay >= days[i]) {
            count++;
        } else if (maxDay < days[i]) {
            result.add(count);
            maxDay = days[i];
            count = 1;
        }
    }
    result.add(count);
    return result.stream().mapToInt(i -> i).toArray();
}

ceil ν•¨μˆ˜λ‘œ 가독성을 높이면 μ’‹μ„κ²ƒκ°™μŠ΅λ‹ˆλ‹€.

Copy link
Collaborator

@wjdheesp44 wjdheesp44 left a comment

Choose a reason for hiding this comment

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

import math

def solution(progresses, speeds):
    answer = []
    stack = []

    for i, (progress, speed) in enumerate(zip(progresses, speeds)):
        date = math.ceil((100-progress)/speed)

        if not stack or stack[-1][0] < date:
            stack.append([date, 1])
        else:
            stack[-1][1] += 1

    for i, cnt in stack:
        answer.append(cnt)
        
    return answer

μ €λŠ” 이런 μ‹μœΌλ‘œ μŠ€νƒμ„ μ΄μš©ν–ˆμ–΄μš”. μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€!

@erase-jeong erase-jeong merged commit 60b11d6 into main Jul 10, 2024
@erase-jeong erase-jeong deleted the 5-erase-jeong branch July 10, 2024 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants