Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created February 28, 2021 12:03
Show Gist options
  • Save MohammedALREAI/c9b19ce3685428f0632882db55912597 to your computer and use it in GitHub Desktop.
Save MohammedALREAI/c9b19ce3685428f0632882db55912597 to your computer and use it in GitHub Desktop.
rotateImage leetcode and codesignal
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