wherehows
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
블로그 내 검색

wherehows

  • 알고리즘/리트코드

    152. Maximum Product Subarray

    2021. 5. 23.

    by. 창고

    https://leetcode.com/problems/maximum-product-subarray/

     

    Maximum Product Subarray - LeetCode

    Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

    leetcode.com

    곱이 가장 큰 subarray 찾기

     

    - 항상 현재 위치(nums[i])를 기준으로 preMin과 preMax를 갱신한다. 어차피 result가 최댓값을 기억한다.

    - 작았던 값이 커질 수 있다.

     

    Input: nums = [2,3,-2,4,-1];

    Input: nums = [-2,0,1];

     

    let preMin = Math.min(min * nums[i], nums[i], max * nums[i]);

    let preMax = Math.max(min * nums[i], nums[i], max * nums[i]);

     

    result = Math.max(result, preMax);

     

    '알고리즘 > 리트코드' 카테고리의 다른 글

    207. Course Schedule  (0) 2021.05.23
    1277. Count Square Submatrices with All Ones  (0) 2021.05.23
    53. Maximum Subarray  (0) 2021.05.23
    121. Best Time to Buy and Sell Stock  (0) 2021.05.23
    1557. Minimum Number of Vertices to Reach All Nodes  (0) 2021.05.20

    댓글

    관련글

    • 207. Course Schedule 2021.05.23
    • 1277. Count Square Submatrices with All Ones 2021.05.23
    • 53. Maximum Subarray 2021.05.23
    • 121. Best Time to Buy and Sell Stock 2021.05.23
    맨 위로
전체 글 보기
Tistory 로그인
Tistory 로그아웃
로그아웃 글쓰기 관리

Today

Total

Powered by ⓒ Kakao Corp.

Designed by Nana
블로그 이미지
창고

티스토리툴바