avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

1825. Seek out MK average value

  2024-01-01        
字数统计: 153字   |   阅读时长: 1min

2023-01-22.png

topic:

1824Minimum side jump number

answer:

I won’t

https://leetcode.cn/problems/minimum-sideway-jumps/solutions/2071617/cong-0-dao-1-de-0-1-bfspythonjavacgo-by-1m8z4/?orderBy=most_votes

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
n = len(obstacles)
dis = [[n] * 3 for _ in range(n)]
dis[0][1] = 0
q = deque([(0, 1)]) # starting point
while True:
i, j = q.popleft()
d = dis[i][j]
if i == n - 1: return d # reach destination
if obstacles[i + 1] != j + 1 and d < dis[i + 1][j]: # To the right
dis[i + 1][j] = d
q.appendleft((i + 1, j)) # Add to the team
for k in (j + 1) % 3, (j + 2) % 3: # The other two other runways are enumerated(up/down)
if obstacles[i] != k + 1 and d + 1 < dis[i][k]:
dis[i][k] = d + 1
q.append((i, k)) # Add to the tail
  • Python
  • unsolved
  • difficulty
  • Graph Theory

扫一扫,分享到微信

微信分享二维码
1825. Seek out MK average value
1828. Statistics the number of a circle mid -point One question daily
目录
  1. 1. topic:
  2. 2. answer:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号