A rectangular panel consists of R rows, with C bulbs in each row.
The rows are numbered from 0 to R-1, and the columns are numbered from 0 to C-1.
Some of the bulbs are turned on and some of them are turned off.
The panel is connected to a board with switches. The switches are arranged into
a rectangle with R rows and C columns (i.e., with the same dimensions as the
panel).
Flipping each switch will cause some of the bulbs to change state: those that were
turned on will become turned off, and vice versa. More precisely, if we flip
the switch with coordinates (row,col), then all bulbs with coordinates (x,y)
where x<=row and y<=col will change their states. In other words, flipping
the switch at (row,col) switches all the bulbs in the rectangle with opposite
corners (0,0) and (row,col).
You will be given a String[] board containing the initial states
of the bulbs. The character '1' represents a bulb that is turned on, and the
character '0' represents a bulb that is turned off.
Return the smallest number of flips necessary to have all the bulbs on at the same time.
|