From 51d48687baa318284289c99b2f64b8b3983313fb Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:49:55 +0900 Subject: [PATCH 1/2] Create 2305. Fair Distribution of Cookies.py --- .../2305. Fair Distribution of Cookies.py" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/2305. Fair Distribution of Cookies.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/2305. Fair Distribution of Cookies.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/2305. Fair Distribution of Cookies.py" new file mode 100644 index 00000000..74558a83 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/2305. Fair Distribution of Cookies.py" @@ -0,0 +1,34 @@ +# + +''' +1. 아이디어 : +모든 경우의 수를 구할 수 있다. + +2. 시간복잡도 : + O(n ** k) + +3. 자료구조/알고리즘 : +백트래킹 + +''' +class Solution: + ans = float('inf') + + def distributeCookies(self, cookies: list[int], k: int) -> int: + child_total = [0] * k + + def backtrack(idx): + if idx == len(cookies): + self.ans = min(self.ans, max(child_total)) + return + + for i in range(k): + child_total[i] += cookies[idx] + + if child_total[i] < self.ans: + backtrack(idx+1) + + child_total[i] -= cookies[idx] + + backtrack(0) + return self.ans From fb702a0069b8569e9b475c78c28871a7f773769d Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:50:06 +0900 Subject: [PATCH 2/2] Create 988. Smallest String Starting From Leaf.py --- ...88. Smallest String Starting From Leaf.py" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/988. Smallest String Starting From Leaf.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/988. Smallest String Starting From Leaf.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/988. Smallest String Starting From Leaf.py" new file mode 100644 index 00000000..1cbc59f8 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/988. Smallest String Starting From Leaf.py" @@ -0,0 +1,45 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right + +# + +''' +1. 아이디어 : +dfs를 통해 leaf까지 도달할때까지 char를 더합니다. +리턴조건은 4개: +- 리프 노드 +- 왼쪽 노드만 존재 +- 오른쪽 노드만 존재 +- 중간 노드 + +2. 시간복잡도 : + O(n) + +3. 자료구조/알고리즘 : +dfs + +''' +class Solution: + def smallestFromLeaf(self, node: TreeNode | None, path: str = "") -> str: + if not node: + return "" + + path = chr(97 + node.val) + path + + if not node.left and not node.right: + return path + + if not node.left: + return self.smallestFromLeaf(node.right, path) + + if not node.right: + return self.smallestFromLeaf(node.left, path) + + return min( + self.smallestFromLeaf(node.left, path), + self.smallestFromLeaf(node.right, path) + )