From 942b27bda56bf2b6fc2ed98e8daf70ef314105dc Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 17 Sep 2026 22:32:52 +0900 Subject: [PATCH 1/2] Create 463. Island Perimeter.py --- .../463. Island Perimeter.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/463. Island Perimeter.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/463. Island Perimeter.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/463. Island Perimeter.py" new file mode 100644 index 000000000..ead912eed --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/463. Island Perimeter.py" @@ -0,0 +1,40 @@ +class Solution: + def islandPerimeter(self, grid: list[list[int]]) -> int: + n = len(grid) + m = len(grid[0]) + dx = [0,0,1,-1] + dy = [1,-1,0,0] + + def bfs(row, col): + ans = 0 + grid[row][col] = 2 + queue = Deque() + queue.append([row,col]) + + while queue: + x, y = queue.popleft() + perimeter = 4 + for dirs in range(4): + nx = x + dx[dirs] + ny = y + dy[dirs] + + if nx < 0 or n <= nx or ny < 0 or m <= ny: + continue + elif 0<=nx Date: Thu, 17 Sep 2026 22:33:10 +0900 Subject: [PATCH 2/2] Create 385. Mini Parser.py --- .../385. Mini Parser.py" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/385. Mini Parser.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/385. Mini Parser.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/385. Mini Parser.py" new file mode 100644 index 000000000..8165eeee2 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/385. Mini Parser.py" @@ -0,0 +1,95 @@ +# """ +# This is the interface that allows for creating nested lists. +# You should not implement it, or speculate about its implementation +# """ +#class NestedInteger: +# def __init__(self, value=None): +# """ +# If value is not specified, initializes an empty list. +# Otherwise initializes a single integer equal to value. +# """ +# +# def isInteger(self): +# """ +# @return True if this NestedInteger holds a single integer, rather than a nested list. +# :rtype bool +# """ +# +# def add(self, elem): +# """ +# Set this NestedInteger to hold a nested list and adds a nested integer elem to it. +# :rtype void +# """ +# +# def setInteger(self, value): +# """ +# Set this NestedInteger to hold a single integer equal to value. +# :rtype void +# """ +# +# def getInteger(self): +# """ +# @return the single integer that this NestedInteger holds, if it holds a single integer +# The result is undefined if this NestedInteger holds a nested list +# :rtype int +# """ +# +# def getList(self): +# """ +# @return the nested list that this NestedInteger holds, if it holds a nested list +# The result is undefined if this NestedInteger holds a single integer +# :rtype List[NestedInteger] +# """ + +class Solution: + def deserialize(self, s: str) -> NestedInteger: + if s[0] != "[": + return NestedInteger(int(s)) + + s = s[1:len(s)-1] + n = len(s) + + def dfs(index): + contains = NestedInteger() + + num = 0 + is_positive = 1 + has_num = False + + while index < n: + if s[index] == "[": + child, index = dfs(index + 1) + contains.add(child) + + elif s[index] == "-": + is_positive = -1 + + elif s[index].isdigit(): + num = num * 10 + int(s[index]) + has_num = True + + elif s[index] == ",": + if has_num: + contains.add(NestedInteger(num * is_positive)) + num = 0 + is_positive = 1 + has_num = False + + elif s[index] == "]": + if has_num: + contains.add(NestedInteger(num * is_positive)) + + return contains, index + + index += 1 + + if has_num: + if not is_positive: + num *= -1 + + contains.add(NestedInteger(num)) + + return contains, index + + ans, _ = dfs(0) + return ans