분류 전체보기(221)
-
[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 -
[LeetCode] Design Circular Queue (Python)
보호되어 있는 글입니다.
2024.03.05 -
[LeetCode] Find All Numbers Disappeared in an Array (Python)
class Solution: def findDisappearedNumbers(self, nums: List[int]) -> List[int]: temp = set(range(1,len(nums)+1)) answer = temp - set(nums) return answer
2024.03.03 -
[LeetCode] Third Maximum Number (Python)
class Solution: def thirdMax(self, nums: List[int]) -> int: nums = set(nums) nums = sorted(nums, reverse=True) if len(nums) < 3: answer = nums[0] else: answer = nums[2] return answer
2024.03.03 -
[LeetCode] Height Checker (Python)
class Solution: def heightChecker(self, heights: List[int]) -> int: new_h = sorted(heights) match = 0 for i in range(len(heights)): if heights[i] != new_h[i]: match += 1 return match
2024.03.03