Skip to content

Commit

Permalink
2024-06-07 16:24:34
Browse files Browse the repository at this point in the history
Affected files:
.obsidian/workspace.json
src/content/blog/leet-code-minimum-path-sum.md
  • Loading branch information
gyunseo committed Jun 7, 2024
1 parent 9ce062b commit 4275c20
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 15 deletions.
35 changes: 20 additions & 15 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@
"type": "split",
"children": [
{
"id": "4d80a0b9491269e4",
"id": "af13f5421c20f0f4",
"type": "tabs",
"children": [
{
"id": "0f0fd716299d38e2",
"id": "6744425213e811d2",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "src/content/blog/boj-5014-스타트링크.md",
"file": "src/content/blog/boj-1940-주몽.md",
"mode": "source",
"source": false
}
}
},
}
]
},
{
"id": "1e447cff571d4449",
"type": "tabs",
"children": [
{
"id": "6352edd452388512",
"id": "7b370b6893c04ec7",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "src/content/blog/boj-random-defense.md",
"file": "src/content/blog/leet-code-minimum-path-sum.md",
"mode": "source",
"source": false
}
}
}
],
"currentTab": 1
]
}
],
"direction": "vertical"
Expand Down Expand Up @@ -99,7 +104,7 @@
"state": {
"type": "backlink",
"state": {
"file": "src/content/blog/boj-random-defense.md",
"file": "src/content/blog/leet-code-minimum-path-sum.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -116,7 +121,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "src/content/blog/boj-random-defense.md",
"file": "src/content/blog/leet-code-minimum-path-sum.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -139,7 +144,7 @@
"state": {
"type": "outline",
"state": {
"file": "src/content/blog/boj-random-defense.md"
"file": "src/content/blog/leet-code-minimum-path-sum.md"
}
}
}
Expand All @@ -162,8 +167,10 @@
"table-editor-obsidian:Advanced Tables Toolbar": false
}
},
"active": "6352edd452388512",
"active": "7b370b6893c04ec7",
"lastOpenFiles": [
"src/content/blog/boj-1940-주몽.md",
"src/content/blog/leet-code-minimum-path-sum.md",
"src/content/blog/boj-5014-스타트링크.md",
"src/content/blog/boj-random-defense.md",
"src/content/blog/boj-14425-문자열-집합.md",
Expand Down Expand Up @@ -196,7 +203,6 @@
"src/content/blog/boj-11507-오르막-수.md",
"src/content/blog/boj-10819-차이를-최대로.md",
"src/content/blog/boj-2230-수-고르기.md",
"src/content/blog/boj-1940-주몽.md",
"src/content/blog/boj-1912-연속합.md",
"src/content/blog/boj-1699-제곱수의-합.md",
"src/content/blog/boj-1026-보물.md",
Expand All @@ -208,7 +214,6 @@
"Excalidraw/Drawing 2024-03-24 18.59.55.excalidraw.md",
"src/content/blog/change-apt-get-source-server.md",
"src/content/blog/personal-statement-for-an-application.md",
"src/content/blog/software-maestro-application.md",
"src/content/blog/24-sw-maestro-1st-coding-test.md"
"src/content/blog/software-maestro-application.md"
]
}
54 changes: 54 additions & 0 deletions src/content/blog/leet-code-minimum-path-sum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
author: Gyunseo Lee
title: "LeetCode: Minimum Path Sum"
pubDatetime: 2024-06-07T16:20:00+09:00
modDatetime: 2024-06-07T16:20:00+09:00
featured: false
draft: false
tags:
- DP
- PS
- Algorithms
- LeetCode
description: DP 웰노운인 최소 거리 합 문제를 풀어 보자...
ogImage: ""
---

## Table of contents

## 들어가며

이 문제는 움직일 수 있는 방향이 오른쪽과 아래 방향이어서 쉽게 DP 문제로 생각해 볼 수 있었습니다. 👍

## AC 받은 Python 코드

```python
from typing import List
import sys

input = sys.stdin.readline


class Solution:
def minPathSum(self, grid: List[List[int]]) -> int:
len_row = len(grid)
len_col = len(grid[0])
for i in range(len_row):
for j in range(len_col):
if i == 0 and j == 0:
continue

if i == 0:
grid[i][j] = grid[i][j - 1] + grid[i][j]
elif j == 0:
grid[i][j] = grid[i - 1][j] + grid[i][j]
else:
grid[i][j] = min(grid[i - 1][j], grid[i][j - 1]) + grid[i][j]
return grid[len_row - 1][len_col - 1]


if __name__ == "__main__":
sol = Solution()
grid = eval(input().rstrip())
print(sol.minPathSum(grid))
```

0 comments on commit 4275c20

Please sign in to comment.