Skip to content

Best Time to Buy and Sell Stock#27

Merged
asuan99 merged 1 commit intomainfrom
legitgoons/best-time-to-buy-and-sell-stock
Dec 26, 2024
Merged

Best Time to Buy and Sell Stock#27
asuan99 merged 1 commit intomainfrom
legitgoons/best-time-to-buy-and-sell-stock

Conversation

@Legitgoons
Copy link
Collaborator

๋ฌธ์ œ

Type Info
Time Complexity 2ms
Space Complexity 59.91mb
Algorithm ๊ตฌํ˜„
Data Structure

Constraints

  • 1 <= prices.length <= 10^5
  • 0 <= prices[i] <= 10^4

Edge Case

ํ’€์ด

  • 2์ค‘ For๋ฌธ ๋Œ๋ฆฌ๊ธฐ -> ์‹œ๊ฐ„๋ณต์žก๋„ O(n^2)์ธ๋ฐ 100000^2์€ ๊ฐ๋‹น๋ถˆ๊ฐ€
  • ํˆฌ ํฌ์ธํ„ฐ๋กœ ํ’€๋ฉด ๋˜์ง€์•Š์„๊นŒ? -> ๊ตฌํ˜„ํ•˜๋‹ค๊ฐ€ ๊นจ๋‹ฌ์•˜๋Š”๋ฐ ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ์ ์šฉํ•˜๋ฉด ์ด์ค‘ for๋ฌธ์ด๋ผ์„œ ํ„ฐ์ง
  • ๊ทธ๋ƒฅ ๋ฐ˜๋ณต๋ฌธ ๋Œ๋ฉด์„œ, ์ง€๊ธˆ๊นŒ์ง€ ๊ฐ’์ด๋ž‘ ๋น„๊ตํ–ˆ์„ ๊ฐ€์žฅ ์ž‘์€๊ฐ’์ด ์–˜์ธ์ง€ check
  • ๊ทธ ๋‹ค์Œ ํ˜„์žฌ๊นŒ์ง€ ์ตœ๊ณ ์ด๋“ vs ์ง€๊ธˆ๊ฐ’ - ์ตœ์†Œ๊ฐ’

์–ด๋ ค์› ๋˜ ์ 

  • ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ์ž˜๋ชป ์ ์šฉํ•ด์„œ ์ข€ ํ—ค๋งธ์Œ

์•Œ๊ฒŒ๋œ ์ 

  • ๋ฌด์ง€์„ฑ์œผ๋กœ ์•„๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋ผ์›Œ๋งž์ถ”์ง€ ๋ง๊ณ , ๋ธŒ๋ฃจํŠธ ํฌ์Šค๋ถ€ํ„ฐ ์ฐจ๊ทผํžˆ ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž

@asuan99 asuan99 merged commit cad3a16 into main Dec 26, 2024
2 checks passed
@BangDori BangDori deleted the legitgoons/best-time-to-buy-and-sell-stock branch December 26, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants