Soln: import heapq class Solution: def minTimeToReach(self, move_time): rows = len(move_time) cols = len(move_time[0]) distances = [[float('inf')] * cols for _ in range(rows)] priority_queue = [] heapq.heappush(priority_queue, (0, 0, 0)) distances[0][0] = 0 directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] while priority_queue: curr_time, curr_row, curr_col = heapq.heappop(priority_queue) if curr_time > distances[curr_row][curr_col]: continue for dr, dc in directions: new_row, new_col = curr_row + dr, curr_col + dc if 0
@ArnabBhadra022 ай бұрын
Soln1: class Solution: def isBalanced(self, num: str) -> bool: sum1 = 0 sum2 = 0 for i in range(len(num)): c = int(num[i]) if i % 2 == 0: sum1 += c else: sum2 += c return sum1 == sum2
@ArnabBhadra022 ай бұрын
Son3: from typing import List import heapq class Solution: def minTimeToReach(self, moveTime: List[List[int]]) -> int: rows, cols = len(moveTime), len(moveTime[0]) min_time = [[[float('inf')] * 2 for _ in range(cols)] for _ in range(rows)] min_time[0][0][0] = 0 priority_queue = [(0, 0, 0, 0)] directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] while priority_queue: current_time, row, col, parity = heapq.heappop(priority_queue) if current_time > min_time[row][col][parity]: continue for dr, dc in directions: new_row, new_col = row + dr, col + dc if 0