Skip to content

[Leetcode - Medium] Minimum Add to Make Parentheses Valid#41

Merged
github-actions[bot] merged 1 commit intomainfrom
bangdori/minimum-add-to-make-parentheses-valid
Jan 9, 2025
Merged

[Leetcode - Medium] Minimum Add to Make Parentheses Valid#41
github-actions[bot] merged 1 commit intomainfrom
bangdori/minimum-add-to-make-parentheses-valid

Conversation

@BangDori
Copy link
Member

@BangDori BangDori commented Jan 1, 2025

๋ฌธ์ œ

Type Info
Time Complexity O(N)
Space Complexity O(N)
Algorithm Stack
Data Structure Array

Constraints

  • 1 <= s.length <= 1000
  • s[i] is either '(' or ')'.

Edge Case

  • ์—†์Œ

ํ’€์ด

1. ๋ฌธ์ž์—ด s๋ฅผ ์ˆœํšŒํ•œ๋‹ค.
  1-1. ์—ด๋ฆฐ ๊ด„ํ˜ธ๋ผ๋ฉด ์Šคํƒ์— pushํ•œ๋‹ค.
  1-2. ๋‹ซํžŒ ๊ด„ํ˜ธ๋ผ๋ฉด ์Šคํƒ์— ๋งˆ์ง€๋ง‰์ด ์—ด๋ฆฐ ๊ด„ํ˜ธ์ธ์ง€ ํ™•์ธํ•œ๋‹ค.
    1-2-1. ์Šคํƒ์— ๋งˆ์ง€๋ง‰์ด ์—ด๋ฆฐ ๊ด„ํ˜ธ๋ผ๋ฉด popํ•œ๋‹ค.
    1-2-2. ๊ทธ๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด count๋ฅผ 1 ์ถ”๊ฐ€ํ•œ๋‹ค.
2. ์ตœ์ข…์ ์œผ๋กœ ์Šคํƒ์— ๋‚จ์•„์žˆ๋Š” ๊ด„ํ˜ธ๋งŒํผ count๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
3. count๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

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

  • ์—†์Œ

์•Œ๊ฒŒ๋œ ์ 

  • ์—†์Œ

@github-actions github-actions bot enabled auto-merge (squash) January 9, 2025 01:24
@github-actions github-actions bot merged commit eeabd90 into main Jan 9, 2025
2 checks passed
@BangDori BangDori deleted the bangdori/minimum-add-to-make-parentheses-valid branch January 10, 2025 01:46
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.

1 participant