Algorithm
[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%3D1756652399%26allow_ip%3D%26allow_referer%3D%26signature%3DucGirUJEpozmRz%252BwiCaTULhlP4Y%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문을 통해 처리하면 시간과 메모리를 아낄..
[LeetCode] 205. Isomorphic Strings (Daily Question)
문제 Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. 주어진 두 문자열 s, t가 같은 구조인지 판별하는 문제이다. 예를 들면, egg와 add는 구..