leetcode
[LeetCode] 1249. Minimum Remove to Make Valid Parentheses (Daily Question)
문제 Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: - It is the empty string, contains only lowercase characters, or - It can be written as AB (A concatenated..
[LeetCode] 1544. Make The String Great (Daily Question)
문제 Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: - 0 "aAcC" --> "cC" --> "" 예시를 보면 없애야 하는 부분을 없앴더니 새로운 부분이 생긴 것을 볼 수 있다. 풀이 아이디어 알파벳은 26개로, 같은 알파벳이 대소문자로 붙어있는 경우는 26*2(소문자+대문자, 대문자+소문자), 32가지 밖에 없다. 주어지는 문자열의 길이도 최대 100으로, 짧기 때문에 없애야 하는 부분을 미리 정의해 두고 문자열이 더 이상 바뀌지 않을 때까지 반복하면 좋은 문자열이 될 것이다. ..
![[LeetCode] 1111. Maximum Nesting Depth of Two Valid Parentheses Strings](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FGlaKQ%2FbtsGmMTD7E8%2FAAAAAAAAAAAAAAAAAAAAABJOZrvkbi9XU8ScWmKlZe2234JbkkfD2Xu6QRbjU6yi%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DnGUjZzDI6LdjVx2z9QIT7cDkpLo%253D)
[LeetCode] 1111. Maximum Nesting Depth of Two Valid Parentheses Strings
문제 A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only. Given a VPS seq, split it into two disjoint subsequences A and B, such that A and B are VPS's (and A.length + B.length = seq.length). Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value. Return an answer array (of length seq.length) that encod..
[LeetCode] 1614. Maximum Nesting Depth of the Parentheses (Daily Question)
문제 A string is a valid parentheses string (denoted VPS) We can similarly define the nesting depth depth(S) of any VPS S Given a VPS represented as string s, return the nesting depth of s. 괄호, 숫자, 연산자로 이루어진 문자열이 주어졌을 때, 괄호의 최대 깊이를 구하는 문제이다.예를 들면 "()"의 깊이는 1, "(((8)))"의 깊이는 3, "(1+(2*3)+((8)/4))+1"의 깊이는 3이다. 풀이 아이디어 문자열을 앞에서부터 살펴보며 열린괄호가 나왔을 때는 깊어지고 닫힌괄호가 나왔을 때는 얕아지는 것으로 생각 코드 class Solution: def ..
![[LeetCode] 79. Word Search (Daily Question)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FbpTbTX%2FbtsGiZAjorb%2FAAAAAAAAAAAAAAAAAAAAABrYha0ZEvTcCYzvVXtRDfhjboNa9fsLr--Vj_pexXEC%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DKdZsck53fPiJ15RirWcbvVghsdI%253D)
[LeetCode] 79. Word Search (Daily Question)
문제 Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. 영문자로 구성된 보드와 단어가 주어졌을 때, 단어가 보드에 있는지 판별하는 문제이다. 문자끼리는 가로 및 세로로 연결되어 있어야 한다. 에를 들면, board는 [["A","B","C","..
[LeetCode] 12. Integer to Roman
문제 Given an integer, convert it to a roman numeral. 1 0001, 23 -> 0023 num_s = str(num).zfill(4) return thousands[int(num_s[0])] + hundreds[int(num_s[1])] + tens[int(num_s[2])] + ones[int(num_s[3])] 후기 난이도 경우의 수가 많지 않다는 것을 파악하면 쉽게 구현할 수 있다. 로마 숫자의 범위가 거의 안 쓰는 F(5000)를 포함하더라도 원래 작지만, 만약 더 큰 수를 나타내는 표기가 많아져 주어지는 수의 범위가 커지더라도, 규칙성을 이용해 쉽게 풀 수 있을 것이다. 다른 풀이 경우의 수를 미리 정의하지 않고 if문을 통해 처리하면 시간과 메모리를 아낄..