알고리즘(48)
-
[LeetCode] Daily Temperatures (Python)
보호되어 있는 글입니다.
2024.03.06 -
[LeetCode] Valid Parentheses (Python)
class Solution: def isValid(self, s: str) -> bool: stack=[] brackets={'}':'{',')':'(',']':'['} for bracket in s: if bracket in brackets.values(): stack.append(bracket) else: if stack and brackets[bracket]==stack[-1] : stack.pop() else: return False if stack: return False return True
2024.03.06 -
[백준 13458] 시험감독 (Python)
N = int(input()) A = list(map(int, input().split())) B, C = map(int, input().split()) answer = 0 for i in range(len(A)): if A[i]
2024.03.05 -
[LeetCode] Perfect Squares (Python)
보호되어 있는 글입니다.
2024.03.05 -
[LeetCode] Open the Lock (Python)
보호되어 있는 글입니다.
2024.03.05 -
[LeetCode] Number of Islands (Python)
from collections import deque class Solution: def numIslands(self, grid: List[List[str]]) -> int: islands = 0 M = len(grid) N = len(grid[0]) visited = [[False] * N for _ in range(M)] def bfs(x, y): dx = [-1, 0, 0, 1] dy = [0, -1, 1, 0] visited[x][y] = True q = deque() q.append((x, y)) while q: cur_x, cur_y = q.popleft() for i in range(4): nx, ny = cur_x + dx[i], cur_y + dy[i] if nx >= 0 and nx <..
2024.03.05