c++ - Rotate NxN Matrix Counter(anti)-Clockwise 90 Degress -
i have 2d matrix m[n][n] need rotate counter-clockwise 90 degrees. have seen many answers clockwise rotation cannot find counter-clockwise. how similar 2 operations?
if reverse order of each individual row , taken rows in opposite order clockwise rotation, count-clockwise rotation.
a b c g d d g c f d e f -> clockwise -> h e b -> reverse -> b e h -> opposite -> b e h g h f c rows c f ordering d g matrix counter clockwise usually it's easier (and more computationally efficient) clockwise rotation rotation on original matrix in reverse order if have clockwise rotating algorithm available.
1 2 3 9 8 7 3 6 9 4 5 6 -> reverse -> 6 5 4 -> clockwise -> 2 5 8 7 8 9 indices 3 2 1 1 4 7 matrix counter clockwise you can take 3 clockwise rotations counter clockwise rotation.
though in reality it's easy edit clockwise algorithm purposes directly. i'd use above options if don't care efficiency , don't want work through logic of changing direction of rotation.
Comments
Post a Comment