You are given two separate coding tasks.
Implement a function pow(x, n) that returns .
x
: a real number (double/float)
n
: a 32-bit signed integer (can be negative)
n < 0
(e.g.,
).
n
may be
-2^31
, so be careful when negating.
You are given an m x n grid of integers representing a map:
-1
represents a
wall
(blocked cell)
0
represents a
gate
INF = 2^31 - 1
) represents an
empty room
Update the grid in-place so that each empty room contains the distance (minimum number of moves) to its nearest gate.
INF
.
Input:
INF -1 0 INF
INF INF INF -1
INF -1 INF -1
0 -1 INF INF
Output:
3 -1 0 1
2 2 1 -1
1 -1 2 -1
0 -1 3 4
1 <= m, n <= 200
(or similar)