Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example 1:Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] n ์ด๋ผ๋ limit์ด ์์ผ๋ฉด,์ฌ๋ ๊ดํธ ์๋ฅผ openN, ๋ซ๋ ๊ดํธ ์๋ฅผ closeN์ด๋ผ๊ณ ํ์ ๋closeN closeN > openN์ด ๋๋ฉด well-formed parentheses๊ฐ ๋์ง ๋ชปํ๊ธฐ ๋๋ฌธ์ด๋ค. ์๋์ ๊ฐ์ด ํธ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ๊ทธ๋ ค๋ณด๋ฉฐ ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์๋ฅผ ์๊ฐํด๋ณผ ์ ์๋ค. ํ์ด1: ๋ฐฑํธ๋ํน, stack ์ด์ฉclass Solution: def generateParen..
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets. ํ์ด 1: ๋ธ๋ฃจํธ ํฌ์ค - ์๊ฐ ์ด๊ณผclass Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: res = set() nums.sort() for i in range(len(nums)): ..
Postfix NotationYou are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.Evaluate the expression. Return an integer that represents the value of the expression.Note that:The valid operators are '+', '-', '*', and '/'.Each operand may be an integer or another expression.The division between two integers always truncates toward zero.There will ..
URL์ ๋ธ๋ผ์ฐ์ ์ ์
๋ ฅํ์ ๋ ์ผ์ด๋๋ ๊ณผ์ ์ ๋ฅํ๊ฒ ์์๋ณด์! 1. URL ํ์ฑ๋ธ๋ผ์ฐ์ ๋ ์
๋ ฅ๋ URL์ ํด์ํ์ฌ ํ๋กํ ์ฝ / ๋๋ฉ์ธ ๋ค์ / ๊ฒฝ๋ก / ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ ๋ฑ์ผ๋ก ๋ถ๋ฆฌํ๋ค.๋ธ๋ผ์ฐ์ ๋ URL์์ example.com ์ด๋ผ๋ ๋๋ฉ์ธ ๋ค์์ ์ถ์ถํ๊ณ ์ด๋ฅผ ํตํด DNS ์ฟผ๋ฆฌ๊ฐ ์์๋๋ค. 2. DNS (Domain Name System) ์กฐํDomain Name์ ์ฌ๋์ด ์ดํดํ๊ธฐ ์ฌ์ด ์ฃผ์์ง๋ง, ์ปดํจํฐ๋ IP ์ฃผ์๋ฅผ ํตํด ํต์ ํ๋ค.DNS๋ ๋๋ฉ์ธ ๋ค์์ IP๋ก ๋ณํํ๊ธฐ ์ํด ์กด์ฌํ๋ค. ์น ๋ธ๋ผ์ฐ์ ๋ DNS ์๋ฒ์ ๊ฒ์ํ๊ธฐ ์ ์ ์บ์ฑ๋ DNS ๊ธฐ๋ก์ ๋จผ์ ํ์ธํ๋ค.์บ์์ ํด๋น ์ ๋ณด๊ฐ ์๋ค๋ฉด, ๋ธ๋ผ์ฐ์ ๋ ๋๋ฉ์ธ์ IP ์ฃผ์๋ก ๋ณํํ๊ธฐ ์ํด DNS ์๋ฒ์ ์์ฒญ์ ๋ณด๋ธ๋ค. ์ด ์์ฒญ์ ์ฌ์ฉ์์ ISP(In..
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:- MinStack() initializes the stack object.- void push(int val) pushes the element val onto the stack.- void pop() removes the element on the top of the stack.- int top() gets the top element of the stack.- int getMin() retrieves the minimum element in the stack.You must i..
Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain the digits 1-9 without repetition.Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.Note:A Sudoku board (partially filled) could be valid but is not necess..
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.You must write an algorithm that runs in O(n) time.longest consecutive sequence๋ฅผ ์ฐพ๋ ๋ฌธ์ ! O(n) ์์ผ๋ก ํ์ด์ผ ํ๋ค.์ฃผ์ํ ์ ์ constraints์ nums์ length๊ฐ 0๋ถํฐ ๊ฐ๋ฅํ๋ค๋ ๊ฒ Hash Set์ ์ด์ฉํ ํ์ดclass Solution: def longestConsecutive(self, nums: List[int]) -> int: numSet = set(nums) longest = 0 f..
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise.์ ํจํ palindrome(ํ๋ฌธ) ๊ฒ์ฌํ๋ ๋ฉ์๋ ๊ตฌํํ๊ธฐ! ํ์ด1: Reverse Stringclass Solution: def isPalindrome(self, s:..
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the correct order.Every close bracket has a corresponding open bracket of the same type.๊ดํธ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ง์ง์ด์ก๋์ง ํ์ธํ๋ ๋ฌธ์ ! ํ์ด1: Stack ์ด์ฉclass Solution: def isValid(sel..
์ ๋ค๋ฆญ(Generic)์ด๋?C๋ ์๋ฐ ๊ฐ์ ์ ์ ์ธ์ด์์ ๋ค์ํ ํ์
๊ฐ์ ์ฌ์ฌ์ฉ์ฑ์ ๋์ด๊ธฐ ์ํด ์ฌ์ฉํ๋ ๋ฌธ๋ฒ์ด๋ค. ํ์
์คํฌ๋ฆฝํธ๋ ์ ์ ํ์
์ ๊ฐ์ง๋ฏ๋ก ์ ๋ค๋ฆญ ๋ฌธ๋ฒ์ ์ง์ํ๋ค.์ ๋ค๋ฆญ์ ์ฌ์ ์ ์๋ฏธ๋ ์ผ๋ฐ์ ์ธ ๊ฒ(general)์ ๋ปํ๋๋ฐ, ํ์
์คํฌ๋ฆฝํธ์ ์ ๋ค๋ฆญ๋ ์ด์ ๋น์ทํ๊ฒ '์ผ๋ฐํ๋ ๋ฐ์ดํฐ' ํ์
์ด๋ผ ๋ณผ ์ ์๋ค.์ ๋ค๋ฆญ: ํจ์, ํ์
, ํด๋์ค ๋ฑ์์ ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉํ ํ์
์ ๋ฏธ๋ฆฌ ์ ํด๋์ง ์๊ณ ํ์
๋ณ์๋ฅผ ์ฌ์ฉํด์ ํด๋น ์์น๋ฅผ ๋น์ ๋ ๋ค์์, ์ค์ ๋ก ๊ทธ ๊ฐ์ ์ฌ์ฉํ ๋ ์ธ๋ถ์์ ํ์
๋ณ์ ์๋ฆฌ์ ํ์
์ ์ง์ ํ์ฌ ์ฌ์ฉํ๋ ๋ฐฉ์-> ์ด๋ ๊ฒ ํ๋ฉด ํจ์, ํ์
, ํด๋์ค ๋ฑ ์ฌ๋ฌ ํ์
์ ๋ํด ํ๋ํ๋ ๋ฐ๋ก ์ ์ํ์ง ์์๋ ๋๊ธฐ ๋๋ฌธ์ ์ฌ์ฌ์ฉ์ฑ์ด ํฌ๊ฒ ํฅ์๋๋ค.ํ์
๋ณ์๋ ์ผ๋ฐ์ ์ผ๋ก ์ ๊ฐ์ด ๊บพ์ ๊ดํธ ๋ด๋ถ์..