Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4576de1

Browse files
committed
[20220814] 306 contest ์ฐธ๊ฐ€
1 parent c7582f2 commit 4576de1

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://leetcode.com/contest/weekly-contest-306/problems/largest-local-values-in-a-matrix/
2+
from typing import List
3+
4+
5+
class Solution:
6+
def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:
7+
8+
result = []
9+
for i in range(0, len(grid) - 2):
10+
inner = []
11+
for j in range(0, len(grid[i]) - 2):
12+
mv = 0
13+
for p in range(3):
14+
for q in range(3):
15+
mv = max(mv, grid[i + p][j + q])
16+
inner.append(mv)
17+
result.append(inner)
18+
return result
19+
20+
21+
if __name__ == '__main__':
22+
sol = Solution()
23+
grid = [[9, 9, 8, 1], [5, 6, 2, 6], [8, 2, 6, 4], [6, 2, 2, 2]]
24+
print(sol.largestLocal(grid))
25+
26+
grid2 = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]
27+
print(sol.largestLocal(grid2))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://leetcode.com/contest/weekly-contest-306/problems/node-with-highest-edge-score/
2+
from typing import List
3+
4+
5+
class Solution:
6+
def edgeScore(self, edges: List[int]) -> int:
7+
graph = [0 for _ in range(len(edges))]
8+
9+
for i in range(len(edges)):
10+
graph[edges[i]] += i
11+
12+
cur_max = -1
13+
cur_node = -1
14+
for i in range(len(graph)):
15+
if cur_max < graph[i]:
16+
cur_max = graph[i]
17+
cur_node = i
18+
elif cur_max == graph[i]:
19+
cur_node = min(cur_node, i)
20+
21+
return cur_node
22+
23+
24+
if __name__ == '__main__':
25+
sol = Solution()
26+
print(sol.edgeScore([1, 0, 0, 0, 0, 7, 7, 5]))
27+
print(sol.edgeScore([2, 0, 0, 2]))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Weekly Contest 306
2+
3+
https://leetcode.com/contest/weekly-contest-306/
4+
5+
### 2373. Largest Local Values in a Matrix
6+
7+
๋ฌธ์ œ๊ฐ€ ๋ญ๋ผ๊ณ  ํ•˜๋Š”์ง€ ๋ชฐ๋ผ์„œ ์‚ด์ง ๋‹นํ™ฉํ–ˆ๋‹ค.
8+
๋‹จ์ˆœ ๊ตฌํ˜„ ๋ฌธ์ œ์˜€๋Š”๋ฐ ๋ฉ˜ํƒˆ์ด ํ„ธ๋ฆฌ๋ฉด ๋ฐ”๋กœ ๋ชป ํ’€๊ฒƒ ๊ฐ™์€ ๊ทธ๋Ÿฐ ๋ฌธ์ œ์˜€์Œ
9+
10+
### 2374. Node With Highest Edge Score
11+
12+
์ž์ฃผ ํ’€์–ด๋ดค๋˜ ๊ทธ๋ž˜ํ”„ ๋ฌธ์ œ๋กœ 1๋ฒˆ ๋ณด๋‹ค ์‰ฌ์› ๋‹ค.
13+
14+
### 2375. Construct Smallest Number From DI String
15+
16+
์ด ๋ฌธ์ œ ๊ทธ๋ฆฌ๋””๋กœ ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๊ธดํ•œ๋ฐ ์•„์ด๋””์–ด๊ฐ€ ์ƒ๊ฐ์ด ์•ˆ๋‚จ
17+
18+
> ๊ทธ๋ฆฌ๋””๋Š” ์ง„์งœ ๋‡Œ์ง€์ปฌ์ด ์ค‘์š”ํ•œ๋“ฏ
19+
20+
์•ž์—์„œ๋ถ€ํ„ฐ ์ž‘์€ ๊ฐ’์„ ์ฑ„์›Œ๋„ฃ์œผ๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ๊นŒ๋‹ค๋กœ์› ์Œ
21+
์ด๋Ÿฐ ๋ฌธ์ œ ๋ฆฟ์ฝ”๋“œ์—์„œ ์ข…์ข… ๋ดค๋Š”๋ฐ, ๊ทธ ๋–„ ๋งˆ๋‹ค ํ’€๋•Œ๋„ ์žˆ๊ณ  ๋ชป ํ’€ ๋•Œ๋„ ์žˆ์–ด์„œ ์ œ๋Œ€๋กœ ์ข€ ํ•ด๋ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ฆ
22+
23+
## ๊ฒฐ๊ณผ
24+
25+
1๋ฒˆ, 2๋ฒˆ ๋‘๊ฐœ ํ’€์–ด์„œ ์ด์  7 ์ 

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /