From ab77dca1e5d383ae6c85a157d192b2179d557830 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:02:34 +0900 Subject: [PATCH 1/2] Create 1320. Minimum Distance to Type a Word Using Two Fingers.py --- ...tance to Type a Word Using Two Fingers.py" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1320. Minimum Distance to Type a Word Using Two Fingers.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1320. Minimum Distance to Type a Word Using Two Fingers.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1320. Minimum Distance to Type a Word Using Two Fingers.py" new file mode 100644 index 00000000..be2ec793 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1320. Minimum Distance to Type a Word Using Two Fingers.py" @@ -0,0 +1,48 @@ +# + +''' +1. 아이디어 : +[i][a][b]는 i번째 알파뱃을 입력하고 난 후 왼손의 위치(a), 오른손의 위치(b)의 최소값입니다. +다음 알파뱃인 c를 입력하기 위해서는 +- dp[i]에서 왼손을 움직이거나(dp[i][a][c]) +- dp[i]에서 오른손을 움직입니다(dp[i+1][c][b]) + +2. 시간복잡도 : + O(n * 27 * 27) + +3. 자료구조/알고리즘 : +3차원 dp + +''' +class Solution: + def minimumDistance(self, word: str) -> int: + def dist(a, b): + if a == 26: + return 0 + return abs(a // 6 - b // 6) + abs(a % 6 - b % 6) + + # 3차원 DP + n = len(word) + dp = [[[float('inf')] * 27 for _ in range(27)] for _ in range(n + 1)] + + dp[0][26][26] = 0 + + for i in range(n): + c = ord(word[i]) - ord('A') + + for a in range(27): + for b in range(27): + curr = dp[i][a][b] + + if curr == float('inf'): + continue + + dp[i+1][c][b] = min( dp[i+1][c][b], curr + dist(a, c)) # 왼손 + + dp[i+1][a][c] = min( dp[i+1][a][c], curr + dist(b, c)) # 오른손 + + ans = float('inf') + for a in range(27): + for b in range(27): + ans = min(ans, dp[n][a][b]) + return ans From a1b3fb3c6c30ddc7999339dca6f3ab909c34d86b Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:05:19 +0900 Subject: [PATCH 2/2] Create 1706. Where Will the Ball Fall.py --- .../1706. Where Will the Ball Fall.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1706. Where Will the Ball Fall.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1706. Where Will the Ball Fall.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1706. Where Will the Ball Fall.py" new file mode 100644 index 00000000..f45b98dd --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1706. Where Will the Ball Fall.py" @@ -0,0 +1,28 @@ +class Solution: + def findBall(self, grid: list[list[int]]) -> list[int]: + m = len(grid) + n = len(grid[0]) + answer = [] + + for start in range(n): + col = start + + for row in range(m): + next_col = col + grid[row][col] + + # 벽에 부딪히는 경우 + if next_col < 0 or next_col >= n: + col = -1 + break + + # V자 형태로 막히는 경우 + if grid[row][col] != grid[row][next_col]: + col = -1 + break + + # 다음 열로 이동 + col = next_col + + answer.append(col) + + return answer