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

BOJ(TLE): 11501 #55

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

BOJ(TLE): 11501 #55

wants to merge 2 commits into from

Conversation

mu-hun
Copy link
Owner

@mu-hun mu-hun commented Jun 9, 2020

https://www.acmicpc.net/problem/11501

하나의 주식을 사서 얻을 수 있는 최대 이익 문제의 변형으로, 살 수 있는 주식의 수가 제한이 없다.

O(n^2) 보다 더 줄일 수 없을까?

O(n^2) 걸릴 수 밖에 없지 않나?
@mu-hun
Copy link
Owner Author

mu-hun commented Jun 9, 2020

기본 문제에서는 "언제 팔 것인가"를 중심으로 max, min 을 갱신하는 방법으로 O(n)에 풀 수 있는 문제였다:

calculateMaxProfit(prices: number[]) {
  let max = 0
  let min = prices[0]
  for (const price of prices.slice(1)) {
    min = Math.min(min, price)
    max = Math.max(max, price - min)
  }
  return max
}

max_profit 은 항상 양수입니다.
@mu-hun mu-hun added the help wanted Extra attention is needed label Mar 20, 2021
@mu-hun mu-hun marked this pull request as draft March 20, 2021 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant