Solved LeetCode program · 797 of 1,000
#1034 · Coloring A Border
Original English source
Keep a shared grid holding 1, 1, 1, and 2. Keep a shared visited as an empty list of whole numbers. Keep a shared queue as an empty list of whole numbers. Keep a shared border as an empty list of whole numbers. Keep a shared rows of 0. Keep a shared columns of 0. Keep a shared old of 0. Keep a shared color of 0. Keep a shared count of 0. Set rows to 2. Set columns to 2. Set old to 1. Set color to 3.
For every cell from 0 to 3.
Place 0 into visited.
To include with node (a whole number).
If item node of visited is 0 and item node of grid is old.
Set item node of visited to 1. Place node into queue. Add 1 to count.
To mark with node (a whole number). The across is node divided by columns. The down is node modulo columns. The edge is 0. If across is 0 or across is rows minus 1 or down is 0 or down is columns minus 1, set edge to 1. If across is more than 0 and item (node minus columns) of grid is not old, set edge to 1. If across is less than rows minus 1 and item (node plus columns) of grid is not old, set edge to 1. If down is more than 0 and item (node minus 1) of grid is not old, set edge to 1. If down is less than columns minus 1 and item (node plus 1) of grid is not old, set edge to 1. If edge is 1, Place node into border.
The head is 0. Include with 0.
Repeat while head is less than count.
The spot is head. The node is item spot of queue. Add 1 to head. Mark with node. The across is node divided by columns. The down is node modulo columns. If across is more than 0, Include with node minus columns. If across is less than rows minus 1, Include with node plus columns. If down is more than 0, Include with node minus 1. If down is less than columns minus 1, Include with node plus 1.
For each node in border.
Set item node of grid to color.
For each value in grid.
Show value.
Expected stdout
3 3 3 2