Created
February 28, 2021 12:03
-
-
Save MohammedALREAI/c9b19ce3685428f0632882db55912597 to your computer and use it in GitHub Desktop.
rotateImage leetcode and codesignal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rotateImage(a: number[][]): number[][] { | |
swap(a) | |
reflext90(a) | |
return a | |
} | |
function swap(a:number[][]):void{ | |
let row=a.length; | |
let col=a[0].length; | |
for(let i = 0; i < row; i ++) { | |
for(let j = i + 1; j < col; j ++) { | |
const temp = a[j][i] | |
a[j][i] = a[i][j] | |
a[i][j] = temp | |
}}} | |
function reflext90(matrix:number[][]):void{ | |
const n= matrix.length | |
for (let i = 0; i < matrix.length; i++){ | |
for (let j = 0; j < matrix.length/2; j++){ | |
const temp = matrix[i][j] | |
matrix[i][j] = matrix[i][n- j -1] | |
matrix[i][n - j -1] = temp | |
} | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment