LeetCode: Rotate Image Solution

1/**
2 * @param {number[][]} matrix
3 * @return {void} Do not return anything, modify matrix in-place instead.
4 */
5var rotate = function (matrix) {
6 const N = matrix.length
7 const M = matrix[0].length
8 matrix.reverse()
9 for (let i = 0; i < N; i++) {
10 for (let j = i + 1; j < M; j++) {
11 ;[matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]
12 }
13 }
14 return matrix
15}

Comments

Loading comments...

Tags

leetcode

array

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

LeetCode: First Unique Character In A String

HoningJS

Search Posts