Skip to content

박영호_Maximum Subarray#61

Open
hexdrinker wants to merge 1 commit intomainfrom
hexdrinker/problem-3
Open

박영호_Maximum Subarray#61
hexdrinker wants to merge 1 commit intomainfrom
hexdrinker/problem-3

Conversation

@hexdrinker
Copy link
Copy Markdown
Contributor

🧑‍💻 언어 및 제출 결과

  • 사용 언어: JavaScript
  • 통과 여부: ✅

🧠 풀이 설명

var maxSubArray = function(nums) {
    let max = Number.MIN_SAFE_INTEGER;
    let endSum = 0;
    
    for (const num of nums) {
        endSum = Math.max(endSum + num, num);
        max = Math.max(endSum, max)
    }
    
    return max;
};
  • 첫번째 요소부터 해서 이중 for문 쓰려고했는데 이게 답이 아닌거 같아서 부분합 찾다가 카데인 알고리즘 발견함..
  • 마지막 요소 기준으로 생각해야함
  • 부분합 중 최대값 + 다음값, 다음값을 비교함.

📊 시간/공간 복잡도

✅ 어떠한 근거로 시간/공간 복잡도가 이렇게 나왔는지 설명해주세요.

⚡️ 풀이의 속도와 메모리 등을 캡쳐해서 올려주세요.

  • 시간 복잡도: O(n)
    • nums 길이만큼 순회하므로
  • 공간 복잡도: O(1)
    • 입력 크기 관계 없이 고정된 변수 사용함
스크린샷 2025-07-30 오후 10 24 31 스크린샷 2025-07-30 오후 10 24 48

📝 추가 설명 (선택)

  • 고민했던 포인트가 있다면 간단히 적어주세요.

🙋‍♂️ 리뷰어에게

  • 리뷰어가 보면 좋을 포인트, 질문, 궁금한 점 등을 작성해 주세요.

@github-actions github-actions bot added the TeamC Team label for TeamC label Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TeamC Team label for TeamC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant